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")
This commit is contained in:
james 2006-10-16 15:42:29 +00:00
parent 1a2b3d7faf
commit 7143e9e01a
5 changed files with 307 additions and 126 deletions

View File

@ -44,10 +44,10 @@ 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 i18n("Mailing Labels").": ";
echo "<a href=\"reports_mailinglabels.php\">".i18n("Mailing Label Generator")."</a>";
echo "<br />";
echo "<br />";
echo i18n("School Access Codes").": ";
echo "<a href=\"reports_schoolaccesscodes.php?type=pdf\">PDF</a> &nbsp; ";

View File

@ -0,0 +1,91 @@
<?
/*
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');
send_header("Administration - Reports > Mailing Labels");
?>
<script type="text/javascript">
function stockChange()
{
var val=document.forms.mailinglabels.stock.options[document.forms.mailinglabels.stock.selectedIndex].value;
var v=val.split(":");
document.forms.mailinglabels.height.value=v[1];
document.forms.mailinglabels.width.value=v[2];
document.forms.mailinglabels.yspacer.value=v[3];
document.forms.mailinglabels.xspacer.value=v[4];
document.forms.mailinglabels.fontsize.value=v[5];
document.forms.mailinglabels.type.value=v[6];
}
function reportChange()
{
var val=document.forms.mailinglabels.reportselect.options[document.forms.mailinglabels.reportselect.selectedIndex].value;
var v=val.split(":");
document.forms.mailinglabels.report.value=v[0];
document.forms.mailinglabels.reportname.value=v[1];
}
</script>
<?
echo "<a href=\"reports.php\">&lt;&lt; ".i18n("Back to Reports")."</a><br />";
echo "<br />";
echo "<form method=\"get\" name=\"mailinglabels\" action=\"reports_mailinglabels_generator.php\">";
echo "<input type=\"hidden\" name=\"type\" value=\"pdf\">";
echo "<input type=\"hidden\" name=\"report\" value=\"pdf\">";
echo "<input type=\"hidden\" name=\"reportname\" value=\"pdf\">";
echo "<select name=\"reportselect\" onchange=\"reportChange()\">";
echo "<option value=\"\">".i18n("Choose which labels")."</option>\n";
echo "<option value=\"sponsors:Award Sponsors\">".i18n("Award Sponsors")."</option>\n";
echo "<option value=\"judges:Judges\">".i18n("Judges")."</option>\n";
echo "<option value=\"schools:Schools\">".i18n("Schools")."</option>\n";
echo "</select>";
echo "<br />";
echo "<select name=\"stock\" onchange=\"stockChange()\">";
echo "<option value=\"Custom::::::\">".i18n("Choose label stock")."</option>\n";
echo "<option value=\"Avery #05163:2:4:0.125:0.125:12:pdf\">Avery #05163 2\"x4\"</option>\n";
echo "<option value=\"Avery #05261:1:4:0.08:0.08:10:pdf\">Avery #05261 1\"x4\"</option>\n";
echo "<option value=\"Custom::::::pdf\">Custom</option>\n";
echo "<option value=\"CSV::::::csv\">CSV (Plain Text)</option>\n";
echo "</select>";
echo "<table>";
echo "<tr><td>Label Height:</td><td><input size=\"5\" type=\"text\" name=\"height\" id=\"height\">\"</td></tr>";
echo "<tr><td>Label Width:</td><td><input size=\"5\" type=\"text\" name=\"width\" id=\"width\">\"</td></tr>";
echo "<tr><td>Label Y-Space:</td><td><input size=\"5\" type=\"text\" name=\"yspacer\" id=\"yspacer\">\"</td></tr>";
echo "<tr><td>Label X-Space:</td><td><input size=\"5\" type=\"text\" name=\"xspacer\" id=\"xspacer\">\"</td></tr>";
echo "<tr><td>Font Size:</td><td><input size=\"5\" type=\"text\" name=\"fontsize\" id=\"fontsize\">pt</td></tr>";
echo "</table>";
echo "<input type=\"submit\" value=\"Generate Mailing Labels\">";
echo "</form>";
send_footer();
?>

View File

@ -0,0 +1,160 @@
<?
/*
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($_GET['report']) $report=$_GET['report'];
if($_GET['reportname']) $reportname=$_GET['reportname']; else $reportname=$_GET['report'];
if($report)
{
if($type=="pdf")
{
$card_width=4.00;
$card_height=2.00;
$xspacer=0.125;
$yspacer=0.125;
$fontsize=10;
if($_GET['width']) $card_width=$_GET['width'];
if($_GET['height']) $card_height=$_GET['height'];
if($_GET['xspacer']) $xspacer=$_GET['xspacer'];
if($_GET['yspacer']) $yspacer=$_GET['yspacer'];
if($_GET['fontsize']) $fontsize=$_GET['fontsize'];
$rep=new lpdf( i18n($config['fairname']),
"$reportname 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,$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();
}
?>

View File

@ -1,103 +0,0 @@
<?
/*
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.00;
$card_height=2.00;
$xspacer=0.125;
$yspacer=0.125;
$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,$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();
?>

View File

@ -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);
}
$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>";
else
{
$textstr=substr($textstr,-$nr);
// echo "nr=$nr";
$numlines++;
}
$prevnr=$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);
}