Centralized init
[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."),$color);
39 echo '</body></html>';
40 exit;
41 }
42
43 /* GLOBALS */
44 sqgetGlobalVar('username', $username, SQ_SESSION);
45 sqgetGlobalVar('key', $key, SQ_COOKIE);
46 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
47
48 sqgetGlobalVar('submit', $submit, SQ_POST);
49
50 for($i = 0; $i <= 9; $i++){
51 $varc = 'CHECK_TEST_'.$i;
52 sqgetGlobalVar($varc, $$varc, SQ_POST);
53 $vart = 'TEST_'.$i;
54 sqgetGlobalVar($vart, $$vart, SQ_POST);
55 }
56
57 /* END GLOBALS */
58
59 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
60 $caps_array = get_caps($imap_stream);
61 $list = array ('TEST_0',
62 'TEST_1',
63 'TEST_2',
64 'TEST_3',
65 'TEST_4',
66 'TEST_5',
67 'TEST_6',
68 'TEST_7',
69 'TEST_8',
70 'TEST_9');
71
72 echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
73 '<table bgcolor="'.$color[3].'" width="100%" align="center" border="1" cellpadding="2">'.
74 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
75 '<table width="95%" align="center" border="1" bgcolor="'.$color[3]."\">\n".
76 '<tr><td bgcolor="'.$color[4].'"><b>'.
77 _("Server Capability response:").
78 "</b><br />\n";
79
80 foreach($caps_array[0] as $value) {
81 echo htmlspecialchars($value);
82 }
83
84 echo "</td></tr><tr><td>\n";
85
86 if (!isset($submit) || $submit == 'default') {
87 echo '<br /><p><small><font color="'.$color[6].'">'.
88 _("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.").
89 "</font></small></p>\n".
90 '<p align="center"><small><b>'.
91 _("NOTE: These commands are live, any changes made will effect your current email account.").
92 "</b></small></p><br />\n";
93 if (!isset($submit)) {
94 $submit = '';
95 }
96 }
97 else {
98 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
99 'default_charset = '.htmlspecialchars($default_charset)."\n";
100 }
101
102 echo "<br /></td></tr></table><br />\n";
103
104
105 if ($submit == 'submit') {
106 $type = array();
107 for ($i=0;$i<count($list);$i++) {
108 $type[$list[$i]] = $$list[$i];
109 }
110 }
111
112 elseif ($submit == 'clear') {
113 for ($i=0;$i<count($list);$i++) {
114 $type[$list[$i]] = '';
115 }
116 }
117
118 elseif (!$submit || $submit == 'default') {
119 $type = array (
120 'TEST_0' => "SELECT $mailbox",
121 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
122 'TEST_2' => "EXAMINE $mailbox",
123 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
124 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
125 'TEST_5' => "SORT (DATE) $default_charset ALL",
126 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
127 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
128 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
129 'TEST_9' => "");
130 }
131
132 echo "<form action=\"options.php\" method=\"post\">\n".
133 "<table border=\"1\" align=\"center\">\n".
134 '<tr><th>'. _("Select").
135 '</th><th>'._("Test Name").
136 '</th><th>'._("IMAP command string")."</th></tr>\n".
137 '<tr><td>';
138
139 foreach($type as $index=>$value) {
140 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
141 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
142 echo ' checked="checked"';
143 }
144 $check = "CHECK_".$index;
145 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
146 echo ' checked="checked"';
147 }
148 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
149 addInput($index, $value, 60);
150 }
151
152 echo "</td></tr></table><br />\n".
153 '<div style="text-align: center;">'.
154 addSubmit('submit','submit').
155 addSubmit('clear','submit',array('id'=>'clear')).
156 addSubmit('default','submit',array('id'=>'default')).
157 "</div><br /></form>\n";
158
159 $tests = array();
160
161 if ($submit == 'submit') {
162 foreach ($type as $index=>$value) {
163 $check = "CHECK_".$index;
164 if (isset($$check)) {
165 $type[$index] = $$index;
166 array_push($tests, $index);
167 }
168 }
169 for ($i=0;$i<count($tests);$i++) {
170 // make sure that microtime function is available before it is called
171 if (function_exists('microtime')) {
172 list($usec, $sec) = explode(" ", microtime());
173 $starttime = (float)$sec + (float)$usec;
174 }
175
176 echo '<table width="95%" align="center" border="0" bgcolor="'.$color[4]."\">\n".
177 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
178 '<tr><td><small><b><font color="'.$color[7].'">'.
179 _("Request:")."</font></b></small></td></tr>\n";
180 // imap_test function outputs imap command
181 $response = imap_test($imap_stream, $type[$tests[$i]]);
182 echo '<tr><td><small><b><font color="'.$color[7].'">'.
183 _("Response:")."</font></b></small></td></tr>\n".
184 '<tr><td>';
185 print_response($response);
186 echo "</td></tr>\n";
187
188 if (function_exists('microtime')) {
189 // get script execution time
190 list($usec, $sec) = explode(" ", microtime());
191 $endtime = (float)$sec + (float)$usec;
192 // i18n: ms = short for miliseconds
193 echo '<tr><td><small><b><font color="'.$color[7].'">'.
194 _("Execution time:")."</font></b></small></td></tr>\n".
195 '<tr><td>'.sprintf(_("%s ms"),round((($endtime - $starttime)*1000),3))."</td></tr>\n";
196 }
197
198 echo "</table><br />\n";
199 }
200 }
201 echo '</td></tr></table>';
202 sqimap_logout($imap_stream);
203
204 /**
205 * Optional hook in info plugin
206 *
207 * Hook allows attaching plugin to bottom of info plugin
208 */
209 do_hook('info_bottom');
210 ?>
211 </body></html>