Location: PHPKode > projects > OpenBizMap > obm2007.1/mydata/script/tmp_tree.txt
<?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';

echo '<h2>';
myecho($title);
echo '</h2>';

//reading get params
for($tmp_ii=0;$tmp_ii<10;$tmp_ii++)
{
  $tmp_value=trim(get('a'.$tmp_ii));
  if($tmp_value)
    $dimension_array[]=$tmp_value;
}

// definition
$max_fields=6;
if(count($dimension_array)>=$max_fields)
  $max_fields=count($dimension_array)+1;


echo '<a class="noprint" style="margin-left:10px;" href="#" onclick="document.getElementById(\'reportdef\').style.display=\'block\'; this.style.display=\'none\';">';
  myecho('Show definition');
echo '</a>';


echo('<form action="index.php" method="get">');
echo('<div id="reportdef" style="display:none;"><input name="odb_script" type="hidden" value="tree"></input>');
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>';

  for($tmp_ii=0;$tmp_ii<$max_fields;$tmp_ii++)
  {
    echo '<th>';
      echo colSymbol($tmp_ii).'.';
    echo '</th>';
  }
echo '</tr>';



echo '<tr>';
  echo '<th>';
    echo 'Tree Level';
  echo '</th>';

  $tmp_ii=0;
  reset($dimension_array);
  foreach($dimension_array as $dimension_name)
  {
    echo '<td>';
      echo '<input class="fld_" name="a'.$tmp_ii.'" value="'.$dimension_name.'"/>';
    echo '</td>';
    $tmp_ii++;
  }
  for($tmp_ii=count($dimension_array);$tmp_ii<$max_fields;$tmp_ii++)
  {
    echo '<td>';
      echo '<input class="fld_" name="a'.$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>');


flush();


//--------------------------------------------------------------------------------------
$report_link='';
$report_link.='&amp;odb_search='.urlencode($search);
$report_link.='&amp;odb_script=tree';
$report_link.='&amp;odb_title='.urlencode($title);
for($ii=0;$ii<10;$ii++)
{
  $report_link.='&amp;a'.$ii.'='.urlencode(get('a'.$ii));
}

$tree_filter=get('tree_filter');

$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='';
  reset($dimension_array);
  foreach($dimension_array as $tree_level)
  {
    $tree_level_value=read($line,$tree_level);
    
    $tree_address.='$'.$tree_level_value;
  }

  if(strpos('_'.$tree_address,$tree_filter)==1)
    $new_show_result_array[]=$line;
  
  $tree_array[$tree_address]=read($line,'sysId');
}
$show_result_array=$new_show_result_array;



ksort($tree_array);


 
function show_tree($tree_array,$tree_filter,$max_level,$tree_node='$')
{
  global $report_link;
  
  $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_sysId)
  {
    if(strpos('_'.$tmp_tree_node.'$',$tree_node)==1)
    {
      $tmp_array=explode('$',$tmp_tree_node);
      $tmp_tree_level_array[$tmp_array[$tree_level]]=$tmp_sysId;
    }
  }

  echo '<ul>';
  reset($tmp_tree_level_array);
  foreach($tmp_tree_level_array as $tmp_tree_node => $tmp_sysId)
  {
    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?'.$report_link.'&amp;odb_tree_filter='.urlencode($tree_node.$tmp_tree_node).'">';
      
      if($tree_level==$max_level)
      {
        
        //echo '<img src="'.cfg_images_path.'/file.png" alt="'.myecho('File','RETURN').'" /> ';
      }
      
      //if($tmp_tree_node)
        echo $tmp_tree_node;
      //else
      //  myecho('No name');
        
      //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>';

$script='';

?>
Return current item: OpenBizMap