You are here

function cmf_admin_both_form_submit in Content Management Filter 6

Same name and namespace in other branches
  1. 5 both.inc \cmf_admin_both_form_submit()
  2. 6.2 both.inc \cmf_admin_both_form_submit()
  3. 7 both.inc \cmf_admin_both_form_submit()

Handle post-validation form submission. Execute the chosen 'Update option' on the selected objects, such as publishing, unpublishing or deleting.

Parameters

the ID of the passed form:

array with the form properties values:

See also

cmf_admin_both_form()

cmf_admin_both_form_validate()

File

./both.inc, line 180
@brief Content management filter "both" operations file

Code

function cmf_admin_both_form_submit($form, &$form_state) {

  // Query building.
  switch ($form_state['values']['operation']) {
    case 'publish':
      $node_query = 'UPDATE {node} SET status = 1 WHERE nid = %d';
      $comment_query = 'UPDATE {comments} SET status = ' . COMMENT_PUBLISHED . ' WHERE cid = %d';
      break;
    case 'unpublish':
      $node_query = 'UPDATE {node} SET status = 0 WHERE nid = %d';
      $comment_query = 'UPDATE {comments} SET status = ' . COMMENT_NOT_PUBLISHED . ' WHERE cid = %d';
      break;
    case 'delete':
      $node_query = 'DELETE FROM {node} WHERE nid = %d';
      $comment_query = 'DELETE FROM {comments} WHERE cid = %d';
      break;
  }

  // Perform queries.
  foreach ($form_state['values']['objects'] as $flag) {
    if ($flag) {
      $object = explode('-', $flag);
      $kind = $object[0];
      $value = $object[1];
      if ($kind == 'n') {
        db_query($node_query, $value);
      }
      elseif ($kind == 'c') {

        // Perform the update action, then refresh node statistics.
        db_query($comment_query, $value);
        $comment = _comment_load($value);
        _comment_update_node_statistics($comment->nid);

        // Allow modules to respond to the updating of a comment.
        comment_invoke_comment($comment, $form_state['values']['operation']);
      }
    }
  }
  cache_clear_all();
  drupal_set_message(t('The update has been performed.'));
  if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
    $form_state['redirect'] = 'user/' . arg(1) . '/cmf';
  }
  else {
    $form_state['redirect'] = 'admin/content/filter';
  }
}