code reuse. moving generic function from plugin to function/plugins.php
[squirrelmail.git] / plugins / info / options.php
index 48427e94edd33d966f98cce195d524c5d3c358ce..421a16ee70c8fe34489dce5f8a794571bcf3b4ce 100644 (file)
@@ -1,24 +1,25 @@
-<?PHP
-
-/* options page for IMAP info plugin 
- * Copyright (c) 1999-2002 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *   
+<?php
+/**
+ * options page for IMAP info plugin
+ *
  * This is where it all happens :)
  *
- * Written by: Jason Munro 
- * jason@stdbev.com
- * 
- * $Id$
- * 
+ * @copyright (c) 1999-2005 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ * @version $Id$
+ * @author Jason Munro jason@stdbev.com
+ * @package plugins
+ * @subpackage info
  */
 
+/** @ignore */
 define('SM_PATH','../../');
 
 /* SquirrelMail required files. */
 require_once(SM_PATH . 'include/validate.php');
 require_once(SM_PATH . 'functions/page_header.php');
 require_once(SM_PATH . 'functions/imap.php');
+require_once(SM_PATH . 'functions/forms.php');
 require_once(SM_PATH . 'plugins/info/functions.php');
 
 global $username, $color, $folder_prefix, $default_charset;
@@ -26,32 +27,37 @@ $default_charset = strtoupper($default_charset);
 displayPageHeader($color, 'None');
 $mailbox = 'INBOX';
 
+/**
+ * testing installation
+ *
+ * prevent use of plugin if it is not enabled
+ */
+if (! is_plugin_enabled('info')) {
+    echo '<p align="center"><big>'.
+         _("Plugin is disabled.").
+         '</big></p></body></html>';
+    exit;
+}
+
 /* GLOBALS */
-$username = $_SESSION['username'];
-$key  = $_COOKIE['key'];
-$onetimepad = $_SESSION['onetimepad'];
+sqgetGlobalVar('username', $username, SQ_SESSION);
+sqgetGlobalVar('key', $key, SQ_COOKIE);
+sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
 
-if(isset($_POST['submit'])) {
-    $submit = $_POST['submit'];
-}
+sqgetGlobalVar('submit', $submit, SQ_POST);
 
 for($i = 0; $i <= 9; $i++){
-    if(isset($_POST["CHECK_TEST_$i"])) {
-        $var = "CHECK_TEST_$i";
-        $$var = $_POST["CHECK_TEST_$i"];
-    }
-    if(isset($_POST["TEST_$i"])) {
-        $var = "TEST_$i";
-        $$var = $_POST["TEST_$i"];
-    }
+    $varc = 'CHECK_TEST_'.$i;
+    sqgetGlobalVar($varc, $$varc, SQ_POST);
+    $vart  = 'TEST_'.$i;
+    sqgetGlobalVar($vart, $$vart, SQ_POST);
 }
 
 /* END GLOBALS */
 
 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
 $caps_array = get_caps($imap_stream);
