Avoid calling javascript check fxn if user is not logged in
[squirrelmail.git] / include / init.php
index 53cebad214d7bf98d324108531c20d273165f80b..28b9eb053156e70fbf2865dd1e6a1072b714d9ef 100644 (file)
@@ -49,9 +49,6 @@ if ((bool) ini_get('register_globals') &&
         case 'key':
         case 'value':
             break;
-        case 'sInitLocation':
-            // FIXME: variable must be set only in src/login.php
-            break;
         default:
             unset($GLOBALS[$key]);
         }
@@ -63,7 +60,8 @@ if ((bool) ini_get('register_globals') &&
 
 /**
  * Used as a dummy value, e.g., for passing as an empty
- * hook argument.
+ * hook argument (where the value is passed by reference,
+ * and therefore NULL itself is not acceptable).
  */
 global $null;
 $null = NULL;
@@ -227,7 +225,7 @@ sqsession_is_active();
  * SquirrelMail internal version number -- DO NOT CHANGE
  * $sm_internal_version = array (release, major, minor)
  */
-$SQM_INTERNAL_VERSION = preg_split('/\./', SM_VERSION, 3);
+$SQM_INTERNAL_VERSION = explode('.', SM_VERSION, 3);
 $SQM_INTERNAL_VERSION[2] = intval($SQM_INTERNAL_VERSION[2]);
 
 
@@ -294,15 +292,12 @@ if (! sqgetGlobalVar('squirrelmail_language',$squirrelmail_language,SQ_COOKIE))
     $squirrelmail_language = '';
 }
 
-
 /**
- * @var $sInitlocation From where do we include.
+ * Do something special for some pages. This is based on the PAGE_NAME constand
+ * set at the top of every page.
  */
-if (!isset($sInitLocation)) {
-    $sInitLocation=NULL;
-}
-
-switch ($sInitLocation) {
+if ( !defined('PAGE_NAME') ) define('PAGE_NAME', NULL);
+switch (PAGE_NAME) {
     case 'style':
 
         // need to get the right template set up
@@ -417,8 +412,8 @@ switch ($sInitLocation) {
             // signout page will deal with users who aren't logged
             // in on its own; don't show error here
             //
-            if (strpos($PHP_SELF, 'signout.php') !== FALSE) {
-            return;
+            if ( PAGE_NAME == 'signout' ) {
+                return;
             }
 
             /**
@@ -568,7 +563,9 @@ if (empty($oTemplate)) {
 }
 
 // We want some variables to always be available to the template
-$oTemplate->assign('javascript_on', checkForJavascript());
+$oTemplate->assign('javascript_on', 
+    (sqGetGlobalVar('user_is_logged_in', $user_is_logged_in, SQ_SESSION)
+     ?  checkForJavascript() : 0));
 $oTemplate->assign('base_uri', sqm_baseuri());
 $always_include = array('sTemplateID', 'icon_theme_path');
 foreach ($always_include as $var) {
@@ -601,6 +598,7 @@ function checkForJavascript($reset = FALSE) {
   if ( !$reset && sqGetGlobalVar('javascript_on', $javascript_on, SQ_SESSION) )
     return $javascript_on;
 
+  $user_is_logged_in = FALSE;
   if ( ( $reset || !isset($javascript_setting) )
     // getPref() not defined (nor is it meaningful) when user not
     // logged in, but that begs the question if $javascript_on is