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

This commit is contained in:
Roland Gruber 2005-07-27 18:27:24 +00:00
parent 65d82116f5
commit 924910d030
2 changed files with 88 additions and 75 deletions

View File

@ -21,140 +21,156 @@ $Id$
*/ */
/** /**
* * Functions to manage the PDF structures.
* *
* @author Michael Dürgner * @author Michael Dürgner
* @version 0.5
* @package PDF * @package PDF
* @copyright Copyright (C) 2003-2004 Michael Dürgner
* @license GPL
*/ */
/** /** LAM configuration */
*
*/
include_once("config.inc"); include_once("config.inc");
/** /** LDAP object */
*
*/
include_once("ldap.inc"); include_once("ldap.inc");
/** /**
* This function will return all available PDF structure definitions for the submitted
* account scope.
* *
* @param string $scope The account scope the PDF structure definitions should be
* returned.
* *
* @param string * @return array $scope All available PDF structure definitions for the submitted account
* * scope. Each entry is a string being the filename that may be passed to the
* @return array * createModulePDF() function as second argument.
*/ */
function getPDFStructureDefinitions($scope = "user") { function getPDFStructureDefinitions($scope = "user") {
$return = array(); $return = array();
$path = $_SESSION['lampath'] . 'config/pdf/' . $scope; $path = $_SESSION['lampath'] . 'config/pdf/';
if(is_dir($path)) { if(is_dir($path)) {
$dirHandle = opendir($path); $dirHandle = opendir($path);
while($file = readdir($dirHandle)) { while($file = readdir($dirHandle)) {
if(!is_dir($file) && $file != '.' && $file != '..' && $file != 'default.xml') { $struct_file = explode('.',$file);
array_push($return, substr($file,0,strlen($file)-4)); if(!is_dir($path.$file) && $file != '.' && $file != '..' && $struct_file[1] == $scope) {
array_push($return, $struct_file[0]);
} }
} }
sort($return); sort($return);
} }
return $return; return $return;
} }
/** /**
* This function is used to get pdf structure from xml file.
* Used in createModulePDF.
* *
* @param string $scope The account scope for wich the PDF structure should be returned.
* @param string $pdf_structure Structure name of selected scope wich should be returned.
* *
* @param string * @return array PDF structure
* @param string
*
* @return array
*/ */
function loadPDFStructureDefinitions($scope='user', $definition='default.xml') { function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') {
$parser = new xmlParser(); $parser = new xmlParser();
$file = $_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition; $file = $_SESSION['lampath'] . 'config/pdf/' . $pdf_structure . '.' . $scope . '.xml';
$xml = $parser->parse($file); $xml = $parser->parse($file);
$border = array(); $border = array();
$structure = array(); $structure = array();
$border[$current] = 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');
$page_definitions = array();
if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) { if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) {
$border['start'] = $xml[1]['PDF'][0]; $border['start'] = $xml[1]['PDF'][0];
$page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes']; $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes'];
foreach($page_definitions as $key => $value) { foreach($page_definitions as $key => $value) {
$page_definitions[strtolower($key)] = $value; $complete_page_definitions[strtolower($key)] = $value;
unset($page_definitions[$key]); unset($page_definitions[$key]);
} }
$border['end'] = $xml[1]['PDF'][1]; $border['end'] = $xml[1]['PDF'][1];
} }
$structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
return array('structure' => $structure, 'page_definitions' => $page_definitions); return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
} }
/** /**
* Saves PDF structure definitions to XML file in format: <name>.<scope>.xml
* *
* * @param string $scope account type
* @param string * @param string $definition Name of definition
* @param string * @return string "no perms" if access denied or "ok".
*/ */
function savePDFStructureDefinitions($scope,$definition) { function savePDFStructureDefinitions($scope,$definition) {
$handle = fopen($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition,'w'); if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms';
$pdf_attributes = ''; if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) { $struct_file = ($_SESSION['lampath'] . 'config/pdf/' . $definition . '.' . $scope . '.xml');
if($key != 'type') { if(!is_writable($_SESSION['lampath'] . 'config/pdf/')) {
$pdf_attributes .= ' ' . $key . '="' . $value . '"'; return 'no perms';
}
} }
$file = '<pdf type="' . $scope . "\"" . $pdf_attributes . ">\n"; else {
foreach($_SESSION['currentPDFStructure'] as $entry) { $handle = fopen($struct_file,'w');
$ident = ''; $pdf_attributes = '';
for($i=0;$i<$entry['level'] -1;$i++) { foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
$ident .= "\t"; if($key != 'type') {
} $pdf_attributes .= ' ' . $key . '="' . $value . '"';
$attributes = '';
if(is_array($entry['attributes'])) {
foreach($entry['attributes'] as $key => $value) {
$attributes .= ' ' . strtolower($key) . '="' . $value . '"';
} }
} }
if($entry['type'] == 'open') { $file = '<pdf type="' . $scope . "\"" . $pdf_attributes . ">\n";
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . ">\n"; foreach($_SESSION['currentPDFStructure'] as $entry) {
} $ident = '';
elseif($entry['type'] == 'close') { for($i=0;$i<$entry['level'] -1;$i++) {
$file .= $ident . '</' . strtolower($entry['tag']) . ">\n"; $ident .= "\t";
}
elseif($entry['type'] == 'complete') {
if(isset($entry['value'])) {
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . '>' . $entry['value'] . '</' . strtolower($entry['tag']) . ">\n";
} }
else { $attributes = '';
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . " />\n"; if(is_array($entry['attributes'])) {
foreach($entry['attributes'] as $key => $value) {
$attributes .= ' ' . strtolower($key) . '="' . $value . '"';
}
}
if($entry['type'] == 'open') {
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . ">\n";
}
elseif($entry['type'] == 'close') {
$file .= $ident . '</' . strtolower($entry['tag']) . ">\n";
}
elseif($entry['type'] == 'complete') {
if(isset($entry['value'])) {
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . '>' . $entry['value'] . '</' . strtolower($entry['tag']) . ">\n";
}
else {
$file .= $ident . '<' . strtolower($entry['tag']) . $attributes . " />\n";
}
} }
} }
$file .= "</pdf>";
fwrite($handle,$file);
fclose($handle);
return 'ok';
} }
$file .= "</pdf>";
fwrite($handle,$file);
fclose($handle);
} }
/** /**
* Deletes XML file with PDF structure definitions.
* *
* @param string $scope account type
* @param string $definition Name of definition to delete
* *
* @param string * @return boolean True if file was deleted or false if a problem occured.
* @param string
*
* @return boolean
*/ */
function deletePDFStructureDefinition($scope,$definition) { function deletePDFStructureDefinition($scope, $definition) {
$file = $_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition; if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false;
return unlink($file); if (!preg_match('/[a-zA-Z]+/',$scope)) return false;
$file = $_SESSION['lampath'] . 'config/pdf/' . $definition . '.' . $scope . '.xml';
if(is_file($file) && is_writable($file)) {
return unlink($file);
}
else {
return false;
}
} }
/** /**
* This function returns an array with all aviliable logo images.
* *
* * @return array list of logo files
* @return array
*/ */
function getAvailableLogos() { function getAvailableLogos() {
$return = array(); $return = array();

View File

@ -99,7 +99,7 @@ if(isset($_GET['submit'])) {
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">";
echo "</head>"; echo "</head>";
echo "<body>"; echo "<body>";
if(!isset($_GET['pdfname']) || !preg_match('/[a-zA-Z0-9\-\_\.]+/',$_GET['pdfname'])) { if(!isset($_GET['pdfname']) || !preg_match('/[a-zA-Z0-9\-\_]+/',$_GET['pdfname'])) {
StatusMessage('ERROR', _('PDF-structure name not valid'), _('The name for that PDF-structure you submitted is not valid. A valid name must constist at least of one of the following characters \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\',\'.\'.')); StatusMessage('ERROR', _('PDF-structure name not valid'), _('The name for that PDF-structure you submitted is not valid. A valid name must constist at least of one of the following characters \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\',\'.\'.'));
} }
else { else {
@ -110,9 +110,6 @@ if(isset($_GET['submit'])) {
elseif($return == 'no perms'){ elseif($return == 'no perms'){
StatusMessage('ERROR', _("Could not save PDF profile, access denied."), $_GET['pdfname']); StatusMessage('ERROR', _("Could not save PDF profile, access denied."), $_GET['pdfname']);
} }
elseif($return == 'file exists'){
StatusMessage('ERROR', _("This file already exists."), $_GET['pdfname']);
}
} }
echo "</body></html>"; echo "</body></html>";
exit; exit;