source: branches/2.1/search.php @ 16055

Last change on this file since 16055 was 6519, checked in by nikrou, 14 years ago

Bug 1730 fixed : search doesn't work when database engine is not mysql
For posgresql and sqlite date must allways use day and month with two diggits.
merge from trunk

  • Property svn:eol-style set to LF
File size: 6.9 KB
RevLine 
[2]1<?php
[354]2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[5196]5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[2]23
[455]24//--------------------------------------------------------------------- include
[364]25define('PHPWG_ROOT_PATH','./');
26include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
[1072]27
28// +-----------------------------------------------------------------------+
29// | Check Access and exit when user status is not ok                      |
30// +-----------------------------------------------------------------------+
31check_status(ACCESS_GUEST);
32
[455]33//------------------------------------------------------------------ form check
34$errors = array();
35$search = array();
36if (isset($_POST['submit']))
[2]37{
[4753]38  foreach ($_POST as $post_key => $post_value)
39  {
40    if (!is_array($post_value))
41    {
[6519]42      $_POST[$post_key] = pwg_db_real_escape_string($post_value);
[4753]43    }
44  } 
45 
[634]46  if (isset($_POST['search_allwords'])
47      and !preg_match('/^\s*$/', $_POST['search_allwords']))
[1059]48  {
[634]49    $drop_char_match = array(
50      '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_',
51      '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*');
52    $drop_char_replace = array(
53      ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ',
54      ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ');
[1059]55
[634]56    // Split words
[1008]57    $search['fields']['allwords'] = array(
58      'words' => array_unique(
59        preg_split(
60          '/\s+/',
61          str_replace(
62            $drop_char_match,
63            $drop_char_replace,
64            $_POST['search_allwords']
65            )
66          )
67        ),
68      'mode' => $_POST['mode'],
69      );
[455]70  }
[1059]71
[1119]72  if (isset($_POST['tags']))
73  {
[5195]74    check_input_parameter('tags', $_POST, true, PATTERN_ID);
[4753]75   
[1119]76    $search['fields']['tags'] = array(
77      'words' => $_POST['tags'],
78      'mode'  => $_POST['tag_mode'],
79      );
80  }
[1125]81
[621]82  if ($_POST['search_author'])
[455]83  {
[1008]84    $search['fields']['author'] = array(
[1015]85      'words' => preg_split(
86        '/\s+/',
87        $_POST['search_author']
88        ),
89      'mode' => 'OR',
[1008]90      );
[17]91  }
[1059]92
[621]93  if (isset($_POST['cat']))
[2]94  {
[5195]95    check_input_parameter('cat', $_POST, true, PATTERN_ID);
[4753]96   
[1008]97    $search['fields']['cat'] = array(
98      'words'   => $_POST['cat'],
99      'sub_inc' => ($_POST['subcats-included'] == 1) ? true : false,
100      );
[2]101  }
[634]102
103  // dates
104  $type_date = $_POST['date_type'];
[1059]105
[621]106  if (!empty($_POST['start_year']))
[634]107  {
[1008]108    $search['fields'][$type_date.'-after'] = array(
[6519]109      'date' => sprintf(
110        '%d-%02d-%02d',
111        $_POST['start_year'],
112        $_POST['start_month'] != 0 ? $_POST['start_month'] : '01',
113        $_POST['start_day']   != 0 ? $_POST['start_day']   : '01'
[1008]114        ),
115      'inc' => true,
116      );
[634]117  }
[621]118
[634]119  if (!empty($_POST['end_year']))
[621]120  {
[1008]121    $search['fields'][$type_date.'-before'] = array(
[6519]122      'date' => sprintf(
123        '%d-%02d-%02d',
124        $_POST['end_year'],
125        $_POST['end_month'] != 0 ? $_POST['end_month'] : '12',
126        $_POST['end_day']   != 0 ? $_POST['end_day']   : '31'
127      ),
[1008]128      'inc' => true,
129      );
[621]130  }
[1059]131
[621]132  if (!empty($search))
133  {
[1008]134    // default search mode : each clause must be respected
135    $search['mode'] = 'AND';
136
137    // register search rules in database, then they will be available on
138    // thumbnails page and picture page.
139    $query ='
140INSERT INTO '.SEARCH_TABLE.'
[1816]141  (rules, last_seen)
[1008]142  VALUES
[1816]143  (\''.serialize($search).'\', NOW())
[1008]144;';
145    pwg_query($query);
146
[4892]147    $search_id = pwg_db_insert_id(SEARCH_TABLE);
[455]148  }
[621]149  else
[455]150  {
[5021]151    array_push($errors, l10n('Empty query. No criteria has been entered.'));
[455]152  }
[2]153}
[455]154//----------------------------------------------------------------- redirection
155if (isset($_POST['submit']) and count($errors) == 0)
156{
[1082]157  redirect(
158    make_index_url(
159      array(
160        'section' => 'search',
161        'search'  => $search_id,
162        )
163      )
164    );
[455]165}
[2]166//----------------------------------------------------- template initialization
[621]167
[345]168//
169// Start output of page
170//
[5021]171$title= l10n('Search');
[850]172$page['body_id'] = 'theSearchPage';
[345]173
[2223]174$template->set_filename('search' ,'search.tpl' );
[1125]175
[2223]176$month_list = $lang['month'];
177$month_list[0]='------------';
178ksort($month_list);
179
180$template->assign(
[1314]181  array(
[2223]182    'F_SEARCH_ACTION' => 'search.php',
[1314]183    'U_HELP' => PHPWG_ROOT_PATH.'popuphelp.php?page=search',
[2324]184
[2223]185    'month_list' => $month_list,
186    'START_DAY_SELECTED' => @$_POST['start_day'],
187    'START_MONTH_SELECTED' => @$_POST['start_month'],
188    'END_DAY_SELECTED' => @$_POST['end_day'],
189    'END_MONTH_SELECTED' => @$_POST['end_month'],
[1314]190    )
191  );
192
[1677]193$available_tags = get_available_tags();
[1125]194
[1314]195if (count($available_tags) > 0)
196{
[2409]197  usort( $available_tags, 'tag_alpha_compare');
[1119]198
[2223]199  $template->assign(
200    'TAG_SELECTION',
201    get_html_tag_selection(
[1314]202        $available_tags,
203        'tags',
204        isset($_POST['tags']) ? $_POST['tags'] : array()
[2223]205        )
[1314]206    );
207}
[355]208
[455]209//------------------------------------------------------------- categories form
[614]210$query = '
[2324]211SELECT id,name,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;';
[2223]223display_select_cat_wrapper($query, array(), 'category_options', false);
[621]224
[2]225//-------------------------------------------------------------- errors display
[455]226if (sizeof($errors) != 0)
[2]227{
[2223]228  $template->assign('errors', $errors);
[2]229}
230//------------------------------------------------------------ log informations
[1627]231include(PHPWG_ROOT_PATH.'include/page_header.php');
[2223]232$template->pparse('search');
[369]233include(PHPWG_ROOT_PATH.'include/page_tail.php');
[362]234?>
Note: See TracBrowser for help on using the repository browser.