added PDFTable

This commit is contained in:
Roland Gruber 2015-07-08 17:14:52 +00:00
parent 4bb9a6d8c5
commit 95b87c003f
2 changed files with 316 additions and 226 deletions

View File

@ -858,6 +858,32 @@ abstract class baseModule {
$result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>'); $result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
} }
/**
* Adds a table entry to the PDF.
*
* @param array $result result array (entry will be added here)
* @param String $name ID
* @param PDFTable $table table
*/
public function addPDFTable(&$result, $name, $table) {
$first = true;
foreach ($table->rows as $row) {
$xml = '<block>';
if ($first && !empty($table->label)) {
$xml .= '<key>' . $table->label . '</key>';
}
$xml .= '<tr>';
foreach ($row->cells as $cell) {
$width = empty($cell->width) ? '' : ' width="' . $cell->width . '"';
$content = ($cell->bold) ? '<b>' . $cell->content . '</b>' : $cell->content;
$xml .= '<td align="' . $cell->align . '"' . $width . '>' . $content . '</td>';
}
$xml .= '</tr></block>';
$result[get_class($this) . '_' . $name][] = $xml;
$first = false;
}
}
/** /**
* Returns an array containing all input columns for the file upload. * Returns an array containing all input columns for the file upload.
* *
@ -1789,5 +1815,71 @@ abstract class baseModule {
} }
/**
* Represents a table for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTable {
/** optional label of table */
public $label = null;
/** list of PDFTableRow elements */
public $rows = array();
}
/**
* Represents a table row for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableRow {
/** list of PDFTableCell */
public $cells = array();
}
/**
* Represents a table cell for PDF export.
*
* @package PDF
* @author Roland Gruber
*/
class PDFTableCell {
const ALIGN_LEFT = 'L';
const ALIGN_RIGHT = 'R';
const ALIGN_CENTER = 'C';
/** content text of cell */
public $content = '';
/** text alignment */
public $align = self::ALIGN_LEFT;
/** cell width (e.g. "20%") */
public $width = null;
/** bold text */
public $bold = false;
/**
* Constructor.
*
* @param String $content cell content
* @param String $align cell alignment (default: left)
* @param String $width width (e.g. "20%")
* @param boolean $bold print in bold
*/
public function __construct($content, $align = null, $width = null, $bold = false) {
$this->content = empty($content) ? ' ' : $content;
$this->align = ($align == null) ? self::ALIGN_LEFT : $align;
$this->width = $width;
$this->bold = $bold;
}
}
?> ?>

View File

@ -5,7 +5,7 @@
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2009 - 2012 Pavel Pozdniak Copyright (C) 2009 - 2012 Pavel Pozdniak
2009 - 2014 Roland Gruber 2009 - 2015 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -817,28 +817,26 @@ class asteriskExtension extends baseModule {
$this->addSimplePDFField($return, 'owners', _('Extension owners'), 'member', '; '); $this->addSimplePDFField($return, 'owners', _('Extension owners'), 'member', '; ');
// rules // rules
$entries = $this->load_extension_parts($extName); $entries = $this->load_extension_parts($extName);
$rulePDF = array(); $pdfTable = new PDFTable();
$rulePDF[] = '<block><tr><td width="80%"> </td></tr></block>'; $pdfRow = new PDFTableRow();
$rulePDF[] = '<block><tr><td width="80%"> </td></tr></block>'; $pdfRow->cells[] = new PDFTableCell(_('Name'), null, '20%', true);
$rulePDF[] = '<block><tr><td width="80%"> </td></tr></block>'; $pdfRow->cells[] = new PDFTableCell(_('Application'), null, '30%', true);
$rulePDF[] = '<block><tr>' . $pdfRow->cells[] = new PDFTableCell(_('Application data'), null, '30%', true);
'<td width="20%"><b>' . _('Name') . '</b></td>' . $pdfRow->cells[] = new PDFTableCell(_('Priority'), null, '20%', true);
'<td width="30%"><b>' . _('Application') . '</b></td>' . $pdfTable->rows[] = $pdfRow;
'<td width="30%"><b>' . _('Application data') . '</b></td>' .
'<td width="20%"><b>' . _('Priority') . '</b></td>' .
'</tr></block>';
for ($i = 0; $i < sizeof($entries); $i++) { for ($i = 0; $i < sizeof($entries); $i++) {
$appdata = ' '; $appdata = ' ';
if (isset($entries[$i]['astapplicationdata'][0])) { if (isset($entries[$i]['astapplicationdata'][0])) {
$appdata = $entries[$i]['astapplicationdata'][0]; $appdata = $entries[$i]['astapplicationdata'][0];
} }
$rulePDF[] = '<block><tr>' . $pdfRow = new PDFTableRow();
'<td width="20%" align=\"L\">' . $entries[$i]['cn'][0] . '</td>' . $pdfRow->cells[] = new PDFTableCell($entries[$i]['cn'][0], null, '20%');
'<td width="30%" align=\"L\">' . $entries[$i]['astapplication'][0] . '</td>' . $pdfRow->cells[] = new PDFTableCell($entries[$i]['astapplication'][0], null, '30%');
'<td width="30%" align=\"L\">' . $appdata . '</td>' . $pdfRow->cells[] = new PDFTableCell($appdata, null, '30%');
'<td width="20%" align=\"L\">' . $entries[$i]['astpriority'][0] . '</td></tr></block>'; $pdfRow->cells[] = new PDFTableCell($entries[$i]['astpriority'][0], null, '20%');
$pdfTable->rows[] = $pdfRow;
} }
$return[get_class($this) . '_rules'] = $rulePDF; $this->addPDFTable($return, 'rules', $pdfTable);
return $return; return $return;
} }