8da3dd9e2e8703c99ac6dad0761845689dea74d4
[squirrelmail.git] / plugins / info / options.php
1 <?php
2
3 /**
4 * options page for IMAP info plugin
5 *
6 * This is where it all happens :)
7 *
8 * @author Jason Munro <jason at stdbev.com>
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package plugins
13 * @subpackage info
14 */
15
16 /**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 require('../../include/init.php');
21
22 /* SquirrelMail required files. */
23 require_once(SM_PATH . 'functions/imap_general.php');
24 require_once(SM_PATH . 'functions/forms.php');
25 require_once(SM_PATH . 'plugins/info/functions.php');
26
27 global $username, $color, $folder_prefix, $default_charset;
28 $default_charset = strtoupper($default_charset);
29 displayPageHeader($color, 'None');
30 $mailbox = 'INBOX';
31
32 /**
33 * testing installation
34 *
35 * prevent use of plugin if it is not enabled
36 */
37 if (! is_plugin_enabled('info')) {
38 error_box(_("Plugin is disabled."));
39 // display footer (closes html) and stop script execution
40 $oTemplate->display('footer.tpl');
41 exit;
42 }
43
44 /* GLOBALS */
45 sqgetGlobalVar('submit', $submit, SQ_POST);
46
47 for($i = 0; $i <= 9; $i++){
48 $varc = 'CHECK_TEST_'.$i;
49 sqgetGlobalVar($varc, $$varc, SQ_POST);
50 $vart = 'TEST_'.$i;
51 sqgetGlobalVar($vart, $$vart, SQ_POST);
52 }
53
54 /* END GLOBALS */
55
56 $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
57 $caps_array = get_caps($imap_stream);
58 $list = array ('TEST_0',
59 'TEST_1',
60 'TEST_2',
61 'TEST_3',
62 'TEST_4',
63 'TEST_5',
64 'TEST_6',
65 'TEST_7',
66 'TEST_8',
67 'TEST_9');
68
69 echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
70 '<table bgcolor="'.$color[3].'" width="100%" align="center" border="1" cellpadding="2">'.
71 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
72 '<table width="95%" align="center" border="1" bgcolor="'.$color[3]."\">\n".
73 '<tr><td bgcolor="'.$color[4].'"><b>'.
74 _("Server Capability response:").
75 "</b><br />\n";
76
77 foreach($caps_array[0] as $value) {
78 echo htmlspecialchars($value);
79 }
80
81 echo "</td></tr><tr><td>\n";
82
83 if (!isset($submit) || $submit == 'default') {
84 echo '<br /><p><small><font color="'.$color[6].'">'.
85 _("Select the IMAP commands you would like to run. Most commands require a selected mailbox so the select command is already setup. You can clear all the commands and test your own IMAP command strings. The commands are executed in order. The default values are simple IMAP commands using your default_charset and folder_prefix from SquirrelMail when needed.").
86 "</font></small></p>\n".
87 '<p align="center"><small><b>'.
88 _("NOTE: These commands are live, any changes made will effect your current email account.").
89 "</b></small></p><br />\n";
90 if (!isset($submit)) {
91 $submit = '';
92 }
93 }
94 else {
95 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
96 'default_charset = '.htmlspecialchars($default_charset)."\n";
97 }
98
99 echo "<br /></td></tr></table><br />\n";
100
101
102 if ($submit == 'submit') {
103 $type = array();
104 for ($i=0;$i<count($list);$i++) {
105 $type[$list[$i]] = $$list[$i];
106 }
107 }
108
109 elseif ($submit == 'clear') {
110 for ($i=0;$i<count($list);$i++) {
111 $type[$list[$i]] = '';
112 }
113 }
114
115 elseif (!$submit || $submit == 'default') {
116 $type = array (
117 'TEST_0' => "SELECT $mailbox",
118 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
119 'TEST_2' => "EXAMINE $mailbox",
120 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
121 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
122 'TEST_5' => "SORT (DATE) $default_charset ALL",
123 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
124 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
125 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
126 'TEST_9' => "");
127 }
128
129 echo "<form action=\"options.php\" method=\"post\">\n".
130 "<table border=\"1\" align=\"center\">\n".
131 '<tr><th>'. _("Select").
132 '</th><th>'._("Test Name").
133 '</th><th>'._("IMAP command string")."</th></tr>\n".
134 '<tr><td>';
135
136 foreach($type as $index=>$value) {
137 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
138 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
139 echo ' checked="checked"';
140 }
141 $check = "CHECK_".$index;
142 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
143 echo ' checked="checked"';
144 }
145 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
146 addInput($index, $value, 60);
147 }
148
149 echo "</td></tr></table><br />\n".
150 '<div style="text-align: center;">'.
151 addSubmit('submit','submit').
152 addSubmit('clear','submit',array('id'=>'clear')).
153 addSubmit('default','submit',array('id'=>'default')).
154 "</div><br /></form>\n";
155
156 $tests = array();
157
158 if ($submit == 'submit') {
159 foreach ($type as $index=>$value) {
160 $check = "CHECK_".$index;
161 if (isset($$check)) {
162 $type[$index] = $$index;
163 array_push($tests, $index);
164 }
165 }
166 for ($i=0;$i<count($tests);$i++) {
167 // make sure that microtime function is available before it is called
168 if (function_exists('microtime')) {
169 list($usec, $sec) = explode(" ", microtime());
170 $starttime = (float)$sec + (float)$usec;
171 }
172
173 echo '<table width="95%" align="center" border="0" bgcolor="'.$color[4]."\">\n".
174 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
175 '<tr><td><small><b><font color="'.$color[7].'">'.
176 _("Request:")."</font></b></small></td></tr>\n";
177 // imap_test function outputs imap command
178 $response = imap_test($imap_stream, $type[$tests[$i]]);
179 echo '<tr><td><small><b><font color="'.$color[7].'">'.
180 _("Response:")."</font></b></small></td></tr>\n".
181 '<tr><td>';
182 print_response($response);
183 echo "</td></tr>\n";
184
185 if (function_exists('microtime')) {
186 // get script execution time
187 list($usec, $sec) = explode(" ", microtime());
188 $endtime = (float)$sec + (float)$usec;
189 // i18n: ms = short for miliseconds
190 echo '<tr><td><small><b><font color="'.$color[7].'">'.
191 _("Execution time:")."</font></b></small></td></tr>\n".
192 '<tr><td>'.sprintf(_("%s ms"),round((($endtime - $starttime)*1000),3))."</td></tr>\n";
193 }
194
195 echo "</table><br />\n";
196 }
197 }
198 echo '</td></tr></table>';
199 sqimap_logout($imap_stream);
200
201 /**
202 * Optional hook in info plugin
203 *
204 * Hook allows attaching plugin to bottom of info plugin
205 */
206 do_hook('info_bottom');
207 ?>
208 </body></html>