usersearch_functions.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:5k
- <?php
-
- function generate_user_search_where() {
- global $_REQUEST, $db;
- /*
- - generates a query to run a user search
- - is used for both ticket searching (limited by users) and user searching
- */
- // id range
- if ($_REQUEST['usersearch_greater']) {
- $where[] = "user.id >= '" . mysql_escape_string($_REQUEST['usersearch_greater']) . "'";
- }
- if ($_REQUEST['usersearch_lessthan']) {
- $where[] = "user.id <= '" . mysql_escape_string($_REQUEST['usersearch_lessthan']) . "'";
- }
- // username
- if (trim($_REQUEST['usersearch_username']) != '') {
- $where[] = "user.username LIKE '%" . mysql_escape_string(addslashes_like($_REQUEST['usersearch_username'])) . "%'";
- }
- // email
- if (trim($_REQUEST['usersearch_email']) != '') {
- $where[] = "user.email LIKE '%" . mysql_escape_string(addslashes_like($_REQUEST['usersearch_email'])) . "%'";
- }
- // earliest date registered
- if ($_REQUEST['ddate_registered_start']) {
- $time = mktime(0, 0, 0, $_REQUEST['mdate_registered_start'], $_REQUEST['ddate_registered_start'], $_REQUEST['ydate_registered_start']);
- $where[] = "user.date_registered >= '$time'";
- }
- // lastest date registered
- if ($_REQUEST['ddate_registered_end']) {
- $time = mktime(0, 0, 0, $_REQUEST['mdate_registered_end'], $_REQUEST['ddate_registered_end'], $_REQUEST['ydate_registered_end']);
- $where[] = "user.date_registered <= '$time'";
- }
- // custom fields
- $db->query("SELECT * FROM user_def WHERE tech_viewable ORDER BY displayorder");
- while ($result = $db->row_array()) {
- $where[] = field_search(
- $result,
- $_REQUEST[custom_fields][$result[name]],
- $_REQUEST[custom_fields]['extra' . $result[name]],
- 'user',
- $_REQUEST[custom_fields][$result[name]."_match"],
- $_REQUEST[custom_fields][$result[name]."_not"],
- 1
- );
- $allowed_fields[] = $result[name];
- $data[$result[name]] = array('display_name' => $result[display_name], 'description' => $result[description]);
- }
- // turn array of conditions into SQL
- if (is_array($where)) {
- foreach ($where AS $key => $var) {
- if ($var != '') {
- if (!$i) {
- $query = "WHERE $var";
- $i = true;
- } else {
- $query .= " AND $var";
- }
- }
- }
- }
- return $query;
- }
- function generate_user_search_form_standard() {
- global $_REQUEST, $db, $settings;
- // id range
- $bit = form_input('usersearch_greater', $_REQUEST['usersearch_greater'], 3) . " < <b>ID</b> > " . form_input('usersearch_lessthan', $_REQUEST['usersearch_lessthan'], 3);
- $table[] = array(table_thelp('<b>User ID Range</b>', 'Users', 'Search: User ID Range'), $bit);
- // user owner
- $bit = form_input('usersearch_username', $_REQUEST['usersearch_username'], 30) . " <a onClick="openWindow('./../users/quickfind.php?name=searchform.usersearch_username', 450, 600, 'userfind')">".html_image('tech/pribut040.gif')."</a>";
- $table[] = array(table_thelp('<b>Username</b>', 'Users', 'Search: Username'), $bit);
- $bit = form_input('usersearch_email', $_REQUEST['usersearch_email'], 30) . " <a onClick="openWindow('./../users/quickfind.php?name=searchform.usersearch_email', 450, 600, 'userfind')">".html_image('tech/pribut040.gif')."</a>";
- $table[] = array(table_thelp('<b>E-mail</b>', 'Users', 'Search: User E-mail'), $bit);
- // sort dates for display
- if ($_REQUEST['ydate_registered_start']) {
- $date = @strtotime("$_REQUEST[ydate_registered_start]-$_REQUEST[mdate_registered_start]-$_REQUEST[ddate_registered_start]");
- } else {
- $date = NULL;
- }
- if ($_REQUEST['ydate_registered_end']) {
- $date2 = @strtotime("$_REQUEST[ydate_registered_end]-$_REQUEST[mdate_registered_end]-$_REQUEST[ddate_registered_end]");
- } else {
- $date2 = NULL;
- }
- // date of registration
- $bit = 'From ' . form_date('date_registered_start', '', $date, '', 1) . "<a onClick="datePop('searchform', 'date_registered_start')">".html_image('tech/bul102.gif')."</a> To " . form_date('date_registered_end', '', $date2, '', 1) . "<a onClick="datePop('searchform', 'date_registered_end')">".html_image('tech/bul102.gif')."</a>";
- $table[] = array(table_thelp('<b>Date Registered</b>', 'Users', 'Search: Date Registered'), $bit);
- unset($date, $date2);
- $db->query("SELECT * FROM user_def WHERE tech_viewable");
- while ($result = $db->row_array()) {
- $display_name = unserialize($result[display_name]);
- $display_name = $display_name[$settings[default_language]];
- $array_fields[$result[name]] = $display_name;
- $bit = field_def($result, 'redo', $_REQUEST[custom_fields][$result[name]], $_REQUEST[custom_fields]["extra" . $result[name]], '', 'custom_fields', 1);
- $table[] = array("<b>$display_name</b>", $bit);
- }
- table_header('User Search');
- table_content('', $table);
- table_footer();
- }
- // $table[] = array(table_thelp('<b>Fields to Display</b>', 'Users', 'Search: Fields to Display'), $tmp);