Centralized init
[squirrelmail.git] / plugins / info / options.php
CommitLineData
01c372f1 1<?php
4b4abf93 2
ea5f4b8e 3/**
91e0dccc 4 * options page for IMAP info plugin
5 *
a7b90f05 6 * This is where it all happens :)
91e0dccc 7 *
4b4abf93 8 * @author Jason Munro <jason at stdbev.com>
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
b11fe046 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
ea5f4b8e 12 * @package plugins
13 * @subpackage info
a7b90f05 14 */
8d6a115b 15
202bcbcc 16/**
17 * Path for SquirrelMail required files.
18 * @ignore
19 */
20require('../../include/init.php');
a7b90f05 21
cdf82d4a 22/* SquirrelMail required files. */
202bcbcc 23require_once(SM_PATH . 'functions/imap_general.php');
a9e1e670 24require_once(SM_PATH . 'functions/forms.php');
cdf82d4a 25require_once(SM_PATH . 'plugins/info/functions.php');
a7b90f05 26
27global $username, $color, $folder_prefix, $default_charset;
28$default_charset = strtoupper($default_charset);
29displayPageHeader($color, 'None');
30$mailbox = 'INBOX';
6a85a764 31
b11fe046 32/**
33 * testing installation
34 *
35 * prevent use of plugin if it is not enabled
36 */
37if (! is_plugin_enabled('info')) {
0b20cce0 38 error_box(_("Plugin is disabled."),$color);
39 echo '</body></html>';
01c372f1 40 exit;
b11fe046 41}
42
6a85a764 43/* GLOBALS */
b11fe046 44sqgetGlobalVar('username', $username, SQ_SESSION);
45sqgetGlobalVar('key', $key, SQ_COOKIE);
46sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
6a85a764 47
b587ac51 48sqgetGlobalVar('submit', $submit, SQ_POST);
6a85a764 49
50for($i = 0; $i <= 9; $i++){
b587ac51 51 $varc = 'CHECK_TEST_'.$i;
52 sqgetGlobalVar($varc, $$varc, SQ_POST);
53 $vart = 'TEST_'.$i;
54 sqgetGlobalVar($vart, $$vart, SQ_POST);
6a85a764 55}
56
57/* END GLOBALS */
58
a7b90f05 59$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
60$caps_array = get_caps($imap_stream);
01c372f1 61$list = array ('TEST_0',
a7b90f05 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
f265009a 72echo '<br /><div style="text-align: center;"><b>'._("IMAP server information")."</b></div><br />\n".
dd0bbc43 73 '<table bgcolor="'.$color[3].'" width="100%" align="center" border="1" cellpadding="2">'.
01c372f1 74 '<tr><td bgcolor="'.$color[3]."\"><br />\n".
dd0bbc43 75 '<table width="95%" align="center" border="1" bgcolor="'.$color[3]."\">\n".
01c372f1 76 '<tr><td bgcolor="'.$color[4].'"><b>'.
77 _("Server Capability response:").
78 "</b><br />\n";
a7b90f05 79
80foreach($caps_array[0] as $value) {
01c372f1 81 echo htmlspecialchars($value);
a7b90f05 82}
83
01c372f1 84echo "</td></tr><tr><td>\n";
a7b90f05 85
86if (!isset($submit) || $submit == 'default') {
01c372f1 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";
a7b90f05 93 if (!isset($submit)) {
94 $submit = '';
95 }
96}
97else {
01c372f1 98 echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
99 'default_charset = '.htmlspecialchars($default_charset)."\n";
a7b90f05 100}
101
dd0bbc43 102echo "<br /></td></tr></table><br />\n";
a7b90f05 103
104
105if ($submit == 'submit') {
106 $type = array();
107 for ($i=0;$i<count($list);$i++) {
108 $type[$list[$i]] = $$list[$i];
109 }
110}
111
112elseif ($submit == 'clear') {
113 for ($i=0;$i<count($list);$i++) {
114 $type[$list[$i]] = '';
115 }
116}
117
118elseif (!$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\" \"*%\"",
3f6dd931 128 'TEST_8' => "LIST \"$folder_prefix\" \"*\"",
a7b90f05 129 'TEST_9' => "");
130}
131
01c372f1 132echo "<form action=\"options.php\" method=\"post\">\n".
dd0bbc43 133 "<table border=\"1\" align=\"center\">\n".
01c372f1 134 '<tr><th>'. _("Select").
135 '</th><th>'._("Test Name").
136 '</th><th>'._("IMAP command string")."</th></tr>\n".
137 '<tr><td>';
a7b90f05 138
139foreach($type as $index=>$value) {
01c372f1 140 echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
a7b90f05 141 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
01c372f1 142 echo ' checked="checked"';
a7b90f05 143 }
144 $check = "CHECK_".$index;
145 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
01c372f1 146 echo ' checked="checked"';
a7b90f05 147 }
01c372f1 148 echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
149 addInput($index, $value, 60);
a7b90f05 150}
151
dd0bbc43 152echo "</td></tr></table><br />\n".
f265009a 153 '<div style="text-align: center;">'.
01c372f1 154 addSubmit('submit','submit').
dd0bbc43 155 addSubmit('clear','submit',array('id'=>'clear')).
156 addSubmit('default','submit',array('id'=>'default')).
f265009a 157 "</div><br /></form>\n";
a7b90f05 158
159$tests = array();
160
161if ($submit == 'submit') {
162 foreach ($type as $index=>$value) {
163 $check = "CHECK_".$index;
164 if (isset($$check)) {
165 $type[$index] = $$index;
91e0dccc 166 array_push($tests, $index);
a7b90f05 167 }
168 }
169 for ($i=0;$i<count($tests);$i++) {
3f6dd931 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
dd0bbc43 176 echo '<table width="95%" align="center" border="0" bgcolor="'.$color[4]."\">\n".
01c372f1 177 '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
178 '<tr><td><small><b><font color="'.$color[7].'">'.
7431eca9 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].'">'.
01c372f1 183 _("Response:")."</font></b></small></td></tr>\n".
184 '<tr><td>';
a7b90f05 185 print_response($response);
3f6dd931 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
dd0bbc43 198 echo "</table><br />\n";
a7b90f05 199 }
200}
dd0bbc43 201echo '</td></tr></table>';
7431eca9 202sqimap_logout($imap_stream);
b11fe046 203
204/**
205 * Optional hook in info plugin
206 *
207 * Hook allows attaching plugin to bottom of info plugin
208 */
209do_hook('info_bottom');
a7b90f05 210?>
91e0dccc 211</body></html>