Location: PHPKode > projects > OpenBizMap > obm2007.1/mydata/script/tmp_chart.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='Chart';


function getIndex($line, $variable_name_array, &$cube_index_array, $drill_array)
{
  $tmp_index_array=array();
  $tmp_index='';
  $tmp_drill=1;
  $full_drill_key='';
  reset($variable_name_array);
  foreach($variable_name_array as $variable_name)
  {
    if(substr($variable_name,-2)=='.Y')
      $tmp_value=substr(read($line,substr($variable_name,0,-2)),0,4);
    elseif(substr($variable_name,-3)=='.YM')
      $tmp_value=substr(read($line,substr($variable_name,0,-3)),0,6);
    elseif(substr($variable_name,-3)=='.YQ')
      $tmp_value=substr(read($line,substr($variable_name,0,-3)),0,4).'Q'.(floor(substr(read($line,substr($variable_name,0,-3)),4,2)/4)+1);
    else
      $tmp_value=read($line,$variable_name);

    $full_drill_key.=$variable_name.'='.$tmp_value.' ';
    $drill_key=($full_drill_key);

    if(!$tmp_drill)
      $tmp_value='&sum;';

    $tmp_index.=strtolower($variable_name.'='.$tmp_value.' ');
    $tmp_index_array[$variable_name]=$tmp_value;

    if(!isset($drill_array[$drill_key]) or $drill_array[$drill_key]==0)
      $tmp_drill=0;
  }
  $tmp_index=($tmp_index);
  $cube_index_array[$tmp_index]=$tmp_index_array;

  return $tmp_index;
}


echo '<a name="top" ></a>';

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

$chart_type=get('type');
if(!$chart_type)
  $chart_type='3d column';

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

  $tmp_value=trim(get('b'.$tmp_ii));
  if($tmp_value)
    $dimension_array['up'][]=$tmp_value;

  $tmp_value=trim(get('c'.$tmp_ii));
  if($tmp_value)
    $measure_array[$tmp_value]=trim(get('d'.$tmp_ii));
}

//~ $dimension_array=array(
  //~ 'up' => array( ),//'All', 'sysGroupBy' ),//Datum der Auffälligkeit'),
  //~ 'left' => array( 'All ', 'Geschäftsstelle', 'Team')
//~ );
//~ $measure_array=array(
  //~ 'Arbeitskosten Gesamt' => 'sum',
  //~ 'Verwaltungskosten Gesamt' => 'sum',
  //~ 'Zinsausfall' => 'sum',
  //~ 'Sonstige Kosten' => 'sum',
  //~ 'Anzahl Auffälligkeiten' => 'count',
  //~ 'Gesamtkosten der Auffälligkeit' => 'sum',
//~ );

// definition
$max_fields=6;
if(count($dimension_array['up'])>=$max_fields)
  $max_fields=count($dimension_array['up'])+1;
if(count($dimension_array['left'])>=$max_fields)
  $max_fields=count($dimension_array['left'])+1;
