X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=src%2Fsearch.php;h=e444ca013d55904e3eaa4663901c0597dc12e15c;hp=03945730b8b7ccaedf6a305e1a1cc93399a5b07e;hb=56e0b3b7cfdd52ac79cd9ed8487b8457099b6b55;hpb=3604c641607660243271429041e78d03a9c5d268;ds=sidebyside diff --git a/src/search.php b/src/search.php index 03945730..e444ca01 100644 --- a/src/search.php +++ b/src/search.php @@ -1,107 +1,351 @@ \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
"._("Search")."
\n"; - echo "
"; - - echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " "; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " "; - echo " \n"; - $what_disp = ereg_replace(",", " ", $what); - $what_disp = str_replace("\\\\", "\\", $what_disp); - $what_disp = str_replace("\\\"", "\"", $what_disp); - $what_disp = str_replace("\"", """, $what_disp); - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo "
"; - echo "
"; - do_hook("search_after_form"); - if ($where && $what) { - sqimap_mailbox_select($imapConnection, $mailbox); - sqimap_search($imapConnection, $where, $what, $mailbox, $color); - } - do_hook("search_bottom"); - sqimap_logout ($imapConnection); +function save_recent($save_index, $username, $data_dir) { + $what_array = get_recent("search_what", $username, $data_dir); + $where_array = get_recent("search_where", $username, $data_dir); + $folder_array = get_recent("search_folder", $username, $data_dir); + $saved_what_once = array_slice($what_array, $save_index, 1); + $saved_where_once = array_slice($where_array, $save_index, 1); + $saved_folder_once = array_slice($folder_array, $save_index, 1); + $saved_array = get_saved("saved_what", $username, $data_dir); + $saved_count = (count($saved_array) + 1); + setPref($data_dir, $username, "saved_what" . "$saved_count", $saved_what_once[0]); + setPref($data_dir, $username, "saved_where" . "$saved_count", $saved_where_once[0]); + setPref($data_dir, $username, "saved_folder" . "$saved_count", $saved_folder_once[0]); +} + + + +/* ------------------------ main ------------------------ */ + +// reset these arrays on each page load just in case + +$what_array = array (); +$where_array = array (); +$folder_array = array (); +$saved_what_array = array (); +$saved_where_array = array (); +$saved_folder_array = array (); +$search_all = "none"; + +// get mailbox names + +$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); +$boxes = sqimap_mailbox_list($imapConnection); + + +// set current mailbox to INBOX if none was selected or if page +// was called to search all folders. + +if ($mailbox == 'None' || $mailbox == "" ) { + $mailbox = $boxes[0]['unformatted']; +} +if ($mailbox == "all") { + $search_all = "all"; + $mailbox = $boxes[0]['unformatted']; +} + +// page headers + +displayPageHeader($color, $mailbox); + +// if the page is called from a search link or button update recent values +// in pref files here + +if ($submit == "Search" && !empty($what)) { + update_recent($what_array, $what, "search_what", $username, $data_dir); + update_recent($where_array, $where, "search_where", $username, $data_dir); + update_recent($folder_array, $mailbox, "search_folder", $username, $data_dir); +} +// if the page is called from a "forget recent" link remove search from pref file +elseif ($submit == "forget") { + forget_recent($count, $username, $data_dir); +} +// if the page is called from a "save recent" link add search to saved searches +elseif ($submit == "save") { + save_recent($count, $username, $data_dir); +} +elseif ($submit == "delete") { + delete_saved($count, $username, $data_dir); +} +// if the page is called from a "delete saved" link delete saved search +do_hook('search_before_form'); + +echo "
\n". + " \n". + " \n". + '
\n". + "
"._("Search")."
\n". + "
'; + +// update the recent and saved searches from the pref files + +$what_array = get_recent("search_what", $username, $data_dir); +$where_array = get_recent("search_where", $username, $data_dir); +$folder_array = get_recent("search_folder", $username, $data_dir); +$recent_count = getPref($data_dir, $username, 'search_memory', 0); +$saved_what_array = get_saved("saved_what", $username, $data_dir); +$saved_where_array = get_saved("saved_where", $username, $data_dir); +$saved_folder_array = get_saved("saved_folder", $username, $data_dir); +$saved_count = count($saved_what_array); + +// saved search table +if ($saved_count > 0) { + echo "
Saved Searches\n". + "\n"; + for ($i=0;$i<$saved_count;$i++) { + echo "\n". + "\n". + "
$saved_folder_array[$i]$saved_what_array[$i]$saved_where_array[$i]   \n". + "". + "edit\n". + " | search\n". + " | delete". + "  "; + } +echo "
\n"; +} + +// recent search table + +if ($recent_count > 0) { + echo "
Recent Searches\n". + "\n"; + for ($i=0;$i<$recent_count;$i++) { + if (!empty($what_array[$i])) { + if ($folder_array[$i] == "") { + $folder_array[$i] = "INBOX"; + } + echo "\n". + "\n". + "\n"; + } + } + echo "
$folder_array[$i]$what_array[$i]$where_array[$i]   ". + "save\n". + " | search\n". + " | forget". + "  
\n". + "
\n"; +} +// search form +echo "Current Search"; +echo " \n"; +echo "\n". + " \n". + ' \n". + " \n". + "\n". + " \n". + " \n". + "\n". + "
'. + " \n"; +$what_disp = str_replace(',', ' ', $what); +$what_disp = str_replace('\\\\', '\\', $what_disp); +$what_disp = str_replace('\\"', '"', $what_disp); +$what_disp = str_replace('"', '"', $what_disp); +echo " \n". + " \n". + "\n" . + " \n". + " \n". + "
\n". + "
\n"; + + +do_hook("search_after_form"); + +// search all folders option still in the works. returns a table for each +// folder it finds a match in. The toggle all link does not work + + +if ($search_all == "all") { + $mailbox == ""; + $boxcount = count($boxes); + echo "
Search Results

\n"; + for ($x=0;$x<$boxcount;$x++) { + if (!in_array('noselect', $boxes[$x]['flags'])) { + $mailbox = $boxes[$x]['unformatted']; + } + echo "
Folder: $mailbox
"; + if (($submit == "Search" || $submit == "Search_no_update") && !empty($what)) { + sqimap_mailbox_select($imapConnection, $mailbox); + sqimap_search($imapConnection, $where, $what, $mailbox, $color, $pos); + } + } +} + +// search one folder option + +else { + if (($submit == "Search" || $submit == "Search_no_update") && !empty($what)) { + echo "
Search Results
\n"; + sqimap_mailbox_select($imapConnection, $mailbox); + sqimap_search($imapConnection, $where, $what, $mailbox, $color, $pos); + } +} + +// must have search terms to search + +if ($submit == "Search" && empty($what)) { + echo "
Please enter something to search for
\n"; +} + +do_hook("search_bottom"); + +// all done + +sqimap_logout ($imapConnection); +echo ''; + ?> -