";
}
+ if ($this->isPreformatted) {
+ echo "";
+ }
if ($this->escapeHTML) {
echo htmlspecialchars($this->string);
}
@@ -1747,6 +1752,9 @@ class htmlOutputText extends htmlElement {
if (is_dir("../graphics")) $graphicsPath = "../graphics";
echo '';
}
+ if ($this->isPreformatted) {
+ echo "
";
+ }
if ($this->isBold) {
echo "";
}
@@ -1783,6 +1791,15 @@ class htmlOutputText extends htmlElement {
$this->noWrap = $noWrap;
}
+ /**
+ * Sets if the text is preformatted.
+ *
+ * @param boolean $preformatted is preformatted (default true)
+ */
+ public function setPreformatted($preformatted = true) {
+ $this->isPreformatted = $preformatted;
+ }
+
}
/**
diff --git a/lam/lib/lamPDF.inc b/lam/lib/lamPDF.inc
index cabd0f3f..bcd50665 100644
--- a/lam/lib/lamPDF.inc
+++ b/lam/lib/lamPDF.inc
@@ -1,4 +1,6 @@
fontName = $fontName;
if (!defined('FPDF_FONTPATH')) {
define('FPDF_FONTPATH', dirname(__FILE__) . '/font/');
@@ -72,7 +74,7 @@ class lamPDF extends UFPDF {
// Call constructor of superclass
parent::__construct('P','mm','A4');
- $this->page_definitions = $page_definitions;
+ $this->structure = $structure;
// Open PDF file and write some basic information
$this->Open();
@@ -81,7 +83,7 @@ class lamPDF extends UFPDF {
$this->AddFont($this->fontName, 'I', $this->fontList[$this->fontName][2]);
$this->AddFont($this->fontName, 'BI', $this->fontList[$this->fontName][3]);
$this->setFont($this->fontName,"",12);
- $this->setTitle($this->page_definitions['headline']);
+ $this->setTitle($structure->getTitle());
$this->setCreator("LDAP Account Manager");
$this->setMargins('10.0','10.0','10.0');
$this->setAutoPageBreak(true,'20.0');
@@ -91,21 +93,21 @@ class lamPDF extends UFPDF {
* Creates the PDF page header.
*/
function header() {
- if($this->page_definitions['filename'] != 'none') {
- $imageFile = substr(__FILE__,0,strlen(__FILE__)- 14) . "config/pdf/" . $_SESSION['config']->getName() . "/logos/" . $this->page_definitions['filename'];
+ if($this->structure->getLogo() != 'none') {
+ $imageFile = substr(__FILE__,0,strlen(__FILE__)- 14) . "config/pdf/" . $_SESSION['config']->getName() . "/logos/" . $this->structure->getLogo();
$imgProperties = getimagesize($imageFile);
$this->Image($imageFile,10,15,($imgProperties[0] / $this->k) / 5, ($imgProperties[1] / $this->k) / 5,0,"JPG");
}
$this->SetY(23);
$this->SetFont($this->fontName,"B",18);
- $this->Cell(170,5,$this->page_definitions['headline'],0,1,"R",0);
+ $this->Cell(170,5,$this->structure->getTitle(), 0, 1, "R", 0);
$this->Ln(3);
$this->SetLineWidth(0.4);
$this->Line(10,38,200,38);
$this->Line(10,40,200,40);
$this->SetY(50);
//set folding marks
- if (isset($this->page_definitions['foldingmarks']) && ($this->page_definitions['foldingmarks'] == 'standard')) {
+ if ($this->structure->getFoldingMarks() == PDFStructure::FOLDING_STANDARD) {
$this->SetLineWidth(0.2);
$foldingMarks = array(97, 202);
foreach ($foldingMarks as $mark) {
diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc
index 966a1a92..1ef4a0d8 100644
--- a/lam/lib/pdf.inc
+++ b/lam/lib/pdf.inc
@@ -1,8 +1,6 @@
get_type();
// Get PDF structure from xml file
- $load = \LAM\PDF\loadPDFStructure($account_type->getId(), $pdf_structure);
- $structure = $load['structure'];
+ $reader = new PDFStructureReader();
+ $structure = $reader->read($account_type->getId(), $pdf_structure);
// get list of PDF keys
$pdfKeys = array();
- foreach($structure as $entry) {
- if ($entry['tag'] == "SECTION" && $entry['type'] == "open") {
- $key = $entry['attributes']['NAME'];
- // only values with a starting "_" are keys
- if (strpos($key, '_') === 0) {
- $pdfKeys[] = substr($key, 1);
- }
+ foreach($structure->getSections() as $section) {
+ if (!$section instanceof PDFEntrySection) {
+ continue;
}
- if ($entry['tag'] == "ENTRY") {
- $pdfKeys[] = $entry['attributes']['NAME'];
+ if ($section->isAttributeTitle()) {
+ $pdfKeys[] = $section->getPdfKey();
+ }
+ foreach ($section->getEntries() as $entry) {
+ $pdfKeys[] = $entry->getKey();
}
}
$pdfKeys = array_unique($pdfKeys);
@@ -95,7 +89,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
$fontName = "Dejavu";
// Create a new PDF file acording to the account type
- $pdf = new \lamPDF($load['page_definitions'],$fontName);
+ $pdf = new \lamPDF($structure, $fontName);
// Loop over each account and add a new page in the PDF file for it
foreach($accounts as $account) {
@@ -107,28 +101,10 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
$entries = $account->get_pdfEntries($pdfKeys, $account_type->getId());
// Now create the PDF file acording to the structure with the submitted values
- foreach($structure as $entry) {
- // We have a new section to start
- if($entry['tag'] == "SECTION" && $entry['type'] == "open") {
- $name = $entry['attributes']['NAME'];
- if(preg_match("/^_[a-zA-Z_]+/",$name)) {
- $section_headline = getSectionHeadline($entries[substr($name,1)][0]);
- }
- else {
- $section_headline = $name;
- }
- $pdf->setFont($fontName, "B", LAMPDF_FONT_SIZE_BIG);
- $pdf->Write(0,$section_headline . ":");
- $pdf->Ln(LAMPDF_LINEHEIGHT);
- }
- // We have a section to end
- elseif($entry['tag'] == "SECTION" && $entry['type'] == "close") {
- $pdf->Ln(LAMPDF_LINEHEIGHT * 2);
- }
- // We have to include a static text.
- elseif($entry['tag'] == "TEXT") {
+ foreach ($structure->getSections() as $section) {
+ if ($section instanceof PDFTextSection) {
$pdf->setFont($fontName, "", LAMPDF_FONT_SIZE);
- $info_string = str_replace("\r", "", $entry['value']);
+ $info_string = str_replace("\r", "", $section->getText());
$info_string = explode("\n", $info_string);
foreach ($info_string as $text) {
$pdf->MultiCell(0, LAMPDF_LINEHEIGHT, trim($text), 0, "L", 0);
@@ -136,32 +112,42 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
}
$pdf->Ln(LAMPDF_LINEHEIGHT * 2);
}
- // We have to include an entry from the account
- elseif($entry['tag'] == "ENTRY") {
- // Get name of current entry
- $name = $entry['attributes']['NAME'];
- // skip non-existent entries
- if (isset($entries[$name])) {
- // Get current entry
- $valueEntries = $entries[$name];
-
- // Print entry only when module sumitted values for it
- if(is_array($valueEntries)) {
- // Loop over all rows of this entry (most of the time this will be just one)
- foreach($valueEntries as $valueEntry) {
- if ($valueEntry instanceof PDFLabelValue) {
- printLabelValue($pdf, $valueEntry, $fontName);
- }
- else if ($valueEntry instanceof PDFTable) {
- printTable($pdf, $valueEntry, $fontName);
+ elseif ($section instanceof PDFEntrySection) {
+ // section headline
+ if($section->isAttributeTitle()) {
+ $section_headline = getSectionHeadline($entries[$section->getPdfKey()][0]);
+ }
+ else {
+ $section_headline = $section->getTitle();
+ }
+ $pdf->setFont($fontName, "B", LAMPDF_FONT_SIZE_BIG);
+ $pdf->Write(0,$section_headline . ":");
+ $pdf->Ln(LAMPDF_LINEHEIGHT);
+ // entries
+ foreach ($section->getEntries() as $entry) {
+ // skip non-existent entries
+ if (isset($entries[$entry->getKey()])) {
+ // Get current entry
+ $valueEntries = $entries[$entry->getKey()];
+ // Print entry only when module sumitted values for it
+ if(is_array($valueEntries)) {
+ // Loop over all rows of this entry (most of the time this will be just one)
+ foreach($valueEntries as $valueEntry) {
+ if ($valueEntry instanceof PDFLabelValue) {
+ printLabelValue($pdf, $valueEntry, $fontName);
+ }
+ else if ($valueEntry instanceof PDFTable) {
+ printTable($pdf, $valueEntry, $fontName);
+ }
}
}
}
}
+ // section end
+ $pdf->Ln(LAMPDF_LINEHEIGHT * 2);
}
}
}
-
// Close PDF
$pdf->Close();
if (!$returnAsString) {
diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc
index f1e8fde6..5cedd21b 100644
--- a/lam/lib/pdfstruct.inc
+++ b/lam/lib/pdfstruct.inc
@@ -71,94 +71,6 @@ function getPDFStructures($typeId, $profile = null) {
return $return;
}
-/**
- * This function is used to get the PDF structure from XML file.
- *
- * @param string $typeId the account type
- * @param string $name structure name
- *
- * @return array PDF structure
- */
-function loadPDFStructure($typeId, $name='default') {
- if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
- return null;
- }
- $parser = new xmlParser();
- $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
- $xml = $parser->parse($file);
- $border = array();
- $structure = array();
- $complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager');
- if (!empty($xml)) {
- $border['start'] = $xml[1]['PDF'][0];
- $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes'];
- foreach($page_definitions as $key => $value) {
- $complete_page_definitions[strtolower($key)] = $value;
- unset($page_definitions[$key]);
- }
- $border['end'] = $xml[1]['PDF'][1];
- $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
- }
- return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
-}
-
-
-/**
- * Saves PDF structure to XML file in format: