type = $type; $this->labels = array( 'nav' => _("%s object(s) found"), 'error_noneFound' => _("No objects found!"), 'newEntry' => _("New object"), 'deleteEntry' => _("Delete object"), 'createPDF' => _("Create PDF for selected object(s)"), 'createPDFAll' => _("Create PDF for all objects")); } /** * Prints the HTML code to display the list view. */ function showPage() { // do POST actions $this->listDoPost(); // get some parameters $this->listGetParams(); // print HTML head $this->listPrintHeader(); // refresh data if needed if ($this->refresh) $this->listRefreshData(); // filter entries $filteredEntries = $this->listFilterAccounts(); // sort rows by sort column if ($filteredEntries) { $filteredEntries = $this->listSort($filteredEntries); } // show form echo ("
type . "&norefresh=true\" method=\"post\">\n"); // draw account list if accounts were found if (sizeof($filteredEntries) > 0) { // navigation bar $this->listDrawNavigationBar(sizeof($filteredEntries)); echo ("
\n"); // account table head $this->listPrintTableHeader(); // account table body $this->listPrintTableBody($filteredEntries); // navigation bar $this->listDrawNavigationBar(sizeof($filteredEntries)); echo ("
\n"); // print combobox with possible sub-DNs $this->listShowOUSelection(); // buttons $this->listPrintButtons(false); } else { // account table head $this->listPrintTableHeader(); echo "
\n"; // print combobox with possible sub-DNs $this->listShowOUSelection(); echo ("
\n"); $this->listPrintButtons(true); } echo ("
\n"); echo "\n"; } /** * Builds the regular expressions from the filter values. * * @return array filter data array($attribute => array('regex' => $reg, 'original' => $orig)) * $reg is the regular expression to use, $orig the user's unmodified input string */ function listBuildFilter() { $filter = array(); // build filter array for ($i = 0; $i < sizeof($this->attrArray); $i++) { if (isset($_POST["filter" . strtolower($this->attrArray[$i])]) && eregi('^([0-9a-z _\\*\\$-])+$', $_POST["filter" . strtolower($this->attrArray[$i])])) { $filter[$this->attrArray[$i]]['original'] = $_POST["filter" . strtolower($this->attrArray[$i])]; $filter[$this->attrArray[$i]]['regex'] = $_POST["filter" . strtolower($this->attrArray[$i])]; // replace special characters $filter[$this->attrArray[$i]]['regex'] = str_replace("*", "(.)*", $filter[$this->attrArray[$i]]['regex']); $filter[$this->attrArray[$i]]['regex'] = str_replace('$', '[$]', $filter[$this->attrArray[$i]]['regex']); // add string begin and end $filter[$this->attrArray[$i]]['regex'] = "^" . $filter[$this->attrArray[$i]]['regex'] . "$"; } } // save filter string $filterAttributes = array_keys($filter); $searchFilter = array(); for ($i = 0; $i < sizeof($filterAttributes); $i++) { $searchFilter[] = "filter" . $filterAttributes[$i] . "=" . $filter[$filterAttributes[$i]]['original']; } if (sizeof($searchFilter) > 0) { $searchFilter = "&" . implode("&", $searchFilter); } else { $searchFilter = ""; } $this->filterText = $searchFilter; return $filter; } /** * Removes all entries which do not fit to the filter. * * @return array filtered list of accounts */ function listFilterAccounts() { $entries = $this->entries; $filter = $this->listBuildFilter(); $attributes = array_keys($filter); for ($r = 0; $r < sizeof($entries); $r++) { for ($a = 0; $a < sizeof($attributes); $a++) { // check if filter fits $found = false; for ($i = 0; $i < sizeof($entries[$r][$attributes[$a]]); $i++) { if (eregi($filter[$attributes[$a]]['regex'], $entries[$r][$attributes[$a]][$i])) { $found = true; break; } } if (!$found) { // remove account and reindex array unset($entries[$r]); $entries = array_values($entries); $r--; break; } } } if (sizeof($entries) == 0) StatusMessage("WARN", "", $this->labels['error_noneFound']); // TODO correct message return $entries; } /** * Sorts an account list by a given attribute * * @param array $info the account list * @return array sorted account list */ function listSort($info) { if (!is_array($this->attrArray)) return $info; if (!is_string($this->sortColumn)) return $info; // sort and return account list usort($info, array($this, "cmp_array")); return $info; } /** * Compare function used for usort-method * * Rows are sorted with the first attribute entry of the sort column. * If objects have attributes with multiple values only the first is used for sorting. * * @param array $a first row which is compared * @param array $b second row which is compared * @return integer 0 if both are equal, 1 if $a is greater, -1 if $b is greater */ function cmp_array($a, $b) { // sort specifies the sort column $sort = $this->sortColumn; $attr_array = $this->attrArray; // sort by first column if no attribute is given if (!$sort) $sort = strtolower($attr_array[0]); if ($sort != "dn") { // sort by first attribute with name $sort return strnatcasecmp($a[$sort][0], $b[$sort][0]); } else { return strnatcasecmp($a[$sort], $b[$sort]); } } /** * Draws a navigation bar to switch between pages * * @param integer $count number of account entries */ function listDrawNavigationBar($count) { echo("type . "nav\" width=\"100%\" border=\"0\">\n"); echo("\n"); echo(""); } echo(""); echo("
  "); if ($this->page != 1) { echo("type . "&norefresh=true&page=" . ($this->page - 1) . "&sort=" . $this->sortColumn . $this->filterText . "\"><=\n"); } else { echo("<="); } echo(" "); if ($this->page < ($count / $this->maxPageEntries)) { echo("type . "&norefresh=true&page=" . ($this->page + 1) . "&sort=" . $this->sortColumn . $this->filterText . "\">=>\n"); } else { echo("=>type . "nav-text\">"); echo" "; printf($this->labels['nav'], $count); echo("type . "nav-activepage\" align=\"right\">"); for ($i = 0; $i < ($count / $this->maxPageEntries); $i++) { if ($i == $this->page - 1) { echo(" " . ($i + 1)); } else { echo(" type . "&norefresh=true&page=" . ($i + 1) . "&sort=" . $this->sortColumn . "\">" . ($i + 1) . "\n"); } } echo("
\n"); } /** * Prints the attribute and filter row at the account table head */ function listPrintTableHeader() { // print table header echo "type . "list\" width=\"100%\">\n"; echo "type . "list-head\">\n\n\n"; // table header for ($k = 0; $k < sizeof($this->descArray); $k++) { if (strtolower($this->attrArray[$k]) == $this->sortColumn) { echo "\n"; } else echo "\n"; } echo "\n"; // print filter row echo "type . "list\">\n"; echo "\n"; echo "\n"; // print input boxes for filters for ($k = 0; $k < sizeof ($this->descArray); $k++) { $value = ""; if (isset($_POST["filter" . strtolower($this->attrArray[$k])])) { $value = " value=\"" . $_POST["filter" . strtolower($this->attrArray[$k])] . "\""; } echo "\n"; } echo "\n"; } /** * Prints the entry list * * @param array $info entries */ function listPrintTableBody($info) { // calculate which rows to show $table_begin = ($this->page - 1) * $this->maxPageEntries; if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info); else $table_end = ($this->page * $this->maxPageEntries); // print account list for ($i = $table_begin; $i < $table_end; $i++) { echo("type . "list\" onMouseOver=\"list_over(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . " onMouseOut=\"list_out(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . " onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . " onDblClick=\"parent.frames[1].location.href='../account/edit.php?type=" . $this->type . "&DN=" . $info[$i]['dn'] . "'\">\n"); if (isset($_GET['selectall'])) { echo " \n"; } else { echo " \n"; } echo (" \n"); for ($k = 0; $k < sizeof($this->attrArray); $k++) { echo ("\n"); } echo("\n"); } // display select all link $colspan = sizeof($this->attrArray) + 1; echo "type . "list\">\n"; echo "\n"; echo "\n"; echo "\n"; echo ("
type . "list-sort\">type . "&". "sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] . "type . "&". "sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] . "
"; // help link echo ""; echo "\"""; echo "\n"; echo ""; echo ""; echo ""; echo ("attrArray[$k]) ."\"" . $value . ">"); echo "
type . "')\"" . " type=\"checkbox\" checked name=\"" . $info[$i]['LAM_ID'] . "\">type . "')\"" . " type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\">type . "&DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . ""); // print all attribute entries seperated by "; " $attrName = strtolower($this->attrArray[$k]); if (isset($info[$i][$attrName]) && sizeof($info[$i][$attrName]) > 0) { // delete "count" entry unset($info[$i][$attrName]['count']); if (is_array($info[$i][$attrName])) { // sort array sort($info[$i][$attrName]); echo implode("; ", $info[$i][$attrName]); } else echo $info[$i][$attrName]; } echo ("
\"select type . "&norefresh=y&page=" . $this->page . "&sort=" . $this->sortColumn . $this->filterText . "&selectall=yes\">" . "" . _("Select all") . "
"); echo ("
"); } /** * Manages all POST actions (e.g. button pressed) for the account lists. */ function listDoPost() { // check if button was pressed and if we have to add/delete an account if (isset($_POST['new']) || isset($_POST['del']) || isset($_POST['pdf']) || isset($_POST['pdf_all'])){ // add new account if (isset($_POST['new'])){ metaRefresh("../account/edit.php?type=" . $this->type); exit; } // delete account(s) elseif (isset($_POST['del'])){ // search for checkboxes $accounts = array_keys($_POST, "on"); $_SESSION['delete_dn'] = array(); for ($i = 0; $i < sizeof($accounts); $i++) { $_SESSION['delete_dn'][] = $this->entries[$accounts[$i]]['dn']; } if (sizeof($accounts) > 0) { metaRefresh("../delete.php?type=" . $this->type); exit; } } // PDF for selected accounts elseif (isset($_POST['pdf'])){ $pdf_structure = $_POST['pdf_structure']; // search for checkboxes $accounts = array_keys($_POST, "on"); $list = array(); // load accounts from LDAP for ($i = 0; $i < sizeof($accounts); $i++) { if (!isset($this->entries[$accounts[$i]]['dn'])) continue; $_SESSION["accountPDF-$i"] = new accountContainer($this->type, "accountPDF-$i"); $_SESSION["accountPDF-$i"]->load_account($this->entries[$accounts[$i]]['dn']); $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { createModulePDF($list,$pdf_structure); exit; } } // PDF for all accounts elseif (isset($_POST['pdf_all'])){ $list = array(); for ($i = 0; $i < sizeof($this->entries); $i++) { $_SESSION["accountPDF-$i"] = new accountContainer($this->type, "accountPDF-$i"); $_SESSION["accountPDF-$i"]->load_account($this->entries[$i]['dn']); $list[$i] = $_SESSION["accountPDF-$i"]; } if (sizeof($list) > 0) { createModulePDF($list,$_POST['pdf_structure']); exit; } } } } /** * Prints a combobox with possible sub-DNs. */ function listShowOUSelection() { if (sizeof($this->possibleSuffixes) > 1) { echo ("

\n"); echo ("" . _("Suffix") . ": "); echo ("\n"); echo (""); echo ("

\n"); } } /** * Prints the create, delete and PDF buttons. * * @param boolean $createOnly true if only the create button should be displayed */ function listPrintButtons($createOnly) { // add/delete/PDF buttons echo ("labels['newEntry'] . "\">\n"); if (!$createOnly) { echo ("labels['deleteEntry'] . "\">\n"); echo ("


\n"); echo "
PDF\n"; echo ("" . _('PDF structure') . ":      \n"; echo ("labels['createPDF'] . "\">\n"); echo " "; echo ("labels['createPDFAll'] . "\">\n"); echo "
"; } } /** * Prints the HTML head. */ function listPrintHeader() { echo $_SESSION['header']; echo "Account list\n"; echo "\n"; echo "type . ".css\">\n"; echo "\n"; $this->listPrintJavaScript(); } /** * Prints JavaScript code needed for mouse-over effects. */ function listPrintJavaScript() { echo "\n"; } /** * Returns an hash array containing with all attributes to be shown and their descriptions. * Format: array(attribute => description) * * @return array attribute list */ function listGetAttributeDescriptionList() { $ret = array(); $attr_string = $_SESSION["config"]->get_listAttributes($this->type); $temp_array = explode(";", $attr_string); $hash_table = getListAttributeDescriptions($this->type); // 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; } /** * Sets some internal parameters. */ function listGetParams() { // get current page if (isset($_GET["page"])) $this->page = $_GET["page"]; else $this->page = 1; // generate attribute-description table $temp_array = $this->listGetAttributeDescriptionList(); $this->attrArray = array_keys($temp_array); // list of LDAP attributes to show $this->descArray = array_values($temp_array); // list of descriptions for the attributes // get maximum count of entries shown on one page if ($_SESSION["config"]->get_MaxListEntries() <= 0) $this->maxPageEntries = 10; // default setting, if not yet set else $this->maxPageEntries = $_SESSION["config"]->get_MaxListEntries(); // get sorting column if (isset($_GET["sort"])) $this->sortColumn = $_GET["sort"]; else $this->sortColumn = strtolower($this->attrArray[0]); // check search suffix if (isset($_POST['suffix'])) $this->suffix = $_POST['suffix']; // new suffix selected via combobox elseif (!$this->suffix) $this->suffix = $_SESSION["config"]->get_Suffix($this->type); // default suffix // check if LDAP data should be refreshed $this->refresh = true; if (isset($_GET['norefresh'])) $this->refresh = false; if (isset($_POST['refresh'])) $this->refresh = true; } /** * Rereads the entries from LDAP. */ function listRefreshData() { // configure search filter $module_filter = get_ldap_filter($this->type); // basic filter is provided by modules $filter = "(&" . $module_filter . ")"; $attrs = $this->attrArray; $sr = @ldap_search($_SESSION["ldap"]->server(), $this->suffix, $filter, $attrs); if (ldap_errno($_SESSION["ldap"]->server()) == 4) { StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem.")); } if ($sr) { $info = ldap_get_entries($_SESSION["ldap"]->server, $sr); ldap_free_result($sr); // delete first array entry which is "count" unset($info['count']); // save position in original $info for ($i = 0; $i < sizeof($info); $i++) $info[$i]['LAM_ID'] = $i; // save results $this->entries = $info; } else { $this->entries = array(); StatusMessage("ERROR", _("LDAP Search failed! Please check your preferences."), $this->labels['error_noneFound']); // TODO correct message } // generate list of possible suffixes $this->possibleSuffixes = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($this->type)); } } ?>