You are here

function tac_lite_admin_scheme_form in Taxonomy Access Control Lite 5

Same name and namespace in other branches
  1. 6 tac_lite.module \tac_lite_admin_scheme_form()
  2. 7 tac_lite.module \tac_lite_admin_scheme_form()

Returns the form for role-based privileges.

1 string reference to 'tac_lite_admin_scheme_form'
tac_lite_admin_settings_scheme in ./tac_lite.module

File

./tac_lite.module, line 166
Control access to site content based on taxonomy, roles and users.

Code

function tac_lite_admin_scheme_form($i) {
  $vids = variable_get('tac_lite_categories', null);
  $roles = user_roles();
  if (count($vids)) {
    $config = _tac_lite_config($i);
    $form['tac_lite_config_scheme_' . $i] = array(
      '#tree' => TRUE,
    );
    $form['tac_lite_config_scheme_' . $i]['name'] = array(
      '#type' => 'textfield',
      '#title' => t('Scheme name'),
      '#description' => t('A human-readable name for administrators to see.  For example, \'read\' or \'read and write\'.'),
      '#default_value' => $config['name'],
      '#required' => TRUE,
    );

    // Currently, only view, update and delete are supported by node_access
    $options = array(
      'grant_view' => 'view',
      'grant_update' => 'update',
      'grant_delete' => 'delete',
    );
    $form['tac_lite_config_scheme_' . $i]['perms'] = array(
      '#type' => 'select',
      '#title' => t('Permissions'),
      '#multiple' => TRUE,
      '#options' => $options,
      '#default_value' => $config['perms'],
      '#description' => t('Select which permissions are granted by this scheme.'),
    );
    $form['helptext'] = array(
      '#type' => 'markup',
      '#value' => t('You may grant these permissions by role, below.  To grant permission to an individual user, visit the tac_lite tab on the user edit page.'),
    );
    $all_defaults = variable_get('tac_lite_grants_scheme_' . $i, array());
    $form['tac_lite_grants_scheme_' . $i] = array(
      '#tree' => true,
    );
    foreach ($roles as $rid => $role_name) {
      $form['tac_lite_grants_scheme_' . $i][$rid] = array(
        '#type' => 'fieldset',
        '#tree' => true,
        '#title' => t('Access for %role', array(
          '%role' => $role_name,
        )),
        '#description' => t(''),
      );
      $defaults = $all_defaults[$rid];
      foreach ($vids as $vid) {
        $v = taxonomy_get_vocabulary($vid);
        $form['tac_lite_grants_scheme_' . $i][$rid][$vid] = _taxonomy_term_select($v->name, null, $defaults[$vid], $vid, '', true, '<' . t('none') . '>');
      }
    }
    return system_settings_form($form);
  }
  else {
    return array(
      'body' => array(
        '#type' => 'markup',
        '#value' => t('First select vocabularies on the <a href=!url>settings page</a>.', array(
          '!url' => url('admin/user/tac_lite'),
        )),
      ),
    );
  }
}