Here is a patch that adds pagination to accounts. It affects src/users.php and 
templates/show_users.tpl

It was made using vegadns-1.1.3, and is based on the code from domains.php

I hope it works for you

-- 
-----------------
Bob Hutchinson
Midwales dot com
-----------------
--- show_users.tpl.old	2004-10-09 21:41:20.000000000 +0100
+++ templates/show_users.tpl	2005-03-17 12:55:13.000000000 +0000
@@ -1,13 +1,49 @@
-<table border=0 width="70%" bgcolor="white">
-<tr><td>
+<table width="70%" border=0 cellspacing=5 cellpadding=3 bgcolor="white">
+<tr bgcolor="#cccccc">
+    <td colspan="7" align="center">
 <table border=0 width="100%">
 <tr bgcolor="#cccccc">
     <td align="middle">All User Accounts
         {if $user_account_type == 'group_admin'} In Your Group{/if}
-</td></tr>
+            </td>
+        </tr>
 </table>
-
-<table border=0 width="100%">
+    </td>
+</tr>
+<tr bgcolor="#cccccc">
+    <td colspan="7" align="center">
+        <table width="100%" border=0 bgcolor="#cccccc">
+        <tr bgcolor="#cccccc">
+            <td align="left" valign="top" colspan="2">
+                Listing {$first_account} - {$last_account} of {$totalaccounts} Accounts {$searchtexttag}</td>
+                <td align="center" colspan="2">
+                {if $previous_url != ""} <a href={$previous_url}>previous</a>
+                {else}previous{/if}
+                {if $next_url != ""} <a href={$next_url}>next</a>
+                {else}next{/if}
+                {if $first_url != ""} <a href={$first_url}>first</a>
+                {else}first{/if}
+                {if $last_url != ""} <a href={$last_url}>last</a>
+                {else}last{/if}
+                <a href={$all_url}>all</a>
+            </td>
+            <td align="right" colspan="2">
+                <form action="{$php_self}">
+                <input type="hidden" name="state" value="{$state}">
+                <input type="hidden" name="mode" value="users">
+                <input type="hidden" name="{$session_name}" value="{$session_id}">
+                <input type="text" name="search" value="{$search}">
+                <input type="submit" value="search"></form>
+            </td>
+        </tr>
+        <tr bgcolor="#cccccc">
+            <td align="center" colspan="6" width=100%>
+                <a href="{$all_url}">ALL</a> | <a href="{$all_url}&scope=num">0-9</a> | <a href="{$all_url}&scope=a">A</a> | <a href="{$all_url}&scope=b">B</a> | <a href="{$all_url}&scope=c">C</a> | <a href="{$all_url}&scope=d">D</a> | <a href="{$all_url}&scope=e">E</a> | <a href="{$all_url}&scope=f">F</a> | <a href="{$all_url}&scope=g">G</a> | <a href="{$all_url}&scope=h">H</a> | <a href="{$all_url}&scope=i">I</a> | <a href="{$all_url}&scope=j">J</a> | <a href="{$all_url}&scope=k">K</a> | <a href="{$all_url}&scope=l">L</a> | <a href="{$all_url}&scope=m">M</a> | <a href="{$all_url}&scope=n">N</a> | <a href="{$all_url}&scope=o">O</a> | <a href="{$all_url}&scope=p">P</a> | <a href="{$all_url}&scope=q">Q</a> | <a href="{$all_url}&scope=r">R</a> | <a href="{$all_url}&scope=s">S</a> | <a href="{$all_url}&scope=t">T</a> | <a href="{$all_url}&scope=u">U</a> | <a href="{$all_url}&scope=v">V</a> | <a href="{$all_url}&scope=w">W</a> | <a href="{$all_url}&scope=x">X</a> | <a href="{$all_url}&scope=y">Y</a> | <a href="{$all_url}&scope=z">Z</a>
+            </td>
+        </tr>
+        </table>
+    </td>
+</tr>
 <tr bgcolor="#cccccc">
   <td nowrap>{$Name}</td>
   <td nowrap>{$Email}</td>
