source: trunk/search.php @ 21631

Last change on this file since 21631 was 20609, checked in by rvelices, 12 years ago

replaced page_messages.php with a function to call

  • Property svn:eol-style set to LF
File size: 7.1 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
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// +-----------------------------------------------------------------------+
23
24//--------------------------------------------------------------------- include
25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_GUEST);
32
33trigger_action('loc_begin_search');
34
35//------------------------------------------------------------------ form check
36$search = array();
37if (isset($_POST['submit']))
38{
39  foreach ($_POST as $post_key => $post_value)
40  {
41    if (!is_array($post_value))
42    {
43      $_POST[$post_key] = pwg_db_real_escape_string($post_value);
44    }
45  } 
46 
47  if (isset($_POST['search_allwords'])
48      and !preg_match('/^\s*$/', $_POST['search_allwords']))
49  {
50    $drop_char_match = array(
51      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
52      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
53    $drop_char_replace = array(
54      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
55      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
56
57    // Split words
58    $search['fields']['allwords'] = array(
59      'words' => array_unique(
60        preg_split(
61          '/\s+/',
62          str_replace(
63            $drop_char_match,
64            $drop_char_replace,
65            $_POST['search_allwords']
66            )
67          )
68        ),
69      'mode' => $_POST['mode'],
70      );
71  }
72
73  if (isset($_POST['tags']))
74  {
75    check_input_parameter('tags', $_POST, true, PATTERN_ID);
76   
77    $search['fields']['tags'] = array(
78      'words' => $_POST['tags'],
79      'mode'  => $_POST['tag_mode'],
80      );
81  }
82
83  if ($_POST['search_author'])
84  {
85    $search['fields']['author'] = array(
86      'words' => preg_split(
87        '/\s+/',
88        $_POST['search_author']
89        ),
90      'mode' => 'OR',
91      );
92  }
93
94  if (isset($_POST['cat']))
95  {
96    check_input_parameter('cat', $_POST, true, PATTERN_ID);
97   
98    $search['fields']['cat'] = array(
99      'words'   => $_POST['cat'],
100      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
101      );
102  }
103
104  // dates
105  $type_date = $_POST['date_type'];
106
107  if (!empty($_POST['start_year']))
108  {
109    $search['fields'][$type_date.'-after'] = array(
110      'date' => sprintf(
111        '%d-%02d-%02d',
112        $_POST['start_year'],
113        $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
114        $_POST['start_day']   != 0 ? $_POST['start_day']   : '01'
115        ),
116      'inc' => true,
117      );
118  }
119
120  if (!empty($_POST['end_year']))
121  {
122    $search['fields'][$type_date.'-before'] = array(
123      'date' => sprintf(
124        '%d-%02d-%02d',
125        $_POST['end_year'],
126        $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
127        $_POST['end_day']   != 0 ? $_POST['end_day']   : '31'
128      ),
129      'inc' => true,
130      );
131  }
132
133  if (!empty($search))
134  {
135    // default search mode : each clause must be respected
136    $search['mode'] = 'AND';
137
138    // register search rules in database, then they will be available on
139    // thumbnails page and picture page.
140    $query ='
141INSERT INTO '.SEARCH_TABLE.'
142  (rules, last_seen)
143  VALUES
144  (\''.serialize($search).'\', NOW())
145;';
146    pwg_query($query);
147
148    $search_id = pwg_db_insert_id(SEARCH_TABLE);
149  }
150  else
151  {
152    array_push($page['errors'], l10n('Empty query. No criteria has been entered.'));
153  }
154}
155//----------------------------------------------------------------- redirection
156if (isset($_POST['submit']) and count($page['errors']) == 0)
157{
158  redirect(
159    make_index_url(
160      array(
161        'section' => 'search',
162        'search'  => $search_id,
163        )
164      )
165    );
166}
167//----------------------------------------------------- template initialization
168
169//
170// Start output of page
171//
172$title= l10n('Search');
173$page['body_id'] = 'theSearchPage';
174
175$template->set_filename('search' ,'search.tpl' );
176
177$month_list = $lang['month'];
178$month_list[0]='------------';
179ksort($month_list);
180
181$template->assign(
182  array(
183    'F_SEARCH_ACTION' => 'search.php',
184    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
185
186    'month_list' => $month_list,
187    'START_DAY_SELECTED' => @$_POST['start_day'],
188    'START_MONTH_SELECTED' => @$_POST['start_month'],
189    'END_DAY_SELECTED' => @$_POST['end_day'],
190    'END_MONTH_SELECTED' => @$_POST['end_month'],
191    )
192  );
193
194$available_tags = get_available_tags();
195
196if (count($available_tags) > 0)
197{
198  usort( $available_tags, 'tag_alpha_compare');
199
200  $template->assign(
201    'TAG_SELECTION',
202    get_html_tag_selection(
203        $available_tags,
204        'tags',
205        isset($_POST['tags']) ? $_POST['tags'] : array()
206        )
207    );
208}
209
210//------------------------------------------------------------- categories form
211$query = '
212SELECT id,name,global_rank,uppercats
213  FROM '.CATEGORIES_TABLE.'
214'.get_sql_condition_FandF
215  (
216    array
217      (
218        'forbidden_categories' => 'id',
219        'visible_categories' => 'id'
220      ),
221    'WHERE'
222  ).'
223;';
224display_select_cat_wrapper($query, array(), 'category_options', false);
225
226
227// include menubar
228$themeconf = $template->get_template_vars('themeconf');
229if (!isset($themeconf['hide_menu_on']) OR !in_array('theSearchPage', $themeconf['hide_menu_on']))
230{
231  include( PHPWG_ROOT_PATH.'include/menubar.inc.php');
232}
233
234//------------------------------------------------------------ html code display
235include(PHPWG_ROOT_PATH.'include/page_header.php');
236trigger_action('loc_end_search');
237flush_page_messages();
238$template->pparse('search');
239include(PHPWG_ROOT_PATH.'include/page_tail.php');
240?>
Note: See TracBrowser for help on using the repository browser.