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,40 +21,38 @@ $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);
@ -63,43 +61,51 @@ function getPDFStructureDefinitions($scope = "user") {
} }
/** /**
* 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';
if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms';
$struct_file = ($_SESSION['lampath'] . 'config/pdf/' . $definition . '.' . $scope . '.xml');
if(!is_writable($_SESSION['lampath'] . 'config/pdf/')) {
return 'no perms';
}
else {
$handle = fopen($struct_file,'w');
$pdf_attributes = ''; $pdf_attributes = '';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) { foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
if($key != 'type') { if($key != 'type') {
@ -136,25 +142,35 @@ function savePDFStructureDefinitions($scope,$definition) {
$file .= "</pdf>"; $file .= "</pdf>";
fwrite($handle,$file); fwrite($handle,$file);
fclose($handle); fclose($handle);
return 'ok';
}
} }
/** /**
* 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;
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); 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;