Search Memory: Now remeber last search position and highlight search
[squirrelmail.git] / src / search.php
1 <?php
2
3 /**
4 * search.php
5 *
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * $Id$
10 */
11
12 require_once('../src/validate.php');
13 require_once('../functions/imap.php');
14 require_once('../functions/imap_search.php');
15 require_once('../functions/array.php');
16
17 function s_opt( $val, $sel, $tit ) {
18 echo " <option value=\"$val\"";
19 if ( $sel == $val ) {
20 echo ' selected';
21 }
22 echo ">$tit</option>\n";
23 }
24
25 /* ------------------------ main ------------------------ */
26
27 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
28 $boxes = sqimap_mailbox_list($imapConnection);
29
30 if( $mailbox == 'None' ) {
31 $mailbox = $boxes[0]['unformatted'];
32 }
33
34 displayPageHeader($color, $mailbox);
35
36 if( !isset( $search_memory ) ) {
37 $search_memory = 0;
38 }
39
40 do_hook('search_before_form');
41 echo "<br>\n".
42 " <table width=\"100%\" align=center cellpadding=2 cellspacing=0 border=0>\n".
43 " <tr><td bgcolor=\"$color[0]\">\n".
44 " <center><b>"._("Search")."</b></center>\n".
45 " </td></tr>\n".
46 ' <tr><td align=center>';
47
48 if( $search_memory > 0 ) {
49
50 if( isset( $pos) ) {
51 setpref( $data_dir, $username, 'search_pos', $pos );
52 } else {
53 $pos = getPref($data_dir, $username, 'search_pos', 0 );
54 }
55
56 }
57
58 for ( $form = 0; $form <= $search_memory; $form++ ) {
59
60 $frm = "$form";
61 $what = "what$frm";
62 $where = "where$frm";
63
64 if( $search_memory > 0 ) {
65 if ( $$what == '' ) {
66 $$what = getPref($data_dir, $username, "search_what$frm", '' );
67 $$where = getPref($data_dir, $username, "search_where$frm", '' );
68 } else {
69 setpref( $data_dir, $username, "search_what$frm", $$what );
70 setpref( $data_dir, $username, "search_where$frm", $$where );
71 }
72 }
73 echo " <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
74 if( !($form == 0 && $search_memory > 0) ) {
75
76 if( $form == $pos ) {
77 $act = $color[5];
78 } else {
79 $act = $color[4];
80 }
81
82 echo "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
83 "<input type=hidden name=pos value=\"$frm\">".
84 " <TR bgcolor=$act><td width=10></td>\n".
85 ' <TD><SELECT NAME="mailbox">';
86
87 for ($i = 0; $i < count($boxes); $i++) {
88 if (!in_array('noselect', $boxes[$i]['flags'])) {
89 $box = $boxes[$i]['unformatted'];
90 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
91 if ($mailbox == $box) {
92 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
93 } else {
94 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
95 }
96 }
97 }
98 echo ' </SELECT>'.
99 " </TD>\n".
100 " <TD ALIGN=\"CENTER\">\n";
101 if (!isset($$what)) {
102 $$what = '';
103 }
104 $what_disp = str_replace(',', ' ', $$what);
105 $what_disp = str_replace('\\\\', '\\', $what_disp);
106 $what_disp = str_replace('\\"', '"', $what_disp);
107 $what_disp = str_replace('"', '&quot;', $what_disp);
108 echo " <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"what$frm\" VALUE=\"$what_disp\">\n".
109 '</TD>'.
110 "<TD ALIGN=\"RIGHT\">\n".
111 "<SELECT NAME=\"where$frm\">";
112
113 s_opt( 'BODY', $$where, _("Body") );
114 s_opt( 'TEXT', $$where, _("Everywhere") );
115 s_opt( 'SUBJECT', $$where, _("Subject") );
116 s_opt( 'FROM', $$where, _("From") );
117 s_opt( 'CC', $$where, _("Cc") );
118 s_opt( 'TO', $$where, _("To") );
119
120 echo " </SELECT>\n" .
121 " </TD>\n".
122 " <TD COLSPAN=\"3\" ALIGN=\"CENTER\">\n".
123 " <INPUT TYPE=\"submit\" VALUE=\""._("Search")."\">\n".
124 " </TD>\n".
125 " </TR>\n".
126 '</FORM>';
127 }
128 echo " </TABLE>\n";
129 }
130
131 echo "</td></tr></table>";
132 do_hook("search_after_form");
133 if( !isset( $pos ) ) {
134 $pos = $frm;
135 }
136 $what = "what$pos";
137 $where = "where$pos";
138
139 if (isset($$where) && $$where && isset($$what) && $$what) {
140 sqimap_mailbox_select($imapConnection, $mailbox);
141 sqimap_search($imapConnection, $$where, $$what, $mailbox, $color, $pos);
142 }
143 do_hook("search_bottom");
144 sqimap_logout ($imapConnection);
145
146 echo '</body></html>';
147
148 ?>