Changeset 634
- Timestamp:
- Dec 5, 2004, 12:47:40 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_category.inc.php
r630 r634 416 416 // SQL where clauses are stored in $clauses array during query 417 417 // construction 418 $clauses = $temp_clauses = array(); 419 if (isset($search['fields']['allwords'])) 420 { 421 $textfields = array('file', 'name', 'comment', 'keywords', 'author'); 422 foreach ($textfields as $textfield) 418 $clauses = array(); 419 420 $textfields = array('file', 'name', 'comment', 'keywords', 'author'); 421 foreach ($textfields as $textfield) 422 { 423 if (isset($search['fields'][$textfield])) 423 424 { 424 425 $local_clauses = array(); 425 foreach ($search['fields'][ 'allwords']['words'] as $word)426 foreach ($search['fields'][$textfield]['words'] as $word) 426 427 { 427 428 array_push($local_clauses, $textfield." LIKE '%".$word."%'"); … … 429 430 // adds brackets around where clauses 430 431 array_walk($local_clauses,create_function('&$s','$s="(".$s.")";')); 431 array_push($ temp_clauses,432 implode(' '.$search['fields'][ 'allwords']['mode'].' ',432 array_push($clauses, 433 implode(' '.$search['fields'][$textfield]['mode'].' ', 433 434 $local_clauses)); 434 435 } 435 array_push($clauses, implode(' OR ', $temp_clauses)); 436 } 437 438 if (isset($search['fields']['author'])) 439 { 440 array_push($clauses, "author LIKE '%".$search['fields']['author']['words'][0]."%'"); 441 } 436 } 437 438 if (isset($search['fields']['allwords'])) 439 { 440 $fields = array('file', 'name', 'comment', 'keywords'); 441 // in the OR mode, request bust be : 442 // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%') 443 // OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%')) 444 // 445 // in the AND mode : 446 // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%') 447 // AND (field1 LIKE '%word2%' OR field2 LIKE '%word2%')) 448 $word_clauses = array(); 449 foreach ($search['fields']['allwords']['words'] as $word) 450 { 451 $field_clauses = array(); 452 foreach ($fields as $field) 453 { 454 array_push($field_clauses, $field." LIKE '%".$word."%'"); 455 } 456 // adds brackets around where clauses 457 array_push($word_clauses, implode(' OR ', $field_clauses)); 458 } 459 array_walk($word_clauses, create_function('&$s','$s="(".$s.")";')); 460 array_push($clauses, 461 implode(' '.$search['fields']['allwords']['mode'].' ', 462 $word_clauses)); 463 } 442 464 443 465 $datefields = array('date_available', 'date_creation'); … … 447 469 if (isset($search['fields'][$key])) 448 470 { 449 $local_clause = $datefield." "; 450 if (isset($search['fields'][$key]['mode'])) 451 { 452 $local_clause .=">"; 453 } 454 $local_clause .="= '"; 455 $local_clause.= str_replace('.', '-', 471 $local_clause = $datefield." = '"; 472 $local_clause.= str_replace('.', '-', 456 473 $search['fields'][$key]['words'][0]); 457 $local_clause.= "'"; 458 array_push($clauses, $local_clause); 459 460 if (isset($search['fields'][$key]['mode'])) 461 { 462 $end_sql_date = str_replace('.', '-', 463 $search['fields'][$key]['mode']); 464 $local_clause = $datefield." <= '".$end_sql_date."'"; 465 array_push($clauses, $local_clause); 466 } 467 } 468 } 469 474 $local_clause.= "'"; 475 array_push($clauses, $local_clause); 476 } 477 478 foreach (array('after','before') as $suffix) 479 { 480 $key = $datefield.'-'.$suffix; 481 if (isset($search['fields'][$key])) 482 { 483 $local_clause = $datefield; 484 if ($suffix == 'after') 485 { 486 $local_clause.= ' >'; 487 } 488 else 489 { 490 $local_clause.= ' <'; 491 } 492 if (isset($search['fields'][$key]['mode']) 493 and $search['fields'][$key]['mode'] == 'inc') 494 { 495 $local_clause.= '='; 496 } 497 $local_clause.= " '"; 498 $local_clause.= str_replace('.', '-', 499 $search['fields'][$key]['words'][0]); 500 $local_clause.= "'"; 501 array_push($clauses, $local_clause); 502 } 503 } 504 } 505 470 506 if (isset($search['fields']['cat'])) 471 507 { … … 509 545 // adds brackets around where clauses 510 546 array_walk($clauses, create_function('&$s', '$s = "(".$s.")";')); 511 $page['where'] = 'WHERE '.implode(' AND', $clauses);547 $page['where'] = 'WHERE '.implode(' '.$search['mode'].' ', $clauses); 512 548 if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden; 513 549 -
trunk/search.php
r629 r634 36 36 if (isset($_POST['submit'])) 37 37 { 38 if ( $_POST['search_allwords'] &&39 !preg_match('/^\s*$/', $_POST['search_allwords']))38 if (isset($_POST['search_allwords']) 39 and !preg_match('/^\s*$/', $_POST['search_allwords'])) 40 40 { 41 41 $local_search = array(); 42 $search_keywords = $_POST['search_allwords']; 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); 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); 50 52 51 52 $words = preg_split('#\s+#', $search_keywords);53 // Split words 54 $words = preg_split('/\s+/', $search_allwords); 53 55 $words = array_unique($words); 54 55 $search['fields']['allwords']['words'] =$words;56 $search['fields']['allwords']['mode']= $_POST['mode'];56 $search['fields']['allwords'] = array(); 57 $search['fields']['allwords']['words'] = $words; 58 $search['fields']['allwords']['mode'] = $_POST['mode']; 57 59 } 58 60 … … 67 69 $search['fields']['cat'] = array(); 68 70 $search['fields']['cat']['words'] = $_POST['cat']; 69 if ( isset($_POST['subcats-included']))71 if ($_POST['subcats-included'] == 1) 70 72 { 71 73 $search['fields']['cat']['mode'] = 'sub_inc'; 72 74 } 73 75 } 76 77 // dates 78 $type_date = $_POST['date_type']; 74 79 75 80 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['end_year']) ) 86 { 87 $end_date = $_POST['end_year'].'.'.$_POST['end_month'].'.'.$_POST['end_day']; 88 $search['fields'][$type_date]['mode'] = $end_date; 89 } 90 } 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 } 90 91 if (!empty($_POST['end_year'])) 92 { 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'; 100 } 101 91 102 // search string (for URL) creation 92 103 $search_string = ''; … … 94 105 if (!empty($search)) 95 106 { 96 foreach (array_keys($search['fields']) as $field)97 {98 $token = $field.':';99 $token.= implode(',', $search['fields'][$field]['words']);100 if (isset($search['fields'][$field]['mode']))101 {102 $token.= '~'.$search['fields'][$field]['mode'];103 }104 array_push($tokens, $token);105 }106 $search_string.= implode(';', $tokens);107 if (count($tokens) > 1)108 {109 $search_string.= '|AND';110 }107 foreach (array_keys($search['fields']) as $field) 108 { 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); 116 } 117 $search_string.= implode(';', $tokens); 118 if (count($tokens) > 1) 119 { 120 $search_string.= '|AND'; 121 } 111 122 } 112 123 else … … 122 133 redirect($url); 123 134 } 124 125 135 //----------------------------------------------------- template initialization 126 // day list 127 $start_day = '<select name="start_day">'; 128 for ($i=0; $i <= 31; $i++) 129 { 130 $start_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; 131 } 132 $start_day .= '</select>'; 133 134 // month list 135 $start_month = '<select name="start_month">'; 136 $start_month .= '<option value="0"> ------------ </option>'; 137 for ($i=1; $i <= 12; $i++) 138 { 139 $start_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; 140 } 141 $start_month .= '</select>'; 142 143 // day list 144 $end_day = '<select name="end_day">'; 145 for ($i=0; $i <= 31; $i++) 146 { 147 $end_day .= '<option value="' . $i . '" >' . ( ($i == 0) ? ' -- ' : str_pad($i, 2, '0', STR_PAD_LEFT) ) . '</option>'; 148 } 149 $end_day .= '</select>'; 150 151 // month list 152 $end_month = '<select name="end_month">'; 153 $end_month .= '<option value="0"> ------------ </option>'; 154 for ($i=1; $i <= 12; $i++) 155 { 156 $end_month .= '<option value="' . $i . '">' . $lang['month'][$i] . '</option>'; 157 } 158 $end_month .= '</select>'; 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) 143 { 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 } 161 } 162 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) 170 { 171 global $template, $lang; 172 173 $template->assign_block_vars( 174 $blockname, array('SELECTED' => '', 175 'VALUE' => 0, 176 'OPTION' => '------------')); 177 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 } 190 } 191 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']); 159 198 160 199 // … … 199 238 'TODAY_MONTH' => date('m', time()), 200 239 'TODAY_YEAR' => date('Y', time()), 201 'E_CALENDAR_MONTH' => $end_month,202 'E_CALENDAR_DAY' => $end_day,203 'S_CALENDAR_MONTH' => $start_month,204 'S_CALENDAR_DAY' => $start_day,205 240 'S_SEARCH_ACTION' => add_session_id( 'search.php' ), 206 241 'U_HOME' => add_session_id( 'category.php' ) … … 212 247 SELECT name,id,date_last,nb_images,global_rank,uppercats 213 248 FROM '.CATEGORIES_TABLE; 214 215 216 249 if ($user['forbidden_categories'] != '') 250 { 251 $query.= ' 217 252 WHERE id NOT IN ('.$user['forbidden_categories'].')'; 218 253 } 219 254 $query.= ' 220 255 ;'; -
trunk/template/default/search.tpl
r630 r634 32 32 <td colspan="2"><b>{L_SEARCH_DATE} :</b><br /><span class="small">{L_SEARCH_DATE_HINT}</span></td> 33 33 <td colspan="2" valign="middle"> 34 <table><tr><td> 35 {L_SEARCH_DATE_FROM} :</td><td> 36 {S_CALENDAR_DAY} {S_CALENDAR_MONTH} <input name="start_year" type="text" size="4" maxlength="4"> 37 <a href="#" name="#" onClick="document.post.start_day.value={TODAY_DAY};document.post.start_month.value={TODAY_MONTH};document.post.start_year.value={TODAY_YEAR};" />{L_TODAY}</a> 38 </tr><tr><td> 39 {L_SEARCH_DATE_TO} :</td><td> 40 {E_CALENDAR_DAY} {E_CALENDAR_MONTH} <input name="end_year" type="text" size="4" maxlength="4"> 41 <a href="#" name="#" onClick="document.post.end_day.value={TODAY_DAY};document.post.end_month.value={TODAY_MONTH};document.post.end_year.value={TODAY_YEAR};" />{L_TODAY}</a> 42 </td></tr></table> 43 </td> 34 <table> 35 <tr> 36 <td>{L_SEARCH_DATE_FROM} :</td> 37 <td> 38 <select name="start_day"> 39 <!-- BEGIN start_day --> 40 <option {start_day.SELECTED} value="{start_day.VALUE}">{start_day.OPTION}</option> 41 <!-- END start_day --> 42 </select> 43 <select name="start_month"> 44 <!-- BEGIN start_month --> 45 <option {start_month.SELECTED} value="{start_month.VALUE}">{start_month.OPTION}</option> 46 <!-- END start_month --> 47 </select> 48 <input name="start_year" type="text" size="4" maxlength="4"> 49 <a href="#" name="#" onClick="document.post.start_day.value={TODAY_DAY};document.post.start_month.value={TODAY_MONTH};document.post.start_year.value={TODAY_YEAR};" />{L_TODAY}</a> 50 </td> 51 </tr> 52 <tr> 53 <td>{L_SEARCH_DATE_TO} :</td> 54 <td> 55 <select name="end_day"> 56 <!-- BEGIN end_day --> 57 <option {end_day.SELECTED} value="{end_day.VALUE}">{end_day.OPTION}</option> 58 <!-- END end_day --> 59 </select> 60 <select name="end_month"> 61 <!-- BEGIN end_month --> 62 <option {end_month.SELECTED} value="{end_month.VALUE}">{end_month.OPTION}</option> 63 <!-- END end_month --> 64 </select> 65 <input name="end_year" type="text" size="4" maxlength="4"> 66 <a href="#" name="#" onClick="document.post.end_day.value={TODAY_DAY};document.post.end_month.value={TODAY_MONTH};document.post.end_year.value={TODAY_YEAR};" />{L_TODAY}</a> 67 </td> 68 </tr> 69 </table> 70 </td> 44 71 </tr> 45 72 <tr class="admin">
Note: See TracChangeset
for help on using the changeset viewer.