From 2f23e31a400e327b6b9b1614d8e48bc9b5fde937 Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 19 Mar 2007 06:51:44 +0000 Subject: [PATCH] - Update the generator, it can do labels and nametags now, almost ready to deprecate all the mailing list/nametag/table label/etc. files. --- admin/reports.inc.php | 186 +++++++++++++++------------- admin/reports_editor.php | 84 ++++++++++++- admin/reports_nametags_students.php | 4 +- admin/reports_students.inc.php | 35 +++--- 4 files changed, 207 insertions(+), 102 deletions(-) diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 1988e99..69ffe66 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -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'])) { diff --git a/admin/reports_editor.php b/admin/reports_editor.php index 50fd95c..995d8c0 100644 --- a/admin/reports_editor.php +++ b/admin/reports_editor.php @@ -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 ""; } echo ""; - } + function selector($name, $a, $selected) + { + echo "'; + } /*