Whew! LPDF Nametag support & nametags for students... that took 5 hours!

This commit is contained in:
james 2005-04-22 17:37:19 +00:00
parent 1d3c7294e4
commit fe1217ba6b
3 changed files with 292 additions and 3 deletions

View File

@ -44,8 +44,12 @@ echo "</tr>";
echo "</table>";
echo "<br />";
echo i18n("Project Table Labels").": ";
echo "<a href=\"reports_projects_tablelabels.php?type=pdf\">PDF</a> &nbsp; ";
echo "<br />";
echo i18n("Student Nametags").": ";
echo "<a href=\"reports_nametags_students.php\">PDF</a> &nbsp; ";
echo "<br />";

View File

@ -0,0 +1,128 @@
<?
/*
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");
$card_width=4;
$card_height=3;
$rep=new lpdf( i18n($config['fairname']),
"Student Nametags",
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
);
$rep->setPageStyle("nametags");
$rep->newPage(8.5,11);
$rep->setNametagDimensions($card_width,$card_height);
$rep->setFontSize(11);
$q=mysql_query("SELECT
registrations.id AS reg_id,
registrations.num AS reg_num,
projects.id,
projects.title,
projects.projectnumber,
projects.projectdivisions_id,
projects.projectcategories_id,
projectdivisions.division,
projectcategories.category,
students.firstname,
students.lastname
FROM
registrations
LEFT JOIN projectdivisions ON projectdivisions.id=projects.projectdivisions_id
LEFT JOIN projectcategories ON projectcategories.id=projects.projectcategories_id
LEFT JOIN projects on projects.registrations_id=registrations.id
LEFT JOIN students ON students.registrations_id=registrations.id
WHERE
projects.year='".$config['FAIRYEAR']."'
AND registrations.status='complete'
ORDER BY
projects.projectnumber
");
// echo mysql_error();
//
/*
this is 4x3" on my screen, so i'll use it to figure
out what it should look like in a semi-proporational
layout.
***********************************************************
* *
* -------- *
* | | [ NAME OF THE SCIENCE FAIR GOES HERE ] *
* | logo | *
* | | [ NAME OF THE FAIR IN FRENCH GOES HERE ] *
* | | *
* -------- *
* *
* *
* [ ] *
* [ THE STUDENTS NAME IN BIG LETTERS ] *
* [ ] *
* *
* *
* [ ] *
* [ PROJECT TITLE GOES HERE ALSO FAIRLY BIG ] *
* [ ] *
* *
* *
* [ CATEGORY / DIVISION ] *
* *
* *
* PROJECT NUMBER *
* *
* *
***********************************************************
on the page we have tagnum layout like this:
1 2
3 4
5 6
*/
while($r=mysql_fetch_object($q))
{
$rep->newNametag();
$rep->setFontSize(18);
$rep->addNametagText(0.0,"$r->firstname $r->lastname");
$rep->setFontSize(14);
$rep->addNametagText(0.75,"$r->title");
$rep->addNametagText(1.5,$r->category." - ".$r->division);
$rep->setFontSize(16);
$rep->addNametagText(1.75,"# $r->projectnumber");
}
$rep->output();
?>

163
lpdf.php
View File

