root/usersearch.php

Revision 324, 20.7 kB (checked in by Nafania, 1 year ago)

Много мелких изменений. Если используется xbtt, то надо обязательно скачать новую версию на форуме.
Добавлен файл cron.php - если есть возможность, то пускайте cron таски через него. Особенно если используете массовую рассылку почты.

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3 require ($root_path . 'include/config.php');
4 require ($root_path . 'include/functions_check.php');
5 require ($root_path . 'include/functions_selects.php');
6
7 $userdata = session_pagestart($user_ip);
8 init_userprefs($userdata);
9 loggedinorreturn();</span>
10 <span class="code-lang">
11 if ($userdata['class'] < UC_MODERATOR) {
12         trigger_error($lang['access_denied']);
13 }
14
15 function generate_select ($name, $type) {
16     global $lang;
17     if ($type == 1) {
18         $opt = array($lang['in'], $lang['before'], $lang['after'], $lang['between']);
19     }
20     elseif ($type == 2) {
21         $opt = array($lang['choose'], $lang['yes'], $lang['no']);
22     }
23     elseif ($type == 3) {
24         $opt = array($lang['equal'], $lang['above'], $lang['below'], $lang['between']);
25     }
26     elseif ($type == 4) {
27         $opt = array($lang['choose'], $lang['confirmed'], $lang['not_confirmed']);
28     }
29     elseif ($type == 5) {
30         $opt = array($lang['choose'], $lang['enabled'], $lang['disabled']);
31     }
32     $s = '<select name="' . $name . '">';
33     for ($i = 0; $i < sizeof($opt); $i++){
34         $s .= '<option value="' . ( $opt[$i] == $lang['choose'] ? '--' : $i ) . '" '.((@$_GET[$name]==$i)?'selected="selected"':'').'>'.$opt[$i].'</option>';
35     }
36     $s .= '</select>';
37     return $s;
38 }
39
40 // Validates date in the form [yy]yy-mm-dd;</span>
41 <span class="code-comment">// Returns date if valid, 0 otherwise.
42 function mkdate($date) {</span>
43 <span class="code-keyword">    if (strpos($date,'-')) {
44         $a = explode('-', $date);
45     }
46     else {
47         return 0;
48     }
49     for ($i=0;$i<3;$i++) {
50         if (!is_numeric($a[$i])) {
51             return 0;
52         }
53         if (checkdate($a[1], $a[2], $a[0])) {
54             return  date ("Y-m-d", mktime (0,0,0,$a[1],$a[2],$a[0]));
55         }
56         else {
57             return 0;
58         }
59     }
60 }
61
62 // checks for the usual wildcards *, ? plus mySQL ones
63 function haswildcard($text) {</span>
64 <span class="code-keyword">    if (strpos($text,'*') === False && strpos($text,'?') === False && strpos($text,'%') === False && strpos($text,'_') === False) {
65         return False;
66     }
67     else {
68         return True;
69     }
70 }
71
72 $input_vars = array('d', 'd2', 'icq', 'dip', 'ls', 'ls2', 'skype', 'ma', 'dl', 'dl2', 'aim', 'em', 'r', 'r2', 'msn', 'ip', 'ul', 'ul2', 'yahoo', 'age', 'ac', 'passkey', 'client', 'c', 'gender', 'speed_up', 'speed_down', 'username');</span>
73 <span class="code-lang">
74 foreach ( $input_vars AS $_null => $var_name ) {
75     $$var_name = request_var($var_name, '');
76 }
77
78 //start cleints select
79 $sql = 'SELECT peer_id, useragent FROM ' . PEERS_TABLE . ' WHERE peer_id <> \'\'  GROUP BY SUBSTR(useragent, 1, 15)';
80 $result = $db->sql_query($sql, 24 * 60 * 60);
81 $agents = array();</span>
82 <span class="code-lang">while ( $row = $db->sql_fetchrow($result) ) {
83     $agent = getagent($row['useragent'], $row['peer_id']);
84     if ( !isset($agents[$agent]) ) {
85         $agents[$agent] = $row['useragent'];
86     }
87 }
88 ksort ($agents);
89 $client_select = '<select name="client" id="client"><option value="">' . $lang['choose'] . '</option>';</span>
90 <span class="code-lang">foreach ( $agents AS $agent => $useragent ) {
91         $client_select .= '<option value="' . urlencode($useragent) . '" ' . ( urldecode($client) == $agent ? 'selected="selected"' : '' ).'>'.$agent.'</option>';
92 }
93 $client_select .= '</select>';
94 //end cleints select</span>
95 <span class="code-comment">
96 //begin class select
97 $class_select = '<select name="c"><option value="0">' . $lang['choose'] . '</option>';</span>
98 <span class="code-lang">for ($i = 3;;++$i) {
99         if ($class = get_user_class_name($i-3)) {
100                 $class_select .= '<option value="' . $i . '"' . ($c && $c == $i? 'selected="selected"' : '') . '>' . $class . '</option>';
101         }
102         else {
103                 break;
104         }
105 }
106 $class_select .= '</select>';
107 //end class select</span>
108 <span class="code-comment">
109 //start gender select
110 $gender_select = '<select name="gender" id="gender"><option value="--">' . $lang['choose'] . '</option>';
111 $gender_select .= '<option value="0"' . ( $gender === 0 ? ' selected="selected"':''). '>' . $lang['gender_male'] . '</option>';
112 $gender_select .= '<option value="1"' . ( $gender === 1 ? ' selected="selected"':''). '>' . $lang['gender_female'] . '</option>';
113 $gender_select .= '</select>';
114 //end gender select
115
116 $reg_date_select = generate_select('dt', 1);
117 $last_access_select = generate_select('lst', 1);
118 $donor_select = generate_select('do', 2);
119 $warn_select = generate_select('w', 2);
120 $downloaded_select = generate_select('dlt', 3);
121 $status_select = generate_select('st', 4);
122 $ratio_select = generate_select('rt', 3);
123 $hidden_torrent_select generate_select('ht', 2);
124 $parked_selected = generate_select('parked', 2);
125 $uploaded_select = generate_select('ult', 3);
126 $enabled_select = generate_select('as', 5);
127
128 //speeds selects
129 $speed_up_select = generate_internet_speed($speed_up, 'speed_up');
130 $speed_down_select = generate_internet_speed($speed_down, 'speed_down');
131
132 $template->assign_vars(array(</span>
133 <span class="code-lang">        'S_FORM_ACTION' => append_sid('usersearch.php'),
134         'USERNAME_VALUE' => $username,
135         'CLIENT_SELECT' => $client_select,
136         'REG_DATE_SELECT' => $reg_date_select,
137         'REG_DATE_INPUT1' => $d,
138         'REG_DATE_INPUT2' => $d2,
139         'ICQ_INPUT' => $icq,
140         'DISABLED_IP_CHECKED' => ( $dip ? 'checked="checked"' : '' ),
141         'CLASS_SELECT' => $class_select,
142         'LAST_ACCESS_SELECT' => $last_access_select,
143         'LAST_ACCESS_INPUT1' => $ls,
144         'LAST_ACCESS_INPUT2' => $ls2,
145         'SKYPE_INPUT' => $skype,
146         'DONOR_SELECT' => $donor_select,
147         'MASK_INPUT' => $ma,
148         'WARN_SELECT' => $warn_select,
149         'DOWNLOADED_SELECT' => $downloaded_select,
150         'DOWNLOADED_INPUT1' => $dl,
151         'DOWNLOADED_INPUT2' => $dl2,
152         'AIM_INPUT' => $aim,
153         'STATUS_SELECT' => $status_select,
154         'EMAIL_INPUT' => $em,
155         'GENDER_SELECT' => $gender_select,
156         'RATIO_SELECT' => $ratio_select,
157         'RATIO_INPUT1' => $r,
158         'RATIO_INPUT2' => $r2,
159         'MSN_INPUT' => $msn,
160         'HIDDEN_TORRENT_SELECT' => $hidden_torrent_select,
161         'IP_INPUT' => $ip,
162         'PARKED_SELECT' => $parked_selected,
163         'UPLOADED_SELECT' => $uploaded_select,
164         'UPLOADED_INPUT1' => $ul,
165         'UPLOADED_INPUT2' => $ul2,
166         'YAHOO_INPUT' => $yahoo,
167         'AGE_INPUT' => $age,
168         'ENABLED_SELECT' => $enabled_select,
169         'ONLY_ACTIVE_CHECKED' => ( $ac ? 'checked="checked"' : '' ),
170         'SPEED_DOWN_SELECT' => $speed_down_select,
171         'SPEED_UP_SELECT' => $speed_up_select,
172         'PASSKEY_INPUT' =>  $passkey
173
174         )
175 );
176
177 ///////////////////////////////////////////////////////////////////////////////
178 $where_is = $q = array();
179 $join_is = '';</span>
180 <span class="code-lang">if ( isset($_GET['submit']) ) {
181     $q[] = "submit=1";
182     $names_exc = array();
183     $names_inc = array();
184     $names = explode(' ', $username);
185     if ($names[0] !== '') {
186         foreach($names as $name) {
187             if (substr($name,0,1) == '~') {
188                 if ($name == '~') {
189                     continue;
190                 }
191                 $names_exc[] = substr($name,1);
192             }
193             else {
194                 $names_inc[] = $name;
195             }
196         }
197         $name_is = '';
198         if (sizeof($names_inc)) {
199             foreach($names_inc as $name) {
200                 if (!haswildcard($name)) {
201                     $name_is .= ( $name_is ?" OR ":"")."u.name = ". "'" . $db->sql_escape($name) . "'";
202                 }
203                 else {
204                     $name = str_replace(array('?','*'), array('_','%'), $name);
205                     $name_is .= ( $name_is ?" OR ":"")."u.name LIKE "."'" . $db->sql_escape($name) . "'";
206                 }
207             }
208             $where_is[] = $name_is;
209             unset($name_is);
210         }
211         if (sizeof($names_exc)) {
212             $where_is .= isset($where_is)?" AND NOT (":" NOT (";
213             foreach($names_exc as $name) {
214                 if (!haswildcard($name)) {
215                     $name_is .= (isset($name_is)?" OR ":"")."u.name = "."'" . $db->sql_escape($name) . "'";
216                 }
217                 else {
218                     $name = str_replace(array('?','*'), array('_','%'), $name);
219                     $name_is .= (isset($name_is)?" OR ":"")."u.name LIKE "."'" . $db->sql_escape($name) . "'";
220                 }
221             }
222             $where_is[] = '(' . $name_is . ')';
223         }
224         $q[] = 'username=' . urlencode($username);
225     }
226
227     $em = ( isset($_GET['em']) ? trim($_GET['em']) : '' );
228     $emaila = explode(' ', $em);
229     if ($emaila[0] !== "") {
230         foreach($emaila as $email) {
231             if (strpos($email,'*') === False && strpos($email,'?') === False && strpos($email,'%') === False) {
232                 if ( !preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]+$/is', $email) ) {
233                     trigger_error($lang['email_invalid']);
234                 }
235                 $email_is .= (isset($email_is)?" OR ":"")."u.email ="."'" . $db->sql_escape($email) . "'";
236             }
237             else {
238                 $sql_email = str_replace(array('?','*'), array('_','%'), $email);
239                 $email_is .= (isset($email_is)?" OR ":"")."u.email LIKE "."'" . $db->sql_escape($sql_email) . "'";
240             }
241         }
242         $where_is[] = $email_is;
243         $q[] = 'em='.urlencode($em);
244     }
245
246
247     if ($c > 0) {
248         $where_is[] = 'u.class=' . ($c - 3);
249         $q[] = 'c='.($c);
250     }
251
252     if ($ip) {
253         $regex = '/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)/';
254         if (!preg_match($regex, $ip)) {
255             trigger_error($lang['bad_ip']);
256         }
257         $mask = trim($_GET['ma']);
258         if ($mask == '' || $mask == '255.255.255.255') {
259             $where_is[] = ( strpos($ip, '*') ? "u.ip LIKE '" . str_replace('*', '%', $ip) . "'" : 'u.ip = \'' . $ip . '\'' );
260         }
261         else {
262             if (substr($mask,0,1) == "/") {
263                 $n = substr($mask, 1, strlen($mask) - 1);
264                 if (!is_numeric($n) or $n < 0 or $n > 32) {
265                     trigger_error($lang['bad_subnet_mask']);
266                 }
267                 else {
268                     $mask = long2ip(pow(2,32) - pow(2,32-$n));
269                 }
270             }
271             elseif (!preg_match($regex, $mask)) {
272                 trigger_error($lang['bad_subnet_mask']);
273             }
274             $where_is[] = "INET_ATON(u.ip) & INET_ATON('$mask') = INET_ATON('" $ip . "') & INET_ATON('$mask')";
275             $q[] = "ma=$mask";
276         }
277         $q[] = 'ip= ' . $ip;
278     }
279
280
281
282     $ratio = ( isset($_GET['r']) ? trim($_GET['r']) : '' );
283     if ($ratio) {
284         if ($ratio == '---') {
285             $ratio2 = '';
286             $where_is[] = "u.uploaded = 0 and u.downloaded = 0";
287         }
288         elseif (strtolower(substr($ratio,0,3)) == 'inf') {
289             $ratio2 = '';
290             $where_is[] = "u.uploaded > 0 and u.downloaded = 0";
291         }
292         else {
293             if (!is_numeric($ratio) || $ratio < 0) {
294                 trigger_error($lang['bad_ratio']);
295             }
296             $ratiotype = $_GET['rt'];
297             $q[] = "rt=$ratiotype";
298             if ($ratiotype == "3") {
299                 $ratio2 = trim($_GET['r2']);
300                 if(!$ratio2) {
301                     trigger_error($lang['two_ratio_fields_must_be_filled']);
302                 }
303                 if (!is_numeric($ratio2) || $ratio2 < $ratio) {
304                     trigger_error($lang['bad_second_ratio_field']);
305                 }
306                 $where_is[] = "(u.uploaded/u.downloaded) BETWEEN $ratio and $ratio2";
307                 $q[] = "r2=$ratio2";
308             }
309             elseif ($ratiotype == "2") {
310                 $where_is[] = "(u.uploaded/u.downloaded) < $ratio";
311             }
312             elseif ($ratiotype == "1") {
313                 $where_is[] = "(u.uploaded/u.downloaded) > $ratio";
314             }
315             else {
316                 $where_is[] = "(u.uploaded/u.downloaded) BETWEEN ($ratio - 0.004) and ($ratio + 0.004)";
317             }
318         }
319         $q[] = "r=$ratio";
320     }
321
322     $ul = ( isset($_GET['ul']) ? trim($_GET['ul']) : '' );
323     if ($ul) {
324         if (!is_numeric($ul) || $ul < 0) {
325             trigger_error($lang['bad_uploaded']);
326         }
327         $ultype = intval($_GET['ult']);
328         $q[] = "ult=$ultype";
329         if ($ultype == 3) {
330             $ul2 = trim($_GET['ul2']);
331             if(!$ul2) {
332                 trigger_error($lang['two_uploaded_fields_must_be_filled']);
333             }
334
335             if (!is_numeric($ul2) || $ul2 < $ul) {
336                 trigger_error($lang['bad_second_uploaded_field']);
337             }
338             $where_is[] = "u.uploaded BETWEEN ". ($ul*1024*1024*1024) ." AND ". ($ul2*1024*1024*1024);
339             $q[] = "ul2=$ul2";
340         }
341         elseif ($ultype == 2) {
342             $where_is[] = "u.uploaded < ".$ul*1024*1024*1024;
343         }
344         elseif ($ultype == 1) {
345             $where_is[] = "u.uploaded >". $ul*1024*1024*1024;
346         }
347         else {
348             $where_is[] = "u.uploaded BETWEEN ".(($ul - 0.004)*1024*1024*1024)." AND ".(($ul + 0.004)*1024*1024*1024);
349         }
350         $q[] = "ul=$ul";
351     }
352
353
354     $dl = ( isset($_GET['dl']) ? trim($_GET['dl']) : '' );
355     if ($dl) {
356         if (!is_numeric($dl) || $dl < 0) {
357             trigger_error($lang['bad_downloaded']);
358         }
359         $dltype = intval($_GET['dlt']);
360         $q[] = "dlt=$dltype";
361         if ($dltype == 3) {
362             $dl2 = trim($_GET['dl2']);
363             if(!$dl2) {
364                 trigger_error($lang['two_downloaded_fields_must_be_filled']);
365             }
366             if (!is_numeric($dl2) or $dl2 < $dl) {
367                 trigger_error($lang['bad_second_downloaded_field']);
368             }
369             $where_is[] = 'u.downloaded BETWEEN '.($dl*1024*1024*1024)." and ".($dl2*1024*1024*1024);
370             $q[] = "dl2=$dl2";
371         }
372         elseif ($dltype == 2) {
373             $where_is[] = "u.downloaded < ".$dl*1024*1024*1024;
374         }
375         elseif ($dltype == 1) {
376             $where_is[] = "u.downloaded > ".$dl*1024*1024*1024;
377         }
378         else {
379             $where_is[] = "u.downloaded BETWEEN ".(($dl - 0.004)*1024*1024*1024)." and ".(($dl + 0.004)*1024*1024*1024);
380         }
381         $q[] = "dl=$dl";
382     }
383
384     // date joined
385     $date = ( isset($_GET['d']) ? trim($_GET['d']) : '' );
386     if ($date) {
387         if (!$date = mkdate($date)) {
388             trigger_error($lang['bad_date']);
389         }
390         $q[] = "d=$date";
391         $xz = explode('-', $date);
392         $date = mktime(0,0,0,$xz[1], $xz[2], $xz[0]);
393         $datetype = intval($_GET['dt']);
394         $q[] = "dt=$datetype";
395         if ($datetype == 0) {
396             $where_is[] = "u.added BETWEEN " . ($date - 86400) . " AND " . ($date + 86400);
397         }
398         if ($datetype == 3) {
399             $date2 = trim($_GET['d2']);
400             if (!$date2 = mkdate($date2)) {
401                 trigger_error($lang['bad_second_date_field']);
402             }
403             if ($date2) {
404                 $q[] = "d2=$date2";
405                 $xz = explode('-', $date2);
406                 $date2 = mktime(0,0,0,$xz[1], $xz[2], $xz[0]);
407                 $where_is[] = "u.added BETWEEN $date AND $date2";
408             }
409             else {
410                 trigger_error($lang['two_date_fields_must_be_filled']);
411             }
412         }
413         elseif ($datetype == 1) {
414             $where_is[] = "u.added < $date";
415         }
416         elseif ($datetype == 2) {
417             $where_is[] = "u.added > $date";
418         }
419     }
420
421     // date last seen
422         $last = ( isset($_GET['ls']) ? trim($_GET['ls']) : '' );
423         if ($last) {
424             if (!$last = mkdate($last)) {
425                 trigger_error($lang['bad_date']);
426             }
427             $q[] = "ls=$last";
428         $xz = explode('-', $last);
429         $last = mktime(0,0,0,$xz[1], $xz[2], $xz[0]);
430             $lasttype = intval($_GET['lst']);
431             $q[] = "lst=$lasttype";
432             if ($lasttype == 0) {
433                 $where_is[] = "u.user_session_time BETWEEN " . ($last - 86400) . " AND " . ($last + 86400);
434             }
435             else {
436                 if ($lasttype == 3) {
437                     $last2 = trim($_GET['ls2']);
438                     if (!$last2 = mkdate($last2)) {
439                         trigger_error($lang['bad_second_date_field']);
440                     }
441                         if ($last2) {
442                             $q[] = "ls=$last2";
443                             $xz = explode('-', $last2);
444                             $last2 = mktime(0,0,0,$xz[1], $xz[2], $xz[0]);
445                             $where_is[] = "u.user_session_time BETWEEN $last AND $last2";
446                         }
447                         else {
448                             trigger_error($lang['two_date_fields_must_be_filled']);
449                         }
450                 }
451                 elseif ($lasttype == 1) {
452                     $where_is[] = "u.user_session_time < $last";
453                 }
454                 elseif ($lasttype == 2) {
455                     $where_is[] = "u.user_session_time > $last";
456                 }
457             }
458         }
459
460         // disabled IP
461
462         $disabled = ( isset($_GET['dip']) ? intval($_GET['dip']) : 0 );
463         if ($disabled) {
464             $distinct = 1;
465             if ( !$config['allow_clons'] ) {
466                 $join_is .= ' LEFT JOIN ' . BANLIST_TABLE . ' pb ON u.ip = pb.ban_ip';
467                 $join_is .= ', ' . USERS_TABLE . ' u2';
468                 $where_is[] = 'u.ip = u2.ip';
469                 $where_is[] = '( pb.ban_ip IS NOT NULL OR u2.enabled = 0)';
470             }
471             else {
472                 $join_is .= ', ' . BANLIST_TABLE . ' pb';
473                 $where_is[] = 'u.ip = pb.ban_ip';
474             }
475             $q[] = "dip=$disabled";
476         }
477
478         // active
479         $active = ( isset($_GET['ac']) ? intval($_GET['ac']) : 0 );
480         if ($active == "1") {
481             $join_is .= ', ' . PEERS_TABLE . ' p';
482             $distinct = 1;
483             $where_is[] = '(p.uploaded > 0 OR p.downloaded > 0)';
484             $where_is[] = 'u.uid = p.uid';
485             $q[] = "ac=$active";
486         }
487
488        //age
489        $age = ( isset($_GET['age']) ? trim($_GET['age']) : '' );
490        if ($age) {
491                $current_y = gmdate("Y", time() + $userdata['tzoffset'] * 60);
492                $current_m = gmdate("m", time() + $userdata['tzoffset'] * 60);
493                $current_d = gmdate("d", time() + $userdata['tzoffset'] * 60);
494                $search_date1 = ($current_y - $age) . '-' . $current_m . '-' . $current_d;
495                $search_date2 = ($current_y - $age - 1) . '-' . $current_m . '-' . $current_d;
496                $where_is[] = "u.birthday BETWEEN '$search_date2' AND '$search_date1'";
497                $q[] = "age=$age";
498        }
499
500         // active
501         $warned = ( isset($_GET['w']) ? $_GET['w'] : 0 );
502         if ( $warned != '--') {
503             $where_is[] = 'u.warneduntil ' . ( $warned == 2 ? ' = 0' : ' <> 0' );
504             $q[] = "w=$warned";
505         }
506
507         $simple_fields1 = array(
508                 'as' => 'enabled',
509                 'do' => 'donor',
510                 'ht' => 'hiddentorrents',
511                 'parked' => 'parked',
512                 'st' => 'status',
513                 'gender' => 'gender'
514         );
515
516         foreach ( $simple_fields1 AS $get_name => $table_name ) {
517             if ( isset($_GET[$get_name]) && $_GET[$get_name] != '--' ) {
518                 $x = intval($_GET[$get_name]);
519                 if ( $x == 1 ) {
520                     $where_is[] = 'u.' . $table_name . ' = 1';
521                 }
522                 else {
523                     $where_is[] = 'u.' . $table_name . ' = 0';
524                 }
525                 $q[] = $get_name . '=' . $x;
526             }
527         }
528
529         $simple_fields2 = array(
530                 'icq' => 'icq',
531                 'msn' => 'msn',
532                 'aim' => 'aim',
533                 'yahoo' => 'yahoo',
534                 'skype' => 'skype',
535                 'speed_up' => 'upload',
536                 'speed_down' => 'download',
537                 'passkey' => 'torrent_pass'
538         );
539
540         foreach ( $simple_fields2 AS $get_name => $table_name ) {
541             if ( !empty($_GET[$get_name]) ) {
542                 $where_is[] = 'u.' . $table_name . ' = ' . "'" . $db->sql_escape(urldecode($$get_name)) . "'";
543                 $q[] = $get_name . '=' . $_GET[$get_name];
544             }
545         }
546
547         if ( $client ) {
548            $join_is .= ', ' . PEERS_TABLE . ' p';
549            $distinct = 1;
550            $where_is[] = "p.useragent LIKE '%" . $db->sql_escape(urldecode($client)) . "%'";
551            $where_is[] = 'u.uid = p.uid';
552          $q[] = "client=$client";
553         }
554
555        $where_is[] = 'u.uid <> ' . ANONYMOUS;
556
557
558        $where_is = ( $where_is ? implode(' AND ', $where_is) : '' );
559        $where = ( $where_is ? ' WHERE ' . $where_is : '' );
560        $q = ( $q ? implode("&amp;", $q) : '' );
561        $join_is = ( $join_is ? $join_is : '' );
562        $from_is = ' FROM ' . USERS_TABLE . ' u' . $join_is;
563        $distinct = isset($distinct) ? ' DISTINCT ' : '';
564
565
566        $count_sql = 'SELECT COUNT(' . $distinct . 'u.uid) AS count ' . $from_is . $where;
567        $result = $db->sql_query($count_sql);
568
569
570        $count = ( $arr = $db->sql_fetchrow($result) ) ? intval($arr['count']) : 0 ;
571        $perpage = 30;
572        list($pagertop, $pagerbottom, $offset, $limit) = pager($perpage, $count, 'usersearch.php?' . $q . '&amp;');
573
574        $select = ' u.uid, u.name, u.email, u.ip, u.class, u.uploaded, u.downloaded, u.donor, u.enabled, u.warneduntil, u.parked';
575        $sql = 'SELECT' . $distinct . $select . $from_is . $where;
576
577        $result = $db->sql_query_limit($sql, $limit, $offset);
578
579        if ( !($user = $db->sql_fetchrow($result)) ) {
580               $template->assign_block_vars('switch_no_count', array());
581        }
582        else {
583               $template->assign_block_vars('switch_count', array(
584                  'PAGERTOP' => $pagertop,
585                  'PAGERBOTTOM' => $pagerbottom, )
586               );
587
588               do {
589                       $seo->set_user_url($user['name'], $user['uid']);
590
591                      $template->assign_block_vars('switch_count.results_row', array(
592                             'U_USERDETAILS' => append_sid($root_path . 'userdetails.php?id=' . $user['uid']),
593                             'ID' => $user['uid'],
594                             'USERNAME' => get_user_class_color($user['class'], $user['name']),
595                             'USER_ICONS' => get_user_icons($user),
596                             'RATIO' => get_ratio($user['uploaded'], $user['downloaded']),
597                             'UPLOADED' => mksize($user['uploaded']),
598                             'DOWNLOADED' => mksize($user['downloaded']),
599                             'IP' => '<a href="http://ripe.net/fcgi-bin/whois?form_type=simple&amp;full_query_string=&amp;searchtext=' . $user['ip'] . '" target="_blank">' . $user['ip'] . '</a>',
600                             'EMAIL' => $user['email'])
601                      );
602               }
603               while ($user = $db->sql_fetchrow($result));
604
605        }
606 }
607 stdhead($lang['user_search'], false);
608 $template->set_filenames(array(</span>
609 <span class="code-lang">        'body' => 'usersearch.html')
610 );
611 stdfoot();
612 ?>
Note: See TracBrowser for help on using the browser.