Add report generation support for mailing labels

Add School Mailing Address Labels for Avery #05163 (4"x2" or 10.2 x 5.1 cm)
This commit is contained in:
james 2006-09-11 18:05:35 +00:00
parent 6ab58a1b8e
commit a8d31a3603
3 changed files with 246 additions and 1 deletions

View File

@ -43,6 +43,11 @@ while($catr=mysql_fetch_object($catq))
echo "</tr>";
echo "</table>";
echo "<br />";
echo i18n("School Mailing Address Labels").": ";
echo "<a href=\"reports_school_mailing_labels.php?type=pdf\">PDF (Avery #05163 4\"x2\")</a> &nbsp; ";
echo "<a href=\"reports_school_mailing_labels.php?type=csv\">CSV</a> &nbsp; ";
echo "<br />";
echo i18n("Student Emergency Contact Names/Numbers").": ";
echo "<a href=\"reports_emergencycontact.php?type=pdf\">PDF</a> &nbsp; ";

View File

@ -0,0 +1,100 @@
<?
/*
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.
*/
?>
<?
require("../common.inc.php");
auth_required('admin');
require("../lpdf.php");
require("../lcsv.php");
if($type=="pdf")
{
$card_width=4;
$card_height=2;
$rep=new lpdf( i18n($config['fairname']),
"School Mailing Labels",
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
);
$rep->setPageStyle("labels");
$rep->newPage(8.5,11);
$rep->setLabelDimensions($card_width,$card_height);
$rep->setFontSize(11);
}
else if($type=="csv") {
$rep=new lcsv(i18n("School Mailing Labels"));
}
$q=mysql_query("SELECT
*
FROM
schools
WHERE
year='{$config['FAIRYEAR']}'
ORDER BY
school
");
if($type=="csv")
{
$table=array();
$table['header'] = array(
i18n("School Name"),
i18n("Address"),
i18n("City"),
i18n("Province"),
i18n("Postal Code"),
i18n("Science Head"));
}
while($r=mysql_fetch_object($q))
{
if($type=="pdf")
{
$rep->newLabel();
$rep->setFontSize(16);
$rep->addLabelText(0.05,$r->school);
$rep->setFontSize(14);
$rep->addLabelText(0.50,$r->address);
$rep->addLabelText(0.75,"$r->city, $r->province_code");
$rep->addLabelText(1.0,$r->postalcode);
if($r->sciencehead)
$rep->addLabelText(1.25,"c/o $r->sciencehead OR Science Head");
else
$rep->addLabelText(1.25,"c/o Science Department Head");
}
else if($type=="csv")
{
$table['data'][]=array($r->school, $r->address, $r->city, $r->province_code, $r->postalcode, $r->sciencehead);
}
}
if($type=="csv")
{
$rep->addTable($table);
}
$rep->output();
?>

142
lpdf.php
View File

@ -52,6 +52,20 @@ class lpdf
var $current_nametag_col_index=0;
var $current_nametag_row_index=1;
//all of these are overwritten by setLabelDimensions(width,height);
var $label_width=4;
var $label_height=2;
var $labels_per_row=2;
var $labels_per_column=5;
var $labels_per_page=10;
var $labels_start_xpos;
var $labels_start_ypos;
var $current_label_index=0;
var $current_label_col_index=0;
var $current_label_row_index=1;
var $currentFontSize=12;
function loc($inch)
@ -249,6 +263,50 @@ class lpdf
*/
}
function addLabelText($Y,$text,$align="center")
{
$fontsize=pdf_get_value($this->pdf,"fontsize",0);
$lineheight=ceil($fontsize*1.3);
$textstr=$text;
$texty=$this->label_current_ypos-$Y;
$nr=0;
$prevnr=-1;
do
{
$len=strlen($textstr);
$nl=false;
//now lets handle a newline at the beginning, just rip it off and move the yloc ourself
while($textstr[0]=="\n")
{
$textstr=substr($textstr,1);
$texty-=$lineheight/72;
$nl=true;
}
if(!$nl)
$texty-=$lineheight/72;
$nr=pdf_show_boxed($this->pdf,$textstr, $this->loc($this->label_current_xpos),$this->loc($texty),$this->loc($this->label_width),$lineheight,$align,null);
if($nr==$prevnr)
{
echo "in addLabelText - breaking because nr==prevnr ($nr==$prevnr) ";
break;
}
$prevnr=$nr;
// printf("x=%f y=%f w=%f h=%f",$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$lineheight);
// echo "$nr didnt fit";
// echo "<br>doing: substr($textstr,-$nr) <br>";
$textstr=substr($textstr,-$nr);
// echo "nr=$nr";
} while($nr>0);
}
function newNametag()
{
if($this->current_nametag_index==$this->nametags_per_page)
@ -309,6 +367,75 @@ class lpdf
pdf_setfont($this->pdf,$this->normalfont,10);
}
function newLabel()
{
if($this->current_label_index==$this->labels_per_page)
{
$this->newPage();
$this->current_label_index=1;
$this->current_label_col_index=0;
$this->current_label_row_index=1;
}
else
{
$this->current_label_index++;
}
if($this->current_label_col_index==$this->labels_per_row)
{
$this->current_label_col_index=1;
$this->current_label_row_index++;
}
else
{
$this->current_label_col_index++;
}
$this->label_current_ypos=$this->labels_start_ypos-(($this->current_label_row_index-1)*$this->label_height)-$this->label_height;
$this->label_current_xpos=$this->labels_start_xpos+(($this->current_label_col_index-1)*$this->label_width);
/*
pdf_rect($this->pdf,
$this->loc($this->label_current_xpos),
$this->loc($this->label_current_ypos),
$this->loc($this->label_width),
$this->loc($this->label_height));
pdf_stroke($this->pdf);
*/
$this->label_current_ypos+=$this->label_height-0.25;
//only put the logo on the label if we actually have the logo
/*
if($this->logoimage)
{
//now place the logo image in the top-left-ish
pdf_place_image($this->pdf,$this->logoimage,
$this->loc($this->label_current_xpos+0.05),
$this->loc($this->label_current_ypos-0.50),0.2);
}
*/
/*
$height['title']=0.50;
$this->label_current_ypos-=$height['title'];
pdf_setfont($this->pdf,$this->headerfont,14);
pdf_show_boxed($this->pdf,$this->page_header,
$this->loc($this->label_current_xpos+0.65),
$this->loc($this->label_current_ypos),
$this->loc($this->label_width-0.70),
$this->loc($height['title']),
"center",
null);
*/
pdf_setfont($this->pdf,$this->normalfont,10);
}
function addTextX($text,$xpos)
@ -516,7 +643,7 @@ class lpdf
}
//page styles: "normal" "nametags" "empty"
//page styles: "normal" "nametags" "empty" "labels"
function setPageStyle($style="normal")
{
$this->page_style=$style;
@ -536,6 +663,19 @@ class lpdf
}
function setLabelDimensions($width,$height)
{
$this->label_width=$width;
$this->label_height=$height;
$this->labels_per_row=floor($this->page_width/$width);
$this->labels_per_column=floor($this->page_height/$height);
$this->labels_per_page=$this->labels_per_row * $this->labels_per_column;
$this->labels_start_xpos=($this->page_width-$this->labels_per_row*$width)/2;
$this->labels_start_ypos=$this->page_height-($this->page_height-$this->labels_per_column*$height)/2;
}
function output()
{