| 15 |
function administration_help($section) { |
function administration_help($section) { |
| 16 |
switch ($section) { |
switch ($section) { |
| 17 |
case 'admin/modules#description': |
case 'admin/modules#description': |
| 18 |
return t('Site administration dashboard.'); |
return t('Site administration dashboard. <strong>Do not disable this module</strong> without first going to <a href="%settings">administration settings</a> and clicking "deactivate menus."', array('%settings' => url('admin/settings/administration'))); |
| 19 |
case 'admin/settings/administration': |
case 'admin/settings/administration': |
| 20 |
return t('IMPORTANT! Before deactivating this module click the "Deactivate" button on this page. If you deactivate this module BEFORE clicking the "Deactivate" button on this page you will need to reactivate the administration module by going to url "admin/modules" and then return here and click "Deactivate".'); |
return t('IMPORTANT! Before deactivating this module click the "Deactivate" button on this page. If you deactivate this module BEFORE clicking the "Deactivate" button on this page you will need to reactivate the administration module by going to url "admin/modules" and then return here and click "Deactivate".'); |
| 21 |
} |
} |
| 24 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 25 |
*/ |
*/ |
| 26 |
function administration_menu($may_cache) { |
function administration_menu($may_cache) { |
|
global $user; |
|
|
|
|
|
$items = array(); |
|
| 27 |
if ($may_cache) { |
if ($may_cache) { |
| 28 |
$access = user_access('administer site configuration'); |
$access = user_access('administer site configuration'); |
| 29 |
$top_path = 'sadmin'; |
$top_path = 'sadmin'; |
| 30 |
|
|
| 31 |
if (variable_get('administration_module_active', 'false') == 'true') { |
if (variable_get('administration_module_active', FALSE)) { |
| 32 |
$config = administration_menu_config(); |
$config = administration_menu_config(); |
| 33 |
if ($config['top_path']) { |
if ($config['top_path']) { |
| 34 |
$top_path = $config['top_path']; |
$top_path = $config['top_path']; |
| 75 |
'type' => MENU_CALLBACK |
'type' => MENU_CALLBACK |
| 76 |
); |
); |
| 77 |
|
|
| 78 |
if (variable_get('administration_module_active', 'false') == 'true') { |
if (variable_get('administration_module_active', FALSE)) { |
| 79 |
$menu_weight = -10; |
$menu_weight = -10; |
| 80 |
|
// Redefine the 'admin' menu here as a callback to get rid of it in the menu |
| 81 |
|
// we need to do this so 'logs' doesn't show up twice |
| 82 |
|
$items[] = array( |
| 83 |
|
'path' => 'admin', |
| 84 |
|
'type' => MENU_CALLBACK |
| 85 |
|
); |
| 86 |
|
|
| 87 |
foreach ($config['section'] as $section_path => $section) { |
foreach ($config['section'] as $section_path => $section) { |
| 88 |
if ($section['callback']) { |
if ($section['callback']) { |
| 89 |
$items[] = array( |
$items[] = array( |
| 93 |
'access' => $access, |
'access' => $access, |
| 94 |
'callback' => $section['callback'], |
'callback' => $section['callback'], |
| 95 |
'callback arguments' => $section['callback arguments'], |
'callback arguments' => $section['callback arguments'], |
| 96 |
'type' => MENU_NORMAL_ITEM, |
'type' => ($section['callback'] == '_administration_sub_dashboard_page' ? MENU_ITEM_GROUPING : MENU_NORMAL_ITEM), |
| 97 |
'weight' => isset($section['weight']) ? $section['weight'] : $menu_weight++, |
'weight' => isset($section['weight']) ? $section['weight'] : $menu_weight++, |
| 98 |
); |
); |
| 99 |
|
$item_weight = 0; |
| 100 |
foreach ((array) $section['items'] as $item_path => $item_info) { |
foreach ((array) $section['items'] as $item_path => $item_info) { |
|
$item_weight = 0; |
|
| 101 |
if ($item_info['callback']) { |
if ($item_info['callback']) { |
| 102 |
$items[] = array( |
$items[] = array( |
| 103 |
'path' => $item_path, |
'path' => $item_path, |
| 115 |
} |
} |
| 116 |
} |
} |
| 117 |
} |
} |
|
theme_add_style(drupal_get_path('module','administration') .'/administration.css'); |
|
| 118 |
return $items; |
return $items; |
| 119 |
} |
} |
| 120 |
|
|
| 169 |
/** |
/** |
| 170 |
* Display the form that turns on and off the menu configuration. |
* Display the form that turns on and off the menu configuration. |
| 171 |
*/ |
*/ |
| 172 |
function administration_form($edit = '') { |
function administration_form() { |
| 173 |
if (!module_exist('menu')) { |
if (!module_exist('menu')) { |
| 174 |
drupal_set_message(t('IMPORTANT! The "Menu" must be enabled BEFORE you activate this module!'), 'error'); |
drupal_set_message(t('IMPORTANT! The "Menu" must be enabled BEFORE you activate this module!'), 'error'); |
| 175 |
} |
} |
| 176 |
if (variable_get('administration_module_active', 'false') == 'true') { |
if (variable_get('administration_module_active', FALSE)) { |
| 177 |
$config = administration_menu_config(); |
$config = administration_menu_config(); |
| 178 |
if (function_exists('administration_form_' . variable_get('administration_config', 'default'))) { |
if (function_exists('administration_form_' . variable_get('administration_config', 'default'))) { |
| 179 |
$form = call_user_func('administration_form_' . variable_get('administration_config', 'default'), $form, $edit); |
$form[variable_get('administration_config', 'default')] = call_user_func('administration_form_' . variable_get('administration_config', 'default'), $form); |
| 180 |
} |
} |
|
$form['buttons']['activate'] = array('#type' => 'submit', '#value' => t('Deactivate menus')); |
|
| 181 |
} |
} |
| 182 |
else { |
else { |
| 183 |
$files = system_listing('\.inc$', drupal_get_path('module', 'administration'), 'name', 0); |
$files = system_listing('\.inc$', drupal_get_path('module', 'administration'), 'name', 0); |
| 184 |
foreach ($files as $file => $info) { |
foreach ($files as $file => $info) { |
| 185 |
$options[$file] = $file; |
$options[$file] = $file; |
| 186 |
} |
} |
| 187 |
$form['config'] = array( |
$form['administration_config'] = array( |
| 188 |
'#type' => 'radios', |
'#type' => 'radios', |
| 189 |
|
'#title' => t('Configuration profile'), |
| 190 |
'#default_value' => variable_get('administration_config', 'default'), |
'#default_value' => variable_get('administration_config', 'default'), |
| 191 |
'#options' => $options, |
'#options' => $options, |
| 192 |
); |
); |
|
$form['activate'] = array('#type' => 'submit', '#value' => t('Activate menus')); |
|
| 193 |
} |
} |
| 194 |
|
$form['administration_module_active'] = array( |
| 195 |
|
'#type' => 'radios', |
| 196 |
|
'#title' => t('Administration menus'), |
| 197 |
|
'#default_value' => variable_get('administration_module_active', FALSE), |
| 198 |
|
'#options' => array(t('Disabled'), t('Enabled')), |
| 199 |
|
'#description' => t('Activate administration menus and dashboard.') |
| 200 |
|
); |
| 201 |
|
|
| 202 |
|
$form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); |
| 203 |
|
|
| 204 |
return drupal_get_form('administration_form', $form); |
return drupal_get_form('administration_form', $form); |
| 205 |
} |
} |
| 208 |
* Submit function for the administration form. |
* Submit function for the administration form. |
| 209 |
*/ |
*/ |
| 210 |
function administration_form_submit($formid, $form_values) { |
function administration_form_submit($formid, $form_values) { |
| 211 |
|
// Retrieve module state before saving changes |
| 212 |
|
$already_active = variable_get('administration_module_active', FALSE); |
| 213 |
|
|
| 214 |
$op = isset($_POST['op']) ? $_POST['op'] : ''; |
if ($form_values['administration_config']) { |
| 215 |
|
variable_set('administration_config', $form_values['administration_config']); |
|
if ($op == 'Deactivate menus') { |
|
|
_administration_unset_menus(); |
|
|
variable_del('administration_panels'); |
|
| 216 |
} |
} |
| 217 |
else { |
|
| 218 |
if ($op == 'Activate menus') { |
if ($form_values['administration_module_active']) { |
| 219 |
variable_set('administration_config', $form_values['config']); |
if (!$already_active) { |
| 220 |
variable_set('administration_module_active', 'true'); |
variable_set('administration_module_active', TRUE); |
|
variable_set('administration_show_menu_icons', $form_values['menu_icons']); |
|
| 221 |
// force a menu_rebuild to get the right menu sections. |
// force a menu_rebuild to get the right menu sections. |
| 222 |
// Yes, this means menu_rebuild is performed twice. |
// Yes, this means menu_rebuild is performed twice. |
| 223 |
menu_rebuild(); |
menu_rebuild(); |
| 224 |
_administration_set_menus(); |
_administration_activate_menus(); |
|
} |
|
|
else { |
|
|
if (function_exists('administration_form_submit_' . variable_get('administration_config', 'default') . '')) { |
|
|
call_user_func('administration_form_submit_' . variable_get('administration_config', 'default'), $formid, $form_values); |
|
|
} |
|
| 225 |
} |
} |
| 226 |
} |
} |
|
if (form_get_errors()) { |
|
|
return administration_form($edit); |
|
|
} |
|
| 227 |
else { |
else { |
| 228 |
//drupal_set_message(t('Changes made.')); |
if ($already_active){ |
| 229 |
drupal_goto('admin/settings/administration'); |
variable_set('administration_module_active', FALSE); |
| 230 |
|
_administration_deactivate_menus(); |
| 231 |
|
} |
| 232 |
} |
} |
| 233 |
|
|
| 234 |
|
if (function_exists('administration_form_submit_' . variable_get('administration_config', 'default'))) { |
| 235 |
|
call_user_func('administration_form_submit_' . variable_get('administration_config', 'default'), $formid, $form_values); |
| 236 |
|
} |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
/** |
| 240 |
|
* De-activates custom menus |
| 241 |
|
*/ |
| 242 |
|
function _administration_deactivate_menus() { |
| 243 |
|
_administration_unset_menus(); |
| 244 |
|
variable_del('administration_panels'); |
| 245 |
|
} |
| 246 |
|
|
| 247 |
|
/** |
| 248 |
|
* Activates custom menus |
| 249 |
|
*/ |
| 250 |
|
function _administration_activate_menus() { |
| 251 |
|
_administration_set_menus(); |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
/** |
/** |
| 313 |
function _administration_set_head() { |
function _administration_set_head() { |
| 314 |
$config = administration_menu_config(); |
$config = administration_menu_config(); |
| 315 |
$cssfile = $config['cssfile'] ? $config['cssfile'] : 'default.css'; |
$cssfile = $config['cssfile'] ? $config['cssfile'] : 'default.css'; |
| 316 |
static $sent = array(); |
$path = drupal_get_path('module','administration') . '/'; |
| 317 |
if (!isset($sent[drupal_get_path('module','administration') . "/$cssfile"])) { |
theme_add_style($path . $cssfile); |
|
theme_add_style(drupal_get_path('module','administration') .'/' . $cssfile); |
|
|
$sent[drupal_get_path('module','administration') . "/' . $cssfile . ;"] = TRUE; |
|
|
} |
|
|
return; |
|
| 318 |
} |
} |
| 319 |
|
|
| 320 |
/** |
/** |
| 343 |
} |
} |
| 344 |
} |
} |
| 345 |
menu_rebuild(); |
menu_rebuild(); |
| 346 |
|
if ($config['after_build']) { |
| 347 |
|
call_user_func($config['after_build'], $config); |
| 348 |
|
} |
| 349 |
} |
} |
| 350 |
|
|
| 351 |
/** |
/** |
| 356 |
$config = administration_menu_config(); |
$config = administration_menu_config(); |
| 357 |
$top_path = $config['top_path'] ? $config['top_path'] : 'sadmin'; |
$top_path = $config['top_path'] ? $config['top_path'] : 'sadmin'; |
| 358 |
_administration_unset_menu_item($menu['path index'][$top_path]); |
_administration_unset_menu_item($menu['path index'][$top_path]); |
|
db_query('DELETE FROM {menu} WHERE mid = %d', $menu['path index']['admin']); |
|
|
|
|
|
drupal_clear_path_cache(); |
|
| 359 |
menu_rebuild(); |
menu_rebuild(); |
| 360 |
} |
} |
| 361 |
|
|
| 381 |
} |
} |
| 382 |
else { |
else { |
| 383 |
$mid = db_next_id('{menu}_mid'); |
$mid = db_next_id('{menu}_mid'); |
| 384 |
$type = MENU_CUSTOM_ITEM | MENU_MODIFIED_BY_ADMIN; |
$type = MENU_NORMAL_ITEM | MENU_MODIFIED_BY_ADMIN; |
| 385 |
db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", $mid, $pid, $path, $title, $desc, $weight, $type); |
db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)", $mid, $pid, $path, $title, $desc, $weight, $type); |
| 386 |
} |
} |
| 387 |
return; |
return; |
| 394 |
db_query('DELETE FROM {menu} WHERE pid = %d', $pid); |
db_query('DELETE FROM {menu} WHERE pid = %d', $pid); |
| 395 |
|
|
| 396 |
$menu = menu_get_menu(); |
$menu = menu_get_menu(); |
| 397 |
foreach ($menu['items'][$pid]['children'] as $cid) { |
foreach ((array) $menu['items'][$pid]['children'] as $cid) { |
| 398 |
if (!empty($menu['items'][$cid]) && $menu['items'][$cid]['children']) { |
if (!empty($menu['items'][$cid]) && $menu['items'][$cid]['children']) { |
| 399 |
_administration_unset_menu_item($cid); |
_administration_unset_menu_item($cid); |
| 400 |
} |
} |
| 401 |
} |
} |
| 402 |
variable_set('administration_module_active', 'false'); |
variable_set('administration_module_active', FALSE); |
| 403 |
} |
} |
| 404 |
|
|
| 405 |
|
|