From f6be307eeff4099ef5298a80909cf1a439103883 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 17 Feb 2007 16:26:08 +0000 Subject: [PATCH] added listPrintTableCellContent() --- lam/HISTORY | 4 ++ lam/docs/README.upgrade.txt | 18 +++++++ lam/lib/lists.inc | 60 +++++++++++++-------- lam/lib/types/group.inc | 89 ++++++++---------------------- lam/lib/types/host.inc | 2 +- lam/lib/types/mailAlias.inc | 2 +- lam/lib/types/smbDomain.inc | 2 +- lam/lib/types/user.inc | 105 +++++++++++++++--------------------- 8 files changed, 127 insertions(+), 155 deletions(-) diff --git a/lam/HISTORY b/lam/HISTORY index 705d07d4..dfe236f7 100644 --- a/lam/HISTORY +++ b/lam/HISTORY @@ -4,6 +4,10 @@ -> ShadowAccount: PDF entry for expire date was wrong (1658868) -> Debian package did not include lamdaemonOld.pl (1660493) + Developers: + API changes: + - added listPrintTableCellContent() to class lamList + 24.01.2007 1.2.0 - Samba 3: better handling of date values diff --git a/lam/docs/README.upgrade.txt b/lam/docs/README.upgrade.txt index 9c7e7981..07a46130 100644 --- a/lam/docs/README.upgrade.txt +++ b/lam/docs/README.upgrade.txt @@ -2,6 +2,24 @@ Upgrade instructions: ===================== +1.2.0 -> 1.3.0: +=============== + +Users: + +No changes. + + +Developers: + +New lamList function: + + The function listPrintTableCellContent() allows you to control how the LDAP + attributes are displayed in the table. This can be used to display links + or binary data. + + + 1.1.x -> 1.2.0: =============== diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index 665d42f6..a726c81a 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -204,27 +204,28 @@ class lamList { * @return array filtered list of accounts */ function listFilterAccounts() { - $entries = $this->entries; + $entries = array(); $filter = $this->listBuildFilter(); $attributes = array_keys($filter); - for ($r = 0; $r < sizeof($entries); $r++) { + for ($r = 0; $r < sizeof($this->entries); $r++) { + $skip = false; 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])) { + for ($i = 0; $i < sizeof($this->entries[$r][$attributes[$a]]); $i++) { + if (eregi($filter[$attributes[$a]]['regex'], $this->entries[$r][$attributes[$a]][$i])) { $found = true; break; } } if (!$found) { - // remove account and reindex array - unset($entries[$r]); - $entries = array_values($entries); - $r--; + $skip = true; break; } } + if (!$skip) { + $entries[] = &$this->entries[$r]; + } } if (sizeof($entries) == 0) StatusMessage("WARN", $this->labels['error_noneFound']); return $entries; @@ -237,7 +238,7 @@ class lamList { * @param array $info the account list * @return array sorted account list */ - function listSort($info) { + function listSort(&$info) { if (!is_array($this->attrArray)) return $info; if (!is_string($this->sortColumn)) return $info; // sort and return account list @@ -256,7 +257,7 @@ class lamList { * @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) { + function cmp_array(&$a, &$b) { // sort specifies the sort column $sort = $this->sortColumn; $attr_array = $this->attrArray; @@ -363,7 +364,7 @@ class lamList { * * @param array $info entries */ - function listPrintTableBody($info) { + 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); @@ -385,18 +386,8 @@ class lamList { echo (" type . "&DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "\n"); for ($k = 0; $k < sizeof($this->attrArray); $k++) { echo (""); - // 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]; - } + $this->listPrintTableCellContent($info[$i], $attrName); echo ("\n"); } echo("\n"); @@ -411,6 +402,26 @@ class lamList { echo "\n"; echo (""); } + + /** + * 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 + */ + function listPrintTableCellContent(&$entry, &$attribute) { + // print all attribute entries seperated by "; " + if (isset($entry[$attribute]) && sizeof($entry[$attribute]) > 0) { + // delete "count" entry + unset($entry[$attribute]['count']); + if (is_array($entry[$attribute])) { + // sort array + sort($entry[$attribute]); + echo implode("; ", $entry[$attribute]); + } + else echo $entry[$attribute]; + } + } /** * Manages all POST actions (e.g. button pressed) for the account lists. @@ -665,7 +676,10 @@ class lamList { // 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; + for ($i = 0; $i < sizeof($info); $i++) { + $info[$i]['LAM_ID'] = $i; + if (isset($info[$i]['count'])) unset($info[$i]['count']); + } // save results $this->entries = $info; } diff --git a/lam/lib/types/group.inc b/lam/lib/types/group.inc index 35a4761a..be6fbafd 100644 --- a/lam/lib/types/group.inc +++ b/lam/lib/types/group.inc @@ -110,80 +110,37 @@ class lamGroupList extends lamList { 'nav' => _("%s group(s) found"), 'error_noneFound' => _("No groups found!"), 'newEntry' => _("New group"), - 'deleteEntry' => _("Delete group"), + 'deleteEntry' => _("Delete group(s)"), 'createPDF' => _("Create PDF for selected group(s)"), 'createPDFAll' => _("Create PDF for all groups")); } /** - * 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 " type . "')\"" . - " type=\"checkbox\" checked name=\"" . $info[$i]['LAM_ID'] . "\">\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 + */ + function listPrintTableCellContent(&$entry, &$attribute) { + if ($attribute == "memberuid") { + if (!is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return; + if (isset($entry[$attribute]['count'])) unset($entry[$attribute]['count']); + // sort array + sort($entry[$attribute]); + // make a link for each member of the group + $linklist = array(); + for ($d = 0; $d < sizeof($entry[$attribute]); $d++) { + $user = $entry[$attribute][$d]; // user name + $linklist[$d] = "" . $user . ""; } - else { - echo " type . "')\"" . - " type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\">\n"; - } - echo (" type . "&DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "\n"); - for ($k = 0; $k < sizeof($this->attrArray); $k++) { - echo (""); - // 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']); - // generate links for group members - if ($attrName == "memberuid") { - // sort array - sort($info[$i][$attrName]); - // make a link for each member of the group - $linklist = array(); - for ($d = 0; $d < sizeof($info[$i][$attrName]); $d++) { - $user = $info[$i][$attrName][$d]; // user name - $linklist[$d] = "" . $user . ""; - } - echo implode("; ", $linklist); - } - // print all other attributes - else { - if (is_array($info[$i][$attrName])) { - // sort array - sort($info[$i][$attrName]); - echo implode("; ", $info[$i][$attrName]); - } - else echo $info[$i][$attrName]; - } - } - echo ("\n"); - } - echo("\n"); + echo implode("; ", $linklist); + } + // print all other attributes + else { + parent::listPrintTableCellContent($entry, $attribute); } - // display select all link - $colspan = sizeof($this->attrArray) + 1; - echo "type . "list\">\n"; - echo "\"select\n"; - echo " type . "&norefresh=y&page=" . $this->page . - "&sort=" . $this->sortColumn . $this->filterText . "&selectall=yes\">" . - "" . _("Select all") . "\n"; - echo "\n"; - echo (""); } - + } diff --git a/lam/lib/types/host.inc b/lam/lib/types/host.inc index e0fcec54..05c0eca7 100644 --- a/lam/lib/types/host.inc +++ b/lam/lib/types/host.inc @@ -112,7 +112,7 @@ class lamHostList extends lamList { 'nav' => _("%s host(s) found"), 'error_noneFound' => _("No hosts found!"), 'newEntry' => _("New host"), - 'deleteEntry' => _("Delete host"), + 'deleteEntry' => _("Delete host(s)"), 'createPDF' => _("Create PDF for selected host(s)"), 'createPDFAll' => _("Create PDF for all hosts")); } diff --git a/lam/lib/types/mailAlias.inc b/lam/lib/types/mailAlias.inc index 80bfd99b..46915769 100644 --- a/lam/lib/types/mailAlias.inc +++ b/lam/lib/types/mailAlias.inc @@ -108,7 +108,7 @@ class lamMailAliasList extends lamList { 'nav' => _("%s alias(es) found"), 'error_noneFound' => _("No aliases found!"), 'newEntry' => _("New alias"), - 'deleteEntry' => _("Delete alias"), + 'deleteEntry' => _("Delete alias(es)"), 'createPDF' => _("Create PDF for selected alias(es)"), 'createPDFAll' => _("Create PDF for all aliases")); } diff --git a/lam/lib/types/smbDomain.inc b/lam/lib/types/smbDomain.inc index dc1d4792..dbc8b3ff 100644 --- a/lam/lib/types/smbDomain.inc +++ b/lam/lib/types/smbDomain.inc @@ -108,7 +108,7 @@ class lamSmbDomainList extends lamList { 'nav' => _("%s domain(s) found"), 'error_noneFound' => _("No domains found!"), 'newEntry' => _("New domain"), - 'deleteEntry' => _("Delete domain"), + 'deleteEntry' => _("Delete domain(s)"), 'createPDF' => _("Create PDF for selected domain(s)"), 'createPDFAll' => _("Create PDF for all domains")); } diff --git a/lam/lib/types/user.inc b/lam/lib/types/user.inc index d3ddeba9..467c33d1 100644 --- a/lam/lib/types/user.inc +++ b/lam/lib/types/user.inc @@ -89,7 +89,8 @@ class user extends baseType { "homedirectory" => _("Home directory"), "loginshell" => _("Login shell"), "mail" => _("E-Mail"), - "gecos" => _("Description") + "gecos" => _("Description"), + "jpegphoto" => _('Photo') ); } @@ -122,7 +123,7 @@ class lamUserList extends lamList { 'nav' => _("%s user(s) found"), 'error_noneFound' => _("No users found!"), 'newEntry' => _("New user"), - 'deleteEntry' => _("Delete user"), + 'deleteEntry' => _("Delete user(s)"), 'createPDF' => _("Create PDF for selected user(s)"), 'createPDFAll' => _("Create PDF for all users")); } @@ -154,72 +155,50 @@ class lamUserList extends lamList { } /** - * 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); - // translate GIDs and resort array if selected - if ($this->trans_primary == "on") { - // translate GIDs - for ($i = 0; $i < sizeof($info); $i++) { - if (isset($this->trans_primary_hash[$info[$i]['gidnumber'][0]])) { - $info[$i]['gidnumber'][0] = $this->trans_primary_hash[$info[$i]['gidnumber'][0]]; - } - } - // resort if needed - if ($this->sortColumn == "gidnumber") { - $info = $this->listSort($info); - } - } - // 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 " type . "')\"" . - " type=\"checkbox\" checked name=\"" . $info[$i]['LAM_ID'] . "\">\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 + */ + function listPrintTableCellContent(&$entry, &$attribute) { + // check if there is something to display at all + if (!is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return; + if (isset($entry[$attribute]['count'])) unset($entry[$attribute]['count']); + // 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]]; } else { - echo " type . "')\"" . - " type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\">\n"; + parent::listPrintTableCellContent($entry, $attribute); } - echo (" type . "&DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "\n"); - for ($k = 0; $k < sizeof($this->attrArray); $k++) { - echo (""); - // 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 ("\n"); - } - echo("\n"); } - // display select all link - $colspan = sizeof($this->attrArray) + 1; - echo "type . "list\">\n"; - echo "\"select\n"; - echo " type . "&norefresh=y&page=" . $this->page . - "&sort=" . $this->sortColumn . $this->filterText . "&selectall=yes\">" . - "" . _("Select all") . "\n"; - echo "\n"; - echo (""); + // show user photos + elseif ($attribute == "jpegphoto") { + if (sizeof($entry[$attribute][0]) < 100) { + // looks like we have read broken binary data, reread photo + $result = @ldap_search($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*"); + if ($result) { + $tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result); + $binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute); + if (isset($binData['count'])) unset($binData['count']); + $entry[$attribute] = $binData; + echo "servus"; + } + } + $jpeg_filename = 'jpg' . $_SESSION['ldap']->new_rand() . '.jpg'; + $outjpeg = @fopen($_SESSION['lampath'] . 'tmp/' . $jpeg_filename, "wb"); + fwrite($outjpeg, $entry[$attribute][0]); + fclose ($outjpeg); + $photoFile = '../../tmp/' . $jpeg_filename; + echo "\"""; + } + // print all other attributes + else { + parent::listPrintTableCellContent($entry, $attribute); + } } - + /** * Prints additional option fields for specific object types. */