You are here

function scald_admin_actions_form_submit in Scald: Media Management made easy 6

Submit handler for Scald Actions admin form.

File

./scald.admin.inc, line 685

Code

function scald_admin_actions_form_submit($form, &$form_state) {
  $scald_config = variable_get('scald_config', 0);

  // Record what all the bitstrings were *before* the change to determine which
  //  roles changed and minimize the number of users that must be updated.
  $actions_results = db_query("SELECT rid, actions FROM {scald_role_actions}");
  $roles = array();
  while ($actions_raw = db_fetch_array($actions_results)) {
    $roles[$actions_raw['rid']] = $actions_raw['actions'];
  }
  $updated = array();

  // Look for the appropriate form values and update the roles
  foreach ($form_state['values'] as $role => $actions) {
    if (substr($role, -5) == '_role') {
      $role = substr($role, 0, -5);
      $bitstring = 0;
      foreach ($actions as $slug => $set) {
        if (!empty($set)) {
          $bitstring = $bitstring | $scald_config->actions[$slug]['mask'];
        }
      }
      if ($role == '@publisher') {
        variable_set('scald_actions_publisher', $bitstring);
      }
      else {
        if ($bitstring != $roles[$role]) {
          db_query("\n              INSERT INTO\n                {scald_role_actions}\n              SET\n                actions = %d,\n                rid = %d\n              ON DUPLICATE KEY\n                UPDATE\n                  actions = %d\n            ", $bitstring, $role, $bitstring);

          // Typecast this to help ensure a direct implode() won't result in SQL
          //  injection
          $updated[] = (int) $role;
        }
      }
    }
  }

  // Update any affected Users
  if (!empty($updated)) {
    batch_set(array(
      'title' => t('Updating User Actions bitstrings.'),
      'operations' => array(
        array(
          'scald_admin_actions_batch',
          array(
            $updated,
          ),
        ),
      ),
      'progress_message' => '',
      // No message because the batch function provides its own
      'file' => drupal_get_path('module', 'scald') . '/scald.admin.inc',
    ));
    batch_process('admin/content/scald/actions');
  }
}