--- ../../drupal/modules/system/system.module	2006-08-02 09:27:01.000000000 +0200
+++ system.module	2006-08-02 13:09:53.000000000 +0200
@@ -95,18 +95,22 @@
     $items[] = array('path' => 'system/files', 'title' => t('file download'),
       'callback' => 'file_download',
       'access' => TRUE,
-      'type' => MENU_CALLBACK);
+      'type' => MENU_CALLBACK
+    );
 
     $access = user_access('administer site configuration');
 
     $items[] = array('path' => 'admin', 'title' => t('administer'),
       'access' => user_access('access administration pages'),
       'callback' => 'system_main_admin_page',
-      'weight' => 9);
+      'weight' => 9
+    );
+    
     $items[] = array('path' => 'admin/compact', 'title' => t('compact mode'),
       'access' => user_access('access administration pages'),
       'callback' => 'system_admin_compact_page',
-      'type' => MENU_CALLBACK);
+      'type' => MENU_CALLBACK
+    );
 
     // menu items that are basically just menu blocks
     $items[] = array(
@@ -116,7 +120,8 @@
       'position' => 'right',
       'weight' => -5,
       'callback' => 'system_settings_overview',
-      'access' => $access);
+      'access' => $access
+    );
 
     $items[] = array('path' => 'admin/build',
       'title' => t('site building'),
@@ -124,7 +129,8 @@
       'position' => 'right',
       'weight' => -10,
       'callback' => 'system_admin_menu_block_page',
-      'access' => $access);
+      'access' => $access
+    );
 
     $items[] = array(
       'path' => 'admin/settings/admin',
@@ -133,14 +139,16 @@
       'position' => 'left',
       'callback' => 'system_admin_page_settings',
       'block callback' => 'system_admin_page_settings',
-      'access' => $access);
+      'access' => $access
+    );
 
     // Themes:
     $items[] = array(
       'path' => 'admin/build/themes',
       'title' => t('themes'),
       'description' => t('Change which theme your site uses or allows users to set.'),
-      'callback' => 'system_themes', 'access' => $access);
+      'callback' => 'system_themes', 'access' => $access
+    );
 
     $items[] = array(
       'path' => 'admin/build/themes/select',
@@ -149,24 +157,34 @@
       'callback' => 'system_themes',
       'access' => $access,
       'type' => MENU_DEFAULT_LOCAL_TASK,
-      'weight' => -1);
+      'weight' => -1
+    );
 
     $items[] = array('path' => 'admin/build/themes/settings',
       'title' => t('configure'),
       'callback' => 'system_theme_settings',
       'access' => $access,
-      'type' => MENU_LOCAL_TASK);
+      'type' => MENU_LOCAL_TASK
+    );
 
     // Theme configuration subtabs
-    $items[] = array('path' => 'admin/build/themes/settings/global', 'title' => t('global settings'),
-      'callback' => 'system_theme_settings', 'access' => $access,
-      'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -1);
+    $items[] = array('path' => 'admin/build/themes/settings/global', 
+			'title' => t('global settings'),
+      'callback' => 'system_theme_settings', 
+			'access' => $access,
+      'type' => MENU_DEFAULT_LOCAL_TASK, 
+			'weight' => -1
+    );
 
     foreach (list_themes() as $theme) {
       if ($theme->status) {
-        $items[] = array('path' => 'admin/build/themes/settings/'. $theme->name, 'title' => $theme->name,
-        'callback' => 'system_theme_settings', 'callback arguments' => array($theme->name), 'access' => $access,
-        'type' => MENU_LOCAL_TASK);
+        $items[] = array('path' => 'admin/build/themes/settings/'. $theme->name, 
+					'title' => $theme->name,
+        	'callback' => 'system_theme_settings', 
+					'callback arguments' => array($theme->name), 
+					'access' => $access,
+        	'type' => MENU_LOCAL_TASK
+        );
       }
     }
 
@@ -176,64 +194,103 @@
       'description' => t('Enable or disable add-on modules for your site.'),
       'weight' => -10,
       'callback' => 'system_modules',
-      'access' => $access);
+      'callback arguments' => array('enabled'),
+      'access' => $access
+    );
+    
+    $items[] = array('path' => 'admin/settings/modules/enabled', 
+			'title' => t('enabled'),
+      'callback' => 'system_modules', 
+			'callback arguments' => array('enabled'), 
+			'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 
+			'weight' => -10
+		);
+    
+    $items[] = array('path' => 'admin/settings/modules/disabled', 
+			'title' => t('disabled'),
+      'callback' => 'system_modules', 
+			'callback arguments' => array('disabled'), 
+			'access' => $access, 
+			'type' => MENU_LOCAL_TASK
+	  );
 
     // Settings:
     $items[] = array(
       'path' => 'admin/settings/site-information',
       'title' => t('site information'),
       'description' => t('Change basic site information, such as the site name, slogan, e-mail address, mission, front page and more.'),
-      'callback' => 'system_site_information_settings');
+      'callback' => 'system_site_information_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/error-reporting',
       'title' => t('error reporting'),
       'description' => t('Control how Drupal deals with errors including 403/404 erros as well as PHP error reporting.'),
-      'callback' => 'system_error_reporting_settings');
+      'callback' => 'system_error_reporting_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/page-caching',
       'title' => t('page caching'),
       'description' => t('Enable or disable page caching for anonymous users.'),
-      'callback' => 'system_page_caching_settings');
+      'callback' => 'system_page_caching_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/file-system',
       'title' => t('file system'),
       'description' => t('Tell Drupal where to store uploaded files and how they are accessed.'),
-      'callback' => 'system_file_system_settings');
+      'callback' => 'system_file_system_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/image-toolkit',
       'title' => t('image toolkit'),
       'description' => t('Choose which image toolkit to use if you have installed optional toolkits.'),
