2004-05-30 13:43:42 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
$Id$
|
|
|
|
|
|
|
|
|
|
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
|
2004-05-31 12:19:42 +00:00
|
|
|
|
Copyright (C) 2003 Michael D<EFBFBD>rgner
|
2004-05-30 13:43:42 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* Functions to manage the PDF structures.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
|
|
|
|
* @author Michael D<EFBFBD>rgner
|
|
|
|
|
* @package PDF
|
|
|
|
|
*/
|
|
|
|
|
|
2005-07-27 18:27:24 +00:00
|
|
|
|
/** LAM configuration */
|
2004-05-30 13:43:42 +00:00
|
|
|
|
include_once("config.inc");
|
2004-10-30 16:46:06 +00:00
|
|
|
|
|
2005-07-27 18:27:24 +00:00
|
|
|
|
/** LDAP object */
|
2004-05-30 13:43:42 +00:00
|
|
|
|
include_once("ldap.inc");
|
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* This function will return all available PDF structure definitions for the submitted
|
|
|
|
|
* account scope.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @param string $scope The account scope the PDF structure definitions should be
|
|
|
|
|
* returned.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @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
|
|
|
|
|
* createModulePDF() function as second argument.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*/
|
2004-05-30 13:43:42 +00:00
|
|
|
|
function getPDFStructureDefinitions($scope = "user") {
|
|
|
|
|
$return = array();
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$path = $_SESSION['lampath'] . 'config/pdf/';
|
2004-09-08 14:40:25 +00:00
|
|
|
|
if(is_dir($path)) {
|
|
|
|
|
$dirHandle = opendir($path);
|
|
|
|
|
while($file = readdir($dirHandle)) {
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$struct_file = explode('.',$file);
|
|
|
|
|
if(!is_dir($path.$file) && $file != '.' && $file != '..' && $struct_file[1] == $scope) {
|
|
|
|
|
array_push($return, $struct_file[0]);
|
2004-09-08 14:40:25 +00:00
|
|
|
|
}
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
2004-09-08 14:40:25 +00:00
|
|
|
|
sort($return);
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
2005-07-27 18:27:24 +00:00
|
|
|
|
return $return;
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* 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.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @return array PDF structure
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*/
|
2005-07-27 18:27:24 +00:00
|
|
|
|
function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') {
|
2004-05-30 13:43:42 +00:00
|
|
|
|
$parser = new xmlParser();
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$file = $_SESSION['lampath'] . 'config/pdf/' . $pdf_structure . '.' . $scope . '.xml';
|
2004-09-08 14:40:25 +00:00
|
|
|
|
$xml = $parser->parse($file);
|
2004-05-30 13:43:42 +00:00
|
|
|
|
$border = array();
|
|
|
|
|
$structure = array();
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$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');
|
2004-08-03 19:07:31 +00:00
|
|
|
|
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) {
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$complete_page_definitions[strtolower($key)] = $value;
|
2004-08-03 19:07:31 +00:00
|
|
|
|
unset($page_definitions[$key]);
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
2004-08-03 19:07:31 +00:00
|
|
|
|
$border['end'] = $xml[1]['PDF'][1];
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
|
|
|
|
$structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
|
2005-07-27 18:27:24 +00:00
|
|
|
|
return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
|
2004-05-30 13:43:42 +00:00
|
|
|
|
}
|
2004-05-31 12:19:42 +00:00
|
|
|
|
|
2005-07-27 18:27:24 +00:00
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* Saves PDF structure definitions to XML file in format: <name>.<scope>.xml
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @param string $scope account type
|
|
|
|
|
* @param string $definition Name of definition
|
|
|
|
|
* @return string "no perms" if access denied or "ok".
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*/
|
2004-05-31 12:19:42 +00:00
|
|
|
|
function savePDFStructureDefinitions($scope,$definition) {
|
2005-07-27 18:27:24 +00:00
|
|
|
|
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';
|
2004-08-03 19:07:31 +00:00
|
|
|
|
}
|
2005-07-27 18:27:24 +00:00
|
|
|
|
else {
|
2005-09-27 12:47:22 +00:00
|
|
|
|
$handle = @fopen($struct_file,'w');
|
|
|
|
|
if (!$handle) return 'no perms';
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$pdf_attributes = '';
|
|
|
|
|
foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
|
|
|
|
|
if($key != 'type') {
|
|
|
|
|
$pdf_attributes .= ' ' . $key . '="' . $value . '"';
|
2004-05-31 12:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$file = '<pdf type="' . $scope . "\"" . $pdf_attributes . ">\n";
|
|
|
|
|
foreach($_SESSION['currentPDFStructure'] as $entry) {
|
|
|
|
|
$ident = '';
|
|
|
|
|
for($i=0;$i<$entry['level'] -1;$i++) {
|
|
|
|
|
$ident .= "\t";
|
|
|
|
|
}
|
|
|
|
|
$attributes = '';
|
|
|
|
|
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";
|
2004-05-31 12:19:42 +00:00
|
|
|
|
}
|
2005-07-27 18:27:24 +00:00
|
|
|
|
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";
|
|
|
|
|
}
|
2004-05-31 12:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2005-07-27 18:27:24 +00:00
|
|
|
|
$file .= "</pdf>";
|
|
|
|
|
fwrite($handle,$file);
|
|
|
|
|
fclose($handle);
|
|
|
|
|
return 'ok';
|
2004-05-31 12:19:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-16 06:33:37 +00:00
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* Deletes XML file with PDF structure definitions.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @param string $scope account type
|
|
|
|
|
* @param string $definition Name of definition to delete
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @return boolean True if file was deleted or false if a problem occured.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*/
|
2005-07-27 18:27:24 +00:00
|
|
|
|
function deletePDFStructureDefinition($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);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-16 06:33:37 +00:00
|
|
|
|
}
|
2004-08-03 19:07:31 +00:00
|
|
|
|
|
2004-10-30 16:46:06 +00:00
|
|
|
|
/**
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* This function returns an array with all aviliable logo images.
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*
|
2005-07-27 18:27:24 +00:00
|
|
|
|
* @return array list of logo files
|
2004-10-30 16:46:06 +00:00
|
|
|
|
*/
|
2004-08-03 19:07:31 +00:00
|
|
|
|
function getAvailableLogos() {
|
|
|
|
|
$return = array();
|
|
|
|
|
$dirPath = $_SESSION['lampath'] . '/config/pdf/logos/';
|
|
|
|
|
$dirHandle = opendir($dirPath);
|
|
|
|
|
while($file = readdir($dirHandle)) {
|
|
|
|
|
if(!is_dir($file) && $file != '.' && $file != '..' && preg_match('/\\.(jpg|png)$/',$file)) {
|
|
|
|
|
$infos = getimagesize($dirPath . $file);
|
|
|
|
|
if($infos[0] <= 400 && $infos[1] <= 60) {
|
|
|
|
|
array_push($return, array('filename' => $file, 'infos' => $infos));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sort($return);
|
|
|
|
|
return $return;
|
|
|
|
|
}
|
2004-05-30 13:43:42 +00:00
|
|
|
|
?>
|