Index: system_module.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/util/system_module.install,v
retrieving revision 1.1
diff -u -r1.1 system_module.install
--- system_module.install	18 Dec 2007 06:52:15 -0000	1.1
+++ system_module.install	8 Sep 2009 17:27:25 -0000
@@ -1,4 +1,10 @@
 <?php
+// $Id$
+
+/**
+ * @file
+ * Customize System Modules fieldsets
+ */
 
 function system_module_install() {
   drupal_install_schema('system_module_users');
@@ -9,10 +15,10 @@
 }
 
 function system_module_users_schema() {
-  //this is not used very much yet.
-  //settings are still saved in user.data field.
-  //in next update this module will move away from using user.data and instead use
-  //its own configuration table
+  // This is not used very much yet.
+  // Settings are still saved in user.data field.
+  // In next update this module will move away from using user.data and instead use
+  // its own configuration table
 
   $schema['system_module_users'] = array(
     'description' => t('Tracks users of this module to enable proper cleanup when module is disabled'),
Index: system_module.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/util/system_module.module,v
retrieving revision 1.4
diff -u -r1.4 system_module.module
--- system_module.module	1 May 2008 18:02:34 -0000	1.4
+++ system_module.module	8 Sep 2009 17:02:36 -0000
@@ -1,20 +1,38 @@
 <?php
+// $Id $
 
+/**
+ * @file
+ * Customize System Modules fieldsets
+ */
+
+function system_module_help($path, $args) {
+  switch ($path) {
+    case 'admin/build/modules':
+      return l(t('Set collapsed state'), 'admin/settings/util/sysmods');
+
+    case 'admin/settings/util/sysmods':
+      return l(t('Go to modules admin page'), 'admin/build/modules');
+  }
+}
 
 function system_module_menu() {
   $menu['admin/settings/util/sysmods'] = array(
-    'title'          => 'System Modules Settings',
-    'description'    => 'Customize System Modules fieldsets.',
-    'page callback'  => 'drupal_get_form',
-    'page arguments' => array('system_module_settings'),
+    'title'            => 'Modules Settings',
+    'description'      => 'Customize System Modules fieldsets.',
+    'page callback'    => 'drupal_get_form',
+    'page arguments'   => array('system_module_settings'),
     'access arguments' => array('administer site configuration'),
+    'type'             => MENU_LOCAL_TASK,
   );
   return $menu;
 }
 
 function system_module_settings() {
   global $user;
-  //get all available packages
+  drupal_add_css(drupal_get_path('module', 'system_module') .'/system_module.css');
+
+  // Get all available packages
   $modules = module_rebuild_cache();
   foreach ($modules as $module) {
     if (!isset($module->info['package']) || !$module->info['package']) {
@@ -23,46 +41,63 @@
     $packages[$module->info['package']] = $module->info['package'];
   }
   ksort($packages);
-  //build settings form
 
- $result = db_fetch_array(db_query("SELECT data FROM {system_module_users} WHERE uid = %d}", $user->uid));
- $result = unserialize($result['data']);
+  // Build settings form
+  $result = db_fetch_array(db_query("SELECT data FROM {system_module_users} WHERE uid = %d}", $user->uid));
+  $result = unserialize($result['data']);
+
+  $form['system_module_collapse_all'] = array(
+    '#type' => 'radios',
+    '#title' => t('Collapse all by default'),
+    '#description' => t('If you collapse all by default, new packages will be collapsed automatically unless you select them below.'),
+    '#default_value' => variable_get('system_module_collapse_all', 0),
+    '#options' => array(t('Expand all by default'), t('Collapse all by default')),
+    );
 
+  $form['list'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Available module packages'),
+    '#description' => t('Check the box to reverse the default collapsed state above.'),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+    );
 
-  $form['system_module_cfg'] = array(
+  $form['list']['system_module_cfg'] = array(
     '#type' => 'checkboxes',
-    '#description' => t('Check the box if you want that package to be collapsed in <a href="@url">system modules</a> page, uncheck to expand', array('@url' => url('admin/build/modules'))),
-    '#default_value' => (isset($result) && is_array($result)?array_keys($result):array()),
+    '#default_value' => (isset($result) && is_array($result) ? array_keys($result) : array()),
     '#options' => $packages,
-  );
+    );
 
   $form['submit'] = array(
     '#type' => 'submit',
-    '#value' => 'Customize --->',
-  );
+    '#value' => 'Save configuration',
+    );
   return $form;
 }
 
 function system_module_settings_submit($form, &$form_state) {
   global $user;
-  $values = $form_state['values'];
-  foreach ($values['system_module_cfg'] as $index => $value) {
+  variable_set('system_module_collapse_all', $form_state['values']['system_module_collapse_all']);
+
+  foreach ($form_state['values']['system_module_cfg'] as $index => $value) {
     if ($value === 0) {
-      unset($values['system_module_cfg'][$index]);
+      unset($form_state['values']['system_module_cfg'][$index]);
     }
   }
-  //must replace this with drupal_write_record at a later date (once i figure out how to use it correctly!)
-  db_query("REPLACE INTO {system_module_users} SET uid = %d, data = '%s'", $user->uid, serialize($values['system_module_cfg']));
+  // Must replace this with drupal_write_record at a later date (once i figure out how to use it correctly!)
+  db_query("REPLACE INTO {system_module_users} SET uid = %d, data = '%s'", $user->uid, serialize($form_state['values']['system_module_cfg']));
+
+  // Save user settings
+  user_save($user, array('system_module_cfg' => $form_state['values']['system_module_cfg']));
 
-  //save user settings
-  user_save($user, array('system_module_cfg' => $values['system_module_cfg']));
+  drupal_set_message(t('Configuration saved'));
 }
 
-// the theme registry
+// The theme registry
 function system_module_theme() {
   return array(
     'system_modules_theme' => array(
-      'arguments' => array('form' => null),
+      'arguments' => array('form' => NULL),
     ),
   );
 }
@@ -70,9 +105,10 @@
 function system_module_form_alter(&$form, $form_state, $form_id) {
   switch ($form_id) {
     case 'system_modules':
-      //a neat idea to allow access to the important module settings directly from the modules page, saves page loads from navigting to site configuration etc etc.
+      // A neat idea to allow access to the important module settings directly from the modules page,
+      // saves page loads from navigting to site configuration etc.
       $form['#theme'] = 'system_modules_theme';
-      $form['description']['system_module']['#value'] = t('<a href="@url">Set default</a> collapsed/expanded state for system modules fieldsets', array('@url' => url('admin/settings/util/sysmods')));
+      $form['description']['system_module']['#value'] = l($form['description']['system_module']['#value'], 'admin/settings/util/sysmods');
       break;
   }
 }
@@ -81,7 +117,7 @@
   drupal_rebuild_theme_registry();
 }
 
-//most of this function was copied from system.module
+// Most of this function was copied from system.module.
 function theme_system_modules_theme($form) {
   global $user;   //needed to enable
   if (isset($form['confirm'])) {
@@ -109,6 +145,14 @@
 
   // Display packages.
   $output = '';
+  $collapse_all = variable_get('system_module_collapse_all', 0);
+  $throttle_available = module_exists('throttle');
+  $status_error_php = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of PHP'));
+  $status_error_core = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core'));
+  $incompat_core = '<div class="incompatible">'. t('This version is incompatible with the !core_version version of Drupal core.', array('!core_version' => VERSION)) .'</div>';
+  $incompat_php = '<div class="incompatible">'. t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion())) .'</div>';
+
+
   foreach ($packages as $package => $modules) {
     $rows = array();
 
@@ -118,28 +162,27 @@
         $enabled_count++;
       }
 
-//      drupal_set_message('<pre>'. print_r($form['status'][$key], 1) .'</pre>');
       $row = array();
       $description = drupal_render($form['description'][$key]);
       if (isset($form['status']['#incompatible_modules_core'][$key])) {
         unset($form['status'][$key]);
-        $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core'));
-        $description .= '<div class="incompatible">'. t('This version is incompatible with the !core_version version of Drupal core.', array('!core_version' => VERSION)) .'</div>';
+        $status = $status_error_core;
+        $description .= $incompat_core;
       }
       elseif (isset($form['status']['#incompatible_modules_php'][$key])) {
         unset($form['status'][$key]);
-        $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of PHP'));
+        $status = $status_error_php;
         $php_required = $form['status']['#incompatible_modules_php'][$key];
         if (substr_count($php_required, '.') < 2) {
           $php_required .= '.*';
         }
-        $description .= '<div class="incompatible">'. t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $php_required, '!php_version' => phpversion())) .'</div>';
+        $description .= $incompat_php;
       }
       else {
         $status = drupal_render($form['status'][$key]);
       }
       $row[] = array('data' => $status, 'align' => 'center');