-      'callback' => 'system_image_toolkit_settings');
+      'callback' => 'system_image_toolkit_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/content/rss-feed',
       'title' => t('RSS feeds'),
       'description' => t('Configure the number of items per feed and whether feeds should be titles/teasers/full-text.'),
-      'callback' => 'system_rss_feeds_settings');
+      'callback' => 'system_rss_feeds_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/date-time',
       'title' => t('date and time'),
       'description' => t('Settings for how Drupal displays date and time, as well as the system\'s default timezone.'),
-      'callback' => 'system_date_time_settings');
+      'callback' => 'system_date_time_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/site-status',
       'title' => t('site status'),
       'description' => t('Take the site off-line for maintenance or bring it back online.'),
-      'callback' => 'system_site_status_settings');
+      'callback' => 'system_site_status_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/unicode',
       'title' => t('unicode'),
       'description' => t('Unicode string handling settings.'),
-      'callback' => 'system_unicode_settings');
+      'callback' => 'system_unicode_settings'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/cron-status',
       'title' => t('cron status'),
       'description' => t('View whether or not cron is running on your site.'),
-      'callback' => 'system_cron_status');
+      'callback' => 'system_cron_status'
+    );
+    
     $items[] = array(
       'path' => 'admin/settings/clean-urls',
       'title' => t('clean URLs'),
       'description' => t('Enable or disable clean URLs for your site.'),
-      'callback' => 'system_clean_url_settings');
+      'callback' => 'system_clean_url_settings'
+    );
   }
 
   return $items;
@@ -250,13 +307,18 @@
 
     if (variable_get('configurable_timezones', 1)) {
       $zones = _system_zonelist();
-      $form['timezone'] = array('#type'=>'fieldset', '#title' => t('Locale settings'), '#weight' => 6);
+      $form['timezone'] = array('#type'=>'fieldset', 
+				'#title' => t('Locale settings'), 
+				'#weight' => 6
+		  );
       $form['timezone']['timezone'] = array(
-        '#type' => 'select', '#title' => t('Time zone'), '#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
-        '#options' => $zones, '#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
+        '#type' => 'select', 
+				'#title' => t('Time zone'), 
+				'#default_value' => strlen($edit['timezone']) ? $edit['timezone'] : variable_get('date_default_timezone', 0),
+        '#options' => $zones, 
+				'#description' => t('Select your current local time. Dates and times throughout this site will be displayed using this time zone.')
       );
     }
-
     return $form;
   }
 }
@@ -319,11 +381,17 @@
   return $output;
 }
 
+/**
+ * Sets the mode for the admin page.
+ * @param
+ * 	The mode default off.  
+ */
 function system_admin_compact_page($mode = 'off') {
   global $user;
   user_save($user, array('admin_compact_mode' => ($mode == 'on')));
   drupal_goto('admin');
 }
+
 /**
  * This function provides a form to control the settings of the
  * administration page.
@@ -353,7 +421,13 @@
   return system_settings_form('system_admin_page_form', $form);
 }
 
-
+/**
+ * Implementation of hook_submit().
+ * @param $form_id
+ * 	The id of the form.
+ * @param $form_values
+ * 	The values passed back from the form.
+ */
 function system_admin_page_submit($form_id, $form_values) {
   // If we're changing themes, make sure the theme has its blocks initialized.
   if ($form_values['admin_theme'] != variable_get('admin_theme', 'bluemarine')) {
@@ -376,7 +450,7 @@
   }
 }
 
-/*
+/**
  * Returns a fieldset containing the theme select form.
  *
  * @param $description
@@ -414,18 +488,38 @@
         $info->screenshot = dirname($info->filename) . '/screenshot.png';
         $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
 
-        $form['themes'][$info->key]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot);
-        $form['themes'][$info->key]['description'] = array('#type' => 'item', '#title' => $info->name,  '#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : ''));
+        $form['themes'][$info->key]['screenshot'] = array(
+					'#type' => 'markup', 
+					'#value' => $screenshot
+				);
+        
+        $form['themes'][$info->key]['description'] = array(
+					'#type' => 'item', 
+					'#title' => $info->name,  
+					'#value' => dirname($info->filename) . ($info->name == variable_get('theme_default', 'bluemarine') ? t('<br /> <em>(site default theme)</em>') : '')
+				);
+        
         $options[$info->key] = '';
       }
 
-      $form['themes']['theme'] = array('#type' => 'radios', '#options' => $options, '#default_value' => $default_value ? $default_value : '');
+      $form['themes']['theme'] = array(
+				'#type' => 'radios', 
+				'#options' => $options, 
+				'#default_value' => $default_value ? $default_value : ''
+			);
+      
       $form['#weight'] = $weight;
       return $form;
     }
   }
 }
-
+/**
+ * Theme hook for the theme form.
+ * @param $form
+ * 	The form to be rendered.
+ * @return 
+ * 	The formatted output.
+ */
 function theme_system_theme_select_form($form) {
   foreach (element_children($form) as $key) {
     $row = array();
@@ -437,22 +531,39 @@
     $rows[] = $row;
   }
 
-  $header = array(t('Screenshot'), t('Name'), t('Selected'));
+  $header = array(
+  	t('Screenshot'), 
+  	t('Name'), 
+  	t('Selected')
+  );
+  
   $output = theme('table', $header, $rows);
   return $output;
 }
