new PDF support added; tested should work;

This commit is contained in:
duergner 2004-08-03 19:07:31 +00:00
parent 98fda9f7f1
commit e69e7f0045
5 changed files with 310 additions and 29 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -54,13 +54,14 @@ function createModulePDF($accounts,$pdf_structure="default.xml") {
}
// Get PDF structure from xml file
$structure = getStructure($account_type,$pdf_structure);
$load = getStructure($account_type,$pdf_structure);
$structure = $load['structure'];
// The decimal separator must be a dot in order to write pdf-files
setlocale(LC_NUMERIC, "C");
// Create a new PDF file acording to the account type
$pdf = new LamPDF($account_type);
$pdf = new LamPDF($account_type,$load['page_definitions']);
// Loop over each account and add a new page in the PDF file for it
foreach($accounts as $account) {
@ -178,14 +179,18 @@ function getStructure($scope,$pdf_structure) {
$border = array();
$structure = array();
$pdf_entries = $xml[1]['PDF'];
while(($index = current($pdf_entries)) != null) {
$border['start'] = $index;
next($pdf_entries);
$border['end'] = current($pdf_entries);
next($pdf_entries);
$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]);
}
return array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
$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);
}
function getSectionHeadline($line) {
@ -325,10 +330,18 @@ function processAttributes($attrs,$return = array()) {
// lamPDF class || For defining own a Header and Footer
class lamPDF extends FPDF {
function lamPDF($account_type = "User") {
var $page_definitions;
function lamPDF($account_type = "User",$page_definitions = array()) {
// Call constructor of superclass
$this->FPDF('P','mm','A4');
$this->page_definitions = $page_definitions;
echo "<pre>";
print_r($this->page_definitions);
echo "</pre>";
// Decide which PDF file type we shall use
switch($account_type) {
case "user":
@ -345,24 +358,43 @@ class lamPDF extends FPDF {
// Open PDF file and write some basic information
$this->Open();
$this->setFont("arial","",12);
$this->setTitle("LDAP Account Manager");
$this->setTitle($this->page_definitions['headline']);
$this->setSubject($subject);
$this->setAuthor("LDAP Account Manager Devel-Team -Michael Duergner-");
$this->setCreator("LDAP Account Manager (pdf.inc)");
//$this->setMargins(10.0,10.0,10.0);
$this->setMargins($this->page_definitions['margin-left'],$this->page_definitions['margin-top'],$this->page_definitions['margin-right']);
$this->setAutoPageBreak(true,$this->page_definitions['margin-bottom']);
}
// Print page header
function header() {
$imageFile = substr(__FILE__,0,strlen(__FILE__)- 11) . "graphics/printLogo.jpg";
$this->Image($imageFile,10,10,50,20,"JPG");
if($this->page_definitions['filename'] != 'none') {
$imageFile = substr(__FILE__,0,strlen(__FILE__)- 11) . "config/pdf/logos/" . $this->page_definitions['filename'];
$width = $this->page_definitions['logo-width'];
$height = $this->page_definitions['logo-height'];
if($this->page_definitions['logo-max'] == true) {
if(($width / $height) <= 2.5) {
$factor = 20 / $height;
$width = $factor * $width;
$height = 20;
}
else {
$factor = 50 / $width;
$height = $factor * $height;
$width = 50;
}
}
$this->Image($imageFile,10,10,$width,$height,"JPG");
}
$this->SetFont("arial","B",22);
$this->Cell(170,5,"LDAP Account Manager",0,1,"R",0);
$this->Cell(170,5,$this->page_definitions['headline'],0,1,"R",0);
$this->Ln(3);
$this->SetFont("times","",14);
$this->Cell(170,5,"- " . $this->subject . " -",0,0,"R",0);
$this->SetLineWidth(0.8);
$this->Line(10,40,200,40);
$this->Line(10,42,200,42);
$this->Line(10,$this->page_definitions['margin-top'] + 30,200,$this->page_definitions['margin-top'] + 30);
$this->Line(10,$this->page_definitions['margin-top'] + 32,200,$this->page_definitions['margin-top'] + 32);
$this->SetY(50);
}

View File

@ -42,23 +42,30 @@ function loadPDFStructureDefinitions($scope='user', $definition='default.xml') {
$border = array();
$structure = array();
$pdf_entries = $xml[1]['PDF'];
$border[$current] = array();
while(($index = current($pdf_entries)) != null) {
if($xml[0][$index]['attributes']['TYPE'] == $scope) {
$border['start'] = $index;
next($pdf_entries);
$border['end'] = current($pdf_entries);
$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]);
}
next($pdf_entries);
$border['end'] = $xml[1]['PDF'][1];
}
$structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
return $structure;
return array('structure' => $structure, 'page_definitions' => $page_definitions);
}
function savePDFStructureDefinitions($scope,$definition) {
$handle = fopen($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition,'w');
$file = "<pdf type=\"" . $scope . "\">\n";
$pdf_attributes = '';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
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++) {
@ -93,4 +100,20 @@ function savePDFStructureDefinitions($scope,$definition) {
function deletePDFStructureDefinition($scope,$definition) {
return unlink($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition . '.xml');
}
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;
}
?>

View File

@ -38,11 +38,12 @@ setlanguage();
if(isset($_SESSION['currentPDFStructure'])) {
unset($_SESSION['currentPDFStructure']);
unset($_SESSION['availablePDFFields']);
unset($_SESSION['currentPageDefinitions']);
session_unregister('currentPDFStructure');
session_unregister('availablePDFFields');
session_unregister('currentPageDefinitions');
}
// check if user is logged in, if not go to login
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
metaRefresh("../login.php");

View File

@ -44,6 +44,9 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
// Write $_POST variables to $_GET when form was submitted via post
if(isset($_POST['type'])) {
$_GET = $_POST;
if($_POST['pdfname'] == '') {
unset($_GET['pdfname']);
}
}
// Abort and go back to main pdf structure page
@ -297,17 +300,89 @@ elseif(isset($_GET['down'])) {
$_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp;
}
}
// TODO implement page handling
elseif(isset($_POST['page'])) {
if($_POST['logoFile'] != 'printLogo.jpg' && $_POST['logoFile'] != $_SESSION['currentPageDefinitions']['filename']) {
$_SESSION['currentPageDefinitions']['filename'] = $_POST['logoFile'];
}
if($_POST['logo-width'] != '50' && $_POST['logo-width'] != $_SESSION['currentPageDefinitions']['logo-width']) {
if($_POST['logo-width'] <= 50 && $_POST['logo-width'] > 0) {
$_SESSION['currentPageDefinitions']['logo-width'] = $_POST['logo-width'];
}
}
if($_POST['logo-height'] != '20' && $_POST['logo-height'] != $_SESSION['currentPageDefinitions']['logo-height']) {
if($_POST['logo-height'] <= 20 && $_POST['logo-height'] > 0) {
$_SESSION['currentPageDefinitions']['logo-height'] = $_POST['logo-height'];
}
}
if(isset($_POST['logo-max']) && !isset($_SESSION['currentPageDefinitions']['logo-max'])) {
$_SESSION['currentPageDefinitions']['logo-max'] = true;
}
if($_POST['headline'] != 'LDAP Account Manager' && $_POST['headline'] != $_SESSION['currentPageDefinitions']['headline']) {
$_SESSION['currentPageDefinitions']['headline'] = $_POST['headline'];
}
if($_POST['margin-top'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-top'] != $_POST['margin-top']) {
$_SESSION['currentPageDefinitions']['margin-top'] = $_POST['margin-top'];
}
if($_POST['margin-bottom'] != '20.0' && $_SESSION['currentPageDefinitions']['margin-bottom'] != $_POST['margin-bottom']) {
$_SESSION['currentPageDefinitions']['margin-bottom'] = $_POST['margin-bottom'];
}
if($_POST['margin-left'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-left'] != $_POST['margin-left']) {
$_SESSION['currentPageDefinitions']['margin-left'] = $_POST['margin-left'];
}
if($_POST['margin-right'] != '10.0' && $_SESSION['currentPageDefinitions']['margin-right'] != $_POST['margin-right']) {
$_SESSION['currentPageDefinitions']['margin-right'] = $_POST['margin-right'];
}
if(isset($_POST['defaults'])) {
foreach($_POST['defaults'] as $default) {
switch($default) {
case 'logoFile':
unset($_SESSION['currentPageDefinitions']['filename']);
break;
case 'logoSize':
unset($_SESSION['currentPageDefinitions']['logo-width']);
unset($_SESSION['currentPageDefinitions']['logo-height']);
unset($_SESSION['currentPageDefinitions']['logo-max']);
break;
case 'headline':
unset($_SESSION['currentPageDefinitions']['headline']);
break;
case 'margin-top':
unset($_SESSION['currentPageDefinitions']['margin-top']);
break;
case 'margin-bottom':
unset($_SESSION['currentPageDefinitions']['margin-bottom']);
break;
case 'margin-left':
unset($_SESSION['currentPageDefinitions']['margin-left']);
break;
case 'margin-right':
unset($_SESSION['currentPageDefinitions']['margin-right']);
break;
default:
break;
}
}
if(count($_SESSION['currentPageDefinitions']['margin']) == 0) {
unset($_SESSION['currentPageDefinitions']['margin']);
}
}
}
// Load PDF structure from file if it is not defined in session
if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit
if($_GET['edit']) {
$_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']);
$load = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']);
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
$_GET['pdfname'] = substr($_GET['edit'],0,strlen($_GET['edit']) - 4);
}
// Load default structure file when creating a new one
else {
$_SESSION['currentPDFStructure'] = loadPDFStructureDefinitions($_GET['type']);
$load = loadPDFStructureDefinitions($_GET['type']);
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
}
}
@ -330,8 +405,15 @@ foreach($_SESSION['availablePDFFields'] as $module => $values) {
}
$modules = join(',',$modules);
$logoFiles = getAvailableLogos();
$logos = '<option value="none"' . (($_SESSION['currentPageDefinitions']['filename'] == 'none') ? ' selected="selected"' : '') . '>' . _('No logo') . "</option>\n";
foreach($logoFiles as $logoFile) {
$logos .= "\t\t\t\t\t\t\t\t\t\t\t<option value=\"" . $logoFile['filename'] . "\"" .(($_SESSION['currentPageDefinitions']['filename'] == $logoFile['filename'] || (!isset($_SESSION['currentPageDefinitions']['filename']) && $logoFile['filename'] == 'printLogo.jpg')) ? ' selected="selected"' : '') . '">' . $logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")</option>\n";
}
// print header
echo $_SESSION['header'];
// TODO Change enctype of form
?>
<title>LDAP Account Manager</title>
<link rel="stylesheet" type="text/css" href="../../style/layout.css">
@ -340,12 +422,155 @@ echo $_SESSION['header'];
<br>
<form action="pdfpage.php" method="post">
<table width="100%">
<tr>
<td width="100%" colspan="3" align="center">
<fieldset>
<legend>
<b><?php echo _('Overall page settings'); ?></b>
</legend>
<table width="100%">
<tr>
<td>
<b><?php echo _('Logo'); ?>:</b>
</td>
<td>
<select name="logoFile" size="1">
<?php echo $logos; ?>
</select>
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="logoFile">
</td>
<td rowspan="4" align="center">
<input type="submit" name="page" value="<?php echo _('Submit page settings'); ?>">
</td>
</tr>
<tr>
<td>
</td>
<td>
<p>
<fieldset>
<legend>
<?php echo _('Size'); ?>
</legend>
<table width="100%">
<tr>
<td>
<?php echo _('Width') . ':'; ?>
</td>
<td>
<input type="text" name="logo-width" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['logo-width'])) ? $_SESSION['currentPageDefinitions']['logo-width'] : '50'); ?>" size="5"> <?php echo _('cm'); ?>
</td>
</tr>
<tr>
<td>
<?php echo _('Height') . ':'; ?>
</td>
<td>
<input type="text" name="logo-height" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['logo-height'])) ? $_SESSION['currentPageDefinitions']['logo-height'] : '20'); ?>" size="5"> <?php echo _('cm'); ?>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="logo-max"<?php echo ((isset($_SESSION['currentPageDefinitions']['logo-max'])) ? ' checked="checked"' : ''); ?>>
</td>
<td>
<?php echo _('Maximize with correct ratio'); ?>
</td>
</tr>
</table>
</fieldset>
</p>
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="logoSize">
</td>
<!-- <td rowspan="3" align="center">
<input type="submit" name="page" value="<?php echo _('Submit page settings'); ?>">
</td> -->
</tr>
<tr>
<td>
<b><?php echo _('Headline'); ?>:</b>
</td>
<td>
<input type="text" name="headline" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['headline'])) ? $_SESSION['currentPageDefinitions']['headline'] : 'LDAP Account Manager'); ?>">
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="headline">
</td>
</tr>
<tr>
<td colspan="3">
<fieldset>
<legend>
<?php echo _('Margin'); ?>
</legend>
<table width="100%">
<tr>
<td>
<b><?php echo _('Top'); ?>:</b>
</td>
<td>
<input type="text" name="margin-top" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['margin-top'])) ? $_SESSION['currentPageDefinitions']['margin-top'] : '10.0'); ?>" size="5">
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="margin-top">
</td>
</tr>
<tr>
<td>
<b><?php echo _('Bottom'); ?>:</b>
</td>
<td>
<input type="text" name="margin-bottom" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['margin-bottom'])) ? $_SESSION['currentPageDefinitions']['margin-bottom'] : '20.0'); ?>" size="5">
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="margin-bottom">
</td>
</tr>
<tr>
<td>
<b><?php echo _('Left'); ?>:</b>
</td>
<td>
<input type="text" name="margin-left" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['margin-left'])) ? $_SESSION['currentPageDefinitions']['margin-left'] : '10.0'); ?>" size="5">
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="margin-left">
</td>
</tr>
<tr>
<td>
<b><?php echo _('right'); ?>:</b>
</td>
<td>
<input type="text" name="margin-right" value="<?php echo ((isset($_SESSION['currentPageDefinitions']['margin-right'])) ? $_SESSION['currentPageDefinitions']['margin-right'] : '10.0'); ?>" size="5">
</td>
<td>
<?php echo _('Use default') ?> <input type="checkbox" name="defaults[]" value="margin-right">
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
<tr>
<!-- print current structure -->
<td width="45%" align="center">
<fieldset>
<legend>
<b><?php echo (($_GET['edit']) ? substr($_GET['edit'],0,strlen($GET['edit']) - 4) : _('New') . ' ' . $_GET['type']) . ' ' . _("PDF structure"); ?></b>
<b><?php echo _("PDF structure"); ?></b>
</legend>
<table>
<?php