@@ -31,10 +67,9 @@
     <img border=0 src="images/trash.png">
     {else}
     <a href="{$row.delete_url}"><img border=0 src="images/trash.png" alt="Trash"></a>
-    {/if}{/strip}</td>
+        {/if}{/strip}
+    </td>
 </tr>
 {/foreach}
 
 </table>
-</td></tr>
-</table>
--- users.php.old	2005-02-09 20:23:50.000000000 +0000
+++ src/users.php	2005-03-17 15:03:32.000000000 +0000
@@ -201,11 +201,53 @@
     } else {
 
         if($user_info['Account_Type'] == 'group_admin') {
-            $q = "select * from accounts where gid='".$user_info['cid']."'";
+            $q = "select * from accounts where gid='".$user_info['cid']."' ";
         } else if($user_info['Account_Type'] == 'senior_admin') {
-            $q = "select * from accounts";
+            $q = "select * from accounts ";
+        }
+        // Get search string if it exists
+        if(isset($_REQUEST['search']) && $_REQUEST['search'] != "") {
+            $tempstring = ereg_replace("[*]", "%", $_REQUEST['search']);
+            $tempstring = ereg_replace("[ ]", "%", $tempstring);
+            $searchstring = " Last_Name like ".$db->Quote('%'.$tempstring.'%')."";
+            // Set appropriate query
+            if($user_info['Account_Type'] == 'senior_admin') {
+                $searchstring = 'where '.$searchstring;
+            } else {
+                $searchstring = $searchstring.' and ';
+            }
+            $smarty->assign('search', $_REQUEST['search']);
+            $smarty->assign('searchtexttag', " matching \"".$_REQUEST['search']."\"");
+            $search = $_REQUEST['search'];
+        } else {
+            $searchstring = "";
+            $search = "";
+        }
+
+        $q .= $searchstring;
+        // Get scope of accounts list, if it exists
+        if(isset($_REQUEST['scope']) && $_REQUEST['scope'] != "") {
+            $searchstring = "";
+            $search = "";
+            $scope = $_REQUEST['scope'];
+            $smarty->assign('scope', $_REQUEST['scope']);
+
+            if($user_info['Account_Type'] == 'senior_admin') {
+                $aux = "where";
+            } else {
+                $aux = "and";
+            }
+
+            if($scope != "num") {
+                $sq = "$aux  Last_Name regexp \"^[$scope" . strtoupper($scope) . "]\"";
+            } else {
+                $sq = "$aux  Last_Name regexp \"^[0-9]\"";
+            }
+        } else {
+            $sq = "";
         }
 
+        $q .= $sq;
     	// sort
     	if (!isset($_REQUEST['sortway'])) {
         	$sortway = 'asc';
@@ -225,10 +267,48 @@
 
 		$q .= " order by $sortfield  $sortway" . (($sortfield == 'Account_Type') ? ", Last_Name" :"" ) . "";
         $result = $db->Execute($q) or die($db->ErrorMsg());
-
+        $totalaccounts = $result->RecordCount();
 
         $smarty->assign('user_account_type', $user_info['Account_Type']);
 
+        // Pagination
+        if(isset($_REQUEST['page'])) {
+            if($_REQUEST['page'] == 'all') {
+                $page = 1;
+                $first_account = 1;
+                $last_account = $totalaccounts;
+                $totalpages = 1;
+            } else {
+                $page = $_REQUEST['page'];
+                $first_account = ($page * $per_page) - $per_page + 1;
+                if($first_account == 0) $first_account++;
+                $last_account = ($first_account + $per_page - 1);
+                $totalpages = ceil(number_format($totalaccounts / $per_page, 10));
+            }
+        } else {
+            $page = 1;
+            if($totalaccounts == 0) {
+                $first_account = 0;
+            } else {
+                $first_account = 1;
+            }
+            $last_account = ($first_account + $per_page - 1);
+            $totalpages = ceil(number_format($totalaccounts / $per_page, 10));
+        }
+        if($last_account > $totalaccounts) $last_account = $totalaccounts;
+        if($page > 1) {
+            $smarty->assign('previous_url', "$base_url&mode=users&user_mode=show_users&page=".($page - 1)."&sortfield=$sortfield&sortway=$sortway&search=".urlencode($search));
+        }
+        if($page < $totalpages) {
+            $smarty->assign('next_url', "$base_url&mode=users&user_mode=show_users&page=".($page + 1)."&sortfield=$sortfield&sortway=$sortway&search=".urlencode($search));
+        }
+        if($page > 1 || (isset($_REQUEST['page']) && $_REQUEST['page'] == 'all')) {
+            $smarty->assign('first_url', "$base_url&mode=users&user_mode=show_users&page=1&sortfield=$sortfield&sortway=$sortway&search=".urlencode($search));
+        }
+        if($page < $totalpages) {
+            $smarty->assign('last_url', "$base_url&mode=users&user_mode=show_users&page=$totalpages&sortfield=$sortfield&sortway=$sortway&search=".urlencode($search));
+        }
+
         // sort
         $sort_array['Name'] = 'Last_Name';
         $sort_array['Email'] = 'Email';
@@ -245,21 +325,34 @@
             $smarty->assign($key, $url);
         }
 
-        $counter = 0;
-        while($row = $result->FetchRow()) {
-            $out_array[$counter]['name'] = $row['First_Name'].' '.$row['Last_Name'];
-            $out_array[$counter]['email'] = $row['Email'];
-            $out_array[$counter]['account_type'] = $row['Account_Type'];
-            $out_array[$counter]['group_owner_name'] = get_groupowner_name($row['gid']);
-            $out_array[$counter]['status'] = $row['Status'];
-            $out_array[$counter]['edit_url'] = "$base_url&mode=users&user_mode=edit_account&cid=".$row['cid'];
-            if($row['cid'] != $user_info['cid']) 
-                $out_array[$counter]['delete_url'] = "$base_url&mode=users&user_mode=delete&cid=".$row['cid'];
-            $counter++;
-        }
-
-
+        
+		$out_array = array();
+		if($totalaccounts > 0) {
+            $account_count = 0;
+            // Actually list accounts
+            while(++$account_count && !$result->EOF && ($row = $result->FetchRow())
+                && ($account_count <= $last_account)) {
+
+                if($account_count < $first_account) continue;
+
+                $out_array[$account_count]['name'] = $row['First_Name'].' '.$row['Last_Name'];
+                $out_array[$account_count]['email'] = $row['Email'];
+                $out_array[$account_count]['account_type'] = $row['Account_Type'];
+                $out_array[$account_count]['group_owner_name'] = get_groupowner_name($row['gid']);
+                $out_array[$account_count]['status'] = $row['Status'];
+                $out_array[$account_count]['edit_url'] = "$base_url&mode=users&user_mode=edit_account&cid=".$row['cid'];
+                if($row['cid'] != $user_info['cid']) 
+                    $out_array[$account_count]['delete_url'] = "$base_url&mode=users&user_mode=delete&cid=".$row['cid'];
+            }
+		}
+
+        $smarty->assign('all_url', "$base_url&mode=users&user_mode=show_users&page=all&sortfield=$sortfield&sortway=$sortway&search=".urlencode($search));
+        $smarty->assign('first_account', $first_account);
+        $smarty->assign('last_account', $last_account);
+        $smarty->assign('totalaccounts', $totalaccounts);
+        $smarty->assign('totalpages', $totalpages);
         $smarty->assign('out_array', $out_array);
+
         $smarty->display('header.tpl');
         $smarty->display('show_users.tpl');
         $smarty->display('footer.tpl');

Reply via email to