3
require_once("../inc/db.inc");
4
require_once("../inc/util.inc");
6
function format_float($x) {
10
return sprintf("%0.5f", $x);
12
return sprintf("%0.4f", $x);
14
return sprintf("%0.3f", $x);
16
return sprintf("%0.2f", $x);
18
return sprintf("%0.1f", $x);
20
return sprintf("%0.0f", $x);
22
return number_format($x);
27
function show_user($user, $which) {
28
$rac=format_float($user->expavg_credit);
29
$tot=format_float($user->total_credit);
32
<td align=\"center\">$which</td>
33
<td align=\"center\">".user_links($user)."</td>
34
<td align=\"center\">".date_str($user->create_time)."</td>
35
<td align=\"center\">".$user->country."</td>
36
<td align=\"center\">$tot</td>
37
<td align=\"center\">$rac</td>
41
function print_table_header($urls, $nextd) {
43
"<table align=\"center\" cellpadding=\"2\" border=\"1\" width=\"100%\">
45
<th align=\"center\">Position</th>
46
<th align=\"center\"><a href=user_search_action.php?search_string=$urls&offset=0&descending=$nextd&order=name>User name</a></th>
47
<th align=\"center\"><a href=user_search_action.php?search_string=$urls&offset=0&descending=$nextd&order=create_time>Joined project</a></th>
48
<th align=\"center\"><a href=user_search_action.php?search_string=$urls&offset=0&descending=$nextd&order=country>Country</a></th>
49
<th align=\"center\"><a href=user_search_action.php?search_string=$urls&offset=0&descending=$nextd&order=total_credit>Total credit</a></th>
50
<th align=\"center\"><a href=user_search_action.php?search_string=$urls&offset=0&descending=$nextd&order=expavg_credit>Recent credit</a></th>
54
/* if needed to help prevent database stress, sleep! */
60
$allowed_order = array('id', 'name', 'create_time','country', 'total_credit', 'expavg_credit');
61
$nice_names = array('', 'sorted by name', 'sorted by date joined', 'sorted by country', 'sorted by total credit', 'sorted by recent average credit');
63
if (!isset ($_GET['order']) || !in_array ($_GET['order'], $allowed_order)) {
64
$order = $default_sort;
67
$order = $_GET['order'];
68
$nice_name = $nice_names[array_search($order, $allowed_order)];
71
$search_string = get_str('search_string');
73
if (isset($_GET['offset'])) $offset = $_GET['offset'];
74
if (!is_numeric($offset) || $offset<0) $offset=0;
76
if (isset($_GET['descending']) && $_GET['descending']==1) {
88
page_head("Search results");
90
if (strlen($search_string)>=3) {
91
$urls = urlencode($search_string);
92
$s = escape_pattern($search_string);
93
$q = "select * from user where name like '$s%' order by $order $upordown limit $offset,$count";
94
$result = mysql_query($q);
97
while ($user = mysql_fetch_object($result)) {
99
echo "<h2>User names starting with '$search_string' $nice_name</h2>\n";
100
print_table_header($urls, $nextd);
102
show_user($user, $n+$offset+1);
106
mysql_free_result($result);
108
echo "<h2>No user names found starting with '$search_string'</h2>\n";
114
if ($offset>=$count) {
115
$prev= $offset-$count;
116
echo "<a href=user_search_action.php?search_string=$urls&offset=$prev&descending=$descending&order=$order>Previous $count</a> \n";
119
$next= $offset+$count;
120
echo "<a href=user_search_action.php?search_string=$urls&offset=$next&descending=$descending&order=$order>Next $count</a>\n";
125
echo "<h2>Search string must be at least three characters long!</h2>\n";
127
echo "<br><h3><a href=profile_menu.php>Return to profile zone</a></h3><br>\n";