added listPrintTableCellContent()

This commit is contained in:
Roland Gruber 2007-02-17 16:26:08 +00:00
parent 5fd4f7b73c
commit f6be307eef
8 changed files with 127 additions and 155 deletions

View File

@ -4,6 +4,10 @@
-> ShadowAccount: PDF entry for expire date was wrong (1658868) -> ShadowAccount: PDF entry for expire date was wrong (1658868)
-> Debian package did not include lamdaemonOld.pl (1660493) -> Debian package did not include lamdaemonOld.pl (1660493)
Developers:
API changes:
- added listPrintTableCellContent() to class lamList
24.01.2007 1.2.0 24.01.2007 1.2.0
- Samba 3: better handling of date values - Samba 3: better handling of date values

View File

@ -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: 1.1.x -> 1.2.0:
=============== ===============

View File

@ -204,27 +204,28 @@ class lamList {
* @return array filtered list of accounts * @return array filtered list of accounts
*/ */
function listFilterAccounts() { function listFilterAccounts() {
$entries = $this->entries; $entries = array();
$filter = $this->listBuildFilter(); $filter = $this->listBuildFilter();
$attributes = array_keys($filter); $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++) { for ($a = 0; $a < sizeof($attributes); $a++) {
// check if filter fits // check if filter fits
$found = false; $found = false;
for ($i = 0; $i < sizeof($entries[$r][$attributes[$a]]); $i++) { for ($i = 0; $i < sizeof($this->entries[$r][$attributes[$a]]); $i++) {
if (eregi($filter[$attributes[$a]]['regex'], $entries[$r][$attributes[$a]][$i])) { if (eregi($filter[$attributes[$a]]['regex'], $this->entries[$r][$attributes[$a]][$i])) {
$found = true; $found = true;
break; break;
} }
} }
if (!$found) { if (!$found) {
// remove account and reindex array $skip = true;
unset($entries[$r]);
$entries = array_values($entries);
$r--;
break; break;
} }
} }
if (!$skip) {
$entries[] = &$this->entries[$r];
}
} }
if (sizeof($entries) == 0) StatusMessage("WARN", $this->labels['error_noneFound']); if (sizeof($entries) == 0) StatusMessage("WARN", $this->labels['error_noneFound']);
return $entries; return $entries;
@ -237,7 +238,7 @@ class lamList {
* @param array $info the account list * @param array $info the account list
* @return array sorted account list * @return array sorted account list
*/ */
function listSort($info) { function listSort(&$info) {
if (!is_array($this->attrArray)) return $info; if (!is_array($this->attrArray)) return $info;
if (!is_string($this->sortColumn)) return $info; if (!is_string($this->sortColumn)) return $info;
// sort and return account list // sort and return account list
@ -256,7 +257,7 @@ class lamList {
* @param array $b second 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 * @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 specifies the sort column
$sort = $this->sortColumn; $sort = $this->sortColumn;
$attr_array = $this->attrArray; $attr_array = $this->attrArray;
@ -363,7 +364,7 @@ class lamList {
* *
* @param array $info entries * @param array $info entries
*/ */
function listPrintTableBody($info) { function listPrintTableBody(&$info) {
// calculate which rows to show // calculate which rows to show
$table_begin = ($this->page - 1) * $this->maxPageEntries; $table_begin = ($this->page - 1) * $this->maxPageEntries;
if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info); if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info);
@ -385,18 +386,8 @@ class lamList {
echo (" <td align='center'><a href=\"../account/edit.php?type=" . $this->type . "&amp;DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "</a></td>\n"); echo (" <td align='center'><a href=\"../account/edit.php?type=" . $this->type . "&amp;DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "</a></td>\n");
for ($k = 0; $k < sizeof($this->attrArray); $k++) { for ($k = 0; $k < sizeof($this->attrArray); $k++) {
echo ("<td>"); echo ("<td>");
// print all attribute entries seperated by "; "
$attrName = strtolower($this->attrArray[$k]); $attrName = strtolower($this->attrArray[$k]);
if (isset($info[$i][$attrName]) && sizeof($info[$i][$attrName]) > 0) { $this->listPrintTableCellContent($info[$i], $attrName);
// 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 ("</td>\n"); echo ("</td>\n");
} }
echo("</tr>\n"); echo("</tr>\n");
@ -412,6 +403,26 @@ class lamList {
echo ("</table>"); echo ("</table>");
} }
/**
* 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. * 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" // delete first array entry which is "count"
unset($info['count']); unset($info['count']);
// save position in original $info // 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 // save results
$this->entries = $info; $this->entries = $info;
} }

View File

@ -110,78 +110,35 @@ class lamGroupList extends lamList {
'nav' => _("%s group(s) found"), 'nav' => _("%s group(s) found"),
'error_noneFound' => _("No groups found!"), 'error_noneFound' => _("No groups found!"),
'newEntry' => _("New group"), 'newEntry' => _("New group"),
'deleteEntry' => _("Delete group"), 'deleteEntry' => _("Delete group(s)"),
'createPDF' => _("Create PDF for selected group(s)"), 'createPDF' => _("Create PDF for selected group(s)"),
'createPDFAll' => _("Create PDF for all groups")); 'createPDFAll' => _("Create PDF for all groups"));
} }
/** /**
* Prints the entry list * Prints the content of a cell in the account list for a given LDAP entry and attribute.
* *
* @param array $info entries * @param array $entry LDAP attributes
*/ * @param string $attribute attribute name
function listPrintTableBody($info) { */
// calculate which rows to show function listPrintTableCellContent(&$entry, &$attribute) {
$table_begin = ($this->page - 1) * $this->maxPageEntries; if ($attribute == "memberuid") {
if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info); if (!is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return;
else $table_end = ($this->page * $this->maxPageEntries); if (isset($entry[$attribute]['count'])) unset($entry[$attribute]['count']);
// print account list // sort array
for ($i = $table_begin; $i < $table_end; $i++) { sort($entry[$attribute]);
echo("<tr class=\"" . $this->type . "list\" onMouseOver=\"list_over(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . // make a link for each member of the group
" onMouseOut=\"list_out(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . $linklist = array();
" onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"\n" . for ($d = 0; $d < sizeof($entry[$attribute]); $d++) {
" onDblClick=\"parent.frames[1].location.href='../account/edit.php?type=" . $this->type . "&amp;DN=" . $info[$i]['dn'] . "'\">\n"); $user = $entry[$attribute][$d]; // user name
if (isset($_GET['selectall'])) { $linklist[$d] = "<a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a>";
echo " <td height=22 align=\"center\"><input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"" .
" type=\"checkbox\" checked name=\"" . $info[$i]['LAM_ID'] . "\"></td>\n";
} }
else { echo implode("; ", $linklist);
echo " <td height=22 align=\"center\"><input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"" . }
" type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\"></td>\n"; // print all other attributes
} else {
echo (" <td align='center'><a href=\"../account/edit.php?type=" . $this->type . "&amp;DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "</a></td>\n"); parent::listPrintTableCellContent($entry, $attribute);
for ($k = 0; $k < sizeof($this->attrArray); $k++) {
echo ("<td>");
// 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] = "<a href=\"userlink.php?user='" . $user . "' \">" . $user . "</a>";
}
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 ("</td>\n");
}
echo("</tr>\n");
} }
// display select all link
$colspan = sizeof($this->attrArray) + 1;
echo "<tr class=\"" . $this->type . "list\">\n";
echo "<td align=\"center\"><img src=\"../../graphics/select.png\" alt=\"select all\"></td>\n";
echo "<td colspan=$colspan>&nbsp;<a href=\"list.php?type=" . $this->type . "&amp;norefresh=y&amp;page=" . $this->page .
"&amp;sort=" . $this->sortColumn . $this->filterText . "&amp;selectall=yes\">" .
"<font color=\"black\"><b>" . _("Select all") . "</b></font></a></td>\n";
echo "</tr>\n";
echo ("</table>");
} }
} }

View File

@ -112,7 +112,7 @@ class lamHostList extends lamList {
'nav' => _("%s host(s) found"), 'nav' => _("%s host(s) found"),
'error_noneFound' => _("No hosts found!"), 'error_noneFound' => _("No hosts found!"),
'newEntry' => _("New host"), 'newEntry' => _("New host"),
'deleteEntry' => _("Delete host"), 'deleteEntry' => _("Delete host(s)"),
'createPDF' => _("Create PDF for selected host(s)"), 'createPDF' => _("Create PDF for selected host(s)"),
'createPDFAll' => _("Create PDF for all hosts")); 'createPDFAll' => _("Create PDF for all hosts"));
} }

View File

@ -108,7 +108,7 @@ class lamMailAliasList extends lamList {
'nav' => _("%s alias(es) found"), 'nav' => _("%s alias(es) found"),
'error_noneFound' => _("No aliases found!"), 'error_noneFound' => _("No aliases found!"),
'newEntry' => _("New alias"), 'newEntry' => _("New alias"),
'deleteEntry' => _("Delete alias"), 'deleteEntry' => _("Delete alias(es)"),
'createPDF' => _("Create PDF for selected alias(es)"), 'createPDF' => _("Create PDF for selected alias(es)"),
'createPDFAll' => _("Create PDF for all aliases")); 'createPDFAll' => _("Create PDF for all aliases"));
} }

