source: trunk/search_rules.php @ 1083

Last change on this file since 1083 was 1083, checked in by rvelices, 19 years ago

language: cleanup unused, uniformization and no more L_ variables in
category.php and tpl

  • Property svn:eol-style set to native
File size: 7.3 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          : $RCSfile$
9// | last update   : $Date: 2005-09-27 23:57:14 +0200 (mar, 27 sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 879 $
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' );
46
47$page['body_id'] = 'thePopuphelpPage';
48$title = l10n('PhpWebGallery Help');
49$page['page_banner'] = '<h1>'.$title.'</h1>';
50include(PHPWG_ROOT_PATH.'include/page_header.php');
51
52$template->set_filenames(array('search_rules' => 'search_rules.tpl'));
53
54// +-----------------------------------------------------------------------+
55// |                        Textual rules creation                         |
56// +-----------------------------------------------------------------------+
57
58// Rules are stored in database, serialized in an array. This array must be
59// transformed into a list of textual rules.
60
61$search = get_search_array($_GET['search_id']);
62
63$template->assign_vars(
64  array(
65    'INTRODUCTION'
66      => 'OR' == $search['mode']
67      ? l10n('At least one listed rule must be satisfied.')
68      : l10n('Each listed rule must be satisfied.'),
69    )
70  );
71
72if (isset($search['fields']['allwords']))
73{
74  $template->assign_block_vars(
75    'words',
76    array(
77      'CONTENT' => sprintf(
78        l10n('searched words : %s'),
79        join(', ', $search['fields']['allwords']['words'])
80        )
81      )
82    );
83}
84
85if (isset($search['fields']['author']))
86{
87  $template->assign_block_vars(
88    'words',
89    array(
90      'CONTENT' => sprintf(
91          l10n('author(s) : %s'),
92          join(', ', $search['fields']['author']['words'])
93        )
94      )
95    );
96}
97
98if (isset($search['fields']['cat']))
99{
100  if ($search['fields']['cat']['sub_inc'])
101  {
102    // searching all the categories id of sub-categories
103    $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
104  }
105  else
106  {
107    $cat_ids = $search['fields']['cat']['words'];
108  }
109
110  $template->assign_block_vars(
111    'categories',
112    array(
113      'LIST_INTRO' => l10n('Categories'),
114      )
115    );
116
117  $query = '
118SELECT id, uppercats, global_rank
119  FROM '.CATEGORIES_TABLE.'
120  WHERE id IN ('.
121    implode(',', $cat_ids).
122    ')
123;';
124  $result = pwg_query($query);
125
126  $categories = array();
127  if (!empty($result))
128  {
129    while ($row = mysql_fetch_array($result))
130    {
131      array_push($categories, $row);
132    }
133  }
134  usort($categories, 'global_rank_compare');
135
136  foreach ($categories as $category)
137  {
138    $template->assign_block_vars(
139      'categories.category',
140      array(
141        'NAME' => get_cat_display_name_cache(
142          $category['uppercats'],
143          '',                      // no url on category names
144          false                    // no blank replacement
145          )
146        )
147      );
148  }
149}
150
151foreach (array('date_available', 'date_creation') as $datefield)
152{
153  if ('date_available' == $datefield)
154  {
155    $lang_items = array(
156      'date'   => 'became available on %s',
157      'period' => 'became available between %s (%s) and %s (%s)',
158      'after'  => 'became available after %s (%s)',
159      'before' => 'became available before %s (%s)',
160      );
161  }
162  elseif ('date_creation' == $datefield)
163  {
164    $lang_items = array(
165      'date'   => 'created on %s',
166      'period' => 'created between %s (%s) and %s (%s)',
167      'after'  => 'created after %s (%s)',
168      'before' => 'created before %s (%s)',
169      );
170  }
171
172  $keys = array(
173    'date'   => $datefield,
174    'after'  => $datefield.'-after',
175    'before' => $datefield.'-before',
176    );
177
178  if (isset($search['fields'][ $keys['date'] ]))
179  {
180    $template->assign_block_vars(
181      $datefield,
182      array(
183        'CONTENT' => sprintf(
184          l10n($lang_items['date']),
185          format_date($search['fields'][ $keys['date'] ])
186          ),
187        )
188      );
189  }
190  elseif (isset($search['fields'][ $keys['before'] ])
191          and isset($search['fields'][ $keys['after'] ]))
192  {
193    $template->assign_block_vars(
194      $datefield,
195      array(
196        'CONTENT' => sprintf(
197          l10n($lang_items['period']),
198
199          format_date($search['fields'][ $keys['after'] ]['date']),
200          inc_exc_str($search['fields'][ $keys['after'] ]['inc']),
201
202          format_date($search['fields'][ $keys['before'] ]['date']),
203          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
204          ),
205        )
206      );
207  }
208  elseif (isset($search['fields'][ $keys['before'] ]))
209  {
210    $template->assign_block_vars(
211      $datefield,
212      array(
213        'CONTENT' => sprintf(
214          l10n($lang_items['before']),
215
216          format_date($search['fields'][ $keys['before'] ]['date']),
217          inc_exc_str($search['fields'][ $keys['before'] ]['inc'])
218          ),
219        )
220      );
221  }
222  elseif (isset($search['fields'][ $keys['after'] ]))
223  {
224    $template->assign_block_vars(
225      $datefield,
226      array(
227        'CONTENT' => 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// +-----------------------------------------------------------------------+
239// |                           html code display                           |
240// +-----------------------------------------------------------------------+
241
242$template->parse('search_rules');
243include(PHPWG_ROOT_PATH.'include/page_tail.php');
244?>
Note: See TracBrowser for help on using the repository browser.