source: branches/branch-1_6/search_rules.php @ 1134

Last change on this file since 1134 was 1119, checked in by plg, 19 years ago

improvement: tags replace keywords. Better data model, less
limitations. Each image can be associated to as many tag as needed. Tags can
contain non ASCII characters. Oriented navigation with tags by association.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: search_rules.php 1119 2006-04-02 22:26:19Z plg $
9// | last update   : $Date: 2006-04-02 22:26:19 +0000 (Sun, 02 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1119 $
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 */
35function inc_exc_str($is_included)
36{
37  return $is_included ? l10n('included') : l10n('excluded');
38}
39
40// +-----------------------------------------------------------------------+
41// |                           initialization                              |
42// +-----------------------------------------------------------------------+
43
44define('PHPWG_ROOT_PATH','./');
45include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
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>';
51include(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$template->assign_vars(
65  array(
66    'INTRODUCTION'
67      => 'OR' == $search['mode']
68      ? l10n('At least one listed rule must be satisfied.')
69      : l10n('Each listed rule must be satisfied.'),
70    )
71  );
72
73if (isset($search['fields']['allwords']))
74{
75  $template->assign_block_vars(
76    'words',
77    array(
78      'CONTENT' => sprintf(
79        l10n('searched words : %s'),
80        join(', ', $search['fields']['allwords']['words'])
81        )
82      )
83    );
84}
85
86if (isset($search['fields']['tags']))
87{
88  $template->assign_block_vars(
89    'tags',
90    array(
91      'LIST_INTRO' => ($search['fields']['tags']['mode'] == 'AND')
92        ? l10n('All tags must match')
93        : l10n('At least one tag must match')
94      )
95    );
96
97  $query = '
98SELECT name
99  FROM '.TAGS_TABLE.'
100  WHERE id IN ('.implode(',', $search['fields']['tags']['words']).')
101;';
102  $result = pwg_query($query);
103  while ($row = mysql_fetch_array($result))
104  {
105    $template->assign_block_vars(
106      'tags.tag',
107      array(
108        'NAME' => $row['name'],
109        )
110      );
111  }
112}
113
114if (isset($search['fields']['author']))
115{
116  $template->assign_block_vars(
117    'words',
118    array(
119      'CONTENT' => sprintf(
120          l10n('author(s) : %s'),
121          join(', ', $search['fields']['author']['words'])
122        )
123      )
124    );
125}
126
127if (isset($search['fields']['cat']))
128{
129  if ($search['fields']['cat']['sub_inc'])
130  {
131    // searching all the categories id of sub-categories
132    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
133  }
134  else
135  {
136    $cat_ids = $search['fields']['cat']['words'];
137  }
138
139  $template->assign_block_vars(
140    'categories',
141    array(
142      'LIST_INTRO' => l10n('Categories'),
143      )
144    );
145
146  $query = '
147SELECT id, uppercats, global_rank
148  FROM '.CATEGORIES_TABLE.'
149  WHERE id IN ('.
150    implode(',', $cat_ids).
151    ')
152;';
153  $result = pwg_query($query);
154
155  $categories = array();
156  if (!empty($result))
157  {
158    while ($row = mysql_fetch_array($result))
159    {
160      array_push($categories, $row);
161    }
162  }
163  usort($categories, 'global_rank_compare');
164
165  foreach ($categories as $category)
166  {
167    $template->assign_block_vars(
168      'categories.category',
169      array(
170        'NAME' => get_cat_display_name_cache(
171          $category['uppercats'],
172          null,                      // no url on category names
173          false                    // no blank replacement
174          )
175        )
176      );
177  }
178}
179
180foreach (array('date_available', 'date_creation') as $datefield)
181{
182  if ('date_available' == $datefield)
183  {
184    $lang_items = array(
185      'date'   => 'became available on %s',
186      'period' => 'became available between %s (%s) and %s (%s)',
187      'after'  => 'became available after %s (%s)',
188      'before' => 'became available before %s (%s)',
189      );
190  }
191  elseif ('date_creation' == $datefield)
192  {
193    $lang_items = array(
194      'date'   => 'created on %s',
195      'period' => 'created between %s (%s) and %s (%s)',
196      'after'  => 'created after %s (%s)',
197      'before' => 'created before %s (%s)',
198      );
199  }
200
201  $keys = array(
202    'date'   => $datefield,
203    'after'  => $datefield.'-after',
204    'before' => $datefield.'-before',
205    );
206
207  if (isset($search['fields'][ $keys['date'] ]))
208  {
209    $template->assign_block_vars(
210      $datefield,
211      array(
212        'CONTENT' => sprintf(
213          l10n($lang_items['date']),
214          format_date($search['fields'][ $keys['date'] ])
215          ),
216        )
217      );
218  }
219  elseif (isset($search['fields'][ $keys['before'] ])
220          and isset($search['fields'][ $keys['after'] ]))
221  {
222    $template->assign_block_vars(
223      $datefield,
224      array(
225        'CONTENT' => sprintf(
226          l10n($lang_items['period']),
227
228          format_date($search['fields'][ $keys['after'] ]['date']),
229          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
230
231          format_date($search['fields'][ $keys['before'] ]['date']),
232          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
233          ),
234        )
235      );
236  }
237  elseif (isset($search['fields'][ $keys['before'] ]))
238  {
239    $template->assign_block_vars(
240      $datefield,
241      array(
242        'CONTENT' => sprintf(
243          l10n($lang_items['before']),
244
245          format_date($search['fields'][ $keys['before'] ]['date']),
246          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
247          ),
248        )
249      );
250  }
251  elseif (isset($search['fields'][ $keys['after'] ]))
252  {
253    $template->assign_block_vars(
254      $datefield,
255      array(
256        'CONTENT' => sprintf(
257          l10n($lang_items['after']),
258
259          format_date($search['fields'][ $keys['after'] ]['date']),
260          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
261          )
262        )
263      );
264  }
265}
266
267// +-----------------------------------------------------------------------+
268// |                           html code display                           |
269// +-----------------------------------------------------------------------+
270
271$template->parse('search_rules');
272include(PHPWG_ROOT_PATH.'include/page_tail.php');
273?>
Note: See TracBrowser for help on using the repository browser.