if(count($measure_array)>=$max_fields)
  $max_fields=count($measure_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="chart"></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>';
  myecho('Title');
  echo '</th>';
  echo '<td>';
   echo '<input class="fld_" name="odb_title" value="'.$title.'"/>';
  echo '</td>';
echo '</tr>';
echo '<tr>';
  echo '<th>';
  myecho('Chart type');
  echo '</th>';
  echo '<td>';
    echo '<select name="odb_type">';
    echo '<option>'.$chart_type.'</option>';
    echo '<option>column</option>';
    echo '<option>3d column</option>';
    echo '<option>stacked column</option>';
    echo '<option>stacked 3d column</option>';
    echo '<option>line</option>';
    echo '<option>bar</option>';
    echo '<option>polar</option>';
    echo '<option>3d pie</option>';
    echo '<option>pie</option>';
    echo '<option>area</option>';
    echo '<option>stacked area</option>';
    echo '</select>';
  echo '</td>';
echo '</tr>';
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 'Left';
  echo '</th>';

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



echo '<tr>';
  echo '<th>';
    echo 'Up';
  echo '</th>';

  $tmp_ii=0;
  reset($dimension_array['up']);
  foreach($dimension_array['up'] as $dimension_name)
  {
    echo '<td>';
      echo '<input class="fld_" name="b'.$tmp_ii.'" value="'.$dimension_name.'"/>';
    echo '</td>';
    $tmp_ii++;
  }

  for($tmp_ii=count($dimension_array['up']);$tmp_ii<$max_fields;$tmp_ii++)
  {
    echo '<td>';
      echo '<input class="fld_" name="b'.$tmp_ii.'" value=""/>';
    echo '</td>';
  }
echo '</tr>';



echo '<tr>';
  echo '<th>';
    echo 'Values';
  echo '</th>';

  $tmp_ii=0;
  reset($measure_array);
  foreach($measure_array as $measure_name => $measure_type)
  {
    echo '<td>';
      echo '<input class="fld_" name="c'.$tmp_ii.'" value="'.$measure_name.'"/>';
      echo '<select name="d'.$tmp_ii.'">';
      echo '<option>'.$measure_type.'</option>';
      echo '<option>sum</option>';
      echo '<option>count</option>';
      echo '</select>';
    echo '</td>';
    $tmp_ii++;
  }

  for($tmp_ii=count($measure_array);$tmp_ii<$max_fields;$tmp_ii++)
  {
    echo '<td>';
      echo '<input class="fld_" name="c'.$tmp_ii.'" value=""/>';
      echo '<select name="d'.$tmp_ii.'">';
      echo '<option></option>';
      echo '<option>sum</option>';
      echo '<option>count</option>';
      echo '</select>';
    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="submit" 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='.urlencode($script);
$report_link.='&amp;odb_title='.urlencode($title);
for($ii=0;$ii<10;$ii++)
{
  $report_link.='&amp;a'.$ii.'='.urlencode(get('a'.$ii));
  $report_link.='&amp;b'.$ii.'='.urlencode(get('b'.$ii));
  $report_link.='&amp;c'.$ii.'='.urlencode(get('c'.$ii));
  $report_link.='&amp;d'.$ii.'='.urlencode(get('d'.$ii));
}


//drill settings
$drill_array=unserialize(get('drill'));

$drillin=get('drillin1');
$drillout=get('drillout1');
if($drillin)
  $drill_array[$drillin]=1;
if($drillout)
  $drill_array[$drillout]=0;

$drillin=get('drillin2');
$drillout=get('drillout2');
if($drillin)
  $drill_array[$drillin]=1;
if($drillout)
  $drill_array[$drillout]=0;

$session_array['drill']=serialize($drill_array);

$category_description_count=0;
$cube_array=array();
$cube_index_array=array();
$total_left=array();
$record_array=$show_result_array;
reset($record_array);
while(list($tmp,$line)=each($record_array))
{
  $up_index=getIndex($line,$dimension_array['up'], $cube_index_array['up'], $drill_array);
  $left_index=getIndex($line,$dimension_array['left'], $cube_index_array['left'], $drill_array);

  reset($measure_array);
  while(list($measure_name,$measure_type)=each($measure_array))
  {
    if($measure_type=='sum')
      $cube_array[$left_index][$up_index][$measure_name]+=read($line,$measure_name);
    else //if($measure_type=='count')
      $cube_array[$left_index][$up_index][$measure_name]+=1;

    $total_left[$left_index]+=$cube_array[$left_index][$up_index][$measure_name];
  }
}

$tmp_cnt=0;
arsort($total_left);
$tmp_total_left=array();
foreach($total_left as $tmp_key => $tmp)
{
  $tmp_cnt++;
  $tmp_total_left[$tmp_key]=1;

  if($tmp_cnt>6)
    break;
}
$tmp_total_left[strtolower($dimension_array['left'][0]).'=other']=1;
$total_left=$tmp_total_left;

$category_description_count=0;
$cube_array=array();
$cube_index_array=array();
$record_array=$show_result_array;
reset($record_array);
while(list($tmp,$line)=each($record_array))
{
  $up_index=getIndex($line,$dimension_array['up'], $cube_index_array['up'], $drill_array);
  $left_index=getIndex($line,$dimension_array['left'], $cube_index_array['left'], $drill_array);

  if(!isset($total_left[$left_index]))
    $left_index=strtolower($dimension_array['left'][0]).'=other';

  reset($measure_array);
  while(list($measure_name,$measure_type)=each($measure_array))
  {
    if($measure_type=='sum')
      $cube_array[$left_index][$up_index][$measure_name]+=read($line,$measure_name);
    else //if($measure_type=='count')
      $cube_array[$left_index][$up_index][$measure_name]+=1;
  }
}

//print_r($cube_index_array['up']); exit;

$tmp_cube_index_array_left=$cube_index_array['left'];
$cube_index_array['left']=array();
reset($total_left);
foreach($total_left as $tmp_key => $tmp)
{
  if(!isset($tmp_cube_index_array_left[$tmp_key]))
    $cube_index_array['left'][$tmp_key][$dimension_array['left'][0]]='Other';
  else
    $cube_index_array['left'][$tmp_key]=$tmp_cube_index_array_left[$tmp_key];
}
//echo '<pre>'; print_r($cube_index_array['left']); exit;


 //$cube_index_array=arsort($cube_index_array);

  $sort_array=array();
  reset($cube_index_array['up']);
  foreach($cube_index_array['up'] as $key => $val)
  {
    $sort_array[$key]=$val;
  }
  ksort($sort_array);
  $cube_index_array['up']=$sort_array;

/* 
  $sort_array=array();
  reset($cube_index_array['left']);
  foreach($cube_index_array['left'] as $key => $val)
  {
    $sort_array[$key]=$val;
  }
  ksort($sort_array);
  $cube_index_array['left']=$sort_array;
*/
// echo '<pre>';
// print_r($cube_index_array['up']);
// echo '</pre>';

//~ echo '<pre>';
//~ print_r($cube_array);
//~ echo '</pre>';

$content_data='';
$font_size='8';
$orientation='horizontal';

//--------------------------------------------------- Preparing data for the chart -----------------------------------
  // UP dimensions headers
  $up_first_level=0; //span switch
  $left_empty_space_presented=0;
  $full_drill_key_array=array();
  reset($dimension_array['up']);
  foreach($dimension_array['up'] as $tmp_ii => $up_dimension_name)
  {
    $content_data.='<row>';

      //left empty space
      if(!$left_empty_space_presented)
      {
        $left_empty_space_presented=1;
        $content_data.='<null/>';
      }

      //up dimension name
      //$content_data.='<string>'.$up_dimension_name.'</string>';

      
      reset($measure_array);
      reset($cube_index_array['up']);
      foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
      {
        if(!$up_first_level or $span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]]>0)
        {
          $full_drill_key_array[$up_index].=$up_dimension_name.'='.$up_index_values_array[$up_dimension_name].' ';
  
          if($up_index_values_array[$up_dimension_name]!='&sum;' and ($tmp_ii!=count($dimension_array['up'])-1))
          {
            $drill_index_array['up'][$up_index]=($full_drill_key_array[$up_index]);
            $drill_key=$drill_index_array['up'][$up_index];
          }
          
          foreach($measure_array as $measure_name => $tmp)
          {
            $content_data.='<string>'.$up_index_values_array[$up_dimension_name].'\r'.$measure_name.'</string>';
            $category_description_count+=strlen($up_index_values_array[$up_dimension_name]);

            if($category_description_count>100)
            {
              $orientation='vertical_down';
              $font_size='12';
            }
            if($category_description_count>200)
            {
              $orientation='vertical_down';
              $font_size='8';
            }

            if($up_first_level)
              $span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]]=0;
          }
        }
      }

    $content_data.='</row>';
    $up_first_level=0;
  }

  // MEASURES headers
  //$content_data.='<row>';

    //left empty space by SPAN
    //measure names row header
    //$content_data.='<null/>';

    //up measure headers
    $col_count=0;
    $up_placeholder_html='<th style="width:10px;"></th>';
    reset($measure_array);
    reset($cube_index_array['up']);
    foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
    foreach($measure_array as $measure_name => $tmp)
    {
      //$content_data.='<string>'.$measure_name.'</string>';

      $up_placeholder_html.='<th>'.colSymbol($col_count).'.</th>';
      $col_count++;
    }
  //$content_data.='</row>';

  //echo '<pre>';
  //print_r($cube_index_array['left']);
  //echo '</pre>';
  
  $rowspan_array=array();
  reset($cube_index_array['left']);
  foreach($cube_index_array['left'] as $left_index => $left_index_values_array)
  {
    foreach($left_index_values_array as $left_dimension_name => $tmp)
    {
      $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]++;
      //echo $left_dimension_name.'==='.$left_index_values_array[$left_dimension_name].'<br />';
      break;
    }
  }
  
  
  // echo '<pre>';
  // print_r($rowspan_array);
  // echo '</pre>';
  
  // MEASURES
  $row_count=1;
  reset($cube_index_array['left']);
  foreach($cube_index_array['left'] as $left_index => $left_index_values_array)
  {
    $content_data.='<row>';

    //left specific headers
    $left_first_level=0; //span switch
    $full_drill_key='';
    reset($dimension_array['left']);
    foreach($dimension_array['left'] as $tmp_ii => $left_dimension_name)
    {
      if(!$left_first_level or $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]>0)
      {
        $content_data.='<string>'.$left_index_values_array[$left_dimension_name].'</string>';

        if($left_first_level)
          $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]=0;
      }
      $left_first_level=0;
    }

    //left empty column - up dimension names placeholder

    reset($measure_array);
    reset($cube_index_array['up']);
    foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
    foreach($measure_array as $measure_name => $measure_type)
    {
      $show_value=$cube_array[$left_index][$up_index][$measure_name];
      $content_data.='<number>'.$show_value.'</number>';
    }
    $content_data.='</row>';
    $row_count++;
  }

