updates to make javascript actually behave correctly for real.
authorebullient <ebullient@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 28 Mar 2004 22:47:11 +0000 (22:47 +0000)
committerebullient <ebullient@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 28 Mar 2004 22:47:11 +0000 (22:47 +0000)
Autodetection is fixed, load of JS dependent items (like address book and
search) will be set to false if javascript_on session var is false/0.

javascript_on will ONLY be true if:
  javascript_setting = 1 (ALWAYS)
  javascript_setting = 2 (Autodetect, and test works)

If you change your javascript settings, javascript_on will change
immediately.

We might actually want to DISABLE Always, and have it be either Never, or autodetect.
Since Always might not always work.. :-P

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@6918 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/prefs.php
include/load_prefs.php
include/options/display.php
src/login.php

index dd97204b60977891f16de056befae12b2d7411aa..1c8ae1e2536412dc8817417f32e3f1716c25ea0a 100644 (file)
@@ -145,24 +145,27 @@ function computeHashDirs($username) {
     return ($hash_dirs);
 }
 
-function checkForJavascript()
+function checkForJavascript($reset = FALSE)
 {
-  global $data_dir, $username, $javascript_on;
-  if ( sqGetGlobalVar('javascript_on', $javascript_on) )
-    return;
+  global $data_dir, $username, $javascript_on, $javascript_setting;
 
-  if ( !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) )
-    $js_autodetect_results = SMPREF_JS_OFF;
+  if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
+    return $javascript_on;
+
+  if ( $reset || !isset($javascript_setting) )
+    $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
 
-  $javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
+  if ( !sqGetGlobalVar('new_js_autodetect_results', $js_autodetect_results) &&
+       !sqGetGlobalVar('js_autodetect_results', $js_autodetect_results) )
+    $js_autodetect_results = SMPREF_JS_OFF;
 
   if ( $javascript_setting == SMPREF_JS_AUTODETECT )
-    $js_pref = $js_autodetect_results;
+    $javascript_on = $js_autodetect_results;
   else
-    $js_pref = $javascript_setting;
+    $javascript_on = $javascript_setting;
 
-  sqsession_register('javascript_on',$js_pref);
-  return $js_pref;
+  sqsession_register($javascript_on, 'javascript_on');
+  return $javascript_on;
 }
 
 ?>
index 69e2724bdfe6f3391d1e3a07f1fc02be2ed36d1a..49a74cc544a0ffd400a6b0e1c520fbf4481616bb 100644 (file)
@@ -265,6 +265,7 @@ $internal_date_sort = getPref($data_dir, $username, 'internal_date_sort', SMPREF
 $sort_by_ref = getPref($data_dir, $username, 'sort_by_ref', 1);
 
 /* Load the javascript settings. */
+$javascript_setting = getPref($data_dir, $username, 'javascript_setting', SMPREF_JS_AUTODETECT);
 if ( checkForJavascript() )
 {
   $use_javascript_folder_list = getPref($data_dir, $username, 'use_javascript_folder_list');
index 43ef12ad502d23d30d3bbaf5bb0c69465e705e45..366024fc1a43c53163baea26454a333791a68d81 100644 (file)
@@ -45,7 +45,7 @@ if ($use_icons) {
  * @return array all option information
  */
 function load_optpage_data_display() {
-    global $theme, $language, $languages, $js_autodetect_results,
+    global $theme, $language, $languages, $js_autodetect_results, $javascript_setting,
     $compose_new_win, $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
     $optmode, $show_alternative_names, $available_languages, $use_icons;
 
@@ -151,22 +151,17 @@ function load_optpage_data_display() {
         'refresh' => SMOPT_REFRESH_ALL,
         'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
                            SMPREF_JS_ON         => _("Always"),
-                           SMPREF_JS_OFF        => _("Never"))
+                           SMPREF_JS_OFF        => _("Never")),
+        'save'    => 'save_option_javascript_autodetect',
+        'script'  => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
     );
 
-
-    if ($optmode != 'submit')
-       $onLoadScript = 'document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\'';
-    else
-       $onLoadScript = '';
-
     $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'js_autodetect_results',
         'caption' => '',
         'type'    => SMOPT_TYPE_HIDDEN,
-        'refresh' => SMOPT_REFRESH_NONE,
+        'refresh' => SMOPT_REFRESH_NONE
         //'post_script' => $js_autodetect_script,
-        'save'    => 'save_option_javascript_autodetect'
     );
 
     /*** Load the General Options into the array ***/
@@ -438,8 +433,7 @@ function load_optpage_data_display() {
     /* Assemble all this together and return it as our result. */
     $result = array(
         'grps' => $optgrps,
-        'vals' => $optvals,
-        'xtra' => $onLoadScript
+        'vals' => $optvals
     );
     return ($result);
 }
@@ -476,10 +470,10 @@ function save_option_theme($option) {
  * This function saves the javascript detection option.
  */
 function save_option_javascript_autodetect($option) {
-    global $data_dir, $username, $new_javascript_setting;
+    global $data_dir, $username;
 
-    setPref($data_dir, $username, 'javascript_setting', $new_javascript_setting);
-    checkForJavascript();
+    save_option($option);
+    checkForJavascript(TRUE);
 }
 
 /** 
index 7b541abaf2ffe1a1ebb9ede02305af80acf460ad..f124cceffd643560d7527d6b57527291683c1745 100644 (file)
@@ -77,7 +77,6 @@ do_hook('login_cookie');
 $header = "<script language=\"JavaScript\" type=\"text/javascript\">\n" .
           "<!--\n".
           "  function squirrelmail_loginpage_onload() {\n".
-          "    document.forms[0].js_autodetect_results.value = '" . SMPREF_JS_ON . "';\n".
           "    var textElements = 0;\n".
           "    for (i = 0; i < document.forms[0].elements.length; i++) {\n".
           "      if (document.forms[0].elements[i].type == \"text\" || document.forms[0].elements[i].type == \"password\") {\n".
@@ -98,7 +97,7 @@ if (@file_exists($theme[$theme_default]['PATH']))
 displayHtmlHeader( "$org_name - " . _("Login"), $header, FALSE );
 
 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" onLoad=\"squirrelmail_loginpage_onload()\">" .
-     "\n" . '<form action="redirect.php" method="post">' . "\n";
+     "\n" . '<form action="redirect.php" method="post" onSubmit="document.forms[0].js_autodetect_results.value=\'' . SMPREF_JS_ON .'\';">' . "\n";
 
 $username_form_name = 'login_username';
 $password_form_name = 'secretkey';
@@ -160,7 +159,7 @@ echo html_tag( 'table',
                                 'right', '', 'width="30%"' ) .
                                 html_tag( 'td',
                                     '<input type="password" name="' . $password_form_name . '" />' . "\n" .
-                                    '<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF" />' . "\n" .
+                                    '<input type="hidden" name="js_autodetect_results" value="'.SMPREF_JS_OFF.'" />' . "\n" .
                                     $rcptaddress .
                                     '<input type="hidden" name="just_logged_in" value="1" />' . "\n",
                                 'left', '', 'width="*"' )