MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mpdfreport.class
Ir para a documentação deste ficheiro.
1<?php
2
11{
15 public $name;
16
17
35 function __construct($name,$title='', $align='left', $nowrap=false, $width=0, $visible=true, $options=null, $order=false, $filter=false)
36 {
37 parent::__construct($title, $align, $nowrap, $width, $visible, $options, $order, $filter);
38 $this->name = $name;
39 }
40
48 function Generate()
49 {
50 }
51}
52
58{
62 public $name;
63
64
80 function __construct($name,$control, $title='',$align='left',$nowrap=false,$width=0,$visible=true)
81 {
82 parent::__construct($control, $title,$align,$nowrap,$width,$visible);
83 $this->name = $name;
84 }
85
93 function Generate()
94 {
95 }
96}
97
105class MPDFReport extends MGrid
106{
111
116
120 var $slot;
121
125 var $ezpdf; // ezPdfReport object
126
130 var $pdf; // MCezPdf object
131
135 var $y;
136
137
151 { global $MIOLO, $state, $page;
152
153 $this->SetPDF(new ezPDFReport('2'));
154 parent::__construct($data, $columns, '', $pageLength, $index);
155 $this->slot = array();
156 $this->rawdata = NULL;
157 $this->InitializeOptions();
158 $this->SetWidth(100);
159 }
160
169 {
170 $this->options['showLines'] = 0;
171 $this->options['showHeadings'] = 1;
172 $this->options['showTableTitle'] = 1;
173 $this->options['shaded'] = 1;
174 $this->options['shadeCol'] = array(0.8,0.8,0.8);
175 $this->options['shadeCol2'] = array(0.7,0.7,0.7);
176 $this->options['fontSize'] = 10;
177 $this->options['textCol'] = array(0,0,0);
178 $this->options['titleFontSize'] = 14;
179 $this->options['rowGap'] = 2;
180 $this->options['colGap'] = 5;
181 $this->options['lineCol'] = array(0,0,0);
182 $this->options['xPos'] = 'center';
183 $this->options['xOrientation'] = 'center';
184 $this->options['width'] = 0;
185 $this->options['maxWidth'] = 596;
186 $this->options['minRowSpace'] = -100;
187 $this->options['innerLineThickness'] = 1;
188 $this->options['outerLineThickness'] = 1;
189 $this->options['protectRows'] = 1;
190 }
191
202 function SetOption($option, $value)
203 {
204 $this->options[$option] = $value;
205 }
206
216 function SetPDF($pdf)
217 {
218 $this->ezpdf = $pdf;
219 $this->pdf = $pdf->pdf;
220 }
221
229 function GetPDF()
230 {
231 return $this->ezpdf;
232 }
233
243 function SetWidth($width)
244 {
245 $width = $this->pdf->getWidthFromPercent($width);
246 $this->SetOption('width',$width);
247 }
248
258 function AddColumn($column)
259 {
260 $this->columns[$column->name] = $column;
261 $this->columns[$column->name]->width = $this->pdf->getWidthFromPercent($column->width);
262 $this->columns[$column->name]->index = count($this->columns);
263 }
264
275 {
276 $this->columns = NULL;
277 if ($columns != NULL)
278 {
279 if (! is_array($columns) ) $columns = array($columns);
280 foreach($columns as $k=>$c)
281 {
282 $this->columns[$c->name] = $c;
283 $this->columns[$c->name]->width = $this->pdf->getWidthFromPercent($c->width);
284 $this->columns[$c->name]->index = $k;
285 }
286 }
287 }
288
296 function GetPage()
297 {
298 if (count($this->rawdata))
299 {
300 return array_slice($this->rawdata,$this->pn->idxFirst,$this->pn->gridCount);
301 }
302 }
303
312 {
313 return NULL;
314 }
315
324 {
325 return NULL;
326 }
327
336 {
337 return NULL;
338 }
339
347 function GenerateHeader()
348 {
349 $header[] = $this->GenerateReportHeader();
350 $header[] = $this->GeneratePageHeader();
351 return $header;
352 }
353
362 {
363 $tbl = array();
364 $p = 0;
365 // generate column headings
366 foreach ( $this->columns as $k=>$col )
367 {
368 if (( !$col->visible ) || ( !$col->title )) continue;
369 $colTitle = $col->title;
370 $tbl["$col->name"] = $colTitle;
371 }
372 return $tbl;
373 }
374
386 function GenerateColumns($tbl, $row = NULL, $i = NULL)
387 { global $MIOLO;
388
389 $cntRow = count($row);
390 foreach($this->columns as $k=>$col)
391 {
392 if (( !$col->title ) || ( !$col->visible )) continue;
393 $control = clone $col->basecontrol; // clonning
394 if ($col->className == 'pdfreportcolumn')
395 {
396 $value = $row[$col->index];
397 $col->value = $value;
398 if ( $col->options )
399 {
400 $value = $col->options[$value];
401 if ( $this->showid )
402 {
403 $value .= " ($row[$k])";
404 }
405 }
406 // by default, we align numbers to the right and text to the left
407 $c = substr($value,0,1);
408 if ( ! $col->align && ( $c == '-' || ( $c >= '0' && $c <= '9' ) ) )
409 {
410 $col->align = 'right';
411 }
412 if ($col->href != '')
413 {
414 $href = $col->href;
415 for ( $r=0; $r<$cntRow; $r++ )
416 $href = str_replace("#$r#",trim($row[$r]),$href);
417 $href = str_replace('#?#',$value,$href);
418 $control->href = $href;
419 $control->action = $href;
420 $control->label = $value;
421 }
422 $control->value = $value;
423 }
424 elseif ($col->className == 'pdfreportcontrol')
425 {
426 $control->Generate();
427 }
428 else
429 {
430 $MIOLO->Error("ERROR: Unknown column class '{$col->className}'!");
431 }
432 $tbl[$i][$col->name] = $control;
433 }
434 }
435
436 function & GenerateEmptyMsg()
437 {
438 $tbl = new SimpleTable('');
439 $tbl->attributes['table'] = "cellspacing=\"0\" cellpadding=\"2\" border=\"0\" class=\"gridAttention\" align=\"center\" width=\"100%\"";
440 $tbl->attributes['row'][0] = "class=\"gridAttention\" align=\"center\"";
441 $tbl->cell[0][0] = new Text('',$this->emptyMsg);
442 $tbl->cell[0][0]->SetClass('gridAttention');
443 return $tbl;
444 }
445
454 {
455 if ( $this->HasErrors() )
456 {
457 $this->GenerateErrors();
458 }
459 $tblData = array();
460 if ( $this->data)
461 {
462 // generate data rows
463 foreach ( $this->data as $i=>$row )
464 {
465 if (isset($this->rowmethod)){
466 call_user_func($this->rowmethod, $row, $this->columns, $this->slot, $this);
467 }
468 $this->GenerateColumns($tblData, $row, $i);
469
470 } // foreach row
471 } // if
472 foreach($tblData as $r=>$row)
473 foreach($row as $c=>$cell)
474 $data[$r][$c] = $cell->value;
475 return $data;
476 }
477
486 {
487 $this->pdf->ezText($this->title,$this->options['titleFontSize'],array('justification'=>'center'));
488 $this->pdf->ezSetDy($this->pdf->getFontDecender($this->options['titleFontSize']));
489 }
490
500 function GenerateBody($data = null)
501 {
502 $titles = $this->GenerateColumnsHeading();
503 $cols = array();
504 foreach ( $this->columns as $k=>$col )
505 {
506 if (( !$col->visible ) || ( !$col->title )) continue;
507 $cols[$col->name] = array('justification'=>$col->align,'width'=>$col->width);
508 }
509 $this->options['cols'] = $cols;
510 if ($this->options['showTableTitle'])
512 else
513 {
514 $this->GeneratePageTitle();
515 $title = '';
516 }
517 $this->y = $this->pdf->ezTable($data,$titles,$title,$this->options);
518 }
519
527 function GenerateFooter()
528 {
529 if (!$this->data)
530 $footer[] = $this->GenerateEmptyMsg();
531 $footer[] = $this->GeneratePageFooter();
532 $footer[] = $this->GenerateReportFooter();
533 return $footer;
534 }
535
543 function GenerateReport()
544 {
545 $this->pdf->ezSetMargins(30,30,30,30);
546 $this->rawdata = $this->GenerateTableData();
547 if ($this->pageLength)
548 {
549 $this->pn = new MGridNavigator($this->pageLength, $this->rowCount, '');
550 }
551 else $this->pn = null;
552 for($page=1;$page<=$this->pn->pageCount;$page++)
553 {
554 $this->pn->SetPageNumber($page);
555 $this->GeneratePageHeader();
556 $this->GenerateBody($this->GetPage());
557 $this->GeneratePageFooter();
558 if ($page != $this->pn->pageCount) $this->pdf->ezNewPage();
559 }
560 }
561
569 function PageBreak()
570 {
571 if (!$this->break)
572 {
573 $this->pdf->ezNewPage();
574 $this->break = true;
575 }
576 }
577
585 function ClearPageBreak()
586 {
587 $this->break = false;
588 }
589
602 function SetTrigger($trigger, $class, $module, $param)
603 {
604 $this->pdf->SetTrigger($trigger, $class, $module, $param);
605 }
606
616 function SetOutput($value='')
617 {
618 $this->ezpdf->SetOutput();
619 }
620
628 function Execute()
629 {
630 $this->ezpdf->Execute();
631 }
632
640 function Generate()
641 {
642 $this->GenerateReport();
643 $this->SetOutput();
644 $this->Execute();
645 }
646
647}
648?>
__construct($name, $title='', $align='left', $nowrap=false, $width=0, $visible=true, $options=null, $order=false, $filter=false)
__construct($name, $control, $title='', $align='left', $nowrap=false, $width=0, $visible=true)
SetOption($option, $value)
SetColumns($columns)
SetOutput($value='')
AddColumn($column)
GenerateColumns($tbl, $row=NULL, $i=NULL)
GenerateReportHeader()
& GenerateEmptyMsg()
SetWidth($width)
GenerateBody($data=null)
GenerateColumnsHeading($tbl)
__construct($data, $columns, $pageLength=1, $index=0)
SetTrigger($trigger, $class, $module, $param)