//echo str_replace('>','&gt;<br/>',str_replace('<','&lt;',$content_data));

  //--------------------------- Preparing chart xml ---------------------------------------------

  $content='';
  $content.='<chart>';

  $content.='<chart_data>';
  $content.=$content_data;
  $content.='</chart_data>';

  $content.='<chart_type>';
  $content.=$chart_type;
  $content.='</chart_type>';

  //Transition
  $content.='<chart_transition type="scale" delay="0" duration="1" order="all"/>';

  $content.='<chart_rect positive_color="ffffff" positive_alpha="20" negative_color="ff0000" negative_alpha="10" />';

  $content.='<series_color>';
  
  $content.='<color>ffa500</color>';
  $content.='<color>ff6347</color>';
  $content.='<color>f0e68c</color>';

  $content.='<color>da70d6</color>';
  $content.='<color>8a2be2</color>';

  $content.='<color>800080</color>';
  $content.='<color>6a5acd</color>';
  $content.='<color>9acd32</color>';
  $content.='<color>808000</color>';

  $content.='<color>4682b4</color>';
  $content.='<color>ff69b4</color>';
  $content.='<color>ffdead</color>';
  $content.='<color>d2691e</color>';

  $content.='<color>8b4513</color>';
  $content.='<color>a52a2a</color>';

  $content.='</series_color>';

  if($chart_type=='3d pie')
  {
    $content.='<chart_value hide_zero="true" color="000000" alpha="80" size="10" position="inside" prefix="" suffix="" decimals="0" separator="" as_percentage="true" />';
  }
  elseif($chart_type=='polar')
  {
    $content.='<chart_value hide_zero="true" color="000000" alpha="80" size="10" position="inside" prefix="" suffix="" decimals="0" separator="" as_percentage="true" />';
    $content.='<axis_category font="arial" bold="true" size="12" color="000000" alpha="50" orientation="horizontal" /><axis_value size="12" alpha="50" decimal_char="," separator=" "  show_min="true" /><chart_value size="12" alpha="80" decimal_char="," separator=" "/>';
  }
  elseif($chart_type=='bar')
  {
    $content.='<chart_value hide_zero="true" color="000000" alpha="80" size="10" position="inside" prefix="" suffix="" decimals="0" separator="" as_percentage="true" />';
    $content.='<axis_category font="arial" bold="true" size="'.round($font_size/2).'" color="000000" alpha="50" orientation="horizontal" /><axis_value size="12" alpha="50" decimal_char="," separator=" "  show_min="true" /><chart_value size="12" alpha="80" decimal_char="," separator=" "/>';
  }
  else
  {
    $content.='<chart_pref rotation_x="0" rotation_y="15" /><chart_grid_h thickness="1" type="solid" /><chart_grid_v thickness="1" type="solid" />';
    $content.='<chart_value hide_zero="true" color="000000" alpha="80" size="10" position="over" prefix="" suffix="" decimals="0" separator="" as_percentage="true" />';
    $content.='<axis_category font="arial" bold="true" size="'.$font_size.'" color="000000" alpha="50" orientation="'.$orientation.'" /><axis_value size="12" alpha="50" decimal_char="," separator=" "  show_min="true" /><chart_value size="12" alpha="80" decimal_char="," separator=" "/>';
  }

  //Label
  $content.='<legend_label layout="horizontal" bullet="circle" font="arial" bold="true" size="13" color="000000" alpha="85" />';
  $content.='<legend_rect fill_color="aaaaaa" fill_alpha="10" line_color="000000" line_alpha="0" line_thickness="0" />';

  //Title
  $content.='<draw>';
  $content.='<text  transition="slide_right" delay="0" duration="1" x="0" y="450" width="400" height="600" h_align="right" v_align="top" rotation="-90" font="arial" bold="true" size="55" color="000000" alpha="10">'.myecho($title,'RETURN').'</text>';
  $content.='</draw>';


  $content.='</chart>';


  $tmp_file_name=USERNAME.'-'.md5(time().rand(0,1000));
  addpath(cfg_data_path.'/temp/tempfile');
  $fp=fopen(cfg_data_path.'/temp/tempfile/'.$tmp_file_name,'w');
  fwrite($fp,$content);
  fclose($fp);
  //style="visibility:hidden;" mouseover menu???