View File

@ -108,7 +108,7 @@ class lamSmbDomainList extends lamList {
'nav' => _("%s domain(s) found"), 'nav' => _("%s domain(s) found"),
'error_noneFound' => _("No domains found!"), 'error_noneFound' => _("No domains found!"),
'newEntry' => _("New domain"), 'newEntry' => _("New domain"),
'deleteEntry' => _("Delete domain"), 'deleteEntry' => _("Delete domain(s)"),
'createPDF' => _("Create PDF for selected domain(s)"), 'createPDF' => _("Create PDF for selected domain(s)"),
'createPDFAll' => _("Create PDF for all domains")); 'createPDFAll' => _("Create PDF for all domains"));
} }

View File

@ -89,7 +89,8 @@ class user extends baseType {
"homedirectory" => _("Home directory"), "homedirectory" => _("Home directory"),
"loginshell" => _("Login shell"), "loginshell" => _("Login shell"),
"mail" => _("E-Mail"), "mail" => _("E-Mail"),
"gecos" => _("Description") "gecos" => _("Description"),
"jpegphoto" => _('Photo')
); );
} }
@ -122,7 +123,7 @@ class lamUserList extends lamList {
'nav' => _("%s user(s) found"), 'nav' => _("%s user(s) found"),
'error_noneFound' => _("No users found!"), 'error_noneFound' => _("No users found!"),
'newEntry' => _("New user"), 'newEntry' => _("New user"),
'deleteEntry' => _("Delete user"), 'deleteEntry' => _("Delete user(s)"),
'createPDF' => _("Create PDF for selected user(s)"), 'createPDF' => _("Create PDF for selected user(s)"),
'createPDFAll' => _("Create PDF for all users")); 'createPDFAll' => _("Create PDF for all users"));
} }
@ -154,70 +155,48 @@ class lamUserList extends lamList {
} }
/** /**
* Prints the entry list * Prints the content of a cell in the account list for a given LDAP entry and attribute.
* *
* @param array $info entries * @param array $entry LDAP attributes
*/ * @param string $attribute attribute name
function listPrintTableBody($info) { */
// calculate which rows to show function listPrintTableCellContent(&$entry, &$attribute) {
$table_begin = ($this->page - 1) * $this->maxPageEntries; // check if there is something to display at all
if (($this->page * $this->maxPageEntries) > sizeof($info)) $table_end = sizeof($info); if (!is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1)) return;
else $table_end = ($this->page * $this->maxPageEntries); if (isset($entry[$attribute]['count'])) unset($entry[$attribute]['count']);
// translate GIDs and resort array if selected // translate GID to group name
if ($this->trans_primary == "on") { if (($attribute == "gidnumber") && ($this->trans_primary == "on")) {
// translate GIDs if (isset($this->trans_primary_hash[$entry[$attribute][0]])) {
for ($i = 0; $i < sizeof($info); $i++) { echo $this->trans_primary_hash[$entry[$attribute][0]];
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("<tr class=\"" . $this->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 . "&amp;DN=" . $info[$i]['dn'] . "'\">\n");
if (isset($_GET['selectall'])) {
echo " <td height=22 align=\"center\"><input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"" .
" type=\"checkbox\" checked name=\"" . $info[$i]['LAM_ID'] . "\"></td>\n";
} }
else { else {
echo " <td height=22 align=\"center\"><input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $this->type . "')\"" . parent::listPrintTableCellContent($entry, $attribute);
" type=\"checkbox\" name=\"" . $info[$i]['LAM_ID'] . "\"></td>\n";
} }
echo (" <td align='center'><a href=\"../account/edit.php?type=" . $this->type . "&amp;DN='" . $info[$i]['dn'] . "'\">" . _("Edit") . "</a></td>\n");
for ($k = 0; $k < sizeof($this->attrArray); $k++) {
echo ("<td>");
// 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 ("</td>\n");
}
echo("</tr>\n");
} }
// display select all link // show user photos
$colspan = sizeof($this->attrArray) + 1; elseif ($attribute == "jpegphoto") {
echo "<tr class=\"" . $this->type . "list\">\n"; if (sizeof($entry[$attribute][0]) < 100) {
echo "<td align=\"center\"><img src=\"../../graphics/select.png\" alt=\"select all\"></td>\n"; // looks like we have read broken binary data, reread photo
echo "<td colspan=$colspan>&nbsp;<a href=\"list.php?type=" . $this->type . "&amp;norefresh=y&amp;page=" . $this->page . $result = @ldap_search($_SESSION['ldap']->server(), $entry['dn'], $attribute . "=*");
"&amp;sort=" . $this->sortColumn . $this->filterText . "&amp;selectall=yes\">" . if ($result) {
"<font color=\"black\"><b>" . _("Select all") . "</b></font></a></td>\n"; $tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
echo "</tr>\n"; $binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute);
echo ("</table>"); 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 "<img src=\"" . $photoFile . "\" alt=\"" . _('Photo') . "\">";
}
// print all other attributes
else {
parent::listPrintTableCellContent($entry, $attribute);
}
} }
/** /**