forked from science-ation/science-ation
factor out PDF code into a separate PDF class
implement new PDF class in reports_checkin
This commit is contained in:
parent
afdc22a2b2
commit
0e10fcda45
@ -4,6 +4,7 @@
|
||||
echo error(i18n("Note: this section will normally be password protected. It is left open for now for debugging and testing purposes"));
|
||||
|
||||
echo "<a href=\"registration.php\">Participant Registration</a> <br />";
|
||||
echo "<a href=\"reports.php\">Printable Reports</a> <br />";
|
||||
|
||||
send_footer();
|
||||
?>
|
||||
|
148
admin/reports_checkin.php
Normal file
148
admin/reports_checkin.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?
|
||||
require("../common.inc.php");
|
||||
require("../lpdf.php");
|
||||
|
||||
$pdf=new lpdf(i18n($config['fairname']),i18n("Checkin List"));
|
||||
|
||||
|
||||
//lets split this up by age category, then sort each one by division... so first, just get the age categories
|
||||
|
||||
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
|
||||
while($catr=mysql_fetch_object($catq))
|
||||
{
|
||||
$q=mysql_query("SELECT registrations.id AS reg_id,
|
||||
registrations.num AS reg_num,
|
||||
registrations.status,
|
||||
projects.title,
|
||||
projects.projectdivisions_id
|
||||
FROM
|
||||
registrations
|
||||
left outer join projects on projects.registrations_id=registrations.id
|
||||
WHERE
|
||||
registrations.year='".$config['FAIRYEAR']."'
|
||||
AND ( registrations.status='complete' OR registrations.status='paymentpending' )
|
||||
AND projects.projectcategories_id='$catr->id'
|
||||
ORDER BY
|
||||
registrations.status DESC,
|
||||
projects.title
|
||||
");
|
||||
echo mysql_error();
|
||||
|
||||
$table=array();
|
||||
|
||||
$table['header']=array(i18n("Paid?"),i18n("Proj #"),i18n("Project Title"),i18n("Student(s)"),i18n("Div"));
|
||||
$table['widths']=array(0.5, 0.6, 3.5, 2.4, 0.5);
|
||||
$table['dataalign']=array("center","left","left","left","center");
|
||||
while($r=mysql_fetch_object($q))
|
||||
{
|
||||
switch($r->status)
|
||||
{
|
||||
case "paymentpending": $status_text="No"; break;
|
||||
case "complete": $status_text=""; break;
|
||||
}
|
||||
$status_text=i18n($status_text);
|
||||
|
||||
$divq=mysql_query("SELECT division FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
|
||||
$divr=mysql_fetch_object($divq);
|
||||
|
||||
$sq=mysql_query("SELECT students.firstname,
|
||||
students.lastname,
|
||||
schools.school
|
||||
FROM
|
||||
students,schools
|
||||
WHERE
|
||||
students.registrations_id='$r->reg_id'
|
||||
AND
|
||||
students.schools_id=schools.id
|
||||
");
|
||||
echo mysql_error();
|
||||
|
||||
$schools="";
|
||||
$students="";
|
||||
while($studentinfo=mysql_fetch_object($sq))
|
||||
{
|
||||
$students.="$studentinfo->firstname $studentinfo->lastname\n";
|
||||
$schools.="$studentinfo->school\n";
|
||||
}
|
||||
|
||||
$table['data'][]=array($status_text,$r->proj_num,$r->title,$students,i18n($divr->division_short));
|
||||
}
|
||||
|
||||
$pdf->addTable($table);
|
||||
$pdf->newPage();
|
||||
}
|
||||
/*
|
||||
|
||||
echo "<table class=\"summarytable\">";
|
||||
echo "<tr>";
|
||||
echo "<th>".i18n("Status")."</th>";
|
||||
echo "<th>".i18n("Reg Num")."</th>";
|
||||
echo "<th>".i18n("Project Title")."</th>";
|
||||
echo "<th>".i18n("Age Category")."</th>";
|
||||
echo "<th>".i18n("Division")."</th>";
|
||||
echo "<th>".i18n("School(s)")."</th>";
|
||||
echo "<th>".i18n("Student(s)")."</th>";
|
||||
echo "</tr>";
|
||||
$stats_totalprojects=0;
|
||||
$stats_totalstudents=0;
|
||||
$stats_divisions=array();
|
||||
$stats_categories=array();
|
||||
|
||||
while($r=mysql_fetch_object($q))
|
||||
{
|
||||
$stats_totalprojects++;
|
||||
$stats_divisions[$r->projectdivisions_id]++;
|
||||
$stats_categories[$r->projectcategories_id]++;
|
||||
|
||||
echo "<tr>";
|
||||
echo "<td>$status_text</td>";
|
||||
echo "<td>$r->reg_num</td>";
|
||||
echo "<td>$r->title</td>";
|
||||
|
||||
|
||||
//now get thh category and division
|
||||
$catq=mysql_query("SELECT category FROM projectcategories WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectcategories_id."'");
|
||||
$catr=mysql_fetch_object($catq);
|
||||
$divq=mysql_query("SELECT division FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
|
||||
$divr=mysql_fetch_object($divq);
|
||||
|
||||
|
||||
echo "<td>".i18n("$catr->category")."</td>";
|
||||
|
||||
echo "<td>".i18n("$divr->division")."</td>";
|
||||
|
||||
$sq=mysql_query("SELECT students.firstname,
|
||||
students.lastname,
|
||||
schools.school
|
||||
FROM
|
||||
students,schools
|
||||
WHERE
|
||||
students.registrations_id='$r->reg_id'
|
||||
AND
|
||||
students.schools_id=schools.id
|
||||
");
|
||||
echo mysql_error();
|
||||
|
||||
$studnum=1;
|
||||
$schools="";
|
||||
$students="";
|
||||
while($studentinfo=mysql_fetch_object($sq))
|
||||
{
|
||||
$students.="$studentinfo->firstname $studentinfo->lastname <br />";
|
||||
$schools.="$studentinfo->school <br />";
|
||||
$stats_totalstudents++;
|
||||
}
|
||||
echo "<td>$schools</td>";
|
||||
echo "<td>$students</td>";
|
||||
|
||||
echo "</tr>";
|
||||
}
|
||||
echo "</table>\n";
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
$pdf->output();
|
||||
?>
|
185
lpdf.php
Normal file
185
lpdf.php
Normal file
@ -0,0 +1,185 @@
|
||||
<?
|
||||
class lpdf
|
||||
{
|
||||
var $pdf;
|
||||
var $yloc=10.25;
|
||||
var $page_header;
|
||||
var $page_subheader;
|
||||
var $pagenumber;
|
||||
|
||||
function loc($inch)
|
||||
{
|
||||
return $inch*72;
|
||||
}
|
||||
|
||||
|
||||
function addHeaderAndFooterToPage()
|
||||
{
|
||||
//The title of the fair
|
||||
$this->yloc=10.25;
|
||||
$height['title']=0.25;
|
||||
$height['subtitle']=0.22;
|
||||
|
||||
pdf_setfont($this->pdf,$this->headerfont,18);
|
||||
pdf_show_boxed($this->pdf,$this->page_header,$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$this->loc($height['title']),"center",null);
|
||||
$this->yloc-=$height['title'];
|
||||
|
||||
pdf_setfont($this->pdf,$this->headerfont,14);
|
||||
pdf_show_boxed($this->pdf,$this->page_subheader,$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$this->loc($height['subtitle']),"center",null);
|
||||
$this->yloc-=$height['subtitle'];
|
||||
|
||||
//header line
|
||||
pdf_moveto($this->pdf,$this->loc(0.5),$this->loc($this->yloc));
|
||||
pdf_lineto($this->pdf,$this->loc(8),$this->loc($this->yloc));
|
||||
pdf_stroke($this->pdf);
|
||||
$this->yloc-=0.5;
|
||||
|
||||
//now put a nice little footer at the bottom
|
||||
$footertext=date("Y-m-d h:ia")." - ".$this->page_header." - ".$this->page_subheader;
|
||||
|
||||
$footerwidth=pdf_stringwidth($this->pdf,$footertext,$this->normalfont,9);
|
||||
pdf_setfont($this->pdf,$this->normalfont,9);
|
||||
pdf_show_xy($this->pdf,$footertext,$this->loc(4.25)-$footerwidth/2,$this->loc(0.5));
|
||||
|
||||
//footer line
|
||||
pdf_moveto($this->pdf,$this->loc(0.5),$this->loc(0.7));
|
||||
pdf_lineto($this->pdf,$this->loc(8.0),$this->loc(0.7));
|
||||
pdf_stroke($this->pdf);
|
||||
}
|
||||
|
||||
function newPage()
|
||||
{
|
||||
$this->pagenumber++;
|
||||
pdf_end_page($this->pdf);
|
||||
//Letter size (8.5 x 11) is 612,792
|
||||
pdf_begin_page($this->pdf,612,792);
|
||||
$this->addHeaderAndFooterToPage();
|
||||
}
|
||||
|
||||
function addTable($table)
|
||||
{
|
||||
$height['tableheader']=0.2;
|
||||
$height['tabledata']=0.18;
|
||||
$xpos_of_table=0.5;
|
||||
|
||||
$top_of_table=$this->yloc;
|
||||
|
||||
$table_width=array_sum($table['widths']);
|
||||
$table_cols=count($table['header']);
|
||||
|
||||
//draw the top line of the table (above the table header)
|
||||
pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc+$height['tableheader']));
|
||||
pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc+$height['tableheader']));
|
||||
pdf_stroke($this->pdf);
|
||||
|
||||
//draw the top line of the table (below the table header)
|
||||
pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc));
|
||||
pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc));
|
||||
pdf_stroke($this->pdf);
|
||||
|
||||
//do the header first
|
||||
if($table['header'])
|
||||
{
|
||||
pdf_setfont($this->pdf,$this->headerfont,12);
|
||||
|
||||
$xpos=$xpos_of_table;
|
||||
|
||||
for($c=0;$c<$table_cols;$c++)
|
||||
{
|
||||
$head=$table['header'][$c];
|
||||
$width=$table['widths'][$c];
|
||||
|
||||
pdf_show_boxed($this->pdf,$head,$this->loc($xpos),$this->loc($this->yloc),$this->loc($width),$this->loc($height['tableheader']),"center",null);
|
||||
$xpos+=$width;
|
||||
}
|
||||
|
||||
$this->yloc-=$height['tableheader'];
|
||||
}
|
||||
|
||||
//now do the data in the table
|
||||
if($table['data'])
|
||||
{
|
||||
pdf_setfont($this->pdf,$this->normalfont,10);
|
||||
|
||||
|
||||
foreach($table['data'] AS $dataline)
|
||||
{
|
||||
$xpos=$xpos_of_table;
|
||||
for($c=0;$c<$table_cols;$c++)
|
||||
{
|
||||
$width=$table['widths'][$c];
|
||||
|
||||
pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos),$this->loc($this->yloc),$this->loc($width),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
|
||||
$xpos+=$width;
|
||||
}
|
||||
|
||||
//draw the line below the table data)
|
||||
pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc));
|
||||
pdf_lineto($this->pdf,$this->loc($xpos_of_table+$table_width),$this->loc($this->yloc));
|
||||
pdf_stroke($this->pdf);
|
||||
|
||||
$this->yloc-=$height['tabledata'];
|
||||
}
|
||||
}
|
||||
|
||||
//now draw all the vertical lines
|
||||
$xpos=$xpos_of_table;
|
||||
for($c=0;$c<$table_cols;$c++)
|
||||
{
|
||||
$width=$table['widths'][$c];
|
||||
//draw the line below the table data)
|
||||
pdf_moveto($this->pdf,$this->loc($xpos),$this->loc($top_of_table+$height['tableheader']));
|
||||
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']));
|
||||
pdf_stroke($this->pdf);
|
||||
$xpos+=$width;
|
||||
}
|
||||
|
||||
//and the final line on the right side of the table:
|
||||
pdf_moveto($this->pdf,$this->loc($xpos),$this->loc($top_of_table+$height['tableheader']));
|
||||
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']));
|
||||
pdf_stroke($this->pdf);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function output()
|
||||
{
|
||||
pdf_end_page($this->pdf);
|
||||
pdf_close($this->pdf);
|
||||
$pdfdata=pdf_get_buffer($this->pdf);
|
||||
header("Content-type: application/pdf");
|
||||
header("Content-disposition: inline; filename=sfiab_".$this->page_subtitle.".pdf");
|
||||
header("Content-length: ".strlen($pdfdata));
|
||||
echo $pdfdata;
|
||||
}
|
||||
|
||||
function lpdf($header,$subheader)
|
||||
{
|
||||
$this->pdf=pdf_new();
|
||||
pdf_open_file($this->pdf,null);
|
||||
|
||||
//open up the first page
|
||||
//Letter size (8.5 x 11) is 612,792
|
||||
pdf_begin_page($this->pdf,612,792);
|
||||
// pdf_set_parameter($this->pdf, "FontOutline", "Arial=/home/sfiab/www.sfiab.ca/sfiab/arial.ttf");
|
||||
//$arial=pdf_findfont($this->pdf,"Arial","host",1);
|
||||
$this->normalfont=pdf_findfont($this->pdf,"Times-Roman","host",0);
|
||||
$this->headerfont=pdf_findfont($this->pdf,"Times-Bold","host",0);
|
||||
|
||||
pdf_set_info($this->pdf,"Author","SFIAB");
|
||||
pdf_set_info($this->pdf,"Creator","SFIAB");
|
||||
pdf_set_info($this->pdf,"Title","SFIAB - $subheader");
|
||||
pdf_set_info($this->pdf,"Subject","$subheader");
|
||||
|
||||
pdf_setlinewidth($this->pdf,0.3);
|
||||
|
||||
$this->page_header=$header;
|
||||
$this->page_subheader=$subheader;
|
||||
|
||||
//add the stuff to the first page
|
||||
$this->addHeaderAndFooterToPage();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user