### Eclipse Workspace Patch 1.0
#P Switch Theme 6
Index: switchtheme.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.module,v
retrieving revision 1.10.2.1
diff -u -r1.10.2.1 switchtheme.module
--- switchtheme.module	20 Apr 2008 20:31:28 -0000	1.10.2.1
+++ switchtheme.module	29 May 2008 02:51:08 -0000
@@ -12,10 +12,13 @@
 function switchtheme_help($path, $arg) {
   switch ($path) {
     case 'admin/settings/modules#description':
-      return t('Creates a switch theme block to allow users to switch themes on the fly. The block can be enabled by role and the admin can define labels to use for each available theme.');
+      return t('Creates a switch theme block to allow users to switch themes on the fly. The block can be enabled by role and the admin can define labels to use for each available theme. It also allows the theme to be changed based on the visitor browser (requires browscap).');
 
     case 'admin/settings/switchtheme':
+    case 'admin/settings/switchtheme/settings':
       return t('Set a label for each enabled theme. This is what will be displayed to the user in the selection box.');
+    case 'admin/settings/switchtheme/browser':
+      return t('Change which theme is used for each browser.');
   }
 }
 
@@ -34,7 +37,7 @@
   drupal_add_css(drupal_get_path('module', 'switchtheme') .'/switchtheme.css');
 
   // If query parameter 'theme' is set, we always assign a new theme.
-  if ($_REQUEST['theme']) {
+  if (isset($_REQUEST['theme'])) {
     $form = array('values' => array('theme' => $_REQUEST['theme']));
     switchtheme_switch_form_submit('', $form);
   }
@@ -43,6 +46,19 @@
   if (isset($_SESSION['custom_theme']) && !isset($custom_theme)) {
     $custom_theme = $_SESSION['custom_theme'];
   }
+  
+  if (module_exists('browscap')) {
+    if (variable_get('switchtheme_browser_enabled', FALSE)) {
+      $browser = browscap_get_browser();
+      if (isset($browser['parent'])) {
+        $parent = trim($browser['parent']);
+        $browser_theme = variable_get('switchtheme_browser_'. md5($parent), 'default');
+        if ($browser_theme != 'default') {
+          $custom_theme = $browser_theme;
+        }
+      }
+    }
+  }
 }
 
 /**
@@ -51,13 +67,34 @@
 function switchtheme_menu() {
   $items = array();
   $items['admin/settings/switchtheme'] = array(
-    'title'    => t('Switchtheme configuration'),
-    'description' => t('Set the labels for the themes in the switchtheme block.'),
-    'access callback'   => 'user_access',
+    'title' => 'Switchtheme',
+    'description' => "Configure settings for the Switchtheme block, as well as change how a visitor's user agent affects which theme is used.",
     'access arguments' => array('administer switch'),
     'page callback' => 'drupal_get_form',
-    'page arguments' => array('switchtheme_admin_settings')
+    'page arguments' => array('switchtheme_admin_settings'),
+    'file' => 'switchtheme.admin.inc',
+    'type' => MENU_NORMAL_ITEM
+  );
+  $items['admin/settings/switchtheme/settings'] = array(
+    'title'    => 'Settings',
+    'description' => 'General settings for the Switchtheme module.',
+    'page arguments' => array('switchtheme_admin_settings'),
+    'access arguments' => array('administer switch'),
+    'file' => 'switchtheme.admin.inc',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => 4,
   );
+  if (module_exists('browscap')) {
+    $items['admin/settings/switchtheme/browser'] = array(
+      'title'    => 'Browser',
+      'description' => "Configuration of switching the theme based on the visitor's browser.",
+      'page arguments' => array('switchtheme_admin_browser_settings'),
+      'access arguments' => array('administer switch'),
+      'file' => 'switchtheme.admin.inc',
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 5,
+    );
+  }
   return $items;
 }
 
@@ -71,22 +108,6 @@
 }
 
 /**
- * Form builder function for administration page; menu callback.
- */
-function switchtheme_admin_settings() {
-  $options = switchtheme_options();
-  foreach ($options as $option) {
-    $form['switchtheme']['switchtheme_'. $option] = array(
-      '#type' => 'textfield',
-      '#title' => $option,
-      '#default_value' => variable_get('switchtheme_'. $option, $option),
-      );
-  }
-
-  return system_settings_form($form);
-}
-
-/**
  * Implementation of hook_block().
  */
 function switchtheme_block($op = 'list', $delta = 0, $edit = array()) {
Index: switchtheme.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.info,v
retrieving revision 1.4
diff -u -r1.4 switchtheme.info
--- switchtheme.info	5 Jul 2007 20:00:21 -0000	1.4
+++ switchtheme.info	29 May 2008 02:51:08 -0000
@@ -1,4 +1,4 @@
 ; $Id: switchtheme.info,v 1.4 2007/07/05 20:00:21 karens Exp $
 name = Switchtheme
-description = Adds a block to allow users to switch between enabled themes.
+description = Allows switching the theme in various means.
 core = 6.x
Index: switchtheme.admin.inc
===================================================================
RCS file: switchtheme.admin.inc
diff -N switchtheme.admin.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ switchtheme.admin.inc	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,57 @@
+<?php
+// $Id$
+
+/**
+ * Form builder function for administration page; menu callback.
+ */
+function switchtheme_admin_settings() {
+  $options = switchtheme_options();
+  foreach ($options as $option) {
+    $form['switchtheme']['switchtheme_'. $option] = array(
+      '#type' => 'textfield',
+      '#title' => $option,
+      '#default_value' => variable_get('switchtheme_'. $option, $option),
+    );
+  }
+  return system_settings_form($form);
+}
+
+/**
+ * Form builder function for administration page; menu callback.
+ */
+function switchtheme_admin_browser_settings() {
+  $form = array();
+  $form['switchtheme_browser_enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Browser-based Theme Switching'),
+    '#description' => t("When enabled, switches the theme based on what browser the visitor is using."),
+    '#default_value' => variable_get('switchtheme_browser_enabled', FALSE),
+  );
+  
+  $themes = switchtheme_select();
+  $themes['default'] = 'Default';
+  $useragents = array();
+  $result = db_query('SELECT data FROM {browscap}');
+  while ($row = db_fetch_object($result)) {
+    $data = $row->data;
+    $data = unserialize($data);
+    if (isset($data['parent'])) {
+      $useragents[trim($data['parent'])][] = isset($data['platform']) ? $data['platform'] : '';
+    }
+  }
+  $form['switchtheme_browser'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Browsers'),
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
+  );
+  foreach ($useragents as $parent => $platforms) {
+    $form['switchtheme_browser']['switchtheme_browser_'. md5($parent)] = array(
+      '#type' => 'select',
+      '#title' => $parent,
+      '#options' => $themes,
+      '#default_value' => variable_get('switchtheme_browser_'. md5($parent), 'default'),
+    );
+  }
+  return system_settings_form($form);
+}
