Changeset 621 for trunk/search.php
- Timestamp:
- Nov 25, 2004, 3:12:33 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/search.php
r614 r621 26 26 // +-----------------------------------------------------------------------+ 27 27 28 //------------------------------------------------------------------- functions29 // date_display displays 3 select input fields. The first one is the30 // day of the month, from 0 to 31. The second is the month of the year,31 // from 01 to 12. The last one is the year. The years displayed are the32 // ones given by get_available_years (see function description in33 // ./include/functions.inc.php).34 function display_date($fieldname, $datefield)35 {36 global $template;37 38 // years39 for ($i = 1990; $i < 2006; $i++)40 {41 $selected = '';42 $key = $datefield.':year';43 if (isset($_POST[$key]) and $i == $_POST[$key])44 {45 $selected = ' selected="selected"';46 }47 48 $template->assign_block_vars(49 $fieldname.'year_option',50 array('OPTION'=>$i,51 'SELECTED'=>$selected52 ));53 }54 // months of year55 for ($i = 1; $i <= 12; $i++)56 {57 $selected = '';58 $key = $datefield.':month';59 if (isset($_POST[$key]) and $i == $_POST[$key])60 {61 $selected = ' selected="selected"';62 }63 64 $template->assign_block_vars(65 $fieldname.'month_option',66 array('OPTION'=>sprintf('%02s', $i),67 'SELECTED'=>$selected68 ));69 }70 // days of the month71 for ($i = 1; $i <= 31; $i++)72 {73 $selected = '';74 $key = $datefield.':day';75 if (isset($_POST[$key]) and $i == $_POST[$key])76 {77 $selected = ' selected="selected"';78 }79 80 $template->assign_block_vars(81 $fieldname.'day_option',82 array('OPTION'=>sprintf('%02s', $i),83 'SELECTED'=>$selected84 ));85 }86 }87 88 function display_3dates($fieldname)89 {90 display_date('datefield.', $fieldname);91 display_date('datefield.after_', $fieldname.'-after');92 display_date('datefield.before_', $fieldname.'-before');93 }94 28 //--------------------------------------------------------------------- include 95 29 define('PHPWG_ROOT_PATH','./'); … … 97 31 //-------------------------------------------------- access authorization check 98 32 check_login_authorization(); 99 //----------------------------------------------------------------- form fields100 $textfields = array('file', 'name', 'comment', 'keywords', 'author');101 $datefields = array('date_available', 'date_creation');102 33 //------------------------------------------------------------------ form check 103 34 $errors = array(); 104 35 $search = array(); 105 $search['fields'] = array();106 36 if (isset($_POST['submit'])) 107 37 { 108 $search['mode'] = $_POST['mode']; 109 110 foreach ($textfields as $textfield) 111 { 112 if (isset($_POST[$textfield.'-content']) 113 and !preg_match('/^\s*$/', $_POST[$textfield.'-content'])) 114 { 115 $local_search = array(); 116 $words = preg_split('/\s+/', $_POST[$textfield.'-content']); 117 foreach ($words as $i => $word) 118 { 119 if (strlen($word) > 2 and !preg_match('/[,;:\']/', $word)) 120 { 121 array_push($local_search, $word); 122 } 123 else 124 { 125 array_push($errors, $lang['invalid_search']); 126 } 127 } 128 $local_search = array_unique($local_search); 129 $search['fields'][$textfield] = array(); 130 $search['fields'][$textfield]['words'] = $local_search; 131 if (count($local_search) > 1) 132 { 133 $search['fields'][$textfield]['mode'] = $_POST[$textfield.'-mode']; 134 } 135 } 136 } 137 foreach ($datefields as $datefield) 138 { 139 $suffixes = array('','-after','-before'); 140 foreach ($suffixes as $suffix) 141 { 142 $field = $datefield.$suffix; 143 if (isset($_POST[$field.'-check'])) 144 { 145 $year = $_POST[$field.':year']; 146 $month = $_POST[$field.':month']; 147 $day = $_POST[$field.':day']; 148 $date = $year.'.'.$month.'.'.$day; 149 if (!checkdate($month, $day, $year)) 150 { 151 array_push($errors, $date.$lang['search_wrong_date']); 152 } 153 $search['fields'][$field] = array(); 154 $search['fields'][$field]['words'] = array($date); 155 if ($suffix == '-after' or $suffix == '-before') 156 { 157 if (isset($_POST[$field.'-included'])) 158 { 159 $search['fields'][$field]['mode'] = 'inc'; 160 } 161 } 162 } 163 } 164 if ($search['mode'] == 'AND') 165 { 166 // before date must be superior to after date 167 if (isset($search['fields'][$datefield.'-before']) 168 and isset($search['fields'][$datefield.'-after'])) 169 { 170 $after = $search['fields'][$datefield.'-after']['words'][0]; 171 $before = $search['fields'][$datefield.'-before']['words'][0]; 172 if ($after >= $before) 173 { 174 array_push($errors, $lang['search_wrong_date_order']); 175 } 176 } 177 // having "search is" and ("search is after" or "search is before") is 178 // not coherent 179 if (isset($search['fields'][$datefield]) 180 and (isset($search['fields'][$datefield.'-before']) 181 or isset($search['fields'][$datefield.'-after']))) 182 { 183 array_push($errors, $lang['search_incoherent_date_search']); 184 } 185 } 186 } 187 if (isset($_POST['categories-check'])) 188 { 189 $field = 'cat'; 190 $search['fields'][$field] = array(); 191 $search['fields'][$field]['words'] = $_POST['cat']; 38 if ($_POST['search_keywords'] && 39 !preg_match('/^\s*$/', $_POST['search_keywords'])) 40 { 41 $local_search = array(); 42 $search_keywords = $_POST['search_keywords']; 43 $drop_char_match = array('-', '^', '$', ';', '#', '&', '(', ')', '<', '>', 44 '`', '\'', '"', '|', ',', '@', '_', '?', '%', '~', '.', '[', ']', '{', '}', 45 ':', '\\', '/', '=', '\'', '!', '*'); 46 $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 47 '', '', ' ', ' ', ' ', ' ', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' 48 , ' ', '' , ' ', ' ', ' ', ' ', ' '); 49 $search_keywords = str_replace($drop_char_match, $drop_char_replace, $search_keywords); 50 51 // Split words 52 $words = preg_split('#\s+#', $search_keywords); 53 $words = array_unique($words); 54 $search['fields']['keywords'] = array(); 55 $search['fields']['keywords']['words'] =$words; 56 $search['fields']['keywords']['mode']= $_POST['mode']; 57 } 58 59 if ($_POST['search_author']) 60 { 61 $search['fields']['author'] = array(); 62 $search['fields']['author']['words'] = array($_POST['search_author']); 63 } 64 65 if (isset($_POST['cat'])) 66 { 67 $search['fields']['cat'] = array(); 68 $search['fields']['cat']['words'] = $_POST['cat']; 192 69 if (isset($_POST['subcats-included'])) 193 70 { 194 $search['fields'][ $field]['mode'] = 'sub_inc';71 $search['fields']['cat']['mode'] = 'sub_inc'; 195 72 } 196 73 } 74 75 if (!empty($_POST['start_year'])) 76 { 77 $type_date = $_POST['date_type']; 78 79 // start event 80 $date = $_POST['start_year'].'.'.$_POST['start_month'].'.'.$_POST['start_day']; 81 $search['fields'][$type_date]['words'] = array($date); 82 83 // duration 84 $search_duration = 0; 85 if ( !empty($date) && !empty( $_POST['duration_day']) ) 86 { 87 $search['fields'][$type_date]['mode'] = $_POST['duration_day']; 88 } 89 } 197 90 // search string (for URL) creation 198 91 $search_string = ''; 199 92 $tokens = array(); 93 if (!empty($search)) 94 { 200 95 foreach (array_keys($search['fields']) as $field) 201 96 { … … 211 106 if (count($tokens) > 1) 212 107 { 213 $search_string.= '| '.$search['mode'];214 } 215 216 if (count($tokens) == 0)108 $search_string.= '|AND'; 109 } 110 } 111 else 217 112 { 218 113 array_push($errors, $lang['search_one_clause_at_least']); … … 226 121 redirect($url); 227 122 } 123 228 124 //----------------------------------------------------- template initialization 125 // day list 126 $start_day = '<select name="start_day">'; 127 for ($i=0; $i <= 31; $i++) 128 { 129 $start_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; 130 } 131 $start_day .= '</select>'; 132 133 // month list 134 $start_month = '<select name="start_month">'; 135 $start_month .= '<option value="0"> ------------ </option>'; 136 for ($i=1; $i <= 12; $i++) 137 { 138 $start_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; 139 } 140 $start_month .= '</select>'; 141 142 // year list 143 $start_year = '<select name="start_year">'; 144 $start_year .= '<option value="0"> ---- </option>'; 145 $begin_year = date('Y', time())-10; 146 for ($i = $begin_year; $i <= date('Y', time()); $i++) 147 { 148 $start_year .= '<option value="' . $i . '">' . $i . '</option>'; 149 } 150 $start_year .= '</select>'; 151 152 229 153 // 230 154 // Start output of page … … 235 159 $template->set_filenames( array('search'=>'search.tpl') ); 236 160 $template->assign_vars(array( 237 'L_ TITLE' => $lang['search_title'],238 'L_SEARCH_ COMMENTS' => $lang['search_comments'],161 'L_SEARCH_TITLE' => $lang['search_title'], 162 'L_SEARCH_OPTIONS' => $lang['search_options'], 239 163 'L_RETURN' => $lang['home'], 240 164 'L_SUBMIT' => $lang['submit'], 241 'L_SEARCH_OR'=>$lang['search_mode_or'], 242 'L_SEARCH_AND'=>$lang['search_mode_and'], 243 'L_SEARCH_OR_CLAUSES'=>$lang['search_or_clauses'], 244 'L_SEARCH_AND_CLAUSES'=>$lang['search_and_clauses'], 245 'L_SEARCH_CATEGORIES'=>$lang['categories'], 246 'L_SEARCH_SUBCATS_INCLUDED'=>$lang['search_subcats_included'], 247 'L_SEARCH_DATE_INCLUDED'=> $lang['search_date_included'], 248 'L_SEARCH_DATE_IS'=>$lang['search_date_is'], 249 'L_SEARCH_DATE_IS_AFTER'=>$lang['search_date_is_after'], 250 'L_SEARCH_DATE_IS_BEFORE'=>$lang['search_date_is_before'], 251 252 'F_ACTION' => add_session_id( 'search.php' ), 253 165 'L_RESET' => $lang['reset'], 166 'L_SEARCH_KEYWORDS'=>$lang['search_keywords'], 167 'L_SEARCH_KEYWORDS_HINT'=>$lang['search_keywords_hint'], 168 'L_SEARCH_ANY_TERMS'=>$lang['search_mode_or'], 169 'L_SEARCH_ALL_TERMS'=>$lang['search_mode_and'], 170 'L_SEARCH_AUTHOR'=>$lang['search_author'], 171 'L_SEARCH_AUTHOR_HINT'=>$lang['search_explain'], 172 'L_SEARCH_CATEGORIES'=>$lang['search_categories'], 173 'L_SEARCH_CATEGORIES_HINT'=>$lang['search_categories_hint'], 174 'L_SEARCH_SUBFORUMS'=>$lang['search_subcats_included'], 175 'L_YES' => $lang['yes'], 176 'L_NO' => $lang['no'], 177 'L_SEARCH_DATE' => $lang['search_date'], 178 'L_SEARCH_DATE_HINT' => $lang['search_date_hint'], 179 'L_TODAY' => $lang['today'], 180 'L_SEARCH_DATE_FROM'=>$lang['search_date_from'], 181 'L_SEARCH_DURATION'=>$lang['search_duration'], 182 'L_DAYS'=>$lang['days'], 183 'L_MONTH'=>$lang['w_month'], 184 'L_SEARCH_DATE_TYPE'=>$lang['search_date_type'], 185 'L_SEARCH_CREATION'=>$lang['search_date_creation'], 186 'L_SEARCH_AVAILABILITY'=>$lang['search_date_available'], 187 'L_RESULT_SORT'=>$lang['search_sort'], 188 'L_SORT_ASCENDING'=>$lang['search_ascending'], 189 'L_SORT_DESCENDING'=>$lang['search_descending'], 190 191 'TODAY_DAY' => date('d', time()), 192 'TODAY_MONTH' => date('m', time()), 193 'TODAY_YEAR' => date('Y', time()), 194 'S_CALENDAR_YEAR' => $start_year, 195 'S_CALENDAR_MONTH' => $start_month, 196 'S_CALENDAR_DAY' => $start_day, 197 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), 254 198 'U_HOME' => add_session_id( 'category.php' ) 255 199 ) 256 200 ); 257 201 258 //------------------------------------------------------------ text fields form259 foreach ($textfields as $textfield)260 {261 if (isset($_POST[$textfield.'-mode']))262 {263 if ($_POST[$textfield.'-mode'] == 'AND')264 {265 $and_checked = 'checked="checked"';266 $or_checked = '';267 }268 else269 {270 $or_checked = 'checked="checked"';271 $and_checked = '';272 }273 }274 else275 {276 $or_checked = 'checked="checked"';277 $and_checked = '';278 }279 280 $value = '';281 if (isset($_POST[$textfield.'-content']))282 {283 $value = $_POST[$textfield.'-content'];284 }285 286 $template->assign_block_vars(287 'textfield',288 array('NAME'=>$lang['search_'.$textfield],289 'L_NAME'=>$textfield,290 'VALUE'=>$value,291 'OR_CHECKED'=>$or_checked,292 'AND_CHECKED'=>$and_checked293 ));294 }295 //------------------------------------------------------------- date field form296 foreach ($datefields as $datefield)297 {298 $checked = '';299 if (isset($_POST[$datefield.'-check']))300 {301 $checked = ' checked="checked"';302 }303 304 $after_checked = '';305 if (isset($_POST[$datefield.'-after-check']))306 {307 $after_checked = ' checked="checked"';308 }309 310 $before_checked = '';311 if (isset($_POST[$datefield.'-before-check']))312 {313 $before_checked = ' checked="checked"';314 }315 316 $after_included_check = '';317 if (isset($_POST[$datefield.'-after-included']))318 {319 $after_included_check = ' checked="checked"';320 }321 322 $before_included_check = '';323 if (isset($_POST[$datefield.'-before-included']))324 {325 $before_included_check = ' checked="checked"';326 }327 328 $template->assign_block_vars(329 'datefield',330 array('NAME'=>$datefield,331 'L_NAME'=>$lang['search_'.$datefield],332 'CHECKED'=>$checked,333 'AFTER_CHECKED'=>$after_checked,334 'BEFORE_CHECKED'=>$before_checked,335 'AFTER_INCLUDED_CHECKED'=>$after_included_check,336 'BEFORE_INCLUDED_CHECKED'=>$before_included_check337 ));338 display_3dates($datefield);339 }340 202 //------------------------------------------------------------- categories form 341 203 $query = ' … … 349 211 $query.= ' 350 212 ;'; 213 351 214 $selecteds = array(); 352 if (isset($_POST['submit']))353 {354 $selecteds = $_POST['cat'];355 }356 215 display_select_cat_wrapper($query, $selecteds, 'category_option', false); 357 216 358 $categories_selected = '';359 if (isset($_POST['categories-check']))360 {361 $categories_selected = 'checked="checked"';362 }363 364 $categories_subcats_selected = '';365 if (isset($_POST['subcats-included']))366 {367 $categories_subcats_selected = 'checked="checked"';368 }369 370 $template->assign_vars(371 array(372 'CATEGORIES_SELECTED'=>$categories_selected,373 'CATEGORIES_SUBCATS_SELECTED'=>$categories_subcats_selected374 )375 );376 //---------------------------------------------------------------------- OR/AND377 if (isset($_POST['mode']))378 {379 if ($_POST['mode'] == 'AND')380 {381 $and_checked = 'checked="checked"';382 $or_checked = '';383 }384 else385 {386 $or_checked = 'checked="checked"';387 $and_checked = '';388 }389 }390 else391 {392 $or_checked = 'checked="checked"';393 $and_checked = '';394 }395 396 $template->assign_vars(397 array(398 'OR_CHECKED'=>$or_checked,399 'AND_CHECKED'=>$and_checked400 )401 );402 217 //-------------------------------------------------------------- errors display 403 218 if (sizeof($errors) != 0)
Note: See TracChangeset
for help on using the changeset viewer.