Index: switchtheme.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.module,v
retrieving revision 1.2.2.4
diff -u -p -r1.2.2.4 switchtheme.module
--- switchtheme.module	31 Aug 2007 14:57:42 -0000	1.2.2.4
+++ switchtheme.module	29 Nov 2007 04:26:05 -0000
@@ -31,8 +31,8 @@ function switchtheme_menu($may_cache) {
   $items = array();
   // plays nice with others, if $custom_theme has already been defined, use it
   // otherwise if session info is set use that
-  if ($_GET['theme']) {
-    $form_values = array('custom_theme' => $_GET['theme']);
+  if ($_REQUEST['theme']) {
+    $form_values = array('theme' => $_REQUEST['theme']);
     switchtheme_switch_form_submit('', $form_values);
   }
   if (isset($_SESSION['custom_theme']) && !isset($custom_theme)) {
@@ -103,7 +103,7 @@ function switchtheme_display_random_bloc
   foreach ($themes as $key => $theme) {
     $theme->screenshot = dirname($theme->filename) . '/screenshot.png';
     if (file_exists($theme->screenshot)) { //return the first one with a screenie
-      $output = l("<img src=\"/$theme->screenshot\" alt=\"preview of $theme->name\"/>", $_GET['q'], NULL, 'theme='.$theme->name, NULL, FALSE, TRUE);
+      $output = l("<img src=\"". base_path() ."$theme->screenshot\" alt=\"preview of $theme->name\" />", $_GET['q'], NULL, 'theme='.$theme->name, NULL, FALSE, TRUE);
       return $output;
     }
   }
@@ -114,10 +114,10 @@ function switchtheme_display_random_bloc
 
 
 function switchtheme_switch_form() {
+  global $user, $custom_theme;
 
-global $user, $custom_theme;
-
-  $form['custom_theme'] = array(
+  $form = array();
+  $form['theme'] = array(
     '#type' => 'select',
     '#default_value' => !empty($custom_theme) ? $custom_theme : $user->theme,
     '#attributes' => array('title' => t('Change the way this site looks.')),
@@ -140,14 +140,24 @@ function theme_switchtheme_block_form($f
 function switchtheme_switch_form_submit($form_id, $form_values) {
   global $user;
 
-  // save the setting in the db for logged in users
-  // save the setting in the variable for all others
   if ($user->uid > 0) {
-    variable_set('theme_default', $form_values['custom_theme']);
-    if (user_save($user, array('theme' => $form_values['custom_theme']))) {
-      $user->theme = $form_values['custom_theme'];
+    // Don't know exactly why, but we are only able to assign a different
+    // theme for authenticated users after cleaning Drupal's copy of user
+    // session variables here.
+    unset($user->session);
+
+    // Never ever alter default theme. 09/10/2007 sun
+    // variable_set('theme_default', $form_values['theme']);
+
+    // save the setting in the db for logged in users
+    if (user_save($user, array('theme' => $form_values['theme']))) {
+      $user->theme = $form_values['theme'];
     }
   }
+  elseif (user_access('switch theme')) {
+    // save the setting in the variable for all others
+    $_SESSION['custom_theme'] = $form_values['theme'];
+  }
 }
 
 
