source: trunk/search.php @ 629

Last change on this file since 629 was 629, checked in by gweltas, 19 years ago

Search form update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-12-02 12:45:57 +0000 (Thu, 02 Dec 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 629 $
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 ($_POST['search_allwords'] &&
39   !preg_match('/^\s*$/', $_POST['search_allwords']))
40  {
41    $local_search = array();
42        $search_keywords = $_POST['search_allwords'];
43        $drop_char_match =   array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>',
44          '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', 
45          ':', '\\', '/', '=', '\'', '!', '*');
46        $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
47          '',  '',   ' ', ' ', ' ', ' ', '',  ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
48          , ' ', '' ,  ' ', ' ', ' ',  ' ', ' ');
49        $search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords);
50       
51        // Split words
52        $words = preg_split('#\s+#', $search_keywords);
53    $words = array_unique($words);
54        $search['fields']['allwords'] = array();
55        $search['fields']['allwords']['words'] =$words;
56        $search['fields']['allwords']['mode']= $_POST['mode'];
57  }
58 
59  if ($_POST['search_author'])
60  {
61    $search['fields']['author'] = array();
62    $search['fields']['author']['words'] = array($_POST['search_author']);
63  }
64 
65  if (isset($_POST['cat']))
66  {
67    $search['fields']['cat'] = array();
68    $search['fields']['cat']['words'] = $_POST['cat'];
69    if (isset($_POST['subcats-included']))
70    {
71      $search['fields']['cat']['mode'] = 'sub_inc';
72    }
73  }
74 
75  if (!empty($_POST['start_year']))
76 {
77  $type_date = $_POST['date_type'];
78
79  // start event
80  $date = $_POST['start_year'].'.'.$_POST['start_month'].'.'.$_POST['start_day'];
81  $search['fields'][$type_date]['words'] = array($date);
82 
83  // duration
84  $search_duration = 0;
85  if ( !empty($date) && !empty( $_POST['end_year']) )
86  {
87        $end_date = $_POST['end_year'].'.'.$_POST['end_month'].'.'.$_POST['end_day'];
88        $search['fields'][$type_date]['mode'] =  $end_date;
89  }
90 }
91  // search string (for URL) creation
92  $search_string = '';
93  $tokens = array();
94  if (!empty($search))
95  {
96  foreach (array_keys($search['fields']) as $field)
97  {
98    $token = $field.':';
99    $token.= implode(',', $search['fields'][$field]['words']);
100    if (isset($search['fields'][$field]['mode']))
101    {
102      $token.= '~'.$search['fields'][$field]['mode'];
103    }
104    array_push($tokens, $token);
105  }
106  $search_string.= implode(';', $tokens);
107  if (count($tokens) > 1)
108  {
109    $search_string.= '|AND';
110  }
111  }
112  else
113  {
114    array_push($errors, $lang['search_one_clause_at_least']);
115  }
116}
117//----------------------------------------------------------------- redirection
118if (isset($_POST['submit']) and count($errors) == 0)
119{
120  $url = 'category.php?cat=search&search='.$search_string;
121  $url = add_session_id($url, true);
122  redirect($url);
123}
124
125//----------------------------------------------------- template initialization
126// day list
127$start_day = '<select name="start_day">';
128for ($i=0; $i <= 31; $i++)
129{
130        $start_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>';
131}
132$start_day .= '</select>';
133
134// month list
135$start_month = '<select name="start_month">';
136$start_month .= '<option value="0"> ------------ </option>';
137for ($i=1; $i <= 12; $i++)
138{
139        $start_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>';
140}
141$start_month .= '</select>';
142
143// day list
144$end_day = '<select name="end_day">';
145for ($i=0; $i <= 31; $i++)
146{
147        $end_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>';
148}
149$end_day .= '</select>';
150
151// month list
152$end_month = '<select name="end_month">';
153$end_month .= '<option value="0"> ------------ </option>';
154for ($i=1; $i <= 12; $i++)
155{
156        $end_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>';
157}
158$end_month .= '</select>';
159
160//
161// Start output of page
162//
163$title= $lang['search_title'];
164include(PHPWG_ROOT_PATH.'include/page_header.php');
165
166$template->set_filenames( array('search'=>'search.tpl') );
167$template->assign_vars(array(
168  'L_SEARCH_TITLE' => $lang['search_title'],
169  'L_SEARCH_OPTIONS' => $lang['search_options'],
170  'L_RETURN' => $lang['home'],
171  'L_SUBMIT' => $lang['submit'],
172  'L_RESET' => $lang['reset'],
173  'L_SEARCH_KEYWORDS'=>$lang['search_keywords'],
174  'L_SEARCH_KEYWORDS_HINT'=>$lang['search_keywords_hint'],
175  'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'],
176  'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'],
177  'L_SEARCH_AUTHOR'=>$lang['search_author'],
178  'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'],
179  'L_SEARCH_CATEGORIES'=>$lang['search_categories'],
180  'L_SEARCH_CATEGORIES_HINT'=>$lang['search_categories_hint'],
181  'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'],
182  'L_YES' => $lang['yes'],
183  'L_NO' => $lang['no'],
184  'L_SEARCH_DATE' => $lang['search_date'],
185  'L_SEARCH_DATE_HINT' => $lang['search_date_hint'],
186  'L_TODAY' => $lang['today'],
187  'L_SEARCH_DATE_FROM'=>$lang['search_date_from'],
188  'L_SEARCH_DATE_TO'=>$lang['search_date_to'],
189  'L_DAYS'=>$lang['days'],
190  'L_MONTH'=>$lang['w_month'],
191  'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'],
192  'L_SEARCH_CREATION'=>$lang['search_date_creation'],
193  'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'],
194  'L_RESULT_SORT'=>$lang['search_sort'],
195  'L_SORT_ASCENDING'=>$lang['search_ascending'],
196  'L_SORT_DESCENDING'=>$lang['search_descending'],
197 
198  'TODAY_DAY' => date('d', time()),
199  'TODAY_MONTH' => date('m', time()),
200  'TODAY_YEAR' => date('Y', time()),
201  'E_CALENDAR_MONTH' => $end_month,
202        'E_CALENDAR_DAY' => $end_day,
203  'S_CALENDAR_MONTH' => $start_month,
204  'S_CALENDAR_DAY' => $start_day,
205  'S_SEARCH_ACTION' => add_session_id( 'search.php' ),   
206  'U_HOME' => add_session_id( 'category.php' )
207  )
208);
209
210//------------------------------------------------------------- categories form
211$query = '
212SELECT name,id,date_last,nb_images,global_rank,uppercats
213  FROM '.CATEGORIES_TABLE;
214  if ($user['forbidden_categories'] != '')
215  {
216    $query.= '
217  WHERE id NOT IN ('.$user['forbidden_categories'].')';
218  }
219$query.= '
220;';
221
222$selecteds = array();
223display_select_cat_wrapper($query, $selecteds, 'category_option', false);
224
225//-------------------------------------------------------------- errors display
226if (sizeof($errors) != 0)
227{
228  $template->assign_block_vars('errors',array());
229  foreach ($errors as $error)
230  {
231    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
232  }
233}
234//------------------------------------------------------------ log informations
235pwg_log( 'search', $title );
236mysql_close();
237$template->pparse('search');
238include(PHPWG_ROOT_PATH.'include/page_tail.php');
239?>
Note: See TracBrowser for help on using the repository browser.