Ver Fonte

updates to make javascript actually behave correctly for real.
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

Erin Schnabel há 21 anos atrás
pai
commit
f3a24d0463
4 ficheiros alterados com 26 adições e 29 exclusões
  1. 14 11
      functions/prefs.php
  2. 1 0
      include/load_prefs.php
  3. 9 15
      include/options/display.php
  4. 2 3
      src/login.php

+ 14 - 11
functions/prefs.php

@@ -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;
 }
 
 ?>

+ 1 - 0
include/load_prefs.php

@@ -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');

+ 9 - 15
include/options/display.php

@@ -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);
 }
 
 /** 

+ 2 - 3
src/login.php

@@ -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="*"' )