@ -31,12 +31,26 @@ class lpdf
var $pagenumber;
var $logoimage;
var $page_style="normal";
var $page_margin=0.75;
//these are defaults, they get overwritten with the first call to newPage(width,height)
var $page_width=8.5;
var $page_height=11;
// var $content_width=$page_width-($page_margin*2);
//all of these are overwritten by setNametagDimensions(width,height);
var $nametag_width=4;
var $nametag_height=3;
var $nametags_per_row=2;
var $nametags_per_column=3;
var $nametags_per_page=6;
var $nametags_start_xpos;
var $nametags_start_ypos;
var $current_nametag_index=0;
var $current_nametag_col_index=0;
var $current_nametag_row_index=1;
function loc($inch)
{
@ -96,12 +110,14 @@ class lpdf
if($this->pagenumber>0)
pdf_end_page($this->pdf);
$this->pagenumber++;
//Letter size (8.5 x 11) is 612,792
pdf_begin_page($this->pdf,$this->loc($this->page_width),$this->loc($this->page_height));
pdf_setlinewidth($this->pdf,0.3);
$this->addHeaderAndFooterToPage();
if($this->page_style=="normal")
$this->addHeaderAndFooterToPage();
}
function vspace($space)
@ -163,6 +179,126 @@ class lpdf
// pdf_rect($this->pdf,$this->loc(0.75),$this->loc($this->yloc),$this->loc(7),$height);
}
function addNametagText($Y,$text,$align="center")
{
$fontsize=pdf_get_value($this->pdf,"fontsize",0);
$lineheight=ceil($fontsize*1.3);
$textstr=$text;
$texty=$this->nametag_current_ypos-$Y;
$nr=0;
$prevnr=-1;
do
{
//echo "textstr=$textstr";
$len=strlen($textstr);
// echo "(lh:$lineheight nr:$nr len:$len)".$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->nametag_current_xpos),$this->loc($texty),$this->loc($this->nametag_width),$lineheight,$align,null);
if($nr==$prevnr)
{
echo "in addNametagText - 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);
/*
$this->nametag_current_ypos-=$lineheight/72;
pdf_show_boxed($this->pdf,$text,
$this->loc($this->nametag_current_xpos),
$this->loc($this->nametag_current_ypos),
$this->loc($this->nametag_width),
$lineheight,
"center",
null);
*/
}
function newNametag()
{
if($this->current_nametag_index==$this->nametags_per_page)
{
$this->newPage();
$this->current_nametag_index=1;
$this->current_nametag_col_index=0;
$this->current_nametag_row_index=1;
}
else
{
$this->current_nametag_index++;
}
if($this->current_nametag_col_index==$this->nametags_per_row)
{
$this->current_nametag_col_index=1;
$this->current_nametag_row_index++;
}
else
{
$this->current_nametag_col_index++;
}
$this->nametag_current_ypos=$this->nametags_start_ypos-(($this->current_nametag_row_index-1)*$this->nametag_height)-$this->nametag_height;
$this->nametag_current_xpos=$this->nametags_start_xpos+(($this->current_nametag_col_index-1)*$this->nametag_width);
pdf_rect($this->pdf,
$this->loc($this->nametag_current_xpos),
$this->loc($this->nametag_current_ypos),
$this->loc($this->nametag_width),
$this->loc($this->nametag_height));
pdf_stroke($this->pdf);
$this->nametag_current_ypos+=$this->nametag_height-0.25;
//only put the logo on the nametag 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->nametag_current_xpos+0.05),
$this->loc($this->nametag_current_ypos-0.50),0.2);
}
$height['title']=0.25;
$this->nametag_current_ypos-=$height['title'];
pdf_setfont($this->pdf,$this->headerfont,14);
pdf_show_boxed($this->pdf,$this->page_header,
$this->loc($this->nametag_current_xpos+0.50),
$this->loc($this->nametag_current_ypos),
$this->loc($this->nametag_width-0.50),
$this->loc($height['title']),
"center",
null);
$this->nametag_current_ypos-=$height['title'];
pdf_setfont($this->pdf,$this->normalfont,10);
}
function addTextX($text,$xpos)
@ -354,6 +490,26 @@ class lpdf
}
//page styles: "normal" "nametags" "empty"
function setPageStyle($style="normal")
{
$this->page_style=$style;
}
function setNametagDimensions($width,$height)
{
$this->nametag_width=$width;
$this->nametag_height=$height;
$this->nametags_per_row=floor($this->page_width/$width);
$this->nametags_per_column=floor($this->page_height/$height);
$this->nametags_per_page=$this->nametags_per_row * $this->nametags_per_column;
$this->nametags_start_xpos=($this->page_width-$this->nametags_per_row*$width)/2;
$this->nametags_start_ypos=$this->page_height-($this->page_height-$this->nametags_per_column*$height)/2;
}
function output()
{
@ -404,3 +560,4 @@ class lpdf
// $this->addHeaderAndFooterToPage();
}
}
?>