<?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.
*/
$content='';
$group_array=array();
$csv_filename=purename(cfg_skin_name);
$addsearch_count=0;
$tmp_search=$search;
while(strlen($tmp_search))
{
$show_result_array=search($tmp_search);
$show_result_array_sizeof=count($show_result_array);
mylog('CSV EXPORT '.$tmp_search);
if($show_result_array_sizeof>0)
{
$sizeof=count($show_result_array);
for($ii=0;$ii<$sizeof;$ii++)
{
$variable_array=$show_result_array[$ii];
if(check_access(read($variable_array,'MyBag')))
{
$group_name=strtolower(read($variable_array,'sysGroupBy'));
$group_array[$group_name][]=$variable_array;
if(strpos($csv_filename,purename($group_name))==0)
$csv_filename.='-'.purename($group_name);
}
}
}
$addsearch_count++;
$tmp_search=get('adsearch'.$addsearch_count);
}
reset($group_array);
while(list($group_name,$show_result_array)=each($group_array))
{
$fields=get($group_name.'_fields');
if($fields)
{
$tmp_variable_array2=explode(',',$fields);
reset($tmp_variable_array2);
while(list($tmp,$val)=each($tmp_variable_array2))
$variable_array2[$val]='1';
}
else
$variable_array2=load_config($group_name);
//$content.='""'.CRLF;
//$content.='"","'.$variable_array2['sysListTitle']['value'].'"'.CRLF;
$comma='';
$content.='"'.$variable_array2['sysListTitle']['value'].'",';
reset($variable_array2);
while(list($variable_name,$tmp)=each($variable_array2))
{
if(substr($variable_name,0,3)!='sys')
{
$content.=$comma.'"'.$variable_name.'"';
$comma=',';
}
}
$content.=$comma.'"sysGroupBy"';
$content.=$comma.'"sysId"';
$content.=''.CRLF;
$cnt=1;
reset($show_result_array);
while(list($tmp,$line)=each($show_result_array))
{
$content.='"'.$cnt.'"';
$content.=',';
//echo $content; $content='';
$comma='';
reset($variable_array2);
while(list($variable_name,$tmp)=each($variable_array2))
{
if(substr($variable_name,0,3)!='sys')
{
$template=$variable_array2[$variable_name]['template'];
$show_value=read($line,$variable_name);
$show_mode=CFG_LOAD;
if(!file_exists(cfg_data_path.'/script/fld_'.$template.'.txt'))
$template='';
if($template!='')
include(cfg_data_path.'/script/fld_'.$template.'.txt');
$content_data=$show_value;
//$content_data=htmlspecialchars($show_value,ENT_QUOTES,'UTF-8');
$content_data=str_replace('&','&',$content_data);
$content_data=str_replace('"','""',$content_data);
$content_data=str_replace(''',"'",$content_data);
$content_data=str_replace('<','<',$content_data);
$content_data=str_replace('>','>',$content_data);
$content.=$comma.'"'.$content_data.'"';
$comma=',';
//echo $content; $content='';
}
}
$content.=$comma.'"'.read($line,'sysGroupBy').'"';
$content.=$comma.'"'.read($line,'sysId').'"';
$content.=''.CRLF;
$cnt++;
//echo $content; $content='';
}
}
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachement; filename="'.$csv_filename.'.csv"'); //attachement couses too much dialog boxes /inline
header('Content-Length: '.strlen($content));
echo $content; $content='';
?>