Cleaning and bug-fix. Added base uri to read mail.
[squirrelmail.git] / src / search.php
CommitLineData
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 12require_once('../src/validate.php');
13require_once('../functions/imap.php');
14require_once('../functions/imap_search.php');
15require_once('../functions/array.php');
c61bb006 16
29eb5486 17function 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
30if( $mailbox == 'None' ) {
31 $mailbox = $boxes[0]['unformatted'];
32}
33
34displayPageHeader($color, $mailbox);
c61bb006 35
0d672ac0 36if( !isset( $search_memory ) ) {
37 $search_memory = 0;
38}
39
29eb5486 40do_hook('search_before_form');
41echo "<br>\n".
a7d0eaf6 42 " <table width=\"100%\" align=center cellpadding=2 cellspacing=0 border=0>\n".
0d672ac0 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
a7d0eaf6 48if( $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
0d672ac0 58for ( $form = 0; $form <= $search_memory; $form++ ) {
c61bb006 59
0d672ac0 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", '' );
29eb5486 68 } else {
0d672ac0 69 setpref( $data_dir, $username, "search_what$frm", $$what );
70 setpref( $data_dir, $username, "search_where$frm", $$where );
71 }
29eb5486 72 }
0d672ac0 73 echo " <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
74 if( !($form == 0 && $search_memory > 0) ) {
29eb5486 75
a7d0eaf6 76 if( $form == $pos ) {
77 $act = $color[5];
78 } else {
79 $act = $color[4];
80 }
81
0d672ac0 82 echo "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
83 "<input type=hidden name=pos value=\"$frm\">".
a7d0eaf6 84 " <TR bgcolor=$act><td width=10></td>\n".
85 ' <TD><SELECT NAME="mailbox">';
0d672ac0 86
0d672ac0 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 }
a7d0eaf6 98 echo ' </SELECT>'.
0d672ac0 99 " </TD>\n".
a7d0eaf6 100 " <TD ALIGN=\"CENTER\">\n";
0d672ac0 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>'.
a7d0eaf6 110 "<TD ALIGN=\"RIGHT\">\n".
0d672ac0 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}
29eb5486 130
0d672ac0 131echo "</td></tr></table>";
29eb5486 132do_hook("search_after_form");
0d672ac0 133if( !isset( $pos ) ) {
134 $pos = $frm;
135}
136$what = "what$pos";
137$where = "where$pos";
138
139if (isset($$where) && $$where && isset($$what) && $$what) {
29eb5486 140 sqimap_mailbox_select($imapConnection, $mailbox);
53828ec5 141 sqimap_search($imapConnection, $$where, $$what, $mailbox, $color, $pos);
29eb5486 142}
143do_hook("search_bottom");
144sqimap_logout ($imapConnection);
99d2a184 145
29eb5486 146echo '</body></html>';
99d2a184 147
0d672ac0 148?>