All pastes #430461 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-04-09 00:12 UTC
rendered paste body
function nmoderation_moderation($content_type, $content_id, $vote, $title= NULL) {
  $output = drupal_get_form('nmoderation_moderation_form', $form_id, $content_type, $content_id, $vote, $title= NULL);
  return $output;
}

function nmoderation_moderation_form($content_type, $content_id, $vote, $title= NULL) {
  global $user;
  static $votes;

  if (user_access('moderate nodes')) {
    if (!isset($votes) && $user->roles) {
      $result = db_query('SELECT mid, vote FROM {nmoderation_votes} ORDER BY weight ASC');
      $votes = array();
      while ($dbvote = db_fetch_object($result)) {
        $votes[$dbvote->mid] = $dbvote->vote;
      }
    }
    
    if ($votes) {
      $form['value'] = array(
        '#type' => 'select',
        '#title' => t('Moderate Post'),
        '#default_value' => $vote->value,
        '#options' => $votes,
        '#description' => t('Your vote contributes to whether or not this post appears on the home page.'),
      );
      
      $form['content_type'] = array(
        '#type' => 'hidden',
        '#value' => $content_type,
      );

      $form['content_id'] = array(
        '#type' => 'hidden',
        '#value' => $content_id,
      );

      if ($vote) {
        $form['vote_id'] = array(
          '#type' => 'hidden',
          '#value' => $vote->vote_id,
        );
      }

      if ($title) {
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => $title,
        );
      }
      return $form;
    }
  }
}

function nmoderation_moderation_form_submit($form_id, $form_values) {
  global $user;
  $content_type = $form_values['content_type'];
  $content_id = $form_values['content_id'];
  $value = $form_values['value'];
  $vote_id = $form_values['vote_id'];

  if ($vote_id) {
    // There's already a vote, we're editing.
    $vote = db_fetch_object(db_query("SELECT * FROM {votingapi_vote} WHERE vote_id=%d", $vote_id));
    if ($vote->uid != $user->uid) {
      $account = user_load(array('uid' => $vote->uid));
    }
    else {
      $account = $user;
    }
  }