<?php
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
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->get_results($sql);
//$ezdebug .= $db->debug();
//$db->debug();
$merge_time = $timer->get($decimals=8);
$TBS->MergeBlock('m',$db);
$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 =========================
?>