You are here

function scald_admin_actions_form in Scald: Media Management made easy 6

Admin form for Scald Actions.

1 string reference to 'scald_admin_actions_form'
scald_admin_actions in ./scald.admin.inc
The Scald Admin page for Scald Actions

File

./scald.admin.inc, line 590

Code

function scald_admin_actions_form() {

  // Pull in the existing settings
  $scald_config = variable_get('scald_config', 0);
  $scald_actions_publisher = variable_get('scald_actions_publisher', 0);

  // Construct the options piece of the form
  $action_options = array();
  foreach ($scald_config->actions as $slug => $details) {
    $action_options[$slug] = $details['title'];
  }

  // The Publisher must be hardcoded in
  $form = array();
  $form['@publisher_set'] = array(
    '#type' => 'fieldset',
    '#title' => t('Atom Publisher'),
    '#description' => t('The Atom Publisher is not a role but is the User who initially registered a given Scald Atom.  Admin Mode is recommended for the Publisher\'s Permitted Actions.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $current_actions = array();
  foreach ($scald_config->actions as $slug => $details) {
    if ($scald_actions_publisher & $details['mask']) {
      $current_actions[] = $slug;
    }
  }
  $form['@publisher_set']['@publisher_role'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Permitted Actions'),
    '#default_value' => $current_actions,
    '#options' => $action_options,
  );

  // Find and add form elements for each Role which has the "use scald" perm
  $roles_results = db_query("\n    SELECT\n      p.rid,\n      p.perm,\n      r.name,\n      a.actions\n    FROM\n      {permission} p\n    LEFT JOIN\n      {role} r\n      ON\n        r.rid = p.rid\n    LEFT JOIN\n      {scald_role_actions} a\n      ON\n        a.rid = p.rid\n  ");
  while ($role_raw = db_fetch_array($roles_results)) {
    $perms = explode(', ', $role_raw['perm']);
    if (in_array('use scald', $perms)) {
      $form[$role_raw['rid'] . '_set'] = array(
        '#type' => 'fieldset',
        '#title' => $role_raw['name'],
        '#collapsible' => TRUE,
        '#collapsed' => TRUE,
      );
      $current_actions = array();
      foreach ($scald_config->actions as $slug => $details) {
        if ($role_raw['actions'] & $details['mask']) {
          $current_actions[] = $slug;
        }
      }
      $form[$role_raw['rid'] . '_set'][$role_raw['rid'] . '_role'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Permitted Actions'),
        '#default_value' => $current_actions,
        '#options' => $action_options,
      );
    }
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}