source: trunk/search_rules.php @ 2223

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