Toma. Zupan <tomaz.zupan@orpo.si>
[squirrelmail.git] / src / options.php
index 1b296972a41d21978af3644d3e0f22634f828b30..b2bd225467b520dc2220385f72dd737cce040cf1 100644 (file)
@@ -1,34 +1,23 @@
 <?php
 
-   /**
   **  options.php
   **
   **  Copyright (c) 1999-2001 The SquirrelMail Development Team
   **  Licensed under the GNU GPL. For full terms see the file COPYING.
   **
   **  Displays the options page. Pulls from proper user preference files
   **  and config.php. Displays preferences as selected and other options.
   **
   **  $Id$
   */
+/**
* options.php
+ *
* Copyright (c) 1999-2002 The SquirrelMail Project Team
* Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
* Displays the options page. Pulls from proper user preference files
* and config.php. Displays preferences as selected and other options.
+ *
* $Id$
+ */
 
 require_once('../src/validate.php');
 require_once('../functions/display_messages.php');
 require_once('../functions/imap.php');
 require_once('../functions/array.php');
 require_once('../functions/options.php');
-
-/* Set the base uri. */
-ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
-$base_uri = $regs[1];
-
-/* First and foremost, deal with language stuff. */
-if (isset($language)) {
-    setcookie('squirrelmail_language', $language, time()+2592000, $base_uri);
-    $squirrelmail_language = $language;
-} else {
-    $language = getPref($data_dir, $username, 'language');
-}
+require_once('../functions/strings.php');
 
 /*********************************/
 /*** Build the resultant page. ***/
@@ -74,6 +63,51 @@ function process_optionmode_link($optpage) {
    /* There will be something here, later. */
 }
 
