Merge pull request #25 from LDAPAccountManager/new_pdf_api

New pdf api
This commit is contained in:
gruberroland 2017-02-19 09:25:56 +01:00 committed by GitHub
commit 7c94b6e13f
49 changed files with 547 additions and 625 deletions

View File

@ -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

View File

@ -19,6 +19,7 @@
@ -49,7 +50,14 @@ This is a list of API changes for all LAM releases.
<br>
<h2>5.6 -&gt; 5.7</h2>
<ul>
<li>module interface: get_pdfEntries() must return an array key =&gt;
PDFEntry (no action required if you did not build the XML yourself)<span style="color: rgb(34, 31, 30); font-family: Sans,sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: rgb(214, 210, 208); display: inline ! important; float: none;"></span></li>
</ul>
<br>
<h2>5.5 -&gt; 5.6</h2>
<ul>
<li>
Functions in lib/types.inc got namespace LAM/TYPES (e.g. getTypeAlias()).</li>

View File

@ -1,9 +1,11 @@
<?php
use \LAM\PDF\PDFLabelValue;
use \LAM\PDF\PDFTable;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2016 Roland Gruber
Copyright (C) 2003 - 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
@ -33,6 +35,9 @@ $Id$
* @see baseModule
*/
/** PDF functions */
include_once('pdf.inc');
/**
* Parent class of all account modules.
* It implements the complete module interface and uses meta-data
@ -808,7 +813,7 @@ abstract class baseModule {
* Returns the PDF entries for this module.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return array list of possible PDF entries
* @return PDFEntry[] list of key => PDFEntry
*/
public function get_pdfEntries($pdfKeys) {
return array();
@ -831,14 +836,9 @@ abstract class baseModule {
if (isset($this->attributes[$attrName]) && (sizeof($this->attributes[$attrName]) > 0)) {
natcasesort($this->attributes[$attrName]);
$value = implode($delimiter, $this->attributes[$attrName]);
// TODO workarounds for PDF parser, remove when migrated to other PDF library
$value = str_replace("\r\n", " ", $value);
$value = str_replace("\n", " ", $value);
$value = str_replace("\r", " ", $value);
// TODO workaround for UFPDF, remove when migrated to other PDF library
$value = trim($value);
}
$result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
$result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value);
}
/**
@ -855,7 +855,7 @@ abstract class baseModule {
natcasesort($value);
$value = implode($delimiter, $value);
}
$result[get_class($this) . '_' . $name] = array('<block><key>' . $label . '</key><value>' . $value . '</value></block>');
$result[get_class($this) . '_' . $name][] = new PDFLabelValue($label, $value);
}
/**
@ -869,19 +869,7 @@ abstract class baseModule {
if (empty($table->rows)) {
return;
}
if (!empty($table->label)) {
$result[get_class($this) . '_' . $name][] = '<block><tr><td><b>' . $table->label . ':</b></td></tr></block>';
}
foreach ($table->rows as $row) {
$xml = '<block><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;
}
$result[get_class($this) . '_' . $name][] = $table;
}
/**
@ -1963,80 +1951,4 @@ 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();
/**
* Constructor
*
* @param String $label label
*/
public function __construct($label = null) {
$this->label = $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;
}
}
?>

View File

