diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc
index 8798db31..b5a775bd 100644
--- a/lam/lib/lists.inc
+++ b/lam/lib/lists.inc
@@ -3,7 +3,7 @@
$Id$
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
- Copyright (C) 2003 - 2006 Roland Gruber
+ Copyright (C) 2003 - 2007 Roland Gruber
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
@@ -62,7 +62,10 @@ class lamList {
var $maxPageEntries = 10;
/** sort column name */
- var $sortColumn;
+ protected $sortColumn;
+
+ /** sort direction: 1 for ascending, -1 for descending */
+ protected $sortDirection = 1;
/** LDAP suffix */
var $suffix;
@@ -269,10 +272,10 @@ class lamList {
if (!$sort) $sort = strtolower($this->attrArray[0]);
if ($sort != "dn") {
// sort by first attribute with name $sort
- return @strnatcasecmp($a[$sort][0], $b[$sort][0]);
+ return @strnatcasecmp($a[$sort][0], $b[$sort][0]) * $this->sortDirection;
}
else {
- return strnatcasecmp($a[$sort], $b[$sort]);
+ return strnatcasecmp($a[$sort], $b[$sort]) * $this->sortDirection;
}
}
@@ -288,12 +291,14 @@ class lamList {
echo("
");
if ($this->page != 1) {
echo("type . "&norefresh=true&page=" . ($this->page - 1) .
- "&sort=" . $this->sortColumn . $this->filterText . "\"> \n");
+ "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $this->filterText . "\">" .
+ " \n");
}
if ($this->page < ($count / $this->maxPageEntries)) {
echo("type . "&norefresh=true&page=" . ($this->page + 1) .
- "&sort=" . $this->sortColumn . $this->filterText . "\"> \n");
+ "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $this->filterText . "\">" .
+ " \n");
}
echo(" ");
@@ -308,7 +313,8 @@ class lamList {
echo(" " . ($i + 1));
}
else {
- echo(" type . "&norefresh=true&page=" . ($i + 1) . "&sort=" . $this->sortColumn . "\">" . ($i + 1) . " \n");
+ echo(" type . "&norefresh=true&page=" . ($i + 1) .
+ "&sort=" . $this->sortColumn . "&sortdirection=" . $this->sortDirection . $this->filterText . "\">" . ($i + 1) . " \n");
}
}
echo("\n");
@@ -324,8 +330,13 @@ class lamList {
// 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 "type . "list-sort\">type . "&".
- "sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] . " \n";
+ "sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] .
+ " \n";
}
else echo "type . "&".
"sort=" . strtolower($this->attrArray[$k]) . $this->filterText . "&norefresh=y" . "\">" . $this->descArray[$k] . " \n";
@@ -410,7 +421,7 @@ class lamList {
*
* $account array LDAP attributes
*/
- function listPrintToolLinks($account) {
+ private function listPrintToolLinks($account) {
// edit image
echo "type . "&DN='" . $account['dn'] . "'\">";
echo " ";
@@ -419,6 +430,13 @@ class lamList {
echo " type . "&DN='" . $account['dn'] . "'\">";
echo " ";
echo " ";
+ // additional tools
+ $tools = $this->getAdditionalTools();
+ for ($i = 0; $i < sizeof($tools); $i++) {
+ echo "getLinkTarget() . "?type=" . $this->type . "&DN='" . $account['dn'] . "'\">";
+ echo " getImage() . "\" alt=\"" . $tools[$i]->getName() . "\" title=\"" . $tools[$i]->getName() . "\">";
+ echo " ";
+ }
}
/**
@@ -678,8 +696,23 @@ class lamList {
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]);
+ if (isset($_GET["sort"])) {
+ if ($_GET["sort"] == $this->sortColumn) {
+ $this->sortDirection = -$this->sortDirection;
+ }
+ else {
+ $this->sortColumn = $_GET["sort"];
+ $this->sortDirection = 1;
+ }
+ }
+ else {
+ $this->sortColumn = strtolower($this->attrArray[0]);
+ $this->sortDirection = 1;
+ }
+ // get sort order
+ if (isset($_GET['sortdirection'])) {
+ $this->sortDirection = $_GET['sortdirection'];
+ }
// check search suffix
if (isset($_POST['suffix'])) $this->suffix = $_POST['suffix']; // new suffix selected via combobox
elseif (isset($_GET['suffix'])) $this->suffix = $_GET['suffix']; // new suffix selected via combobox
@@ -729,6 +762,73 @@ class lamList {
function listPrintAdditionalOptions() {
// may be used by subclasses
}
+
+ /**
+ * Returns a list of lamListTool objects to display next to the edit/delete buttons.
+ *
+ * @return lamListTool[] tools
+ */
+ protected function getAdditionalTools() {
+ return array();
+ }
+
+}
+
+/**
+ * Represents a tool which can be included in the account lists.
+ *
+ * @package lists
+ * @author Roland Gruber
+ */
+class lamListTool {
+
+ private $name;
+ private $image;
+ private $target;
+
+ /**
+ * Constructor
+ *
+ * @param String $name tool name
+ * @param String $image image file
+ * @param String $target target page
+ * @return lamListTool tool object
+ */
+ function lamListTool($name, $image, $target) {
+ $this->name = $name;
+ $this->image = $image;
+ $this->target = $target;
+ }
+
+ /**
+ * Returns the name of the tool image.
+ * The image is returned without path (e.g. mytool.png). All images must reside in the graphics folder.
+ *
+ * @return String image name
+ */
+ function getImage() {
+ return $this->image;
+ }
+
+ /**
+ * Returns the tool name.
+ * This is used for the tool tip.
+ *
+ * @return String name
+ */
+ function getName() {
+ return $this->name;
+ }
+
+ /**
+ * Returns the PHP file (relative to 'templates/lists') which will be the target for this tool.
+ * The target page will be opened with two GET parameters: DN and type (e.g. user)
+ *
+ * @return String page file (e.g. 'mytool.php')
+ */
+ function getLinkTarget() {
+ return $this->target;
+ }
}