source: trunk/search_rules.php @ 4326

Last change on this file since 4326 was 4325, checked in by nikrou, 15 years ago

Feature 1244 resolved
Replace all mysql functions in core code by ones independant of database engine

Fix small php code synxtax : hash must be accessed with [ ] and not { }.

  • Property svn:eol-style set to LF
File size: 7.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 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/**
25 * returns language value 'included' or 'excluded' depending on boolean
26 * value. This function is useful only to make duplicate code shorter
27 *
28 * @param bool is_included
29 * @return string
30 */
31function inc_exc_str($is_included)
32{
33  return $is_included ? l10n('included') : l10n('excluded');
34}
35
36// +-----------------------------------------------------------------------+
37// |                           initialization                              |
38// +-----------------------------------------------------------------------+
39
40define('PHPWG_ROOT_PATH','./');
41include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
42check_status(ACCESS_FREE);
43include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' );
44
45$page['body_id'] = 'thePopuphelpPage';
46$title = l10n('Piwigo Help');
47$page['page_banner'] = '<h1>'.$title.'</h1>';
48$page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
49include(PHPWG_ROOT_PATH.'include/page_header.php');
50
51$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
52
53// +-----------------------------------------------------------------------+
54// |                        Textual rules creation                         |
55// +-----------------------------------------------------------------------+
56
57// Rules are stored in database, serialized in an array. This array must be
58// transformed into a list of textual rules.
59
60$search = get_search_array($_GET['search_id']);
61
62if (isset($search['q']))
63{
64  $template->append( 'search_words', $search['q'] );
65}
66else
67{
68  $template->assign(
69    array(
70      'INTRODUCTION'
71        => 'OR' == $search['mode']
72        ? l10n('At least one listed rule must be satisfied.')
73        : l10n('Each listed rule must be satisfied.'),
74      )
75    );
76}
77
78if (isset($search['fields']['allwords']))
79{
80  $template->append( 'search_words',
81      sprintf(
82        l10n('searched words : %s'),
83        join(', ', $search['fields']['allwords']['words'])
84        )
85      );
86}
87
88if (isset($search['fields']['tags']))
89{
90  $template->assign('SEARCH_TAGS_MODE', $search['fields']['tags']['mode']);
91 
92  $query = '
93SELECT name
94  FROM '.TAGS_TABLE.'
95  WHERE id IN ('.implode(',', $search['fields']['tags']['words']).')
96;';
97  $template->assign(
98      'search_tags',
99      array_from_query($query, 'name')
100    );
101}
102
103if (isset($search['fields']['author']))
104{
105  $template->append(
106    'search_words',
107     sprintf(
108          l10n('author(s) : %s'),
109          join(', ', $search['fields']['author']['words'])
110        )
111      );
112}
113
114if (isset($search['fields']['cat']))
115{
116  if ($search['fields']['cat']['sub_inc'])
117  {
118    // searching all the categories id of sub-categories
119    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
120  }
121  else
122  {
123    $cat_ids = $search['fields']['cat']['words'];
124  }
125
126  $query = '
127SELECT id, uppercats, global_rank
128  FROM '.CATEGORIES_TABLE.'
129  WHERE id IN ('.
130    implode(',', $cat_ids).
131    ')
132;';
133  $result = pwg_query($query);
134
135  $categories = array();
136  if (!empty($result))
137  {
138    while ($row = pwg_db_fetch_assoc($result))
139    {
140      array_push($categories, $row);
141    }
142  }
143  usort($categories, 'global_rank_compare');
144
145  foreach ($categories as $category)
146  {
147    $template->append(
148      'search_categories',
149      get_cat_display_name_cache(
150          $category['uppercats'],
151          null,                      // no url on category names
152          false                    // no blank replacement
153          )
154      );
155  }
156}
157
158foreach (array('date_available', 'date_creation') as $datefield)
159{
160  if ('date_available' == $datefield)
161  {
162    $lang_items = array(
163      'date'   => 'became available on %s',
164      'period' => 'became available between %s (%s) and %s (%s)',
165      'after'  => 'became available after %s (%s)',
166      'before' => 'became available before %s (%s)',
167      );
168  }
169  elseif ('date_creation' == $datefield)
170  {
171    $lang_items = array(
172      'date'   => 'created on %s',
173      'period' => 'created between %s (%s) and %s (%s)',
174      'after'  => 'created after %s (%s)',
175      'before' => 'created before %s (%s)',
176      );
177  }
178
179  $keys = array(
180    'date'   => $datefield,
181    'after'  => $datefield.'-after',
182    'before' => $datefield.'-before',
183    );
184
185  if (isset($search['fields'][ $keys['date'] ]))
186  {
187    $template->assign(
188      strtoupper($datefield),
189      sprintf(
190          l10n($lang_items['date']),
191          format_date($search['fields'][ $keys['date'] ])
192          )
193      );
194  }
195  elseif (isset($search['fields'][ $keys['before'] ])
196          and isset($search['fields'][ $keys['after'] ]))
197  {
198    $template->assign(
199      strtoupper($datefield),
200      sprintf(
201          l10n($lang_items['period']),
202
203          format_date($search['fields'][ $keys['after'] ]['date']),
204          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
205
206          format_date($search['fields'][ $keys['before'] ]['date']),
207          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
208          )
209      );
210  }
211  elseif (isset($search['fields'][ $keys['before'] ]))
212  {
213    $template->assign(
214      strtoupper($datefield),
215      sprintf(
216          l10n($lang_items['before']),
217
218          format_date($search['fields'][ $keys['before'] ]['date']),
219          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
220          )
221      );
222  }
223  elseif (isset($search['fields'][ $keys['after'] ]))
224  {
225    $template->assign(
226      strtoupper($datefield),
227      sprintf(
228          l10n($lang_items['after']),
229
230          format_date($search['fields'][ $keys['after'] ]['date']),
231          inc_exc_str($search['fields'][ $keys['after'] ]['inc'])
232          )
233      );
234  }
235}
236
237// +-----------------------------------------------------------------------+
238// |                           html code display                           |
239// +-----------------------------------------------------------------------+
240
241$template->pparse('search_rules');
242include(PHPWG_ROOT_PATH.'include/page_tail.php');
243?>
Note: See TracBrowser for help on using the repository browser.