-      if (module_exists('throttle')) {
+      if ($throttle_available) {
         $row[] = array('data' => drupal_render($form['throttle'][$key]), 'align' => 'center');
       }
       $row[] = '<strong>'. drupal_render($form['name'][$key]) .'</strong>';
@@ -147,10 +190,19 @@
       $row[] = array('data' => $description, 'class' => 'description');
       $rows[] = $row;
     }
+
+    // Here we influence the fieldset to be collapsed or expanded by default.
+    if ($collapse_all) {
+      $collapsed = (isset($user->system_module_cfg[$package]) ? FALSE : TRUE);
+    }
+    else {
+      $collapsed = (isset($user->system_module_cfg[$package]) ? TRUE : FALSE);
+    }
+
     $fieldset = array(
       '#title' => $package .' ['. $enabled_count .'] of ['. sizeof($modules) .']',
       '#collapsible' => TRUE,
-      '#collapsed' => (isset($user->system_module_cfg[$package])? true:false), //here we influence the fieldset to be collapsed or expanded by default.
+      '#collapsed' => $collapsed,
       '#value' => theme('table', $header, $rows, array('class' => 'package')),
     );
     $output .= theme('fieldset', $fieldset);
--- system_module.css
+++ system_module.css
@@ -0,0 +1,39 @@
+/* $Id $ */
+/**
+ * @file
+ * Customize System Modules fieldsets
+ */
+
+#system-module-settings .form-radios {
+  margin-top: 0;
+}
+
+#system-module-settings .form-radios .form-item {
+  float: left;
+  margin-left: 2em;
+}
+
+#system-module-settings .form-checkboxes .form-item, #system-module-settings .form-radios .form-item {
+  float: left;
+  margin-top: 0;
+  margin-bottom: 0;
+  /* width: 33%; /* 3 columns per row */
+  width: 24%; /* 4 columns per row */
+  /* width: 19%; /* 5 columns per row */
+  /* margin-right: 1em; /* as many as will fit */
+}
+
+#system-module-settings .description {
+  clear: both;
+}
+
+#system-module-settings fieldset legend{
+  font-weight: bold;
+}
+
+#system-module-settings .form-submit {
+  margin-top: 1em;
+  font-weight: bold;
+  color: #009900;
+  padding: 1px;
+}


