You are here

function poll_insert in Drupal 6

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

Implementation of hook_insert().

File

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

Code

function poll_insert($node) {
  if (!user_access('administer nodes')) {

    // Make sure all votes are 0 initially
    foreach ($node->choice as $i => $choice) {
      $node->choice[$i]['chvotes'] = 0;
    }
    $node->active = 1;
  }
  db_query("INSERT INTO {poll} (nid, runtime, active) VALUES (%d, %d, %d)", $node->nid, $node->runtime, $node->active);
  $i = 0;
  foreach ($node->choice as $choice) {
    if ($choice['chtext'] != '') {
      db_query("INSERT INTO {poll_choices} (nid, chtext, chvotes, chorder) VALUES (%d, '%s', %d, %d)", $node->nid, $choice['chtext'], $choice['chvotes'], $i++);
    }
  }
}