<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
global $filter_array;
$title=get('title');
if(!$title)
$title=$mm2;
if(!$title)
$title='Tree';
//reading get params
for($tmp_ii=0;$tmp_ii<10;$tmp_ii++)
{
$tmp_value=trim(get('tree'.$tmp_ii));
if($tmp_value)
$dimension_array[]=$tmp_value;
}
// definition
$max_fields=4;
if(count($dimension_array)>=$max_fields)
$max_fields=count($dimension_array)+1;
//--------------------------------------------------------------------------------------
$tree_array=array();
$new_show_result_array=array();
$record_array=$show_result_array;
reset($record_array);
while(list($tmp_kk,$line)=each($record_array))
{
$tmp_tree_filter='';
$tree_address='';
$tmp_empty=0;
reset($dimension_array);
foreach($dimension_array as $tree_level)
{
$tree_level_value=read($line,$tree_level);
$tree_address.='$'.$tree_level_value;
if($tree_level_value=='')
$tmp_empty=1;
}
if(!$tmp_empty and strpos('_'.$tree_address.'$',$tree_filter.'$')==1)
$new_show_result_array[]=$line;
$tree_array[$tree_address]++;
}
$show_result_array=$new_show_result_array;
ksort($tree_array);
function show_tree($tree_array,$tree_filter,$max_level,$tree_node='$')
{
$tree_level=strlen($tree_node)-strlen(str_replace('$','',$tree_node));
$tmp_tree_level_array=array();
reset($tree_array);
foreach($tree_array as $tmp_tree_node => $tmp_cnt)
{
if(strpos('_'.$tmp_tree_node.'$',$tree_node)==1)
{
$tmp_array=explode('$',$tmp_tree_node);
$tmp_tree_level_array[$tmp_array[$tree_level]]=$tmp_cnt;
}
}
echo '<ul>';
$cnt=1;
reset($tmp_tree_level_array);
foreach($tmp_tree_level_array as $tmp_tree_node => $tmp_cnt)
{
if($tmp_tree_node)
{
if($tree_level<$max_level)
if(strpos('_'.$tree_filter.'$',$tree_node.$tmp_tree_node.'$')==1)
echo '<li class="opened" onclick="if(first_click){if(this.className==\'opened\'){this.className=\'closed\'}else{this.className=\'opened\'}}; first_click=false;">';
else
echo '<li class="closed" onclick="if(first_click){if(this.className==\'opened\'){this.className=\'closed\'}else{this.className=\'opened\'}}; first_click=false;">';
else
echo '<li onclick="first_click=false;">';
echo '<a onclick="first_click=false;" href="index.php?'.REPORTLINK.'&odb_tree_filter='.urlencode($tree_node.$tmp_tree_node).'">';
if($tree_level==$max_level)
{
//echo ($cnt++).'. ';
}
echo $tmp_tree_node;
//if($tree_level==$max_level)
echo '</a>';
if($tree_level<$max_level)
show_tree($tree_array,$tree_filter,$max_level,$tree_node.$tmp_tree_node.'$');
echo '</li>';
}
}
echo '</ul>';
}
echo '<script>var first_click=true;</script>';
echo '<div id="tree" onclick="first_click=true">';
show_tree($tree_array,$tree_filter,count($dimension_array));
echo '</div>';
//-------------------------------------------------------------------------------
/*
echo '<a class="noprint" style="margin-left:10px;" href="#" onclick="document.getElementById(\'treedef\').style.display=\'block\'; this.style.display=\'none\';">';
myecho('Show definition');
echo '</a>';
echo('<form action="index.php" method="get">');
echo('<div id="treedef" style="display:none;">');
echo('<input name="odb_search" type="hidden" value="'.$search.'"></input>');
echo '<div class="supergroup">';
echo '<h3>';
myecho('Definition');
echo '</h3>';
echo '<table class="noprint">';
echo '<tr>';
echo '<th>';
echo '</th>';
echo '<th>';
myecho('Tree Branch');
echo '</th>';
echo '</tr>';
$tmp_ii=0;
reset($dimension_array);
foreach($dimension_array as $dimension_name)
{
echo '<tr>';
echo '<th>';
echo ($tmp_ii+1).'.';
echo '</th>';
echo '<td>';
echo '<input class="fld_" name="odb_tree'.$tmp_ii.'" value="'.$dimension_name.'"/>';
echo '</td>';
$tmp_ii++;
echo '</tr>';
}
for($tmp_ii=count($dimension_array);$tmp_ii<$max_fields;$tmp_ii++)
{
echo '<tr>';
echo '<th>';
echo ($tmp_ii+1).'.';
echo '</th>';
echo '<td>';
echo '<input class="fld_" name="odb_tree'.$tmp_ii.'" value=""/>';
echo '</td>';
echo '</tr>';
}
echo '</table>';
echo '<a class="noprint" style="margin-left:10px;" href="index.php?odb_sys=structure" target="_blank">';
myecho('Show all available fields');
echo '</a>';
echo('<br /><input type="submit" class="button" value="'.myecho('Change definition','RETURN').'" />');
echo '</div>';
echo('</div></form>');
*/
?>