You are here

function poll_load in Drupal 4

Same name and namespace in other branches
  1. 5 modules/poll/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.module, line 226
Enables your site to capture votes on different topics in the form of multiple choice questions.

Code

function poll_load($node) {
  global $user;

  // Load the appropriate choices into the $node object
  $poll = db_fetch_object(db_query("SELECT runtime, active FROM {poll} WHERE nid = %d", $node->nid));
  $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 && db_num_rows(db_query('SELECT uid FROM {poll_votes} WHERE nid = %d AND uid = %d', $node->nid, $user->uid)) == 0) {
      $poll->allowvotes = TRUE;
    }
    else {
      if ($user->uid == 0 && db_num_rows(db_query("SELECT hostname FROM {poll_votes} WHERE nid = %d AND hostname = '%s'", $node->nid, $_SERVER['REMOTE_ADDR'])) == 0) {
        $poll->allowvotes = TRUE;
      }
    }
  }
  return $poll;
}