source: trunk/search.php @ 2279

Last change on this file since 2279 was 2223, checked in by rvelices, 17 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: 6.7 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.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//--------------------------------------------------------------------- include
28define('PHPWG_ROOT_PATH','./');
29include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_GUEST);
35
36//------------------------------------------------------------------ form check
37$errors = array();
38$search = array();
39if (isset($_POST['submit']))
40{
41  if (isset($_POST['search_allwords'])
42      and !preg_match('/^\s*$/', $_POST['search_allwords']))
43  {
44    $drop_char_match = array(
45      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
46      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
47    $drop_char_replace = array(
48      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
49      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
50
51    // Split words
52    $search['fields']['allwords'] = array(
53      'words' => array_unique(
54        preg_split(
55          '/\s+/',
56          str_replace(
57            $drop_char_match,
58            $drop_char_replace,
59            $_POST['search_allwords']
60            )
61          )
62        ),
63      'mode' => $_POST['mode'],
64      );
65  }
66
67  if (isset($_POST['tags']))
68  {
69    $search['fields']['tags'] = array(
70      'words' => $_POST['tags'],
71      'mode'  => $_POST['tag_mode'],
72      );
73  }
74
75  if ($_POST['search_author'])
76  {
77    $search['fields']['author'] = array(
78      'words' => preg_split(
79        '/\s+/',
80        $_POST['search_author']
81        ),
82      'mode' => 'OR',
83      );
84  }
85
86  if (isset($_POST['cat']))
87  {
88    $search['fields']['cat'] = array(
89      'words'   => $_POST['cat'],
90      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
91      );
92  }
93
94  // dates
95  $type_date = $_POST['date_type'];
96
97  if (!empty($_POST['start_year']))
98  {
99    $search['fields'][$type_date.'-after'] = array(
100      'date' => join(
101        '-',
102        array(
103          $_POST['start_year'],
104          $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
105          $_POST['start_day']   != 0 ? $_POST['start_day']   : '01',
106          )
107        ),
108      'inc' => true,
109      );
110  }
111
112  if (!empty($_POST['end_year']))
113  {
114    $search['fields'][$type_date.'-before'] = array(
115      'date' => join(
116        '-',
117        array(
118          $_POST['end_year'],
119          $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
120          $_POST['end_day']   != 0 ? $_POST['end_day']   : '31',
121          )
122        ),
123      'inc' => true,
124      );
125  }
126
127  if (!empty($search))
128  {
129    // default search mode : each clause must be respected
130    $search['mode'] = 'AND';
131
132    // register search rules in database, then they will be available on
133    // thumbnails page and picture page.
134    $query ='
135INSERT INTO '.SEARCH_TABLE.'
136  (rules, last_seen)
137  VALUES
138  (\''.serialize($search).'\', NOW())
139;';
140    pwg_query($query);
141
142    $search_id = mysql_insert_id();
143  }
144  else
145  {
146    array_push($errors, l10n('search_one_clause_at_least'));
147  }
148}
149//----------------------------------------------------------------- redirection
150if (isset($_POST['submit']) and count($errors) == 0)
151{
152  redirect(
153    make_index_url(
154      array(
155        'section' => 'search',
156        'search'  => $search_id,
157        )
158      )
159    );
160}
161//----------------------------------------------------- template initialization
162
163//
164// Start output of page
165//
166$title= l10n('search_title');
167$page['body_id'] = 'theSearchPage';
168
169$template->set_filename('search' ,'search.tpl' );
170
171$month_list = $lang['month'];
172$month_list[0]='------------';
173ksort($month_list);
174
175$template->assign(
176  array(
177    'F_SEARCH_ACTION' => 'search.php',
178    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
179   
180    'month_list' => $month_list,
181    'START_DAY_SELECTED' => @$_POST['start_day'],
182    'START_MONTH_SELECTED' => @$_POST['start_month'],
183    'END_DAY_SELECTED' => @$_POST['end_day'],
184    'END_MONTH_SELECTED' => @$_POST['end_month'],
185    )
186  );
187
188$available_tags = get_available_tags();
189
190if (count($available_tags) > 0)
191{
192  usort( $available_tags, 'name_compare');
193
194  $template->assign(
195    'TAG_SELECTION',
196    get_html_tag_selection(
197        $available_tags,
198        'tags',
199        isset($_POST['tags']) ? $_POST['tags'] : array()
200        )
201    );
202}
203
204//------------------------------------------------------------- categories form
205$query = '
206SELECT name,id,date_last,nb_images,global_rank,uppercats
207  FROM '.CATEGORIES_TABLE.'
208'.get_sql_condition_FandF
209  (
210    array
211      (
212        'forbidden_categories' => 'id',
213        'visible_categories' => 'id'
214      ),
215    'WHERE'
216  ).'
217;';
218display_select_cat_wrapper($query, array(), 'category_options', false);
219
220//-------------------------------------------------------------- errors display
221if (sizeof($errors) != 0)
222{
223  $template->assign('errors', $errors);
224}
225//------------------------------------------------------------ log informations
226include(PHPWG_ROOT_PATH.'include/page_header.php');
227$template->pparse('search');
228include(PHPWG_ROOT_PATH.'include/page_tail.php');
229?>
Note: See TracBrowser for help on using the repository browser.