[2] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[354] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[354] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2005-05-14 13:39:00 +0000 (Sat, 14 May 2005) $ |
---|
| 10 | // | last modifier : $Author: None $ |
---|
| 11 | // | revision : $Revision: 790 $ |
---|
| 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] | 29 | define('PHPWG_ROOT_PATH','./'); |
---|
| 30 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
[2] | 31 | //-------------------------------------------------- access authorization check |
---|
| 32 | check_login_authorization(); |
---|
[455] | 33 | //------------------------------------------------------------------ form check |
---|
| 34 | $errors = array(); |
---|
| 35 | $search = array(); |
---|
| 36 | if (isset($_POST['submit'])) |
---|
[2] | 37 | { |
---|
[634] | 38 | if (isset($_POST['search_allwords']) |
---|
| 39 | and !preg_match('/^\s*$/', $_POST['search_allwords'])) |
---|
[455] | 40 | { |
---|
[621] | 41 | $local_search = array(); |
---|
[634] | 42 | $search_allwords = $_POST['search_allwords']; |
---|
| 43 | $drop_char_match = array( |
---|
| 44 | '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', |
---|
| 45 | '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); |
---|
| 46 | $drop_char_replace = array( |
---|
| 47 | ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', |
---|
| 48 | ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' '); |
---|
| 49 | $search_allwords = str_replace($drop_char_match, |
---|
| 50 | $drop_char_replace, |
---|
| 51 | $search_allwords); |
---|
[621] | 52 | |
---|
[634] | 53 | // Split words |
---|
| 54 | $words = preg_split('/\s+/', $search_allwords); |
---|
[621] | 55 | $words = array_unique($words); |
---|
[634] | 56 | $search['fields']['allwords'] = array(); |
---|
| 57 | $search['fields']['allwords']['words'] = $words; |
---|
| 58 | $search['fields']['allwords']['mode'] = $_POST['mode']; |
---|
[455] | 59 | } |
---|
[621] | 60 | |
---|
| 61 | if ($_POST['search_author']) |
---|
[455] | 62 | { |
---|
[621] | 63 | $search['fields']['author'] = array(); |
---|
| 64 | $search['fields']['author']['words'] = array($_POST['search_author']); |
---|
[17] | 65 | } |
---|
[621] | 66 | |
---|
| 67 | if (isset($_POST['cat'])) |
---|
[2] | 68 | { |
---|
[621] | 69 | $search['fields']['cat'] = array(); |
---|
| 70 | $search['fields']['cat']['words'] = $_POST['cat']; |
---|
[634] | 71 | if ($_POST['subcats-included'] == 1) |
---|
[455] | 72 | { |
---|
[621] | 73 | $search['fields']['cat']['mode'] = 'sub_inc'; |
---|
[455] | 74 | } |
---|
[2] | 75 | } |
---|
[634] | 76 | |
---|
| 77 | // dates |
---|
| 78 | $type_date = $_POST['date_type']; |
---|
[621] | 79 | |
---|
| 80 | if (!empty($_POST['start_year'])) |
---|
[634] | 81 | { |
---|
| 82 | $year = $_POST['start_year']; |
---|
| 83 | $month = $_POST['start_month'] != 0 ? $_POST['start_month'] : '01'; |
---|
| 84 | $day = $_POST['start_day'] != 0 ? $_POST['start_day'] : '01'; |
---|
| 85 | $date = $year.'-'.$month.'-'.$day; |
---|
| 86 | |
---|
| 87 | $search['fields'][$type_date.'-after']['words'] = array($date); |
---|
| 88 | $search['fields'][$type_date.'-after']['mode'] = 'inc'; |
---|
| 89 | } |
---|
[621] | 90 | |
---|
[634] | 91 | if (!empty($_POST['end_year'])) |
---|
[621] | 92 | { |
---|
[634] | 93 | $year = $_POST['end_year']; |
---|
| 94 | $month = $_POST['end_month'] != 0 ? $_POST['end_month'] : '12'; |
---|
| 95 | $day = $_POST['end_day'] != 0 ? $_POST['end_day'] : '31'; |
---|
| 96 | $date = $year.'-'.$month.'-'.$day; |
---|
| 97 | |
---|
| 98 | $search['fields'][$type_date.'-before']['words'] = array($date); |
---|
| 99 | $search['fields'][$type_date.'-before']['mode'] = 'inc'; |
---|
[621] | 100 | } |
---|
[634] | 101 | |
---|
[455] | 102 | // search string (for URL) creation |
---|
| 103 | $search_string = ''; |
---|
| 104 | $tokens = array(); |
---|
[621] | 105 | if (!empty($search)) |
---|
| 106 | { |
---|
[634] | 107 | foreach (array_keys($search['fields']) as $field) |
---|
[455] | 108 | { |
---|
[634] | 109 | $token = $field.':'; |
---|
| 110 | $token.= implode(',', $search['fields'][$field]['words']); |
---|
| 111 | if (isset($search['fields'][$field]['mode'])) |
---|
| 112 | { |
---|
| 113 | $token.= '~'.$search['fields'][$field]['mode']; |
---|
| 114 | } |
---|
| 115 | array_push($tokens, $token); |
---|
[455] | 116 | } |
---|
[785] | 117 | $search_string.= implode('--', $tokens); |
---|
[634] | 118 | if (count($tokens) > 1) |
---|
| 119 | { |
---|
| 120 | $search_string.= '|AND'; |
---|
| 121 | } |
---|
[455] | 122 | } |
---|
[621] | 123 | else |
---|
[455] | 124 | { |
---|
| 125 | array_push($errors, $lang['search_one_clause_at_least']); |
---|
| 126 | } |
---|
[2] | 127 | } |
---|
[455] | 128 | //----------------------------------------------------------------- redirection |
---|
| 129 | if (isset($_POST['submit']) and count($errors) == 0) |
---|
| 130 | { |
---|
| 131 | $url = 'category.php?cat=search&search='.$search_string; |
---|
| 132 | $url = add_session_id($url, true); |
---|
| 133 | redirect($url); |
---|
| 134 | } |
---|
[2] | 135 | //----------------------------------------------------- template initialization |
---|
[634] | 136 | /** |
---|
| 137 | * instantiate number list for days in a template block |
---|
| 138 | * |
---|
| 139 | * @param string blockname |
---|
| 140 | * @param string selection |
---|
| 141 | */ |
---|
| 142 | function get_day_list($blockname, $selection) |
---|
[621] | 143 | { |
---|
[634] | 144 | global $template; |
---|
| 145 | |
---|
| 146 | $template->assign_block_vars( |
---|
| 147 | $blockname, array('SELECTED' => '', 'VALUE' => 0, 'OPTION' => '--')); |
---|
| 148 | |
---|
| 149 | for ($i = 1; $i <= 31; $i++) |
---|
| 150 | { |
---|
| 151 | $selected = ''; |
---|
| 152 | if ($i == (int)$selection) |
---|
| 153 | { |
---|
| 154 | $selected = 'selected="selected"'; |
---|
| 155 | } |
---|
| 156 | $template->assign_block_vars( |
---|
| 157 | $blockname, array('SELECTED' => $selected, |
---|
| 158 | 'VALUE' => $i, |
---|
| 159 | 'OPTION' => str_pad($i, 2, '0', STR_PAD_LEFT))); |
---|
| 160 | } |
---|
[621] | 161 | } |
---|
| 162 | |
---|
[634] | 163 | /** |
---|
| 164 | * instantiate month list in a template block |
---|
| 165 | * |
---|
| 166 | * @param string blockname |
---|
| 167 | * @param string selection |
---|
| 168 | */ |
---|
| 169 | function get_month_list($blockname, $selection) |
---|
[621] | 170 | { |
---|
[634] | 171 | global $template, $lang; |
---|
| 172 | |
---|
| 173 | $template->assign_block_vars( |
---|
| 174 | $blockname, array('SELECTED' => '', |
---|
| 175 | 'VALUE' => 0, |
---|
| 176 | 'OPTION' => '------------')); |
---|
[621] | 177 | |
---|
[634] | 178 | for ($i = 1; $i <= 12; $i++) |
---|
| 179 | { |
---|
| 180 | $selected = ''; |
---|
| 181 | if ($i == (int)$selection) |
---|
| 182 | { |
---|
| 183 | $selected = 'selected="selected"'; |
---|
| 184 | } |
---|
| 185 | $template->assign_block_vars( |
---|
| 186 | $blockname, array('SELECTED' => $selected, |
---|
| 187 | 'VALUE' => $i, |
---|
| 188 | 'OPTION' => $lang['month'][$i])); |
---|
| 189 | } |
---|
[621] | 190 | } |
---|
| 191 | |
---|
[634] | 192 | // start date |
---|
| 193 | get_day_list('start_day', @$_POST['start_day']); |
---|
| 194 | get_month_list('start_month', @$_POST['start_month']); |
---|
| 195 | // end date |
---|
| 196 | get_day_list('end_day', @$_POST['end_day']); |
---|
| 197 | get_month_list('end_month', @$_POST['end_month']); |
---|
[621] | 198 | |
---|
[345] | 199 | // |
---|
| 200 | // Start output of page |
---|
| 201 | // |
---|
| 202 | $title= $lang['search_title']; |
---|
[369] | 203 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[345] | 204 | |
---|
[355] | 205 | $template->set_filenames( array('search'=>'search.tpl') ); |
---|
| 206 | $template->assign_vars(array( |
---|
[780] | 207 | 'L_RETURN_HINT' => $lang['home_hint'], |
---|
[621] | 208 | 'L_SEARCH_TITLE' => $lang['search_title'], |
---|
| 209 | 'L_SEARCH_OPTIONS' => $lang['search_options'], |
---|
[607] | 210 | 'L_RETURN' => $lang['home'], |
---|
[355] | 211 | 'L_SUBMIT' => $lang['submit'], |
---|
[621] | 212 | 'L_RESET' => $lang['reset'], |
---|
| 213 | 'L_SEARCH_KEYWORDS'=>$lang['search_keywords'], |
---|
| 214 | 'L_SEARCH_KEYWORDS_HINT'=>$lang['search_keywords_hint'], |
---|
| 215 | 'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'], |
---|
| 216 | 'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'], |
---|
| 217 | 'L_SEARCH_AUTHOR'=>$lang['search_author'], |
---|
| 218 | 'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'], |
---|
| 219 | 'L_SEARCH_CATEGORIES'=>$lang['search_categories'], |
---|
| 220 | 'L_SEARCH_CATEGORIES_HINT'=>$lang['search_categories_hint'], |
---|
| 221 | 'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'], |
---|
| 222 | 'L_YES' => $lang['yes'], |
---|
| 223 | 'L_NO' => $lang['no'], |
---|
| 224 | 'L_SEARCH_DATE' => $lang['search_date'], |
---|
| 225 | 'L_SEARCH_DATE_HINT' => $lang['search_date_hint'], |
---|
| 226 | 'L_TODAY' => $lang['today'], |
---|
| 227 | 'L_SEARCH_DATE_FROM'=>$lang['search_date_from'], |
---|
[629] | 228 | 'L_SEARCH_DATE_TO'=>$lang['search_date_to'], |
---|
[621] | 229 | 'L_DAYS'=>$lang['days'], |
---|
| 230 | 'L_MONTH'=>$lang['w_month'], |
---|
| 231 | 'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'], |
---|
| 232 | 'L_SEARCH_CREATION'=>$lang['search_date_creation'], |
---|
| 233 | 'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'], |
---|
| 234 | 'L_RESULT_SORT'=>$lang['search_sort'], |
---|
| 235 | 'L_SORT_ASCENDING'=>$lang['search_ascending'], |
---|
| 236 | 'L_SORT_DESCENDING'=>$lang['search_descending'], |
---|
[355] | 237 | |
---|
[621] | 238 | 'TODAY_DAY' => date('d', time()), |
---|
| 239 | 'TODAY_MONTH' => date('m', time()), |
---|
| 240 | 'TODAY_YEAR' => date('Y', time()), |
---|
| 241 | 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), |
---|
[355] | 242 | 'U_HOME' => add_session_id( 'category.php' ) |
---|
| 243 | ) |
---|
| 244 | ); |
---|
| 245 | |
---|
[455] | 246 | //------------------------------------------------------------- categories form |
---|
[614] | 247 | $query = ' |
---|
| 248 | SELECT name,id,date_last,nb_images,global_rank,uppercats |
---|
| 249 | FROM '.CATEGORIES_TABLE; |
---|
[634] | 250 | if ($user['forbidden_categories'] != '') |
---|
| 251 | { |
---|
| 252 | $query.= ' |
---|
[614] | 253 | WHERE id NOT IN ('.$user['forbidden_categories'].')'; |
---|
[634] | 254 | } |
---|
[614] | 255 | $query.= ' |
---|
| 256 | ;'; |
---|
[621] | 257 | |
---|
[455] | 258 | $selecteds = array(); |
---|
[614] | 259 | display_select_cat_wrapper($query, $selecteds, 'category_option', false); |
---|
[455] | 260 | |
---|
[2] | 261 | //-------------------------------------------------------------- errors display |
---|
[455] | 262 | if (sizeof($errors) != 0) |
---|
[2] | 263 | { |
---|
[355] | 264 | $template->assign_block_vars('errors',array()); |
---|
[455] | 265 | foreach ($errors as $error) |
---|
[2] | 266 | { |
---|
[455] | 267 | $template->assign_block_vars('errors.error',array('ERROR'=>$error)); |
---|
[2] | 268 | } |
---|
| 269 | } |
---|
| 270 | //------------------------------------------------------------ log informations |
---|
[345] | 271 | pwg_log( 'search', $title ); |
---|
[17] | 272 | mysql_close(); |
---|
[688] | 273 | $template->parse('search'); |
---|
[369] | 274 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[362] | 275 | ?> |
---|