add a class to export the reports to CSV - modelled after the PDF class so the two will be easy to use together

update the checkin reports to export to CSV as well
This commit is contained in:
james 2005-02-23 14:29:28 +00:00
parent a2b274f4b9
commit 353835d402
4 changed files with 147 additions and 11 deletions

View File

@ -27,7 +27,7 @@
send_header("Administration");
echo "<a href=\"registration.php\">Participant Registration</a> <br />";
echo "<a href=\"reports.php\">Printable Reports</a> <br />";
echo "<a href=\"reports.php\">Print / Export Reports</a> <br />";
echo "<a href=\"committees.php\">Committee Management</a> <br />";
send_footer();

View File

@ -27,13 +27,21 @@
send_header("Administration - Reports");
echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a><br />";
echo "<br />";
echo "<table><tr><td>";
echo i18n("Day of Fair Registration/Checkin Forms").": ";
echo "</td>";
//lets split this up by age category,
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($catr=mysql_fetch_object($catq))
{
echo "<a href=\"reports_checkin.php?cat=$catr->id\">$catr->category</a> &nbsp; ";
echo "<td>";
echo "<a href=\"reports_checkin.php?type=pdf&cat=$catr->id\">$catr->category (PDF)</a> &nbsp; ";
echo "<br>";
echo "<a href=\"reports_checkin.php?type=csv&cat=$catr->id\">$catr->category (CSV)</a> &nbsp; ";
echo "</td>";
}
echo "</tr>";
echo "</table>";
send_footer();

View File

@ -25,18 +25,28 @@
require("../common.inc.php");
auth_required('admin');
require("../lpdf.php");
require("../lcsv.php");
$type=$_GET['type'];
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' AND id='".$_GET['cat']."'");
if($catr=mysql_fetch_object($catq))
{
if($type=="pdf")
{
$pdf=new lpdf( i18n($config['fairname']),
i18n("Checkin List")." - ".i18n($catr->category),
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
);
$pdf=new lpdf( i18n($config['fairname']),
i18n("Checkin List")." - ".i18n($catr->category),
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
);
$pdf->newPage();
$pdf->setFontSize(11);
$pdf->newPage();
$pdf->setFontSize(11);
}
else if($type=="csv")
{
$csv=new lcsv(i18n("Checkin List")." - ".i18n($catr->category));
}
$q=mysql_query("SELECT registrations.id AS reg_id,
registrations.num AS reg_num,
registrations.status,
@ -110,8 +120,15 @@ if($catr=mysql_fetch_object($catq))
}
$pdf->addTable($table);
$pdf->output();
if($type=="pdf")
{
$pdf->addTable($table);
$pdf->output();
}
else if($type=="csv")
{
$csv->addTable($table);
$csv->output();
}
}
?>

111
lcsv.php Normal file
View File

@ -0,0 +1,111 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
class lcsv
{
var $csvdata;
var $str_separator;
var $str_newline;
function separator()
{
return $this->str_separator;
}
function setSeparator($s)
{
$this->str_separator=$s;
}
function newline()
{
return $this->str_newline;
}
function setNewline($s)
{
$this->str_newline=$s;
}
function addTable($table)
{
if($table['header'])
{
$table_cols=count($table['header']);
for($c=0;$c<$table_cols;$c++)
{
$head=$table['header'][$c];
$this->csvdata.=$head;
if($c<$table_cols-1)
$this->csvdata.=$this->separator();
}
$this->csvdata.=$this->newline();
}
else
{
//is this right ?
$table_cols=count($table['data'][0]);
}
//now do the data in the table
if($table['data'])
{
foreach($table['data'] AS $dataline)
{
for($c=0;$c<$table_cols;$c++)
{
//if the data contains the separator, we need to puti the data inside ""'s
if(strstr($dataline[$c],$this->separator()))
$this->csvdata.="\"".$dataline[$c]."\"";
else
$this->csvdata.=$dataline[$c];
if($c<$table_cols-1)
$this->csvdata.=$this->separator();
}
$this->csvdata.=$this->newline();
}
}
}
function output()
{
if($this->csvdata)
{
//header("Content-type: application/csv");
header("Content-type: application/csv");
header("Content-disposition: inline; filename=sfiab_".$this->page_subtitle.".csv");
header("Content-length: ".strlen($this->csvdata));
echo $this->csvdata;
}
}
function lcsv($subtitle,$sep=",",$nl="\r\n")
{
$this->page_subtitle=$subtitle;
$this->setSeparator($sep);
$this->setNewline($nl);
}
}