source: trunk/search.php @ 1009

Last change on this file since 1009 was 1009, checked in by plg, 19 years ago

Code cleaning (deletion of previously commented code)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 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-01-20 14:39:31 +0000 (Fri, 20 Jan 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1009 $
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//-------------------------------------------------- access authorization check
32check_login_authorization();
33//------------------------------------------------------------------ form check
34$errors = array();
35$search = array();
36if (isset($_POST['submit']))
37{
38  if (isset($_POST['search_allwords'])
39      and !preg_match('/^\s*$/', $_POST['search_allwords']))
40  {   
41    $drop_char_match = array(
42      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
43      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
44    $drop_char_replace = array(
45      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
46      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
47       
48    // Split words
49    $search['fields']['allwords'] = array(
50      'words' => array_unique(
51        preg_split(
52          '/\s+/',
53          str_replace(
54            $drop_char_match,
55            $drop_char_replace,
56            $_POST['search_allwords']
57            )
58          )
59        ),
60      'mode' => $_POST['mode'],
61      );
62  }
63 
64  if ($_POST['search_author'])
65  {
66    $search['fields']['author'] = array(
67      'words' => array($_POST['search_author']),
68      );
69  }
70 
71  if (isset($_POST['cat']))
72  {
73    $search['fields']['cat'] = array(
74      'words'   => $_POST['cat'],
75      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
76      );
77  }
78
79  // dates
80  $type_date = $_POST['date_type'];
81 
82  if (!empty($_POST['start_year']))
83  {
84    $search['fields'][$type_date.'-after'] = array(
85      'date' => join(
86        '-',
87        array(
88          $_POST['start_year'],
89          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
90          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
91          )
92        ),
93      'inc' => true,
94      );
95  }
96
97  if (!empty($_POST['end_year']))
98  {
99    $search['fields'][$type_date.'-before'] = array(
100      'date' => join(
101        '-',
102        array(
103          $_POST['end_year'],
104          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
105          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
106          )
107        ),
108      'inc' => true,
109      );
110  }
111 
112  if (!empty($search))
113  {
114    // default search mode : each clause must be respected
115    $search['mode'] = 'AND';
116
117    // register search rules in database, then they will be available on
118    // thumbnails page and picture page.
119    $query ='
120INSERT INTO '.SEARCH_TABLE.'
121  (rules)
122  VALUES
123  (\''.serialize($search).'\')
124;';
125    pwg_query($query);
126
127    $search_id = mysql_insert_id();
128  }
129  else
130  {
131    array_push($errors, $lang['search_one_clause_at_least']);
132  }
133}
134//----------------------------------------------------------------- redirection
135if (isset($_POST['submit']) and count($errors) == 0)
136{
137  $url = 'category.php?cat=search&search='.$search_id;
138  redirect($url);
139}
140//----------------------------------------------------- template initialization
141
142// start date
143get_day_list('start_day', @$_POST['start_day']);
144get_month_list('start_month', @$_POST['start_month']);
145// end date
146get_day_list('end_day', @$_POST['end_day']);
147get_month_list('end_month', @$_POST['end_month']);
148
149//
150// Start output of page
151//
152$title= $lang['search_title'];
153$page['body_id'] = 'theSearchPage';
154include(PHPWG_ROOT_PATH.'include/page_header.php');
155
156$template->set_filenames( array('search'=>'search.tpl') );
157$template->assign_vars(array(
158  'L_SEARCH_TITLE' => $lang['search_title'],
159  'L_SEARCH_OPTIONS' => $lang['search_options'],
160  'L_RETURN' => $lang['home'],
161  'L_SUBMIT' => $lang['submit'],
162  'L_RESET' => $lang['reset'],
163  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
164  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
165  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
166  'L_SEARCH_AUTHOR'=>$lang['search_author'],
167  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
168  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
169  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
170  'L_YES' => $lang['yes'],
171  'L_NO' => $lang['no'],
172  'L_SEARCH_DATE' => $lang['search_date'],
173  'L_TODAY' => $lang['today'],
174  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
175  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
176  'L_DAYS'=>$lang['days'],
177  'L_MONTH'=>$lang['w_month'],
178  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
179  'L_SEARCH_CREATION'=>$lang['search_date_creation'],
180  'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'],
181  'L_RESULT_SORT'=>$lang['search_sort'],
182  'L_SORT_ASCENDING'=>$lang['search_ascending'],
183  'L_SORT_DESCENDING'=>$lang['search_descending'],
184 
185  'TODAY_DAY' => date('d', time()),
186  'TODAY_MONTH' => date('m', time()),
187  'TODAY_YEAR' => date('Y', time()),
188  'S_SEARCH_ACTION' => 'search.php',
189  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
190  'U_HOME' => 'category.php'
191  )
192);
193
194//------------------------------------------------------------- categories form
195$query = '
196SELECT name,id,date_last,nb_images,global_rank,uppercats
197  FROM '.CATEGORIES_TABLE;
198if ($user['forbidden_categories'] != '')
199{
200  $query.= '
201  WHERE id NOT IN ('.$user['forbidden_categories'].')';
202}
203$query.= '
204;';
205
206$selecteds = array();
207display_select_cat_wrapper($query, $selecteds, 'category_option', false);
208
209//-------------------------------------------------------------- errors display
210if (sizeof($errors) != 0)
211{
212  $template->assign_block_vars('errors',array());
213  foreach ($errors as $error)
214  {
215    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
216  }
217}
218//------------------------------------------------------------ log informations
219pwg_log( 'search', $title );
220$template->parse('search');
221include(PHPWG_ROOT_PATH.'include/page_tail.php');
222?>
Note: See TracBrowser for help on using the repository browser.