forked from science-ation/science-ation
- Update the generator, it can do labels and nametags now, almost ready to
deprecate all the mailing list/nametag/table label/etc. files.
This commit is contained in:
parent
3f737b3270
commit
2f23e31a40
@ -30,7 +30,7 @@
|
||||
|
||||
$options = array();
|
||||
$options['type'] = array( 'desc' => 'Report Format',
|
||||
'values' => array('pdf'=>'PDF', 'csv'=>'CSV')
|
||||
'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label')
|
||||
);
|
||||
$options['group_new_page'] = array( 'desc' => 'Start each new grouping on a new page',
|
||||
'values' => array('no'=>'No', 'yes'=>'Yes')
|
||||
@ -38,6 +38,16 @@
|
||||
$options['allow_multiline'] = array( 'desc' => 'Allow table rows to span multiple lines',
|
||||
'values' => array('no'=>'No', 'yes'=>'Yes')
|
||||
);
|
||||
|
||||
$options['label_box'] = array( 'desc' => 'Draw a box around each label',
|
||||
'values' => array('no'=>'No', 'yes'=>'Yes')
|
||||
);
|
||||
$options['label_fairname'] = array( 'desc' => 'Print the fair name at the top of each label',
|
||||
'values' => array('no'=>'No', 'yes'=>'Yes')
|
||||
);
|
||||
$options['label_logo'] = array( 'desc' => 'Print the fair logo at the top of each label',
|
||||
'values' => array('no'=>'No', 'yes'=>'Yes')
|
||||
);
|
||||
|
||||
|
||||
|
||||
@ -58,7 +68,7 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
|
||||
/* FIXME: put these in a databse */
|
||||
$stock = array();
|
||||
$stock['5964'] = array('name' => 'Avery 5964, G&T 99763',
|
||||
'page_width' => 8 + 1/2,
|
||||
'page_width' => 8.5,
|
||||
'page_height' => 11,
|
||||
'label_width' => 4,
|
||||
'x_spacing' => 3/16,
|
||||
@ -67,76 +77,30 @@ LRP 180 99765 5967 4 1 3/4 x 1/2 80 */
|
||||
'y_spacing' => 0,
|
||||
'rows' => 3,
|
||||
);
|
||||
|
||||
$labels[] = array( 'name' => 'GVRSF Project Labels',
|
||||
'options' => array('fair_header' => true),
|
||||
'items' => array(
|
||||
array( 'field' => 'pn',
|
||||
'x' => 'center',
|
||||
'y' => 'center',
|
||||
'h' => 50 ),
|
||||
array( 'field' => 'bothnames',
|
||||
'x' => 'center',
|
||||
'y' => 80,
|
||||
'h' => 10 ),
|
||||
array( 'field' => 'categorydivision',
|
||||
'x' => 'center',
|
||||
'y' => 90,
|
||||
'h' => 10 ),
|
||||
),
|
||||
);
|
||||
$stock['nametag'] = array('name' => '4"x3" cards',
|
||||
'page_width' => 8.5,
|
||||
'page_height' => 11,
|
||||
'label_width' => 4,
|
||||
'x_spacing' => 0,
|
||||
'cols' => 2,
|
||||
'label_height' => 3,
|
||||
'y_spacing' => 0,
|
||||
'rows' => 3,
|
||||
);
|
||||
|
||||
|
||||
/* Add more types to the report format */
|
||||
$options['stock'] = array('desc' => "Paper Type",
|
||||
'values' => array('letter' => 'Letter 8.5 x 11') );
|
||||
foreach($stock as $n=>$v) {
|
||||
$options['type']['values'][$n] = $v['name'];
|
||||
$options['stock']['values'][$n] = $v['name'];
|
||||
}
|
||||
|
||||
|
||||
$allow_options = array_keys($options);
|
||||
|
||||
|
||||
function report_load_field($report, $type)
|
||||
{
|
||||
global $allow_options, $report_students_fields, $report_judges_fields, $report_awards_fields;
|
||||
|
||||
$allow_fields = array();
|
||||
|
||||
switch($report['type']) {
|
||||
case 'student': $allow_fields = array_keys($report_students_fields); break;
|
||||
case 'judge': $allow_fields = array_keys($report_judges_fields); break;
|
||||
case 'award': $allow_fields = array_keys($report_awards_fields); break;
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
$q = mysql_query("SELECT * FROM reports_items
|
||||
WHERE reports_id='{$report['id']}'
|
||||
AND type='$type'
|
||||
ORDER BY `order`");
|
||||
print(mysql_error());
|
||||
|
||||
if(mysql_num_rows($q) == 0) return $ret;
|
||||
|
||||
while($a = mysql_fetch_assoc($q)) {
|
||||
$f = $a['field'];
|
||||
if($type == 'option') {
|
||||
if(!in_array($f, $allow_options)) {
|
||||
print("Type[$type] Field[$f] not allowed.\n");
|
||||
exit;
|
||||
}
|
||||
$ret[$f] = $a['value'];
|
||||
} else {
|
||||
if(!in_array($f, $allow_fields)) {
|
||||
print("Type[$type] Field[$f] not allowed.\n");
|
||||
exit;
|
||||
}
|
||||
$ret[] = $a['field'];
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function report_save_field($report, $type)
|
||||
function report_save_field($report, $type, $loc)
|
||||
{
|
||||
global $allow_options;
|
||||
global $report_students_fields, $report_judges_fields, $report_awards_fields;
|
||||
@ -166,10 +130,14 @@ foreach($stock as $n=>$v) {
|
||||
$val = '';
|
||||
}
|
||||
if($q != '') $q .= ',';
|
||||
$q .= "({$report['id']}, '$field', '$type', '$val', $x)";
|
||||
$q .= "({$report['id']}, '$field', '$type', '$val', $x,
|
||||
'{$loc[$field]['xp']}', '{$loc[$field]['yp']}', '{$loc[$field]['wp']}',
|
||||
'{$loc[$field]['hp']}', '{$loc[$field]['lhp']}','{$loc[$field]['face']}',
|
||||
'{$loc[$field]['align']}')";
|
||||
$x++;
|
||||
}
|
||||
mysql_query("INSERT INTO reports_items(`reports_id`,`field`,`type`,`value`,`order`)
|
||||
mysql_query("INSERT INTO reports_items(`reports_id`,`field`,`type`,`value`,`order`,
|
||||
`xp`, `yp`, `wp`, `hp`, `lhp`, `face`, `align`)
|
||||
VALUES $q;");
|
||||
echo mysql_error();
|
||||
|
||||
@ -177,6 +145,9 @@ foreach($stock as $n=>$v) {
|
||||
|
||||
function report_load($report_id)
|
||||
{
|
||||
global $allow_options, $report_students_fields, $report_judges_fields;
|
||||
global $report_committees_fields, $report_awards_fields;
|
||||
|
||||
$report = array();
|
||||
|
||||
$q = mysql_query("SELECT * FROM reports WHERE id='$report_id'");
|
||||
@ -187,13 +158,49 @@ foreach($stock as $n=>$v) {
|
||||
$report['creator'] = $r['creator'];
|
||||
$report['type'] = $r['type'];
|
||||
|
||||
/* Get the data */
|
||||
$report['col'] = report_load_field($report, 'col');
|
||||
$report['group'] = report_load_field($report, 'group');
|
||||
$report['sort'] = report_load_field($report, 'sort');
|
||||
$report['distinct'] = report_load_field($report, 'distinct');
|
||||
$report['option'] = report_load_field($report, 'option');
|
||||
$allow_fields = array();
|
||||
switch($report['type']) {
|
||||
case 'student': $allow_fields = array_keys($report_students_fields); break;
|
||||
case 'judge': $allow_fields = array_keys($report_judges_fields); break;
|
||||
case 'award': $allow_fields = array_keys($report_awards_fields); break;
|
||||
case 'committee':$allow_fields = array_keys($report_committees_fields); break;
|
||||
}
|
||||
|
||||
$q = mysql_query("SELECT * FROM reports_items
|
||||
WHERE reports_id='{$report['id']}'
|
||||
ORDER BY `order`");
|
||||
print(mysql_error());
|
||||
|
||||
if(mysql_num_rows($q) == 0) return $ret;
|
||||
|
||||
while($a = mysql_fetch_assoc($q)) {
|
||||
$f = $a['field'];
|
||||
$t = $a['type'];
|
||||
switch($t) {
|
||||
case 'option':
|
||||
if(!in_array($f, $allow_options)) {
|
||||
print("Type[$type] Field[$f] not allowed.\n");
|
||||
exit;
|
||||
}
|
||||
$report['option'][$f] = $a['value'];
|
||||
break;
|
||||
case 'col':
|
||||
/* Get the coords, if they exist */
|
||||
$loc = array();
|
||||
$loc_fields = array('xp', 'yp', 'wp', 'hp', 'lhp', 'face', 'align');
|
||||
foreach($loc_fields as $lf) $loc[$lf] = $a[$lf];
|
||||
$report['loc'][$f] = $loc;
|
||||
|
||||
/* Fall through */
|
||||
default:
|
||||
if(!in_array($f, $allow_fields)) {
|
||||
print("Type[$type] Field[$f] not allowed.\n");
|
||||
exit;
|
||||
}
|
||||
$report[$t][] = $f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $report;
|
||||
}
|
||||
|
||||
@ -212,11 +219,11 @@ foreach($stock as $n=>$v) {
|
||||
`type`='".mysql_escape_string($report['type'])."'
|
||||
WHERE `id`={$report['id']}");
|
||||
|
||||
report_save_field($report, 'col');
|
||||
report_save_field($report, 'group');
|
||||
report_save_field($report, 'sort');
|
||||
report_save_field($report, 'distinct');
|
||||
report_save_field($report, 'option');
|
||||
report_save_field($report, 'col', $report['loc']);
|
||||
report_save_field($report, 'group', array());
|
||||
report_save_field($report, 'sort', array());
|
||||
report_save_field($report, 'distinct', array());
|
||||
report_save_field($report, 'option', array());
|
||||
return $report['id'];
|
||||
}
|
||||
|
||||
@ -265,6 +272,7 @@ foreach($stock as $n=>$v) {
|
||||
function report_gen($report)
|
||||
{
|
||||
global $config, $report_students_fields, $report_judges_fields, $report_awards_fields;
|
||||
global $stock;
|
||||
|
||||
//print_r($report);
|
||||
switch($report['type']) {
|
||||
@ -288,14 +296,15 @@ foreach($stock as $n=>$v) {
|
||||
|
||||
} else if($report['option']['type']=='label') {
|
||||
/* Label */
|
||||
$label_stock = $stock($report['option']['stock']);
|
||||
$label_stock = $stock[$report['option']['stock']];
|
||||
$rep=new lpdf( i18n($config['fairname']),
|
||||
i18n($report_name),
|
||||
$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif");
|
||||
$rep->newPage($label_stock['pw'], $label_stock['ph']);
|
||||
$rep->setPageStyle("labels");
|
||||
$rep->newPage($label_stock['page_width'], $label_stock['page_height']);
|
||||
$rep->setFontSize(11);
|
||||
$rep->setLabelDimensions($label_stock['w'], $label_stock['h'],
|
||||
$label_stock['xs'], $label_stock['ys']);
|
||||
$rep->setLabelDimensions($label_stock['label_width'], $label_stock['label_height'],
|
||||
$label_stock['x_spacing'], $label_stock['y_spacing']);
|
||||
$gen_mode = 'label';
|
||||
} else {
|
||||
$rep=new lpdf( i18n($config['fairname']),
|
||||
@ -441,6 +450,12 @@ foreach($stock as $n=>$v) {
|
||||
|
||||
$data = array();
|
||||
$x=0;
|
||||
if($gen_mode == 'label') {
|
||||
$show_box = ($report['option']['label_box'] == 'yes') ? true : false;
|
||||
$show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false;
|
||||
$show_logo = ($report['option']['label_logo'] == 'yes') ? true : false;
|
||||
$rep->newLabel($show_box, $show_fair, $show_logo);
|
||||
}
|
||||
foreach($report['col'] as $c) {
|
||||
if(is_array($fields[$c]['value_map'])) {
|
||||
$v = $fields[$c]['value_map'][$i["C$x"]];
|
||||
@ -450,14 +465,19 @@ foreach($stock as $n=>$v) {
|
||||
if($gen_mode == 'table') {
|
||||
$data[] = $v;
|
||||
} else if($gen_mode == 'label') {
|
||||
$d = $label_data[$c];
|
||||
$d = $report['loc'][$c];
|
||||
/* Label text: x%, y%, width%, height%, text */
|
||||
$this->addLabelText2($d['x'], $d['y'], $d['w'],
|
||||
$d['h'], $v);
|
||||
|
||||
$opt = array();
|
||||
if($d['face'] == 'bold') $opt[] = 'bold';
|
||||
$opt[] = $d['align'];
|
||||
|
||||
$rep->addLabelText2($d['xp'], $d['yp'], $d['wp'],
|
||||
$d['hp'], $d['lhp'], $v, $opt);
|
||||
}
|
||||
$x++;
|
||||
}
|
||||
$table['data'][] = $data;
|
||||
if(count($data)) $table['data'][] = $data;
|
||||
}
|
||||
|
||||
if(count($table['data'])) {
|
||||
|
@ -31,6 +31,7 @@
|
||||
require_once('reports.inc.php');
|
||||
|
||||
$fields = array();
|
||||
$locs = array('X' => 'xp', 'Y' => 'yp', 'W' => 'wp', 'H' => 'hp', 'LineHeight' => 'lhp');
|
||||
|
||||
function field_selector($name, $id, $selected)
|
||||
{
|
||||
@ -42,9 +43,17 @@
|
||||
echo "<option value=\"$k\" $sel >{$f['name']}</option>";
|
||||
}
|
||||
echo "</select>";
|
||||
|
||||
}
|
||||
|
||||
function selector($name, $a, $selected)
|
||||
{
|
||||
echo "<select name=\"$name\">";
|
||||
foreach($a as $v=>$val) {
|
||||
$sel = ($selected == $v) ? 'selected=\"selected\"' : '';
|
||||
echo "<option value=\"$v\" $sel>$val</option>";
|
||||
}
|
||||
echo '</select>';
|
||||
}
|
||||
/*
|
||||
<script type="text/javascript">
|
||||
function reportChange()
|
||||
@ -131,6 +140,32 @@ function reportChange()
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
function parse_loc($f)
|
||||
{
|
||||
global $locs;
|
||||
$ret = array();
|
||||
if(!is_array($_POST[$f])) return array();
|
||||
|
||||
foreach($_POST[$f] as $c=>$l) {
|
||||
if(trim($c) == '') continue;
|
||||
foreach($l as $ll=>$val) {
|
||||
$floatloc = array_values($locs);
|
||||
if(in_array($ll, $floatloc)) {
|
||||
$val = floatval($val);
|
||||
} else if($ll == 'face') {
|
||||
$val = ($val == 'bold') ? 'bold' : '';
|
||||
} else if($ll = 'align') {
|
||||
$aligns = array('left', 'right', 'center');
|
||||
if(!in_array($val, $aligns)) {
|
||||
echo "Invalid alignment $val";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$ret[$c][$ll] = $val;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/* Decode the report */
|
||||
|
||||
@ -145,6 +180,7 @@ function reportChange()
|
||||
$report['sort'] = parse_fields('sort');
|
||||
$report['distinct'] = parse_fields('distinct');
|
||||
$report['option'] = parse_options('option');
|
||||
$report['loc'] = parse_loc('loc');
|
||||
|
||||
// print_r($report);
|
||||
|
||||
@ -250,6 +286,7 @@ function reportChange()
|
||||
echo "<td>";
|
||||
field_selector("col[]", "col$x", $f);
|
||||
echo "</td></tr>";
|
||||
|
||||
$x++;
|
||||
}
|
||||
for(;$x<$n_columns;$x++) {
|
||||
@ -257,9 +294,8 @@ function reportChange()
|
||||
echo "<td>";
|
||||
field_selector("col[]", "col$x", '');
|
||||
echo "</td></tr>";
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo "<tr><td></td>";
|
||||
echo "<td align=\"right\">";
|
||||
echo "<select name=\"colaction\"><option value=\"\"></option><option value=\"add\">Add more columns</option></select>";
|
||||
@ -267,6 +303,48 @@ function reportChange()
|
||||
echo "</td></tr>";
|
||||
echo "</table>\n";
|
||||
|
||||
echo "<h4>Label Data Locations</h4>";
|
||||
echo "<table>";
|
||||
$x=0;
|
||||
|
||||
if($report['option']['type'] == 'label') {
|
||||
|
||||
foreach($report['col'] as $f) {
|
||||
echo "<tr><td align=\"right\">Loc ".($x+1).": </td>";
|
||||
echo "<td>";
|
||||
foreach($locs as $k=>$v) {
|
||||
echo "$k=<input type=\"text\" size=\"3\" name=\"loc[$f][$v]\" value=\"{$report['loc'][$f][$v]}\">";
|
||||
}
|
||||
echo 'Face=';
|
||||
selector("loc[$f][face]",
|
||||
array('' => '', 'bold' => 'Bold'),
|
||||
$report['loc'][$f]['face']);
|
||||
echo 'Align';
|
||||
selector("loc[$f][align]", array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
|
||||
$report['loc'][$f]['align']);
|
||||
$x++;
|
||||
}
|
||||
for(;$x<$n_columns;$x++) {
|
||||
echo "<tr><td align=\"right\">Loc ".($x+1).": </td>";
|
||||
echo "<td>";
|
||||
foreach($locs as $k=>$v) {
|
||||
echo "$k=<input type=\"text\" size=\"3\" name=\"loc[$x][$v]\" value=\"\">";
|
||||
}
|
||||
echo 'Face=';
|
||||
selector("loc[$f][face]",
|
||||
array('' => '', 'bold' => 'Bold'),
|
||||
'');
|
||||
echo 'Align';
|
||||
selector("loc[$f][align]",
|
||||
array('center' => 'Center', 'left' => 'Left', 'right' => 'Right'),
|
||||
'center');
|
||||
echo "</td></tr>";
|
||||
}
|
||||
}
|
||||
echo "</table>\n";
|
||||
|
||||
|
||||
|
||||
echo "<h4>Grouping</h4>";
|
||||
for($x=0;$x<2;$x++) {
|
||||
echo "Group By".($x + 1).": ";
|
||||
|
@ -137,9 +137,9 @@
|
||||
students.lastname
|
||||
FROM
|
||||
registrations
|
||||
LEFT JOIN projects on projects.registrations_id=registrations.id
|
||||
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
|
||||
@ -150,7 +150,7 @@
|
||||
ORDER BY
|
||||
projects.projectnumber
|
||||
");
|
||||
// echo mysql_error();
|
||||
echo mysql_error();
|
||||
//
|
||||
/*
|
||||
this is 4x3" on my screen, so i'll use it to figure
|
||||
|
@ -29,87 +29,94 @@ $report_students_fields = array(
|
||||
'table' => 'projects.projectnumber' ),
|
||||
|
||||
'last_name' => array(
|
||||
'name' => 'Last Name',
|
||||
'name' => 'Student -- Last Name',
|
||||
'header' => 'Last Name',
|
||||
'width' => 1.0,
|
||||
'table' => 'students.lastname' ),
|
||||
|
||||
'first_name' => array(
|
||||
'name' => 'First Name',
|
||||
'name' => 'Student -- First Name',
|
||||
'header' => 'First Name',
|
||||
'width' => 1.0,
|
||||
'table' => 'students.firstname' ),
|
||||
|
||||
'name' => array(
|
||||
'name' => 'Full Student Name (last, first)',
|
||||
'name' => 'Student -- Full Name (last, first)',
|
||||
'header' => 'Name',
|
||||
'width' => 1.75,
|
||||
'table' => "CONCAT(students.lastname, ', ', students.firstname)",
|
||||
'table_sort'=> 'students.lastname' ),
|
||||
|
||||
'namefl' => array(
|
||||
'name' => 'Student -- Full Name (first last)',
|
||||
'header' => 'Name',
|
||||
'width' => 1.75,
|
||||
'table' => "CONCAT(students.firstname, ' ', students.lastname)",
|
||||
'table_sort'=> 'students.lastname' ),
|
||||
|
||||
'partner' => array(
|
||||
'name' => 'Partner Name',
|
||||
'name' => 'Student -- Partner Name',
|
||||
'header' => 'Partner',
|
||||
'width' => 1.5,
|
||||
'table' => "CONCAT(students2.lastname, ', ', students2.firstname)" ),
|
||||
|
||||
'bothnames' => array(
|
||||
'name' => "Both Student Names",
|
||||
'name' => "Student -- Both Student Names",
|
||||
'header' => 'Student(s)',
|
||||
'width' => 3.0,
|
||||
'table' => "CONCAT(students.firstname, ' ', students.lastname, IF(students2.lastname IS NULL,'', CONCAT(', ', students2.firstname, ' ', students2.lastname)))",
|
||||
'table_sort' => 'students.lastnmae'),
|
||||
|
||||
'grade' => array(
|
||||
'name' => 'Grade',
|
||||
'name' => 'Student -- Grade',
|
||||
'header' => 'Grade',
|
||||
'width' => 0.5,
|
||||
'table' => 'students.grade'),
|
||||
|
||||
'gender' => array(
|
||||
'name' => 'Gender',
|
||||
'name' => 'Student -- Gender',
|
||||
'header' => 'Gender',
|
||||
'width' => 0.5,
|
||||
'table' => 'students.sex',
|
||||
'value_map' =>array ('male' => 'Male', 'female' => 'Female')),
|
||||
|
||||
'birthdate' => array(
|
||||
'name' => 'Birthdate',
|
||||
'name' => 'Student -- Birthdate',
|
||||
'header' => 'Birthdate',
|
||||
'width' => 1,
|
||||
'table' => 'students.dateofbirth'),
|
||||
|
||||
'title' => array(
|
||||
'name' => 'Project Title',
|
||||
'name' => 'Project -- Title',
|
||||
'header' => 'Project Title',
|
||||
'width' => 2.75,
|
||||
'table' => 'projects.title' ),
|
||||
|
||||
'division' => array(
|
||||
'name' => 'Project Division',
|
||||
'name' => 'Project -- Division',
|
||||
'header' => 'Division',
|
||||
'width' => 3.0,
|
||||
'table' => 'projectdivisions.division' ),
|
||||
|
||||
'div' => array(
|
||||
'name' => 'Project Division Short Form' ,
|
||||
'name' => 'Project -- Division Short Form' ,
|
||||
'header' => 'Div',
|
||||
'width' => 0.4,
|
||||
'table' => 'projectdivisions.division_shortform' ),
|
||||
|
||||
'category' => array(
|
||||
'name' => 'Project Category',
|
||||
'name' => 'Project -- Category',
|
||||
'header' => 'Category',
|
||||
'width' => 1,
|
||||
'table_sort' => 'projectcategories.id',
|
||||
'table' => 'projectcategories.category' ),
|
||||
|
||||
'categorydivision' => array(
|
||||
'name' => 'Project Category - Project Division',
|
||||
'name' => 'Project -- Category and Division',
|
||||
'header' => 'Category/Division',
|
||||
'width' => 3.5,
|
||||
'table_sort' => 'projectcategories.id',
|
||||
'table' => "CONCAT(projectcategories.category',' - ', projectdivisions.division)"),
|
||||
'table' => "CONCAT(projectcategories.category,' - ', projectdivisions.division)"),
|
||||
|
||||
'address' => array(
|
||||
'name' => 'Student Address -- Street Address',
|
||||
|
Loading…
Reference in New Issue
Block a user