LDAPAccountManager/lam/lib/pdfstruct.inc

174 lines
4.5 KiB
PHP
Raw Normal View History

<?php
/*
$Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Michael D<EFBFBD>rgner
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
/**
*
*
* @author Michael D<EFBFBD>rgner
* @version 0.5
* @package PDF
* @copyright Copyright (C) 2003-2004 Michael D<EFBFBD>rgner
* @license GPL
*/
/**
*
*/
include_once("config.inc");
2004-10-30 16:46:06 +00:00
/**
*
*/
include_once("ldap.inc");
2004-10-30 16:46:06 +00:00
/**
*
*
* @param string
*
* @return array
*/
function getPDFStructureDefinitions($scope = "user") {
$return = array();
2004-09-08 14:40:25 +00:00
$path = $_SESSION['lampath'] . 'config/pdf/' . $scope;
if(is_dir($path)) {
$dirHandle = opendir($path);
while($file = readdir($dirHandle)) {
if(!is_dir($file) && $file != '.' && $file != '..' && $file != 'default.xml') {
array_push($return, substr($file,0,strlen($file)-4));
}
}
2004-09-08 14:40:25 +00:00
sort($return);
}
return $return;
}
2004-10-30 16:46:06 +00:00
/**
*
*
* @param string
* @param string
*
* @return array
*/
function loadPDFStructureDefinitions($scope='user', $definition='default.xml') {
$parser = new xmlParser();
2004-09-08 14:40:25 +00:00
$file = $_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition;
$xml = $parser->parse($file);
$border = array();
$structure = array();
$border[$current] = array();
$page_definitions = array();
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) {
$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' => $page_definitions);
}
2004-10-30 16:46:06 +00:00
/**
*
*
* @param string
* @param string
*/
function savePDFStructureDefinitions($scope,$definition) {
$handle = fopen($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition,'w');
$pdf_attributes = '';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
2004-09-08 14:40:25 +00:00
if($key != 'type') {
$pdf_attributes .= ' ' . $key . '="' . $value . '"';
}
}
$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";
}
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);
}
2004-10-30 16:46:06 +00:00
/**
*
*
* @param string
* @param string
*
* @return boolean
*/
function deletePDFStructureDefinition($scope,$definition) {
2004-09-08 14:40:25 +00:00
$file = $_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition;
return unlink($file);
}
2004-10-30 16:46:06 +00:00
/**
*
*
* @return array
*/
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;
}
?>