From f7fc93aedbe04f8fd5b0bc919412292b72aaf9b5 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Mon, 5 Apr 2010 10:13:37 +0000 Subject: [PATCH] implemented descriptive PDF fields --- lam/docs/devel/mod_pdf.htm | 32 +++++-------- lam/docs/devel/upgrade.htm | 8 ++++ lam/lib/modules.inc | 16 ++++++- lam/lib/modules/shadowAccount.inc | 14 +++--- lam/templates/pdfedit/pdfpage.php | 80 +++++++++++++++++++++++-------- 5 files changed, 102 insertions(+), 48 deletions(-) diff --git a/lam/docs/devel/mod_pdf.htm b/lam/docs/devel/mod_pdf.htm index fb3dfae5..36740fd4 100644 --- a/lam/docs/devel/mod_pdf.htm +++ b/lam/docs/devel/mod_pdf.htm @@ -1,11 +1,10 @@ - - - Module HowTo - PDF output +Module HowTo - PDF output + + + - - - +

Module HowTo - PDF output

@@ -21,15 +20,13 @@ not be able to select values from your module.
The PDF values are specified with get_pdfFields() or meta['PDF_fields'].

-Example:
+Example:

The ieee802Device module has only one attribute and therefore one PDF value: the MAC address.

- +
    /**
@@ -44,11 +41,9 @@ get_metaData() {
[...]
        // available PDF fields
    -    $return['PDF_fields'] = array(
+    $return['PDF_fields'] = array(
    -        'macAddress'
+        'macAddress' => _('MAC address')
        );
        return $return;
@@ -67,14 +62,12 @@ you module is asked for data to put into the PDF file.

This is done with get_pdfEntries().

-Example:
+Example:

The ieee802Device module will return the MAC address list of the account.

- +
@@ -624,19 +642,14 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
    /**
@@ -103,5 +96,4 @@ $this->attributes['macAddress']) . '</value></block>';

- - + \ No newline at end of file diff --git a/lam/docs/devel/upgrade.htm b/lam/docs/devel/upgrade.htm index 331f9caa..229bef5a 100644 --- a/lam/docs/devel/upgrade.htm +++ b/lam/docs/devel/upgrade.htm @@ -2,6 +2,7 @@ + Upgrade notes @@ -19,8 +20,15 @@ This is a list of API changes for all LAM releases.
+

3.0.0 -> 3.1.0

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' => _('MAC address'))) in get_pdfFields() or the meta data.
+The old format is still supported. LAM will continue to show the field name as label in this case.
+
+

2.9.0 -> 3.0.0

+ You can now integrate JavaScript libraries by simply putting the files into templates/lib. All files with the name *.js are automatically included on all pages.
diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index f9eb7df3..60ad49ed 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -358,14 +358,26 @@ function getHelp($module,$helpID,$scope='') { * Returns a list of available PDF entries. * * @param string $scope account type (user, group, host) -* @return array PDF entries +* @return array PDF entries (field ID => field label) */ function getAvailablePDFFields($scope) { $mods = $_SESSION['config']->get_AccountModules($scope); $return = array(); for ($i = 0; $i < sizeof($mods); $i++) { $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 $return; diff --git a/lam/lib/modules/shadowAccount.inc b/lam/lib/modules/shadowAccount.inc index ab13e759..c9e6388e 100644 --- a/lam/lib/modules/shadowAccount.inc +++ b/lam/lib/modules/shadowAccount.inc @@ -4,7 +4,7 @@ $Id$ This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) 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 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 $return['PDF_fields'] = array( - 'shadowLastChange', - 'shadowWarning', - 'shadowInactive', - 'shadowExpire' + 'shadowLastChange' => _('Last password change'), + 'shadowWarning' => _('Password warning'), + 'shadowInactive' => _('Account inactive'), + 'shadowExpire' => _('Password expiration') ); // help Entries $return['help'] = array ( @@ -415,8 +415,8 @@ class shadowAccount extends baseModule implements passwordService { function get_pdfEntries() { return array('shadowAccount_shadowLastChange' => array('' . _('Last password change') . '' . $this->attributes['shadowLastChange'][0] . ''), 'shadowAccount_shadowWarning' => array('' . _('Password warning') . '' . $this->attributes['shadowWarn'][0] . ''), - 'shadowAccount_shadowInactive' => array('' . _('Account inactive') . '' . $this->attributes['shadowInactive'][0] . ''), - 'shadowAccount_shadowExpire' => array('' . _('Password expiration') . '' . date('d. m. Y',$this->attributes['shadowExpire'][0]*24*3600) . '')); + 'shadowAccount_shadowInactive' => array('' . _('Password expiration') . '' . $this->attributes['shadowInactive'][0] . ''), + 'shadowAccount_shadowExpire' => array('' . _('Account expiration date') . '' . date('d. m. Y',$this->attributes['shadowExpire'][0]*24*3600) . '')); } /** diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index 018120b9..92732429 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -353,12 +353,30 @@ if(!isset($_SESSION['availablePDFFields'])) { $modules = array(); $section_items_array = array(); $section_items = ''; -foreach($_SESSION['availablePDFFields'] as $module => $values) { - $modules[] = $module; - foreach($values as $attribute) { - $section_items_array[] = $module . '_' . $attribute; - $section_items .= "\n"; +$sortedModules = array(); +foreach($_SESSION['availablePDFFields'] as $module => $fields) { + if ($module != 'main') { + $title = getModuleAlias($module, $_GET['type']); } + 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 .= ""; + natcasesort($values); + foreach($values as $attribute => $attributeLabel) { + $section_items_array[] = $module . '_' . $attribute; + $section_items .= "\n"; + } + $section_items .= "\n"; } $modules = join(',',$modules); @@ -435,7 +453,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) { - + @@ -517,7 +535,7 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
- +
+


+ \ No newline at end of file + +/** + * 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; +} + +?>