?>
<div>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" 
  WIDTH="950" 
  HEIGHT="400" 
  id="chart1" 
  ALIGN="">
<PARAM NAME=movie VALUE="charts/charts.swf?library_path=charts/charts_library&xml_source=odb_tempfile.php?odb_file=<?php echo $tmp_file_name;?>">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#ffffff>
<PARAM NAME=wmode VALUE=transparent>

<EMBED src="charts/charts.swf?library_path=charts/charts_library&xml_source=odb_tempfile.php?odb_file=<?php echo $tmp_file_name;?>"
       quality=high 
       bgcolor=#ffffff
       wmode=transparent
       WIDTH="950" 
       HEIGHT="400" 
       NAME="charts" 
       ALIGN="" 
       swLiveConnect="true" 
       TYPE="application/x-shockwave-flash" 
       PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
</div>
<?php


echo '<div class="supergroup">';
echo '<table border="1">';

  // UP dimensions headers
  $up_first_level=0; //span switch
  $left_empty_space_presented=0;
  $full_drill_key_array=array();
  reset($dimension_array['up']);
  foreach($dimension_array['up'] as $tmp_ii => $up_dimension_name)
  {
    echo '<tr>';
    $content_data.='<row>';

      //left empty space
      if(!$left_empty_space_presented)
      {
        echo '<th rowspan="'.(count($dimension_array['up'])).'" colspan="'.count($dimension_array['left']).'"></th>';
        $left_empty_space_presented=1;
        $content_data.='<null/>';
      }

      //up dimension name
      echo '<th>';
        echo $up_dimension_name;
      echo '</th>';
      $content_data.='<string>'.$up_dimension_name.'</string>';

      //up specific headers
      /*
      if($up_first_level)
      {
        $span_array=array();
        reset($measure_array);
        reset($cube_index_array['up']);
        foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
        //foreach($measure_array as $measure_name => $tmp)
          $span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]]++;
      }
      */
      
      reset($measure_array);
      reset($cube_index_array['up']);
      foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
      {
        if(!$up_first_level or $span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]]>0)
        {
          $full_drill_key_array[$up_index].=$up_dimension_name.'='.$up_index_values_array[$up_dimension_name].' ';
  
          if($up_index_values_array[$up_dimension_name]!='&sum;' and ($tmp_ii!=count($dimension_array['up'])-1))
          {
            $drill_index_array['up'][$up_index]=($full_drill_key_array[$up_index]);
            $drill_key=$drill_index_array['up'][$up_index];
          }
          
          foreach($measure_array as $measure_name => $tmp)
          {
            if($up_first_level)
              echo '<th colspan="'.$span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]].'">';
            else
              echo '<th>';
              
            if($up_index_values_array[$up_dimension_name]!='&sum;' and ($tmp_ii!=count($dimension_array['up'])-1))
            {
              if(!isset($drill_array[$drill_key]) or $drill_array[$drill_key]==0)
                echo '<a href="index.php?odb_script=chart&amp;odb_drillin1='.$drill_key.'&amp;'.$report_link.'">';
              else
                echo '<a href="index.php?odb_script=chart&amp;odb_drillout1='.$drill_key.'&amp;'.$report_link.'">';
  
              if(strlen($up_index_values_array[$up_dimension_name]))
                echo $up_index_values_array[$up_dimension_name];
              else
                echo '&mdash;';
  
              echo '</a>';
            }
            else
            {
              if(strlen($up_index_values_array[$up_dimension_name]))
                echo $up_index_values_array[$up_dimension_name];
              else
                echo '&mdash;';
            }
  
            echo '</th>';
            $content_data.='<string>'.$up_index_values_array[$up_dimension_name].'</string>';

            if($up_first_level)
              $span_array[$up_dimension_name][$up_index_values_array[$up_dimension_name]]=0;
          }
        }
      }

    echo '</tr>';
    $content_data.='</row>';
    $up_first_level=0;
  }

  // MEASURES headers
  echo '<tr>';
  //$content_data.='<row>';

    //left empty space by SPAN
    //measure names row header
    echo '<th rowspan="1" colspan="'.(count($dimension_array['left'])+1).'"></th>';

    //up measure headers
    $col_count=0;
    $up_placeholder_html='<th style="width:10px;"></th>';
    reset($measure_array);
    reset($cube_index_array['up']);
    foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
    foreach($measure_array as $measure_name => $tmp)
    {
      echo '<th>';
      echo $measure_name;
      echo '</th>';
      //$content_data.='<string>'.$measure_name.'</string>';

      $up_placeholder_html.='<th>'.colSymbol($col_count).'.</th>';
      $col_count++;
    }

  echo '</tr>';
  //$content_data.='</row>';

  // LEFT dimensions headers
  echo '<tr>';
  //$content_data.='<row>';

    //left dimension names
    reset($dimension_array['left']);
    foreach($dimension_array['left'] as $left_dimension_name)
    {
      echo '<th>';
      echo $left_dimension_name;
      echo '</th>';
      //$content_data.='<string>'.$left_dimension_name.'</string>';
    }

    //up empty space
    echo $up_placeholder_html;

  echo '</tr>';
  //$content_data.='</row>';

  //echo '<pre>';
  //print_r($cube_index_array['left']);
  //echo '</pre>';

  
  $rowspan_array=array();
  reset($cube_index_array['left']);
  foreach($cube_index_array['left'] as $left_index => $left_index_values_array)
  {
    foreach($left_index_values_array as $left_dimension_name => $tmp)
    {
      $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]++;
      //echo $left_dimension_name.'==='.$left_index_values_array[$left_dimension_name].'<br />';
      break;
    }
  }
  
  
  // echo '<pre>';
  // print_r($rowspan_array);
  // echo '</pre>';
  
  // MEASURES
  $row_count=1;
  reset($cube_index_array['left']);
  foreach($cube_index_array['left'] as $left_index => $left_index_values_array)
  {
    echo '<tr>';
    $content_data.='<row>';

    //left specific headers
    $left_first_level=0; //span switch
    $full_drill_key='';
    reset($dimension_array['left']);
    foreach($dimension_array['left'] as $tmp_ii => $left_dimension_name)
    {
      if(!$left_first_level or $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]>0)
      {
        if($left_first_level)
          echo '<th rowspan="'.$rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]].'">';
        else
          echo '<th>';
          
        if($left_index_values_array[$left_dimension_name]!='&sum;' and ($tmp_ii!=count($dimension_array['left'])-1))
        {
          $full_drill_key.=$left_dimension_name.'='.$left_index_values_array[$left_dimension_name].' ';
          $drill_key=($full_drill_key);
          $drill_index_array['left'][$left_index]=$drill_key;
  
          if(!isset($drill_array[$drill_key]) or $drill_array[$drill_key]==0)
            echo '<a href="index.php?odb_script=chart&amp;odb_drillin2='.$drill_key.'&amp;'.$report_link.'">';
          else
            echo '<a href="index.php?odb_script=chart&amp;odb_drillout2='.$drill_key.'&amp;'.$report_link.'">';
  
          if(strlen($left_index_values_array[$left_dimension_name]))
            echo $left_index_values_array[$left_dimension_name];
          else
            echo '&mdash;';
          echo '</a>';
        }
        else
        {
          if(strlen($left_index_values_array[$left_dimension_name]))
            echo $left_index_values_array[$left_dimension_name];
          else
            echo '&mdash;';
        }
  
        echo '</a></th>';
        $content_data.='<string>'.$left_index_values_array[$left_dimension_name].'</string>';

        if($left_first_level)
          $rowspan_array[$left_dimension_name][$left_index_values_array[$left_dimension_name]]=0;
      }
      $left_first_level=0;
    }

    //left empty column - up dimension names placeholder
    echo '<th style="width:10px;">'.$row_count.'.</th>';

    reset($measure_array);
    reset($cube_index_array['up']);
    foreach($cube_index_array['up'] as $up_index => $up_index_values_array)
    foreach($measure_array as $measure_name => $measure_type)
    {
      echo '<td>';

        $show_mode=CFG_SHOW;
        $show_value=$cube_array[$left_index][$up_index][$measure_name];
        if($measure_type=='sum')
          $template='money';
        else
          $template='number';

        //bilding search filter
        $tmp_search=$search.' ';
        reset($up_index_values_array);
        foreach($up_index_values_array as $tmp_key => $tmp_val)
          if($tmp_val=='')
            $tmp_search.='-[$'.$tmp_key.'=] ';
          elseif($tmp_val!='&sum;')
            $tmp_search.='['.$tmp_key.'='.$tmp_val.'] ';//$ removed becouse of dates.YM/.YQ/.Y
        reset($left_index_values_array);
        foreach($left_index_values_array as $tmp_key => $tmp_val)
          if($tmp_val=='')
            $tmp_search.='-[$'.$tmp_key.'=] ';
          elseif($tmp_val!='&sum;')
            $tmp_search.='['.$tmp_key.'='.$tmp_val.'$] ';
        
        $tmp_search=str_replace('.Y','',$tmp_search);
        $tmp_search=str_replace('.YM','',$tmp_search);
        $tmp_search=str_replace('.YQ','',$tmp_search);
        echo '<a href="index.php?odb_search='.urlencode(trim($tmp_search)).'">';
        
        if(file_exists(cfg_data_path.'/config/script/fld_'.$template.'.txt'))
        {
          include(cfg_data_path.'/config/script/fld_'.$template.'.txt');
        }
        else
        {
          if(!file_exists(cfg_data_path.'/script/fld_'.$template.'.txt'))
            $template='';

          include(cfg_data_path.'/script/fld_'.$template.'.txt');
        }


        echo '</a>';
      echo '</td>';
      $content_data.='<number>'.$show_value.'</number>';
    }

    echo '</tr>';
    $content_data.='</row>';
    $row_count++;
  }

echo '</table>';
echo '</div>';


?>
Return current item: OpenBizMap