[dev] Horde Users administration :: Search and Users per page
Joel Vandal
jvandal at infoteck.qc.ca
Mon Apr 5 05:25:29 PDT 2004
Hi,
> > This patch add search capability and users per page to the Horde
> > users administration page.
>
> Do you want to create a new patch for this, now that we have the pager in
> the framework?
Here is the new version of the patch.
--
Joel Vandal Infoteck Internet
http://www.infoteck.qc.ca Tel. 819-370-3232
jvandal at infoteck.qc.ca Fax. 819-370-3624
-------------- next part --------------
===================================================================
RCS file: /repository/horde/admin/user.php,v
retrieving revision 1.42
diff -u -r1.42 user.php
--- admin/user.php 26 Feb 2004 13:02:04 -0000 1.42
+++ admin/user.php 5 Apr 2004 12:19:47 -0000
@@ -12,6 +12,7 @@
require_once HORDE_BASE . '/lib/base.php';
require_once HORDE_LIBS . 'Horde/Menu.php';
require_once HORDE_LIBS . 'Horde/Form.php';
+require_once HORDE_LIBS . 'Horde/Variables.php';
require_once HORDE_LIBS . 'Horde/Form/Renderer.php';
require_once HORDE_LIBS . 'Horde/Variables.php';
@@ -203,13 +204,41 @@
}
if ($auth->hasCapability('list')) {
+
+ /* If we aren't supplied with a page number, default to page 0. */
+ $page = Util::getFormData('page', 0);
+ $search_pattern = Util::getFormData('search_pattern', '');
+
$users = $auth->listUsers();
if (is_a($users, 'PEAR_Error')) {
Horde::fatal($users, __FILE__, __LINE__);
}
+
+ /* Returns only users that match the specified pattern. */
+ require_once HORDE_LIBS . 'Horde/Array.php';
+ $users = Horde_Array::grep($users, $search_pattern, true);
+
+ require_once HORDE_LIBS . 'Horde/UI/Pager.php';
+ $viewurl = Util::addParameter('admin/user.php', 'search_pattern', $search_pattern);
+
+ $numitem = count($users);
+ $perpage = 20;
+
+ $min = $page * $perpage;
+ while ($min > $numitem) {
+ $page--;
+ $min = $page * $perpage;
+ }
+ $max = $min + $perpage;
+
+ $start = ($page * $perpage) + 1;
+ $end = min($numitem, $start + $perpage - 1);
+
require HORDE_TEMPLATES . '/admin/user/list.inc';
} else {
require HORDE_TEMPLATES . '/admin/user/nolist.inc';
}
require HORDE_TEMPLATES . '/common-footer.inc';
+
+
Index: templates/admin/user/list.inc
===================================================================
RCS file: /repository/horde/templates/admin/user/list.inc,v
retrieving revision 1.8
diff -u -r1.8 list.inc
--- templates/admin/user/list.inc 30 May 2003 13:29:54 -0000 1.8
+++ templates/admin/user/list.inc 5 Apr 2004 12:19:49 -0000
@@ -2,10 +2,44 @@
<tr>
<td align="left" class="header">
<b><?php echo _("Users in the system:") ?></b>
+<?php
+if ($numitem) {
+ echo '<span class="smallheader">[' . sprintf(_("%s to %s of %s"), $start, $end, $numitem) . ']</span>';
+}
+?>
</td>
</tr>
+<tr>
+ <td>
+<form method="post" name="search" action="<?php echo Horde::selfURL() ?>">
+<?php Util::pformInput() ?>
+<input type="hidden" name="page" value="0">
+<table border="0" cellpadding="2" cellspacing="0" width="100%">
+<tr>
+ <td class="item" align="right" valign="top" nowrap="nowrap">
+ <b><?php echo _("Search") ?>:</b>
+ </td>
+ <td class="item" width="100%">
+ <input name="search_pattern" type="text" value="" size="50" maxlength="100" /> <input type="submit" class="button" value="<?php echo _("Search") ?>" />
+ </td>
+</tr>
+</table>
+
+<br />
+</td></tr>
+</form>
<tr><td class="control"><table border="0" width="100%" cellpadding="1" cellspacing="0">
-<?php $_i = 0; $remove = $auth->hasCapability('remove'); foreach ($users as $user): ?>
+<?php $_i = 0; $remove = $auth->hasCapability('remove');
+
+$total = 0;
+
+foreach ($users as $user): ?>
+
+<?php
+if ($total++ < $min || $total > $max) {
+ continue;
+}
+?>
<tr class="item<?php echo $_i++%2 ?>">
<?php if ($remove): ?>
<td width="1%"><?php echo Horde::link(Horde::applicationUrl('admin/user.php?form=remove_f&user_name=' . $user), _("Delete")) . Horde::img('delete.gif', _("Delete")) ?></a></td>
@@ -14,5 +48,10 @@
<td align="left"><?php echo $user ?></td>
</tr>
<?php endforeach; ?>
+<?php if ($numitem) {
+ $pager = &new Horde_UI_Pager('page', $vars, array('num' => $total, 'url' => $viewurl, 'page_count' => 10, 'perpage' => $perpage));
+ echo $pager->render($page, $total, $viewurl);
+} ?>
+
</table></td></tr>
</table>
More information about the dev
mailing list