db_Delete("polls", " poll_id='".intval($existing)."' ")) { if(function_exists("admin_purge_related")) { admin_purge_related("poll", $existing); } return "Poll deleted."; } } function submit_poll($mode=1) { /* $mode = 1 :: poll is main poll $mode = 2 :: poll is forum poll */ global $tp, $sql; extract($_POST); $poll_title = $tp->toDB($poll_title); $active_start = (!$_POST['startmonth'] || !$_POST['startday'] || !$_POST['startyear'] ? 0 : mktime (0, 0, 0, $_POST['startmonth'], $_POST['startday'], $_POST['startyear'])); $active_end = (!$_POST['endmonth'] || !$_POST['endday'] || !$_POST['endyear'] ? 0 : mktime (0, 0, 0, $_POST['endmonth'], $_POST['endday'], $_POST['endyear'])); $poll_options = ""; foreach($poll_option as $key => $value) { $poll_options .= $tp->toDB($poll_option[$key]).chr(1); } if(POLLACTION == "edit") { $sql -> db_Update("polls", "poll_title='$poll_title', poll_options='$poll_options', poll_type=$mode, poll_comment='".$tp -> toDB($poll_comment)."', poll_allow_multiple=".intval($multipleChoice).", poll_result_type=".intval($showResults).", poll_vote_userclass=".intval($pollUserclass).", poll_storage_method=".intval($storageMethod)." WHERE poll_id=".intval(POLLID)); /* update poll results - bugtracker #1124 .... */ $sql -> db_Select("polls", "poll_votes", "poll_id='".intval(POLLID)."' "); $foo = $sql -> db_Fetch(); $voteA = explode(chr(1), $foo['poll_votes']); $opt = count($poll_option) - count($voteA); if($opt) { for($a=0; $a<=$opt; $a++) { $foo['poll_votes'] .= "0".chr(1); } $sql -> db_Update("polls", "poll_votes='".$foo['poll_votes']."' WHERE poll_id='".intval(POLLID)."' "); } $message = POLLAN_45; } else { $votes = ""; for($a=1; $a<=count($_POST['poll_option']); $a++) { $votes .= "0".chr(1); } if($mode == 1) { /* deactivate other polls */ if($sql -> db_Select("polls", "*", "poll_type=1 AND poll_vote_userclass!=255")) { $deacArray = $sql -> db_getList(); foreach($deacArray as $deacpoll) { $sql -> db_Update("polls", "poll_end_datestamp='".time()."', poll_vote_userclass='255' WHERE poll_id=".$deacpoll['poll_id']); } } $sql -> db_Insert("polls", "'0', ".time().", ".intval($active_start).", ".intval($active_end).", ".ADMINID.", '$poll_title', '$poll_options', '$votes', '', '1', '".$tp -> toDB($poll_comment)."', '".intval($multipleChoice)."', '".intval($showResults)."', '".intval($pollUserclass)."', '".intval($storageMethod)."'"); } else { $sql -> db_Insert("polls", "'0', ".intval($_POST['iid']).", '0', '0', ".USERID.", '$poll_title', '$poll_options', '$votes', '', '2', '0', '".intval($multipleChoice)."', '0', '0', '".intval($storageMethod)."'"); } } return $message; } function get_poll($query) { global $sql, $e107; if ($sql->db_Select_gen($query)) { $pollArray = $sql -> db_Fetch(); if (!check_class($pollArray['poll_vote_userclass'])) { $POLLMODE = "disallowed"; } else { switch($pollArray['poll_storage_method']) { case POLL_MODE_COOKIE: $userid = ""; $cookiename = "poll_".$pollArray['poll_id']; if(isset($_COOKIE[$cookiename])) { $POLLMODE = "voted"; } else { $POLLMODE = "notvoted"; } break; case POLL_MODE_IP: $userid = $e107->getip(); $voted_ids = explode("^", substr($pollArray['poll_ip'], 0, -1)); if (in_array($userid, $voted_ids)) { $POLLMODE = "voted"; } else { $POLLMODE = "notvoted"; } break; case POLL_MODE_USERID: if(!USER) { $POLLMODE = "disallowed"; } else { $userid = USERID; $voted_ids = explode("^", substr($pollArray['poll_ip'], 0, -1)); if (in_array($userid, $voted_ids)) { $POLLMODE = "voted"; } else { $POLLMODE = "notvoted"; } } break; } } } if(isset($_POST['pollvote']) && $POLLMODE == "notvoted" && ($POLLMODE != "disallowed")) { if ($_POST['votea']) { // $sql -> db_Select("polls", "*", "poll_vote_userclass!=255 AND poll_type=1 ORDER BY poll_datestamp DESC LIMIT 0,1"); $row = $pollArray; extract($row); $votes = explode(chr(1), $poll_votes); if(is_array($_POST['votea'])) { /* multiple choice vote */ foreach($_POST['votea'] as $vote) { $vote = intval($vote); $votes[($vote-1)] ++; } } else { $votes[($_POST['votea']-1)] ++; } $optionArray = explode(chr(1), $pollArray['poll_options']); $optionArray = array_slice($optionArray, 0, -1); foreach($optionArray as $k=>$v) { if(!$votes[$k]) { $votes[$k] = 0; } } $votep = implode(chr(1), $votes); $pollArray['poll_votes'] = $votep; $sql->db_Update("polls", "poll_votes = '$votep', poll_ip='".$poll_ip.$userid."^' WHERE poll_id=".$poll_id); echo " "; $POLLMODE = "voted"; } } $this->pollRow = $pollArray; $this->pollmode = $POLLMODE; } function render_poll($pollArray = "", $type = "menu", $POLLMODE = "", $returnMethod=FALSE) { global $POLLSTYLE, $sql, $tp, $ns; if($POLLMODE == "query") { $this->get_poll($pollArray); $pollArray = $this->pollRow; $POLLMODE = $this->pollmode; } $barl = (file_exists(THEME."images/barl.png") ? THEME_ABS."images/barl.png" : e_PLUGIN."poll/images/barl.png"); $barr = (file_exists(THEME."images/barr.png") ? THEME_ABS."images/barr.png" : e_PLUGIN."poll/images/barr.png"); $bar = (file_exists(THEME."images/bar.png") ? THEME_ABS."images/bar.png" : e_PLUGIN."poll/images/bar.png"); if($type == "preview") { /* load lan file */ @include_once(e_PLUGIN."poll/languages/".e_LANGUAGE.".php"); @include_once(e_PLUGIN."poll/languages/English.php"); $optionArray = $pollArray['poll_option']; $voteArray = array(); $voteArray = array_pad($voteArray, count($optionArray), 0); $pollArray['poll_allow_multiple'] = $pollArray['multipleChoice']; } else if($type == "forum") { @include_once(e_PLUGIN."poll/languages/".e_LANGUAGE.".php"); @include_once(e_PLUGIN."poll/languages/English.php"); if(isset($_POST['fpreview'])) { $pollArray['poll_allow_multiple'] = $pollArray['multipleChoice']; $optionArray = $pollArray['poll_option']; } else { $optionArray = explode(chr(1), $pollArray['poll_options']); $optionArray = array_slice($optionArray, 0, -1); } $voteArray = explode(chr(1), $pollArray['poll_votes']); // $voteArray = array_slice($voteArray, 0, -1); } else { $optionArray = explode(chr(1), $pollArray['poll_options']); $optionArray = array_slice($optionArray, 0, -1); $voteArray = explode(chr(1), $pollArray['poll_votes']); // $voteArray = array_slice($voteArray, 0, -1); } $voteTotal = array_sum($voteArray); $percentage = array(); if(count($voteArray)) { foreach($voteArray as $votes) { if ($voteTotal > 0) { $percentage[] = round(($votes/$voteTotal) * 100, 2); } else { $percentage[] = 0; } } } /* get template */ if (file_exists(THEME."poll_template.php")) { require(THEME."poll_template.php"); } else if(!isset($POLL_NOTVOTED_START)) { require(e_PLUGIN."poll/templates/poll_template.php"); } $preview = FALSE; if ($type == "preview") { $POLLMODE = "notvoted"; } else if($type == "forum") { $preview = TRUE; } $comment_total = $sql->db_Select("comments", "*", "comment_item_id='".intval($pollArray['poll_id'])."' AND comment_type=4"); $QUESTION = $tp -> toHTML($pollArray['poll_title'], TRUE,"emotes_off, defs"); $VOTE_TOTAL = POLLAN_31.": ".$voteTotal; $COMMENTS = ($pollArray['poll_comment'] ? " ".POLLAN_27.": ".$comment_total."" : ""); $OLDPOLLS = ($type == "menu" ? "".POLLAN_28."" : ""); $AUTHOR = POLLAN_35." ".($type == "preview" || $type == "forum" ? USERNAME : "".$pollArray['user_name'].""); switch ($POLLMODE) { case "notvoted": $text = "
"; break; case "voted": if($pollArray['poll_result_type'] && !strstr(e_SELF, "comment.php")) { $text = "\n$text\n |