eddf8ae3943bf7c20ca5846350dae3cc7623b350
[squirrelmail.git] / src / search.php
1 <?php
2
3 /**
4 * right_main.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 displayPageHeader($color, $mailbox);
28 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
29
30 if( !isset( $search_memory ) ) {
31 $search_memory = 0;
32 }
33
34 do_hook('search_before_form');
35 echo "<br>\n".
36 " <table width=\"95%\" align=center cellpadding=2 cellspacing=0 border=0>\n".
37 " <tr><td bgcolor=\"$color[0]\">\n".
38 " <center><b>"._("Search")."</b></center>\n".
39 " </td></tr>\n".
40 ' <tr><td align=center>';
41
42 for ( $form = 0; $form <= $search_memory; $form++ ) {
43
44 $frm = "$form";
45 $what = "what$frm";
46 $where = "where$frm";
47
48 if( $search_memory > 0 ) {
49 if ( $$what == '' ) {
50 $$what = getPref($data_dir, $username, "search_what$frm", '' );
51 $$where = getPref($data_dir, $username, "search_where$frm", '' );
52 } else {
53 setpref( $data_dir, $username, "search_what$frm", $$what );
54 setpref( $data_dir, $username, "search_where$frm", $$where );
55 }
56 }
57 echo " <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
58 if( !($form == 0 && $search_memory > 0) ) {
59
60 echo "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
61 "<input type=hidden name=pos value=\"$frm\">".
62 " <TR>\n".
63 " <TD WIDTH=\"33%\">\n".
64 ' <TT><SMALL><SELECT NAME="mailbox">';
65
66 $boxes = sqimap_mailbox_list($imapConnection);
67
68 for ($i = 0; $i < count($boxes); $i++) {
69 if (!in_array('noselect', $boxes[$i]['flags'])) {
70 $box = $boxes[$i]['unformatted'];
71 $box2 = str_replace(' ', '&nbsp;', $boxes[$i]['unformatted-disp']);
72 if ($mailbox == $box) {
73 echo " <OPTION VALUE=\"$box\" SELECTED>$box2</OPTION>\n";
74 } else {
75 echo " <OPTION VALUE=\"$box\">$box2</OPTION>\n";
76 }
77 }
78 }
79 echo ' </SELECT></SMALL></TT>'.
80 " </TD>\n".
81 " <TD ALIGN=\"CENTER\" WIDTH=\"33%\">\n";
82 if (!isset($$what)) {
83 $$what = '';
84 }
85 $what_disp = str_replace(',', ' ', $$what);
86 $what_disp = str_replace('\\\\', '\\', $what_disp);
87 $what_disp = str_replace('\\"', '"', $what_disp);
88 $what_disp = str_replace('"', '&quot;', $what_disp);
89 echo " <INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"what$frm\" VALUE=\"$what_disp\">\n".
90 '</TD>'.
91 "<TD ALIGN=\"RIGHT\" WIDTH=\"33%\">\n".
92 "<SELECT NAME=\"where$frm\">";
93
94 s_opt( 'BODY', $$where, _("Body") );
95 s_opt( 'TEXT', $$where, _("Everywhere") );
96 s_opt( 'SUBJECT', $$where, _("Subject") );
97 s_opt( 'FROM', $$where, _("From") );
98 s_opt( 'CC', $$where, _("Cc") );
99 s_opt( 'TO', $$where, _("To") );
100
101 echo " </SELECT>\n" .
102 " </TD>\n".
103 " <TD COLSPAN=\"3\" ALIGN=\"CENTER\">\n".
104 " <INPUT TYPE=\"submit\" VALUE=\""._("Search")."\">\n".
105 " </TD>\n".
106 " </TR>\n".
107 '</FORM>';
108 }
109 echo " </TABLE>\n";
110 }
111
112 echo "</td></tr></table>";
113 do_hook("search_after_form");
114 if( !isset( $pos ) ) {
115 $pos = $frm;
116 }
117 $what = "what$pos";
118 $where = "where$pos";
119
120 if (isset($$where) && $$where && isset($$what) && $$what) {
121 sqimap_mailbox_select($imapConnection, $mailbox);
122 sqimap_search($imapConnection, $$where, $$what, $mailbox, $color);
123 }
124 do_hook("search_bottom");
125 sqimap_logout ($imapConnection);
126
127 echo '</body></html>';
128
129 ?>