source: trunk/search.php @ 2006

Last change on this file since 2006 was 1903, checked in by vdigital, 18 years ago

Updates:

  • Copyrights 2003-2007
  • help
  • Some HTML comform requests
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[1903]5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
[354]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[354]8// | file          : $RCSfile$
9// | last update   : $Date: 2007-03-13 22:44:45 +0000 (Tue, 13 Mar 2007) $
10// | last modifier : $Author: vdigital $
11// | revision      : $Revision: 1903 $
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// +-----------------------------------------------------------------------+
[2]27
[455]28//--------------------------------------------------------------------- include
[364]29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1072]31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_GUEST);
36
[455]37//------------------------------------------------------------------ form check
38$errors = array();
39$search = array();
40if (isset($_POST['submit']))
[2]41{
[634]42  if (isset($_POST['search_allwords'])
43      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]44  {
[634]45    $drop_char_match = array(
46      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
47      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
48    $drop_char_replace = array(
49      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
50      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]51
[634]52    // Split words
[1008]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      );
[455]66  }
[1059]67
[1119]68  if (isset($_POST['tags']))
69  {
70    $search['fields']['tags'] = array(
71      'words' => $_POST['tags'],
72      'mode'  => $_POST['tag_mode'],
73      );
74  }
[1125]75
[621]76  if ($_POST['search_author'])
[455]77  {
[1008]78    $search['fields']['author'] = array(
[1015]79      'words' => preg_split(
80        '/\s+/',
81        $_POST['search_author']
82        ),
83      'mode' => 'OR',
[1008]84      );
[17]85  }
[1059]86
[621]87  if (isset($_POST['cat']))
[2]88  {
[1008]89    $search['fields']['cat'] = array(
90      'words'   => $_POST['cat'],
91      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
92      );
[2]93  }
[634]94
95  // dates
96  $type_date = $_POST['date_type'];
[1059]97
[621]98  if (!empty($_POST['start_year']))
[634]99  {
[1008]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      );
[634]111  }
[621]112
[634]113  if (!empty($_POST['end_year']))
[621]114  {
[1008]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      );
[621]126  }
[1059]127
[621]128  if (!empty($search))
129  {
[1008]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.'
[1816]137  (rules, last_seen)
[1008]138  VALUES
[1816]139  (\''.serialize($search).'\', NOW())
[1008]140;';
141    pwg_query($query);
142
143    $search_id = mysql_insert_id();
[455]144  }
[621]145  else
[455]146  {
147    array_push($errors, $lang['search_one_clause_at_least']);
148  }
[2]149}
[455]150//----------------------------------------------------------------- redirection
151if (isset($_POST['submit']) and count($errors) == 0)
152{
[1082]153  redirect(
154    make_index_url(
155      array(
156        'section' => 'search',
157        'search'  => $search_id,
158        )
159      )
160    );
[455]161}
[2]162//----------------------------------------------------- template initialization
[621]163
[634]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']);
[621]170
[345]171//
172// Start output of page
173//
174$title= $lang['search_title'];
[850]175$page['body_id'] = 'theSearchPage';
[345]176
[355]177$template->set_filenames( array('search'=>'search.tpl') );
[1125]178
[1314]179$template->assign_vars(
180  array(
181    'TODAY_DAY' => date('d', time()),
182    'TODAY_MONTH' => date('m', time()),
183    'TODAY_YEAR' => date('Y', time()),
184    'S_SEARCH_ACTION' => 'search.php',
185    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
186    'U_HOME' => make_index_url(),
187    )
188  );
189
[1677]190$available_tags = get_available_tags();
[1125]191
[1314]192if (count($available_tags) > 0)
193{
194  usort( $available_tags, 'name_compare');
[1119]195
[1314]196  $template->assign_block_vars('tags', array());
197 
198  $template->assign_vars(
199    array(
200      'TAG_SELECTION' => get_html_tag_selection(
201        $available_tags,
202        'tags',
203        isset($_POST['tags']) ? $_POST['tags'] : array()
204        ),
205      )
206    );
207}
[355]208
[455]209//------------------------------------------------------------- categories form
[614]210$query = '
211SELECT name,id,date_last,nb_images,global_rank,uppercats
[1677]212  FROM '.CATEGORIES_TABLE.'
213'.get_sql_condition_FandF
214  (
215    array
216      (
217        'forbidden_categories' => 'id',
218        'visible_categories' => 'id'
219      ),
220    'WHERE'
221  ).'
[614]222;';
[621]223
[455]224$selecteds = array();
[614]225display_select_cat_wrapper($query, $selecteds, 'category_option', false);
[455]226
[2]227//-------------------------------------------------------------- errors display
[455]228if (sizeof($errors) != 0)
[2]229{
[355]230  $template->assign_block_vars('errors',array());
[455]231  foreach ($errors as $error)
[2]232  {
[455]233    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
[2]234  }
235}
236//------------------------------------------------------------ log informations
[1627]237include(PHPWG_ROOT_PATH.'include/page_header.php');
[688]238$template->parse('search');
[369]239include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]240?>
Note: See TracBrowser for help on using the repository browser.