<?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.
*/
//init
$sort_variable_name='';
$column_array=array();
$tab_array=array();
$max_pages=5;
$page_size=10;
$current_page=get('page');
$show_all_records=0;
if($current_page=='all')
$show_all_records=1;
if(!$current_page)
$current_page=1;
$sort1=get('sort1');
$sort2=get('sort2');
$sort_column=get('sort1');
$sort_desc=get('sort2');
$max_width=$session_array['max_width'];
if($max_width<400)
$max_width=1000;
$size_array['']=145;
$size_array['number']=88;
$size_array['money']=88;
$size_array['date']=66;
$size_array['description']=140;
$size_array['check']=105;
$size_array['speedometer']=310;
$size_array['S']=61;
$size_array['M']=140;
$size_array['L']=160;
$size_array['XL']=200;
$size_array['XXL']=250;
$marknew=get('marknew');
$grp_search=$search;
if(!strpos('_'.$search,'sysGroupBy='.$group_name))
$grp_search=$search.'%20sysGroupBy='.$group_name;
flush();
//looking for column names
//config
$variable_array2=load_config($group_name);
if(get('tab'))
$current_tab=get('tab');
elseif(get('mark')==$cnt_mark or $marknew==$cnt_mark)
$current_tab=get('tab');
elseif(sizeof($variable_array2)==3)
$current_tab='...';
else
$current_tab=$variable_array2['sysDetailTitle']['value'];
reset($variable_array2);
while(list($variable_name,$val)=each($variable_array2))
{
if(substr($variable_name,0,3)!='sys' and check_access($variable_name,1)!=0)
{
if($variable_array2[$variable_name]['show_cond']==0 and substr($variable_name,0,3)!='sys')
$variable_array2[$variable_name]['show_cond']=2;
if($variable_array2[$variable_name]['show_cond']>1 and $variable_array2[$variable_name]['show_cond']<5 and check_access($variable_name,1)) //$variable_array2[$variable_name]['hl'] and
{
$column_array[$variable_name]=$variable_array2[$variable_name];
}
if(strlen($variable_array2[$variable_name]['tab']))
$tab_array[$variable_array2[$variable_name]['tab']]++;
}
}
//records
$max_access=0;
for($ii=0;$ii<count($record_array);$ii++)
{
$tmp_access=check_access(read($record_array[$ii],'MyBag'));
if($tmp_access>$max_access)
$max_access=$tmp_access;
}
//checking distribution
reset($column_array);
foreach($column_array as $column_name => $tmp)
if($variable_array2[$column_name]['hl'] and read($record_array[0],$column_name))
$value_distribution_array[$column_name]=read($record_array[0],$column_name);
reset($value_distribution_array);
foreach($value_distribution_array as $important_column_name => $important_column_value)
{
reset($record_array);
foreach($record_array as $tmp_ii => $tmp_line)
{
if(read($tmp_line,$important_column_name)!= $important_column_value)
{
unset($value_distribution_array[$important_column_name]);
break;
}
}
}
$tmp_value_distribution_array=array();
reset($value_distribution_array);
foreach($value_distribution_array as $important_column_name => $important_column_value)
{
$tmp_value_distribution_array[$important_column_name]=$important_column_value;
if(count($tmp_value_distribution_array)>2)
break;
}
$value_distribution_array=$tmp_value_distribution_array;
echo '<div id="'.$group_name.'" class="main supergroup">';
echo '<h2>';
if($max_access>1)
{
echo('<input id="sw'.$cnt_mark.'" title="Select / unselect all" type="checkbox" onclick="on();check(this.checked,document.forms,\'sw'.$cnt_mark.'\',\'sw'.($cnt_mark+1).'\');" /> ');
}
myecho($variable_array2['sysListTitle']['value']);
echo '</h2>';
echo '<h3>';
reset($value_distribution_array);
foreach($value_distribution_array as $important_column_name => $important_column_value)
{
echo '<div style="margin-right:20px;">';
myecho($important_column_name);
echo ': ';
$show_mode=CFG_LOAD;
$template=$column_array[$important_column_name]['template'];
$show_value=$important_column_value;
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 $show_value.'</div>';
}
echo '</h3>';
//cutting to important columns only
$important_column_array=array();
$tmp_width=130;
reset($column_array);
while(list($variable_name,$tmp)=each($column_array))
if($tmp_width<$max_width and $variable_array2[$variable_name]['hl'] and !isset($value_distribution_array[$variable_name]))
{
//Important fields
//echo '=+='.$variable_name.'='.$tmp_width.'/'.$max_width;
$tmp_size=$size_array[$column_array[$variable_name]['size'].$column_array[$variable_name]['template']];
if(!$tmp_size)
$tmp_size=$size_array[''];
$tmp_width=$tmp_width+$tmp_size;
if($tmp_width<$max_width)
$important_column_array[$variable_name]=$column_array[$variable_name];
}
//echo $tmp_width.'=='.$max_width;
/*
reset($column_array);
while(list($variable_name,$tmp)=each($column_array))
if($tmp_width<$max_width and $variable_array2[$variable_name]['hl']) // and isset($value_distribution_array[$variable_name]))
{
$important_column_array[$variable_name]=$column_array[$variable_name];
$tmp_size=$size_array[$column_array[$variable_name]['size'].$column_array[$variable_name]['template']];
if(!$tmp_size)
$tmp_size=$size_array[''];
$tmp_width=$tmp_width+$tmp_size;
}
*/
/*
reset($column_array);
while(list($variable_name,$tmp)=each($column_array))
if($tmp_width<$max_width and !$variable_array2[$variable_name]['hl'] and $variable_array2[$variable_name]['tab']!='...')
{
//Other fields
//echo '=-='.$variable_name.'='.$tmp_width.'/'.$max_width;
$tmp_size=$size_array[$column_array[$variable_name]['size'].$column_array[$variable_name]['template']];
if(!$tmp_size)
$tmp_size=$size_array[''];
$tmp_width=$tmp_width+$tmp_size;
if($tmp_width<$max_width)
$important_column_array[$variable_name]=$column_array[$variable_name];
}
if($tmp_width+$size_array['']<$max_width)
{
$important_column_array['sysModInfo']['show_cond'] = 2;
}
*/
//cutting to important columns only
echo '<table>';
//~ echo '<caption>';
//~ myecho($variable_array2['sysListTitle']['value']);
//~ echo '</caption>';
//no th problem
$col_count=0;
echo '<tr class="header">';
if($max_access>1)
{
echo '<th class="noprint">';
$col_count++;
echo '</th>';
}
echo '<th class="noprint">';
$col_count++;
echo '</th>';
reset($important_column_array);
while(list($key,$val)=each($important_column_array))
{
echo '<th>';
//&odb_page=all
if($key==$sort_column)
if($sort_desc)
echo '<a href="index.php?odb_sort1='.urlencode($sort_column).'&odb_tab='.$current_tab.'&odb_search='.$grp_search.'"><img alt="Sorted a-z" src="images/down.gif" />';
else
echo '<a href="index.php?odb_tab='.$current_tab.'&odb_search='.$grp_search.'"><img alt="Sorted z-a" src="images/up.gif" />';
else
echo '<a href="index.php?odb_sort2=1&odb_sort1='.urlencode($key).'&odb_tab='.$current_tab.'&odb_search='.$grp_search.'">';
myecho($key);
echo '</a>';
$col_count++;
echo '</th>';
}
echo '<th class="noprint">';
$col_count++;
echo '</th>';
echo '</tr>';
echo '<tr>';
for($ii=0;$ii<$col_count;$ii++)
{
echo '<th class="column_numbers">';
echo colSymbol($ii).'.';
echo '</th>';
}
echo '</tr>';
//echo '<pre>';
//print_r($value_distribution_array);
//echo '</pre>';
//sorting
$record_array_index=array();
reset($record_array_index);
reset($record_array);
foreach($record_array as $tmp_ii => $tmp_line)
if($sort_column)
$record_array_index[$tmp_ii]=read($tmp_line,$sort_column);
else
$record_array_index[$tmp_ii]=$tmp_ii;
if($sort_column)
{
if($sort_desc)
arsort($record_array_index);
else
asort($record_array_index);
$tmp_record_array_index=array();
reset($record_array_index);
foreach($record_array_index as $tmp_ii => $tmp_value)
$tmp_record_array_index[]=$tmp_ii;
$record_array_index=$tmp_record_array_index;
$tmp_record_array_index=array();
}
//showing fields
if(count($record_array)>$page_size and count($record_array)<2*$page_size)
$page_size=count($record_array);
if(count($record_array)>$page_size)
$there_are_hidden_objects=1;
$first_record_ii=$page_size*($current_page-1);
$last_record_ii=$page_size*$current_page;
if($first_record_ii<0)
$first_record_ii=0;
if($last_record_ii>=count($record_array))
//if($max_access>1)
$last_record_ii=count($record_array);
//else
// $last_record_ii=count($record_array)-1;
if($show_all_records)
{
$first_record_ii=0;
//if($max_access>1)
$last_record_ii=count($record_array);
//else
// $last_record_ii=count($record_array)-1;
}
for($ii=$first_record_ii;$ii<$last_record_ii;$ii++)
{
//if($max_access>1 and $ii==$last_record_ii) //showing new record
// $variable_array='$sysId='.purename('new'.$group_name).'1$';
//else //showing normal record
//{
$variable_array=$record_array[$record_array_index[$ii]];
//}
$id=read($variable_array,'sysId');
//$display_mode=$standard_display_mode;
echo '<tr id="rec'.$id.'" onclick="lock(\''.$id.'\',\''.USERNAME.'\');" class="record'.($ii%2).'">';
if(read($variable_array,'Quality')=='Suspected')
echo('<th class="noprint" style="background-color:#ff0;"><img src="images/radioactive1.jpg" />');
else
echo('<th class="noprint">');
if(strpos('_'.$id,purename('new'.$group_name))==0)
echo ''.($ii+1).'.';
if(read($variable_array,'MyBag')=='deleted')
echo('<image src="'.cfg_images_path.'/deleted.jpg" title="'.myecho('Deleted','RETURN').'" alt="'.myecho('Deleted','RETURN').'" /> ');
echo('</th>');
if($max_access>1)
{
$show_name='odb_'.$id;
$tmp_access=check_access(read($variable_array,'MyBag'));
echo('<th class="noprint">');
if(strpos('_'.$id,purename('new'.$group_name))>0)
echo('');
elseif($tmp_access>1)
echo('<input class="checkme" onclick="on();" name="'.$show_name.'" type="checkbox"></input>');
else
echo('');
echo('</th>');
}
reset($important_column_array);
while(list($variable_name,$val)=each($important_column_array))
{
$tmp_access=check_access(read($variable_array,'MyBag'));
$template=trim($column_array[$variable_name]['template']);
$show_name='odb_'.purename($variable_name).'_'.$id;
$show_label=$variable_name;
$show_value=htmlspecialchars(read($variable_array,$variable_name));
$show_dictionary=$column_array[$variable_name]['dict'];
$show_size=$column_array[$variable_name]['size'];
if(strlen($show_size))
$show_size=' size'.$show_size;
$access=check_access($variable_name,$tmp_access); //field access
$show_mode_ext=CFG_LIST;
if(read($variable_array,'MyBag')=='deleted')
{
$show_mode=CFG_SHOW;
if($show_value)
echo '<td class="val_'.substr(purename($show_value),0,10).'">';
else
echo '<td>';
}
elseif($variable_name=='MyBag' and $access==2)
{
$show_mode=CFG_SHOW;
if($show_value)
echo '<td class="val_'.substr(purename($show_value),0,10).'">';
else
echo '<td>';
}
elseif($access==1)
{
$show_mode=CFG_SHOW;
if($show_value)
echo '<td class="val_'.substr(purename($show_value),0,10).'">';
else
echo '<td>';
}
elseif($column_array[$variable_name]['formula']=='' and $column_array[$variable_name]['show_cond']==2)
{
$show_mode=CFG_EDIT;
if(strlen($template) and strpos('_numbermoney',$template))
echo '<td style="text-align:right;">';
elseif($show_value)
echo '<td class="val_'.substr(purename($show_value),0,10).'">';
else
echo '<td>';
}
else
{
$show_mode=CFG_SHOW;
if(strlen($template) and strpos('_numbermoney',$template))
echo '<td style="text-align:right;">';
elseif($show_value)
echo '<td class="val_'.substr(purename($show_value),0,10).'">';
else
echo '<td>';
}
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 '</td>';
}
if(strpos('_'.$id,purename('new'.$group_name))>0)
{
echo '<td class="noprint">';
echo '</td>';
}
else
{
echo '<td class="noprint">';
echo(' <a href="index.php?odb_search='.$group_name.'%20sysId%3D'.$id.''.$context_params.'">');
myecho('More...');
echo '</a>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';
echo '<div class="more">';
myecho('Records: %1',$group_cnt_max);
$sort_string='';
if($sort1)
$sort_string.='odb_sort1='.urlencode($sort1).'&';
if($sort2)
$sort_string.='odb_sort2='.urlencode($sort2).'&';
$pages=ceil($group_cnt_max/$page_size);
if($pages>1)
{
echo ' | ';
myecho('Page');
echo ' ';
$first_page=$current_page-$max_pages;
if($first_page<1)
$first_page=1;
$last_page=$current_page+$max_pages;
if($last_page>$pages)
$last_page=$pages;
if($first_page<$current_page)
{
echo '<a href="index.php?'.$sort_string.'odb_page='.($current_page-1).'&odb_search='.$grp_search.'&odb_tab='.$current_tab.'">';
myecho('Previous');
echo '</a>';
echo ' ';
}
for($ii=$first_page;$ii<=$last_page;$ii++)
if($ii==$current_page)
echo $current_page.' ';
else
echo '<a href="index.php?'.$sort_string.'odb_page='.$ii.'&odb_tab='.$current_tab.'&odb_search='.$grp_search.'">'.$ii.'</a> ';
echo ' ';
if($last_page>$current_page)
{
echo '<a href="index.php?'.$sort_string.'odb_page='.($current_page+1).'&odb_tab='.$current_tab.'&odb_search='.$grp_search.'">';
myecho('Next');
echo '</a>';
}
echo ' ';
if($pages>1)
{
echo ' | ';
echo '<a href="index.php?'.$sort_string.'odb_page=all&odb_tab='.$current_tab.'&odb_search='.$grp_search.'">';
myecho('Show all');
echo '</a>';
}
}
echo ' | ';
echo '<a href="index.php?odb_script=search&odb_group='.$group_name.'&odb_search=---">';
myecho('Search');
echo '</a>';
echo '</div>';
echo '</div>';
?>