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