new type API

This commit is contained in:
Roland Gruber 2016-12-24 13:04:31 +01:00
parent aa9c11ae0c
commit f9995d7cb6
7 changed files with 137 additions and 123 deletions

View File

@ -1,4 +1,6 @@
<?php <?php
use LAM\TYPES\ConfiguredType;
/* /*
$Id$ $Id$
@ -103,7 +105,7 @@ class lamList {
/** /**
* Constructor * Constructor
* *
* @param string $type account type * @param LAM\TYPES\ConfiguredType $type account type
* @return lamList list object * @return lamList list object
*/ */
public function __construct($type) { public function __construct($type) {
@ -122,8 +124,8 @@ class lamList {
*/ */
private function listReadOptionsFromCookie() { private function listReadOptionsFromCookie() {
if (sizeof($this->configOptions) > 0) { if (sizeof($this->configOptions) > 0) {
if (isset($_COOKIE["ListOptions_" . $this->type])) { if (isset($_COOKIE["ListOptions_" . $this->type->getId()])) {
$cookieValue = $_COOKIE["ListOptions_" . $this->type]; $cookieValue = $_COOKIE["ListOptions_" . $this->type->getId()];
$valueParts = explode(";", $cookieValue); $valueParts = explode(";", $cookieValue);
$values = array(); $values = array();
for ($i = 0; $i < sizeof($valueParts); $i++) { for ($i = 0; $i < sizeof($valueParts); $i++) {
@ -172,7 +174,7 @@ class lamList {
// show form // show form
echo "<div class=\"ui-tabs-panel ui-widget-content ui-corner-bottom\">"; echo "<div class=\"ui-tabs-panel ui-widget-content ui-corner-bottom\">";
echo "<div id=\"listTabContentArea\">\n"; echo "<div id=\"listTabContentArea\">\n";
echo ("<form action=\"list.php?type=" . $this->type . "&amp;norefresh=true\" method=\"post\">\n"); echo ("<form action=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true\" method=\"post\">\n");
// draw account list if accounts were found // draw account list if accounts were found
if (sizeof($this->entries) > 0) { if (sizeof($this->entries) > 0) {
// buttons // buttons
@ -289,12 +291,12 @@ class lamList {
if ($count > $this->maxPageEntries) { if ($count > $this->maxPageEntries) {
echo("<td class=\"activepage\" align=\"right\">"); echo("<td class=\"activepage\" align=\"right\">");
if ($this->page != 1) { if ($this->page != 1) {
echo("<a title=\"" . _('Jump to first page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=1" . echo("<a title=\"" . _('Jump to first page') . "\" href=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true&amp;page=1" .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-first.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-first.png\"></a>\n");
} }
if ($this->page > 11) { if ($this->page > 11) {
echo("<a title=\"" . _('Jump 10 pages backward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page - 10) . echo("<a title=\"" . _('Jump 10 pages backward') . "\" href=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true&amp;page=" . ($this->page - 10) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-previous.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-previous.png\"></a>\n");
} }
@ -307,24 +309,24 @@ class lamList {
continue; continue;
} }
if ($i == $this->page - 1) { if ($i == $this->page - 1) {
$url = "list.php?type=" . $this->type . "&amp;norefresh=true" . $url = "list.php?type=" . $this->type->getId() . "&amp;norefresh=true" .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter; "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter;
echo '<input type="number" class="listPageInput" id="listNavPage" name="listNavPage"' echo '<input type="number" class="listPageInput" id="listNavPage" name="listNavPage"'
. ' value="' . ($i + 1) . '" min="1" max="' . $pageCount . '"' . ' value="' . ($i + 1) . '" min="1" max="' . $pageCount . '"'
. ' onkeypress="listPageNumberKeyPress(\'' . $url . '\', event);">'; . ' onkeypress="listPageNumberKeyPress(\'' . $url . '\', event);">';
} }
else { else {
echo "&nbsp;<a href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($i + 1) . echo "&nbsp;<a href=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true&amp;page=" . ($i + 1) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . ($i + 1) . "</a>\n"; "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . ($i + 1) . "</a>\n";
} }
} }
if ($this->page < ($pageCount - 10)) { if ($this->page < ($pageCount - 10)) {
echo("<a title=\"" . _('Jump 10 pages forward') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . ($this->page + 10) . echo("<a title=\"" . _('Jump 10 pages forward') . "\" href=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true&amp;page=" . ($this->page + 10) .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-next.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-next.png\"></a>\n");
} }
if ($this->page < $pageCount) { if ($this->page < $pageCount) {
echo("<a title=\"" . _('Jump to last page') . "\" href=\"list.php?type=" . $this->type . "&amp;norefresh=true&amp;page=" . $pageCount . echo("<a title=\"" . _('Jump to last page') . "\" href=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true&amp;page=" . $pageCount .
"&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" . "&amp;sort=" . $this->sortColumn . "&amp;sortdirection=" . $this->sortDirection . $filter . "\">" .
"<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-last.png\"></a>\n"); "<img height=16 width=16 class=\"align-middle\" alt=\"\" src=\"../../graphics/go-last.png\"></a>\n");
} }
@ -352,8 +354,8 @@ class lamList {
protected function listPrintTableHeader() { protected function listPrintTableHeader() {
$filter = $this->getFilterAsTextForURL(); $filter = $this->getFilterAsTextForURL();
// print table header // print table header
echo "<table id=\"accountTable\" frame=\"box\" rules=\"none\" class=\"" . $this->type . "-border collapse accountlist ui-corner-all\" width=\"100%\"><thead>\n"; echo "<table id=\"accountTable\" frame=\"box\" rules=\"none\" class=\"" . $this->type->getScope() . "-border collapse accountlist ui-corner-all\" width=\"100%\"><thead>\n";
echo "<tr class=\"" . $this->type . "-dark\">\n"; echo "<tr class=\"" . $this->type->getScope() . "-dark\">\n";
echo "<th width=22 height=34><a href=\"#\" onClick=\"list_switchAccountSelection();\"><img height=16 width=16 src=\"../../graphics/selectDown.png\" alt=\"select all\"></a></th>\n"; echo "<th width=22 height=34><a href=\"#\" onClick=\"list_switchAccountSelection();\"><img height=16 width=16 src=\"../../graphics/selectDown.png\" alt=\"select all\"></a></th>\n";
echo "<td>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" . echo "<td>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" .
"<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n"; "<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n";
@ -364,17 +366,17 @@ class lamList {
if ($this->sortDirection < 0) { if ($this->sortDirection < 0) {
$sortImage = "sort_desc.png"; $sortImage = "sort_desc.png";
} }
echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;". echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type->getId() . "&amp;".
"sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] .
"&nbsp;<img height=16 width=16 style=\"vertical-align: middle;\" src=\"../../graphics/$sortImage\" alt=\"sort direction\"></a></th>\n"; "&nbsp;<img height=16 width=16 style=\"vertical-align: middle;\" src=\"../../graphics/$sortImage\" alt=\"sort direction\"></a></th>\n";
} }
else echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type . "&amp;". else echo "<th align=\"left\"><a href=\"list.php?type=" . $this->type->getId() . "&amp;".
"sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "</a></th>\n"; "sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "</a></th>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
// print filter row // print filter row
echo "<tr align=\"center\" class=\"" . $this->type . "-bright\">\n"; echo "<tr align=\"center\" class=\"" . $this->type->getScope() . "-bright\">\n";
echo "<td width=22 height=34>"; echo "<td width=22 height=34>";
printHelpLink(getHelp('', '250'), '250'); printHelpLink(getHelp('', '250'), '250');
echo "</td>\n"; echo "</td>\n";
@ -389,7 +391,7 @@ class lamList {
$clearFilterButton->setTitle(_('Clear filter')); $clearFilterButton->setTitle(_('Clear filter'));
$filterGroup->addElement($clearFilterButton); $filterGroup->addElement($clearFilterButton);
} }
parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type); parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type->getScope());
echo "</td>\n"; echo "</td>\n";
// print input boxes for filters // print input boxes for filters
for ($k = 0; $k < sizeof($this->descArray); $k++) { for ($k = 0; $k < sizeof($this->descArray); $k++) {
@ -416,10 +418,10 @@ class lamList {
} }
} }
$filterInput = new htmlInputField('filter' . strtolower($attrName), $value); $filterInput = new htmlInputField('filter' . strtolower($attrName), $value);
$filterInput->setCSSClasses(array($this->type . '-dark')); $filterInput->setCSSClasses(array($this->type->getScope() . '-dark'));
$filterInput->setFieldSize('15'); $filterInput->setFieldSize('15');
$filterInput->setOnKeyPress("SubmitForm('apply_filter', event);"); $filterInput->setOnKeyPress("SubmitForm('apply_filter', event);");
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type); parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type->getScope());
} }
/** /**
@ -459,14 +461,14 @@ class lamList {
$index = $sortMapping[$i]; $index = $sortMapping[$i];
$rowID = base64_encode($info[$index]['dn']); $rowID = base64_encode($info[$index]['dn']);
if ((($i - $table_begin) % 2) == 1) { if ((($i - $table_begin) % 2) == 1) {
$classes = ' ' . $this->type . '-bright'; $classes = ' ' . $this->type->getScope() . '-bright';
} }
else { else {
$classes = ' ' . $this->type . '-dark'; $classes = ' ' . $this->type->getScope() . '-dark';
} }
echo("<tr class=\"$classes\"" . echo("<tr class=\"$classes\"" .
" onClick=\"list_click('" . $rowID . "')\"\n" . " onClick=\"list_click('" . $rowID . "')\"\n" .
" onDblClick=\"top.location.href='../account/edit.php?type=" . $this->type . "&amp;DN=" . rawurlencode($info[$index]['dn']) . "'\">\n"); " onDblClick=\"top.location.href='../account/edit.php?type=" . $this->type->getId() . "&amp;DN=" . rawurlencode($info[$index]['dn']) . "'\">\n");
echo " <td align=\"center\"><input class=\"accountBoxUnchecked\" onClick=\"list_click('" . $rowID . "')\"" . echo " <td align=\"center\"><input class=\"accountBoxUnchecked\" onClick=\"list_click('" . $rowID . "')\"" .
" type=\"checkbox\" name=\"" . $rowID . "\"></td>\n"; " type=\"checkbox\" name=\"" . $rowID . "\"></td>\n";
$this->listPrintToolLinks($info[$index], $rowID); $this->listPrintToolLinks($info[$index], $rowID);
@ -480,7 +482,7 @@ class lamList {
} }
// display select all link // display select all link
$colspan = sizeof($this->attrArray) + 1; $colspan = sizeof($this->attrArray) + 1;
echo "<tr class=\"" . $this->type . "-bright\">\n"; echo "<tr class=\"" . $this->type->getScope() . "-bright\">\n";
echo "<td align=\"center\"><a href=\"#\" onClick=\"list_switchAccountSelection();\"><img height=16 width=16 src=\"../../graphics/select.png\" alt=\"select all\"></a></td>\n"; echo "<td align=\"center\"><a href=\"#\" onClick=\"list_switchAccountSelection();\"><img height=16 width=16 src=\"../../graphics/select.png\" alt=\"select all\"></a></td>\n";
echo "<td colspan=$colspan>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" . echo "<td colspan=$colspan>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" .
"<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n"; "<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n";
@ -499,13 +501,13 @@ class lamList {
$toolCount = 0; $toolCount = 0;
$group = new htmlGroup(); $group = new htmlGroup();
// edit link // edit link
$editLink = new htmlLink('', "../account/edit.php?type=" . $this->type . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/edit.png'); $editLink = new htmlLink('', "../account/edit.php?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/edit.png');
$editLink->setTitle(_("Edit")); $editLink->setTitle(_("Edit"));
$group->addElement($editLink); $group->addElement($editLink);
$toolCount++; $toolCount++;
// delete link // delete link
if (checkIfWriteAccessIsAllowed($this->type) && checkIfDeleteEntriesIsAllowed($this->type)) { if (checkIfWriteAccessIsAllowed($this->type->getId()) && checkIfDeleteEntriesIsAllowed($this->type->getId())) {
$deleteLink = new htmlLink('', "deletelink.php?type=" . $this->type . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/delete.png'); $deleteLink = new htmlLink('', "deletelink.php?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/delete.png');
$deleteLink->setTitle(_("Delete")); $deleteLink->setTitle(_("Delete"));
$group->addElement($deleteLink); $group->addElement($deleteLink);
$toolCount++; $toolCount++;
@ -518,14 +520,14 @@ class lamList {
// additional tools // additional tools
$tools = $this->getAdditionalTools(); $tools = $this->getAdditionalTools();
for ($i = 0; $i < sizeof($tools); $i++) { for ($i = 0; $i < sizeof($tools); $i++) {
$toolLink = new htmlLink('', $tools[$i]->getLinkTarget() . "?type=" . $this->type . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/' . $tools[$i]->getImage()); $toolLink = new htmlLink('', $tools[$i]->getLinkTarget() . "?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/' . $tools[$i]->getImage());
$toolLink->setTitle($tools[$i]->getName()); $toolLink->setTitle($tools[$i]->getName());
$group->addElement($toolLink); $group->addElement($toolLink);
$toolCount++; $toolCount++;
} }
$width = ($toolCount * 20) + 20; $width = ($toolCount * 20) + 20;
echo "<td align='center' style=\"white-space: nowrap; width: ${width}px;\">"; echo "<td align='center' style=\"white-space: nowrap; width: ${width}px;\">";
parseHtml(null, $group, array(), false, $this->tabindex, $this->type); parseHtml(null, $group, array(), false, $this->tabindex, $this->type->getScope());
echo "</td>\n"; echo "</td>\n";
} }
@ -560,16 +562,16 @@ class lamList {
} }
// check if button was pressed and if we have to add/delete an account or call file upload // check if button was pressed and if we have to add/delete an account or call file upload
if (isset($_POST['new']) || isset($_POST['del']) || isset($_POST['fileUpload'])){ if (isset($_POST['new']) || isset($_POST['del']) || isset($_POST['fileUpload'])){
if (!checkIfWriteAccessIsAllowed($this->type)) { if (!checkIfWriteAccessIsAllowed($this->type->getId())) {
die(); die();
} }
// add new account // add new account
if (isset($_POST['new']) && checkIfNewEntriesAreAllowed($this->type)){ if (isset($_POST['new']) && checkIfNewEntriesAreAllowed($this->type->getId())){
metaRefresh("../account/edit.php?type=" . $this->type . "&amp;suffix=" . $this->suffix); metaRefresh("../account/edit.php?type=" . $this->type->getId() . "&amp;suffix=" . $this->suffix);
exit; exit;
} }
// delete account(s) // delete account(s)
elseif (isset($_POST['del']) && checkIfDeleteEntriesIsAllowed($this->type)){ elseif (isset($_POST['del']) && checkIfDeleteEntriesIsAllowed($this->type->getId())){
// search for checkboxes // search for checkboxes
$accounts = array_keys($_POST, "on"); $accounts = array_keys($_POST, "on");
// build DN list // build DN list
@ -578,13 +580,13 @@ class lamList {
$_SESSION['delete_dn'][] = base64_decode($accounts[$i]); $_SESSION['delete_dn'][] = base64_decode($accounts[$i]);
} }
if (sizeof($accounts) > 0) { if (sizeof($accounts) > 0) {
metaRefresh("../delete.php?type=" . $this->type); metaRefresh("../delete.php?type=" . $this->type->getId());
exit; exit;
} }
} }
// file upload // file upload
elseif (isset($_POST['fileUpload']) && checkIfNewEntriesAreAllowed($this->type)){ elseif (isset($_POST['fileUpload']) && checkIfNewEntriesAreAllowed($this->type->getId())){
metaRefresh("../upload/masscreate.php?type=" . $this->type); metaRefresh("../upload/masscreate.php?type=" . $this->type->getId());
exit; exit;
} }
} }
@ -662,7 +664,7 @@ class lamList {
$cookieValue .= $this->configOptions[$i]->getID() . "=" . $this->configOptions[$i]->getValue() . ';'; $cookieValue .= $this->configOptions[$i]->getID() . "=" . $this->configOptions[$i]->getValue() . ';';
} }
// save options as cookie for one year // save options as cookie for one year
setcookie("ListOptions_" . $this->type, $cookieValue, time()+60*60*24*365, "/", null, null, true); setcookie("ListOptions_" . $this->type->getId(), $cookieValue, time()+60*60*24*365, "/", null, null, true);
// notify subclasses // notify subclasses
$this->listConfigurationChanged(); $this->listConfigurationChanged();
} }
@ -688,17 +690,17 @@ class lamList {
$selAccounts[] = $id; $selAccounts[] = $id;
} }
// get possible PDF structures // get possible PDF structures
$pdf_structures = getPDFStructureDefinitions($this->type); $pdf_structures = getPDFStructureDefinitions($this->type->getId());
$this->listPrintHeader(); $this->listPrintHeader();
echo "<div class=\"ui-tabs-nav " . $this->type . "-bright\">"; echo "<div class=\"ui-tabs-nav " . $this->type->getScope() . "-bright\">";
echo "<div class=\"smallPaddingContent\">\n"; echo "<div class=\"smallPaddingContent\">\n";
$refresh = '&amp;norefresh=true'; $refresh = '&amp;norefresh=true';
if (isset($_GET['refresh']) && ($_GET['refresh'] == 'true')) { if (isset($_GET['refresh']) && ($_GET['refresh'] == 'true')) {
$refresh = '&amp;refresh=true'; $refresh = '&amp;refresh=true';
} }
echo "<form action=\"list.php?type=" . $this->type . $refresh . "\" method=\"post\">\n"; echo "<form action=\"list.php?type=" . $this->type->getId() . $refresh . "\" method=\"post\">\n";
$container = new htmlTable(); $container = new htmlTable();
$container->addElement(new htmlSubTitle(_('Create PDF file')), true); $container->addElement(new htmlSubTitle(_('Create PDF file')), true);
@ -735,7 +737,7 @@ class lamList {
$container->addElement(new htmlHiddenInput('clickedAccount', $id)); $container->addElement(new htmlHiddenInput('clickedAccount', $id));
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $this->tabindex, $this->type); parseHtml(null, $container, array(), false, $this->tabindex, $this->type->getScope());
$this->listPrintFooter(); $this->listPrintFooter();
} }
@ -753,7 +755,7 @@ class lamList {
$suffixList[getAbstractDN($this->possibleSuffixes[$i])] = $this->possibleSuffixes[$i]; $suffixList[getAbstractDN($this->possibleSuffixes[$i])] = $this->possibleSuffixes[$i];
} }
$suffixSelect = new htmlSelect('suffix', $suffixList, array($this->suffix)); $suffixSelect = new htmlSelect('suffix', $suffixList, array($this->suffix));
$suffixSelect->setOnchangeEvent("listOUchanged('" . $this->type . "', this)"); $suffixSelect->setOnchangeEvent("listOUchanged('" . $this->type->getId() . "', this)");
$suffixSelect->setRightToLeftTextDirection(true); $suffixSelect->setRightToLeftTextDirection(true);
$suffixSelect->setSortElements(false); $suffixSelect->setSortElements(false);
$suffixSelect->setHasDescriptiveElements(true); $suffixSelect->setHasDescriptiveElements(true);
@ -774,23 +776,22 @@ class lamList {
$left = new htmlGroup(); $left = new htmlGroup();
// button part // button part
$left->alignment = htmlElement::ALIGN_LEFT; $left->alignment = htmlElement::ALIGN_LEFT;
if (checkIfWriteAccessIsAllowed($this->type)) { if (checkIfWriteAccessIsAllowed($this->type->getId())) {
// add button // add button
if (checkIfNewEntriesAreAllowed($this->type)) { if (checkIfNewEntriesAreAllowed($this->type->getId())) {
$newButton = new htmlButton('new', $this->labels['newEntry']); $newButton = new htmlButton('new', $this->labels['newEntry']);
$newButton->setIconClass('createButton'); $newButton->setIconClass('createButton');
$left->addElement($newButton); $left->addElement($newButton);
} }
// delete button // delete button
if (!$createOnly && checkIfDeleteEntriesIsAllowed($this->type)) { if (!$createOnly && checkIfDeleteEntriesIsAllowed($this->type->getId())) {
$left->addElement(new htmlSpacer('1px', null)); $left->addElement(new htmlSpacer('1px', null));
$delButton = new htmlButton('del', $this->labels['deleteEntry']); $delButton = new htmlButton('del', $this->labels['deleteEntry']);
$delButton->setIconClass('deleteButton'); $delButton->setIconClass('deleteButton');
$left->addElement($delButton); $left->addElement($delButton);
} }
$type = new $this->type();
$toolSettings = $_SESSION['config']->getToolSettings(); $toolSettings = $_SESSION['config']->getToolSettings();
if ($type->supportsFileUpload() && checkIfNewEntriesAreAllowed($this->type) if ($this->type->getBaseType()->supportsFileUpload() && checkIfNewEntriesAreAllowed($this->type->getId())
&& !(isset($toolSettings['tool_hide_toolFileUpload']) && ($toolSettings['tool_hide_toolFileUpload'] == 'true'))) { && !(isset($toolSettings['tool_hide_toolFileUpload']) && ($toolSettings['tool_hide_toolFileUpload'] == 'true'))) {
$left->addElement(new htmlSpacer('20px', null)); $left->addElement(new htmlSpacer('20px', null));
$uploadButton = new htmlButton('fileUpload', _('File upload')); $uploadButton = new htmlButton('fileUpload', _('File upload'));
@ -815,7 +816,7 @@ class lamList {
$this->addExtraInputElementsToTopArea($left, $right); $this->addExtraInputElementsToTopArea($left, $right);
$table->addElement($left); $table->addElement($left);
$table->addElement($right); $table->addElement($right);
parseHtml(null, $table, array(), false, $this->tabindex, $this->type); parseHtml(null, $table, array(), false, $this->tabindex, $this->type->getScope());
} }
/** /**
@ -844,8 +845,8 @@ class lamList {
</form></div></div> </form></div></div>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function() { jQuery(document).ready(function() {
jQuery('#tab_<?php echo $this->type; ?>').addClass('ui-tabs-active'); jQuery('#tab_<?php echo $this->type->getId(); ?>').addClass('ui-tabs-active');
jQuery('#tab_<?php echo $this->type; ?>').addClass('ui-state-active'); jQuery('#tab_<?php echo $this->type->getId(); ?>').addClass('ui-state-active');
window.onload = listResizeITabContentDiv; window.onload = listResizeITabContentDiv;
window.onresize = listResizeITabContentDiv; window.onresize = listResizeITabContentDiv;
jQuery('#filterButton').button(); jQuery('#filterButton').button();
@ -862,33 +863,10 @@ class lamList {
* @return array attribute list * @return array attribute list
*/ */
protected function listGetAttributeDescriptionList() { protected function listGetAttributeDescriptionList() {
$attrs = $this->type->getAttributes();
$ret = array(); $ret = array();
$attr_string = $_SESSION["config"]->get_listAttributes($this->type); foreach ($attrs as $attr) {
$temp_array = explode(";", $attr_string); $ret[$attr->getAttributeName()] = $attr->getAlias();
$hash_table = LAM\TYPES\getListAttributeDescriptions($this->type);
$hash_table = array_change_key_case($hash_table, CASE_LOWER);
// generate column attributes and descriptions
for ($i = 0; $i < sizeof($temp_array); $i++) {
// if value is predifined, look up description in hash_table
if (substr($temp_array[$i],0,1) == "#") {
$attr = strtolower(substr($temp_array[$i],1));
if (isset($hash_table[$attr])) {
$ret[$attr] = $hash_table[$attr];
}
else {
$ret[$attr] = $attr;
}
}
// if not predefined, the attribute is seperated by a ":" from description
else {
$attr = explode(":", $temp_array[$i]);
if (isset($attr[1])) {
$ret[$attr[0]] = $attr[1];
}
else {
$ret[$attr[0]] = $attr[0];
}
}
} }
return $ret; return $ret;
} }
@ -932,9 +910,18 @@ class lamList {
$this->sortDirection = $_GET['sortdirection']; $this->sortDirection = $_GET['sortdirection'];
} }
// check search suffix // check search suffix
if (isset($_POST['suffix'])) $this->suffix = $_POST['suffix']; // new suffix selected via combobox if (isset($_POST['suffix'])) {
elseif (isset($_GET['suffix'])) $this->suffix = $_GET['suffix']; // new suffix selected via combobox // new suffix selected via combobox
elseif (!$this->suffix) $this->suffix = $_SESSION["config"]->get_Suffix($this->type); // default suffix $this->suffix = $_POST['suffix'];
}
elseif (isset($_GET['suffix'])) {
// new suffix selected via combobox
$this->suffix = $_GET['suffix'];
}
elseif (!$this->suffix) {
// default suffix
$this->suffix = $this->type->getSuffix();
}
// check if LDAP data should be refreshed // check if LDAP data should be refreshed
$this->refresh = true; $this->refresh = true;
if (isset($_GET['norefresh'])) $this->refresh = false; if (isset($_GET['norefresh'])) $this->refresh = false;
@ -949,10 +936,10 @@ class lamList {
protected function listRefreshData() { protected function listRefreshData() {
// check suffix // check suffix
if (!$this->suffix) { if (!$this->suffix) {
$this->suffix = $_SESSION["config"]->get_Suffix($this->type); // default suffix $this->suffix = $this->type->getSuffix(); // default suffix
} }
// configure search filter // configure search filter
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules $module_filter = get_ldap_filter($this->type->getId()); // basic filter is provided by modules
$filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")"; $filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
$attrs = $this->attrArray; $attrs = $this->attrArray;
// remove virtual attributes from list // remove virtual attributes from list
@ -975,8 +962,7 @@ class lamList {
call_user_func_array('StatusMessage', $lastError); call_user_func_array('StatusMessage', $lastError);
} }
// generate list of possible suffixes // generate list of possible suffixes
$typeObj = new $this->type(); $this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
$this->possibleSuffixes = $typeObj->getSuffixList();
} }
/** /**
@ -1039,7 +1025,7 @@ class lamList {
*/ */
protected function listPrintConfigurationPage() { protected function listPrintConfigurationPage() {
echo "<div id=\"settingsDialog\" class=\"hidden\">\n"; echo "<div id=\"settingsDialog\" class=\"hidden\">\n";
echo "<form id=\"settingsDialogForm\" action=\"list.php?type=" . $this->type . "&amp;norefresh=true\" method=\"post\">\n"; echo "<form id=\"settingsDialogForm\" action=\"list.php?type=" . $this->type->getId() . "&amp;norefresh=true\" method=\"post\">\n";
echo '<table width="100%"><tr><td>'; echo '<table width="100%"><tr><td>';
$configContainer = new htmlTable(); $configContainer = new htmlTable();
@ -1049,7 +1035,7 @@ class lamList {
$configContainer->addElement(new htmlHiddenInput('saveConfigOptions', 'ok')); $configContainer->addElement(new htmlHiddenInput('saveConfigOptions', 'ok'));
addSecurityTokenToMetaHTML($configContainer); addSecurityTokenToMetaHTML($configContainer);
parseHtml('', $configContainer, array(), false, $this->tabindex, $this->type); parseHtml('', $configContainer, array(), false, $this->tabindex, $this->type->getScope());
echo "</td></tr></table>\n"; echo "</td></tr></table>\n";
echo '</form>'; echo '</form>';

View File

@ -150,10 +150,12 @@ class ConfiguredType {
private $alias; private $alias;
private $ldapFilter; private $additionalLdapFilter;
private $hidden; private $hidden;
private $baseType;
/** /**
* Constructor * Constructor
* *
@ -172,7 +174,7 @@ class ConfiguredType {
$this->suffix = $suffix; $this->suffix = $suffix;
$this->attributes = $attributes; $this->attributes = $attributes;
$this->alias = $alias; $this->alias = $alias;
$this->ldapFilter = $ldapFilter; $this->additionalLdapFilter = $ldapFilter;
$this->hidden = $hidden; $this->hidden = $hidden;
} }
@ -206,7 +208,7 @@ class ConfiguredType {
/** /**
* Returns a list of configured attributes. * Returns a list of configured attributes.
* *
* @return array $attributes list of ListAttribute * @return ListAttribute[] $attributes list of ListAttribute
*/ */
public function getAttributes() { public function getAttributes() {
return $this->attributes; return $this->attributes;
@ -226,8 +228,8 @@ class ConfiguredType {
* *
* @return string $ldapFilter LDAP filter * @return string $ldapFilter LDAP filter
*/ */
public function getLdapFilter() { public function getAdditionalLdapFilter() {
return $this->ldapFilter; return $this->additionalLdapFilter;
} }
/** /**
@ -239,6 +241,20 @@ class ConfiguredType {
return $this->hidden; return $this->hidden;
} }
/**
* Returns the base type of this configured type.
*
* @return baseType base type
*/
public function getBaseType() {
if ($this->baseType != null) {
return $this->baseType;
}
$scope = $this->scope;
$this->baseType = new $scope();
return $this->baseType;
}
} }
/** /**
@ -314,6 +330,15 @@ class ListAttribute {
*/ */
class TypeManager { class TypeManager {
public function getConfiguredType($typeId) {
$configuredTypes = array();
$activeTypes = $_SESSION['config']->get_ActiveTypes();
if (in_array($typeId, $activeTypes)) {
return $this->buildConfiguredType($typeId);
}
return null;
}
/** /**
* Returns a list of configured account types. * Returns a list of configured account types.
* *

View File

@ -5,7 +5,7 @@
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) 2009 - 2012 Pozdnyak Pavel Copyright (C) 2009 - 2012 Pozdnyak Pavel
2010 - 2013 Roland Gruber 2010 - 2016 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
@ -160,14 +160,14 @@ class lamAsteriskExtList extends lamList {
/** /**
* Groups the extensions. * Groups the extensions.
* *
* (non-PHPdoc) * (non-PHPdoc)
* @see lamList::listRefreshData() * @see lamList::listRefreshData()
*/ */
protected function listRefreshData() { protected function listRefreshData() {
parent::listRefreshData(); parent::listRefreshData();
// configure search filter // configure search filter
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules $module_filter = get_ldap_filter($this->type->getId()); // basic filter is provided by modules
$filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")"; $filter = "(&" . $module_filter . $this->buildLDAPAttributeFilter() . ")";
$attrs = $this->attrArray; $attrs = $this->attrArray;
$attrs[] = "astpriority"; $attrs[] = "astpriority";
@ -176,17 +176,16 @@ class lamAsteriskExtList extends lamList {
if ($lastError != null) { if ($lastError != null) {
call_user_func_array('StatusMessage', $lastError); call_user_func_array('StatusMessage', $lastError);
} }
$entries = $this->normalizeLdapOutput($entries); $entries = $this->normalizeLdapOutput($entries);
$this->entries = $entries; $this->entries = $entries;
// generate list of possible suffixes // generate list of possible suffixes
$typeObj = new $this->type(); $this->possibleSuffixes = $this->type->getBaseType()->getSuffixList();
$this->possibleSuffixes = $typeObj->getSuffixList();
} }
/** /**
* Groups the extensions. * Groups the extensions.
* *
* @param array $entries extension entries * @param array $entries extension entries
*/ */
private function normalizeLdapOutput($entries){ private function normalizeLdapOutput($entries){
@ -198,7 +197,7 @@ class lamAsteriskExtList extends lamList {
} }
return array_values($entries); return array_values($entries);
} }
} }
?> ?>

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) 2008 Thomas Manninger Copyright (C) 2008 Thomas Manninger
2009 - 2014 Roland Gruber 2009 - 2016 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
@ -37,7 +37,7 @@ $Id$
**/ **/
class dhcp extends baseType { class dhcp extends baseType {
/** /**
* Constructs a new DHCP type object. * Constructs a new DHCP type object.
*/ */
@ -46,7 +46,7 @@ class dhcp extends baseType {
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another DHCP entry'); $this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another DHCP entry');
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to DHCP list'); $this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to DHCP list');
} }
/** /**
* Returns the alias name of this account type. * Returns the alias name of this account type.
* *
@ -220,7 +220,7 @@ class lamDHCPList extends lamList {
// Search after the fixed ip entry // Search after the fixed ip entry
if (is_array($entry['dhcpstatements'])) { if (is_array($entry['dhcpstatements'])) {
foreach($entry['dhcpstatements'] AS $id => $value) { foreach($entry['dhcpstatements'] AS $id => $value) {
if (!is_array($value) && array_shift( explode(" ", $value) ) == "fixed-address") { if (!is_array($value) && array_shift( explode(" ", $value) ) == "fixed-address") {
$ip = explode(" ", $value); $ip = explode(" ", $value);
echo $ip['1']; echo $ip['1'];
@ -260,15 +260,15 @@ class lamDHCPList extends lamList {
parent::listPrintTableCellContent($entry, $attribute); parent::listPrintTableCellContent($entry, $attribute);
} }
} }
/** /**
* Add DCP main settings button. * Add DCP main settings button.
* *
* @param htmlGroup $left left part * @param htmlGroup $left left part
* @param htmlGroup $right right part * @param htmlGroup $right right part
*/ */
protected function addExtraInputElementsToTopArea(&$left, &$right) { protected function addExtraInputElementsToTopArea(&$left, &$right) {
if (checkIfWriteAccessIsAllowed($this->type)) { if (checkIfWriteAccessIsAllowed($this->type->getId())) {
$left->addElement(new htmlSpacer('20px', null)); $left->addElement(new htmlSpacer('20px', null));
$dhcpButton = new htmlButton('dhcpDefaults', $this->labels['dhcpDefaults']); $dhcpButton = new htmlButton('dhcpDefaults', $this->labels['dhcpDefaults']);
$dhcpButton->setIconClass('settingsButton'); $dhcpButton->setIconClass('settingsButton');
@ -278,7 +278,7 @@ class lamDHCPList extends lamList {
/** /**
* Manages all POST actions (e.g. button pressed) for the account lists. * Manages all POST actions (e.g. button pressed) for the account lists.
* *
* @return String HTML fragment to insert into beginning of account list * @return String HTML fragment to insert into beginning of account list
*/ */
function listDoPost() { function listDoPost() {

View File

@ -829,10 +829,10 @@ class lamUserList extends lamList {
_('Locked') => self::FILTER_LOCKED _('Locked') => self::FILTER_LOCKED
); );
$filterInput = new htmlSelect('filter' . strtolower($attrName), $filterOptions, array($value)); $filterInput = new htmlSelect('filter' . strtolower($attrName), $filterOptions, array($value));
$filterInput->setCSSClasses(array($this->type . '-dark')); $filterInput->setCSSClasses(array($this->type->getScope() . '-dark'));
$filterInput->setHasDescriptiveElements(true); $filterInput->setHasDescriptiveElements(true);
$filterInput->setOnchangeEvent('document.getElementsByName(\'apply_filter\')[0].click();'); $filterInput->setOnchangeEvent('document.getElementsByName(\'apply_filter\')[0].click();');
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type); parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type->getScope());
} }
/** /**

View File

@ -41,22 +41,23 @@ startSecureSession();
setlanguage(); setlanguage();
$type = $_GET['type']; $typeManager = new LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
// check if list is hidden // check if list is hidden
if (isAccountTypeHidden($type)) { if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to access hidden account list: ' . $type); logNewMessage(LOG_ERR, 'User tried to access hidden account list: ' . $type->getId());
die(); die();
} }
// create list object if needed // create list object if needed
$listClass = LAM\TYPES\getListClassName($type); $listClass = LAM\TYPES\getListClassName($type->getScope());
if (!isset($_SESSION['list_' . $type])) { if (!isset($_SESSION['list_' . $type->getId()])) {
$list = new $listClass($type); $list = new $listClass($type);
$_SESSION['list_' . $type] = $list; $_SESSION['list_' . $type->getId()] = $list;
} }
// show page // show page
$_SESSION['list_' . $type]->showPage(); $_SESSION['list_' . $type->getId()]->showPage();
?> ?>

View File

@ -3,7 +3,7 @@
$Id$ $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 - 2014 Roland Gruber Copyright (C) 2003 - 2016 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
@ -40,11 +40,14 @@ setlanguage();
$conf = $_SESSION['config']; $conf = $_SESSION['config'];
$new_suffs = array(); $new_suffs = array();
// get list of active types // get list of active types
$types = $_SESSION['config']->get_ActiveTypes(); $typeManager = new LAM\TYPES\TypeManager();
for ($i = 0; $i < sizeof($types); $i++) { $types = $typeManager->getConfiguredTypes();
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($conf->get_Suffix($types[$i])), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER); foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
$res = @ldap_get_entries($_SESSION['ldap']->server(), $info); $res = @ldap_get_entries($_SESSION['ldap']->server(), $info);
if (!$res && !in_array($conf->get_Suffix($types[$i]), $new_suffs)) $new_suffs[] = $conf->get_Suffix($types[$i]); if (!$res && !in_array($type->getSuffix(), $new_suffs)) {
$new_suffs[] = $type->getSuffix();
}
} }
// display page to add suffixes, if needed // display page to add suffixes, if needed
@ -53,11 +56,11 @@ if ((sizeof($new_suffs) > 0) && checkIfWriteAccessIsAllowed()) {
} }
else { else {
if (sizeof($types) > 0) { if (sizeof($types) > 0) {
for ($i = 0; $i < sizeof($types); $i++) { foreach ($types as $type) {
if (isAccountTypeHidden($types[$i])) { if ($type->isHidden()) {
continue; continue;
} }
metaRefresh("lists/list.php?type=" . $types[$i]); metaRefresh("lists/list.php?type=" . $type->getId());
break; break;
} }
} }