things improved since last version:

- add static text
- move up/down section/static text
- save pdf structure
things todo:
- implement correct getAvailablePDFFields functions
- add error checking and reporting
This commit is contained in:
duergner 2004-05-31 12:19:42 +00:00
parent f56f816f94
commit 1a1c369401
3 changed files with 205 additions and 14 deletions

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Roland Gruber Copyright (C) 2003 Michael Dürgner
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -55,4 +55,38 @@ function loadPDFStructureDefinitions($scope='user', $definition='default.xml') {
$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 $structure; return $structure;
} }
function savePDFStructureDefinitions($scope,$definition) {
$handle = fopen($_SESSION['lampath'] . 'config/pdf/' . $scope . '/' . $definition,'w');
$file = "<pdf type=\"" . $scope . "\">\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);
}
?> ?>

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Roland Gruber Copyright (C) 2003 Michael Dürgner
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam) This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
Copyright (C) 2003 Roland Gruber Copyright (C) 2003 Michael Dürgner
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -54,7 +54,7 @@ if(isset($_GET['abort'])) {
exit; exit;
} }
elseif(isset($_GET['submit'])) { elseif(isset($_GET['submit'])) {
// TODO implement save of PDF structure savePDFStructureDefinitions($_GET['type'],$_GET['pdfname'] . '.xml');
unset($_SESSION['currentPDFStructure']); unset($_SESSION['currentPDFStructure']);
unset($_SESSION['availablePDFFields']); unset($_SESSION['availablePDFFields']);
session_unregister('currentPDFStructure'); session_unregister('currentPDFStructure');
@ -129,28 +129,110 @@ elseif(isset($_GET['up'])) {
$tmp = $_SESSION['currentPDFStructure'][$_GET['up']]; $tmp = $_SESSION['currentPDFStructure'][$_GET['up']];
$prev = $_SESSION['currentPDFStructure'][$_GET['up'] - 1]; $prev = $_SESSION['currentPDFStructure'][$_GET['up'] - 1];
if($tmp['tag'] == 'SECTION') { if($tmp['tag'] == 'SECTION') {
$pos = 0;
$borders = array();
$current = current($_SESSION['currentPDFStructure']);
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
while($pos < $_GET['up']) {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
}
if(count($borders['close']) > 0) {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders['close'][] = $pos;
$cut_start = $borders['open'][count($borders['open']) - 1];
$cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1;
$insert_pos = $borders['open'][count($borders['open']) - 2];
$tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count);
array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove);
}
} }
elseif($tmp['tag'] == 'ENTRY' && $prev['tag'] == 'ENTRY') { elseif($tmp['tag'] == 'ENTRY' && $prev['tag'] == 'ENTRY') {
$_SESSION['currentPDFStructure'][$_GET['up']] = $_SESSION['currentPDFStructure'][$_GET['up'] - 1]; $_SESSION['currentPDFStructure'][$_GET['up']] = $_SESSION['currentPDFStructure'][$_GET['up'] - 1];
$_SESSION['currentPDFStructure'][$_GET['up'] - 1] = $tmp; $_SESSION['currentPDFStructure'][$_GET['up'] - 1] = $tmp;
} }
elseif($tmp['tag'] == 'TEXT') { elseif($tmp['tag'] == 'TEXT') {
if($_GET['up'] != 0) {
$tomove = array_splice($_SESSION['currentPDFStructure'],$_GET['up'],1);
array_splice($_SESSION['currentPDFStructure'],0,0,$tomove);
}
} }
} }
elseif(isset($_GET['down'])) { elseif(isset($_GET['down'])) {
$tmp = $_SESSION['currentPDFStructure'][$_GET['down']]; $tmp = $_SESSION['currentPDFStructure'][$_GET['down']];
$next = $_SESSION['currentPDFStructure'][$_GET['down'] + 1]; $next = $_SESSION['currentPDFStructure'][$_GET['down'] + 1];
if($tmp['tag'] == 'SECTION') { if($tmp['tag'] == 'SECTION') {
$pos = 0;
$current = current($_SESSION['currentPDFStructure']);
while($pos < $_GET['down']) {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders = array();
$borders[$current['type']][] = $pos;
$current = next($_SESSION['currentPDFStructure']);
$pos++;
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders['close'][] = $pos;
$current = next($_SESSION['currentPDFStructure']);
$pos++;
if($current) {
$borders[$current['type']][] = $pos;
$current = next($_SESSION['currentPDFStructure']);
$pos++;
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders['close'][] = $pos;
}
if(count($borders['open']) > 1) {
$cut_start = $borders['open'][count($borders['open']) - 1];
$cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1;
$insert_pos = $borders['open'][count($borders['open']) - 2];
$tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count);
array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove);
}
} }
elseif($tmp['tag'] == 'ENTRY' && $next['tag'] == 'ENTRY') { elseif($tmp['tag'] == 'ENTRY' && $next['tag'] == 'ENTRY') {
$_SESSION['currentPDFStructure'][$_GET['down']] = $_SESSION['currentPDFStructure'][$_GET['down'] + 1]; $_SESSION['currentPDFStructure'][$_GET['down']] = $_SESSION['currentPDFStructure'][$_GET['down'] + 1];
$_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp; $_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp;
} }
elseif($tmp['tag'] == 'TEXT') { elseif($tmp['tag'] == 'TEXT') {
if($_GET['down'] != (count($_SESSION['currentPDFStructure']) -1)) {
$tomove = array_splice($_SESSION['currentPDFStructure'],$_GET['down'],1);
array_splice($_SESSION['currentPDFStructure'],count($_SESSION['currentPDFStructure']),0,$tomove);
}
}
}
elseif(isset($_GET['add_text'])) {
if($_GET['text_type'] == 'config') {
$entry = array('tag' => 'TEXT','type' => 'complete','level' => '2','attributes' => array('type' => $_GET['type']));
}
else {
$entry = array('tag' => 'TEXT','type' => 'complete','level' => '2','value' => $_GET['text_text']);
}
if($_GET['text_position'] == 'top') {
array_splice($_SESSION['currentPDFStructure'],0,0,array($entry));
}
else {
array_push($_SESSION['currentPDFStructure'],$entry);
} }
} }
@ -235,7 +317,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
} }
// We have to include a static text. // We have to include a static text.
elseif($entry['tag'] == "TEXT") { elseif($entry['tag'] == "TEXT") {
if($entry['type'] == "complete") { if(!isset($entry['value'])) {
?> ?>
<tr> <tr>
<td> <td>
@ -271,18 +353,23 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
<?php echo $links;?> <?php echo $links;?>
</tr> </tr>
<tr> <tr>
<td colspan="3"> <td colspan="2">
</td> </td>
<td> <td>
<textarea name="pdftext" rows="10" cols="50" wrap="off">
<?php echo $entry['value'];?> <?php echo $entry['value'];?>
</textarea>
</td> </td>
<td colspan="6"> <td colspan="6">
</td> </td>
</tr> </tr>
<?php <?php
} }
?>
<tr>
<td colspan="9">
<br>
</td>
</tr>
<?php
} }
// We have to include an entry from the account // We have to include an entry from the account
elseif($entry['tag'] == "ENTRY") { elseif($entry['tag'] == "ENTRY") {
@ -310,7 +397,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
<legend> <legend>
<b><?php echo _("Add new section"); ?></b> <b><?php echo _("Add new section"); ?></b>
</legend> </legend>
<table align="left"> <table align="left" width="100%">
<tr> <tr>
<td> <td>
<input type="radio" name="section_type" value="text" checked> <input type="radio" name="section_type" value="text" checked>
@ -334,6 +421,76 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
</tr> </tr>
</table> </table>
</fieldset> </fieldset>
<p>&nbsp;</p>
<fieldset>
<legend>
<b><?php echo _("Add static text"); ?></b>
</legend>
<table align="left" width="100%">
<tr>
<td colspan="2">
<fieldset style="margin:0px;">
<legend>
<?php echo _('Position');?>
</legend>
<table width="100%" style="margin:0px;">
<tr>
<td>
<input type="radio" name="text_position" value="top" checked>
</td>
<td width="50%">
<?php echo _('Top');?>
</td>
<td>
<input type="radio" name="text_position" value="bottom">
</td>
<td width="50%">
<?php echo _('Bottom');?>
</td>
</tr>
</table>
</fieldset>
</td>
<td rowspan="2">
<input type="submit" name="add_text" value="<?php echo _('Add');?>">
</td>
</tr>
<tr>
<td>
<fieldset>
<legend>
<?php echo _('Text');?>
</legend>
<table width="100%">
<tr>
<td>
<input type="radio" name="text_type" value="config" checked>
</td>
<td>
<?php echo _('Insert static text from config.');?>
</td>
</tr>
<tr>
<td>
<input type="radio" name="text_type" value="textfield">
</td>
<td>
<?php echo _('Use text from field below.');?>
</td>
</tr>
<tr>
<td>
</td>
<td>
<textarea name="text_text" rows="4" cols="40"></textarea>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
</table>
</fieldset>
</fieldset> </fieldset>
<p>&nbsp;</p> <p>&nbsp;</p>
<fieldset> <fieldset>