moved PDF templates to config/pdf (code from Lukas)

This commit is contained in:
Roland Gruber 2005-07-27 18:38:17 +00:00
parent 924910d030
commit fdefad666f
1 changed files with 32 additions and 91 deletions

View File

@ -22,74 +22,44 @@ $Id$
/** /**
* LDAP Account Manager PDF printing library. It consists of lamPDF class, * LDAP Account Manager PDF printing library. It consists of lamPDF class,
* the createModulePDF() and getAvailablePDFStructure() functions that may * the createModulePDF() function that may be called by other pages
* be called by other pages and furthermore some helper functions. * and furthermore some helper functions.
* *
* @author Michael Dürgner * @author Michael Dürgner
* @package PDF * @package PDF
* @copyright Copyright (C) 2003-2004 Michael Dürgner
* @license GPL
*/ */
/** /** PDF line width */
*
*/
define('LAMPDF_LINEWIDTH',190); define('LAMPDF_LINEWIDTH',190);
/** /** PDF generator class */
*
*/
include_once("fpdf.php"); include_once("fpdf.php");
/** /** Unicode support for FPDF */
*
*/
include_once("ufpdf.php"); include_once("ufpdf.php");
/** /** XML functions */
*
*/
include_once('xml_parser.inc'); include_once('xml_parser.inc');
/** access to PDF configuration files */
include_once('pdfstruct.inc');
$key = false; $key = false;
$line_width = LAMPDF_LINEWIDTH; $line_width = LAMPDF_LINEWIDTH;
/**
* This function will return all available PDF structure definitions for the submitted
* account scope.
*
* @param string The account scope the PDF structure definitions should be
* returned.
*
* @return array All available PDF structure definitions for the submitted account
* scope. Each entry is a string being the filename that may be passed to the
* createModulePDF() function as second argument.
*/
function getAvailablePDFStructures($scope='user') {
$return = array();
$dirHandle = opendir($_SESSION['lampath'] . '/config/pdf/' . $scope . '/');
while($file = readdir($dirHandle)) {
if(!is_dir($file) && $file != '.' && $file != '..') {
array_push($return,$file);
}
}
sort($return);
return $return;
}
/** /**
* This function creates the PDF output of one or more accounts. At the moment * This function creates the PDF output of one or more accounts. At the moment
* this function can create a PDF page for user, group and host accounts. But * this function can create a PDF page for user, group and host accounts. But
* this is not limited by the function itself but by the account types that are * this is not limited by the function itself but by the account types that are
* allowed in LAM and the exsisting PDF structure definitions. * allowed in LAM and the exsisting PDF structure definitions.
* *
* @param array A numbered array containing all accounts the PDF page should * @param array $accounts A numbered array containing all accounts the PDF page should
* be created for. The entries of the array must be AccountContainer objects. * be created for. The entries of the array must be AccountContainer objects.
* @param string The filename of the structure definition that should be used * @param string $pdf_structure The filename of the structure definition that should be used
* to create the PDF page. If not submitted the 'default.xml' structure definition * to create the PDF page. If not submitted the 'default.user' structure definition
* for the appropriate account type. * for the appropriate account type.
*/ */
function createModulePDF($accounts,$pdf_structure="default.xml") { function createModulePDF($accounts,$pdf_structure="default") {
global $key; global $key;
@ -98,9 +68,8 @@ function createModulePDF($accounts,$pdf_structure="default.xml") {
if($account_type == "" || $account_type != $accounts[0]->get_type()) { if($account_type == "" || $account_type != $accounts[0]->get_type()) {
$account_type = $accounts[0]->get_type(); $account_type = $accounts[0]->get_type();
} }
// Get PDF structure from xml file // Get PDF structure from xml file
$load = getStructure($account_type,$pdf_structure); $load = loadPDFStructureDefinitions($account_type,$pdf_structure);
$structure = $load['structure']; $structure = $load['structure'];
// The decimal separator must be a dot in order to write pdf-files // The decimal separator must be a dot in order to write pdf-files
@ -219,39 +188,11 @@ function createModulePDF($accounts,$pdf_structure="default.xml") {
} }
/** /**
* Creates a section headline.
* *
* @param string $line section name
* *
* @param string * @return string XML code for headline
* @param string
*
* @return array
*/
function getStructure($scope,$pdf_structure) {
$parser = new xmlParser();
$xml = $parser->parse($_SESSION['lampath'] . '/config/pdf/' . $scope . '/' . $pdf_structure);
$border = array();
$structure = array();
$complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager', 'margin-top' => '10.0', 'margin-bottom' => '20.0', 'margin-left' => '10.0', 'margin-right' => '10.0');
if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) {
$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);
}
/**
*
*
* @param string
*
* @return string
*/ */
function getSectionHeadline($line) { function getSectionHeadline($line) {
$headline_pattern = '/<block>.*<value>(.*)<\/value><\/block>/'; $headline_pattern = '/<block>.*<value>(.*)<\/value><\/block>/';
@ -265,12 +206,12 @@ function getSectionHeadline($line) {
} }
/** /**
* Creates the XML code for an PDF entry.
* *
* @param string $line XML code of PDF entry
* @param boolean $first_td True if this is the first column
* *
* @param string * @return array XML codes
* @param boolean
*
* @return array
*/ */
function processLine($line,$first_td = true, $fontName) { function processLine($line,$first_td = true, $fontName) {
global $key, $line_width; global $key, $line_width;
@ -335,12 +276,12 @@ function processLine($line,$first_td = true, $fontName) {
} }
/** /**
* Formats the XML code.
* *
* @param string $line XML code of PDF entry
* @param string $style style commands
* *
* @param string * @return array XML code
* @param string
*
* @return array
*/ */
function processFormatTags($line,$style) { function processFormatTags($line,$style) {
// PCRE matching a <i> tag // PCRE matching a <i> tag
@ -368,12 +309,12 @@ function processFormatTags($line,$style) {
} }
/** /**
* Processes width, height and alignment attributes.
* *
* @param string $attrs attributes
* @param array $return XML code
* *
* @param string * @return array XML code
* @param array
*
* @return array
*/ */
function processAttributes($attrs,$return = array()) { function processAttributes($attrs,$return = array()) {
global $line_width; global $line_width;
@ -440,10 +381,10 @@ class lamPDF extends UFPDF {
/** /**
* *
* *
* @param string * @param string $account_type
* @param array * @param array $page_definitions
*/ */
function lamPDF($account_type = "User",$page_definitions = array(),$fontName) { function lamPDF($account_type = "user",$page_definitions = array(),$fontName) {
$this->fontName = $fontName; $this->fontName = $fontName;
define('FPDF_FONTPATH', $_SESSION['lampath'] . "lib/" . 'font/'); define('FPDF_FONTPATH', $_SESSION['lampath'] . "lib/" . 'font/');
// Call constructor of superclass // Call constructor of superclass