From f9995d7cb6314baabe5f2c8460a21c4d5a529561 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 24 Dec 2016 13:04:31 +0100 Subject: [PATCH] new type API --- lam/lib/lists.inc | 152 +++++++++++++++------------------- lam/lib/types.inc | 35 ++++++-- lam/lib/types/asteriskExt.inc | 19 ++--- lam/lib/types/dhcp.inc | 16 ++-- lam/lib/types/user.inc | 4 +- lam/templates/lists/list.php | 15 ++-- lam/templates/main.php | 19 +++-- 7 files changed, 137 insertions(+), 123 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 32efcc4e..49b7750a 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -1,4 +1,6 @@ configOptions) > 0) { - if (isset($_COOKIE["ListOptions_" . $this->type])) { - $cookieValue = $_COOKIE["ListOptions_" . $this->type]; + if (isset($_COOKIE["ListOptions_" . $this->type->getId()])) { + $cookieValue = $_COOKIE["ListOptions_" . $this->type->getId()]; $valueParts = explode(";", $cookieValue); $values = array(); for ($i = 0; $i < sizeof($valueParts); $i++) { @@ -172,7 +174,7 @@ class lamList { // show form echo "
"; echo "
\n"; - echo ("
type . "&norefresh=true\" method=\"post\">\n"); + echo ("type->getId() . "&norefresh=true\" method=\"post\">\n"); // draw account list if accounts were found if (sizeof($this->entries) > 0) { // buttons @@ -289,12 +291,12 @@ class lamList { if ($count > $this->maxPageEntries) { echo(""); if ($this->page != 1) { - echo("type . "&norefresh=true&page=1" . + echo("type->getId() . "&norefresh=true&page=1" . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter . "\">" . "\"\"\n"); } if ($this->page > 11) { - echo("type . "&norefresh=true&page=" . ($this->page - 10) . + echo("type->getId() . "&norefresh=true&page=" . ($this->page - 10) . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter . "\">" . "\"\"\n"); } @@ -307,24 +309,24 @@ class lamList { continue; } if ($i == $this->page - 1) { - $url = "list.php?type=" . $this->type . "&norefresh=true" . + $url = "list.php?type=" . $this->type->getId() . "&norefresh=true" . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter; echo ''; } else { - echo " type . "&norefresh=true&page=" . ($i + 1) . + echo " type->getId() . "&norefresh=true&page=" . ($i + 1) . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter . "\">" . ($i + 1) . "\n"; } } if ($this->page < ($pageCount - 10)) { - echo("type . "&norefresh=true&page=" . ($this->page + 10) . + echo("type->getId() . "&norefresh=true&page=" . ($this->page + 10) . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter . "\">" . "\"\"\n"); } if ($this->page < $pageCount) { - echo("type . "&norefresh=true&page=" . $pageCount . + echo("type->getId() . "&norefresh=true&page=" . $pageCount . "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $filter . "\">" . "\"\"\n"); } @@ -352,8 +354,8 @@ class lamList { protected function listPrintTableHeader() { $filter = $this->getFilterAsTextForURL(); // print table header - echo "type . "-border collapse accountlist ui-corner-all\" width=\"100%\">\n"; - echo "type . "-dark\">\n"; + echo "
type->getScope() . "-border collapse accountlist ui-corner-all\" width=\"100%\">\n"; + echo "type->getScope() . "-dark\">\n"; echo "\n"; echo "\n"; @@ -364,17 +366,17 @@ class lamList { if ($this->sortDirection < 0) { $sortImage = "sort_desc.png"; } - echo "\n"; } - else echo "\n"; } echo "\n"; // print filter row - echo "type . "-bright\">\n"; + echo "type->getScope() . "-bright\">\n"; echo "\n"; @@ -389,7 +391,7 @@ class lamList { $clearFilterButton->setTitle(_('Clear filter')); $filterGroup->addElement($clearFilterButton); } - parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type); + parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type->getScope()); echo "\n"; // print input boxes for filters for ($k = 0; $k < sizeof($this->descArray); $k++) { @@ -416,10 +418,10 @@ class lamList { } } $filterInput = new htmlInputField('filter' . strtolower($attrName), $value); - $filterInput->setCSSClasses(array($this->type . '-dark')); + $filterInput->setCSSClasses(array($this->type->getScope() . '-dark')); $filterInput->setFieldSize('15'); $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]; $rowID = base64_encode($info[$index]['dn']); if ((($i - $table_begin) % 2) == 1) { - $classes = ' ' . $this->type . '-bright'; + $classes = ' ' . $this->type->getScope() . '-bright'; } else { - $classes = ' ' . $this->type . '-dark'; + $classes = ' ' . $this->type->getScope() . '-dark'; } echo("type . "&DN=" . rawurlencode($info[$index]['dn']) . "'\">\n"); + " onDblClick=\"top.location.href='../account/edit.php?type=" . $this->type->getId() . "&DN=" . rawurlencode($info[$index]['dn']) . "'\">\n"); echo " \n"; $this->listPrintToolLinks($info[$index], $rowID); @@ -480,7 +482,7 @@ class lamList { } // display select all link $colspan = sizeof($this->attrArray) + 1; - echo "type . "-bright\">\n"; + echo "type->getScope() . "-bright\">\n"; echo "\n"; echo "\n"; @@ -499,13 +501,13 @@ class lamList { $toolCount = 0; $group = new htmlGroup(); // 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")); $group->addElement($editLink); $toolCount++; // delete link - if (checkIfWriteAccessIsAllowed($this->type) && checkIfDeleteEntriesIsAllowed($this->type)) { - $deleteLink = new htmlLink('', "deletelink.php?type=" . $this->type . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/delete.png'); + if (checkIfWriteAccessIsAllowed($this->type->getId()) && checkIfDeleteEntriesIsAllowed($this->type->getId())) { + $deleteLink = new htmlLink('', "deletelink.php?type=" . $this->type->getId() . "&DN='" . rawurlencode($account['dn']) . "'", '../../graphics/delete.png'); $deleteLink->setTitle(_("Delete")); $group->addElement($deleteLink); $toolCount++; @@ -518,14 +520,14 @@ class lamList { // additional tools $tools = $this->getAdditionalTools(); 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()); $group->addElement($toolLink); $toolCount++; } $width = ($toolCount * 20) + 20; echo "\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 if (isset($_POST['new']) || isset($_POST['del']) || isset($_POST['fileUpload'])){ - if (!checkIfWriteAccessIsAllowed($this->type)) { + if (!checkIfWriteAccessIsAllowed($this->type->getId())) { die(); } // add new account - if (isset($_POST['new']) && checkIfNewEntriesAreAllowed($this->type)){ - metaRefresh("../account/edit.php?type=" . $this->type . "&suffix=" . $this->suffix); + if (isset($_POST['new']) && checkIfNewEntriesAreAllowed($this->type->getId())){ + metaRefresh("../account/edit.php?type=" . $this->type->getId() . "&suffix=" . $this->suffix); exit; } // delete account(s) - elseif (isset($_POST['del']) && checkIfDeleteEntriesIsAllowed($this->type)){ + elseif (isset($_POST['del']) && checkIfDeleteEntriesIsAllowed($this->type->getId())){ // search for checkboxes $accounts = array_keys($_POST, "on"); // build DN list @@ -578,13 +580,13 @@ class lamList { $_SESSION['delete_dn'][] = base64_decode($accounts[$i]); } if (sizeof($accounts) > 0) { - metaRefresh("../delete.php?type=" . $this->type); + metaRefresh("../delete.php?type=" . $this->type->getId()); exit; } } // file upload - elseif (isset($_POST['fileUpload']) && checkIfNewEntriesAreAllowed($this->type)){ - metaRefresh("../upload/masscreate.php?type=" . $this->type); + elseif (isset($_POST['fileUpload']) && checkIfNewEntriesAreAllowed($this->type->getId())){ + metaRefresh("../upload/masscreate.php?type=" . $this->type->getId()); exit; } } @@ -662,7 +664,7 @@ class lamList { $cookieValue .= $this->configOptions[$i]->getID() . "=" . $this->configOptions[$i]->getValue() . ';'; } // 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 $this->listConfigurationChanged(); } @@ -688,17 +690,17 @@ class lamList { $selAccounts[] = $id; } // get possible PDF structures - $pdf_structures = getPDFStructureDefinitions($this->type); + $pdf_structures = getPDFStructureDefinitions($this->type->getId()); $this->listPrintHeader(); - echo "
type . "-bright\">"; + echo "
type->getScope() . "-bright\">"; echo "
\n"; $refresh = '&norefresh=true'; if (isset($_GET['refresh']) && ($_GET['refresh'] == 'true')) { $refresh = '&refresh=true'; } - echo "type . $refresh . "\" method=\"post\">\n"; + echo "type->getId() . $refresh . "\" method=\"post\">\n"; $container = new htmlTable(); $container->addElement(new htmlSubTitle(_('Create PDF file')), true); @@ -735,7 +737,7 @@ class lamList { $container->addElement(new htmlHiddenInput('clickedAccount', $id)); addSecurityTokenToMetaHTML($container); - parseHtml(null, $container, array(), false, $this->tabindex, $this->type); + parseHtml(null, $container, array(), false, $this->tabindex, $this->type->getScope()); $this->listPrintFooter(); } @@ -753,7 +755,7 @@ class lamList { $suffixList[getAbstractDN($this->possibleSuffixes[$i])] = $this->possibleSuffixes[$i]; } $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->setSortElements(false); $suffixSelect->setHasDescriptiveElements(true); @@ -774,23 +776,22 @@ class lamList { $left = new htmlGroup(); // button part $left->alignment = htmlElement::ALIGN_LEFT; - if (checkIfWriteAccessIsAllowed($this->type)) { + if (checkIfWriteAccessIsAllowed($this->type->getId())) { // add button - if (checkIfNewEntriesAreAllowed($this->type)) { + if (checkIfNewEntriesAreAllowed($this->type->getId())) { $newButton = new htmlButton('new', $this->labels['newEntry']); $newButton->setIconClass('createButton'); $left->addElement($newButton); } // delete button - if (!$createOnly && checkIfDeleteEntriesIsAllowed($this->type)) { + if (!$createOnly && checkIfDeleteEntriesIsAllowed($this->type->getId())) { $left->addElement(new htmlSpacer('1px', null)); $delButton = new htmlButton('del', $this->labels['deleteEntry']); $delButton->setIconClass('deleteButton'); $left->addElement($delButton); } - $type = new $this->type(); $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'))) { $left->addElement(new htmlSpacer('20px', null)); $uploadButton = new htmlButton('fileUpload', _('File upload')); @@ -815,7 +816,7 @@ class lamList { $this->addExtraInputElementsToTopArea($left, $right); $table->addElement($left); $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 {
\"select " . "" . _("Select all") . "type . "&". + echo "type->getId() . "&". "sort=" . strtolower($this->attrArray[$k]) . $filter . "&norefresh=y" . "\">" . $this->descArray[$k] . " \"sorttype . "&". + else echo "type->getId() . "&". "sort=" . strtolower($this->attrArray[$k]) . $filter . "&norefresh=y" . "\">" . $this->descArray[$k] . "
"; printHelpLink(getHelp('', '250'), '250'); echo "
\"select " . "" . _("Select all") . ""; - parseHtml(null, $group, array(), false, $this->tabindex, $this->type); + parseHtml(null, $group, array(), false, $this->tabindex, $this->type->getScope()); echo "