-
+/**
+ * Returns a list of system zones.
+ * @return 
+ *  List of system zones.
+ */
 function _system_zonelist() {
   $timestamp = time();
   $zonelist = array(-11, -10, -9.5, -9, -8, -7, -6, -5, -4, -3.5, -3, -2, -1, 0, 1, 2, 3, 3.5, 4, 5, 5.5, 5.75, 6, 6.5, 7, 8, 9, 9.5, 10, 10.5, 11, 11.5, 12, 12.75, 13, 14);
   $zones = array();
   foreach ($zonelist as $offset) {
     $zone = $offset * 3600;
-    $zones[$zone] = format_date($timestamp, 'custom', variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone);
+    $zones[$zone] = format_date(
+    		$timestamp, 'custom', 
+    		variable_get('date_format_long', 'l, F j, Y - H:i') . ' O', $zone
+    );
   }
   return $zones;
 }
 
+/**
+ * Site information menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_site_information_settings() {
   $form['site_name'] = array(
     '#type' => 'textfield',
@@ -461,12 +572,14 @@
     '#description' => t('The name of this web site.'),
     '#required' => TRUE
   );
+
   $form['site_mail'] = array(
     '#type' => 'textfield',
     '#title' => t('E-mail address'),
     '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
     '#description' => t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.')
   );
+
   $form['site_slogan'] = array(
     '#type' => 'textfield',
     '#title' => t('Slogan'),
@@ -480,18 +593,21 @@
     '#default_value' => variable_get('site_mission', ''),
     '#description' => t('Your site\'s mission statement or focus.')
   );
+
   $form['site_footer'] = array(
     '#type' => 'textarea',
     '#title' => t('Footer message'),
     '#default_value' => variable_get('site_footer', ''),
     '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.')
   );
+
   $form['anonymous'] = array(
     '#type' => 'textfield',
     '#title' => t('Anonymous user'),
     '#default_value' => variable_get('anonymous', 'Anonymous'),
     '#description' => t('The name used to indicate anonymous users.')
   );
+
   $form['site_frontpage'] = array(
     '#type' => 'textfield',
     '#title' => t('Default front page'),
@@ -502,6 +618,11 @@
   return system_settings_form('system_site_information_settings', $form);
 }
 
+/**
+ * Clean URL settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_clean_url_settings() {
   // We check for clean URL support using an image on the client side.
   $form['clean_url'] = array(
@@ -526,6 +647,11 @@
   return system_settings_form('system_clean_url_settings', $form);
 }
 
+/**
+ * Error reporting settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_error_reporting_settings() {
 
   $form['site_403'] = array(
@@ -543,13 +669,16 @@
   );
 
   $form['error_level'] = array(
-    '#type' => 'select', '#title' => t('Error reporting'), '#default_value' => variable_get('error_level', 1),
+    '#type' => 'select', 
+		'#title' => t('Error reporting'), 
+		'#default_value' => variable_get('error_level', 1),
     '#options' => array(t('Write errors to the log'), t('Write errors to the log and to the screen')),
     '#description' =>  t('Where Drupal, PHP and SQL errors are logged. On a production server it is recommended that errors are only written to the error log. On a test server it can be helpful to write logs to the screen.')
   );
 
   $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200), 'format_interval');
   $period['1000000000'] = t('Never');
+
   $form['watchdog_clear'] = array(
     '#type' => 'select',
     '#title' => t('Discard log entries older than'),
@@ -561,6 +690,11 @@
   return system_settings_form('system_error_reporting_settings', $form);
 }
 
+/**
+ * Page caching settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_page_caching_settings() {
 
   $form['cache'] = array(
@@ -573,6 +707,7 @@
 
   $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
   $period[0] = t('none');
+
   $form['cache_lifetime'] = array(
     '#type' => 'select',
     '#title' => t('Minimum cache lifetime'),
@@ -584,6 +719,11 @@
   return system_settings_form('system_page_caching_settings', $form);
 }
 
+/**
+ * File system settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_file_system_settings() {
 
   $form['file_directory_path'] = array(
@@ -615,6 +755,11 @@
   return system_settings_form('system_file_system_settings', $form);
 }
 
+/**
+ * Image toolkit settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_image_toolkit_settings() {
   $toolkits_available = image_get_available_toolkits();
   if (count($toolkits_available) > 1) {
@@ -632,6 +777,11 @@
   }
 }
 
+/**
+ * RSS feeds settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_rss_feeds_settings() {
 
   $form['feed_default_items'] = array(
@@ -652,6 +802,11 @@
   return system_settings_form('system_rss_feeds_settings', $form);
 }
 
+/**
+ * Date time settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_date_time_settings() {
   // Date settings:
   $zones = _system_zonelist();
@@ -730,6 +885,11 @@
   return system_settings_form('system_date_time_settings', $form);
 }
 
+/**
+ * Site status settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_site_status_settings() {
 
   $form['site_offline'] = array(
@@ -750,10 +910,20 @@
   return system_settings_form('system_site_status_settings', $form);
 }
 
+/**
+ * Unicode settings menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_unicode_settings() {
   return system_settings_form('system_unicode_settings', unicode_settings());
 }
 
+/**
+ * Cron status menu callback. 
+ * @return
+ * 	The page to display.
+ */
 function system_cron_status() {
   $cron_last = variable_get('cron_last', NULL);
 
@@ -1004,8 +1174,14 @@
 
 // Add the submit / reset buttons and run drupal_get_form()
 function system_settings_form($form_id, $form) {
-  $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
-  $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
+  $form['buttons']['submit'] = array(
+		'#type' => 'submit', 
+		'#value' => t('Save configuration')
+	);
+  $form['buttons']['reset'] = array(
+		'#type' => 'submit', 
+		'#value' => t('Reset to defaults') 
+	);
 
   if (!empty($_POST) && form_get_errors()) {
     drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
@@ -1014,6 +1190,9 @@
   return drupal_get_form($form_id, $form, 'system_settings_form');
 }
 
+/**
+ * Implementation of the theme setting hook_submit(). 
+ */
 function system_theme_settings_submit($form_id, $values) {
   $op = isset($_POST['op']) ? $_POST['op'] : '';
   $key = $values['var'];
@@ -1073,16 +1252,30 @@
 
   foreach ($themes as $info) {
     $info->screenshot = dirname($info->filename) . '/screenshot.png';
+		//TODO: Change to if statement for readibility
     $screenshot = file_exists($info->screenshot) ? theme('image', $info->screenshot, t('Screenshot for %theme theme', array('%theme' => $info->name)), '', array('class' => 'screenshot'), FALSE) : t('no screenshot');
 
-    $form[$info->name]['screenshot'] = array('#type' => 'markup', '#value' => $screenshot);
-    $form[$info->name]['description'] = array('#type' => 'item', '#title' => $info->name,  '#value' => dirname($info->filename));
+    $form[$info->name]['screenshot'] = array(
+			'#type' => 'markup', 
+			'#value' => $screenshot
+		);
+		
+    $form[$info->name]['description'] = array(
+			'#type' => 'item', 
+			'#title' => $info->name,  
+			'#value' => dirname($info->filename)
+		);
+    
     $options[$info->name] = '';
     if ($info->status) {
       $status[] = $info->name;
     }
     if ($info->status && (function_exists($info->prefix . '_settings') || function_exists($info->prefix . '_features'))) {
-      $form[$info->name]['operations'] = array('#type' => 'markup', '#value' => l(t('configure'), 'admin/build/themes/settings/' . $info->name) );
+      $form[$info->name]['operations'] = array(
+				'#type' => 'markup', 
+				'#value' => l(t('configure'), 
+				'admin/build/themes/settings/' . $info->name) 
+			);
     }
     else {
       // Dummy element for form_render. Cleaner than adding a check in the theme function.
@@ -1090,14 +1283,38 @@
     }
   }
 
-  $form['status'] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => $status);
-  $form['theme_default'] = array('#type' => 'radios', '#options' => $options, '#default_value' => variable_get('theme_default', 'bluemarine'));
-  $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
-  $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
+  $form['status'] = array(
+		'#type' => 'checkboxes', 
+		'#options' => $options, 
+		'#default_value' => $status
+	);
+  
+  $form['theme_default'] = array(
+		'#type' => 'radios', 
+		'#options' => $options, 
+		'#default_value' => variable_get('theme_default', 'bluemarine')
+	);
+  
+  $form['buttons']['submit'] = array(
+		'#type' => 'submit', 
+		'#value' => t('Save configuration') 
+	);
+
+  $form['buttons']['reset'] = array(
+		'#type' => 'submit', 
+		'#value' => t('Reset to defaults') 
+	);
 
   return drupal_get_form('system_themes', $form);
 }
 
+/**
+ * Theme hook for the themes page.
+ * @param 
+ *  The form to render. 
+ * @return
+ * 	The formatted content.
+ */
 function theme_system_themes($form) {
   foreach (element_children($form) as $key) {
     $row = array();
@@ -1113,13 +1330,26 @@
     $rows[] = $row;
   }
 
-  $header = array(t('Screenshot'), t('Name'), t('Enabled'), t('Default'), t('Operations'));
+  $header = array(
+  	t('Screenshot'), 
+  	t('Name'), 
+  	t('Enabled'), 
+  	t('Default'), 
+  	t('Operations')
+  );
+  
   $output = theme('table', $header, $rows);
   $output .= form_render($form);
   return $output;
 }
 
-
+/**
+ * Implementation of the themes hook_submit().
+ * @param $form_id
+ * 	The id of the form
+ * @param $values
+ * 	The form values passed back from the client.
+ */
 function system_themes_submit($form_id, $values) {
 
   db_query("UPDATE {system} SET status = 0 WHERE type = 'theme'");
@@ -1150,138 +1380,437 @@
 }
 
 /**
+ * Parse drupal meta file format.
+ *
+ * @param $filename 
+ *   The path to the filename
+ * @return 
+ * 	 The meta data array
+ */
+function system_parse_meta_file($filename) {
+	$handle = fopen($filename, "r");
+	$meta = fread($handle, filesize($filename));
+	fclose($handle);
+	$metadata = array();				
+	if (preg_match_all('@^\s*((?:[^:/]|/(?!/))+?)\s*:\s*(?:("(?:[^"]|(?<=\\\\)")*")|(\'(?:[^\']|(?<=\\\\)\')*\')|([^\n]*?))\s*($|//)@ms', $meta, $matches, PREG_SET_ORDER)) {
+	  foreach ($matches as $match) {
+	    list(, $key, $value1, $value2, $value3) = $match;
+	    $value = stripslashes(trim($value1, '"')) . stripslashes(trim($value2, "'")) . $value3;
+    	$metadata[$key] = $value;
+	  }
+	}	
+	return $metadata;
+}
+
+/**
+ * Load the metadata associated with a module.
+ *
+ * @param $module
+ *   The name of the module
+ * @param $path
+ *   The path the module lives in, not including the module name.
+ */
+function system_get_meta_info($module, $path) {
+  $filename = $path . '/' . $module . '.meta';
+  $metadata = array();
+
+  if (file_exists($filename)) {
+    //$metadata = parse_ini_file($filename, true);
+    $metadata = system_parse_meta_file($filename);
+  }
+  if (!$metadata['package']) {
+    $metadata['package'] = t('uncategorized');
+  }
+  if (!$metadata['version']) {
+    $metadata['version'] = t('unknown');
+  }
+  if (!$metadata['drupal']) {
+    $metadata['drupal'] = t('undefined');
+  }
+  if (!$metadata['name']) {
+    $metadata['name'] = $module;
+  }
+  if (!$metadata['links']) {
+    $metadata['links'] = array();
+  }
+  else {
+ 		$metadata['links'] = explode(",",$metadata['links']);
+    $links = array();
+    foreach ($metadata['links'] as $link) {
+    	list($link, $destination) = explode("=",$link,2);
+      $links[] = array('title' => trim($link), 'href' => trim($destination));
+    }
+    $metadata['links'] = $links;
+  }
+  if ($metadata['dependencies']) {
+    $metadata['dependencies'] = explode(',', $metadata['dependencies']);
+  }
+  else {
+    $metadata['dependencies'] = array();
+  }
+  return $metadata;
+}
+
+/**
+ * This is called to update the system table when a module changes paths or
+ * new modules are discovered.
+ */
+function system_update_system_table($file) {
+  // log the critical hooks implemented by this module
+  $bootstrap = 0;
+  foreach (bootstrap_hooks() as $hook) {
+    if (module_hook($file->name, $hook)) {
+      $bootstrap = 1;
+      break;
+    }
+  }
+
+  // Update the contents of the system table:
+  if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) {
+    db_query("UPDATE {system} SET description = '%s', name = '%s', bootstrap = %d, filename = '%s' WHERE filename = '%s'", $file->description, $file->name, $bootstrap, $file->filename, $file->old_filename);
+  }
+  else {
+    // This is a new module.
+    db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
+  }
+}
+
+/**
+ * Helper function to reduce code. Provides a form that is a button or two
+ * keyed to the module.
+ */
+function system_module_form($module, $metadata, $type, $type2 = NULL) {
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => $type,
+  );
+  
+  $form['metadata'] = array(
+    '#type' => 'value',
+    '#value' => $metadata,
+  );
+  
+  if ($type2) {
+    $form['submit2'] = array(
+      '#type' => 'submit',
+      '#value' => $type2,
+    );
+  
+  }
+  return drupal_get_form("system_module_form_$module", $form, 'system_module_form');
+}
+
+/**
  * Menu callback; displays a listing of all modules.
  */
