source: trunk/search.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 18 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28//--------------------------------------------------------------------- include
29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_GUEST);
36
37//------------------------------------------------------------------ form check
38$errors = array();
39$search = array();
40if (isset($_POST['submit']))
41{
42  if (isset($_POST['search_allwords'])
43      and !preg_match('/^\s*$/', $_POST['search_allwords']))
44  {
45    $drop_char_match = array(
46      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
47      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
48    $drop_char_replace = array(
49      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
50      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
51
52    // Split words
53    $search['fields']['allwords'] = array(
54      'words' => array_unique(
55        preg_split(
56          '/\s+/',
57          str_replace(
58            $drop_char_match,
59            $drop_char_replace,
60            $_POST['search_allwords']
61            )
62          )
63        ),
64      'mode' => $_POST['mode'],
65      );
66  }
67
68  if ($_POST['search_author'])
69  {
70    $search['fields']['author'] = array(
71      'words' => preg_split(
72        '/\s+/',
73        $_POST['search_author']
74        ),
75      'mode' => 'OR',
76      );
77  }
78
79  if (isset($_POST['cat']))
80  {
81    $search['fields']['cat'] = array(
82      'words'   => $_POST['cat'],
83      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
84      );
85  }
86
87  // dates
88  $type_date = $_POST['date_type'];
89
90  if (!empty($_POST['start_year']))
91  {
92    $search['fields'][$type_date.'-after'] = array(
93      'date' => join(
94        '-',
95        array(
96          $_POST['start_year'],
97          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
98          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
99          )
100        ),
101      'inc' => true,
102      );
103  }
104
105  if (!empty($_POST['end_year']))
106  {
107    $search['fields'][$type_date.'-before'] = array(
108      'date' => join(
109        '-',
110        array(
111          $_POST['end_year'],
112          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
113          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
114          )
115        ),
116      'inc' => true,
117      );
118  }
119
120  if (!empty($search))
121  {
122    // default search mode : each clause must be respected
123    $search['mode'] = 'AND';
124
125    // register search rules in database, then they will be available on
126    // thumbnails page and picture page.
127    $query ='
128INSERT INTO '.SEARCH_TABLE.'
129  (rules)
130  VALUES
131  (\''.serialize($search).'\')
132;';
133    pwg_query($query);
134
135    $search_id = mysql_insert_id();
136  }
137  else
138  {
139    array_push($errors, $lang['search_one_clause_at_least']);
140  }
141}
142//----------------------------------------------------------------- redirection
143if (isset($_POST['submit']) and count($errors) == 0)
144{
145  $url = 'category.php?cat=search&search='.$search_id;
146  redirect($url);
147}
148//----------------------------------------------------- template initialization
149
150// start date
151get_day_list('start_day', @$_POST['start_day']);
152get_month_list('start_month', @$_POST['start_month']);
153// end date
154get_day_list('end_day', @$_POST['end_day']);
155get_month_list('end_month', @$_POST['end_month']);
156
157//
158// Start output of page
159//
160$title= $lang['search_title'];
161$page['body_id'] = 'theSearchPage';
162include(PHPWG_ROOT_PATH.'include/page_header.php');
163
164$template->set_filenames( array('search'=>'search.tpl') );
165$template->assign_vars(array(
166  'L_SEARCH_TITLE' => $lang['search_title'],
167  'L_SEARCH_OPTIONS' => $lang['search_options'],
168  'L_RETURN' => $lang['home'],
169  'L_SUBMIT' => $lang['submit'],
170  'L_RESET' => $lang['reset'],
171  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
172  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
173  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
174  'L_SEARCH_AUTHOR'=>$lang['search_author'],
175  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
176  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
177  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
178  'L_YES' => $lang['yes'],
179  'L_NO' => $lang['no'],
180  'L_SEARCH_DATE' => $lang['search_date'],
181  'L_TODAY' => $lang['today'],
182  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
183  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
184  'L_DAYS'=>$lang['days'],
185  'L_MONTH'=>$lang['w_month'],
186  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
187  'L_RESULT_SORT'=>$lang['search_sort'],
188  'L_SORT_ASCENDING'=>$lang['search_ascending'],
189  'L_SORT_DESCENDING'=>$lang['search_descending'],
190
191  'TODAY_DAY' => date('d', time()),
192  'TODAY_MONTH' => date('m', time()),
193  'TODAY_YEAR' => date('Y', time()),
194  'S_SEARCH_ACTION' => 'search.php',
195  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
196  'U_HOME' => 'category.php'
197  )
198);
199
200//------------------------------------------------------------- categories form
201$query = '
202SELECT name,id,date_last,nb_images,global_rank,uppercats
203  FROM '.CATEGORIES_TABLE;
204if ($user['forbidden_categories'] != '')
205{
206  $query.= '
207  WHERE id NOT IN ('.$user['forbidden_categories'].')';
208}
209$query.= '
210;';
211
212$selecteds = array();
213display_select_cat_wrapper($query, $selecteds, 'category_option', false);
214
215//-------------------------------------------------------------- errors display
216if (sizeof($errors) != 0)
217{
218  $template->assign_block_vars('errors',array());
219  foreach ($errors as $error)
220  {
221    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
222  }
223}
224//------------------------------------------------------------ log informations
225pwg_log( 'search', $title );
226$template->parse('search');
227include(PHPWG_ROOT_PATH.'include/page_tail.php');
228?>
Note: See TracBrowser for help on using the repository browser.