[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * $Horde: imp/search.php,v 2.128.2.23 2007/01/02 13:54:54 jan Exp $ 4 * 5 * Copyright 1999-2007 Charles J. Hagenbuch <chuck@horde.org> 6 * Copyright 1999-2007 Jon Parise <jon@horde.org> 7 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 8 * 9 * See the enclosed file COPYING for license information (GPL). If you 10 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 11 * 12 * URL Parameters: 13 * --------------- 14 * 'search_mailbox' -- If exists, don't show the folder selection list; use 15 * the passed in mailbox value instead. 16 * 'edit_query' -- If exists, the search query to edit. 17 */ 18 19 /** 20 * Generates the HTML for a day selection widget. 21 * 22 * @param string $name The name of the widget. 23 * @param integer $default The value to select by default. Range: 1-31 24 * @param string $params Any additional parameters to include in the <a> 25 * tag. 26 * 27 * @return string The HTML <select> widget. 28 */ 29 function buildDayWidget($name, $default = null, $params = null) 30 { 31 $html = '<select id="' . $name . '" name="' . $name. '"'; 32 if (!is_null($params)) { 33 $html .= ' ' . $params; 34 } 35 $html .= '>'; 36 37 for ($day = 1; $day <= 31; $day++) { 38 $html .= '<option value="' . $day . '"'; 39 $html .= ($day == $default) ? ' selected="selected">' : '>'; 40 $html .= $day . '</option>'; 41 } 42 43 return $html . "</select>\n"; 44 } 45 46 /** 47 * Generates the HTML for a month selection widget. 48 * 49 * @param string $name The name of the widget. 50 * @param integer $default The value to select by default. 51 * @param string $params Any additional parameters to include in the <a> 52 * tag. 53 * 54 * @return string The HTML <select> widget. 55 */ 56 function buildMonthWidget($name, $default = null, $params = null) 57 { 58 $html = '<select id="' . $name . '" name="' . $name. '"'; 59 if (!is_null($params)) { 60 $html .= ' ' . $params; 61 } 62 $html .= '>'; 63 64 for ($month = 1; $month <= 12; $month++) { 65 $html .= '<option value="' . $month . '"'; 66 $html .= ($month == $default) ? ' selected="selected">' : '>'; 67 $html .= strftime('%B', mktime(0, 0, 0, $month, 1)) . '</option>'; 68 } 69 70 return $html . "</select>\n"; 71 } 72 73 /** 74 * Generates the HTML for a year selection widget. 75 * 76 * @param integer $name The name of the widget. 77 * @param integer $years The number of years to include. 78 * If (+): future years 79 * If (-): past years 80 * @param string $default The timestamp to select by default. 81 * @param string $params Any additional parameters to include in the <a> 82 * tag. 83 * 84 * @return string The HTML <select> widget. 85 */ 86 function buildYearWidget($name, $years, $default = null, $params = null) 87 { 88 $curr_year = date('Y'); 89 $yearlist = array(); 90 91 $startyear = (!is_null($default) && ($default < $curr_year) && ($years > 0)) ? $default : $curr_year; 92 $startyear = min($startyear, $startyear + $years); 93 for ($i = 0; $i <= abs($years); $i++) { 94 $yearlist[] = $startyear++; 95 } 96 if ($years < 0) { 97 $yearlist = array_reverse($yearlist); 98 } 99 100 $html = '<select id="' . $name . '" name="' . $name. '"'; 101 if (!is_null($params)) { 102 $html .= ' ' . $params; 103 } 104 $html .= '>'; 105 106 foreach ($yearlist as $year) { 107 $html .= '<option value="' . $year . '"'; 108 $html .= ($year == $default) ? ' selected="selected">' : '>'; 109 $html .= $year . '</option>'; 110 } 111 112 return $html . "</select>\n"; 113 } 114 115 define('IMP_BASE', dirname(__FILE__)); 116 $authentication = OP_HALFOPEN; 117 require_once IMP_BASE . '/lib/base.php'; 118 require_once IMP_BASE . '/lib/Folder.php'; 119 require_once IMP_BASE . '/lib/Search.php'; 120 121 $actionID = Util::getFormData('actionID'); 122 $edit_query = Util::getFormData('edit_query'); 123 $edit_query_id = Util::getFormData('edit_query_id', $edit_query); 124 $edit_query_vfolder = Util::getFormData('edit_query_vfolder'); 125 $search_mailbox = Util::getFormData('search_mailbox'); 126 127 $imp_search_fields = $imp_search->searchFields(); 128 129 /* Get URL parameter data. */ 130 $search = array(); 131 if (Util::getFormData('no_match')) { 132 $search = $imp_search->retrieveUIQuery(); 133 } elseif (!is_null($edit_query) && $imp_search->isSearchMbox($edit_query)) { 134 if ($imp_search->isVFolder($edit_query)) { 135 $edit_query_vfolder = true; 136 if (!$imp_search->isEditableVFolder($edit_query)) { 137 $notification->push(_("Special Virtual Folders cannot be edited."), 'horde.error'); 138 header('Location: ' . Horde::applicationUrl('mailbox.php', true)); 139 exit; 140 } 141 } 142 $search = $imp_search->retrieveUIQuery($edit_query); 143 } 144 if (empty($search)) { 145 if (empty($actionID) && 146 ($def_search = $prefs->getValue('default_search'))) { 147 $search['field'] = array($def_search); 148 } else { 149 $search['field'] = Util::getFormData('field', array()); 150 if (!empty($search['field']) && !end($search['field'])) { 151 array_pop($search['field']); 152 } 153 } 154 $search['field_end'] = count($search['field']); 155 $search['match'] = Util::getFormData('search_match'); 156 $search['text'] = Util::getFormData('search_text'); 157 $search['text_not'] = Util::getFormData('search_text_not'); 158 $search['date'] = Util::getFormData('search_date'); 159 $search['flag'] = Util::getFormData('search_flag'); 160 $search['folders'] = Util::getFormData('search_folders', array()); 161 $search['save_vfolder'] = Util::getFormData('save_vfolder'); 162 $search['vfolder_label'] = Util::getFormData('vfolder_label'); 163 $search['mbox'] = Util::getFormData('mbox', $search_mailbox); 164 } 165 166 $curr_date = getdate(); 167 168 /* Run through the action handlers. */ 169 switch ($actionID) { 170 case 'do_search': 171 /* Create the search query. */ 172 require_once IMP_BASE . '/lib/IMAP/Search.php'; 173 $query = &new IMP_IMAP_Search_Query(); 174 175 /* Flag searches. */ 176 $flag_names = array( 177 IMP_SEARCH_FLAG_SEEN => 'seen', 178 IMP_SEARCH_FLAG_ANSWERED => 'answered', 179 IMP_SEARCH_FLAG_FLAGGED => 'flagged', 180 IMP_SEARCH_FLAG_DELETED => 'deleted' 181 ); 182 183 foreach ($search['flag'] as $key => $val) { 184 $flag = $flag_names[$key]; 185 switch ($val) { 186 case 0: 187 $query->$flag(true); 188 break; 189 case 1: 190 $query->$flag(false); 191 break; 192 } 193 } 194 195 /* Field searches. */ 196 $search_array = array(); 197 foreach ($search['field'] as $key => $val) { 198 $ob = &new IMP_IMAP_Search_Query(); 199 switch ($imp_search_fields[$val]['type']) { 200 case IMP_SEARCH_HEADER: 201 if (!empty($search['text'][$key])) { 202 $ob->header($val, $search['text'][$key], $search['text_not'][$key]); 203 $search_array[] = $ob; 204 } 205 break; 206 207 case IMP_SEARCH_BODY: 208 if (!empty($search['text'][$key])) { 209 $ob->body($search['text'][$key], $search['text_not'][$key]); 210 $search_array[] = $ob; 211 } 212 break; 213 214 case IMP_SEARCH_TEXT: 215 if (!empty($search['text'][$key])) { 216 $ob->text($search['text'][$key], $search['text_not'][$key]); 217 $search_array[] = $ob; 218 } 219 break; 220 221 case IMP_SEARCH_DATE: 222 if (!empty($search['date'][$key]['day']) && 223 !empty($search['date'][$key]['month']) && 224 !empty($search['date'][$key]['year'])) { 225 if ($val == 'received_on') { 226 $ob->on($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); 227 } elseif ($val == 'received_until') { 228 $ob->before($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); 229 } elseif ($val == 'received_since') { 230 $ob->since($search['date'][$key]['day'], $search['date'][$key]['month'], $search['date'][$key]['year']); 231 } 232 $search_array[] = $ob; 233 } 234 break; 235 } 236 } 237 238 /* Search match. */ 239 if ($search['match'] == 'and') { 240 $query->imapAnd($search_array); 241 } elseif ($search['match'] == 'or') { 242 $query->imapOr($search_array); 243 } 244 245 /* Save the search as a virtual folder if requested. */ 246 if (!empty($search['save_vfolder'])) { 247 if (empty($search['vfolder_label'])) { 248 $notification->push(_("Virtual Folders require a label."), 'horde.error'); 249 break; 250 } 251 252 if ($edit_query_id) { 253 $imp_search->deleteSearchQuery($edit_query_id); 254 } 255 $id = $imp_search->addVFolder($query, $search['folders'], $search, $search['vfolder_label']); 256 $notification->push(sprintf(_("Virtual Folder \"%s\" created succesfully."), $search['vfolder_label']), 'horde.success'); 257 } else { 258 /* Set the search in the IMP session. */ 259 $id = $imp_search->createSearchQuery($query, $search['folders'], $search, _("Search Results")); 260 } 261 262 /* Redirect to the Mailbox Screen. */ 263 header('Location: ' . Util::addParameter(Horde::applicationUrl('mailbox.php', true), 'mailbox', $GLOBALS['imp_search']->createSearchID($id), false)); 264 exit; 265 266 case 'reset_search': 267 if ($def_search = $prefs->getValue('default_search')) { 268 $search['field'] = array($def_search); 269 $search['field_end'] = 1; 270 } else { 271 $search['field'] = array(); 272 $search['field_end'] = 0; 273 } 274 $search['match'] = null; 275 $search['date'] = $search['text'] = $search['text_not'] = $search['flag'] = array(); 276 $search['folders'] = array(); 277 break; 278 279 case 'delete_field': 280 $key = Util::getFormData('delete_field_id'); 281 282 /* Unset all entries in array input and readjust ids. */ 283 $vars = array('field', 'text', 'text_not', 'date'); 284 foreach ($vars as $val) { 285 unset($search[$val][$key]); 286 if (!empty($search[$val])) { 287 $search[$val] = array_values($search[$val]); 288 } 289 } 290 $search['field_end'] = count($search['field']); 291 break; 292 } 293 294 $subscribe = 0; 295 if (!$conf['user']['allow_folders']) { 296 $search['mbox'] = 'INBOX'; 297 $search['folders'][] = 'INBOX'; 298 $subscribe = false; 299 } elseif ($subscribe = $prefs->getValue('subscribe')) { 300 $shown = Util::getFormData('show_subscribed_only', $subscribe); 301 } 302 303 $title = _("Message Search"); 304 if ($edit_query_id) { 305 $submit_label = _("Save"); 306 } else { 307 $submit_label = _("Submit"); 308 } 309 require IMP_TEMPLATES . '/common-header.inc'; 310 require IMP_TEMPLATES . '/menu.inc'; 311 IMP::status(); 312 require IMP_TEMPLATES . '/search/javascript.inc'; 313 require IMP_TEMPLATES . '/search/header.inc'; 314 315 /* Process the list of fields. */ 316 for ($i = 0; $i <= $search['field_end']; $i++) { 317 $last_field = ($i == $search['field_end']); 318 $curr_field = (isset($search['field'][$i])) ? $search['field'][$i] : null; 319 require IMP_TEMPLATES . '/search/fields.inc'; 320 } 321 322 $newcol = 1; 323 $numcolumns = 1; 324 $folderlist = ''; 325 $imp_folder = &IMP_Folder::singleton(); 326 327 if (empty($search['mbox'])) { 328 $mailboxes = $imp_folder->flist_IMP(array(), (isset($shown)) ? (bool) $shown : null); 329 $total = ceil(count($mailboxes) / 3); 330 331 if (empty($search['folders']) && ($actionID != 'update_search')) { 332 /* Default to Inbox search. */ 333 $search['folders'][] = 'INBOX'; 334 } 335 336 $count = 0; 337 foreach ($mailboxes as $mbox) { 338 $newcol++; 339 if (!empty($mbox['val'])) { 340 $folderlist .= '<input id="folder' . $count . '" type="checkbox" name="search_folders[]" value="' . htmlspecialchars($mbox['val']) . '"'; 341 if (in_array($mbox['val'], $search['folders'])) { 342 $folderlist .= ' checked="checked"'; 343 } 344 } else { 345 $folderlist .= '<input id="folder' . $count . '" type="checkbox" disabled="disabled"'; 346 } 347 348 $folderlist .= " />\n" . Horde::label('folder' . $count++, str_replace(' ', ' ', $mbox['label']), '') . "<br />\n"; 349 350 if (($newcol > $total) && ($numcolumns != 3)) { 351 $newcol = 1; 352 $numcolumns++; 353 $folderlist .= "</td>\n" . '<td class="item leftAlign" valign="top">'; 354 } 355 } 356 } 357 358 require IMP_TEMPLATES . '/search/main.inc'; 359 require $registry->get('templates', 'horde') . '/common-footer.inc';
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |