add a script to populate the db with some fake data

update divisions to accept 'shortform'
some updates to PDF
This commit is contained in:
james 2005-01-13 23:59:22 +00:00
parent 0e10fcda45
commit 2c3f6e745f
4 changed files with 107 additions and 106 deletions

View File

@ -2,14 +2,12 @@
require("../common.inc.php");
require("../lpdf.php");
$pdf=new lpdf(i18n($config['fairname']),i18n("Checkin List"));
//lets split this up by age category, then sort each one by division... so first, just get the age categories
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($catr=mysql_fetch_object($catq))
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' AND id='".$_GET['cat']."'");
if($catr=mysql_fetch_object($catq))
{
$pdf=new lpdf(i18n($config['fairname']),i18n("Checkin List")." - ".i18n($catr->category));
$pdf->newPage();
$q=mysql_query("SELECT registrations.id AS reg_id,
registrations.num AS reg_num,
registrations.status,
@ -23,7 +21,6 @@ while($catr=mysql_fetch_object($catq))
AND ( registrations.status='complete' OR registrations.status='paymentpending' )
AND projects.projectcategories_id='$catr->id'
ORDER BY
registrations.status DESC,
projects.title
");
echo mysql_error();
@ -42,107 +39,31 @@ while($catr=mysql_fetch_object($catq))
}
$status_text=i18n($status_text);
$divq=mysql_query("SELECT division FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
$divq=mysql_query("SELECT division,division_shortform FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
$divr=mysql_fetch_object($divq);
$sq=mysql_query("SELECT students.firstname,
students.lastname,
schools.school
students.lastname
FROM
students,schools
students
WHERE
students.registrations_id='$r->reg_id'
AND
students.schools_id=schools.id
");
echo mysql_error();
$schools="";
$students="";
$studnum=0;
while($studentinfo=mysql_fetch_object($sq))
{
$students.="$studentinfo->firstname $studentinfo->lastname\n";
$schools.="$studentinfo->school\n";
if($studnum>0) $students.=", ";
$students.="$studentinfo->firstname $studentinfo->lastname";
$studnum++;
}
$table['data'][]=array($status_text,$r->proj_num,$r->title,$students,i18n($divr->division_short));
$table['data'][]=array($status_text,$r->proj_num,$r->title,$students,i18n($divr->division_shortform));
}
$pdf->addTable($table);
$pdf->newPage();
}
/*
echo "<table class=\"summarytable\">";
echo "<tr>";
echo "<th>".i18n("Status")."</th>";
echo "<th>".i18n("Reg Num")."</th>";
echo "<th>".i18n("Project Title")."</th>";
echo "<th>".i18n("Age Category")."</th>";
echo "<th>".i18n("Division")."</th>";
echo "<th>".i18n("School(s)")."</th>";
echo "<th>".i18n("Student(s)")."</th>";
echo "</tr>";
$stats_totalprojects=0;
$stats_totalstudents=0;
$stats_divisions=array();
$stats_categories=array();
while($r=mysql_fetch_object($q))
{
$stats_totalprojects++;
$stats_divisions[$r->projectdivisions_id]++;
$stats_categories[$r->projectcategories_id]++;
echo "<tr>";
echo "<td>$status_text</td>";
echo "<td>$r->reg_num</td>";
echo "<td>$r->title</td>";
//now get thh category and division
$catq=mysql_query("SELECT category FROM projectcategories WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectcategories_id."'");
$catr=mysql_fetch_object($catq);
$divq=mysql_query("SELECT division FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' AND id='".$r->projectdivisions_id."'");
$divr=mysql_fetch_object($divq);
echo "<td>".i18n("$catr->category")."</td>";
echo "<td>".i18n("$divr->division")."</td>";
$sq=mysql_query("SELECT students.firstname,
students.lastname,
schools.school
FROM
students,schools
WHERE
students.registrations_id='$r->reg_id'
AND
students.schools_id=schools.id
");
echo mysql_error();
$studnum=1;
$schools="";
$students="";
while($studentinfo=mysql_fetch_object($sq))
{
$students.="$studentinfo->firstname $studentinfo->lastname <br />";
$schools.="$studentinfo->school <br />";
$stats_totalstudents++;
}
echo "<td>$schools</td>";
echo "<td>$students</td>";
echo "</tr>";
}
echo "</table>\n";
*/
$pdf->output();
}
?>

View File

@ -16,7 +16,8 @@
{
mysql_query("UPDATE projectdivisions SET ".
"id='".$_POST['id']."', ".
"division='".mysql_escape_string(stripslashes($_POST['division']))."' ".
"division='".mysql_escape_string(stripslashes($_POST['division']))."', ".
"division_shortform='".mysql_escape_string(stripslashes($_POST['division_shortform']))."' ".
"WHERE id='".$_POST['saveid']."'");
echo happy(i18n("Division successfully saved"));
}
@ -38,9 +39,10 @@
}
else
{
mysql_query("INSERT INTO projectdivisions (id,division,year) VALUES ( ".
mysql_query("INSERT INTO projectdivisions (id,division,division_shortform,year) VALUES ( ".
"'".$_POST['id']."', ".
"'".mysql_escape_string(stripslashes($_POST['division']))."', ".
"'".mysql_escape_string(stripslashes($_POST['division_shortform']))."', ".
"'".$config['FAIRYEAR']."') ");
echo happy(i18n("Division successfully added"));
}
@ -68,6 +70,7 @@
echo "<tr>";
echo "<th>".i18n("Division ID")."</th>\n";
echo "<th>".i18n("Division Name")."</th>\n";
echo "<th>".i18n("Short Form")."</th>\n";
echo "<th>".i18n("Actions")."</th>\n";
echo "</tr>";
@ -86,9 +89,10 @@
$buttontext="Add";
}
echo "<tr>";
echo " <td><input type=\"text\" size=\"3\" name=\"id\" value=\"$divisionr->id\"></td>";
echo " <td><input type=\"text\" size=\"40\" name=\"division\" value=\"$divisionr->division\"></td>";
echo " <td><input type=\"submit\" value=\"".i18n($buttontext)."\"></td>";
echo " <td><input type=\"text\" size=\"3\" name=\"id\" value=\"$divisionr->id\" /></td>";
echo " <td><input type=\"text\" size=\"40\" name=\"division\" value=\"$divisionr->division\" /></td>";
echo " <td align=\"center\"><input type=\"text\" size=\"5\" name=\"division_shortform\" value=\"$divisionr->division_shortform\" /></td>";
echo " <td><input type=\"submit\" value=\"".i18n($buttontext)."\" /></td>";
echo "</tr>";
}
else
@ -99,6 +103,7 @@
echo "<tr>";
echo " <td>$r->id</td>";
echo " <td>$r->division</td>";
echo " <td align=\"center\">$r->division_shortform</td>";
echo " <td>";
echo "<a title=\"Edit\" href=\"".$_SERVER['PHP_SELF']."?action=edit&edit=$r->id\"><img src=\"".$config['SFIABDIRECTORY']."/images/16/edit.".$config['icon_extension']."\" border=0></a>";
echo "&nbsp; &nbsp;";

