cleanup some plugins to make use of sqgetGlobalVar
[squirrelmail.git] / plugins / info / options.php
1 <?PHP
2
3 /* options page for IMAP info plugin
4 * Copyright (c) 1999-2003 The SquirrelMail Project Team
5 * Licensed under the GNU GPL. For full terms see the file COPYING.
6 *
7 * This is where it all happens :)
8 *
9 * Written by: Jason Munro
10 * jason@stdbev.com
11 *
12 * $Id$
13 *
14 */
15
16 define('SM_PATH','../../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/page_header.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'plugins/info/functions.php');
23
24 global $username, $color, $folder_prefix, $default_charset;
25 $default_charset = strtoupper($default_charset);
26 displayPageHeader($color, 'None');
27 $mailbox = 'INBOX';
28
29 /* GLOBALS */
30 sqgetGlobalVar('username', $username, SQ_SESSION);
31 sqgetGlobalVar('key', $key, SQ_COOKIE);
32 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34 sqgetGlobalVar('submit', $submit, SQ_POST);
35
36 for($i = 0; $i <= 9; $i++){
37 $varc = 'CHECK_TEST_'.$i;
38 sqgetGlobalVar($varc, $$varc, SQ_POST);
39 $vart = 'TEST_'.$i;
40 sqgetGlobalVar($vart, $$vart, SQ_POST);
41 }
42
43 /* END GLOBALS */
44
45 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
46 $caps_array = get_caps($imap_stream);
47 $list = array (
48 'TEST_0',
49 'TEST_1',
50 'TEST_2',
51 'TEST_3',
52 'TEST_4',
53 'TEST_5',
54 'TEST_6',
55 'TEST_7',
56 'TEST_8',
57 'TEST_9');
58
59 print "<BR><CENTER><B>IMAP server information</B></CENTER><BR>\n";
60 print "<CENTER><TABLE BGCOLOR=".$color[3]." WIDTH=\"100%\" BORDER=1 CELLPADDING=2><TR><TD BGCOLOR=".$color[3]."><BR>\n";
61 print "<CENTER><TABLE WIDTH=\"95%\" BORDER=1 BGCOLOR=".$color[3].">\n";
62 print "<TR><TD BGCOLOR=".$color[4]."><B>Server Capability response:</B><BR>\n";
63
64 foreach($caps_array[0] as $value) {
65 print $value;
66 }
67
68 print "</TD></TR><TR><TD>\n";
69
70 if (!isset($submit) || $submit == 'default') {
71 print "<BR><SMALL><FONT COLOR=".$color[6].">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.<BR><BR><B><CENTER>NOTE: These commands are live, any changes made will effect your current email account.</B></CENTER></FONT></SMALL><BR>\n";
72 if (!isset($submit)) {
73 $submit = '';
74 }
75 }
76 else {
77 print "folder_prefix = $folder_prefix<BR>\n";
78 print "default_charset = $default_charset\n";
79 }
80
81 print "<BR></TD></TR></TABLE></CENTER><BR>\n";
82
83
84 if ($submit == 'submit') {
85 $type = array();
86 for ($i=0;$i<count($list);$i++) {
87 $type[$list[$i]] = $$list[$i];
88 }
89 }
90
91 elseif ($submit == 'clear') {
92 for ($i=0;$i<count($list);$i++) {
93 $type[$list[$i]] = '';
94 }
95 }
96
97 elseif (!$submit || $submit == 'default') {
98 $type = array (
99 'TEST_0' => "SELECT $mailbox",
100 'TEST_1' => "STATUS $mailbox (MESSAGES RECENT)",
101 'TEST_2' => "EXAMINE $mailbox",
102 'TEST_3' => "SEARCH CHARSET \"$default_charset\" ALL *",
103 'TEST_4' => "THREAD REFERENCES $default_charset ALL",
104 'TEST_5' => "SORT (DATE) $default_charset ALL",
105 'TEST_6' => "FETCH 1:* (FLAGS BODY[HEADER.FIELDS (FROM DATE TO)])",
106 'TEST_7' => "LSUB \"$folder_prefix\" \"*%\"",
107 'TEST_8' => "LIST \"$folder_prefix*\" \"*\"",
108 'TEST_9' => "");
109 }
110
111 print "<FORM ACTION=\"options.php\" METHOD=POST>\n";
112 print "<CENTER><TABLE BORDER=1>\n";
113 print "<TR><TH>Select</TH><TH>Test Name</TH><TH>IMAP command string</TH>\n";
114 print "</TR><TR><TD>\n";
115
116 foreach($type as $index=>$value) {
117 print "</TD></TR><TR><TD WIDTH=\"10%\"><INPUT TYPE=CHECKBOX VALUE=1 NAME=CHECK_$index";
118 if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
119 print " CHECKED";
120 }
121 $check = "CHECK_".$index;
122 if (isset($$check) && $submit != 'clear' && $submit != 'default') {
123 print " CHECKED";
124 }
125 print "></TD><TD WIDTH=\"30%\">$index</TD><TD WIDTH=\"60%\">\n";
126 print "<INPUT TYPE=TEXT NAME=$index VALUE='$value' SIZE=60>\n";
127 }
128
129 print "</TD></TR></TABLE></CENTER><BR>\n";
130 print "<CENTER><INPUT TYPE=SUBMIT NAME=submit value=submit>\n";
131 print "<INPUT TYPE=SUBMIT NAME=submit value=clear>\n";
132 print "<INPUT TYPE=SUBMIT NAME=submit value=default></CENTER><BR>\n";
133
134 $tests = array();
135
136 if ($submit == 'submit') {
137 foreach ($type as $index=>$value) {
138 $check = "CHECK_".$index;
139 if (isset($$check)) {
140 $type[$index] = $$index;
141 array_push($tests, $index);
142 }
143 }
144 for ($i=0;$i<count($tests);$i++) {
145 print "<CENTER><TABLE WIDTH=\"95%\" BORDER=0 BGCOLOR=".$color[4].">\n";
146 print "<TR><TD><B>".$tests[$i]."</B></TD><TR>";
147 print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
148 ">Request:</FONT></SMALL></B></TD></TR>\n";
149 $response = imap_test($imap_stream, $type[$tests[$i]]);
150 print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
151 ">Response:</FONT></SMALL></B></TD></TR>\n";
152 print "<TR><TD>";
153 print_response($response);
154 print "</TD><TR></TABLE></CENTER><BR>\n";
155 }
156 }
157 print "</TD></TR></TABLE></CENTER></BODY></HTML>";
158 sqimap_logout($imap_stream);
159 do_hook('info_bottom');
160 ?>