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