View File

@ -49,10 +49,13 @@ class lpdf
function newPage()
{
$this->pagenumber++;
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,612,792);
pdf_setlinewidth($this->pdf,0.3);
$this->addHeaderAndFooterToPage();
}
@ -66,6 +69,7 @@ class lpdf
$table_width=array_sum($table['widths']);
$table_cols=count($table['header']);
$table_padding=0.03;
//draw the top line of the table (above the table header)
pdf_moveto($this->pdf,$this->loc($xpos_of_table),$this->loc($this->yloc+$height['tableheader']));
@ -109,7 +113,7 @@ class lpdf
{
$width=$table['widths'][$c];
pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos),$this->loc($this->yloc),$this->loc($width),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
pdf_show_boxed($this->pdf,$dataline[$c],$this->loc($xpos+$table_padding),$this->loc($this->yloc),$this->loc($width-2*$table_padding),$this->loc($height['tabledata']),$table['dataalign'][$c],null);
$xpos+=$width;
}
@ -129,14 +133,14 @@ class lpdf
$width=$table['widths'][$c];
//draw the line below the table data)
pdf_moveto($this->pdf,$this->loc($xpos),$this->loc($top_of_table+$height['tableheader']));
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']));
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']-.02));
pdf_stroke($this->pdf);
$xpos+=$width;
}
//and the final line on the right side of the table:
pdf_moveto($this->pdf,$this->loc($xpos),$this->loc($top_of_table+$height['tableheader']));
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']));
pdf_lineto($this->pdf,$this->loc($xpos),$this->loc($this->yloc+$height['tableheader']-.02));
pdf_stroke($this->pdf);
}
@ -160,7 +164,7 @@ class lpdf
//open up the first page
//Letter size (8.5 x 11) is 612,792
pdf_begin_page($this->pdf,612,792);
// pdf_begin_page($this->pdf,612,792);
// pdf_set_parameter($this->pdf, "FontOutline", "Arial=/home/sfiab/www.sfiab.ca/sfiab/arial.ttf");
//$arial=pdf_findfont($this->pdf,"Arial","host",1);
$this->normalfont=pdf_findfont($this->pdf,"Times-Roman","host",0);
@ -171,13 +175,12 @@ class lpdf
pdf_set_info($this->pdf,"Title","SFIAB - $subheader");
pdf_set_info($this->pdf,"Subject","$subheader");
pdf_setlinewidth($this->pdf,0.3);
$this->page_header=$header;
$this->page_subheader=$subheader;
$this->pagenumber=0;
//add the stuff to the first page
$this->addHeaderAndFooterToPage();
// $this->addHeaderAndFooterToPage();
}

