SUBJECT is now the default search criteria in stead of TEXT
[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');
46d38f78 16require_once('../functions/strings.php');
c61bb006 17
29eb5486 18function s_opt( $val, $sel, $tit ) {
19 echo " <option value=\"$val\"";
0d672ac0 20 if ( $sel == $val ) {
bd9bbfef 21 echo ' selected';
99d2a184 22 }
29eb5486 23 echo ">$tit</option>\n";
24}
99d2a184 25
0d672ac0 26/* ------------------------ main ------------------------ */
27
29eb5486 28$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
c1cb7ba4 29$boxes = sqimap_mailbox_list($imapConnection);
30
31if( $mailbox == 'None' ) {
32 $mailbox = $boxes[0]['unformatted'];
33}
34
35displayPageHeader($color, $mailbox);
c61bb006 36
0d672ac0 37if( !isset( $search_memory ) ) {
38 $search_memory = 0;
39}
40
29eb5486 41do_hook('search_before_form');
42echo "<br>\n".
a7d0eaf6 43 " <table width=\"100%\" align=center cellpadding=2 cellspacing=0 border=0>\n".
0d672ac0 44 " <tr><td bgcolor=\"$color[0]\">\n".
45 " <center><b>"._("Search")."</b></center>\n".
46 " </td></tr>\n".
47 ' <tr><td align=center>';
c61bb006 48
a7d0eaf6 49if( $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
0d672ac0 59for ( $form = 0; $form <= $search_memory; $form++ ) {
c61bb006 60
0d672ac0 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", '' );
29eb5486 69 } else {
0d672ac0 70 setpref( $data_dir, $username, "search_what$frm", $$what );
71 setpref( $data_dir, $username, "search_where$frm", $$where );
72 }
29eb5486 73 }
0d672ac0 74 echo " <TABLE WIDTH=\"75%\" cellpadding=0 cellspacing=0>\n";
75 if( !($form == 0 && $search_memory > 0) ) {
29eb5486 76
a7d0eaf6 77 if( $form == $pos ) {
78 $act = $color[5];
79 } else {
80 $act = $color[4];
81 }
82
0d672ac0 83 echo "<FORM ACTION=\"$PHP_SELF\" NAME=s>\n".
84 "<input type=hidden name=pos value=\"$frm\">".
a7d0eaf6 85 " <TR bgcolor=$act><td width=10></td>\n".
86 ' <TD><SELECT NAME="mailbox">';
0d672ac0 87
0d672ac0 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 }
a7d0eaf6 99 echo ' </SELECT>'.
0d672ac0 100 " </TD>\n".
a7d0eaf6 101 " <TD ALIGN=\"CENTER\">\n";
0d672ac0 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>'.
a7d0eaf6 111 "<TD ALIGN=\"RIGHT\">\n".
0d672ac0 112 "<SELECT NAME=\"where$frm\">";
113
2ccf2baf 114 s_opt( 'SUBJECT', $$where, _("Subject") );
0d672ac0 115 s_opt( 'BODY', $$where, _("Body") );
116 s_opt( 'TEXT', $$where, _("Everywhere") );
0d672ac0 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}
29eb5486 131
0d672ac0 132echo "</td></tr></table>";
29eb5486 133do_hook("search_after_form");
0d672ac0 134if( !isset( $pos ) ) {
135 $pos = $frm;
136}
137$what = "what$pos";
138$where = "where$pos";
139
140if (isset($$where) && $$where && isset($$what) && $$what) {
29eb5486 141 sqimap_mailbox_select($imapConnection, $mailbox);
53828ec5 142 sqimap_search($imapConnection, $$where, $$what, $mailbox, $color, $pos);
29eb5486 143}
144do_hook("search_bottom");
145sqimap_logout ($imapConnection);
99d2a184 146
29eb5486 147echo '</body></html>';
99d2a184 148
43fdb2a4 149?>