query("INSERT INTO $wpdb->pollsq VALUES (0, '$pollquestion', '$now', 0)");
if(!$addq) {
$text .= "Error In Adding Poll '" . stripslashes($pollquestion) . "'";
}
// Add Poll Answer
$pollanswers = $_POST['pollanswer'];
$poll_last_id = intval($wpdb->insert_id);
foreach($pollanswers as $pollanswer) {
if(get_magic_quotes_gpc())
$pollanswer = addslashes(trim($pollanswer));
else
$pollanswer = trim($pollanswer);
$adda = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0,$poll_last_id,'$pollanswer',0)");
if(!$adda) {
$text .= "Error In Adding Poll's Answer '" . stripslashes($pollanswer) . "'";
}
}
if(empty($text)) {
$text = "Poll '" . stripslashes($pollquestion) . "' Added Successfully";
}
break;
case 'Edit Poll':
// Edit Poll Question
$id = intval($_POST['id']);
$total_votes = intval($_POST['total_votes']);
if(get_magic_quotes_gpc())
$pollquestion = addslashes(trim($_POST['pollquestion']));
else
$pollquestion = trim($_POST['pollquestion']);
$editpollq = $wpdb->query("UPDATE $wpdb->pollsq SET question = '$pollquestion', total_votes = $total_votes WHERE id=$id;");
if(!$editpollq) {
$text = "Error In Editing Poll '" . stripslashes($pollquestion) . "'";
}
// Get Poll Answers ID
$answers = array();
$getpollqid = $wpdb->get_results("SELECT aid FROM $wpdb->pollsa WHERE qid=$id ORDER BY answers");
if($getpollqid) {
foreach($getpollqid as $answer) {
$answers[] = intval($answer->aid);
}
foreach($answers as $answer) {
if(get_magic_quotes_gpc())
$answer_text = addslashes(trim($_POST[$answer]));
else
$answer_text = trim($_POST[$answer]);
$editpolla = $wpdb->query("UPDATE $wpdb->pollsa SET answers = '$answer_text' WHERE qid=$id AND aid=$answer");
if(!$editpolla) {
$text .= "
Error In Editing Poll's Answer '" . stripslashes($answer_text) . "'";
}
}
} else {
$text .= "
Invalid Poll '" . stripslashes($pollquestion) . "'";
}
if(empty($text)) {
$text = "Poll '" . stripslashes($pollquestion) . "' Edited Successfully";
} else {
$text .= '
Please do not be alarmed if you see the errors. The errors occur because most likely you did not modify the values.';
}
break;
case 'Delete Poll':
$id = intval($_POST['id']);
$pollquestion = trim($_POST['poll_question']);
$delete_q = $wpdb->query("DELETE FROM $wpdb->pollsq WHERE id=$id");
$delete_ans = $wpdb->query("DELETE FROM $wpdb->pollsa WHERE qid=$id");
if(!$delete_q) {
$text = "Error In Deleting Poll '" . stripslashes($pollquestion) . "' Question";
}
if(!$delete_ans) {
$text .= "
Error In Deleting Poll Answers For '" . stripslashes($pollquestion) . "'";
}
if(empty($text)) {
$text = "Poll '" . stripslashes($pollquestion) . "' Deleted Successfully";
}
break;
case 'Add Answer':
$id = intval($_POST['id']);
if(get_magic_quotes_gpc())
$answer = addslashes(trim($_POST['answer']));
else
$answer = trim($_POST['answer']);
$addq = $wpdb->query("INSERT INTO $wpdb->pollsa VALUES (0,$id,'$answer',0)");
if(!$addq) {
$text = "Error In Adding Poll Answer '" . stripslashes($answer) . "'";
} else {
$text = "Poll Answer '" . stripslashes($answer) . "' Added Successfully";
}
break;
}
}
### Determines Which Mode It Is
switch($mode) {
// Add A Poll
case 'add':
$title = 'Add Poll';
$standalone = 0;
require("./admin-header.php");
if ($user_level < 5) {
die('
Insufficient Level
'); } ?>| ID | Question | Total Votes | Date Added | Action | $poll->id | "; echo ''; if($i == 0) { echo 'Displayed: '; } echo $poll->question.' | '; echo "$poll->total_votes | "; echo ''.date("d.m.Y", $poll->timestamp).' | '; echo "id\" class=\"edit\">Edit | "; echo "id\" class=\"delete\">Delete | "; echo ''; $i++; $total_votes+= $poll->total_votes; } } else { echo '
|---|---|---|---|---|---|
| No Polls Found | |||||
| Total Polls: | =$i?> |
|---|---|
| Total Polls' Answers: | =number_format($total_ans)?> |
| Total Votes Casted: | =number_format($total_votes)?> |