source: trunk/search.php @ 26507

Last change on this file since 26507 was 26461, checked in by mistic100, 11 years ago

Update headers to 2014. Happy new year!!

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