141 lines
4.8 KiB
PHP
141 lines
4.8 KiB
PHP
<?php
|
|
|
|
// Copyright (C) 2002-2006 Balint Kis (balint@k-i-s.net)
|
|
// Copyright (C) 2005-2013 Solomon Peachy (pizza@shaftnet.org)
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation; either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program; if not, write to the Free Software
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
include_once "include/config.php";
|
|
include_once "include/common.php";
|
|
include_once "include/site.php";
|
|
include_once "include/orderby.php";
|
|
include_once "include/search.php";
|
|
|
|
function display_users_search_entry($database, $search_string, $current_user_id) {
|
|
global $thm_elem;
|
|
global $search_interface;
|
|
global $site_url;
|
|
global $strings;
|
|
|
|
theme_display_navigator_box_top($search_interface['users']['idx'], $search_interface, "100%");
|
|
|
|
print "<form action=\"search.users.php\" method=\"post\" accept-charset=\"".$strings['formats_encoding']."\">";
|
|
print "<table class=\"search\">";
|
|
print "<tr><td align=\"center\">";
|
|
print "<input type=\"text\" name=\"search_string\" value=\"$search_string\" size=\"50\"/>";
|
|
print "</td>";
|
|
print "</tr>";
|
|
print "<tr><td align=\"center\">";
|
|
print $thm_elem['button.search'];
|
|
print "</td></tr>";
|
|
print "</table>";
|
|
print "</form>";
|
|
|
|
theme_display_navigator_box_bottom("100%");
|
|
}
|
|
|
|
function build_users_search_string($search_string, $identifier) {
|
|
$itemized_search_string = "";
|
|
|
|
/* translate tabs and new lines into spaces */
|
|
$token = strtok($search_string," ");
|
|
while ($token) {
|
|
if (strncmp($token, "AND", 3) == 0) {
|
|
$itemized_search_string = $itemized_search_string . "AND ";
|
|
} elseif (strncmp($token, "NOT", 3) == 0) {
|
|
$itemized_search_string = $itemized_search_string . "NOT ";
|
|
} elseif (strncmp($token, "OR", 2) == 0) {
|
|
$itemized_search_string = $itemized_search_string . "OR ";
|
|
} else {
|
|
$itemized_search_string = $itemized_search_string . emit_a("search.users.php?$identifier=$token", "$token ");
|
|
}
|
|
$token = strtok("+ \n\t");
|
|
}
|
|
|
|
return $itemized_search_string;
|
|
}
|
|
|
|
$search_string = isset($_REQUEST['search_string']) ? $_REQUEST['search_string'] : "";
|
|
$sql_search_string = validate_search_string($search_string);
|
|
$search_string = htmlentities($search_string);
|
|
|
|
$current_user_id = isset($_REQUEST['current_user']) ? $_REQUEST['current_user'] : $po_user['id'];
|
|
if ($current_user_id == 'null')
|
|
$current_user_id = $po_user['id'];
|
|
|
|
$master = isset($_REQUEST['only_masters']);
|
|
|
|
$offset = pg_escape_string($database, isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0);
|
|
|
|
$order_by = $po_options['order_by'];
|
|
|
|
$database = site_prolog();
|
|
|
|
site_header($strings['generic_search']);
|
|
|
|
site_navigator(2);
|
|
|
|
$keywords = extract_keywords($sql_search_string, $po_options['search_enable_stemming']);
|
|
|
|
if (!$keywords) {
|
|
site_navigator_status($strings['search_string'], "");
|
|
display_users_search_entry($database, $search_string, $current_user_id);
|
|
print " <br/>\n";
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
|
|
$num_of_matches = 0;
|
|
|
|
$status_string = $strings['search_display_users'];
|
|
|
|
$sql_search_string = "AND (".
|
|
build_sql_search_string($keywords, "last_name")." OR ".
|
|
build_sql_search_string($keywords, "first_name")." OR ".
|
|
build_sql_search_string($keywords, "username").")";
|
|
|
|
$search_result = pg_query($database,
|
|
"select count(identifier)
|
|
from users
|
|
where type > ".PO_USER_TYPE_CLIENT."
|
|
$sql_search_string");
|
|
$search_result = pg_fetch_row($search_result);
|
|
$num_of_matches = $search_result[0];
|
|
|
|
if ($num_of_matches == 0) {
|
|
$itemized_search_string = build_users_search_string($search_string, "search_string");
|
|
site_navigator_status($strings['search_no_matches']." $itemized_search_string", "");
|
|
|
|
display_users_search_entry($database, $search_string, $current_user_id);
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
|
|
$itemized_search_string = build_users_search_string($search_string, "search_string");
|
|
site_navigator_status($strings['search_searched_for']." $itemized_search_string", $status_string. " " . display_photo_index_status($offset, 0, $num_of_matches));
|
|
|
|
display_users_search_entry($database, $search_string, $current_user_id);
|
|
|
|
display_users($database, $po_user['id'], $sql_search_string);
|
|
$itemized_search_string = build_users_search_string($search_string, "search_string");
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
?>
|