@ -5,7 +5,7 @@ use LAM\TYPES\ConfiguredType;
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2016 Roland Gruber
Copyright (C) 2003 - 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
@ -609,7 +609,7 @@ class lamList {
if ($option == 'DN') {
$_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF");
$_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount']));
$filename = createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct);
$filename = \LAM\PDF\createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct);
unset($_SESSION["accountPDF"]);
}
// create for all selected accounts
@ -624,7 +624,7 @@ class lamList {
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
$filename = createModulePDF($list,$pdfStruct);
$filename = \LAM\PDF\createModulePDF($list,$pdfStruct);
for ($i = 0; $i < sizeof($accounts); $i++) {
unset($_SESSION["accountPDF-$i"]);
}
@ -640,7 +640,7 @@ class lamList {
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
$filename = createModulePDF($list,$pdfStruct);
$filename = \LAM\PDF\createModulePDF($list,$pdfStruct);
for ($i = 0; $i < $entriesCount; $i++) {
// clean session
unset($_SESSION["accountPDF-$i"]);
@ -648,7 +648,7 @@ class lamList {
}
}
elseif ($option == 'SESSION') {
$filename = createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct);
$filename = \LAM\PDF\createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct);
unset($_SESSION[$_POST['PDFSessionID']]);
}
if ($filename != '') {

View File

@ -2006,7 +2006,7 @@ class accountContainer {
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* @return PDFEntry[] list of key => PDFEntry
*/
function get_pdfEntries($pdfKeys) {
$return = array();
@ -2018,7 +2018,7 @@ class accountContainer {
if (isset($this->finalDN)) {
$dn = $this->finalDN;
}
$return = array_merge($return,array('main_dn' => array('<block><key>' . _('DN') . '</key><value>' . $dn . '</value></block>')));
$return = array_merge($return,array('main_dn' => array(new \LAM\PDF\PDFLabelValue(_('DN'), $dn))));
return $return;
}

View File

@ -220,10 +220,8 @@ class account extends baseModule {
}
/**
* Returns the PDF entries for this module.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return array list of possible PDF entries
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -975,10 +975,8 @@ class asteriskAccount extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,11 +1,13 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2009 - 2012 Pavel Pozdniak
2009 - 2015 Roland Gruber
2009 - 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
@ -795,10 +797,8 @@ class asteriskExtension extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$a = $this->attributes;

View File

@ -362,10 +362,8 @@ class asteriskVoicemail extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -221,10 +221,8 @@ class authorizedServiceObject extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -403,10 +403,8 @@ class ddns extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
public function get_pdfEntries($pdfKeys) {
// attributes are taken from DHCP server object

View File

@ -657,10 +657,8 @@ By default, the nodes are configured as H-Nodes which fits for small networks. I
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$nodeType = $this->getDHCPOption('netbios-node-type');

View File

@ -548,10 +548,8 @@ class eduPerson extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,10 +1,13 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2008 Thomas Manninger
2008 - 2015 Roland Gruber
2008 - 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
@ -728,10 +731,8 @@ class fixed_ip extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -685,10 +685,8 @@ class freeRadius extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -195,10 +195,8 @@ class hostObject extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -155,10 +155,8 @@ class ieee802device extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -344,10 +344,8 @@ class inetLocalMailRecipient extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1970,10 +1970,8 @@ class inetOrgPerson extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -390,10 +390,8 @@ class kolabGroup extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -510,10 +510,8 @@ class kolabSharedFolder extends baseModule { // TODO folder type
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2015 Roland Gruber
Copyright (C) 2004 - 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
@ -696,10 +699,8 @@ class kolabUser extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2005 - 2015 Roland Gruber
Copyright (C) 2005 - 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
@ -279,10 +282,8 @@ class ldapPublicKey extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -465,10 +465,8 @@ class nisMailAlias extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -521,10 +521,8 @@ class nisMailAliasUser extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2016 Roland Gruber
Copyright (C) 2016 - 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
@ -249,10 +252,8 @@ class nisNetGroupHost extends nisNetGroupUser {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2015 - 2016 Roland Gruber
Copyright (C) 2015 - 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
@ -467,10 +470,8 @@ class nisNetGroupUser extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2009 - 2015 Roland Gruber
Copyright (C) 2009 - 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
@ -569,10 +572,8 @@ class nisnetgroup extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1826,10 +1826,8 @@ class posixAccount extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$uidLabel = _('User name');

View File

@ -613,10 +613,8 @@ class posixGroup extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is not yet part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2012 - 2016 Roland Gruber
Copyright (C) 2012 - 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
@ -395,10 +398,8 @@ class puppetClient extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -253,10 +253,8 @@ class pykotaBillingCode extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -459,10 +459,8 @@ class pykotaGroup extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -576,10 +576,8 @@ class pykotaPrinter extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2015 Roland Gruber
Copyright (C) 2013 - 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
@ -881,10 +884,8 @@ class pykotaUser extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,10 +1,13 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz
2007 - 2015 Roland Gruber
2007 - 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
@ -608,10 +611,8 @@ class quota extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$this->initQuotas();

View File

@ -1,10 +1,13 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2008 Thomas Manninger
2008 - 2015 Roland Gruber
2008 - 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
@ -761,10 +764,8 @@ class range extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -590,10 +590,8 @@ class sambaDomain extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -529,10 +529,8 @@ class sambaGroupMapping extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1904,10 +1904,8 @@ class sambaSamAccount extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -547,10 +547,8 @@ class shadowAccount extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
function get_pdfEntries($pdfKeys) {
$timeZone = getTimeZone();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2011 - 2015 Roland Gruber
Copyright (C) 2011 - 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
@ -373,10 +376,8 @@ class systemQuotas extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
public function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,9 +1,12 @@
<?php
use \LAM\PDF\PDFTable;
use \LAM\PDF\PDFTableCell;
use \LAM\PDF\PDFTableRow;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2013 - 2016 Roland Gruber
Copyright (C) 2013 - 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
@ -901,10 +904,8 @@ class windowsGroup extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
public function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -281,10 +281,8 @@ class windowsHost extends baseModule {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
public function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -2415,10 +2415,8 @@ class windowsUser extends baseModule implements passwordService {
}
/**
* Returns a list of possible PDF entries for this account.
*
* @param array $pdfKeys list of PDF keys that are included in document
* @return list of PDF entries (array(<PDF key> => <PDF lines>))
* {@inheritDoc}
* @see baseModule::get_pdfEntries()
*/
public function get_pdfEntries($pdfKeys) {
$return = array();

View File

@ -1,10 +1,11 @@
<?php
namespace LAM\PDF;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2004 Michael Duergner
2003 - 2015 Roland Gruber
2003 - 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
@ -31,8 +32,16 @@ $Id$
* @package PDF
*/
/** PDF line width */
define('LAMPDF_LINEWIDTH',190);
/** line width */
define('LAMPDF_LINEWIDTH', 190);
/** line height */
define('LAMPDF_LINEHEIGHT', 5);
/** width of a label */
define('LAMPDF_LABELWIDTH', 50);
/** font size */
define('LAMPDF_FONT_SIZE', 7);
/** font size for bigger text */
define('LAMPDF_FONT_SIZE_BIG', 10);
/** XML functions */
include_once('xml_parser.inc');
@ -40,9 +49,6 @@ include_once('xml_parser.inc');
/** access to PDF configuration files */
include_once('pdfstruct.inc');
$key = false;
$line_width = LAMPDF_LINEWIDTH;
/**
* This function creates the PDF output of one or more accounts.
*
@ -63,8 +69,6 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
/** LAM PDF generator class */
include_once("lamPDF.inc");
global $key;
$account_type = $accounts[0]->get_type();
// Get PDF structure from xml file
$load = \LAM\PDF\loadPDFStructure($account_type->getId(), $pdf_structure);
@ -91,7 +95,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
$fontName = "BitstreamVeraSans-Roman";
// Create a new PDF file acording to the account type
$pdf = new lamPDF($load['page_definitions'],$fontName);
$pdf = new \lamPDF($load['page_definitions'],$fontName);
// Loop over each account and add a new page in the PDF file for it
foreach($accounts as $account) {
@ -113,23 +117,24 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
else {
$section_headline = $name;
}
$pdf->setFont($fontName,"B",10);
$pdf->setFont($fontName, "B", LAMPDF_FONT_SIZE_BIG);
$pdf->Write(0,$section_headline . ":");
$pdf->Ln(6);
$pdf->Ln(LAMPDF_LINEHEIGHT);
}
// We have a section to end
elseif($entry['tag'] == "SECTION" && $entry['type'] == "close") {
$pdf->Ln(9);
$pdf->Ln(LAMPDF_LINEHEIGHT * 2);
}
// We have to include a static text.
elseif($entry['tag'] == "TEXT") {
// Load PDF text from structure array
$info_string = $entry['value'];
// Set font for text
$pdf->setFont($fontName,"",10);
$pdf->MultiCell(0,5,$info_string,0,"L",0);
// Print linebreak afterwards
$pdf->Ln(6);
$pdf->setFont($fontName, "", LAMPDF_FONT_SIZE);
$info_string = str_replace("\r", "", $entry['value']);
$info_string = explode("\n", $info_string);
foreach ($info_string as $text) {
$pdf->MultiCell(0, LAMPDF_LINEHEIGHT, trim($text), 0, "L", 0);
$pdf->Ln(0);
}
$pdf->Ln(LAMPDF_LINEHEIGHT * 2);
}
// We have to include an entry from the account
elseif($entry['tag'] == "ENTRY") {
@ -138,22 +143,21 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
// skip non-existent entries
if (isset($entries[$name])) {
// Get current entry
$value_entry = $entries[$name];
$valueEntries = $entries[$name];
// Print entry only when module sumitted values for it
if(is_array($value_entry)) {
if(is_array($valueEntries)) {
// Loop over all rows of this entry (most of the time this will be just one)
foreach($value_entry as $line) {
// Substitue XML syntax with valid FPDF methods
$methods = processLine($line,true,$fontName);
// Call every method
foreach($methods as $method) {
call_user_func_array(array(&$pdf,$method[0]),$method[1]);
foreach($valueEntries as $valueEntry) {
if ($valueEntry instanceof PDFLabelValue) {
printLabelValue($pdf, $valueEntry, $fontName);
}
else if ($valueEntry instanceof PDFTable) {
printTable($pdf, $valueEntry, $fontName);
}
}
}
}
$key = false;
}
}
}
@ -177,170 +181,208 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
/**
* Creates a section headline.
*
* @param string $line section name
* @param PDFEntry $entry content entry
*
* @return string XML code for headline
* @return string headline
*/
function getSectionHeadline($line) {
$headline_pattern = '/<block>.*<value>(.*)<\/value><\/block>/';
if(preg_match($headline_pattern,$line,$matches)) {
$valueStyle = processFormatTags($matches[1],'');
return $valueStyle[1];
}
else {
return '';
}
function getSectionHeadline($entry) {
return $entry->getHeadline();
}
/**
* Creates the XML code for an PDF entry.
* Prints a PDFLabelValue entry.
*
* @param string $line XML code of PDF entry
* @param boolean $first_td True if this is the first column
* @param String $fontName font name
*
* @return array XML codes
* @param lamPDF $pdf PDF
* @param PDFLabelValue $valueEntry entry
* @param string $fontName font name
*/
function processLine($line, $first_td = true, $fontName) {
global $key, $line_width;
// PCRE matching <block> tag
$block_pattern = '/<block><\/block>/';
// PCRE matching a <key> tag
$key_pattern = '/(<block>)<key>(.+)<\/key>(.*<\/block>)/';
// PCRE matching a <value> tag
// !!FIXME!! value must contain at least one character
$value_pattern = '/(<block>.*)<value>(.*)<\/value>(<\/block>)/';
// PCRE matching a <td> tag
$td_pattern = '/(<block>.*?)<td(.*?)>(.+?)<\/td>(.*<\/block>)/';
// PCRE matching <tr> tag
$tr_pattern = '/<tr><\/tr>/';
// PCRE matching a <p> tag
$p_pattern = '/(<block>.*)<p>(.+)<\/p>(.*<\/block>)/';
// PCRE matching a <br> tag
$br_pattern = '/<br \/>/';
$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 <i> tag
$i_pattern = '/(.*)<i>(.+)<\/i>(.*)/';
// PCRE matching a <b> tag
$b_pattern = '/(.*)<b>(.+)<\/b>(.*)/';
// PCRE matching a <u> tag
$u_pattern = '/(.*)<u>(.+)<\/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(preg_match($u_pattern,$line,$matches)) {
$style .= "U";
$line = preg_replace($u_pattern,$replace,$line);
if ($cell->bold) {
$pdf->SetFont($fontName, 'B', LAMPDF_FONT_SIZE);
}
return array($style,$line);
$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);
}
$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;
}
}

View File

@ -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'] ++;

View File

@ -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();

View File

@ -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);
}