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-11-25 14:12:33 +0000 (Thu, 25 Nov 2004) $ |
---|
10 | // | last modifier : $Author: gweltas $ |
---|
11 | // | revision : $Revision: 621 $ |
---|
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 |
---|
29 | define('PHPWG_ROOT_PATH','./'); |
---|
30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
31 | //-------------------------------------------------- access authorization check |
---|
32 | check_login_authorization(); |
---|
33 | //------------------------------------------------------------------ form check |
---|
34 | $errors = array(); |
---|
35 | $search = array(); |
---|
36 | if (isset($_POST['submit'])) |
---|
37 | { |
---|
38 | if ($_POST['search_keywords'] && |
---|
39 | !preg_match('/^\s*$/', $_POST['search_keywords'])) |
---|
40 | { |
---|
41 | $local_search = array(); |
---|
42 | $search_keywords = $_POST['search_keywords']; |
---|
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']['keywords'] = array(); |
---|
55 | $search['fields']['keywords']['words'] =$words; |
---|
56 | $search['fields']['keywords']['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['duration_day']) ) |
---|
86 | { |
---|
87 | $search['fields'][$type_date]['mode'] = $_POST['duration_day']; |
---|
88 | } |
---|
89 | } |
---|
90 | // search string (for URL) creation |
---|
91 | $search_string = ''; |
---|
92 | $tokens = array(); |
---|
93 | if (!empty($search)) |
---|
94 | { |
---|
95 | foreach (array_keys($search['fields']) as $field) |
---|
96 | { |
---|
97 | $token = $field.':'; |
---|
98 | $token.= implode(',', $search['fields'][$field]['words']); |
---|
99 | if (isset($search['fields'][$field]['mode'])) |
---|
100 | { |
---|
101 | $token.= '~'.$search['fields'][$field]['mode']; |
---|
102 | } |
---|
103 | array_push($tokens, $token); |
---|
104 | } |
---|
105 | $search_string.= implode(';', $tokens); |
---|
106 | if (count($tokens) > 1) |
---|
107 | { |
---|
108 | $search_string.= '|AND'; |
---|
109 | } |
---|
110 | } |
---|
111 | else |
---|
112 | { |
---|
113 | array_push($errors, $lang['search_one_clause_at_least']); |
---|
114 | } |
---|
115 | } |
---|
116 | //----------------------------------------------------------------- redirection |
---|
117 | if (isset($_POST['submit']) and count($errors) == 0) |
---|
118 | { |
---|
119 | $url = 'category.php?cat=search&search='.$search_string; |
---|
120 | $url = add_session_id($url, true); |
---|
121 | redirect($url); |
---|
122 | } |
---|
123 | |
---|
124 | //----------------------------------------------------- template initialization |
---|
125 | // day list |
---|
126 | $start_day = '<select name="start_day">'; |
---|
127 | for ($i=0; $i <= 31; $i++) |
---|
128 | { |
---|
129 | $start_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; |
---|
130 | } |
---|
131 | $start_day .= '</select>'; |
---|
132 | |
---|
133 | // month list |
---|
134 | $start_month = '<select name="start_month">'; |
---|
135 | $start_month .= '<option value="0"> ------------ </option>'; |
---|
136 | for ($i=1; $i <= 12; $i++) |
---|
137 | { |
---|
138 | $start_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; |
---|
139 | } |
---|
140 | $start_month .= '</select>'; |
---|
141 | |
---|
142 | // year list |
---|
143 | $start_year = '<select name="start_year">'; |
---|
144 | $start_year .= '<option value="0"> ---- </option>'; |
---|
145 | $begin_year = date('Y', time())-10; |
---|
146 | for ($i = $begin_year; $i <= date('Y', time()); $i++) |
---|
147 | { |
---|
148 | $start_year .= '<option value="' . $i . '">' . $i . '</option>'; |
---|
149 | } |
---|
150 | $start_year .= '</select>'; |
---|
151 | |
---|
152 | |
---|
153 | // |
---|
154 | // Start output of page |
---|
155 | // |
---|
156 | $title= $lang['search_title']; |
---|
157 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
158 | |
---|
159 | $template->set_filenames( array('search'=>'search.tpl') ); |
---|
160 | $template->assign_vars(array( |
---|
161 | 'L_SEARCH_TITLE' => $lang['search_title'], |
---|
162 | 'L_SEARCH_OPTIONS' => $lang['search_options'], |
---|
163 | 'L_RETURN' => $lang['home'], |
---|
164 | 'L_SUBMIT' => $lang['submit'], |
---|
165 | 'L_RESET' => $lang['reset'], |
---|
166 | 'L_SEARCH_KEYWORDS'=>$lang['search_keywords'], |
---|
167 | 'L_SEARCH_KEYWORDS_HINT'=>$lang['search_keywords_hint'], |
---|
168 | 'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'], |
---|
169 | 'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'], |
---|
170 | 'L_SEARCH_AUTHOR'=>$lang['search_author'], |
---|
171 | 'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'], |
---|
172 | 'L_SEARCH_CATEGORIES'=>$lang['search_categories'], |
---|
173 | 'L_SEARCH_CATEGORIES_HINT'=>$lang['search_categories_hint'], |
---|
174 | 'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'], |
---|
175 | 'L_YES' => $lang['yes'], |
---|
176 | 'L_NO' => $lang['no'], |
---|
177 | 'L_SEARCH_DATE' => $lang['search_date'], |
---|
178 | 'L_SEARCH_DATE_HINT' => $lang['search_date_hint'], |
---|
179 | 'L_TODAY' => $lang['today'], |
---|
180 | 'L_SEARCH_DATE_FROM'=>$lang['search_date_from'], |
---|
181 | 'L_SEARCH_DURATION'=>$lang['search_duration'], |
---|
182 | 'L_DAYS'=>$lang['days'], |
---|
183 | 'L_MONTH'=>$lang['w_month'], |
---|
184 | 'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'], |
---|
185 | 'L_SEARCH_CREATION'=>$lang['search_date_creation'], |
---|
186 | 'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'], |
---|
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_CALENDAR_YEAR' => $start_year, |
---|
195 | 'S_CALENDAR_MONTH' => $start_month, |
---|
196 | 'S_CALENDAR_DAY' => $start_day, |
---|
197 | 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), |
---|
198 | 'U_HOME' => add_session_id( 'category.php' ) |
---|
199 | ) |
---|
200 | ); |
---|
201 | |
---|
202 | //------------------------------------------------------------- categories form |
---|
203 | $query = ' |
---|
204 | SELECT name,id,date_last,nb_images,global_rank,uppercats |
---|
205 | FROM '.CATEGORIES_TABLE; |
---|
206 | if ($user['forbidden_categories'] != '') |
---|
207 | { |
---|
208 | $query.= ' |
---|
209 | WHERE id NOT IN ('.$user['forbidden_categories'].')'; |
---|
210 | } |
---|
211 | $query.= ' |
---|
212 | ;'; |
---|
213 | |
---|
214 | $selecteds = array(); |
---|
215 | display_select_cat_wrapper($query, $selecteds, 'category_option', false); |
---|
216 | |
---|
217 | //-------------------------------------------------------------- errors display |
---|
218 | if (sizeof($errors) != 0) |
---|
219 | { |
---|
220 | $template->assign_block_vars('errors',array()); |
---|
221 | foreach ($errors as $error) |
---|
222 | { |
---|
223 | $template->assign_block_vars('errors.error',array('ERROR'=>$error)); |
---|
224 | } |
---|
225 | } |
---|
226 | //------------------------------------------------------------ log informations |
---|
227 | pwg_log( 'search', $title ); |
---|
228 | mysql_close(); |
---|
229 | $template->pparse('search'); |
---|
230 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
231 | ?> |
---|