public function addVote($uID, $iStance, $iComment) { $input = array('stance' => $iStance, 'comment' => $iComment); $rtn = Validator::init('addVote', $input); if (is_array($rtn)) { foreach ($rtn as $key => $value) { if ($rtn[$key] != 'valid') { $flag = false; } } } else { return false; } if (!isset($flag)) { $rtn = DataHandler::insertRegVote($this->getID(), $uID, $iStance, $iComment); if ($rtn[0] == true) { if (is_numeric($rtn[1])) { array_push($this->voterefs, $rtn); CookiesManager::SetCookies($this->id, $rtn[1]); return true; } else { return false; } } else { return false; } } else { return 'Invalid Input'; } }
public function destruirCookie() { if (isset($_POST['destruirCookie']) && isset($_COOKIE[$_POST['destruirCookie']])) { CookiesManager::borrarCookie($_POST['destruirCookie']); $this->segundosCookie = "Cookie borrada!"; } else { $this->segundosCookie = "No existe la cookie para borrar!"; $this->validationClassDestruir = "error"; $this->mensajeErrorNombreCookieDestruir = "No existe una cookie con ese nombre"; } $this->buildViewPrint(); }
private static function SetUserState($pID) { if (!empty(self::$pCookie)) { if (self::$pCookie != $pID) { self::$uState = 'new_poll'; } else { if (self::$cCookie == 'unset') { self::$uState = 'only_voted'; } else { self::$uState = 'closed'; } } } else { self::$uState = 'new_poll'; } }
private static function validateaddVote($input) { if (CookiesManager::GetUserState() != 'closed') { foreach ($input as $key => $value) { switch ($key) { case "stance": if (is_bool($input[$key])) { $validity['stance'] = 'valid'; break; } else { $validity['stance'] = 'invalid'; break; } case "comment": if (is_string($input[$key])) { $input[$key] = trim($input[$key]); if (strlen($input[$key]) <= 350) { $validity['comment'] = 'valid'; break; } else { $validity['comment'] = 'invalid'; break; } } else { $validity['comment'] = 'invalid'; break; } default: return false; } } return $validity; } else { echo CookiesManager::GetUserState(); return false; } }
public static function insertRegVote($pID, $uID, $vStance, $vComment) { mysqli_real_escape_string(dbConnect::dbGetLink(), $vComment); if (CookiesManager::GetUserState() != 'closed') { if (CookiesManager::GetUserState() == 'only_voted') { $vID = CookiesManager::vGetCookie(); $q = "UPDATE votes SET stance={$vStance}, user_id={$uID}, comment='{$vComment}', commenttime=NOW() WHERE vote_id = {$vID}"; $r = mysqli_query(dbConnect::dbGetLink(), $q); if ($r) { $outcome[] = mysqli_affected_rows(dbConnect::dbGetLink()) == 1 ? true : false; $outcome[] = $vID; return $outcome; } else { return $outcome[] = false; } } else { $q = "INSERT INTO votes (poll_id, stance, votetime, user_id, comment, commenttime) VALUES ({$pID}, {$vStance}, NOW(), {$uID}, '{$vComment}', NOW())"; $r = mysqli_query(dbConnect::dbGetLink(), $q); if ($r) { if (mysqli_affected_rows(dbConnect::dbGetLink()) == 1) { $outcome[] = true; $outcome[] = mysqli_insert_id(dbConnect::dbGetLink()); return $outcome; } else { return $outcome[] = false; } } else { return $outcome[] = false; } } } }
<?php require_once 'libs/class.CookiesManager.php'; CookiesManager::init(1); require_once 'libs/class.Poll.php'; require_once 'libs/class.Vote.php'; dbConnect::init(); //$CurrentPoll = new Poll; //echo $CurrentPoll->getStatement(); //$CurrentPoll->setStatement("Polen zijn nodig voor onze economie"); //$CurrentPoll->setName('SimplePollv2'); //echo $CurrentPoll->getStatement(); //echo $CurrentPoll->getName(); //if (!is_object($TestVote = new Vote('82.171.43.213', 1))) {//82.171.43.213 // echo "false"; //} else { // echo $TestVote->comment; //} //echo '<p>' . $CurrentPoll->addVote( 4, true,'Zukini') . '</p>'; $CurrentPoll = new Poll(); $yn = $CurrentPoll->addVote(5, true, 'Helemaal mee eens'); include 'includes/header.html'; echo $vyn; include 'includes/footer.html'; ?>