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]) { if (($poll[timestamp] + $poll[runtime]) < time()) { $poll[active] = 0; node_save($poll, array(active)); } } } } function poll_get_choices_array($poll) { if (!$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 (!$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 $status, $user; $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" => (user_access($user, "poll") ? "admin.php?mod=poll&op=edit&id=$poll->nid" : "node.php?id=$poll->nid"), "user" => $poll->userid, "date" => $poll->timestamp); } return $find; } function poll_help() { ?> No help available.
" . check_output($value) . " | " . poll_graph($node->chvotes[$key] / $node->maxvotes) . " | " . round(($node->chvotes[$key] / $node->totalvotes) * 100) . "% |
" . poll_graph($node->chvotes[$key] / $node->maxvotes) . " | " . round(($node->chvotes[$key] / $node->totalvotes) * 100) . "% |
";
foreach ($node->choice as $key => $value) {
if ($value) {
$output .= "chid[$key] . "\"> " . check_output($value) . " \r\n"; } } $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, author => $user->id, cid, comment => category_comment($edit[cid]), moderate => topic_moderate($edit[tid]), promote => category_promote($edit[cid]), runtime, score => 0, status => (category_submission($edit[cid]) ? $status[queued] : $status[posted]), tid, timestamp => time(), title, type => "poll", votes => 0, voters => ""));
}
else if (user_access($user)) {
$nid = node_save($edit, array(active, cid, tid, 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[votes][$key]) ."', '". check_input($key) ."')";
}
}
db_query("INSERT INTO poll_choices (nid, chtext, chvotes, chorder) VALUES " . implode(",", $v));
}
}
function poll_block() {
$poll = node_get_object(array("type" => "poll", "active" => 1));
if ($poll) {
$poll = poll_view($poll, 0, 1);
$output = "" . $poll[title] . "
" . $poll[content];
}
$blocks[0][subject] = "Latest poll";
$blocks[0][content] = $output ? $output : "No active polls.";
$blocks[0][info] = "Display the latest active poll.";
$blocks[0][link] = "index.php";
return $blocks;
}
function poll_query($type = "") {
global $status;
$queries = array(array("recent polls", "WHERE n.type = 'poll' ORDER BY n.timestamp DESC"), array("active polls", "WHERE n.type = 'poll' AND n.status = '$status[posted]' ORDER BY n.timestamp DESC"), array("queued polls", "WHERE n.type = 'poll' AND n.status = '$status[queued]' ORDER BY n.timestamp DESC"), array("dumped polls", "WHERE n.type = 'poll' AND n.status = '$status[dumped]' ORDER BY n.timestamp DESC"), array("polls without category (integrity)", "WHERE n.type = 'poll' AND n.cid = '0' ORDER BY n.timestamp DESC"), array("polls without topic (integrity)", "WHERE n.type = 'poll' AND n.tid = '0' ORDER BY n.timestamp DESC"));
return ($queries[$type] ? $queries[$type] : $queries);
}
function poll_overview($query = array()) {
return node_overview($query);
}
function poll_admin() {
global $id, $edit, $mod, $keys, $op, $theme, $type, $user;
print "add new poll | poll listing | search poll | overview | help