source: trunk/search.php @ 16930

Last change on this file since 16930 was 15578, checked in by mistic100, 12 years ago

feature:2538 little rework of messages system, now can be used on 'loc_end_index' and 'loc_end_picture'

  • Property svn:eol-style set to LF
File size: 7.0 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
[2]23
[455]24//--------------------------------------------------------------------- include
[364]25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1072]27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_GUEST);
32
[455]33//------------------------------------------------------------------ form check
34$search = array();
35if (isset($_POST['submit']))
[2]36{
[4753]37  foreach ($_POST as $post_key => $post_value)
38  {
39    if (!is_array($post_value))
40    {
[6518]41      $_POST[$post_key] = pwg_db_real_escape_string($post_value);
[4753]42    }
43  } 
44 
[634]45  if (isset($_POST['search_allwords'])
46      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]47  {
[634]48    $drop_char_match = array(
49      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
50      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
51    $drop_char_replace = array(
52      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
53      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]54
[634]55    // Split words
[1008]56    $search['fields']['allwords'] = array(
57      'words' => array_unique(
58        preg_split(
59          '/\s+/',
60          str_replace(
61            $drop_char_match,
62            $drop_char_replace,
63            $_POST['search_allwords']
64            )
65          )
66        ),
67      'mode' => $_POST['mode'],
68      );
[455]69  }
[1059]70
[1119]71  if (isset($_POST['tags']))
72  {
[5195]73    check_input_parameter('tags', $_POST, true, PATTERN_ID);
[4753]74   
[1119]75    $search['fields']['tags'] = array(
76      'words' => $_POST['tags'],
77      'mode'  => $_POST['tag_mode'],
78      );
79  }
[1125]80
[621]81  if ($_POST['search_author'])
[455]82  {
[1008]83    $search['fields']['author'] = array(
[1015]84      'words' => preg_split(
85        '/\s+/',
86        $_POST['search_author']
87        ),
88      'mode' => 'OR',
[1008]89      );
[17]90  }
[1059]91
[621]92  if (isset($_POST['cat']))
[2]93  {
[5195]94    check_input_parameter('cat', $_POST, true, PATTERN_ID);
[4753]95   
[1008]96    $search['fields']['cat'] = array(
97      'words'   => $_POST['cat'],
98      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
99      );
[2]100  }
[634]101
102  // dates
103  $type_date = $_POST['date_type'];
[1059]104
[621]105  if (!empty($_POST['start_year']))
[634]106  {
[1008]107    $search['fields'][$type_date.'-after'] = array(
[6518]108      'date' => sprintf(
109        '%d-%02d-%02d',
110        $_POST['start_year'],
111        $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
112        $_POST['start_day']   != 0 ? $_POST['start_day']   : '01'
[1008]113        ),
114      'inc' => true,
115      );
[634]116  }
[621]117
[634]118  if (!empty($_POST['end_year']))
[621]119  {
[1008]120    $search['fields'][$type_date.'-before'] = array(
[6518]121      'date' => sprintf(
122        '%d-%02d-%02d',
123        $_POST['end_year'],
124        $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
125        $_POST['end_day']   != 0 ? $_POST['end_day']   : '31'
126      ),
[1008]127      'inc' => true,
128      );
[621]129  }
[1059]130
[621]131  if (!empty($search))
132  {
[1008]133    // default search mode : each clause must be respected
134    $search['mode'] = 'AND';
135
136    // register search rules in database, then they will be available on
137    // thumbnails page and picture page.
138    $query ='
139INSERT INTO '.SEARCH_TABLE.'
[1816]140  (rules, last_seen)
[1008]141  VALUES
[1816]142  (\''.serialize($search).'\', NOW())
[1008]143;';
144    pwg_query($query);
145
[4892]146    $search_id = pwg_db_insert_id(SEARCH_TABLE);
[455]147  }
[621]148  else
[455]149  {
[12764]150    array_push($page['errors'], l10n('Empty query. No criteria has been entered.'));
[455]151  }
[2]152}
[455]153//----------------------------------------------------------------- redirection
[12764]154if (isset($_POST['submit']) and count($page['errors']) == 0)
[455]155{
[1082]156  redirect(
157    make_index_url(
158      array(
159        'section' => 'search',
160        'search'  => $search_id,
161        )
162      )
163    );
[455]164}
[2]165//----------------------------------------------------- template initialization
[621]166
[345]167//
168// Start output of page
169//
[5021]170$title= l10n('Search');
[850]171$page['body_id'] = 'theSearchPage';
[345]172
[2223]173$template->set_filename('search' ,'search.tpl' );
[1125]174
[2223]175$month_list = $lang['month'];
176$month_list[0]='------------';
177ksort($month_list);
178
179$template->assign(
[1314]180  array(
[2223]181    'F_SEARCH_ACTION' => 'search.php',
[1314]182    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
[2324]183
[2223]184    'month_list' => $month_list,
185    'START_DAY_SELECTED' => @$_POST['start_day'],
186    'START_MONTH_SELECTED' => @$_POST['start_month'],
187    'END_DAY_SELECTED' => @$_POST['end_day'],
188    'END_MONTH_SELECTED' => @$_POST['end_month'],
[1314]189    )
190  );
191
[1677]192$available_tags = get_available_tags();
[1125]193
[1314]194if (count($available_tags) > 0)
195{
[2409]196  usort( $available_tags, 'tag_alpha_compare');
[1119]197
[2223]198  $template->assign(
199    'TAG_SELECTION',
200    get_html_tag_selection(
[1314]201        $available_tags,
202        'tags',
203        isset($_POST['tags']) ? $_POST['tags'] : array()
[2223]204        )
[1314]205    );
206}
[355]207
[455]208//------------------------------------------------------------- categories form
[614]209$query = '
[2324]210SELECT id,name,global_rank,uppercats
[1677]211  FROM '.CATEGORIES_TABLE.'
212'.get_sql_condition_FandF
213  (
214    array
215      (
216        'forbidden_categories' => 'id',
217        'visible_categories' => 'id'
218      ),
219    'WHERE'
220  ).'
[614]221;';
[2223]222display_select_cat_wrapper($query, array(), 'category_options', false);
[621]223
[10812]224
225// include menubar
226$themeconf = $template->get_template_vars('themeconf');
[10824]227if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on']))
[10812]228{
229  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
230}
231
232//------------------------------------------------------------ html code display
[1627]233include(PHPWG_ROOT_PATH.'include/page_header.php');
[15578]234include(PHPWG_ROOT_PATH.'include/page_messages.php');
[2223]235$template->pparse('search');
[369]236include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]237?>
Note: See TracBrowser for help on using the repository browser.