-function system_modules() {
+function system_modules($type) {
   // Get current list of modules
   $files = system_listing('\.module$', 'modules', 'name', 0);
-
   // Extract current files from database.
   system_get_files_database($files, 'module');
 
   ksort($files);
 
+  $required = array('block', 'filter', 'node', 'system', 'user', 'watchdog');
   foreach ($files as $filename => $file) {
-    drupal_get_filename('module', $file->name, $file->filename);
-    drupal_load('module', $file->name);
-
-    $file->description = module_invoke($file->name, 'help', 'admin/settings/modules#description');
-
-    $form['name'][$file->name] = array('#value' => $file->name);
-    $form['description'][$file->name] = array('#value' => $file->description);
-    $options[$file->name] = '';
-    if ($file->status) {
-      $status[] = $file->name;
-    }
-    if ($file->throttle) {
-      $throttle[] = $file->name;
+    $metadata = system_get_meta_info($file->name, dirname($file->filename));
+    if (($type == 'enabled' && $file->status) || ($type == 'disabled' && !$file->status)) {
+      $packages[$metadata['package']][] = $file->name;
+      $options[$file->name] = '';
+      system_update_system_table($file);
     }
+    $file->description = $metadata['description'];
 
-    // log the critical hooks implemented by this module
-    $bootstrap = 0;
-    foreach (bootstrap_hooks() as $hook) {
-      if (module_hook($file->name, $hook)) {
-        $bootstrap = 1;
-        break;
-      }
-    }
-
-    // Update the contents of the system table:
-    if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) {
-      db_query("UPDATE {system} SET description = '%s', name = '%s', bootstrap = %d, filename = '%s' WHERE filename = '%s'", $file->description, $file->name, $bootstrap, $file->filename, $file->old_filename);
+    // for later dependency checking.
+    if ($file->status) {
+      $metadata['enabled'] = true;
     }
-    else {
-      // This is a new module.
-      db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->description, 'module', $file->filename, $file->status, $file->throttle, $bootstrap);
+    else if ($file->schema_version != -1) {
+      $metadata['uninstalled'] = true;
     }
+    $metdata['filename'] = $file->filename;
+    $modules[$filename] = $metadata;
   }
+  // Re-order packages to force core modules to the top.
+  ksort($packages);
+  $packages = array_merge(
+  	array(
+  		t('required modules') => $packages[t('required modules')],
+  		t('drupal core modules') => $packages[t('drupal core modules')]
+  	),
+  	$packages
+  );
+
+  if (!is_array($packages[t('required modules')])) { // this is only on enabled page
+  	array_splice($packages,0,1); 
+  }
+
+	// set header for the rest.
+	// This was the first attempt at theming the headings and is not required anymore 
+	// @see theme_system_modules_table
+	// I would like to simplify this in a patch on theme.inc. 
+	// Consistency: @see theme.inc#_theme_table_cell use of attributes.
+/*  $header = array(
+		theme('links', array(array(
+				'title' => t('Name'), 
+				'attributes' => array(
+						'class' => 'modules-heading', 
+						'style' => 'font-weight : bold;') //to be removed to stylesheet
+				)
+		)),
+		theme('links', array(array(
+				'title' => t('Version'), 
+				'attributes' => array(
+						'class' => 'modules-heading', 
+						'style' => 'font-weight : bold;') //to be removed to stylesheet
+				)
+		)),
+		theme('links', array(array(
+				'title' => t('Description'), 
+				'attributes' => array(
+						'class' => 'modules-heading', 
+						'style' => 'font-weight : bold;') //to be removed to stylesheet
+				)
+		)),
+		theme('links', array(array(
+				'title' => t('Operations'), 
+				'attributes' => array(
+						'class' => 'modules-heading', 
+						'style' => 'font-weight : bold;') //to be removed to stylesheet
+				)
+		))
+  );
+*/
+
+  $header = array(
+ 		array('data' => t('Name'),'header' => 1),
+ 		array('data' => t('Version'),'header' => 1),
+ 		array('data' => t('Description'),'header' => 1),
+ 		array('data' => t('Operations'),'header' => 1)
+ 	);
+ 			 
+  $rows = array();
+  foreach ($packages as $group => $package) {
+
+    	$rows[] = array(array(
+    		'colspan' => 4,
+    		'header'	=> 1,
+				'data' => theme('links',array(array(
+					'title' => $group, 
+					'attributes' => array(
+						'class' => 'modules-header', 
+						'style' => 'font-weight : bold;') //to be removed to stylesheet
+					)
+				)))
+			);
+   	$rows[] = $header;
+    foreach ($package as $module) {
+    	$modules[$module]['buttons'] = array();
+    
+      // Check for dependencies.
+      $depends = '';
+      $can_change = true;
+      $compatible = stripos(VERSION,$modules[$module]['drupal']) === 0;
+				
+      if (!$modules[$module]['enabled']) {
+        // disabled modules and don't get their links
+        $modules[$module]['links'] = array();
+        foreach ($modules[$module]['dependencies'] as $dependency) {
+          $depends .= (!$depends ? t('Depends on: ') : ', ') . "<em>$dependency</em>";
+          if (!$modules[$dependency]['enabled']) {
+            $depends .= t(' (not present)');
+            $can_change = false;
+          }
+        }
+        if ($can_change&&$compatible) {
+          if ($modules[$module]['uninstalled']) {
+            $modules[$module]['buttons'][] = system_module_form($module, $modules[$module], t('Enable'), t('Uninstall'));
+          } 
+          else {
+            $modules[$module]['buttons'][] = system_module_form($module, $modules[$module], t('Install'));  
+          }
+        }
+        else {
+          if ($modules[$module]['uninstalled']) {
+            $modules[$module]['buttons'][] = system_module_form($module, $modules[$module], t('Uninstall'));
+          } 
+        }
+      }
+      else {
+        // Check for modules that depend on this module.
+        foreach ($modules as $dependency => $module_data) {
+          if (in_array($module, $module_data['dependencies']) && $module_data['enabled']) {
+            $depends .= (!$depends ? t('Required by: ') : ', ') . "<em>$dependency</em>";
+            $can_change = false;
+          }
+        }
+        if ($can_change && !in_array($module, $required)) {
+          $modules[$module]['buttons'][] = system_module_form($module, $modules[$module], t('Disable'));
+        }
+      }
 
+      $cells = array();
+      $cells[] = $modules[$module]['name'];
+      $cells[] = $modules[$module]['version'];
+      $cells[] = $modules[$module]['description'];
+      $cells[] = array(
+				'data' => theme('operations_links',	$modules[$module]['links'],	$modules[$module]['buttons']),
+				'nowrap' => TRUE
+			);
 
-  // Handle status checkboxes, including overriding the generated
-  // checkboxes for required modules.
-  $form['status'] = array('#type' => 'checkboxes', '#default_value' => $status, '#options' => $options);
-  $required = array('block', 'filter', 'node', 'system', 'user', 'watchdog');
-  foreach ($required as $require) {
-    $form['status'][$require] = array('#type' => 'hidden', '#value' => 1, '#suffix' => t('required'));
-  }
+      $rows[] = $cells;
+      if ($depends) {
+        $rows[] = array('',array('data' => $depends, 'colspan' => 3));
+      }
+      if (!$compatible) {
+        $rows[] = array('',array('data' => t('(This module is not compatible with your current Drupal version)'), 'colspan' => 3));
+      }
 
-  /**
-   * Handle throttle checkboxes, including overriding the generated checkboxes for required modules.
-   */
-  if (module_exist('throttle')) {
-    $form['throttle'] = array('#type' => 'checkboxes', '#default_value' => $throttle, '#options' => $options);
-    $throttle_required = array_merge($required, array('throttle'));
-    foreach ($throttle_required as $require) {
-      $form['throttle'][$require] = array('#type' => 'hidden', '#value' => 0, '#suffix' => t('required'));
     }
   }
-
-  $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
-
-  return drupal_get_form('system_modules', $form);
-}
-
-function theme_system_modules($form) {
-  foreach (element_children($form['name']) as $key) {
-    $row = array();
-    $row[] = form_render($form['name'][$key]);
-    $row[] = form_render($form['description'][$key]);
-    $row[] = array('data' => form_render($form['status'][$key]), 'align' => 'center');
-
-    if (module_exist('throttle')) {
-      $row[] = array('data' => form_render($form['throttle'][$key]), 'align' => 'center');
+    if ($rows) {
+      $output .= theme('system_modules_table', array(), $rows, array('width' => '100%'));
     }
-    $rows[] = $row;
-  }
-
-  $header = array(t('Name'), t('Description'), t('Enabled'));
-  if (module_exist('throttle')) {
-    $header[] = t('Throttle');
-  }
 
-  $output = theme('table', $header, $rows);
   $output .= form_render($form);
   return $output;
 }
 
 
-function system_modules_submit($form_id, $edit) {
-  db_query("UPDATE {system} SET status = 0, throttle = 0 WHERE type = 'module'");
+/**
+ * This is only for a proof of concept to get theme.inc patched to allow for cells to 
+ * be able to identify that they are <th> and not <td>
+ * Thus the call to the private method in theme.inc _theme_table_cell
+ */
+function theme_system_modules_table($header, $rows, $attributes = array()) {
+  $output = '<table'. drupal_attributes($attributes) .">\n";
+  // Format the table header:
+  if (count($header)) {
+    $ts = tablesort_init($header);
+    $output .= ' <thead><tr>';
+    foreach ($header as $cell) {
+      $cell = tablesort_header($cell, $header, $ts);
+      $output .= _theme_table_cell($cell, 1); //private method call for proof of concept
+    }
+    $output .= " </tr></thead>\n";
+  }
+
+  // Format the table rows:
+  $output .= "<tbody>\n";
+  if (count($rows)) {
+    foreach ($rows as $number => $row) {
+      $attributes = array();
+
+      // Check if we're dealing with a simple or complex row
+      if (isset($row['data'])) {
+        foreach ($row as $key => $value) {
+          if ($key == 'data') {
+            $cells = $value;
+          }
+          else {
+            $attributes[$key] = $value;
+          }
+        }
+      }
+      else {
+        $cells = $row;
+      }
 
-  $new_modules = array();
-  foreach ($edit['status'] as $key => $choice) {
-    if ($choice) {
-      db_query("UPDATE {system} SET status = 1 WHERE type = 'module' AND name = '%s'", $key);
-      if (!module_exist($key)) {
-        $new_modules[] = $key;
+      // Add odd/even class
+      $class = ($number % 2 == 1) ? 'even': 'odd';
+      if (isset($attributes['class'])) {
+        $attributes['class'] .= ' '. $class;
+      }
+      else {
+        $attributes['class'] = $class;
       }
-    }
-  }
 
-  if (is_array($edit['throttle'])) {
-    foreach ($edit['throttle'] as $key => $choice) {
-      if ($choice) {
-        db_query("UPDATE {system} SET throttle = 1 WHERE type = 'module' and name = '%s'", $key);
+      // Build row
+      $output .= ' <tr'. drupal_attributes($attributes) .'>';
+      $i = 0;
+			$header_keys = array(1,true,'th'); //any possibility of identifying a cell as a header
+      foreach ($cells as $cell) {
+        $cell = tablesort_cell($cell, $header, $ts, $i++);
+        $isheader = 0; // default cell not a th
+        if (isset($cell['header'])) {
+        	if (in_array($cell['header'],$header_keys)) {
+						$isheader = 1;        	
+        	}
+	        unset($cell['header']); //remove header to not end up in attributes
+        }
+        $output .= _theme_table_cell($cell, $isheader); //private method call for proof of concept
       }
+      $output .= " </tr>\n";
     }
   }
 
-  module_list(TRUE, FALSE);
+  $output .= "</tbody></table>\n";
+  return $output;
+}
 
-  include './includes/install.inc';
-  foreach ($new_modules as $module) {
-    // Set the installed schema version for newly-enabled modules
-    $versions = drupal_get_schema_versions($module);
-    if (drupal_get_installed_schema_version($module) == SCHEMA_UNINSTALLED) {
+/**
+ * Theme call back for module action buttons and links.
+ * @param $links
+ * 	List of links.
+ * @param $buttons
+ * 	List of buttons.
+ */
+function theme_operations_links($links,$buttons){
+		$output  =  '<div class="container-inline">';
+		$output .=	theme('links', $links);
+		$output .=	' ';
+		$output .=	implode(' ', $buttons);	
+		$output .=	'</div>';	
+	return $output;								
+}
+
+/**
+ * Implementation of the module form hook_submit().
+ * @param $form_id
+ * 	The id of the form.
+ * @param $form_values
+ * 	The values passed back from the client.
+ */
+function system_module_form_submit($form_id, $form_values) {
+  $module = str_replace('system_module_form_', '', $form_id);
+  $metadata = $form_values['metadata'];
+
+  // include the module's .install file
+  $install_file = dirname($metadata['filename']) .'/'. $module .'.install';
+  if (is_file($install_file)) {
+    include_once $install_file;
+  }
+
+  $op = $_POST['op'];
+  if ($op == t('Install') || $op == t('Enable')) {
+    $status = 1;
+    if ($op == t('Install')) {
+      include './includes/install.inc';
+      // Set the installed schema version for newly installed modules
+      $versions = drupal_get_schema_versions($module);
       drupal_set_installed_schema_version($module, $versions ? max($versions) : SCHEMA_INSTALLED);
       module_invoke($module, 'install');
+      drupal_set_message(t('%module installed.', array('%module' => $metadata['name'])));
+    } 
+    else {
+      module_invoke($module, 'enable');
+      drupal_set_message(t('%module enabled.', array('%module' => $metadata['name'])));
     }
   }
-
+  else {
+    $status = 0;
+    if ($op == t('Uninstall')) {
+      include './includes/install.inc';
+      drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
+      drupal_set_message(t('%module uninstalled.', array('%module' => $metadata['name'])));
+    }
+    else {
+      module_invoke($module, 'disable');
+      drupal_set_message(t('%module disabled.', array('%module' => $metadata['name'])));
+    }
+  }
+  db_query("UPDATE {system} SET status = %d WHERE type = 'module' AND name = '%s'", $status, $module);
   menu_rebuild();
-
-  drupal_set_message(t('The configuration options have been saved.'));
-  return 'admin/settings/modules';
 }
 
 
@@ -1326,7 +1855,10 @@
     $var = 'theme_settings';
   }
 
-  $form['var'] = array('#type' => 'hidden', '#value' => $var);
+  $form['var'] = array(
+		'#type' => 'hidden', 
+		'#value' => $var
+	);
 
   // Check for a new uploaded logo, and use that instead.
   if ($file = file_check_upload('logo_upload')) {
@@ -1348,6 +1880,7 @@
   // Check for a new uploaded favicon, and use that instead.
   if ($file = file_check_upload('favicon_upload')) {
     $parts = pathinfo($file->filename);
+  	//TODO: Change to if statemnt for readability
     $filename = ($key) ? str_replace('/', '_', $key) . '_favicon.' . $parts['extension'] : 'favicon.' . $parts['extension'];
 
     if ($file = file_save_upload('favicon_upload', $filename, 1)) {
@@ -1387,7 +1920,12 @@
   foreach ($toggles as $name => $title) {
     if ((!$key) || in_array($name, $features)) {
       // disable search box if search.module is disabled
-      $form['theme_settings'][$name] = array('#type' => 'checkbox', '#title' => $title, '#default_value' => $settings[$name]);
+      $form['theme_settings'][$name] = array(
+				'#type' => 'checkbox', 
+				'#title' => $title, 
+				'#default_value' => $settings[$name]
+			);
+      
       if (isset($disabled[$name])) {
         $form['theme_settings'][$name]['#attributes'] = array('disabled' => 'disabled');
       }
@@ -1412,8 +1950,13 @@
         '#prefix' => '<div class="theme-settings-right">',
         '#suffix' => '</div>',
       );
+      
       foreach ($node_types as $type => $name) {
-        $form['node_info']["toggle_node_info_$type"] = array('#type' => 'checkbox', '#title' => $name, '#default_value' => $settings["toggle_node_info_$type"]);
+        $form['node_info']["toggle_node_info_$type"] = array(
+					'#type' => 'checkbox', 
+					'#title' => $name, 
+					'#default_value' => $settings["toggle_node_info_$type"]
+				);
       }
     }
   }
@@ -1426,6 +1969,7 @@
       '#description' => t('If toggled on, the following logo will be displayed.'),
       '#attributes' => array('class' => 'theme-settings-bottom'),
     );
+    
     $form['logo']["default_logo"] = array(
       '#type' => 'checkbox',
       '#title' => t('Use the default logo'),
@@ -1433,11 +1977,13 @@
       '#tree' => FALSE,
       '#description' => t('Check here if you want the theme to use the logo supplied with it.')
     );
+    
     $form['logo']['logo_path'] = array(
       '#type' => 'textfield',
       '#title' => t('Path to custom logo'),
       '#default_value' => $settings['logo_path'],
-      '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.'));
+      '#description' => t('The path to the file you would like to use as your logo file instead of the default logo.')
+    );
 
     $form['logo']['logo_upload'] = array(
       '#type' => 'file',
@@ -1449,14 +1995,22 @@
 
   // Icon settings
   if ((!$key) || in_array('toggle_favicon', $features)) {
-    $form['favicon'] = array('#type' => 'fieldset', '#title' => t('Shortcut icon settings'));
-    $form['favicon']['text'] = array('#value' => t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.'));
+    $form['favicon'] = array(
+			'#type' => 'fieldset', 
+			'#title' => t('Shortcut icon settings')
+		);
+    
+    $form['favicon']['text'] = array(
+			'#value' => t('Your shortcut icon or \'favicon\' is displayed in the address bar and bookmarks of most browsers.')
+		);
+
     $form['favicon']['default_favicon'] = array(
       '#type' => 'checkbox',
       '#title' => t('Use the default shortcut icon.'),
       '#default_value' => $settings['default_favicon'],
       '#description' => t('Check here if you want the theme to use the default shortcut icon.')
     );
+
     $form['favicon']['favicon_path'] = array(
       '#type' => 'textfield',
       '#title' => t('Path to custom icon'),
@@ -1477,11 +2031,23 @@
     if (function_exists($function)) {
       if ($themes[$key]->template) {
         // file is a template or a style of a template
-        $form['specific'] = array('#type' => 'fieldset', '#title' => t('Engine-specific settings'), '#description' => t('These settings only exist for all the templates and styles based on the %engine theme engine.', array('%engine' => $themes[$key]->prefix)));
+        $form['specific'] = array(
+					'#type' => 'fieldset', 
+					'#title' => t('Engine-specific settings'), 
+					'#description' => t('These settings only exist for all the templates and styles based on the %engine theme engine.', 
+					array('%engine' => $themes[$key]->prefix))
+				);
+
       }
       else {
         // file is a theme or a style of a theme
-        $form['specific'] = array('#type' => 'fieldset', '#title' => t('Theme-specific settings'), '#description' => t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->prefix)));
+        $form['specific'] = array(
+					'#type' => 'fieldset', 
+					'#title' => t('Theme-specific settings'), 
+					'#description' => t('These settings only exist for the %theme theme and all the styles based on it.', 
+					array('%theme' => $themes[$key]->prefix))
+				);
+
       }
       $group = $function();
       $form['specific'] = array_merge($form['specific'], (is_array($group) ? $group : array()));
@@ -1531,11 +2097,26 @@
   drupal_set_title($question);
   $form['#attributes'] = array('class' => 'confirmation');
   $form['description'] = array('#value' => $description);
-  $form[$name] = array('#type' => 'hidden', '#value' => 1);
 
-  $form['actions'] = array('#prefix' => '<div class="container-inline">', '#suffix' => '</div>');
-  $form['actions']['submit'] = array('#type' => 'submit', '#value' => $yes ? $yes : t('Confirm'));
-  $form['actions']['cancel'] = array('#value' => l($no ? $no : t('Cancel'), $path));
+  $form[$name] = array(
+		'#type' => 'hidden', 
+		'#value' => 1
+	);
+
+  $form['actions'] = array(
+		'#prefix' => '<div class="container-inline">', 
+		'#suffix' => '</div>'
+	);
+  
+  $form['actions']['submit'] = array(
+		'#type' => 'submit', 
+		'#value' => $yes ? $yes : t('Confirm')
+	);
+  
+  $form['actions']['cancel'] = array(
+		'#value' => l($no ? $no : t('Cancel'), $path)
+	);
+  
   return drupal_get_form($form_id, $form, 'confirm_form');
 }
 
