function render()
 {
     $polls = new PlogPollPolls();
     $allpolls = $polls->getAllPolls($this->_blogInfo->getId());
     $this->setValue("polls", $allpolls);
     parent::render();
 }
 function perform()
 {
     $vote = split("-", $this->_request->getValue("vote"));
     $pollid = $vote[0];
     $voteid = $vote[1];
     if (!is_numeric($pollid) || !is_numeric($voteid)) {
         $this->_returnToPrevious();
         return false;
     }
     $pollmodel = new PlogPollPolls();
     if (!$pollmodel->registerVote($pollid, $voteid)) {
         $this->_returnToPrevious();
         return false;
     } else {
         $this->_returnToPrevious();
         return true;
     }
 }
 function perform()
 {
     $sub = $this->_request->getValue("subject");
     $rawresponses = $this->_request->getValue("responses");
     $responses = split("\n", $rawresponses);
     $resdata = array();
     for ($i = 0; $i < count($responses); $i++) {
         $resdata[$i] = 0;
     }
     $poll = new PlogPollPoll(-1, $sub, $responses, $resdata, -1, 0, $this->_blogInfo->getId());
     $pollsmodel = new PlogPollPolls();
     if (!$pollsmodel->addPoll(&$poll)) {
         $this->_view->setErrorMessage("Failed to add the poll to the database - localize");
         $this->setCommonData();
         return false;
     }
     $this->_view->setSuccessMessage("Added Poll - " . $sub . " - localize");
     $this->setCommonData();
     return true;
 }
 function generateActivePollHTML($blogId)
 {
     $pmod = new PlogPollPolls();
     $poll = $pmod->getActivePoll($blogId);
     if (!$poll) {
         return "<table id='pollbody'><tr><th>No Polls Currently Active</th></tr></table>";
     }
     $table = "";
     if ($pmod->hasVoted($poll->getId())) {
         $width = 100;
         $height = 15;
         $totalVotes = 0;
         foreach ($poll->getResponseData() as $num) {
             $totalVotes += $num;
         }
         $percentage = array();
         foreach ($poll->getResponseData() as $votes) {
             $percentage[] = (double) $votes / (double) $totalVotes;
         }
         $table .= "<table id='pollbody'>";
         $table .= "<tr><th>" . $poll->getSubject() . "</th></tr>";
         $responses = $poll->getResponses();
         for ($i = 0; $i < count($responses); $i++) {
             $table .= "<tr>\n            <td>" . $responses[$i] . "<div style='width:" . (int) ($percentage[$i] * $width) . "px;\n                            height:" . $height . "px;background:darkblue;'>\n                    &nbsp;" . (int) ($percentage[$i] * $width) . "%</div>\n            </td>\n          </tr>";
         }
         $table .= "</table>";
     } else {
         $config =& Config::getConfig();
         $table .= "<form method='post' action='" . $config->getValue('base_url') . "/?op=plogpollRegisterVote'>\n";
         $table .= "<table id='pollbody'>";
         $table .= "<tr><th>" . $poll->getSubject() . "</th></tr>";
         $responses = $poll->getResponses();
         for ($i = 0; $i < count($responses); $i++) {
             $table .= "<tr><td> <input type='radio' name='vote' " . "value='" . $poll->getId() . "-" . $i . "' />\n" . $responses[$i] . "</td></tr>\n";
         }
         $table .= "<tr><td>\n                 <input id='pollsubmit' type='submit' value='Vote' />\n                 </td></tr></table>\n                 <input type='hidden' name='disppage' \n                 value='" . $this->requestURI() . "' /></form>";
     }
     return $table;
 }
 function perform()
 {
     $plids = $this->_request->getValue("plid");
     $pollmodel = new PlogPollPolls();
     $emsg = $smsg = "";
     if ($plids != "") {
         foreach ($plids as $plid) {
             if (!$pollmodel->deletePoll($plid, $this->_blogInfo->getId())) {
                 $emsg .= "delete failed - localize\n";
             } else {
                 $smsg .= "delete succeded - localize\n";
             }
         }
     }
     $activepoll = $this->_request->getValue('activepoll');
     if (is_numeric($activepoll)) {
         $poll = $pollmodel->getPollById($activepoll);
         if (!$poll) {
             $emsg .= "invalid poll to set active... ignoring\n";
         } else {
             if ($poll->getBlogId() != $this->_blogInfo->getId()) {
                 $emsg .= "you do not own this poll...\n";
             } else {
                 $pollmodel->setNewActivePoll($poll->getId(), $this->_blogInfo->getId());
                 $smsg .= "changes updated\n";
             }
         }
     }
     if ($smsg != "") {
         $this->_view->setSuccessMessage($smsg);
     }
     if ($emsg != "") {
         $this->_view->setErrorMessage($emsg);
     }
     $this->setCommonData();
     return true;
 }