+
+/**
+ * This function prints out an option page row.
+ */
+function print_optionpages_row($leftopt, $rightopt = false) {
+    global $color;
+
+    echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=5 BORDER=0>" .
+            '<TR><TD VALIGN="TOP">' .
+               '<TABLE WIDTH="100%" CELLPADDING="3" CELLSPACING="0" BORDER="0">' .
+                  '<TR>' .
+                     "<TD VALIGN=TOP BGCOLOR=\"$color[9]\" WIDTH=\"49%\">" .
+                        '<A HREF="' . $leftopt['url'] . '">' . $leftopt['name'] . '</A>'.
+                     '</TD>'.
+                     "<TD VALIGN=TOP BGCOLOR=\"$color[4]\" WIDTH=\"2%\">&nbsp;</TD>";
+    if ($rightopt) {
+        echo         "<TD VALIGN=top BGCOLOR=\"$color[9]\" WIDTH=\"49%\">" .
+                        '<A HREF="' . $rightopt['url'] . '">' . $rightopt['name'] . '</A>' .
+                     '</TD>';
+    } else {
+        echo         "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"49%\">&nbsp;</TD>";
+    }
+
+    echo          '</TR>' .
+                  '<TR>' .
+                     "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"49%\">" .
+                        $leftopt['desc'] .
+                     '</TD>' .
+                     "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"\2%\">&nbsp;</TD>";
+    if ($rightopt) {
+        echo         "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"49%\">" .
+                        $rightopt['desc'] .
+                     '</TD>';
+    } else {
+        echo         "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"49%\">&nbsp;</TD>";
+    }
+    
+    echo          '</TR>' . 
+               '</TABLE>' .
+            '</TD></TR>' .
+         "</TABLE>\n";
+}
+
+/* ---------------------------- main ---------------------------- */
+
 /* Make sure we have an Option Page set. Default to main. */
 if (!isset($optpage)) {
     $optpage = 'main';
@@ -84,9 +118,9 @@ if (!isset($optmode)) {
     $optmode = SMOPT_MODE_DISPLAY;
 }
 
-/*************************************************************/
-/*** First, set the load information for each option page. ***/
-/*************************************************************/
+/*
+ * First, set the load information for each option page.   
+ */
 
 /* Initialize load information variables. */
 $optpage_name = '';
@@ -97,31 +131,36 @@ $optpage_loader = '';
 switch ($optpage) {
     case SMOPT_PAGE_MAIN: break;
     case SMOPT_PAGE_PERSONAL:
-        $optpage_name   = _("Personal Information");
-        $optpage_file   = 'options_personal.php';
-        $optpage_loader = 'load_optpage_data_personal';
+        $optpage_name     = _("Personal Information");
+        $optpage_file     = '../src/options_personal.php';
+        $optpage_loader   = 'load_optpage_data_personal';
+        $optpage_loadhook = 'optpage_loadhook_personal';
         break;
     case SMOPT_PAGE_DISPLAY:
         $optpage_name   = _("Display Preferences");
-        $optpage_file   = 'options_display.php';
+        $optpage_file   = '../src/options_display.php';
         $optpage_loader = 'load_optpage_data_display';
+        $optpage_loadhook = 'optpage_loadhook_display';
         break;
     case SMOPT_PAGE_HIGHLIGHT:
         $optpage_name   = _("Message Highlighting");
-        $optpage_file   = 'options_highlight.php';
+        $optpage_file   = '../src/options_highlight.php';
         $optpage_loader = 'load_optpage_data_highlight';
+        $optpage_loadhook = 'optpage_loadhook_highlight';
         break;
     case SMOPT_PAGE_FOLDER:
         $optpage_name   = _("Folder Preferences");
-        $optpage_file   = 'options_folder.php';
+        $optpage_file   = '../src/options_folder.php';
         $optpage_loader = 'load_optpage_data_folder';
+        $optpage_loadhook = 'optpage_loadhook_folder';
         break;
     case SMOPT_PAGE_ORDER:
         $optpage_name = _("Index Order");
-        $optpage_file = 'options_order.php';
+        $optpage_file = '../src/options_order.php';
         $optpage_loader = 'load_optpage_data_order';
+        $optpage_loadhook = 'optpage_loadhook_order';
         break;
-    default: do_hook('set_optpage_loadinfo');
+    default: do_hook('optpage_set_loadinfo');
 }
 
 /**********************************************************/
@@ -135,6 +174,7 @@ if ($optpage != SMOPT_PAGE_MAIN) {
     /* Assemble the data for this option page. */
     $optpage_data = array();
     $optpage_data = $optpage_loader();
+    do_hook($optpage_loadhook);
     $optpage_data['options'] =
         create_option_groups($optpage_data['grps'], $optpage_data['vals']);
 }
@@ -143,15 +183,16 @@ if ($optpage != SMOPT_PAGE_MAIN) {
 /*** Next, process anything that needs to be processed. ***/
 /***********************************************************/
 
-switch ($optmode) {
-    case SMOPT_MODE_SUBMIT:
-        $max_refresh = process_optionmode_submit($optpage, $optpage_data);
-        break;
-    case SMOPT_MODE_LINK:
-        $max_refresh = process_optionmode_link($optpage, $optpage_data);
-        break;
+if ( isset( $optpage_data ) ) {
+    switch ($optmode) {
+        case SMOPT_MODE_SUBMIT:
+            $max_refresh = process_optionmode_submit($optpage, $optpage_data);
+            break;
+        case SMOPT_MODE_LINK:
+            $max_refresh = process_optionmode_link($optpage, $optpage_data);
+            break;
+    }
 }
-
 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
 
 $optpage_title = _("Options");
@@ -159,16 +200,12 @@ if (isset($optpage_name) && ($optpage_name != '')) {
     $optpage_title .= " - $optpage_name";
 }
 
-?>
-
-<BR>
-<TABLE BGCOLOR="<?php echo $color[0] ?>" WIDTH="95%" ALIGN="CENTER" CELLPADDING="2" CELLSPACING="0" BORDER="0">
-<TR><TD ALIGN="CENTER">
-    <B><?php echo $optpage_title; ?></B><BR>
-    <TABLE WIDTH="100%" BORDER="0" CELLPADDING="5" CELLSPACING="0">
-    <TR><TD BGCOLOR="<?php echo $color[4] ?>" ALIGN="CENTER">
-
-<?php
+echo '<BR>' .
+     "<TABLE BGCOLOR=\"$color[0]\" WIDTH=\"95%\" ALIGN=\"CENTER\" CELLPADDING=\"2\" CELLSPACING=\"0\" BORDER=\"0\">\n".
+    '<TR><TD ALIGN="CENTER">'.
+    "<B>$optpage_title</B><BR>\n".
+    '<TABLE WIDTH="100%" BORDER="0" CELLPADDING="5" CELLSPACING="0">'.
+    "<TR><TD BGCOLOR=\"$color[4]\" ALIGN=\"CENTER\">\n";
 
 /*******************************************************************/
 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
@@ -187,7 +224,8 @@ if ($optmode == SMOPT_MODE_SUBMIT)   {
         case SMOPT_PAGE_FOLDER:
             $save_hook_name = 'options_folder_save';
             break;
-        default: $save_hook_name = 'options_save';
+        default: 
+            $save_hook_name = 'options_save';
             break;
     }
 
@@ -219,14 +257,18 @@ if ($optpage == SMOPT_PAGE_MAIN) {
     /* First, display the results of a submission, if needed. */
     /**********************************************************/
     if ($optmode == SMOPT_MODE_SUBMIT) {
+        if (!isset($frame_top)) {
+            $frame_top = '_top';
+        }
         /* Display a message indicating a successful save. */
         echo '<B>' . _("Successfully Saved Options") . ": $optpage_name</B><BR>\n";
 
         /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
-        if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
+        if ( !isset( $max_refresh ) ) {
+        } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
             echo '<A HREF="../src/left_main.php" TARGET="left">' . _("Refresh Folder List") . '</A><BR>';
         } else if ($max_refresh) {
-            echo '<A HREF="../src/webmail.php?right_frame=options.php" TARGET="_top">' . _("Refresh Page") . '</A><BR>';
+            echo '<A HREF="../src/webmail.php?right_frame=options.php" TARGET="' . $frame_top . '">' . _("Refresh Page") . '</A><BR>';
         }
     }
     /******************************************/
@@ -270,7 +312,7 @@ if ($optpage == SMOPT_PAGE_MAIN) {
     $optpage_blocks[] = array(
         'name' => _("Index Order"),
         'url'  => 'options_order.php',
-        'desc' => _("The order of the message index can be rearanged and changed to contain the headers in any order you want."),
+        'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
         'js'   => false
     );
 
@@ -297,7 +339,7 @@ if ($optpage == SMOPT_PAGE_MAIN) {
     $first_optpage = false;
     echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=\"5\" BORDER=\"0\">" .
                 '<TR><TD VALIGN="TOP">' .
-                   "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" BORDER=\"0\">";
+                   "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" BORDER=\"0\"><TR><TD>";
     foreach ($optpage_blocks as $next_optpage) {
         if ($first_optpage == false) {
             $first_optpage = $next_optpage;
@@ -311,7 +353,7 @@ if ($optpage == SMOPT_PAGE_MAIN) {
         print_optionpages_row($first_optpage);
     }
 
-    echo "</TABLE></TD></TR></TABLE>\n";
+    echo "</TD></TR></TABLE></TD></TR></TABLE>\n";
 
     do_hook('options_link_and_description');
 
@@ -321,16 +363,13 @@ if ($optpage == SMOPT_PAGE_MAIN) {
 /*************************************************************************/
 } else {
     echo '<FORM NAME="f" ACTION="options.php" METHOD="POST"><BR>' . "\n"
-       . '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0">' . "\n"
        . create_optpage_element($optpage)
-       . create_optmode_element(SMOPT_MODE_SUBMIT);
+       . create_optmode_element(SMOPT_MODE_SUBMIT)
+       . '<TABLE WIDTH="100%" CELLPADDING=2 CELLSPACING=0 BORDER=0>' . "\n";
 
     /* Output the option groups for this page. */
     print_option_groups($optpage_data['options']);
 
-    /*** FIXME: CURRENTLY, THIS NEXT SWITCH STATEMENT DOES NOT TAKE
-     *** INTO ACCOUNT FOR PLUGINS. NEED TO FIX IT. ***/
     /* Set the inside_hook_name and submit_name. */
     switch ($optpage) {
         case SMOPT_PAGE_PERSONAL:
@@ -345,12 +384,12 @@ if ($optpage == SMOPT_PAGE_MAIN) {
             break;
         case SMOPT_PAGE_HIGHLIGHT:
             $inside_hook_name = 'options_highlight_inside';
-            $bottom_hook_name = 'options_display_bottom';
+            $bottom_hook_name = 'options_highlight_bottom';
             $submit_name = 'submit_highlight';
             break;
         case SMOPT_PAGE_FOLDER:
             $inside_hook_name = 'options_folder_inside';
-            $bottom_hook_name = 'options_display_bottom';
+            $bottom_hook_name = 'options_folder_bottom';
             $submit_name = 'submit_folder';
             break;
         case SMOPT_PAGE_ORDER:
@@ -379,76 +418,10 @@ if ($optpage == SMOPT_PAGE_MAIN) {
     }
 }
 
-?>
-    </TD></TR>
-    </TABLE>
-
-</TD></TR>
-</TABLE>
-
-</BODY></HTML>
-
-<?php
-
-    /*******************************************************************/
-    /* Please be warned. The code below this point sucks. This is just */
-    /* my first implementation to make the option rows work for both   */
-    /* Javascript and non-Javascript option chunks.                    */
-    /*                                                                 */
-    /* Please, someone make these better for me. All three functions   */
-    /* below REALLY do close to the same thing.                        */
-    /*                                                                 */
-    /* This code would be GREATLY improved by a templating system.     */
-    /* Don't try to implement that now, however. That will come later. */
-    /*******************************************************************/
-
-    /*******************************************************************/
-    /* Actually, now that I think about it, don't do anything with     */
-    /* this code yet. There is ACTUALLY supposed to be a difference    */
-    /* between the three functions that write the option rows. I just  */
-    /* have not yet gotten to integrating that yet.                    */
-    /*******************************************************************/
-
-    /**
-     * This function prints out an option page row.
-     */
-    function print_optionpages_row($leftopt, $rightopt = false) {
-        global $color;
-
-        echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=5 BORDER=0>" .
-                '<TR><TD VALIGN="TOP">' .
-                   '<TABLE WIDTH="100%" CELLPADDING="3" CELLSPACING="0" BORDER="0">' .
-                      '<TR>' .
-                         "<TD VALIGN=TOP BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
-                            '<A HREF="' . $leftopt['url'] . '">' . $leftopt['name'] . '</A>'.
-                         '</TD>'.
-                         "<TD VALIGN=TOP BGCOLOR=\"$color[4]\">&nbsp;</TD>";
-        if ($rightopt) {
-            echo         "<TD VALIGN=top BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
-                            '<A HREF="' . $rightopt['url'] . '">' . $rightopt['name'] . '</A>' .
-                         '</TD>';
-        } else {
-            echo         "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\">&nbsp;</TD>";
-        }
-
-        echo          '</TR>' .
-                      '<TR>' .
-                         "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
-                            $leftopt['desc'] .
-                         '</TD>' .
-                         "<TD VALIGN=top BGCOLOR=\"$color[4]\">&nbsp;</TD>";
-        if ($rightopt) {
-            echo         "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
-                            $rightopt['desc'] .
-                         '</TD>';
-        } else {
-            echo         "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\">&nbsp;</TD>";
-        }
-        
-        echo          '</TR>' .
-                   '</TABLE>' .
-                '</TD></TR>' .
-             "</TABLE>\n";
-    }
+echo        '</TD></TR>' .
+        '</TABLE>'.
+        '</TD></TR>'.
+     '</TABLE>' .
+     '</BODY></HTML>';
 
 ?>
\ No newline at end of file