Search call back adjusted to fit new format
[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=\"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>';
47
48 for ( $form = 0; $form <= $search_memory; $form++ ) {
49
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", '' );
58 } else {
59 setpref( $data_dir, $username, "search_what$frm", $$what );
60 setpref( $data_dir, $username, "search_where$frm", $$where );
61 }
62 }
63 echo " <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
64 if( !($form == 0 && $search_memory > 0) ) {
65
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
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(' ', '&nbsp;', $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('"', '&quot;', $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 }
115
116 echo "</td></tr></table>";
117 do_hook("search_after_form");
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) {
125 sqimap_mailbox_select($imapConnection, $mailbox);
126 sqimap_search($imapConnection, $$where, $$what, $mailbox, $color);
127 }
128 do_hook("search_bottom");
129 sqimap_logout ($imapConnection);
130
131 echo '</body></html>';
132
133 ?>