72
scripts/populate_fake.php Normal file
View File

@ -0,0 +1,72 @@
<?
include "../common.inc.php";
$numprojects=150;
function getrand($ar)
{
return $ar[rand(0,count($ar)-1)];
}
//the following work as one in x where x is the number below
$prob_dual=3;
$prob_unpaid=10;
$firstnames=array("James","Bob","Ali","Erin","Julia","Dave","Steve","Bryan","Jane","Elizabeth","Norm","Sue","Eric","Terry","Arthur","Angel","Allison","Jeremy","Jacqueline","Derek","Kristen","Greg","Cheryl","Debbie","Heather","Donald","Linda","George","Patrica","Carmel","Dawn","Scott","Brad","Bruce","Paul","Guillaume");
$lastnames=array("Grant","Browning","Mehdi","Borque","Temple","Culhane","Sargent","Sing","Belanger","Desjardin","Jones","Smith","Brown","Johnson","Williams","White","Thompson","Baker");
$domains=array("lightbox.org","microsoft.com","yahoo.com","msn.com","gmail.com","reach.net","slicer.ca","cwsf.ca"."sfiab.ca");
$nouns=array("age","animal","arm","baby","ball","bat","bear","boat","camp","car","child","circle","city","cotton","design","dog","dress","duck","ear","egg","enemy");
$starters=array("effects of","study of","analysis of");
$joiners=array("on","combined with","broken apart by","burned with","attacked by","left alone with");
for($x=0;$x<$numprojects;$x++)
{
$id=0;
$regnum=rand(100000,999999);
$email=strtolower(getrand($firstnames)."@".getrand($domains));
$pd=rand(1,$prob_unpaid);
if($pd==1) $status='paymentpending'; else $status='complete';
$q=mysql_query("INSERT INTO registrations (num,email,start,status,year) VALUES ('$regnum','$email',NOW(),'$status',2005)");
if($id=mysql_insert_id())
{
$peeps=rand(1,$prob_dual);
if($peeps==1) $num=2; else $num=1;
$gradenum=rand(1,10);
if($gradenum<6) { $grade=rand(7,8); $cat=1;}
else if($gradenum<8) { $grade=rand(9,10); $cat=2; }
else if($gradenum<10) { $grade=rand(11,12); $cat=3; }
$schools_id=rand(1,2);
for($a=1;$a<=$num;$a++)
{
$sexnum=rand(1,3);
if($sexnum<3) $sex="male"; else $sex="female";
mysql_query("INSERT INTO students (registrations_id,firstname,lastname,sex,grade,year,schools_id) VALUES ('$id','".getrand($firstnames)."','".getrand($lastnames)."','$sex','$grade',2005,'$schools_id')");
}
$div=rand(1,6);
$title=ucwords(getrand($starters)." ".getrand($nouns)." ".getrand($joiners)." ".getrand($nouns));
$req_enum=rand(1,4);
if($req_enum==1) $req_e="yes"; else $req_e="no";
$req_tnum=rand(1,30);
if($req_tnum==1) $req_t="no"; else $req_t="yes";
mysql_query("INSERT INTO projects (registrations_id,projectcategories_id,projectdivisions_id,title,year,req_electricity,req_table) VALUES ('$id','$cat','$div','$title',2005,'$req_e','$req_t')");
}
}
?>