You are here

function poll_load in Drupal 5

Same name and namespace in other branches
  1. 4 modules/poll.module \poll_load()
  2. 6 modules/poll/poll.module \poll_load()
  3. 7 modules/poll/poll.module \poll_load()

Implementation of hook_load().

File

modules/poll/poll.module, line 283
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_load($node) {
  global $user;
  $poll = db_fetch_object(db_query("SELECT runtime, active FROM {poll} WHERE nid = %d", $node->nid));

  // Load the appropriate choices into the $poll object.
  $result = db_query("SELECT chtext, chvotes, chorder FROM {poll_choices} WHERE nid = %d ORDER BY chorder", $node->nid);
  while ($choice = db_fetch_array($result)) {
    $poll->choice[$choice['chorder']] = $choice;
  }

  // Determine whether or not this user is allowed to vote.
  $poll->allowvotes = FALSE;
  if (user_access('vote on polls') && $poll->active) {
    if ($user->uid) {
      $result = db_fetch_object(db_query('SELECT chorder FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid));
    }
    else {
      $result = db_fetch_object(db_query("SELECT chorder FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, $_SERVER['REMOTE_ADDR']));
    }
    if (isset($result->chorder)) {
      $poll->vote = $result->chorder;
    }
    else {
      $poll->vote = -1;
      $poll->allowvotes = TRUE;
    }
  }
  return $poll;
}