From 7143e9e01a77532e785b7b6c4e5fcb69b49024d3 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 16 Oct 2006 15:42:29 +0000 Subject: [PATCH] Delete old school mailing labels and replace with a mailing label generator that allows you to customize the size of the labels to suit _ANY_ label stock paper. Add to label generator the option to get judge mailing labels, and award sponsor mailing labels, and make it easy to add more mailing labels down the road (students? committee? etc?) Add two default label stocks (Avery 1"x4" and Avery 2"x4") --- admin/reports.php | 6 +- admin/reports_mailinglabels.php | 91 ++++++++++++ admin/reports_mailinglabels_generator.php | 160 ++++++++++++++++++++++ admin/reports_school_mailing_labels.php | 103 -------------- lpdf.php | 73 +++++++--- 5 files changed, 307 insertions(+), 126 deletions(-) create mode 100644 admin/reports_mailinglabels.php create mode 100644 admin/reports_mailinglabels_generator.php delete mode 100644 admin/reports_school_mailing_labels.php diff --git a/admin/reports.php b/admin/reports.php index c2e99aa..bea8b49 100644 --- a/admin/reports.php +++ b/admin/reports.php @@ -44,10 +44,10 @@ echo ""; echo ""; echo "
"; - echo i18n("School Mailing Address Labels").": "; - echo "PDF (Avery #05163 4\"x2\")   "; - echo "CSV   "; + echo i18n("Mailing Labels").": "; + echo "".i18n("Mailing Label Generator").""; + echo "
"; echo "
"; echo i18n("School Access Codes").": "; echo "PDF   "; diff --git a/admin/reports_mailinglabels.php b/admin/reports_mailinglabels.php new file mode 100644 index 0000000..d96f3d6 --- /dev/null +++ b/admin/reports_mailinglabels.php @@ -0,0 +1,91 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> + Mailing Labels"); +?> + + + +<< ".i18n("Back to Reports")."
"; + echo "
"; + + echo "
"; + echo ""; + echo ""; + echo ""; + + echo ""; + echo "
"; + + + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo "
Label Height:\"
Label Width:\"
Label Y-Space:\"
Label X-Space:\"
Font Size:pt
"; + echo ""; + + echo "
"; + + send_footer(); +?> diff --git a/admin/reports_mailinglabels_generator.php b/admin/reports_mailinglabels_generator.php new file mode 100644 index 0000000..39853cf --- /dev/null +++ b/admin/reports_mailinglabels_generator.php @@ -0,0 +1,160 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> +setPageStyle("labels"); + $rep->newPage(8.5,11); + $rep->setLabelDimensions($card_width,$card_height,$xspacer,$yspacer,$fontsize); + } + else if($type=="csv") { + $rep=new lcsv(i18n("$reportname Mailing Labels")); + } + + switch($report) + { + case "schools": + $q=mysql_query("SELECT + schools.school AS name, + IF(schools.sciencehead=\"\",\"Science Department Head\",schools.sciencehead) AS co, + schools.address AS address, + schools.city AS city, + schools.province_code AS province, + schools.postalcode AS postalcode + FROM + schools + WHERE + year='{$config['FAIRYEAR']}' + ORDER BY + school + "); + break; + + case "sponsors": + + $q=mysql_query("SELECT + award_sponsors.organization AS name, + award_sponsors.address AS address, + award_sponsors.city AS city, + award_sponsors.province_code AS province, + award_sponsors.postalcode AS postalcode, + IF(award_contacts.salutation=\"\", + CONCAT(award_contacts.firstname,' ',award_contacts.lastname), + CONCAT(award_contacts.salutation,' ',award_contacts.firstname,' ',award_contacts.lastname)) + AS co + FROM + award_sponsors, + award_contacts + WHERE + award_sponsors.confirmed='yes' + AND award_contacts.award_sponsors_id=award_sponsors.id + ORDER BY + organization + "); + break; + + case "judges": + $q=mysql_query("SELECT + CONCAT(judges.firstname,' ',judges.lastname) AS name, + IF(judges.address2=\"\", + judges.address, + CONCAT(judges.address,' ',judges.address2) + ) AS address, + '' AS co, + judges.city AS city, + judges.province AS province, + judges.postalcode AS postalcode + FROM + judges, + judges_years + WHERE + judges_years.judges_id=judges.id + AND judges_years.year='{$config['FAIRYEAR']}' + ORDER BY + lastname,firstname + "); + break; + + } + + + if($type=="csv") + { + $table=array(); + $table['header'] = array( + i18n("Name"), + i18n("C/O"), + i18n("Address"), + i18n("City"), + i18n("Province"), + i18n("Postal Code")); + } + + while($r=mysql_fetch_object($q)) + { + if($type=="pdf") + { + $rep->newLabel(); + $rep->mailingLabel($r->name,$r->co,$r->address,$r->city,$r->province,$r->postalcode); + } + else if($type=="csv") + { + $table['data'][]=array($r->name,$r->co,$r->address,$r->city,$r->province,$r->postalcode); + } + } + + if($type=="csv") + $rep->addTable($table); + + $rep->output(); + +} +?> diff --git a/admin/reports_school_mailing_labels.php b/admin/reports_school_mailing_labels.php deleted file mode 100644 index 83af774..0000000 --- a/admin/reports_school_mailing_labels.php +++ /dev/null @@ -1,103 +0,0 @@ - - Copyright (C) 2005 James Grant - - 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. -*/ -?> -setPageStyle("labels"); - $rep->newPage(8.5,11); - $rep->setLabelDimensions($card_width,$card_height,$xspacer,$yspacer); - $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); - $rep->setFontSize(10); - 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(); - -?> diff --git a/lpdf.php b/lpdf.php index e542d3f..7bf4f59 100644 --- a/lpdf.php +++ b/lpdf.php @@ -265,10 +265,42 @@ class lpdf */ } - function addLabelText($Y,$text,$align="center") + function mailingLabel($to,$co,$address,$city,$province,$postalcode) { + $this->setFontSize($this->currentFontSize); + //mailing addresses are all uppercase, left aligned + //see http://www.canadapost.ca/tools/pg/standards/cps1-05-e.asp + $tmpY=0.1; + $fontsize=pdf_get_value($this->pdf,"fontsize",0); - $lineheight=ceil($fontsize*1.3); + $lineheight=ceil($fontsize*1.2); + + //this is to make sure if the name of the school goes onto two lines we handle it properly + $l=$this->addLabelText($tmpY,strtoupper(trim($to))); + $tmpY+=($lineheight/72)*$l; + if($co) + { + $l=$this->addLabelText($tmpY,trim(strtoupper("C/O $co"))); + $tmpY+=($lineheight/72)*$l; + } + if($address[strlen($address)-1]==".") $address=substr($address,0,-1); + $l=$this->addLabelText($tmpY,strtoupper(trim($address))); + $tmpY+=($lineheight/72)*$l; + + if(strlen($postalcode)==6) $pc=substr($postalcode,0,3)." ".substr($postalcode,3,3); else $pc=$postalcode; + + $this->addLabelText($tmpY,trim(strtoupper("$city $province $pc"))); + + } + + function addLabelText($Y,$text,$align="left") + { + $this->setFontSize($this->currentFontSize); + $fontsize=pdf_get_value($this->pdf,"fontsize",0); + $lineheight=ceil($fontsize*1.35); + $linemove=ceil($fontsize*1.2); + +// echo "fontsize=$fontsize lineheight=$lineheight"; $textstr=$text; @@ -276,6 +308,7 @@ class lpdf $nr=0; $prevnr=-1; + $numlines=0; do { $len=strlen($textstr); @@ -285,28 +318,29 @@ class lpdf while($textstr[0]=="\n") { $textstr=substr($textstr,1); - $texty-=$lineheight/72; + $texty-=$linemove/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); + $texty-=$linemove/72; - if($nr==$prevnr) + $nr=pdf_show_boxed($this->pdf,$textstr, $this->loc($this->label_current_xpos+0.20),$this->loc($texty),$this->loc($this->label_width-0.3),$lineheight,$align,null); + if($nr==$len) { - echo "in addLabelText - breaking because nr==prevnr ($nr==$prevnr) "; - break; + $texty+=$linemove/72; + //okay so it really doesnt fit. so lets just keep shortening it until it does! + $textstr=substr($textstr,0,-1); + } + else + { + $textstr=substr($textstr,-$nr); + $numlines++; } - $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 "
doing: substr($textstr,-$nr)
"; - $textstr=substr($textstr,-$nr); -// echo "nr=$nr"; } while($nr>0); + + return $numlines; } function newNametag() @@ -436,8 +470,6 @@ class lpdf "center", null); */ - pdf_setfont($this->pdf,$this->normalfont,10); - } @@ -666,20 +698,21 @@ class lpdf } - function setLabelDimensions($width,$height,$xspacer=0.125,$yspacer=0.125) + function setLabelDimensions($width,$height,$xspacer=0.125,$yspacer=0.125,$fontsize=10) { $this->label_width=$width; $this->label_height=$height; $this->label_xspacer=$xspacer; $this->label_yspacer=$yspacer; - $this->labels_per_row=floor($this->page_width/$width); - $this->labels_per_column=floor($this->page_height/$height); + $this->labels_per_row=floor($this->page_width/($width+$xspacer)); + $this->labels_per_column=floor($this->page_height/($height+$yspacer)); $this->labels_per_page=$this->labels_per_row * $this->labels_per_column; $this->labels_start_xpos=($this->page_width-$this->labels_per_row*$width - $this->label_xspacer*($this->labels_per_row-1))/2; $this->labels_start_ypos=$this->page_height - ($this->page_height-$this->labels_per_column*$height-$this->label_yspacer*($this->labels_per_column-1))/2; + $this->setFontSize($fontsize); }