You are here

function merci_permissions_form in MERCI (Manage Equipment Reservations, Checkout and Inventory) 8.2

Same name and namespace in other branches
  1. 6.2 modules/merci_permissions/merci_permissions.module \merci_permissions_form()
  2. 6 modules/merci_permissions/merci_permissions.module \merci_permissions_form()
  3. 7.2 modules/merci_permissions/merci_permissions.module \merci_permissions_form()

@todo Please document this function.

See also

http://drupal.org/node/1354

1 string reference to 'merci_permissions_form'
merci_permissions_menu in modules/merci_permissions/merci_permissions.module
@file Provides functions for resetting permissions on the permission page.

File

modules/merci_permissions/merci_permissions.module, line 95
Provides functions for resetting permissions on the permission page.

Code

function merci_permissions_form($form, &$form_state) {
  $role_names = user_roles();

  // Retrieve role names for columns.
  $role_names = user_roles();

  // Fetch permissions for all roles or the one selected role.
  $role_permissions = user_role_permissions($role_names);
  $merci_types = merci_permissions_load_merci_type_settings();
  if (empty($merci_types)) {
    drupal_set_message(t("You need to add some reservable content types to make this form usefull."));
    return;
  }
  $options = array();
  $admin = array();
  $form['permission'][] = array(
    '#markup' => t("General Permissions"),
  );

  //$form['permission']['admin all reservations'] = array('#markup' => t('Admin all reservations'));

  //$options['admin all reservations'] = '';
  $merci_perms = merci_permission();
  foreach ($merci_perms as $perm => $data) {
    $options[$perm] = '';
    $form['permission'][$perm] = array(
      '#markup' => t("@perm", array(
        '@perm' => $perm,
      )),
    );
    foreach ($role_names as $rid => $name) {

      // Builds arrays for checked boxes for each role
      if (isset($role_permissions[$rid][$perm])) {
        $status[$rid][] = $perm;
      }
    }
  }
  $form['permission'][] = array(
    '#markup' => t('Bucket and Resource Permissions'),
  );
  foreach ($merci_types as $type => $name) {
    $perm = "reserve {$type}";
    $options[$perm] = '';
    $form['permission'][$perm] = array(
      '#markup' => t("@name", array(
        '@name' => $name,
      )),
    );
    foreach ($role_names as $rid => $name) {

      // Builds arrays for checked boxes for each role
      if (isset($role_permissions[$rid]['delete own ' . $type . ' content']) && isset($role_permissions[$rid]['edit own ' . $type . ' content'])) {
        $status[$rid][] = $perm;
      }
      if (isset($role_permissions[$rid]['delete any ' . $type . ' content']) && isset($role_permissions[$rid]['edit any ' . $type . ' content'])) {
        if (!strstr($admin[$rid], 'false')) {
          $admin[$rid] = 'true';
        }
      }
      else {
        $admin[$rid] = 'false';
      }
    }
  }

  /*
    foreach ($role_names as $rid => $name) {
   if (strstr($admin[$rid], 'true')) {
     $status[$rid][] = 'admin all reservations';
   }
    }
  */

  // Have to build checkboxes here after checkbox arrays are built
  foreach ($role_names as $rid => $name) {
    $form['checkboxes'][$rid] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
    );
    $form['role_names']['#value'][] = $name;
    $form['role_names'][$rid] = array(
      '#markup' => $name,
      '#tree' => TRUE,
    );
  }
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save Permissions'),
  );
  $form['#submit'][] = 'merci_permissions_settings_form_submit';
  return $form;
}