cvs: php-master-web /include functions.inc /manage users.php

From: Date: Thu, 18 Oct 2001 21:19:55 +0000
Subject: cvs: php-master-web /include functions.inc /manage users.php
Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-7080@lists.php.net to get a copy of this message
jimw Thu Oct 18 17:19:55 2001 EDT Modified files: /php-master-web/include functions.inc /php-master-web/manage users.php Log: add search capabilities and a direct link to the account of the logged-in user Index: php-master-web/include/functions.inc diff -u php-master-web/include/functions.inc:1.1 php-master-web/include/functions.inc:1.2 --- php-master-web/include/functions.inc:1.1 Wed Oct 17 20:59:41 2001 +++ php-master-web/include/functions.inc Thu Oct 18 17:19:54 2001 @@ -29,16 +29,25 @@ echo "</body></html>"; } -#TODO: generalize passing in extra parameters (take an array?) -function show_prev_next($begin,$rows,$skip,$total) { - global $order, $PHP_SELF;?> +function array_to_url($array,$overlay=0) { + if ($overlay) $array = array_merge($array,$overlay); + $out = ""; + while (list($k,$v) = each($array)) { + $out .= "&amp;" . rawurlencode($k) . "=" . rawurlencode($v); + } + return substr($out,5); # skip first &amp; +} + +function show_prev_next($begin,$rows,$skip,$total,$extra=array()) { + global $PHP_SELF;?> <table border="0" cellspacing="1" width="100%"> <tr bgcolor="#eeeeee"> <td align="left" width="33%"> <?php if ($begin > 0) { - printf("<a href=\"%s\">&laquo; Previous %d", - "$PHP_SELF?order=$order&amp;begin=".max(0,$begin-$skip), + printf("<a href=\"%s?%s\">&laquo; Previous %d", + $PHP_SELF, + array_to_url($extra, array("begin" => max(0,$begin-$skip))), min($skip,$begin)); } ?> @@ -51,8 +60,9 @@ &nbsp; <?php if ($begin+$rows < $total) { - printf("<a href=\"%s\">Next %d &raquo;", - "$PHP_SELF?order=$order&amp;begin=".($begin+$skip), + printf("<a href=\"%s?%s\">Next %d &raquo;", + $PHP_SELF, + array_to_url($extra, array("begin" => $begin+$skip)), min($skip,$total-($begin+$skip))); } ?> Index: php-master-web/manage/users.php diff -u php-master-web/manage/users.php:1.8 php-master-web/manage/users.php:1.9 --- php-master-web/manage/users.php:1.8 Wed Oct 17 22:33:02 2001 +++ php-master-web/manage/users.php Thu Oct 18 17:19:54 2001 @@ -66,14 +66,16 @@ . ($in[passwd] ? ",passwd='$in[passwd]'" : ""); query($query); - $newid = mysql_insert_id(); + $nid = mysql_insert_id(); # TODO: handle failure better - $query = "INSERT users_cvs" - . " SET userid=$newid,cvsuser='$in[cvsuser]',approved=$approved"; - query($query); + if ($in[cvsuser]) { + $query = "INSERT users_cvs" + . " SET userid=$nid,cvsuser='$in[cvsuser]',approved=$approved"; + query($query); + } - warn("record $newid added"); + warn("record $nid added"); } } } @@ -130,30 +132,54 @@ foot(); exit; } +?> +<table width="100%"> + <tr> + <td><a href="<?php echo "$PHP_SELF?username=$user";?>">edit your entry</a></td> + <td align="right"> + <form method="GET" action="<?php echo $PHP_SELF;?>"> + <input type="text" name="search" value="<?php echo clean($search);?>" /> + <input type="submit" value="search"> + </form> + </tr> +</table> +<?php $begin = $begin ? (int)$begin : 0; -$max = $max ? (int)$max : 30; +$max = $max ? (int)$max : ($search ? 15 : 30); $limit = "LIMIT $begin,$max"; $orderby = $order ? "ORDER BY $order" : ""; -$query = "SELECT COUNT(*) FROM users"; +$searchby = $search ? "WHERE MATCH(name,email) AGAINST ('$search') OR MATCH(note) AGAINST ('$search') OR users_cvs.cvsuser = '$search'" : ""; + +$query = "SELECT DISTINCT COUNT(users.userid) FROM users"; +if ($searchby) + $query .= " LEFT JOIN users_cvs USING (userid) LEFT JOIN users_note USING(userid) $searchby"; $res = mysql_query($query) or die("query '$query' failed: ".mysql_error()); $total = mysql_result($res,0); -$query = "SELECT users.userid,approved,cvsuser,name,email FROM users LEFT JOIN users_cvs USING (userid) $orderby $limit"; +$query = "SELECT DISTINCT users.userid,approved,cvsuser,name,email,note FROM users LEFT JOIN users_cvs USING (userid) LEFT JOIN users_note USING (userid) $searchby $orderby $limit"; + +#echo "<pre>$query</pre>"; $res = mysql_query($query) or die("query '$query' failed: ".mysql_error()); -show_prev_next($begin,mysql_num_rows($res),$max,$total); +$extra = array( + "search" => stripslashes($search), + "order" => $order, + "begin" => $begin, +); + +show_prev_next($begin,mysql_num_rows($res),$max,$total,$extra); ?> <table border="0" cellspacing="1" width="100%"> <tr bgcolor="#aaaaaa"> <td></td> - <th><a href="<?php echo "$PHP_SELF?begin=$begin&order=name";?>">name</a></th> - <th><a href="<?php echo "$PHP_SELF?begin=$begin&order=email";?>">email</a></th> - <th><a href="<?php echo "$PHP_SELF?begin=$begin&order=cvsuser";?>">username</a></th> + <th><a href="<?php echo "$PHP_SELF?",array_to_url($extra,array("order"=>"name"));?>">name</a></th> + <th><a href="<?php echo "$PHP_SELF?",array_to_url($extra,array("order"=>"email"));?>">email</a></th> + <th><a href="<?php echo "$PHP_SELF?",array_to_url($extra,array("order"=>"cvsuser"));?>">username</a></th> </tr> <?php $color = '#dddddd'; @@ -166,11 +192,17 @@ <td<?php if ($row[cvsuser] && !$row[approved]) echo ' bgcolor="#ff',substr($color,2),'"';?>><?php echo htmlspecialchars($row[cvsuser]);?></td> </tr> <?php + if ($search && $row[note]) {?> +<tr bgcolor="<?php echo $color;?>"> + <td></td><td colspan="3"><?php echo htmlspecialchars($row[note]);?></td> +</tr> +<?php + } $color = substr($color,2,2) == 'dd' ? '#eeeeee' : '#dddddd'; } ?> </table> -<?php show_prev_next($begin,mysql_num_rows($res),$max,$total); ?> +<?php show_prev_next($begin,mysql_num_rows($res),$max,$total,$extra); ?> <p><a href="<?php echo $PHP_SELF;?>?id=0">add a new user</a></p> <?php foot();

« previous php.mirrors (#7080) next »