<?php
include_once("php_inc/tbssql_adapter_3.2a.php"); // Instantiate the tbssql class w/ connection info
error_reporting(E_ERROR); // for PHP5 error reporting
$db->cache_dir = false; // DEFAULT is FALSE
$db->cache_queries = false; // DEFAULT is FALSE
$db->cache_inserts = false; // DEFAULT is FALSE
$db->use_disk_cache = false; // DEFAULT is FALSE
// =============== tips from Skrol29 ===================
if (isset($this)) {
// we are under the TBS Subtemplate Mode =>
// variables are always local, not global,
// and the TBS object is referenced by variable $this.
$TBS =& $this;
//$TBS->NoErr = true;
} else {
// This sub-script can also be run under the normal mode =>
// its corresponding template will be displayed like a main template.
$TBS = new clsTinyButStrong;
//$TBS->NoErr = true;
}
// ========================================================
// ====== TbsSQL v.3.0 properties to be configured =======
// $Db->Mode = TBSSQL_TRACE + TBSSQL_GRID + TBSSQL_CONSOLE; // default false
// $Db->DefaultRowType = TBSSQL_OBJECT; // default is: TBSSQL_ARRAY;
// $Db->ConfInfo(); // Show the current configuration of TbsSQL.
$Db->CacheTimeout = 2; //mins //TBSSQL_1HOUR; //mins // DEFAULT: no caching // when debugging
//$Db->TempCacheTimeout = 2; //mins //TBSSQL_1HOUR; //mins // DEFAULT: no caching // when debugging
$Db->CacheAutoClear = 60; //mins //TBSSQL_1HOUR, TBSSQL_1DAY, or TBSSQL_1WEEK
//$Db->CacheDir = "tbssql_cache"; // Default is: "."
// ========================================================
include("class_timer.php");
$timer = new timer(1); //started in auto_prepend file
// ---------------------------------------------------------------------------
// Hierarchical Menu using the calculated "lineage' for each item making the
// complete menu build as simple as a flat-file sort of a single query!!!!
// This eliminates the whole issue of subqueries and the related performance hit
//
// Credit for the basic idea of usonig "lineage" was found at
// http://www.evolt.org/article/Four_ways_to_work_with_hierarchical_data/17/4047/index.html
// which includes a helpful discussion about various strategies for hierarchical menus
//
// It convinced me to build a full TBS application to build and display the menus.
// I wrote a utility script "lineage_create_php.php" to automate the construction
// of the "lineage" value for each item see http://tomhenry.us/tbs3/ for the source.s
//
// By setting up the db table properly the lineage can be refreshed without any
// recursion at all - I think it's slick as bananas on peanut butter!
// ---------------------------------------------------------------------------
// This TBS script is running with direct include of TBS and ezSQL db plugin classes
// include("../php_inc/tbs_ddwork_ezsql.inc");
//$table = "t_test_tree";
$table = "t_test_tree_2";
// footer copyright
$year = date("Y");
$timer = new timer(1);
//$connect_time = $timer->get($decimals=8);
$load_time = $timer->get($decimals=8);
// ===================== ======== =============================
$TBS = new clsTinyButStrong ;
//$debug .= "ezSQL version: ".$ezsql_version;
$TBS->LoadTemplate(basename($_SERVER['SCRIPT_NAME'], ".php").".tpl") ;
//$sql = "SELECT m_parent,m_id,m_title,m_lineage,m_newlineage,CONCAT(m_newlineage,'-',m_id) AS sort_order FROM $table ORDER BY sort_order ";
// Gotta add a 'sequence field for ordering of peers >> "m_sequence"
//$sql = "SELECT m_parent,m_id,m_title,m_lineage,m_newlineage,m_sequence,CONCAT(m_newlineage,'-',m_id) AS sort_order FROM $table ORDER BY sort_order";
//$sql = "SELECT m_id , m_parent , m_title , m_lineage , m_newlineage , m_sequence FROM t_test_tree ORDER BY m_newlineage ASC";
$sql = "SELECT id,m_parent,m_id,m_title,m_lineage,m_newlineage,CONCAT(m_newlineage,'-',m_id) AS sort_order FROM $table ORDER BY sort_order";
$query_time = $timer->get($decimals=8);
$result = $Db->GetRows($sql);
$merge_time = $timer->get($decimals=8);
$TBS->MergeBlock('m',$result);
$show_time = $timer->get($decimals=8);
$TBS->show();
// ====================== ONDATA function =========================
function f_ondata_tree($BlockName,&$CurrRec,$RecNum) {
//global $timer;
$topslug="  :: "; // maybe a special indent for the main manu divisions
// count the number of levels to build the "indent" string
$count=substr_count($CurrRec['m_newlineage'], "-");
$count==0 ? $slug=$topslug : $slug=" ";
$i=0;
while($i<$count){
$slug .="    "; // $slug .="*"; // or another indent character
$i++;
}
$CurrRec['indent']=$slug;
} // end ondata function
// ====================== ONDATA function =========================
?>