From a8d31a3603d396eb232c0672ccabae3c2f3cde09 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 11 Sep 2006 18:05:35 +0000 Subject: [PATCH] Add report generation support for mailing labels Add School Mailing Address Labels for Avery #05163 (4"x2" or 10.2 x 5.1 cm) --- admin/reports.php | 5 + admin/reports_school_mailing_labels.php | 100 +++++++++++++++++ lpdf.php | 142 +++++++++++++++++++++++- 3 files changed, 246 insertions(+), 1 deletion(-) create mode 100644 admin/reports_school_mailing_labels.php diff --git a/admin/reports.php b/admin/reports.php index 4ec6a2b..f9861da 100644 --- a/admin/reports.php +++ b/admin/reports.php @@ -43,6 +43,11 @@ while($catr=mysql_fetch_object($catq)) echo ""; echo ""; + echo "
"; + echo i18n("School Mailing Address Labels").": "; + echo "PDF (Avery #05163 4\"x2\")   "; + echo "CSV   "; + echo "
"; echo i18n("Student Emergency Contact Names/Numbers").": "; echo "PDF   "; diff --git a/admin/reports_school_mailing_labels.php b/admin/reports_school_mailing_labels.php new file mode 100644 index 0000000..a4ef1f2 --- /dev/null +++ b/admin/reports_school_mailing_labels.php @@ -0,0 +1,100 @@ + + 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); + $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(); + +?> diff --git a/lpdf.php b/lpdf.php index 2093e71..c528550 100644 --- a/lpdf.php +++ b/lpdf.php @@ -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 "
doing: substr($textstr,-$nr)
"; + $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() {