responsive account table

This commit is contained in:
Roland Gruber 2018-10-28 10:11:45 +01:00
parent dec9585733
commit 985828da3a
4 changed files with 37 additions and 248 deletions

View File

@ -201,13 +201,7 @@ class lamList {
// navigation bar
$this->listDrawNavigationBar(sizeof($this->entries));
echo ("<br>\n");
echo "<div id=\"listScrollArea\" style=\"overflow: auto; padding: 1px;\">";
$this->printAccountTable($this->entries);
// account table head
$this->listPrintTableHeader();
// account table body
$this->listPrintTableBody($this->entries);
echo "</div>";
}
else {
// buttons
@ -218,8 +212,6 @@ class lamList {
echo ("<br>\n");
$accounts = array();
$this->printAccountTable($accounts);
// account table head
$this->listPrintTableHeader();
echo "</table><br>\n";
}
$this->printFooter();
@ -474,7 +466,7 @@ class lamList {
$actionElement->addElement($clearFilterButton);
}
$filterElements = array($actionElement);
$filterElements = array(new htmlDiv(null, $actionElement, array('nowrap')));
$clearFilter = isset($_POST['clear_filter']);
foreach ($this->attrArray as $attributeName) {
$attributeName = strtolower($attributeName);
@ -483,7 +475,7 @@ class lamList {
if (!$clearFilter && isset($this->filters[$attributeName])) {
$value = $this->filters[$attributeName];
}
$filterInput = new htmlInputField('filter' . $attributeName, $value);
$filterInput = new htmlInputField('filter' . $attributeName, $value, null);
$filterInput->setCSSClasses(array($this->type->getScope() . '-bright'));
$filterInput->setOnKeyPress("SubmitForm('apply_filter', event);");
$filterElements[] = $filterInput;
@ -531,11 +523,10 @@ class lamList {
$onClickEvents[$i + 2] = "list_click('" . $rowID . "');";
$onDoubleClickEvents[$i + 2] = "top.location.href='../account/edit.php?type=" . $this->type->getId() . "&amp;DN=" . rawurlencode($info[$index]['dn']) . "';";
$this->addToolLinks($info[$index], $rowID, $actionElement);
$row[] = $actionElement;
$row[] = new htmlDiv(null, $actionElement, array('nowrap'));
foreach ($this->attrArray as $attributeName) {
$attributeName = strtolower($attributeName);
$row[] = new htmlOutputText($attributeName); // TODO
//$this->listPrintTableCellContent($info[$index], $attributeName);
$row[] = $this->getTableCellContent($info[$index], $attributeName);
}
$data[] = $row;
}
@ -577,84 +568,6 @@ class lamList {
}
}
/**
* Prints the attribute and filter row at the account table head
* @deprecated
*/
protected function listPrintTableHeader() {
$filter = $this->getFilterAsTextForURL();
// print table header
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->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 "<td>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" .
"<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n";
// table header
for ($k = 0; $k < sizeof($this->descArray); $k++) {
if (strtolower($this->attrArray[$k]) == $this->sortColumn) {
$sortImage = "sort_asc.png";
if ($this->sortDirection < 0) {
$sortImage = "sort_desc.png";
}
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] .
"&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->getId() . "&amp;".
"sort=" . strtolower($this->attrArray[$k]) . $filter . "&amp;norefresh=y" . "\">" . $this->descArray[$k] . "</a></th>\n";
}
echo "</tr>\n";
// print filter row
echo "<tr align=\"center\" class=\"" . $this->type->getScope() . "-bright\">\n";
echo "<td width=22 height=34>";
printHelpLink(getHelp('', '250'), '250');
echo "</td>\n";
echo "<td>";
$filterGroup = new htmlGroup();
$filterButton = new htmlButton('apply_filter', 'filter.png', true);
$filterButton->setTitle(_("Filter"));
$filterGroup->addElement($filterButton);
if (sizeof($this->filters) > 0) {
$filterGroup->addElement(new htmlSpacer('1px', null));
$clearFilterButton = new htmlButton('clear_filter', 'clearFilter.png', true);
$clearFilterButton->setTitle(_('Clear filter'));
$filterGroup->addElement($clearFilterButton);
}
parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type->getScope());
echo "</td>\n";
// print input boxes for filters
for ($k = 0; $k < sizeof($this->descArray); $k++) {
echo "<td align=\"left\">";
if ($this->canBeFiltered($this->attrArray[$k])) {
$this->printFilterArea($this->attrArray[$k], isset($_POST['clear_filter']));
}
echo "</td>\n";
}
echo "</tr></thead>\n";
}
/**
* Prints the content of a single attribute filter area.
*
* @param String $attrName attribute name
* @param boolean $clearFilter true if filter value should be cleared
* @deprecated
*/
protected function printFilterArea($attrName, $clearFilter) {
$value = "";
if (!$clearFilter) {
if (isset($this->filters[strtolower($attrName)])) {
$value = $this->filters[strtolower($attrName)];
}
}
$filterInput = new htmlInputField('filter' . strtolower($attrName), $value);
$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->getScope());
}
/**
* Returns if the given attribute can be filtered.
* If filtering is not possible then no filter box will be displayed.
@ -668,123 +581,27 @@ class lamList {
}
/**
* Prints the entry list
*
* @param array $info entries
* @deprecated
*/
protected function listPrintTableBody(&$info) {
echo "<tbody>\n";
// 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);
// get sort mapping
$sortMapping = &$this->sortMapping;
if (empty($sortMapping)) {
$sortMapping = array();
$infoSize = sizeof($info);
for ($i = 0; $i < $infoSize; $i++) {
$sortMapping[$i] = $i;
}
}
// print account list
for ($i = $table_begin; $i < $table_end; $i++) {
$index = $sortMapping[$i];
$rowID = base64_encode($info[$index]['dn']);
if ((($i - $table_begin) % 2) == 1) {
$classes = ' ' . $this->type->getScope() . '-bright';
}
else {
$classes = ' ' . $this->type->getScope() . '-dark';
}
echo("<tr class=\"$classes\"" .
" onClick=\"list_click('" . $rowID . "')\"\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 . "')\"" .
" type=\"checkbox\" name=\"" . $rowID . "\"></td>\n";
$this->listPrintToolLinks($info[$index], $rowID);
for ($k = 0; $k < sizeof($this->attrArray); $k++) {
echo ("<td>");
$attrName = strtolower($this->attrArray[$k]);
$this->listPrintTableCellContent($info[$index], $attrName);
echo ("</td>\n");
}
echo("</tr>\n");
}
// display select all link
$colspan = sizeof($this->attrArray) + 1;
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 colspan=$colspan>&nbsp;<a href=\"#\" onClick=\"list_switchAccountSelection();\">" .
"<font color=\"black\"><small>" . _("Select all") . "</small></font></a></td>\n";
echo "</tr>\n";
echo "</tbody>\n";
echo "</table>\n";
}
/**
* Prints the tool image links (e.g. edit and delete) for each account.
*
* @param array $account LDAP attributes
* @param String $id account ID
* @deprecated
*/
private function listPrintToolLinks($account, $id) {
$toolCount = 0;
$group = new htmlGroup();
// edit link
$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->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++;
}
// PDF button
$pdfButton = new htmlButton("createPDF_" . $id, 'pdf.png', true);
$pdfButton->setTitle(_('Create PDF file'));
$group->addElement($pdfButton);
$toolCount++;
// additional tools
$tools = $this->getAdditionalTools();
for ($i = 0; $i < sizeof($tools); $i++) {
$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 "<td align='center' style=\"white-space: nowrap; width: ${width}px;\">";
parseHtml(null, $group, array(), false, $this->tabindex, $this->type->getScope());
echo "</td>\n";
}
/**
* Prints the content of a cell in the account list for a given LDAP entry and attribute.
* Returns 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
* @return htmlElement content
*/
protected function listPrintTableCellContent(&$entry, &$attribute) {
protected function getTableCellContent(&$entry, &$attribute) {
// print all attribute entries seperated by "; "
if (isset($entry[$attribute]) && sizeof($entry[$attribute]) > 0) {
if (is_array($entry[$attribute])) {
if (($attribute == 'entryexpiretimestamp') && !empty($entry[$attribute][0])) {
echo formatLDAPTimestamp($entry[$attribute][0]);
return new htmlOutputText(formatLDAPTimestamp($entry[$attribute][0]));
}
else {
// sort array
sort($entry[$attribute]);
echo htmlspecialchars(implode("; ", $entry[$attribute]), ENT_QUOTES, "UTF-8");
return new htmlOutputText(implode("; ", $entry[$attribute]));
}
}
else {
echo htmlspecialchars($entry[$attribute], ENT_QUOTES, "UTF-8");
return new htmlOutputText($entry[$attribute]);
}
}
}
@ -1110,9 +927,6 @@ class lamList {
jQuery(document).ready(function() {
jQuery('#tab_<?php echo $this->type->getId(); ?>').addClass('ui-tabs-active');
jQuery('#tab_<?php echo $this->type->getId(); ?>').addClass('ui-state-active');
window.onload = listResizeITabContentDiv;
window.onresize = listResizeITabContentDiv;
jQuery('#filterButton').button();
});
</script>
<?php

View File

@ -284,12 +284,10 @@ class lamGroupList extends lamList {
}
/**
* 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
* {@inheritDoc}
* @see lamList::getTableCellContent()
*/
function listPrintTableCellContent(&$entry, &$attribute) {
protected function getTableCellContent(&$entry, &$attribute) {
if ($attribute == "memberuid") {
// $gid is used for linking primary group memebers
$gid = -1;
@ -350,11 +348,10 @@ class lamGroupList extends lamList {
}
}
}
echo implode("; ", $linklist);
return new htmlOutputText(implode("; ", $linklist), false);
}
// pretty print member DNs
elseif (in_array_ignore_case($attribute, array('member', 'uniqueMember', 'owner', 'roleOccupant')) && !empty($entry[$attribute])) {
echo '<div class="rightToLeftText">';
$values = $entry[$attribute];
if (!empty($values)) {
usort($values, 'compareDN');
@ -375,12 +372,11 @@ class lamGroupList extends lamList {
$values[$i] = getAbstractDN($values[$i]);
}
}
echo implode('<br>', $values);
echo '</div>';
return new htmlDiv(null, new htmlOutputText(implode('<br>', $values), false), array('rightToLeftText'));
}
// print all other attributes
else {
parent::listPrintTableCellContent($entry, $attribute);
return parent::getTableCellContent($entry, $attribute);
}
}

View File

@ -717,24 +717,21 @@ class lamUserList extends lamList {
}
/**
* 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
* {@inheritDoc}
* @see lamList::getTableCellContent()
*/
protected function listPrintTableCellContent(&$entry, &$attribute) {
protected function getTableCellContent(&$entry, &$attribute) {
// check if there is something to display at all
if (($attribute != self::ATTR_ACCOUNT_STATUS) && (!isset($entry[$attribute]) || !is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1))) {
parent::listPrintTableCellContent($entry, $attribute);
return;
return parent::getTableCellContent($entry, $attribute);
}
// translate GID to group name
if (($attribute == "gidnumber") && ($this->trans_primary == "on")) {
if (isset($this->trans_primary_hash[$entry[$attribute][0]])) {
echo $this->trans_primary_hash[$entry[$attribute][0]];
return new htmlOutputText($this->trans_primary_hash[$entry[$attribute][0]]);
}
else {
parent::listPrintTableCellContent($entry, $attribute);
return parent::getTableCellContent($entry, $attribute);
}
}
// show user photos
@ -764,47 +761,45 @@ class lamUserList extends lamList {
if ($imgHeight < 64) {
$minSize = $imgHeight;
}
$imgTitle = _('Click to switch between thumbnail and original size.');
echo "<img id=\"img$imgNumber\" title=\"$imgTitle\" height=$minSize src=\"" . $photoFile . "\" alt=\"" . _('Photo') . "\">";
echo '<script type="text/javascript">';
echo "addResizeHandler(document.getElementById(\"img$imgNumber\"), $minSize, " . $imgHeight . ")";
echo '</script>';
return new htmlImage($photoFile, null, $minSize, _('Photo'));
}
elseif (($attribute == 'mail') || ($attribute == 'rfc822Mailbox')) {
$group = new htmlGroup();
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
for ($i = 0; $i < sizeof($entry[$attribute]); $i++) {
if ($i > 0) {
echo ", ";
$group->addElement(new htmlOutputText(", "));
}
echo "<a href=\"mailto:" . $entry[$attribute][$i] . "\">" . $entry[$attribute][$i] . "</a>\n";
$group->addElement(new htmlLink($entry[$attribute][$i], "mailto:" . $entry[$attribute][$i]));
}
}
return $group;
}
// expire dates
elseif ($attribute == 'shadowexpire') {
if (!empty($entry[$attribute][0])) {
$time = new DateTime('@' . $entry[$attribute][0] * 24 * 3600, getTimeZone());
echo $time->format('d.m.Y');
return new htmlOutputText($time->format('d.m.Y'));
}
}
elseif ($attribute == 'sambakickofftime') {
if (!empty($entry[$attribute][0])) {
if ($entry[$attribute][0] > 2147483648) {
echo "";
return new htmlOutputText("");
}
else {
$date = new DateTime('@' . $entry[$attribute][0], new DateTimeZone('UTC'));
echo $date->format('d.m.Y');
return new htmlOutputText($date->format('d.m.Y'));
}
}
}
// account status
elseif ($attribute == self::ATTR_ACCOUNT_STATUS) {
$this->printAccountStatus($entry);
return $this->getAccountStatus($entry);
}
// print all other attributes
else {
parent::listPrintTableCellContent($entry, $attribute);
return parent::getTableCellContent($entry, $attribute);
}
}
@ -1040,11 +1035,12 @@ class lamUserList extends lamList {
}
/**
* Prints the account status.
* Returns the account status.
*
* @param array $attrs LDAP attributes
* @return htmlElement content
*/
private function printAccountStatus(&$attrs) {
private function getAccountStatus(&$attrs) {
// check status
$unixAvailable = self::isUnixAvailable($attrs);
$sambaAvailable = self::isSambaAvailable($attrs);
@ -1144,10 +1140,10 @@ class lamUserList extends lamList {
$tipContent .= '<tr><td>' . _('Password expired') . '&nbsp;&nbsp;</td><td><img height=16 width=16 src=&quot;../../graphics/lock.png&quot;></td></tr>';
}
$tipContent .= '</table>';
echo '<img helptitle="' . _('Account status') . '" helpdata="' . $tipContent . '" alt="status" height=16 width=16 src="../../graphics/' . $icon . '">';
return new htmlOutputText('<img helptitle="' . _('Account status') . '" helpdata="' . $tipContent . '" alt="status" height=16 width=16 src="../../graphics/' . $icon . '">', false);
}
else {
echo '<img alt="status" height=16 width=16 src="../../graphics/' . $icon . '">';
return new htmlImage('../../graphics/' . $icon, 16, 16, 'status');
}
}

View File

@ -62,23 +62,6 @@ function listPageNumberKeyPress(url, e) {
return true;
}
/**
* Resizes the content area of the account lists to fit the window size.
* This prevents that the whole page is scrolled in the browser. Only the account table has scroll bars.
*/
function listResizeITabContentDiv() {
var myDiv = document.getElementById("listTabContentArea");
var height = document.documentElement.clientHeight;
height -= myDiv.offsetTop;
height -= 105;
myDiv.style.height = height +"px";
var myDivScroll = document.getElementById("listScrollArea");
var top = myDivScroll.offsetTop;
var scrollHeight = height - (top - myDiv.offsetTop);
myDivScroll.style.height = scrollHeight + "px";
};
/**
* Shows the dialog to change the list settings.
*