";
// draw account list if accounts were found
if (sizeof($this->entries) > 0) {
// buttons
$this->listPrintButtons(false);
echo ("
\n");
// navigation bar
$this->listDrawNavigationBar(sizeof($this->entries));
echo ("
\n");
// account table head
$this->listPrintTableHeader();
// account table body
$this->listPrintTableBody($this->entries);
echo ("
\n");
// navigation bar
$this->listDrawNavigationBar(sizeof($this->entries));
echo ("
\n");
// buttons
$this->listPrintButtons(false);
echo ("
\n");
}
else {
// buttons
$this->listPrintButtons(true);
echo ("
\n");
// navigation bar
$this->listDrawNavigationBar(sizeof($this->entries));
echo ("
\n");
// account table head
$this->listPrintTableHeader();
echo "
\n";
}
$this->listPrintFooter();
}
/**
* Builds the regular expressions from the filter values.
*/
protected function listBuildFilter() {
$filter = array();
$filterParam = "";
$LDAPFilterPart = "";
// build filter array
for ($i = 0; $i < sizeof($this->attrArray); $i++) {
$foundFilter = null;
if (isset($_GET["filter" . strtolower($this->attrArray[$i])])) {
$foundFilter = $_GET["filter" . strtolower($this->attrArray[$i])];
}
if (isset($_POST["filter" . strtolower($this->attrArray[$i])])) {
$foundFilter = $_POST["filter" . strtolower($this->attrArray[$i])];
}
if (isset($foundFilter) && ($foundFilter != '')) {
if (preg_match('/^([\p{L}\p{N} _\\*\\$\\.-])+$/iu', $foundFilter)) { // \p{L} matches any Unicode letter
$filterParam .= "&filter" . $this->attrArray[$i] . '=' . $foundFilter;
$LDAPFilterPart .= '(' . $this->attrArray[$i] . '=' . $foundFilter . ')';
}
else {
StatusMessage('ERROR', _('Please enter a valid filter. Only letters, numbers and " _*$.-" are allowed.'), htmlspecialchars($foundFilter));
}
}
}
$this->filterText = $filterParam;
$this->filterPart = $LDAPFilterPart;
}
/**
* Sorts an account list by a given attribute
*
* @param array $info the account list
* @return array sorted account list
*/
protected 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
*/
protected function cmp_array(&$a, &$b) {
if ($this->sortColumn != "dn") {
// sort by first attribute with name $sort
return @strnatcasecmp($a[$this->sortColumn][0], $b[$this->sortColumn][0]) * $this->sortDirection;
}
else {
return strnatcasecmp($a[$this->sortColumn], $b[$this->sortColumn]) * $this->sortDirection;
}
}
/**
* Draws a navigation bar to switch between pages
*
* @param integer $count number of account entries
*/
protected function listDrawNavigationBar($count) {
echo("
\n");
}
/**
* Prints the attribute and filter row at the account table head
*/
protected function listPrintTableHeader() {
// print table header
echo "
");
}
/**
* Prints the tool image links (e.g. edit and delete) for each account.
*
* @param array $account LDAP attributes
* @param String $id account ID
*/
private function listPrintToolLinks($account, $id) {
// edit image
echo "
type . "&DN='" . rawurlencode($account['dn']) . "'\">";
echo "";
echo "\n ";
// delete image
if (checkIfWriteAccessIsAllowed()) {
echo "
type . "&DN='" . rawurlencode($account['dn']) . "'\">";
echo "";
echo "\n ";
}
// pdf image
$pdfButtonStyle = "background-image: url(../../graphics/pdf.png);background-position: -1px -1px;background-repeat: no-repeat;width:20px;height:20px;background-color:transparent;border-style:none;";
echo "
\n ";
// additional tools
$tools = $this->getAdditionalTools();
for ($i = 0; $i < sizeof($tools); $i++) {
echo "
getLinkTarget() . "?type=" . $this->type . "&DN='" . rawurlencode($account['dn']) . "'\">";
echo "getImage() . "\" alt=\"" . $tools[$i]->getName() . "\" title=\"" . $tools[$i]->getName() . "\">";
echo "\n ";
}
}
/**
* Prints the content of a cell in the account list for a given LDAP entry and attribute.
*
* @param array $entry LDAP attributes
* @param string $attribute attribute name
*/
protected function listPrintTableCellContent(&$entry, &$attribute) {
// print all attribute entries seperated by "; "
if (isset($entry[$attribute]) && sizeof($entry[$attribute]) > 0) {
if (is_array($entry[$attribute])) {
// sort array
sort($entry[$attribute]);
echo htmlspecialchars(implode("; ", $entry[$attribute]), ENT_QUOTES, "UTF-8");
}
else {
echo htmlspecialchars($entry[$attribute], ENT_QUOTES, "UTF-8");
}
}
}
/**
* Manages all POST actions (e.g. button pressed) for the account lists.
*/
protected function listDoPost() {
// check if button was pressed and if we have to add/delete an account
if (isset($_POST['new']) || isset($_POST['del'])){
if (!checkIfWriteAccessIsAllowed()) {
die();
}
// add new account
if (isset($_POST['new'])){
metaRefresh("../account/edit.php?type=" . $this->type . "&suffix=" . $this->suffix);
exit;
}
// delete account(s)
elseif (isset($_POST['del'])){
// search for checkboxes
$accounts = array_keys($_POST, "on");
// build DN list
$_SESSION['delete_dn'] = array();
for ($i = 0; $i < sizeof($accounts); $i++) {
$_SESSION['delete_dn'][] = base64_decode($accounts[$i]);
}
if (sizeof($accounts) > 0) {
metaRefresh("../delete.php?type=" . $this->type);
exit;
}
}
}
// PDF button
foreach ($_POST as $key => $value) {
if (strpos($key, 'createPDF_') > -1) {
$parts = explode("_", $key);
if (sizeof($parts) == 2) {
$this->showPDFPage($parts[1]);
exit;
}
}
}
// PDF creation Ok
if (isset($_POST['createPDFok'])) {
$pdfStruct = $_POST['pdf_structure'];
$option = $_POST['createFor'];
// create for clicked account
if ($option == 'DN') {
$_SESSION["accountPDF"] = new accountContainer($this->type, "accountPDF");
$_SESSION["accountPDF"]->load_account(base64_decode($_POST['clickedAccount']));
createModulePDF(array($_SESSION["accountPDF"]),$pdfStruct);
unset($_SESSION["accountPDF"]);
exit;
}
// create for all selected accounts
elseif ($option == 'SELECTED') {
// search for checkboxes
$accounts = array_keys($_POST, "on");
$list = array();
// load accounts from LDAP
for ($i = 0; $i < sizeof($accounts); $i++) {
$_SESSION["accountPDF-$i"] = new accountContainer($this->type, "accountPDF-$i");
$_SESSION["accountPDF-$i"]->load_account(base64_decode($accounts[$i]));
$list[$i] = $_SESSION["accountPDF-$i"];
}
if (sizeof($list) > 0) {
createModulePDF($list,$pdfStruct);
for ($i = 0; $i < sizeof($accounts); $i++) {
unset($_SESSION["accountPDF-$i"]);
}
exit;
}
}
// create for all accounts
elseif ($option == '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,$pdfStruct);
for ($i = 0; $i < sizeof($this->entries); $i++) {
// clean session
unset($_SESSION["accountPDF-$i"]);
}
exit;
}
}
elseif ($option == 'SESSION') {
createModulePDF(array($_SESSION[$_POST['PDFSessionID']]),$pdfStruct);
unset($_SESSION[$_GET['PDFSessionID']]);
exit;
}
}
// check if back from configuration page
if (sizeof($this->configOptions) > 0) {
if (isset($_POST['saveConfigOptions'])) {
$cookieValue = '';
for ($i = 0; $i < sizeof($this->configOptions); $i++) {
$this->configOptions[$i]->fillFromPostData();
$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, "/");
// notify subclasses
$this->listConfigurationChanged();
}
}
}
/**
* Shows the page where the user may select the PDF options.
*
* @param String $id account ID
*/
private function showPDFPage($id) {
$sessionObject = null;
$PDFSessionID = null;
if (($id == null) && isset($_GET['PDFSessionID'])) {
$PDFSessionID = $_GET['PDFSessionID'];
$sessionObject = $_SESSION[$PDFSessionID];
}
// search for checkboxes
$selAccounts = array_keys($_POST, "on");
if (!in_array($id, $selAccounts)) {
$selAccounts[] = $id;
}
$this->listPrintHeader();
echo "
\n";
echo "
\n");
echo "