Пример #1
0
<?php

global $wp, $logger;
// Check if poll is set (also can be used to check for direct access)
if (isset($_POST['poll'])) {
    $logger->logVar($_POST, '$_POST');
    // Set our poll variables
    $pollID = (int) $_POST['poll'];
    $simplyPoll = new SimplyPoll();
    $answer = null;
    // A vote has been made
    if (isset($_POST['answer'])) {
        $logger->log('The int `' . $_POST['answer'] . '` has been accepted');
        $answer = $_POST['answer'];
        // Check if we have the 'sptaken' cookie before trying to get data
        if (isset($_COOKIE['sptaken'])) {
            $taken = $_COOKIE['sptaken'];
        } else {
            $taken = null;
        }
        $taken = unserialize($taken);
        // Unsearlize $taken to get an array
        $taken[] = $pollID;
        // Add this poll's ID to the $taken array
        $taken = serialize($taken);
        // Serialize $taken array ready to be stored again
        setcookie('sptaken', $taken, time() + 315569260, '/');
    } else {
        $logger->log('The no answer accepted');
    }
    // No back url has been set so treat it as a Javascript call
Пример #2
0
function spResults()
{
    global $logger;
    $logger->log('spResults()');
    $logger->logVar($_POST, '$_POST');
    if (isset($_POST['pollid'])) {
        $pollid = $_POST['pollid'];
    }
    $simplypoll = new SimplyPoll(false);
    $results = $simplypoll->grabPoll($pollid);
    $logger->logVar($results, '$results');
    $answers = $results['answers'];
    $totalvotes = $results['totalvotes'];
    require SP_RESULTS;
    exit;
}
Пример #3
0
 /**
  * Add New Poll to DB
  * 
  * @param	array	$poll
  * @param	array	$editPoll
  * @return	int
  *************************************************************************/
 private function pushPollToDB($poll, $pollEdit)
 {
     $pollData = parent::pollDB()->getPollDB();
     $poll['active'] = true;
     $poll['totalvotes'] = 0;
     $poll['time'] = time();
     $pollData['polls'][] = $poll;
     if ($pollEdit == 'new') {
         // Add new poll
         return parent::pollDB()->newPollDB($poll);
     } elseif ($pollEdit > 0) {
         // Update poll
         $poll['id'] = $pollEdit;
         return parent::pollDB()->updatePollDB($poll);
     }
 }