diff --git a/admin/reports.inc.php b/admin/reports.inc.php index 3d87fdb..470235e 100644 --- a/admin/reports.inc.php +++ b/admin/reports.inc.php @@ -49,7 +49,7 @@ $report_options = array(); $report_options['type'] = array('desc' => 'Report Format', - 'values' => array('pdf'=>'PDF', 'csv'=>'CSV', 'label'=>'Label', 'tcpdf_label'=>'TCPDF Label (experimental)') + 'values' => array('tcpdf' => 'PDF', 'tcpdf_label'=>'Label', 'csv'=>'CSV (for Excel)', 'text'=>'Text (Plain text in columns)', 'pdf'=>'PDF (PDFlib deprecated)', 'label'=>'Label (PDFlib deprecated)', ) ); $report_options['group_new_page'] = array('desc' => 'Start each new grouping on a new page', 'values' => array('no'=>'No', 'yes'=>'Yes') @@ -443,14 +443,20 @@ foreach($report_stock as $n=>$v) { (i.e. nothign has changed, only adding on */ if($val['lines'] == 0) $val['lines'] = 1; + + /* Old format, where align and valign are stored in 'align', + * separte them. */ $opts = explode(" ", $val['align']); $align_opts = array ('left', 'right', 'center'); $valign_opts = array ('vtop', 'vbottom', 'vcenter'); - $style_opts = array ('bold'); foreach($opts as $o) { if(in_array($o, $align_opts)) $val['align'] = $o; if(in_array($o, $valign_opts)) $val['valign'] = $o; - if(in_array($o, $valign_opts)) $val['face'] = $o; + } + /* Turn the old 'face' into the fontstyle array */ + $style_opts = array ('bold'); + if(in_array($val['face'], $style_opts)) { + $val['fontstyle'] = array($val['face']); } $report[$t][$a['ord']] = $val; @@ -559,9 +565,7 @@ foreach($report_stock as $n=>$v) { $fieldname = array(); $thead = array(); - $table['header']=array(); - $table['widths']=array(); - $table['dataalign']=array(); + $table['col']=array(); $table['option']=array(); $table['total']=0; @@ -578,8 +582,8 @@ foreach($report_stock as $n=>$v) { $rep=new lcsv(i18n($report['name'])); $gen_mode = 'table'; break; +/* case 'label': - /* Label */ $label_stock = $report_stock[$report['option']['stock']]; $rep=new lpdf( i18n($config['fairname']), i18n($report['name']), @@ -591,8 +595,7 @@ foreach($report_stock as $n=>$v) { $label_stock['x_spacing'], $label_stock['y_spacing'],11,$label_stock['y_padding']); $gen_mode = 'label'; break; - case 'pdf': case '': - /* FIXME: handle landscape pages in here */ + case 'old_pdf': $label_stock = $report_stock[$report['option']['stock']]; $rep=new lpdf( i18n($config['fairname']), i18n($report['name']), @@ -611,7 +614,9 @@ foreach($report_stock as $n=>$v) { if($report['option']['allow_multiline'] == 'yes') $table['option']['allow_multiline'] = true; break; - case 'tcpdf_label': +*/ + case 'label': + case 'tcpdf_label': $label_stock = $report_stock[$report['option']['stock']]; $show_box = ($report['option']['label_box'] == 'yes') ? true : false; $show_fair = ($report['option']['label_fairname'] == 'yes') ? true : false; @@ -625,6 +630,27 @@ foreach($report_stock as $n=>$v) { $gen_mode = 'tcpdf_label'; break; + case 'pdf': case '': + $label_stock = $report_stock[$report['option']['stock']]; + if($report['option']['allow_multiline'] == 'yes') + $on_overflow = 'nothing'; + else + $on_overflow = '...'; + + $rep=new pdf($report['name'], $label_stock['page_format'], $label_stock['page_orientation']); + $rep->setup_for_tables($show_box, $show_fair, $show_logo, + $label_stock['label_width'] * 25.4, $label_stock['label_height'] * 25.4, + $label_stock['x_spacing'] * 25.4, $label_stock['y_spacing'] * 25.4, + $label_stock['rows'], $label_stock['cols']); + $gen_mode = 'table'; + break; + + + + case 'text': + echo "Not implemented [{$report['option']['type']}]"; + exit; + default: echo "Invalid type [{$report['option']['type']}]"; exit; @@ -643,30 +669,47 @@ foreach($report_stock as $n=>$v) { * ones are scalable, just in case */ foreach($report['col'] as $o=>$d) { $f = $d['field']; - $total_width += $fields[$f]['width']; - if($fields[$f]['scalable'] == true) - $scale_width += $fields[$f]['width']; + if($d['w'] != 0) { + /* Always 0 on old reports, so we never get in here */ + $total_width += $d['w']; + /* For the rest of the computation, this field is + * not scalable */ + /* FIXME! */ + } else { + $total_width += $fields[$f]['width']; + if($fields[$f]['scalable'] == true) + $scale_width += $fields[$f]['width']; + } } /* Determine the scale factor (use the label width so * we can enforce margins) */ if($report['option']['fit_columns'] == 'yes') { // && $total_width > $label_stock['label_width']) { $static_width = $total_width - $scale_width; - if($scale_width) - $scale_factor = ($label_stock['label_width'] - $static_width) / $scale_width; - else - $scale_factor = 1.0; + if($scale_width) + $scale_factor = ($label_stock['label_width'] - $static_width) / $scale_width; + else + $scale_factor = 1.0; } else { $scale_factor = 1.0; } + /* Select columns to display */ foreach($report['col'] as $o=>$d) { $f = $d['field']; - $table['header'][] = i18n($fields[$f]['header']); - $sf = ($fields[$f]['scalable'] == true) ? $scale_factor : 1.0; - $table['widths'][] = $fields[$f]['width'] * $sf; - $table['dataalign'][] = 'left'; + + /* If width is specificed, use that, else compute based on default field width */ + if($d['w'] == 0) + $width = $fields[$f]['width'] * (($fields[$f]['scalable'] == true) ? $scale_factor : 1.0); + else + $width = $d['w']; + $col = array( 'header' => i18n($fields[$f]['header']), + 'width' => $width, + 'align' => 'left', + 'on_overflow' => $on_overflow); + $table['col'][] = $col; + $sel[] = "{$fields[$f]['table']} AS C$x"; $fieldname[$f] = "C$x"; /* We want to add these to group by, but AFTER all the other group bys */ @@ -688,7 +731,7 @@ foreach($report_stock as $n=>$v) { $fieldname[$f] = "G$o"; } - if(isset($fields[$f]['table_sort'])) + if(isset($fields[$f]['able_sort'])) $order[] = $fields[$f]['table_sort']; else $order[] = $fieldname[$f]; @@ -810,25 +853,22 @@ foreach($report_stock as $n=>$v) { /* Dump the last table */ if(count($table['data'])) { // print_r($table); - $rep->addTable($table); - $rep->nextLine(); + $rep->add_table($table); $table['data'] = array(); $table['total'] = 0; /* Start a new page AFTER a table is * dumped, so the first page doesn't * end up blank */ if($report['option']['group_new_page'] == 'yes') { - $rep->newPage(); + $rep->addpage(); } else { $rep->hr(); - $rep->vspace(-0.1); } } /* Construct a new header */ $h = implode(" -- ", $last_group_data); $rep->heading($h); - $rep->nextLine(); } } @@ -904,7 +944,7 @@ foreach($report_stock as $n=>$v) { if(count($data)) $table['data'][] = $data; } if(count($table['data'])) { - $rep->addTable($table); + $rep->add_table($table); } diff --git a/admin/reports_editor.php b/admin/reports_editor.php index 980e127..374cc9f 100644 --- a/admin/reports_editor.php +++ b/admin/reports_editor.php @@ -39,7 +39,7 @@ require_once('../tcpdf.inc.php'); $fields = array(); - $locs = array('X' => 'x', 'Y' => 'y', 'W' => 'w', 'H' => 'h', 'Lines' => 'lines'); + $locs = array('X' => 'x', 'Y' => 'y', 'W' => 'w', 'H' => 'h'); function field_selector($name, $id, $selected) { @@ -203,53 +203,7 @@ function initCanvas(w,h,lw,lh) { labelHeight=lh; } -function createData(x,y,w,h,l,face,align,valign,value) { - var canvas=document.getElementById('layoutcanvas'); - var newdiv=document.createElement('div'); - if(valign=="vcenter") verticalAlign="middle"; - else if(valign=="vtop") verticalAlign="top"; - else if(valign=="vbottom") verticalAlign="bottom"; - else verticalAlign="top"; -// alert(verticalAlign); - - //convert x,y,w,h from % to absolute - - var dx=Math.round(x*canvasWidth/100); - var dy=Math.round(y*canvasHeight/100); - var dw=Math.round(w*canvasWidth/100); - var dh=Math.round(h*canvasHeight/100); -// alert(dx+','+dy+','+dw+','+dh); - - var fontheight=Math.round(dh/l); - - newdiv.setAttribute('id','o_'+canvasObjectIndex); - newdiv.style.display="table-cell"; - newdiv.style.position="absolute"; - newdiv.style.width=dw+"px"; - newdiv.style.height=dh+"px"; - newdiv.style.left=dx+"px"; - newdiv.style.top=dy+"px"; - newdiv.style.textAlign=align; - newdiv.style.verticalAlign=verticalAlign; - newdiv.style.padding="0 0 0 0"; - newdiv.style.margin="0 0 0 0"; -// newdiv.style.vertical-align=valign; - newdiv.style.border="1px solid blue"; - newdiv.style.fontSize=fontheight+"px"; - newdiv.style.lineHeight=fontheight+"px"; - newdiv.style.fontFamily="Verdana"; - newdiv.style.fontSizeAdjust=0.65; - - var maxlength=Math.floor(dw/(fontheight*0.7))*l; - if(value.length>maxlength) value=value.substring(0,maxlength); - newdiv.innerHTML=value; //"Maple Test xxxx"; //value; - - canvas.appendChild(newdiv); - - canvasObjectIndex++; -} - -function createDataTCPDF(x,y,w,h,align,valign,fontname,fontstyle,fontsize,value) { +function createData(x,y,w,h,align,valign,fontname,fontstyle,fontsize,value) { var canvas=document.getElementById('layoutcanvas'); var newdiv=document.createElement('div'); @@ -451,27 +405,15 @@ function createDataTCPDF(x,y,w,h,align,valign,fontname,fontstyle,fontsize,value) echo "\n"; $doCanvasSample = false; -$doCanvasSampletcpdf = false; $l_w=$report_stock[$report['option']['stock']]['label_width']; $l_h=$report_stock[$report['option']['stock']]['label_height']; - if($l_w && $l_h && $report['option']['type']=="label") { + + if($l_w && $l_h && $report['option']['type']=='label') { echo "
"; +// print_r($table); + /* Compute the lines in height of each row for pagination */ + + $html = '
{$col['header']} | "; + } + $html .= '
$d | "; + } + $html .= '
"; +//echo $html; + + +/* +$html = <<+ + + +A +XXXX +XXXX +XXXX +XXXX +XXXX ++ + +B +XXXX +XXXX +XXXX +XXXX +XXXX ++ +1. +XXXX +
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX
XXXXXXXX +
XXXXXXXX +
XXXXXXXX +XXXX +
XXXX+ +2. +XXXX +
XXXXXXXX +
XXXXXXXX +
XXXXXXXX +
XXXX+ +XXXX +
XXXX
XXXX
XXXXXXXX +
XXXXXXXX +
XXXX+ +RRRRRR +
XXXX
XXXX
XXXX
XXXX
XXXX
XXXX
XXXXXXXX +
XXXXXXXX +
XXXX+ +3. +XXXX1 +
XXXXXXXX +
XXXXXXXX +
XXXX+ + +EOD; +*/ + function add_table($table) + { + $orig_lmargin = $this->lMargin; + $orig_tmargin = $this->tMargin; + + $html = $this->get_table_html($table); + $total_width = 0; + foreach($table['col'] as $c=>$col) + $total_width += $col['width']; + + $lpad = (($this->getPageWidth() - $this->lMargin - $this->rMargin) - $total_width)/2; + + $this->SetLeftMargin($orig_lmargin + $lpad); + $this->writeHTML($html, false, false, false, false, ''); + $this->SetLeftMargin($orig_lmargin); + + if($table['total'] != 0) { + $this->Cell($total_width, 0, "(Total: {$table['total']})", 0, 1, 'R'); + } else { + $t = count($table['data']); + $this->Cell($total_width, 0, "(Rows: $t)", 0, 1, 'R'); + } + } + + function output($filename='', $dest='I') + { + if($filename == '') { + $filename=strtolower($this->subject); + $filename=ereg_replace("[^a-z0-9]","_",$filename).'.pdf'; + } + parent::Output($filename, $dest); + } + + }4. +XXXX +
XXXXXXXX +
XXXXXXXX +
XXXXXXXX +
XXXX