You are here

function system_module_settings in Util 6.3

Same name and namespace in other branches
  1. 6 system_module.module \system_module_settings()
  2. 6.2 system_module.module \system_module_settings()
1 string reference to 'system_module_settings'
system_module_menu in ./system_module.module

File

./system_module.module, line 30
Customize System Modules fieldsets

Code

function system_module_settings() {
  global $user;
  drupal_add_css(drupal_get_path('module', 'system_module') . '/system_module.css');

  // Get all available packages.
  $packages = $includes = array();
  $result = db_query("SELECT filename, name, info FROM {system} WHERE type = 'module'");
  while ($module = db_fetch_object($result)) {
    $module->info = unserialize($module->info);
    if (!isset($module->info['package']) || !$module->info['package']) {
      $module->info['package'] = t('Other');
    }
    $pkg = $module->info['package'];
    $packages[$pkg] = $pkg;
    $includes[$pkg][] = $module->info['name'];
  }
  ksort($packages);
  ksort($includes);

  // 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['general_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('General options'),
    '#description' => t('Options that affect the Modules List page.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['general_options']['system_module_show_internal_names'] = array(
    '#type' => 'radios',
    '#title' => t('Show internal module names'),
    '#description' => t('Displays the internal module names (i.e. the name of the directory the module is stored in) on the Modules List page.'),
    '#options' => array(
      t('No'),
      t('Yes'),
    ),
    '#default_value' => variable_get('system_module_show_internal_names', 0),
  );
  $form['system_module_collapse_all'] = array(
    '#type' => 'radios',
    '#title' => t('Collapse all module packages 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['list']['system_module_cfg'] = array(
    '#type' => 'checkboxes',
    '#default_value' => isset($result) && is_array($result) ? array_keys($result) : array(),
    '#options' => $packages,
  );
  $form['dir'] = array(
    '#type' => 'fieldset',
    '#title' => t('Directory of package contents'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $rows = $list = array();
  $header = array(
    t('Package'),
    t('Includes'),
  );
  foreach ($includes as $pkg => $modules) {
    $pkg_id = _system_modules_make_pkgid($pkg);
    $link = l($pkg, 'admin/build/modules', array(
      'fragment' => "package-{$pkg_id}",
      'query' => 'expand="' . $pkg . '"',
    ));
    $rows[] = array(
      $link,
      implode(', ', $modules),
    );
    foreach ($modules as $name) {
      $list[] = "{$name} - {$link}";
    }
  }
  asort($list);
  $piece = ceil(count($list) / 3);
  $cols = array(
    array(
      theme('item_list', array_slice($list, 0, $piece)),
      theme('item_list', array_slice($list, $piece, $piece)),
      theme('item_list', array_slice($list, 2 * $piece)),
    ),
  );
  $form['dir']['list'] = array(
    '#type' => 'markup',
    '#value' => theme('table', $header, $rows, array(
      'id' => 'modules-by-package',
    )) . theme('table', array(), $cols, array(
      'id' => 'modules-by-name',
    )),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save configuration',
  );
  return $form;
}