<?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
$indent_code="<ul>
<li>Fruit
-- <ul>
--- <li>Red
--- <ul>
---- <li>Cherry</li>
---- <li>Strawberry</li>
---- <li>Red apple</li>
--- </ul>
--- </li>
--- <li>Yellow
---- <ul>
---- <li>Lemon</li>
---- <li>Elstar</li>
---- </ul>
--- </li>
-- </ul>
</li>
</ul>";
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";
$prev_count=0; // initialize this for use in ondata function
$timer = new timer(1);
//$connect_time = $timer->get($decimals=8);
$load_time = $timer->get($decimals=8);
// ===================== ======== =============================
$TBS = new clsTinyButStrong ;
$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();
$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) {
// we will need to know the number of levels between current record and prev record
global $prev_count;
$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'], "-");
$prev_count<$count ? $prepend="<ul><li>" : $append="</li>" ;
$delta=$prev_count-$count; // get the nnumber of levels traversed
if($prev_count==$count ){
$prepend="<li>";
$append="" ;
}
if($prev_count>$count){
// 1st need to do the OUT-dent thingy for unwinding list levels
$delta=$prev_count-$count;
for ($i=0; $i < $delta; $i++) {
$prepend.="</ul>";
}
$prepend.="<li>";
$append="" ;
}
// for top level ITEMS special CSS handling instead of bulleted
// do the OUT-dent thingy for unwinding list levels
if($count==0){
$prepend=""; // kill any li prepend for the top level items
for ($i=0; $i < $delta; $i++) {
$prepend.="</ul>";
}
$prepend.="<div class=\"menu".$CurrRec['m_newlineage']."\">";
$append="</div>" ;
}
$CurrRec['prepend']=$prepend;
$CurrRec['append']=$append;
$CurrRec['precnt']=$prev_count;
$CurrRec['count']=$count;
// before we leave the ondata function reset prevcount to the current count
$prev_count=$count;
// we need to bring prev_count around the corner
return $prev_count;
} // end ondata function
// ====================== ONDATA function =========================
?>