new PDF model
This commit is contained in:
parent
b527ad253b
commit
af3c0965bf
|
@ -1704,6 +1704,8 @@ class htmlOutputText extends htmlElement {
|
||||||
private $markAsRequired = false;
|
private $markAsRequired = false;
|
||||||
/** no wrap */
|
/** no wrap */
|
||||||
private $noWrap = false;
|
private $noWrap = false;
|
||||||
|
/** preformatted */
|
||||||
|
private $isPreformatted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -1736,6 +1738,9 @@ class htmlOutputText extends htmlElement {
|
||||||
if ($this->isBold) {
|
if ($this->isBold) {
|
||||||
echo "<b>";
|
echo "<b>";
|
||||||
}
|
}
|
||||||
|
if ($this->isPreformatted) {
|
||||||
|
echo "<pre>";
|
||||||
|
}
|
||||||
if ($this->escapeHTML) {
|
if ($this->escapeHTML) {
|
||||||
echo htmlspecialchars($this->string);
|
echo htmlspecialchars($this->string);
|
||||||
}
|
}
|
||||||
|
@ -1747,6 +1752,9 @@ class htmlOutputText extends htmlElement {
|
||||||
if (is_dir("../graphics")) $graphicsPath = "../graphics";
|
if (is_dir("../graphics")) $graphicsPath = "../graphics";
|
||||||
echo '<img src="' . $graphicsPath . '/required.png" alt="required" width=16 height=16 title="' . _('required') . '">';
|
echo '<img src="' . $graphicsPath . '/required.png" alt="required" width=16 height=16 title="' . _('required') . '">';
|
||||||
}
|
}
|
||||||
|
if ($this->isPreformatted) {
|
||||||
|
echo "</pre>";
|
||||||
|
}
|
||||||
if ($this->isBold) {
|
if ($this->isBold) {
|
||||||
echo "</b>";
|
echo "</b>";
|
||||||
}
|
}
|
||||||
|
@ -1783,6 +1791,15 @@ class htmlOutputText extends htmlElement {
|
||||||
$this->noWrap = $noWrap;
|
$this->noWrap = $noWrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if the text is preformatted.
|
||||||
|
*
|
||||||
|
* @param boolean $preformatted is preformatted (default true)
|
||||||
|
*/
|
||||||
|
public function setPreformatted($preformatted = true) {
|
||||||
|
$this->isPreformatted = $preformatted;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -71,6 +71,37 @@ function getPDFStructures($typeId, $profile = null) {
|
||||||
return $return;
|
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 loadPDFStructureOld($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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used to get the PDF structure from XML file.
|
* This function is used to get the PDF structure from XML file.
|
||||||
*
|
*
|
||||||
|
@ -102,6 +133,65 @@ function loadPDFStructure($typeId, $name='default') {
|
||||||
return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
|
return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a PDF structure file.
|
||||||
|
*
|
||||||
|
* @param string $file file name
|
||||||
|
* @return PDFStructure structure
|
||||||
|
*/
|
||||||
|
function _readPDFFile($file) {
|
||||||
|
$xml = new \XMLReader();
|
||||||
|
$xml->open($file);
|
||||||
|
$structure = new PDFStructure();
|
||||||
|
// open <pdf>
|
||||||
|
$xml->read();
|
||||||
|
if (!$xml->name == 'pdf') {
|
||||||
|
throw new \LAMException(_('Unable to read PDF structure.'));
|
||||||
|
}
|
||||||
|
$structure->setLogo($xml->getAttribute('filename'));
|
||||||
|
$structure->setTitle($xml->getAttribute('headline'));
|
||||||
|
$foldingMarks = $xml->getAttribute('foldingmarks');
|
||||||
|
if ($foldingMarks === 'yes') {
|
||||||
|
$structure->setFoldingMarks(true);
|
||||||
|
}
|
||||||
|
$sections = array();
|
||||||
|
while ($xml->read()) {
|
||||||
|
if ($xml->name === '#text') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
elseif (($xml->name === 'pdf') && ($xml->nodeType == \XMLReader::END_ELEMENT)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
elseif ($xml->name === 'text') {
|
||||||
|
$xml->read();
|
||||||
|
$sections[] = new PDFTextSection($xml->value);
|
||||||
|
$xml->read();
|
||||||
|
if (!$xml->name === 'text') {
|
||||||
|
throw new \LAMException(_('Unable to read PDF structure.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elseif ($xml->name === 'section') {
|
||||||
|
$section = new PDFEntrySection();
|
||||||
|
while ($xml->read()) {
|
||||||
|
if (($xml->name === 'section') && ($xml->nodeType == \XMLReader::END_ELEMENT)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!$xml->name === 'entry') {
|
||||||
|
throw new \LAMException(_('Unable to read PDF structure.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sections[] = $section;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
echo '#' . $xml->name . '#';
|
||||||
|
throw new \LAMException(_('Unable to read PDF structure.'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$xml->close();
|
||||||
|
print_r($sections);
|
||||||
|
$structure->setSections($sections);
|
||||||
|
return $structure;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves PDF structure to XML file in format: <name>.<typeId>.xml
|
* Saves PDF structure to XML file in format: <name>.<typeId>.xml
|
||||||
|
@ -382,4 +472,131 @@ function installPDFTemplates() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF structure
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*/
|
||||||
|
class PDFStructure {
|
||||||
|
|
||||||
|
private $logo = null;
|
||||||
|
|
||||||
|
private $title = null;
|
||||||
|
|
||||||
|
private $foldingMarks = false;
|
||||||
|
|
||||||
|
private $sections = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the logo file path.
|
||||||
|
*
|
||||||
|
* @return string logo
|
||||||
|
*/
|
||||||
|
public function getLogo() {
|
||||||
|
return $this->logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the logo file path.
|
||||||
|
*
|
||||||
|
* @param string $logo logo
|
||||||
|
*/
|
||||||
|
public function setLogo($logo) {
|
||||||
|
$this->logo = $logo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the title.
|
||||||
|
*
|
||||||
|
* @return string title
|
||||||
|
*/
|
||||||
|
public function getTitle() {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the title.
|
||||||
|
*
|
||||||
|
* @param string $title title
|
||||||
|
*/
|
||||||
|
public function setTitle($title) {
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if to print folding marks.
|
||||||
|
*
|
||||||
|
* @return boolean print folding marks
|
||||||
|
*/
|
||||||
|
public function getFoldingMarks() {
|
||||||
|
return $this->foldingMarks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets if to print folding marks.
|
||||||
|
*
|
||||||
|
* @param boolean $foldingMarks print folding marks
|
||||||
|
*/
|
||||||
|
public function setFoldingMarks($foldingMarks) {
|
||||||
|
$this->foldingMarks = $foldingMarks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the sections.
|
||||||
|
*
|
||||||
|
* @return PDFTextSection[]|PDFEntrySection[] $sections
|
||||||
|
*/
|
||||||
|
public function getSections() {
|
||||||
|
return $this->sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the sections.
|
||||||
|
*
|
||||||
|
* @param PDFTextSection[]|PDFEntrySection[] $sections sections
|
||||||
|
*/
|
||||||
|
public function setSections($sections) {
|
||||||
|
$this->sections = $sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Section for static text.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*/
|
||||||
|
class PDFTextSection {
|
||||||
|
|
||||||
|
private $text = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param string $text text
|
||||||
|
*/
|
||||||
|
public function __construct($text) {
|
||||||
|
$this->text = $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the text.
|
||||||
|
*
|
||||||
|
* @return string text
|
||||||
|
*/
|
||||||
|
public function getText() {
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PDF section that contains LDAP data entries.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*/
|
||||||
|
class PDFEntrySection {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -574,6 +574,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
|
||||||
$structureContent->addElement($linkRemove, true);
|
$structureContent->addElement($linkRemove, true);
|
||||||
$structureContent->addElement(new htmlSpacer('10px', null));
|
$structureContent->addElement(new htmlSpacer('10px', null));
|
||||||
$staticTextOutput = new htmlOutputText($entry['value']);
|
$staticTextOutput = new htmlOutputText($entry['value']);
|
||||||
|
$staticTextOutput->setPreformatted();
|
||||||
$structureContent->addElement($staticTextOutput, true);
|
$structureContent->addElement($staticTextOutput, true);
|
||||||
}
|
}
|
||||||
// We have to include an entry from the account
|
// We have to include an entry from the account
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
|
||||||
|
Copyright (C) 2017 Roland Gruber
|
||||||
|
|
||||||
|
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
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
include_once 'lam/lib/pdfstruct.inc';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a sample PDF structure.
|
||||||
|
*
|
||||||
|
* @author Roland Gruber
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class ReadStructureTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
const TEST_FILE = 'lam/tests/resources/pdf/test.xml';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the sample structure.
|
||||||
|
*/
|
||||||
|
public function testRead() {
|
||||||
|
$structure = \LAM\PDF\_readPDFFile(ReadStructureTest::TEST_FILE);
|
||||||
|
$this->assertEquals('printLogo.jpg', $structure->getLogo());
|
||||||
|
$this->assertEquals('User information', $structure->getTitle());
|
||||||
|
$this->assertEquals(true, $structure->getFoldingMarks());
|
||||||
|
$this->assertEquals(3, sizeof($structure->getSections()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<pdf filename="printLogo.jpg" headline="User information" type="user" foldingmarks="yes">
|
||||||
|
<section name="Personal user information">
|
||||||
|
<entry name="inetOrgPerson_givenName" />
|
||||||
|
<entry name="inetOrgPerson_sn" />
|
||||||
|
</section>
|
||||||
|
<text>test text</text>
|
||||||
|
<section name="_posixAccount_uid">
|
||||||
|
<entry name="posixAccount_homeDirectory" />
|
||||||
|
<entry name="posixAccount_loginShell" />
|
||||||
|
</section>
|
||||||
|
</pdf>
|
Loading…
Reference in New Issue