source: trunk/search_rules.php @ 2297

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23// +-----------------------------------------------------------------------+
24// | PhpWebGallery - a PHP based picture gallery                           |
25// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
26// | Copyright (C) 2003-2008 PhpWebGallery Team - http://phpwebgallery.net |
27// +-----------------------------------------------------------------------+
28// | file          : $Id: search_rules.php 2297 2008-04-04 22:57:23Z plg $
29// | last update   : $Date: 2008-04-04 22:57:23 +0000 (Fri, 04 Apr 2008) $
30// | last modifier : $Author: plg $
31// | revision      : $Revision: 2297 $
32// +-----------------------------------------------------------------------+
33// | This program is free software; you can redistribute it and/or modify  |
34// | it under the terms of the GNU General Public License as published by  |
35// | the Free Software Foundation                                          |
36// |                                                                       |
37// | This program is distributed in the hope that it will be useful, but   |
38// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
39// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
40// | General Public License for more details.                              |
41// |                                                                       |
42// | You should have received a copy of the GNU General Public License     |
43// | along with this program; if not, write to the Free Software           |
44// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
45// | USA.                                                                  |
46// +-----------------------------------------------------------------------+
47
48/**
49 * returns language value 'included' or 'excluded' depending on boolean
50 * value. This function is useful only to make duplicate code shorter
51 *
52 * @param bool is_included
53 * @return string
54 */
55function inc_exc_str($is_included)
56{
57  return $is_included ? l10n('included') : l10n('excluded');
58}
59
60// +-----------------------------------------------------------------------+
61// |                           initialization                              |
62// +-----------------------------------------------------------------------+
63
64define('PHPWG_ROOT_PATH','./');
65include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
66check_status(ACCESS_NONE);
67include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' );
68
69$page['body_id'] = 'thePopuphelpPage';
70$title = l10n('PhpWebGallery Help');
71$page['page_banner'] = '<h1>'.$title.'</h1>';
72$page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
73include(PHPWG_ROOT_PATH.'include/page_header.php');
74
75$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
76
77// +-----------------------------------------------------------------------+
78// |                        Textual rules creation                         |
79// +-----------------------------------------------------------------------+
80
81// Rules are stored in database, serialized in an array. This array must be
82// transformed into a list of textual rules.
83
84$search = get_search_array($_GET['search_id']);
85
86if (isset($search['q']))
87{
88  $template->append( 'search_words', $search['q'] );
89}
90else
91{
92  $template->assign(
93    array(
94      'INTRODUCTION'
95        => 'OR' == $search['mode']
96        ? l10n('At least one listed rule must be satisfied.')
97        : l10n('Each listed rule must be satisfied.'),
98      )
99    );
100}
101
102if (isset($search['fields']['allwords']))
103{
104  $template->append( 'search_words',
105      sprintf(
106        l10n('searched words : %s'),
107        join(', ', $search['fields']['allwords']['words'])
108        )
109      );
110}
111
112if (isset($search['fields']['tags']))
113{
114  $template->assign('SEARCH_TAGS_MODE', $search['fields']['tags']['mode']);
115 
116  $query = '
117SELECT name
118  FROM '.TAGS_TABLE.'
119  WHERE id IN ('.implode(',', $search['fields']['tags']['words']).')
120;';
121  $template->assign(
122      'search_tags',
123      array_from_query($query, 'name')
124    );
125}
126
127if (isset($search['fields']['author']))
128{
129  $template->append(
130    'search_words',
131     sprintf(
132          l10n('author(s) : %s'),
133          join(', ', $search['fields']['author']['words'])
134        )
135      );
136}
137
138if (isset($search['fields']['cat']))
139{
140  if ($search['fields']['cat']['sub_inc'])
141  {
142    // searching all the categories id of sub-categories
143    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
144  }
145  else
146  {
147    $cat_ids = $search['fields']['cat']['words'];
148  }
149
150  $query = '
151SELECT id, uppercats, global_rank
152  FROM '.CATEGORIES_TABLE.'
153  WHERE id IN ('.
154    implode(',', $cat_ids).
155    ')
156;';
157  $result = pwg_query($query);
158
159  $categories = array();
160  if (!empty($result))
161  {
162    while ($row = mysql_fetch_array($result))
163    {
164      array_push($categories, $row);
165    }
166  }
167  usort($categories, 'global_rank_compare');
168
169  foreach ($categories as $category)
170  {
171    $template->append(
172      'search_categories',
173      get_cat_display_name_cache(
174          $category['uppercats'],
175          null,                      // no url on category names
176          false                    // no blank replacement
177          )
178      );
179  }
180}
181
182foreach (array('date_available', 'date_creation') as $datefield)
183{
184  if ('date_available' == $datefield)
185  {
186    $lang_items = array(
187      'date'   => 'became available on %s',
188      'period' => 'became available between %s (%s) and %s (%s)',
189      'after'  => 'became available after %s (%s)',
190      'before' => 'became available before %s (%s)',
191      );
192  }
193  elseif ('date_creation' == $datefield)
194  {
195    $lang_items = array(
196      'date'   => 'created on %s',
197      'period' => 'created between %s (%s) and %s (%s)',
198      'after'  => 'created after %s (%s)',
199      'before' => 'created before %s (%s)',
200      );
201  }
202
203  $keys = array(
204    'date'   => $datefield,
205    'after'  => $datefield.'-after',
206    'before' => $datefield.'-before',
207    );
208
209  if (isset($search['fields'][ $keys['date'] ]))
210  {
211    $template->assign(
212      strtoupper($datefield),
213      sprintf(
214          l10n($lang_items['date']),
215          format_date($search['fields'][ $keys['date'] ])
216          )
217      );
218  }
219  elseif (isset($search['fields'][ $keys['before'] ])
220          and isset($search['fields'][ $keys['after'] ]))
221  {
222    $template->assign(
223      strtoupper($datefield),
224      sprintf(
225          l10n($lang_items['period']),
226
227          format_date($search['fields'][ $keys['after'] ]['date']),
228          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
229
230          format_date($search['fields'][ $keys['before'] ]['date']),
231          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
232          )
233      );
234  }
235  elseif (isset($search['fields'][ $keys['before'] ]))
236  {
237    $template->assign(
238      strtoupper($datefield),
239      sprintf(
240          l10n($lang_items['before']),
241
242          format_date($search['fields'][ $keys['before'] ]['date']),
243          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
244          )
245      );
246  }
247  elseif (isset($search['fields'][ $keys['after'] ]))
248  {
249    $template->assign(
250      strtoupper($datefield),
251      sprintf(
252          l10n($lang_items['after']),
253
254          format_date($search['fields'][ $keys['after'] ]['date']),
255          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
256          )
257      );
258  }
259}
260
261// +-----------------------------------------------------------------------+
262// |                           html code display                           |
263// +-----------------------------------------------------------------------+
264
265$template->pparse('search_rules');
266include(PHPWG_ROOT_PATH.'include/page_tail.php');
267?>
Note: See TracBrowser for help on using the repository browser.