257 lines
8.4 KiB
PHP
257 lines
8.4 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_general_search_entry($database, $search_string, $current_user_id, $masters_only) {
|
|
global $thm_elem;
|
|
global $search_interface;
|
|
global $site_url;
|
|
global $strings;
|
|
|
|
theme_display_navigator_box_top($search_interface['text_general']['idx'], $search_interface, "100%");
|
|
|
|
print "<table class=\"search\">";
|
|
print "<tr><td align=\"center\">";
|
|
print "<input type=\"text\" name=\"search_string\" value=\"$search_string\" size=\"50\"/>";
|
|
print "</td>";
|
|
|
|
print "<td >";
|
|
print generate_html_users_combo("current_user", $database, $current_user_id, TRUE, FALSE);
|
|
print "</td>";
|
|
|
|
print "</tr>";
|
|
print "<tr><td align=\"center\" colspan=\"2\">".emit_checkbox_item("only_masters", "only_masters", "", $masters_only) . $strings['search_masters_only'] ."</td></tr>";
|
|
|
|
print "<tr><td align=\"center\" colspan=\"2\">";
|
|
print $thm_elem['button.search'];
|
|
print "</td></tr>";
|
|
print "</table>";
|
|
|
|
theme_display_navigator_box_bottom("100%");
|
|
}
|
|
|
|
$folder_id = "";
|
|
$album_id = "";
|
|
|
|
$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']);
|
|
|
|
if (!$current_user_id || ($current_user_id=="all")) {
|
|
$current_user_id = "null";
|
|
$sql_photo_users_string = " ";
|
|
$sql_folder_users_string = " ";
|
|
$sql_album_users_string = " ";
|
|
} else {
|
|
$sql_photo_users_string = " and photo.users = $current_user_id ";
|
|
$sql_folder_users_string = " and folder.users = $current_user_id ";
|
|
$sql_album_users_string = " and album.users = $current_user_id ";
|
|
}
|
|
|
|
$offset = pg_escape_string($database, isset($_REQUEST['offset']) ? $_REQUEST['offset'] : 0);
|
|
if ($offset && !is_numeric($offset)) {
|
|
$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) {
|
|
if (!$master && ($po_options['search_masters_only'] != 'f')) {
|
|
$master = TRUE;
|
|
}
|
|
site_navigator_status($strings['search_string'], "");
|
|
print "<form action=\"search.text.general.php\" method=\"post\" accept-charset=\"".$strings['formats_encoding']."\">";
|
|
display_general_search_entry($database, $search_string, $current_user_id, $master);
|
|
print "</form>";
|
|
print " <br/>\n";
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
|
|
$num_of_matches = 0;
|
|
|
|
$photo_view = $po_options['photo_view'];
|
|
|
|
if ($photo_view) {
|
|
$limit = $po_options['photos_per_page'];
|
|
} else {
|
|
$limit = $po_options['rows_list_view'];
|
|
}
|
|
|
|
if ($master)
|
|
$master = "and photo_version.master = 't'";
|
|
else
|
|
$master = "";
|
|
|
|
$status_string=$strings['search_displaying'];
|
|
|
|
$entries = array();
|
|
$cols = array('photo.title',
|
|
'photo.author',
|
|
'photo.comments',
|
|
'photo.caption',
|
|
'view_location.place',
|
|
'view_location.city',
|
|
'view_location.state',
|
|
'view_location.country',
|
|
'photo_version.original_image_name');
|
|
|
|
foreach ($cols as $col) {
|
|
$entries[] = build_sql_search_string($keywords, $col);
|
|
}
|
|
$entries[] = build_sql_search_string_keywords($keywords);
|
|
|
|
$sql_search_combined = implode(" OR ", $entries);
|
|
|
|
$froms = array('view_location');
|
|
$fields = array();
|
|
$filter = " view_location.identifier = photo.location AND ($sql_search_combined)
|
|
$sql_photo_users_string
|
|
$master";
|
|
$search_result = get_photo_query($database, $fields, $froms, $filter, 0, 0, $order_by);
|
|
|
|
$num_of_matches = sizeof($search_result);
|
|
|
|
/* Sanity checks */
|
|
if ($limit > $num_of_matches) {
|
|
$limit = $num_of_matches;
|
|
}
|
|
while ($num_of_matches && $offset >= $num_of_matches) {
|
|
$offset -= $limit;
|
|
}
|
|
if ($offset < 0) {
|
|
$offset = 0;
|
|
}
|
|
if (($offset + $limit) > $num_of_matches) {
|
|
$items = $num_of_matches - $offset;
|
|
} else {
|
|
$items = $limit;
|
|
}
|
|
|
|
if ($num_of_matches == 0) {
|
|
$itemized_search_string = build_itemized_search_string($search_string, "search_string");
|
|
site_navigator_status($strings['search_no_matches']." $itemized_search_string", "");
|
|
|
|
print "<form action=\"search.text.general.php\" method=\"post\" accept-charset=\"".$strings['formats_encoding']."\">";
|
|
display_general_search_entry($database, $search_string, $current_user_id, $master);
|
|
print "</form>";
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
exit();
|
|
}
|
|
|
|
$itemized_search_string = build_itemized_search_string($search_string, "search_string");
|
|
site_navigator_status($strings['search_searched_for']."<strong>$itemized_search_string</strong>", $status_string. " " . display_photo_index_status($offset, $limit, $num_of_matches));
|
|
print "<form action=\"search.text.general.php\" method=\"post\" accept-charset=\"".$strings['formats_encoding']."\">";
|
|
display_general_search_entry($database, $search_string, $current_user_id, $master);
|
|
print "</form>";
|
|
|
|
$arguments = "";
|
|
|
|
if ($master) {
|
|
$arguments .= "&only_masters=true";
|
|
}
|
|
|
|
$search_string_exp = str_replace(" ", "+", $search_string);
|
|
|
|
print "<form name=\"photoList\" method=\"post\" action=\"folder.content.php\" accept-charset=\"".$strings['formats_encoding']."\">";
|
|
print "<input type=\"hidden\" name=\"return\" value=\"search.text.general.php?search_string=$search_string$arguments\"/>";
|
|
|
|
display_photo_navigator("search.text.general.php?search_string=$search_string_exp$arguments", $offset, $limit, $num_of_matches);
|
|
|
|
if ($photo_view == "slide") {
|
|
$checkboxes = display_photo_slides("search_general", $folder_id, $search_result, $offset, $items, true, true);
|
|
} else {
|
|
$checkboxes = display_photo_list("search_general", $folder_id, $search_result, $offset, $items);
|
|
}
|
|
|
|
display_photo_navigator("search.text.general.php?search_string=$search_string_exp$arguments", $offset, $limit, $num_of_matches);
|
|
|
|
$itemized_search_string = build_itemized_search_string($search_string, "search_string");
|
|
site_navigator_status($strings['search_searched_for'] ."$itemized_search_string", $status_string ." " . display_photo_index_status($offset, $limit, $num_of_matches));
|
|
|
|
print "<div class=\"actions\">";
|
|
if ($checkboxes !== FALSE) {
|
|
display_order_by_combo_with_button($order_by);
|
|
|
|
if ($photo_view == 'slide') {
|
|
print emit_photos_per_page_combo('photos_per_page', $po_options['photos_per_page']);
|
|
} else {
|
|
print emit_photos_per_page_combo('rows_list_view', $po_options['rows_list_view']);
|
|
}
|
|
}
|
|
|
|
print "<span>\n";
|
|
|
|
if ($checkboxes !== FALSE) {
|
|
display_list_slide_option($photo_view, "search.text.general.php?search_string=$_REQUEST[search_string]&offset=$offset");
|
|
}
|
|
|
|
if ($checkboxes > 0 && $po_user['id']) {
|
|
theme_display_selectButton();
|
|
print $thm_elem['button.add.to.spool'];
|
|
print $thm_elem['button.bulk.update'];
|
|
}
|
|
|
|
print "</span>\n";
|
|
|
|
if ($checkboxes > 0 && $po_user['id']) {
|
|
$album_all = get_users_album($database);
|
|
$folder_all = get_users_folder($database);
|
|
print emit_folder_actions($folder_all, $folder_id);
|
|
if (count($album_all)) {
|
|
print emit_album_actions($album_all, $album_id);
|
|
}
|
|
|
|
}
|
|
if ($po_user['id']) {
|
|
print emit_spool_actions($database, $po_user['id']);
|
|
print emit_import_actions($database, $po_user['id']);
|
|
print emit_print_actions($database, $po_user['id']);
|
|
}
|
|
|
|
print "</div>";
|
|
print "</form>";
|
|
|
|
site_footer($database);
|
|
site_epilog($database);
|
|
?>
|