-$list = array (
-               'TEST_0',
+$list = array ('TEST_0',
                'TEST_1',
                'TEST_2',
                'TEST_3',
@@ -62,29 +68,37 @@ $list = array (
                'TEST_8',
                'TEST_9');
 
-print "<BR><CENTER><B>IMAP server information</B></CENTER><BR>\n";
-print "<CENTER><TABLE BGCOLOR=".$color[3]." WIDTH=\"100%\" BORDER=1 CELLPADDING=2><TR><TD BGCOLOR=".$color[3]."><BR>\n";
-print "<CENTER><TABLE WIDTH=\"95%\" BORDER=1 BGCOLOR=".$color[3].">\n";
-print "<TR><TD BGCOLOR=".$color[4]."><B>Server Capability response:</B><BR>\n";
+echo '<br /><center><b>'._("IMAP server information")."</b></center><br />\n".
+     '<center><table bgcolor="'.$color[3].'" width="100%" border="1" cellpadding="2">'.
+     '<tr><td bgcolor="'.$color[3]."\"><br />\n".
+     '<center><table width="95%" border="1" bgcolor="'.$color[3]."\">\n".
+     '<tr><td bgcolor="'.$color[4].'"><b>'.
+     _("Server Capability response:").
+     "</b><br />\n";
 
 foreach($caps_array[0] as $value) {
-    print $value;
+    echo htmlspecialchars($value);
 }
 
-print "</TD></TR><TR><TD>\n";
+echo "</td></tr><tr><td>\n";
 
 if (!isset($submit) || $submit == 'default') {
-    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";
+    echo '<br /><p><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.").
+         "</font></small></p>\n".
+         '<p align="center"><small><b>'.
+         _("NOTE: These commands are live, any changes made will effect your current email account.").
+         "</b></small></p><br />\n";
     if (!isset($submit)) {
         $submit = '';
     }
 }
 else {
-    print "folder_prefix = $folder_prefix<BR>\n";
-    print "default_charset = $default_charset\n";
+    echo 'folder_prefix = ' . htmlspecialchars($folder_prefix)."<br />\n" .
+         'default_charset = '.htmlspecialchars($default_charset)."\n";
 }
 
-print "<BR></TD></TR></TABLE></CENTER><BR>\n";
+echo "<br /></td></tr></table></center><br />\n";
 
 
 if ($submit == 'submit') {
@@ -114,28 +128,32 @@ elseif (!$submit || $submit == 'default')  {
         'TEST_9' => "");
 }
 
-print "<FORM ACTION=\"options.php\" METHOD=POST>\n";
-print "<CENTER><TABLE BORDER=1>\n";
-print "<TR><TH>Select</TH><TH>Test Name</TH><TH>IMAP command string</TH>\n";
-print "</TR><TR><TD>\n";
+echo "<form action=\"options.php\" method=\"post\">\n".
+     "<center><table border=\"1\">\n".
+     '<tr><th>'. _("Select").
+     '</th><th>'._("Test Name").
+     '</th><th>'._("IMAP command string")."</th></tr>\n".
+     '<tr><td>';
 
 foreach($type as $index=>$value) {
-    print "</TD></TR><TR><TD WIDTH=\"10%\"><INPUT TYPE=CHECKBOX VALUE=1 NAME=CHECK_$index";
+    echo "</td></tr>\n<tr><td width=\"10%\">\n<input type=\"checkbox\" value=\"1\" name=\"CHECK_$index\"";
     if ($index == 'TEST_0' && ($submit == 'default' || $submit == '')) {
-        print " CHECKED";
+        echo ' checked="checked"';
     }
     $check = "CHECK_".$index;
     if (isset($$check) && $submit != 'clear' && $submit != 'default') {
-        print " CHECKED";
+        echo ' checked="checked"';
     }
-    print "></TD><TD WIDTH=\"30%\">$index</TD><TD WIDTH=\"60%\">\n";
-    print "<INPUT TYPE=TEXT NAME=$index VALUE='$value' SIZE=60>\n"; 
+    echo " /></td><td width=\"30%\">$index</td><td width=\"60%\">\n".
+         addInput($index, $value, 60);
 }
 
-print "</TD></TR></TABLE></CENTER><BR>\n";
-print "<CENTER><INPUT TYPE=SUBMIT NAME=submit value=submit>\n";
-print "<INPUT TYPE=SUBMIT NAME=submit value=clear>\n";
-print "<INPUT TYPE=SUBMIT NAME=submit value=default></CENTER><BR>\n";
+echo "</td></tr></table></center><br />\n".
+     '<center>'.
+     addSubmit('submit','submit').
+     addSubmit('clear','submit').
+     addSubmit('default','submit').
+     "</center><br /></form>\n";
 
 $tests = array();
 
@@ -144,23 +162,31 @@ if ($submit == 'submit') {
         $check = "CHECK_".$index;
         if (isset($$check)) {
             $type[$index] = $$index;
-            array_push($tests, $index); 
+            array_push($tests, $index);
         }
     }
     for ($i=0;$i<count($tests);$i++) {
-        print "<CENTER><TABLE WIDTH=\"95%\" BORDER=0 BGCOLOR=".$color[4].">\n";
-        print "<TR><TD><B>".$tests[$i]."</B></TD><TR>";
-        print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
-              ">Request:</FONT></SMALL></B></TD></TR>\n";
+        echo '<center><table width="95%" border="0" bgcolor="'.$color[4]."\">\n".
+             '<tr><td><b>'.$tests[$i]."</b></td></tr>\n".
+             '<tr><td><small><b><font color="'.$color[7].'">'.
+            _("Request:")."</font></b></small></td></tr>\n";
+        // imap_test function outputs imap command
         $response = imap_test($imap_stream, $type[$tests[$i]]);
-        print "<TR><TD><SMALL><B><FONT COLOR=".$color[7].
-              ">Response:</FONT></SMALL></B></TD></TR>\n";
-        print "<TR><TD>";
+        echo '<tr><td><small><b><font color="'.$color[7].'">'.
+             _("Response:")."</font></b></small></td></tr>\n".
+             '<tr><td>';
         print_response($response);
-        print "</TD><TR></TABLE></CENTER><BR>\n";
+        echo "</td></tr></table></center><br />\n";
     }
 }
-    print "</TD></TR></TABLE></CENTER></BODY></HTML>";
-    sqimap_logout($imap_stream);
-    do_hook('info_bottom');
+echo '</td></tr></table></center>';
+sqimap_logout($imap_stream);
+
+/**
+ * Optional hook in info plugin
+ *
+ * Hook allows attaching plugin to bottom of info plugin
+ */
+do_hook('info_bottom');
 ?>
+</body></html>
\ No newline at end of file