/[drupal]/contributions/modules/util/system_module.module
ViewVC logotype

Contents of /contributions/modules/util/system_module.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.13 - (show annotations) (download) (as text)
Thu Dec 18 16:40:27 2008 UTC (11 months, 1 week ago) by litwol
Branch: MAIN
CVS Tags: HEAD
Changes since 1.12: +3 -1 lines
File MIME type: text/x-php
#287990 by psynaptic: "Add a message when settings are saved"
1 <?php
2
3
4 function system_module_menu() {
5 $menu['admin/settings/util/sysmods'] = array(
6 'title' => 'System Modules Settings',
7 'description' => 'Customize System Modules fieldsets.',
8 'page callback' => 'drupal_get_form',
9 'page arguments' => array('system_module_settings'),
10 'access arguments' => array('administer site configuration'),
11 );
12 return $menu;
13 }
14
15 function system_module_settings() {
16 global $user;
17 //get all available packages
18 $modules = module_rebuild_cache();
19 foreach ($modules as $module) {
20 if (!isset($module->info['package']) || !$module->info['package']) {
21 $module->info['package'] = t('Other');
22 }
23 $packages[$module->info['package']] = $module->info['package'];
24 }
25 ksort($packages);
26 //build settings form
27
28 $result = db_fetch_array(db_query("SELECT data FROM {system_module_users} WHERE uid = %d}", $user->uid));
29 $result = unserialize($result['data']);
30
31
32 $form['system_module_cfg'] = array(
33 '#type' => 'checkboxes',
34 '#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'))),
35 '#default_value' => (isset($result) && is_array($result)?array_keys($result):array()),
36 '#options' => $packages,
37 );
38 $form['system_module_show_counts'] = array(
39 '#type' => 'checkbox',
40 '#title' => t('Show module counts after package title'),
41 '#default_value' => variable_get('system_module_show_counts', 1),
42 );
43
44 $form['submit'] = array(
45 '#type' => 'submit',
46 '#value' => 'Submit',
47 );
48 return $form;
49 }
50
51 function system_module_settings_submit($form, &$form_state) {
52 global $user;
53
54 $values = $form_state['values'];
55 foreach ($values['system_module_cfg'] as $index => $value) {
56 if ($value === 0) {
57 unset($values['system_module_cfg'][$index]);
58 }
59 }
60
61 $data = serialize($values['system_module_cfg']);
62 // Update.
63 db_query("UPDATE {system_module_users} SET data = '%s' WHERE uid = %d", $data, $user->uid);
64 if (!db_affected_rows()) {
65 // Insert.
66 @db_query("INSERT INTO {system_module_users} (uid, data) VALUES (%d, '%s')", $user->uid, $data);
67 }
68
69 variable_set('system_module_show_counts', $values['system_module_show_counts']);
70
71 // Save user settings.
72 if (user_save($user, array('system_module_cfg' => $values['system_module_cfg']))) {
73 drupal_set_message('Configuration options have been saved.');
74 }
75 }
76
77 // the theme registry
78 function system_module_theme() {
79 return array(
80 'system_modules_theme' => array(
81 'arguments' => array('form' => null),
82 ),
83 );
84 }
85
86 function system_module_form_alter(&$form, $form_state, $form_id) {
87 switch ($form_id) {
88 case 'system_modules':
89 //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.
90 $form['#theme'] = 'system_modules_theme';
91 $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')));
92 break;
93 }
94 }
95
96 //most of this function was copied from system.module
97 function theme_system_modules_theme($form) {
98 global $user; //needed to enable
99 //print 'what the hell';
100 if (isset($form['confirm'])) {
101 return drupal_render($form);
102 }
103
104 // Individual table headers.
105 $header = array(t('Enabled'));
106 if (module_exists('throttle')) {
107 $header[] = t('Throttle');
108 }
109 $header[] = t('Name');
110 $header[] = t('Version');
111 $header[] = t('Description');
112
113 //allow other modules to alter headers
114 drupal_alter('system_module_headers', $header);
115
116 // Pull package information from module list and start grouping modules.
117 $modules = $form['validation_modules']['#value'];
118 foreach ($modules as $module) {
119 if (!isset($module->info['package']) || !$module->info['package']) {
120 $module->info['package'] = t('Other');
121 }
122 $packages[$module->info['package']][$module->name] = $module->info;
123 }
124 ksort($packages);
125
126 // Display packages.
127 $output = '';
128 foreach ($packages as $package => $modules) {
129 $rows = array();
130
131 $enabled_count = 0;
132 foreach ($modules as $key => $module) {
133 if (isset($form['status'][$key]['#default_value']) && $form['status'][$key]['#default_value']) {
134 $enabled_count++;
135 }
136 $row = array();
137 $description = drupal_render($form['description'][$key]);
138 if (isset($form['status']['#incompatible_modules_core'][$key])) {
139 unset($form['status'][$key]);
140 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of Drupal core'));
141 $description .= '<div class="incompatible">'. t('This version is incompatible with the !core_version version of Drupal core.', array('!core_version' => VERSION)) .'</div>';
142 }
143 elseif (isset($form['status']['#incompatible_modules_php'][$key])) {
144 unset($form['status'][$key]);
145 $status = theme('image', 'misc/watchdog-error.png', t('incompatible'), t('Incompatible with this version of PHP'));
146 $php_required = $form['status']['#incompatible_modules_php'][$key];
147 if (substr_count($php_required, '.') < 2) {
148 $php_required .= '.*';
149 }
150 $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>';
151 }
152 else {
153 $status = drupal_render($form['status'][$key]);
154 }
155 $row[] = array('data' => $status, 'align' => 'center');
156 if (module_exists('throttle')) {
157 $row[] = array('data' => drupal_render($form['throttle'][$key]), 'align' => 'center');
158 }
159 $row[] = '<strong>'. drupal_render($form['name'][$key]) .'</strong>';
160 $row[] = drupal_render($form['version'][$key]);
161 $row[] = array('data' => $description, 'class' => 'description');
162
163 //allow other modules to alter table rows
164 $row['__drupal_alter_by_ref'][] = $key;
165 $row['__drupal_alter_by_ref'][] = &$form;
166 drupal_alter('system_module_weights', $row);
167
168 $rows[] = $row;
169 }
170 $title = $package;
171 if (variable_get('system_module_show_counts', 1)) {
172 $title .= ' ['. $enabled_count .'] of ['. sizeof($modules) .']';
173 }
174 $fieldset = array(
175 '#title' => $title,
176 '#collapsible' => TRUE,
177 '#collapsed' => (isset($user->system_module_cfg[$package])? true:false), //here we influence the fieldset to be collapsed or expanded by default.
178 '#value' => theme('table', $header, $rows, array('class' => 'package')),
179 );
180 $output .= theme('fieldset', $fieldset);
181 }
182
183 $output .= drupal_render($form);
184 return $output;
185 }

  ViewVC Help
Powered by ViewVC 1.1.2