runtime = $poll[runtime]; $this->active = $poll[active]; $this->voters = $poll[voters]; $this->choice = $poll[choice]; $this->chvotes = $poll[chvotes]; $this->chid = $poll[chid]; } } function poll_cron() { $result = _node_get(array("type" => "poll")); while ($poll = db_fetch_array($result)) { if (($poll[active]) && ($poll[runtime])) { if (($poll[timestamp] + $poll[runtime]) < time()) { $poll[active] = 0; node_save($poll, array(active)); } } } } function poll_delete($node) { if ($node->nid) { db_query("DELETE FROM poll_choices WHERE nid='" . $node->nid . "'"); } } function poll_get_choices_array($poll) { if (!is_array($poll[choice])) { $result = db_query("SELECT * FROM poll_choices WHERE nid='" . $poll[nid] . "'"); if ($result) { while ($choices = db_fetch_array($result)) { $m = max($m, $choices[chvotes]); $t += $choices[chvotes]; $poll[choice][$choices[chorder]] = $choices[chtext]; $poll[chvotes][$choices[chorder]] = $choices[chvotes]; $poll[chid][$choices[chorder]] = $choices[chid]; } if ($poll[choice]) ksort($poll[choice]); } } $poll[maxvotes] = max(1, $m); $poll[totalvotes] = $t; return $poll; } function poll_get_choices_obj($poll) { if (!is_array($poll->choice)) { $result = db_query("SELECT * FROM poll_choices WHERE nid='" . $poll->nid . "'"); if ($result) { while ($choices = db_fetch_array($result)) { $m = max($m,$choices[chvotes]); $t += $choices[chvotes]; $poll->choice[$choices[chorder]] = $choices[chtext]; $poll->chvotes[$choices[chorder]] = $choices[chvotes]; $poll->chid[$choices[chorder]] = $choices[chid]; } if ($poll->choice) ksort($poll->choice); } } $poll->maxvotes = max(1, $m); $poll->totalvotes = $t; return $poll; } function poll_status() { return array(dumped, queued, posted); } function poll_search($keys) { global $PHP_SELF, $status; $result = db_query("SELECT n.*, p.* FROM poll p LEFT JOIN node n ON n.nid = p.nid AND n.lid = p.lid WHERE n.status = '$status[posted]' AND (n.title LIKE '%$keys%') LIMIT 20"); while ($poll = db_fetch_object($result)) { $find[$i++] = array("title" => check_output($poll->title), "link" => ($PHP_SELF == "/admin.php" ? "admin.php?mod=poll&op=edit&id=$poll->nid" : "node.php?id=$poll->nid"), "user" => $poll->name, "date" => $poll->timestamp); } return $find; } function poll_help() { ?>
Poll.module allows you to run simple multiple choice polls on your site. After creating the necessary categories, you can add a poll through this administration interface.
The poll.module also has a block to show the latest poll. If you combine it with a poll category that doesn't promote to the mainpage, you'll get a side-block only poll system.
If you want to set a limit on the duration of a poll, use the Poll Duration setting. After the specified interval, the poll will automatically be closed, preventing anymore voting.
foreground ? $theme->foreground : "#000000"; $clrempty = $theme->background ? $theme->background : "#ffffff"; $p = round($val * 100); return "" : "") . ($p < 100 ? " | ":"") . " |
" . poll_graph($node->chvotes[$key] / $node->maxvotes, $theme->pollfill, $theme->pollempty) . " | " . round(($node->chvotes[$key] / $node->totalvotes) * 100) . "% |
" . check_output($value) . " | " . poll_graph($node->chvotes[$key] / $node->maxvotes, $theme->pollfill, $theme->pollempty) . " | " . round(($node->chvotes[$key] / $node->totalvotes) * 100) . "% |
";
foreach ($node->choice as $key => $value) {
if ($value) {
$output .= "chid[$key] . "\"> " . check_output($value) . " "; } } if ($block) { $output .= " |
\n"; $form .= form_submit(t("Preview")); } else if ((!$edit[choice][0]) && (!$edit[choice][1])) { $form .= "". t("Warning: you must supply at least 2 choices.") ."
\n";
$form .= form_submit(t("Preview"));
}
else {
$form .= form_submit(t("Preview"));
$form .= form_submit(t("Submit"));
}
return form($REQUEST_URI, $form);
}
function poll_save($edit) {
global $status, $user;
if (!$edit[nid]) {
$nid = node_save($edit, array(active => 1, attributes => node_attributes_save("poll", $edit), author => $user->id, comment => variable_get("poll_comment", 0), moderate => variable_get("poll_moderate", ""), promote => variable_get("poll_promote", 0), runtime, score => 0, status => variable_get("poll_status", $status[queued]), timestamp => time(), title, type => "poll", votes => 0, voters => ""));
}
else if (user_access("administer nodes")) {
$nid = node_save($edit, array(active, attributes => node_attributes_save("poll", $edit), runtime, title, type => "poll"));
db_query("DELETE FROM poll_choices WHERE nid='" . $nid . "'");
}
if ($nid) {
foreach ($edit[choice] as $key => $value) {
if ($value) {
$v[] = "('" . $nid . "', '" . check_input($value) . "', '". check_input($edit[chvotes][$key]) ."', '". check_input($key) ."')";
}
}
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES " . implode(",", $v));
}
}
function poll_block() {
global $status;
$result = _node_get(array("type" => "poll"));
while ($poll = db_fetch_object($result)) {
if (($poll->active) && ($poll->status == $status[posted])) {
$content = poll_view($poll, 0, 1);
$output = "" . $content[title] . "
" . $content[content] . "