source: branches/1.6/search.php @ 27569

Last change on this file since 27569 was 1313, checked in by plg, 18 years ago

bug 373 fixed: if there is no tag defined, an explicit message is displayed
in the administration section. In the public search screen, tag fieldset is
not displayed if no reachable tag.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-05-15 22:19:48 +0000 (Mon, 15 May 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1313 $
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//--------------------------------------------------------------------- include
29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_GUEST);
36
37//------------------------------------------------------------------ form check
38$errors = array();
39$search = array();
40if (isset($_POST['submit']))
41{
42  if (isset($_POST['search_allwords'])
43      and !preg_match('/^\s*$/', $_POST['search_allwords']))
44  {
45    $drop_char_match = array(
46      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
47      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
48    $drop_char_replace = array(
49      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
50      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
51
52    // Split words
53    $search['fields']['allwords'] = array(
54      'words' => array_unique(
55        preg_split(
56          '/\s+/',
57          str_replace(
58            $drop_char_match,
59            $drop_char_replace,
60            $_POST['search_allwords']
61            )
62          )
63        ),
64      'mode' => $_POST['mode'],
65      );
66  }
67
68  if (isset($_POST['tags']))
69  {
70    $search['fields']['tags'] = array(
71      'words' => $_POST['tags'],
72      'mode'  => $_POST['tag_mode'],
73      );
74  }
75
76  if ($_POST['search_author'])
77  {
78    $search['fields']['author'] = array(
79      'words' => preg_split(
80        '/\s+/',
81        $_POST['search_author']
82        ),
83      'mode' => 'OR',
84      );
85  }
86
87  if (isset($_POST['cat']))
88  {
89    $search['fields']['cat'] = array(
90      'words'   => $_POST['cat'],
91      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
92      );
93  }
94
95  // dates
96  $type_date = $_POST['date_type'];
97
98  if (!empty($_POST['start_year']))
99  {
100    $search['fields'][$type_date.'-after'] = array(
101      'date' => join(
102        '-',
103        array(
104          $_POST['start_year'],
105          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
106          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
107          )
108        ),
109      'inc' => true,
110      );
111  }
112
113  if (!empty($_POST['end_year']))
114  {
115    $search['fields'][$type_date.'-before'] = array(
116      'date' => join(
117        '-',
118        array(
119          $_POST['end_year'],
120          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
121          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
122          )
123        ),
124      'inc' => true,
125      );
126  }
127
128  if (!empty($search))
129  {
130    // default search mode : each clause must be respected
131    $search['mode'] = 'AND';
132
133    // register search rules in database, then they will be available on
134    // thumbnails page and picture page.
135    $query ='
136INSERT INTO '.SEARCH_TABLE.'
137  (rules)
138  VALUES
139  (\''.serialize($search).'\')
140;';
141    pwg_query($query);
142
143    $search_id = mysql_insert_id();
144  }
145  else
146  {
147    array_push($errors, $lang['search_one_clause_at_least']);
148  }
149}
150//----------------------------------------------------------------- redirection
151if (isset($_POST['submit']) and count($errors) == 0)
152{
153  redirect(
154    make_index_url(
155      array(
156        'section' => 'search',
157        'search'  => $search_id,
158        )
159      )
160    );
161}
162//----------------------------------------------------- template initialization
163
164// start date
165get_day_list('start_day', @$_POST['start_day']);
166get_month_list('start_month', @$_POST['start_month']);
167// end date
168get_day_list('end_day', @$_POST['end_day']);
169get_month_list('end_month', @$_POST['end_month']);
170
171//
172// Start output of page
173//
174$title= $lang['search_title'];
175$page['body_id'] = 'theSearchPage';
176include(PHPWG_ROOT_PATH.'include/page_header.php');
177
178$template->set_filenames( array('search'=>'search.tpl') );
179
180$template->assign_vars(
181  array(
182    'TODAY_DAY' => date('d', time()),
183    'TODAY_MONTH' => date('m', time()),
184    'TODAY_YEAR' => date('Y', time()),
185    'S_SEARCH_ACTION' => 'search.php',
186    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
187    'U_HOME' => make_index_url(),
188    )
189  );
190
191$available_tags = get_available_tags(
192      isset($user['forbidden_categories'])
193      ? explode(',', $user['forbidden_categories'])
194      : null
195      );
196
197if (count($available_tags) > 0)
198{
199  usort( $available_tags, 'name_compare');
200
201  $template->assign_block_vars('tags', array());
202 
203  $template->assign_vars(
204    array(
205      'TAG_SELECTION' => get_html_tag_selection(
206        $available_tags,
207        'tags',
208        isset($_POST['tags']) ? $_POST['tags'] : array()
209        ),
210      )
211    );
212}
213
214//------------------------------------------------------------- categories form
215$query = '
216SELECT name,id,date_last,nb_images,global_rank,uppercats
217  FROM '.CATEGORIES_TABLE;
218if ($user['forbidden_categories'] != '')
219{
220  $query.= '
221  WHERE id NOT IN ('.$user['forbidden_categories'].')';
222}
223$query.= '
224;';
225
226$selecteds = array();
227display_select_cat_wrapper($query, $selecteds, 'category_option', false);
228
229//-------------------------------------------------------------- errors display
230if (sizeof($errors) != 0)
231{
232  $template->assign_block_vars('errors',array());
233  foreach ($errors as $error)
234  {
235    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
236  }
237}
238//------------------------------------------------------------ log informations
239pwg_log( 'search', $title );
240$template->parse('search');
241include(PHPWG_ROOT_PATH.'include/page_tail.php');
242?>
Note: See TracBrowser for help on using the repository browser.