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