implemented descriptive PDF fields

This commit is contained in:
Roland Gruber 2010-04-05 10:13:37 +00:00
parent 24f2b3bd6f
commit f7fc93aedb
5 changed files with 102 additions and 48 deletions

View File

@ -1,11 +1,10 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <html><head><title>Module HowTo - PDF output</title>
<head>
<title>Module HowTo - PDF output</title>
<link rel="stylesheet" type="text/css" href="style/layout.css"> <link rel="stylesheet" type="text/css" href="style/layout.css">
<link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"> <link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico"></head><body>
</head>
<body>
<div style="text-align: center;"> <div style="text-align: center;">
<h1>Module HowTo - PDF output<br> <h1>Module HowTo - PDF output<br>
</h1> </h1>
@ -21,15 +20,13 @@ not be able to select values from your module.<br>
The PDF values are specified with <span style="font-weight: bold;">get_pdfFields()</span> The PDF values are specified with <span style="font-weight: bold;">get_pdfFields()</span>
or <span style="font-weight: bold;">meta['PDF_fields']</span>.<br> or <span style="font-weight: bold;">meta['PDF_fields']</span>.<br>
<br> <br>
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;">
style="font-weight: bold; text-decoration: underline;">
<br> <br>
The <span style="font-style: italic;">ieee802Device</span> The <span style="font-style: italic;">ieee802Device</span>
module has only one attribute and therefore one PDF value: the MAC module has only one attribute and therefore one PDF value: the MAC
address.<br> address.<br>
<br> <br>
<table style="width: 100%; text-align: left;" class="mod-code" <table style="width: 100%; text-align: left;" class="mod-code" border="0" cellpadding="2" cellspacing="2">
border="0" cellpadding="2" cellspacing="2">
<tbody> <tbody>
<tr> <tr>
<td style="vertical-align: top;">&nbsp;&nbsp;&nbsp; /**<br> <td style="vertical-align: top;">&nbsp;&nbsp;&nbsp; /**<br>
@ -44,11 +41,9 @@ get_metaData() {<br>
[...]<br> [...]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // available PDF fields<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // available PDF fields<br>
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; $return['PDF_fields'] = array(</span><br &nbsp;&nbsp;&nbsp; $return['PDF_fields'] = array(</span><br style="color: rgb(255, 0, 0);">
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 'macAddress'</span><br &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 'macAddress' =&gt; _('MAC address')</span><br style="color: rgb(255, 0, 0);">
style="color: rgb(255, 0, 0);">
<span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp; <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; );</span><br style="color: rgb(255, 0, 0);"> &nbsp;&nbsp;&nbsp; );</span><br style="color: rgb(255, 0, 0);">
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $return;<br> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return $return;<br>
@ -67,14 +62,12 @@ you module is asked for data to put into the PDF file.<br>
<br> <br>
This is done with <span style="font-weight: bold;">get_pdfEntries()</span>.<br> This is done with <span style="font-weight: bold;">get_pdfEntries()</span>.<br>
<br> <br>
<span style="font-weight: bold; text-decoration: underline;">Example:</span><br <span style="font-weight: bold; text-decoration: underline;">Example:</span><br style="font-weight: bold; text-decoration: underline;">
style="font-weight: bold; text-decoration: underline;">
<br> <br>
The <span style="font-style: italic;">ieee802Device</span> The <span style="font-style: italic;">ieee802Device</span>
module will return the MAC address list of the account.<br> module will return the MAC address list of the account.<br>
<br> <br>
<table style="width: 100%; text-align: left;" class="mod-code" <table style="width: 100%; text-align: left;" class="mod-code" border="0" cellpadding="2" cellspacing="2">
border="0" cellpadding="2" cellspacing="2">
<tbody> <tbody>
<tr> <tr>
<td style="vertical-align: top;">&nbsp; &nbsp; /**<br> <td style="vertical-align: top;">&nbsp; &nbsp; /**<br>
@ -103,5 +96,4 @@ $this-&gt;attributes['macAddress']) . '&lt;/value&gt;&lt;/block&gt;';<br>
<h2><span style="font-weight: bold;"></span></h2> <h2><span style="font-weight: bold;"></span></h2>
</div> </div>
</div> </div>
</body> </body></html>
</html>

View File

@ -2,6 +2,7 @@
<html><head> <html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title>
@ -19,8 +20,15 @@ This is a list of API changes for all LAM releases.
<br> <br>
<h2>3.0.0 -&gt; 3.1.0</h2>The PDF editor now supports descriptive PDF
fields. You can use this by returning an associative array for the PDF
fields (e.g. array('macAddress' =&gt; _('MAC address'))) in <span style="font-weight: bold;">get_pdfFields()</span> or the meta data.<br>
The old format is still supported. LAM will continue to show the field name as label in this case.<br>
<br>
<br>
<h2>2.9.0 -&gt; 3.0.0</h2> <h2>2.9.0 -&gt; 3.0.0</h2>
You can now integrate JavaScript libraries by simply putting the files You can now integrate JavaScript libraries by simply putting the files
into templates/lib. All files with the name *.js are automatically into templates/lib. All files with the name *.js are automatically
included on all pages.<br> included on all pages.<br>

View File

@ -358,14 +358,26 @@ function getHelp($module,$helpID,$scope='') {
* Returns a list of available PDF entries. * Returns a list of available PDF entries.
* *
* @param string $scope account type (user, group, host) * @param string $scope account type (user, group, host)
* @return array PDF entries * @return array PDF entries (field ID => field label)
*/ */
function getAvailablePDFFields($scope) { function getAvailablePDFFields($scope) {
$mods = $_SESSION['config']->get_AccountModules($scope); $mods = $_SESSION['config']->get_AccountModules($scope);
$return = array(); $return = array();
for ($i = 0; $i < sizeof($mods); $i++) { for ($i = 0; $i < sizeof($mods); $i++) {
$module = new $mods[$i]($scope); $module = new $mods[$i]($scope);
$return[$mods[$i]] = $module->get_pdfFields(); $fields = $module->get_pdfFields();
$return[$mods[$i]] = array();
if (is_array($fields)) {
foreach ($fields as $fieldID => $fieldLabel) {
if (is_integer($fieldID)) {
// support old PDF field list which did not contain a label
$return[$mods[$i]][$fieldLabel] = $fieldLabel;
}
else {
$return[$mods[$i]][$fieldID] = $fieldLabel;
}
}
}
} }
$return['main'] = array('dn'); $return['main'] = array('dn');
return $return; return $return;

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Tilo Lutz Copyright (C) 2003 - 2006 Tilo Lutz
Copyright (C) 2007 - 2009 Roland Gruber Copyright (C) 2007 - 2010 Roland Gruber
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
@ -162,10 +162,10 @@ class shadowAccount extends baseModule implements passwordService {
); );
// available PDF fields // available PDF fields
$return['PDF_fields'] = array( $return['PDF_fields'] = array(
'shadowLastChange', 'shadowLastChange' => _('Last password change'),
'shadowWarning', 'shadowWarning' => _('Password warning'),
'shadowInactive', 'shadowInactive' => _('Account inactive'),
'shadowExpire' 'shadowExpire' => _('Password expiration')
); );
// help Entries // help Entries
$return['help'] = array ( $return['help'] = array (
@ -415,8 +415,8 @@ class shadowAccount extends baseModule implements passwordService {
function get_pdfEntries() { function get_pdfEntries() {
return array('shadowAccount_shadowLastChange' => array('<block><key>' . _('Last password change') . '</key><value>' . $this->attributes['shadowLastChange'][0] . '</value></block>'), return array('shadowAccount_shadowLastChange' => array('<block><key>' . _('Last password change') . '</key><value>' . $this->attributes['shadowLastChange'][0] . '</value></block>'),
'shadowAccount_shadowWarning' => array('<block><key>' . _('Password warning') . '</key><value>' . $this->attributes['shadowWarn'][0] . '</value><block>'), 'shadowAccount_shadowWarning' => array('<block><key>' . _('Password warning') . '</key><value>' . $this->attributes['shadowWarn'][0] . '</value><block>'),
'shadowAccount_shadowInactive' => array('<block><key>' . _('Account inactive') . '</key><value>' . $this->attributes['shadowInactive'][0] . '</value></block>'), 'shadowAccount_shadowInactive' => array('<block><key>' . _('Password expiration') . '</key><value>' . $this->attributes['shadowInactive'][0] . '</value></block>'),
'shadowAccount_shadowExpire' => array('<block><key>' . _('Password expiration') . '</key><value>' . date('d. m. Y',$this->attributes['shadowExpire'][0]*24*3600) . '</value></block>')); 'shadowAccount_shadowExpire' => array('<block><key>' . _('Account expiration date') . '</key><value>' . date('d. m. Y',$this->attributes['shadowExpire'][0]*24*3600) . '</value></block>'));
} }
/** /**

View File

@ -353,12 +353,30 @@ if(!isset($_SESSION['availablePDFFields'])) {
$modules = array(); $modules = array();
$section_items_array = array(); $section_items_array = array();
$section_items = ''; $section_items = '';
foreach($_SESSION['availablePDFFields'] as $module => $values) { $sortedModules = array();
$modules[] = $module; foreach($_SESSION['availablePDFFields'] as $module => $fields) {
foreach($values as $attribute) { if ($module != 'main') {
$section_items_array[] = $module . '_' . $attribute; $title = getModuleAlias($module, $_GET['type']);
$section_items .= "<option>" . $module . '_' . $attribute . "</option>\n";
} }
else {
$title = _('Main');
}
$sortedModules[$module] = $title;
}
natcasesort($sortedModules);
foreach($sortedModules as $module => $title) {
$values = $_SESSION['availablePDFFields'][$module];
if (!is_array($values) || (sizeof($values) < 1)) {
continue;
}
$modules[] = $module;
$section_items .= "<optgroup label=\"" . $title . "\"\n>";
natcasesort($values);
foreach($values as $attribute => $attributeLabel) {
$section_items_array[] = $module . '_' . $attribute;
$section_items .= "<option value=\"" . $module . '_' . $attribute . "\">" . $attributeLabel . "</option>\n";
}
$section_items .= "</optgroup>\n";
} }
$modules = join(',',$modules); $modules = join(',',$modules);
@ -435,7 +453,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
<?php <?php
foreach($section_items_array as $item) { foreach($section_items_array as $item) {
?> ?>
<option value="_<?php echo $item;?>"<?php echo ((substr($name,1) == $item) ? ' selected' : '');?>><?php echo $item;?></option> <option value="_<?php echo $item;?>"<?php echo ((substr($name,1) == $item) ? ' selected' : '');?>><?php echo translateFieldIDToName($item);?></option>
<?php <?php
} }
?> ?>
@ -517,7 +535,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
<td width="20"> <td width="20">
</td> </td>
<td> <td>
<?php echo $name;?> <?php echo translateFieldIDToName($name, $_GET['type']);?>
</td> </td>
<td width="20"> <td width="20">
</td> </td>
@ -624,19 +642,14 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
</legend><BR> </legend><BR>
<select name="new_field"> <select name="new_field">
<?php <?php
foreach($_SESSION['availablePDFFields'] as $module => $fields) { foreach($sortedModules as $module => $title) {
$fields = $_SESSION['availablePDFFields'][$module];
if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) { if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) {
sort($fields); natcasesort($fields);
if ($module != 'main') {
$title = getModuleAlias($module, $_GET['type']);
}
else {
$title = _('Main');
}
echo "<optgroup label=\"$title\">\n"; echo "<optgroup label=\"$title\">\n";
foreach ($fields as $field) { foreach ($fields as $field => $fieldLabel) {
echo "<option value=\"" . $module . "_" . $field . "\" label=\"$field\">$field</option>\n"; echo "<option value=\"" . $module . "_" . $field . "\" label=\"$fieldLabel\">$fieldLabel</option>\n";
} }
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
} }
@ -707,8 +720,37 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
</table> </table>
<input type="hidden" name="modules" value="<?php echo $modules;?>"> <input type="hidden" name="modules" value="<?php echo $modules;?>">
<input type="hidden" name="type" value="<?php echo $_GET['type'];?>"> <input type="hidden" name="type" value="<?php echo $_GET['type'];?>">
<br><br><br>
</form> </form>
</body> </body>
</html> </html>
<?php <?php
?>
/**
* Translates a given field ID (e.g. inetOrgPerson_givenName) to its descriptive name.
*
* @param String $id field ID
* @param String $scope account type
*/
function translateFieldIDToName($id, $scope) {
foreach ($_SESSION['availablePDFFields'] as $module => $fields) {
if (!(strpos($id, $module . '_') === 0)) {
continue;
}
foreach ($fields as $name => $label) {
if ($id == $module . '_' . $name) {
if ($module == 'main') {
return _('Main') . ': ' . $label;
}
else {
return getModuleAlias($module, $scope) . ': ' . $label;
}
}
}
}
return $id;
}
?>