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	18 Sep 2008 23:04:35 -0000
@@ -0,0 +1,63 @@
+<?php
+// $Id: switchtheme.module,v 1.10.2.1 2008/04/20 20:31:28 sun Exp $
+
+/**
+ * @file
+ * Switchtheme administration functions.
+ */
+
+/**
+ * Form builder function for theme settings; 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 browser settings; menu callback.
+ */
+function switchtheme_admin_browser_settings() {
+  $form = array();
+  $form['switchtheme_browser_enabled'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Browser-based theme switching'),
+    '#description' => t('If enabled, the theme will be switched based on the browser of a visitor.'),
+    '#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);
+}
+
Index: switchtheme.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.info,v
retrieving revision 1.4
diff -u -p -r1.4 switchtheme.info
--- switchtheme.info	5 Jul 2007 20:00:21 -0000	1.4
+++ switchtheme.info	18 Sep 2008 22:46:48 -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.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/switchtheme/switchtheme.module,v
retrieving revision 1.10.2.1
diff -u -p -r1.10.2.1 switchtheme.module
--- switchtheme.module	20 Apr 2008 20:31:28 -0000	1.10.2.1
+++ switchtheme.module	18 Sep 2008 23:01:03 -0000
@@ -12,10 +12,14 @@
 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/themes':
       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 +38,7 @@ function switchtheme_init() {
   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 +47,19 @@ function switchtheme_init() {
   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 +68,29 @@ function switchtheme_init() {
 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',
   );
+  $items['admin/settings/switchtheme/themes'] = array(
+    'title' => 'Theme settings',
+    'description' => 'Theme display settings for the Switchtheme block.',
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'weight' => -10,
+  );
+  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'),
+      'type' => MENU_LOCAL_TASK,
+      'weight' => 2,
+    );
+  }
   return $items;
 }
 
@@ -71,22 +104,6 @@ function switchtheme_theme() {
 }
 
 /**
- * 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()) {
