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 : $Id: search_rules.php 1537 2006-08-15 02:06:06Z rvelices $ |
---|
9 | // | last update : $Date: 2006-08-15 02:06:06 +0000 (Tue, 15 Aug 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1537 $ |
---|
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 | /** |
---|
29 | * returns language value 'included' or 'excluded' depending on boolean |
---|
30 | * value. This function is useful only to make duplicate code shorter |
---|
31 | * |
---|
32 | * @param bool is_included |
---|
33 | * @return string |
---|
34 | */ |
---|
35 | function inc_exc_str($is_included) |
---|
36 | { |
---|
37 | return $is_included ? l10n('included') : l10n('excluded'); |
---|
38 | } |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | initialization | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | |
---|
44 | define('PHPWG_ROOT_PATH','./'); |
---|
45 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
46 | include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' ); |
---|
47 | |
---|
48 | $page['body_id'] = 'thePopuphelpPage'; |
---|
49 | $title = l10n('PhpWebGallery Help'); |
---|
50 | $page['page_banner'] = '<h1>'.$title.'</h1>'; |
---|
51 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
52 | |
---|
53 | $template->set_filenames(array('search_rules' => 'search_rules.tpl')); |
---|
54 | |
---|
55 | // +-----------------------------------------------------------------------+ |
---|
56 | // | Textual rules creation | |
---|
57 | // +-----------------------------------------------------------------------+ |
---|
58 | |
---|
59 | // Rules are stored in database, serialized in an array. This array must be |
---|
60 | // transformed into a list of textual rules. |
---|
61 | |
---|
62 | $search = get_search_array($_GET['search_id']); |
---|
63 | |
---|
64 | if (isset($search['q'])) |
---|
65 | { |
---|
66 | $template->assign_block_vars( |
---|
67 | 'words', |
---|
68 | array( |
---|
69 | 'CONTENT' => $search['q'] |
---|
70 | ) |
---|
71 | ); |
---|
72 | } |
---|
73 | else |
---|
74 | { |
---|
75 | $template->assign_vars( |
---|
76 | array( |
---|
77 | 'INTRODUCTION' |
---|
78 | => 'OR' == $search['mode'] |
---|
79 | ? l10n('At least one listed rule must be satisfied.') |
---|
80 | : l10n('Each listed rule must be satisfied.'), |
---|
81 | ) |
---|
82 | ); |
---|
83 | } |
---|
84 | |
---|
85 | if (isset($search['fields']['allwords'])) |
---|
86 | { |
---|
87 | $template->assign_block_vars( |
---|
88 | 'words', |
---|
89 | array( |
---|
90 | 'CONTENT' => sprintf( |
---|
91 | l10n('searched words : %s'), |
---|
92 | join(', ', $search['fields']['allwords']['words']) |
---|
93 | ) |
---|
94 | ) |
---|
95 | ); |
---|
96 | } |
---|
97 | |
---|
98 | if (isset($search['fields']['tags'])) |
---|
99 | { |
---|
100 | $template->assign_block_vars( |
---|
101 | 'tags', |
---|
102 | array( |
---|
103 | 'LIST_INTRO' => ($search['fields']['tags']['mode'] == 'AND') |
---|
104 | ? l10n('All tags must match') |
---|
105 | : l10n('At least one tag must match') |
---|
106 | ) |
---|
107 | ); |
---|
108 | |
---|
109 | $query = ' |
---|
110 | SELECT name |
---|
111 | FROM '.TAGS_TABLE.' |
---|
112 | WHERE id IN ('.implode(',', $search['fields']['tags']['words']).') |
---|
113 | ;'; |
---|
114 | $result = pwg_query($query); |
---|
115 | while ($row = mysql_fetch_array($result)) |
---|
116 | { |
---|
117 | $template->assign_block_vars( |
---|
118 | 'tags.tag', |
---|
119 | array( |
---|
120 | 'NAME' => $row['name'], |
---|
121 | ) |
---|
122 | ); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | if (isset($search['fields']['author'])) |
---|
127 | { |
---|
128 | $template->assign_block_vars( |
---|
129 | 'words', |
---|
130 | array( |
---|
131 | 'CONTENT' => sprintf( |
---|
132 | l10n('author(s) : %s'), |
---|
133 | join(', ', $search['fields']['author']['words']) |
---|
134 | ) |
---|
135 | ) |
---|
136 | ); |
---|
137 | } |
---|
138 | |
---|
139 | if (isset($search['fields']['cat'])) |
---|
140 | { |
---|
141 | if ($search['fields']['cat']['sub_inc']) |
---|
142 | { |
---|
143 | // searching all the categories id of sub-categories |
---|
144 | $cat_ids = get_subcat_ids($search['fields']['cat']['words']); |
---|
145 | } |
---|
146 | else |
---|
147 | { |
---|
148 | $cat_ids = $search['fields']['cat']['words']; |
---|
149 | } |
---|
150 | |
---|
151 | $template->assign_block_vars( |
---|
152 | 'categories', |
---|
153 | array( |
---|
154 | 'LIST_INTRO' => l10n('Categories'), |
---|
155 | ) |
---|
156 | ); |
---|
157 | |
---|
158 | $query = ' |
---|
159 | SELECT id, uppercats, global_rank |
---|
160 | FROM '.CATEGORIES_TABLE.' |
---|
161 | WHERE id IN ('. |
---|
162 | implode(',', $cat_ids). |
---|
163 | ') |
---|
164 | ;'; |
---|
165 | $result = pwg_query($query); |
---|
166 | |
---|
167 | $categories = array(); |
---|
168 | if (!empty($result)) |
---|
169 | { |
---|
170 | while ($row = mysql_fetch_array($result)) |
---|
171 | { |
---|
172 | array_push($categories, $row); |
---|
173 | } |
---|
174 | } |
---|
175 | usort($categories, 'global_rank_compare'); |
---|
176 | |
---|
177 | foreach ($categories as $category) |
---|
178 | { |
---|
179 | $template->assign_block_vars( |
---|
180 | 'categories.category', |
---|
181 | array( |
---|
182 | 'NAME' => get_cat_display_name_cache( |
---|
183 | $category['uppercats'], |
---|
184 | null, // no url on category names |
---|
185 | false // no blank replacement |
---|
186 | ) |
---|
187 | ) |
---|
188 | ); |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | foreach (array('date_available', 'date_creation') as $datefield) |
---|
193 | { |
---|
194 | if ('date_available' == $datefield) |
---|
195 | { |
---|
196 | $lang_items = array( |
---|
197 | 'date' => 'became available on %s', |
---|
198 | 'period' => 'became available between %s (%s) and %s (%s)', |
---|
199 | 'after' => 'became available after %s (%s)', |
---|
200 | 'before' => 'became available before %s (%s)', |
---|
201 | ); |
---|
202 | } |
---|
203 | elseif ('date_creation' == $datefield) |
---|
204 | { |
---|
205 | $lang_items = array( |
---|
206 | 'date' => 'created on %s', |
---|
207 | 'period' => 'created between %s (%s) and %s (%s)', |
---|
208 | 'after' => 'created after %s (%s)', |
---|
209 | 'before' => 'created before %s (%s)', |
---|
210 | ); |
---|
211 | } |
---|
212 | |
---|
213 | $keys = array( |
---|
214 | 'date' => $datefield, |
---|
215 | 'after' => $datefield.'-after', |
---|
216 | 'before' => $datefield.'-before', |
---|
217 | ); |
---|
218 | |
---|
219 | if (isset($search['fields'][ $keys['date'] ])) |
---|
220 | { |
---|
221 | $template->assign_block_vars( |
---|
222 | $datefield, |
---|
223 | array( |
---|
224 | 'CONTENT' => sprintf( |
---|
225 | l10n($lang_items['date']), |
---|
226 | format_date($search['fields'][ $keys['date'] ]) |
---|
227 | ), |
---|
228 | ) |
---|
229 | ); |
---|
230 | } |
---|
231 | elseif (isset($search['fields'][ $keys['before'] ]) |
---|
232 | and isset($search['fields'][ $keys['after'] ])) |
---|
233 | { |
---|
234 | $template->assign_block_vars( |
---|
235 | $datefield, |
---|
236 | array( |
---|
237 | 'CONTENT' => sprintf( |
---|
238 | l10n($lang_items['period']), |
---|
239 | |
---|
240 | format_date($search['fields'][ $keys['after'] ]['date']), |
---|
241 | inc_exc_str($search['fields'][ $keys['after'] ]['inc']), |
---|
242 | |
---|
243 | format_date($search['fields'][ $keys['before'] ]['date']), |
---|
244 | inc_exc_str($search['fields'][ $keys['before'] ]['inc']) |
---|
245 | ), |
---|
246 | ) |
---|
247 | ); |
---|
248 | } |
---|
249 | elseif (isset($search['fields'][ $keys['before'] ])) |
---|
250 | { |
---|
251 | $template->assign_block_vars( |
---|
252 | $datefield, |
---|
253 | array( |
---|
254 | 'CONTENT' => sprintf( |
---|
255 | l10n($lang_items['before']), |
---|
256 | |
---|
257 | format_date($search['fields'][ $keys['before'] ]['date']), |
---|
258 | inc_exc_str($search['fields'][ $keys['before'] ]['inc']) |
---|
259 | ), |
---|
260 | ) |
---|
261 | ); |
---|
262 | } |
---|
263 | elseif (isset($search['fields'][ $keys['after'] ])) |
---|
264 | { |
---|
265 | $template->assign_block_vars( |
---|
266 | $datefield, |
---|
267 | array( |
---|
268 | 'CONTENT' => sprintf( |
---|
269 | l10n($lang_items['after']), |
---|
270 | |
---|
271 | format_date($search['fields'][ $keys['after'] ]['date']), |
---|
272 | inc_exc_str($search['fields'][ $keys['after'] ]['inc']) |
---|
273 | ) |
---|
274 | ) |
---|
275 | ); |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | // +-----------------------------------------------------------------------+ |
---|
280 | // | html code display | |
---|
281 | // +-----------------------------------------------------------------------+ |
---|
282 | |
---|
283 | $template->parse('search_rules'); |
---|
284 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
285 | ?> |
---|