Index: system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.82
diff -u -r1.82 system.admin.inc
--- system.admin.inc	23 Jul 2008 07:37:06 -0000	1.82
+++ system.admin.inc	28 Jul 2008 22:41:20 -0000
@@ -319,16 +319,15 @@
   // Default settings are defined in theme_get_settings() in includes/theme.inc
   if ($key) {
     $settings = theme_get_settings($key);
-    $var = str_replace('/', '_', 'theme_' . $key . '_settings');
+    $var = str_replace('/', '_', $key);
     $themes = system_theme_data();
     $features = $themes[$key]->info['features'];
   }
   else {
     $settings = theme_get_settings('');
-    $var = 'theme_settings';
   }
 
-  $form['var'] = array('#type' => 'hidden', '#value' => $var);
+  $form['theme'] = array('#type' => 'hidden', '#value' => $var);
 
   // Check for a new uploaded logo, and use that instead.
   if ($file = file_save_upload('logo_upload', array('file_validate_is_image' => array()))) {
@@ -530,7 +529,13 @@
  */
 function system_theme_settings_submit($form, &$form_state) {
   $values = $form_state['values'];
-  $key = $values['var'];
+  $theme = $values['theme'];
+  $themes = system_theme_data();
+
+  $key = 'theme_settings';
+  if(!empty($theme)) {
+    $key = 'theme_'. $theme .'_settings';
+  }
 
   if ($values['op'] == t('Reset to defaults')) {
     variable_del($key);
@@ -539,6 +544,30 @@
   else {
     // Exclude unnecessary elements before saving.
     unset($values['var'], $values['submit'], $values['reset'], $values['form_id'], $values['op'], $values['form_build_id'], $values['form_token']);
+
+    // Include the theme's theme-settings.php file
+    $filename = './' . str_replace("/$theme.info", '', $themes[$theme]->filename) . '/theme-settings.php';
+    if (!file_exists($filename) and !empty($themes[$theme]->info['base theme'])) {
+      // If the theme doesn't have a theme-settings.php file, use the base theme's.
+      $base = $themes[$theme]->info['base theme'];
+      $filename = './' . str_replace("/$base.info", '', $themes[$base]->filename) . '/theme-settings.php';
+    }
+    if (file_exists($filename)) {
+      require_once $filename;
+    }
+
+    // Call engine-specific post process functions.
+    $function = $themes[$theme]->prefix .'_engine_settings_process';
+    if (function_exists($function)) {
+      $function($values);
+    }
+    // Call theme-specific post process functions.
+    $function = $theme . '_settings_process';
+    if (function_exists($function)) {
+      drupal_set_message('Before: '. $values['header_background']);
+      $function($values);
+    }
+
     variable_set($key, $values);
     drupal_set_message(t('The configuration options have been saved.'));
   }
@@ -705,7 +734,7 @@
   return strcasecmp($a->info['name'], $b->info['name']);
 }
 
-/** 
+/**
  * Build a table row for the system modules page.
  */
 function _system_modules_build_row($info, $extra) {
@@ -881,7 +910,7 @@
             );
           }
           else {
-            $dependencies[$name]['dependencies'][$dependency] = $files[$dependency]->info['name'];          
+            $dependencies[$name]['dependencies'][$dependency] = $files[$dependency]->info['name'];
           }
           $modules[$dependency] = array('group' => $files[$dependency]->info['package'], 'enabled' => TRUE);
         }
@@ -2092,10 +2121,10 @@
     // Add the description, along with any dependencies.
     $description .= drupal_render($module['description']);
     if ($module['#dependencies']) {
-     $description .= '<div class="admin-dependencies">' . t('Depends on: ') . implode(', ', $module['#dependencies']) . '</div>'; 
+     $description .= '<div class="admin-dependencies">' . t('Depends on: ') . implode(', ', $module['#dependencies']) . '</div>';
     }
     if ($module['#dependents']) {
-     $description .= '<div class="admin-dependencies">' . t('Required by: ') . implode(', ', $module['#dependents']) . '</div>'; 
+     $description .= '<div class="admin-dependencies">' . t('Required by: ') . implode(', ', $module['#dependents']) . '</div>';
     }
     $row[] = array('data' => $description, 'class' => 'description');
     $rows[] = $row;

