diff --git a/lam/HISTORY b/lam/HISTORY
index 50116e1e..022ccb86 100644
--- a/lam/HISTORY
+++ b/lam/HISTORY
@@ -1,5 +1,6 @@
March 2017
- 2-factor authentication for admin login and self service with privacyIDEA
+ - Updated Debian dependencies
18.12.2016 5.6
diff --git a/lam/docs/devel/upgrade.htm b/lam/docs/devel/upgrade.htm
index 199d5603..822a3da4 100644
--- a/lam/docs/devel/upgrade.htm
+++ b/lam/docs/devel/upgrade.htm
@@ -19,6 +19,7 @@
+
@@ -49,7 +50,14 @@ This is a list of API changes for all LAM releases.
+
tag
- $p_pattern = '/( (.+)<\/p>(.*<\/block>)/';
- // PCRE matching a
tag
- $br_pattern = '/
/';
-
- $return = array();
- if(preg_match($key_pattern,$line,$matches)) {
- $key = true;
- $line_width = $line_width - 50;
- $format = processFormatTags($matches[2],'B');
- $return[] = array('setFont',array($fontName,$format[0],7));
- $return[] = array('Cell',array(50,5,$format[1] . ':',0,0,'R',0));
- $return[] = array('setFont',array($fontName,'',7));
- return array_merge($return,processLine($matches[1] . $matches[3],false,$fontName));
- }
- elseif(preg_match($value_pattern,$line,$matches)) {
- $format = processFormatTags($matches[2],'');
- $return[] = array('setFont',array($fontName,$format[0],7));
- $return[] = array('MultiCell',array(0,5,$format[1],0,'L',0));
- $return[] = array('setFont',array($fontName,'',7));
- return array_merge($return,processLine($matches[1] . $matches[3],true,$fontName));
- }
- elseif(preg_match($p_pattern,$line,$matches)) {
- $format = processFormatTags($matches[2],'');
- $return[] = array('setFont',array($fontName,$format[0],7));
- $return[] = array('Write',array(5,$format[1]));
- $return[] = array('setFont',array($fontName,'',7));
- return array_merge($return,processLine($matches[1] . $matches[3],true,$fontName));
- }
- elseif(preg_match($td_pattern,$line,$matches)) {
- if($first_td && $key) {
- $first_td = !$first_td;
- $return[] = array('Cell',array(50,5,'',0,0,'L',0));
- }
- $format = processFormatTags($matches[3],'');
- $attrs = processAttributes($matches[2],array('width' => $line_width,'height' => 5,'align' => 'L'));
- $return[] = array('setFont',array($fontName,$format[0],7));
- $return[] = array('Cell',array($attrs['width'],$attrs['height'],$format[1],0,0,$attrs['align'],0));
- $return[] = array('setFont',array($fontName,'',7));
- return array_merge($return,processLine($matches[1] . $matches[4],$first_td,$fontName));
- }
- elseif(preg_match($br_pattern,$line,$matches)) {
- return array(array('Ln',array(5)));
- }
- elseif(preg_match($block_pattern,$line,$matches)) {
- $line_width = LAMPDF_LINEWIDTH;
- return array();
- }
- elseif(preg_match($tr_pattern,$line,$matches)) {
- $line_width = LAMPDF_LINEWIDTH;
- return array(array('Ln',array(5)));
- }
+function printLabelValue(&$pdf, $valueEntry, $fontName) {
+ $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE);
+ $pdf->Cell(LAMPDF_LABELWIDTH, LAMPDF_LINEHEIGHT, $valueEntry->getLabel() . ':', 0, 0, 'R', 0);
+ $pdf->SetFont($fontName, '', LAMPDF_FONT_SIZE);
+ $pdf->MultiCell(0, LAMPDF_LINEHEIGHT, $valueEntry->getValue(), 0, 'L', 0);
+ $pdf->Ln(0);
}
/**
- * Formats the XML code.
+ * Prints a PDFTable entry.
*
- * @param string $line XML code of PDF entry
- * @param string $style style commands
- *
- * @return array XML code
+ * @param lamPDF $pdf PDF
+ * @param PDFTable $table entry
+ * @param string $fontName font name
*/
-function processFormatTags($line,$style) {
- // PCRE matching a tag
- $i_pattern = '/(.*)(.+)<\/i>(.*)/';
- // PCRE matching a tag
- $b_pattern = '/(.*)(.+)<\/b>(.*)/';
- // PCRE matching a tag
- $u_pattern = '/(.*)(.+)<\/u>(.*)/';
- // Replacement pattern when one of the above pattern matched
- $replace = "\$1\$2\$3";
-
- if(preg_match($i_pattern,$line,$matches)) {
- $style .= "I";
- $line = preg_replace($i_pattern,$replace,$line);
+function printTable(&$pdf, $table, $fontName) {
+ if (!empty($table->getHeadline())) {
+ $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE);
+ $pdf->Cell(LAMPDF_LABELWIDTH, LAMPDF_LINEHEIGHT, $table->getHeadline() . ':', 0 , 0, 'L', 0);
+ $pdf->Ln(LAMPDF_LINEHEIGHT);
}
- if(preg_match($b_pattern,$line,$matches)) {
- $style .= "B";
- $line = preg_replace($b_pattern,$replace,$line);
+ foreach ($table->rows as $row) {
+ foreach ($row->cells as $cell) {
+ $width = $cell->width;
+ if (!empty($width) && (strpos($width, '%') !== false)) {
+ $width = ceil(LAMPDF_LINEWIDTH * substr($width, 0, -1) / 100);
+ }
+ if ($cell->bold) {
+ $pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE);
+ }
+ $pdf->Cell($width, LAMPDF_LINEHEIGHT, $cell->content, 0, 0, $cell->align, 0);
+ if ($cell->bold) {
+ $pdf->SetFont($fontName, '', LAMPDF_FONT_SIZE);
+ }
+ }
+ $pdf->Ln(LAMPDF_LINEHEIGHT);
}
- if(preg_match($u_pattern,$line,$matches)) {
- $style .= "U";
- $line = preg_replace($u_pattern,$replace,$line);
- }
- return array($style,$line);
+ $pdf->Ln(LAMPDF_LINEHEIGHT);
}
/**
- * Processes width, height and alignment attributes.
+ * Common interface for all PDF entries.
*
- * @param string $attrs attributes
- * @param array $return XML code
- *
- * @return array XML code
+ * @package PDF
+ * @author Roland Gruber
*/
-function processAttributes($attrs,$return = array()) {
- global $line_width;
+interface PDFEntry {
- // PCRE matching width attribute
- $width_pattern = '/(.*)width\=\"(\\d+)(\%?)\"(.*)/';
- // PCRE matching height attribute
- $height_pattern = '/(.*)height\=\"(\\d+)\"(.*)/';
- // PCRE matching align attribute
- $align_pattern = '/(.*)align\=\"(L|R|C)\"(.*)/';
+ /**
+ * Returns the head line of the entry.
+ *
+ * @return string label
+ */
+ public function getHeadline();
+
+}
+
+/**
+ * Represents a table for PDF export.
+ *
+ * @package PDF
+ * @author Roland Gruber
+ */
+class PDFTable implements PDFEntry {
+
+ /** optional label of table */
+ private $label = '';
+ /** list of PDFTableRow elements */
+ public $rows = array();
+
+ /**
+ * Constructor
+ *
+ * @param String $label label
+ */
+ public function __construct($label = null) {
+ $this->label = $label;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see PDFEntry::getHeadline()
+ */
+ public function getHeadline() {
+ return $this->label;
+ }
+
+}
+
+/**
+ * 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 $width width (e.g. "20%")
+ * @param String $align cell alignment (default: left)
+ * @param boolean $bold print in bold
+ */
+ public function __construct($content, $width = null, $align = null, $bold = false) {
+ $this->content = empty($content) ? ' ' : $content;
+ $this->align = ($align == null) ? self::ALIGN_LEFT : $align;
+ $this->width = $width;
+ $this->bold = $bold;
+ }
+
+}
+
+/**
+ * Simple PDF object to print label value entries.
+ *
+ * @package PDF
+ * @author Roland Gruber
+ */
+class PDFLabelValue implements PDFEntry {
+
+ private $label = '';
+
+ private $value = '';
+
+ /**
+ * Constructor
+ *
+ * @param string $label label
+ * @param string $value value
+ */
+ public function __construct($label, $value) {
+ $this->label = $label;
+ $this->value = $value;
+ }
+
+ /**
+ * Returns the label.
+ *
+ * @return string $label label
+ */
+ public function getLabel() {
+ return $this->label;
+ }
+
+ /**
+ * Returns the value.
+ *
+ * @return string $value value
+ */
+ public function getValue() {
+ return $this->value;
+ }
+
+ /**
+ * {@inheritDoc}
+ * @see PDFEntry::getHeadline()
+ */
+ public function getHeadline() {
+ return $this->value;
+ }
- // Remove leading and trailing whitespaces
- $attrs = trim($attrs);
-
- if(preg_match($width_pattern,$attrs,$matches)) {
- if($matches[3] == '%') {
- $return['width'] = ceil($line_width * $matches[2] / 100);
- }
- else {
- $return['width'] = ceil($matches[2]);
- }
- return processAttributes($matches[1] . $matches[4],$return);
- }
- elseif(preg_match($height_pattern,$attrs,$matches)) {
- $return['height'] = $matches[2];
- return processAttributes($matches[1] . $matches[3],$return);
- }
- elseif(preg_match($align_pattern,$attrs,$matches)) {
- $return['align'] = $matches[2];
- return processAttributes($matches[1] . $matches[3],$return);
- }
- else {
- return $return;
- }
}
diff --git a/lam/lib/upload.inc b/lam/lib/upload.inc
index 119d8d5e..5d400325 100644
--- a/lam/lib/upload.inc
+++ b/lam/lib/upload.inc
@@ -294,7 +294,7 @@ class Uploader {
break;
}
// create and save PDF
- $pdfContent = createModulePDF(array($_SESSION['mass_pdfAccount']), $pdfStructure, true);
+ $pdfContent = \LAM\PDF\createModulePDF(array($_SESSION['mass_pdfAccount']), $pdfStructure, true);
$fileName = $dn . '.pdf';
$pdfZip->addFromString($fileName, $pdfContent);
$_SESSION['mass_pdf']['counter'] ++;
diff --git a/lam/lib/xml_parser.inc b/lam/lib/xml_parser.inc
index f06bb328..fb425911 100644
--- a/lam/lib/xml_parser.inc
+++ b/lam/lib/xml_parser.inc
@@ -60,7 +60,8 @@ class xmlParser {
if(file_exists($filename)) {
$xmlStructure = array();
$xmlIndex = array();
- xml_parse_into_struct($this->xmlParser, implode("\n", file($filename)), $xmlStructure, $xmlIndex);
+ $xmlContent =
+ xml_parse_into_struct($this->xmlParser, implode("", file($filename)), $xmlStructure, $xmlIndex);
return array($xmlStructure, $xmlIndex);
}
return array();
diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php
index aa295ac2..e31b46f1 100644
--- a/lam/templates/pdfedit/pdfpage.php
+++ b/lam/templates/pdfedit/pdfpage.php
@@ -143,11 +143,11 @@ if(isset($_GET['submit'])) {
// add a new text field
elseif(isset($_GET['add_text'])) {
// Check if text for static text field is specified
- if(!isset($_GET['text_text']) || ($_GET['text_text'] == '')) {
+ if(empty($_GET['text_text'])) {
StatusMessage('ERROR',_('No static text specified'),_('The static text must contain at least one character.'));
}
else {
- $entry = array(array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => $_GET['text_text']));
+ $entry = array(array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => str_replace("\r", "\n", $_GET['text_text'])));
// Insert new field in structure
array_splice($_SESSION['currentPDFStructure'],$_GET['add_text_position'],0,$entry);
}