added accountContainer when getting PDF fields

This commit is contained in:
Roland Gruber 2017-04-22 10:52:31 +02:00
parent 9a8f264450
commit c01e6c242e
2 changed files with 25 additions and 55 deletions

View File

@ -762,49 +762,8 @@ abstract class baseModule {
/**
* Returns a hashtable with all entries that may be printed out in the PDF.
*
* Calling this method does not require the existence of an enclosing {@link accountContainer}.<br>
* <br>
* This method must be overwritten in case that there are non static values
* to be returned. The $this->meta['PDF_fields'] array may be used for static content.<br>
* <br>
* <b>Format of returned hashtable:</b><br>
* <br>
* This function uses XML formatted commands to define the PDF output. Each part in the PDF
* document is surrounded by "<block>" and "</block>".<br>
* Inside the <block> tags there are different ways to format the output:
* <ul>
* <li><b>simple line with attribute name and value:</b> <block><key><b>attribute name</b></key><value><b>attribute value</b></value></block></li>
* <li><b>table:</b> <block><key><b>attribute name</b></key><tr><td><b>value</b><td><td><b>value</b><td></tr></block><block><tr><td><b>value</b></td><td><b>value</b><td></tr></block></li>
* </ul>
* <b>Special commands:</b>
* <ul>
* <li><b>Alignment in <td>:</b> You can specify the alignment in <td> tags with align=(L|R|C) (e.g. <td align=\"L\">)</li>
* <li><b>Cell width:</b> <td> allows an attribute "width" to set the cell width (e.g. <td width=20%> or <td width=30>).</li>
* <li><b>Line breaks:</b> Line breaks can be specified by adding a <<br>> tag. The new line will start at the left border of the PDF document.</li>
* </ul>
* <br>
* <b>Examples:</b><br>
* <br>
* <b>Simple name+value lines:</b><br><br>
* In most cases you will just want to display a single line per attribute with its name and value.<br>
* <br>
* 'myAttribute' => '<block><key>AttrName</key><value>12345</value></block>'<br>
* <br>
* This will give the following PDF output:<br>
* <br>
* <b>Attribute name:</b> 12345<br>
* <br>
* <br>
* <b>Multiline values:</b><br><br>
* Sometimes you have multivalued attributes where it is not applicable to write all values in one line but
* where you want to list your values one below the other or show a table. This can be done by using the <td> tag.<br>
* <br>
* This example only uses one column but you can just use more <td> tags per <block> tag to display more columns.<br>
* <br>
* 'myAttribute' => '<block><key>AttrName</key><tr><td align=\"L\">123</td></tr></block><block><tr><td align=\"L\">456</td></tr></block><block><tr><td align=\"L\">789</td></tr></block>'
*
* @param string $typeId type id (user, group, host)
* @return array PDF entries
* @return array PDF entries as key => label
*
* @see baseModule::get_metaData()
*/

View File

@ -409,25 +409,29 @@ function getHelp($module,$helpID,$scope='') {
* @return array PDF entries (field ID => field label)
*/
function getAvailablePDFFields($typeId) {
$mods = $_SESSION['config']->get_AccountModules($typeId);
$typeManager = new TypeManager();
$_SESSION['pdfContainer'] = new accountContainer($typeManager->getConfiguredType($typeId), 'pdfContainer');
$_SESSION['pdfContainer']->initModules();
$mods = $_SESSION['pdfContainer']->getAccountModules();
$return = array();
for ($i = 0; $i < sizeof($mods); $i++) {
$module = moduleCache::getModule($mods[$i], \LAM\TYPES\getScopeFromTypeId($typeId));
foreach ($mods as $module) {
$fields = $module->get_pdfFields($typeId);
$return[$mods[$i]] = array();
$moduleName = get_class($module);
$return[$moduleName] = 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;
$return[$moduleName][$fieldLabel] = $fieldLabel;
}
else {
$return[$mods[$i]][$fieldID] = $fieldLabel;
$return[$moduleName][$fieldID] = $fieldLabel;
}
}
}
}
$return['main'] = array('dn' => _('DN'));
unset($_SESSION['pdfContainer']);
return $return;
}
@ -803,7 +807,7 @@ class accountContainer {
/**
* Returns the included account modules.
*
* @return array modules
* @return baseModule[] modules
*/
function getAccountModules() {
return $this->module;
@ -1699,15 +1703,11 @@ class accountContainer {
/**
* This function will prepare the object for a new account.
*/
function new_account() {
public function new_account() {
logNewMessage(LOG_DEBUG, "New account with type " . $this->type->getId());
$this->isNewAccount = true;
$this->lastLoadedProfile = 'default';
$modules = $_SESSION['config']->get_AccountModules($this->type->getId());
foreach ($modules as $module) {
$this->module[$module] = new $module($this->type->getScope());
$this->module[$module]->init($this->base);
}
$this->initModules();
// sort module buttons
$this->sortModules();
$profile = \LAM\PROFILES\loadAccountProfile('default', $this->type->getId());
@ -1729,6 +1729,17 @@ class accountContainer {
return 0;
}
/**
* Creates the account modules and initializes them.
*/
public function initModules() {
$modules = $_SESSION['config']->get_AccountModules($this->type->getId());
foreach ($modules as $module) {
$this->module[$module] = new $module($this->type->getScope());
$this->module[$module]->init($this->base);
}
}
/**
* This function will save an account to the LDAP database.
*