Example #1
0
 * @param $last
 * @param $optin
 * @param $group
 */
require_once $_SERVER['DOCUMENT_ROOT'] . '/../inc/config.inc.php';
// Response object
$responseObj = new AjaxResponse_Json();
// recaptcha?
$recaptchaObj = new Recaptcha();
$recaptchaResult = $recaptchaObj->validateRecaptcha($_REQUEST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($recaptchaResult === false) {
    $responseObj->setSuccess(false);
    $responseObj->setError(array('RECAPTCHA_ERROR' => 'reCAPTCHA did not validate.'));
} else {
    // entry object
    $entryObj = new App_Entry(array('email' => $_REQUEST['email'], 'first' => $_REQUEST['first'], 'last' => $_REQUEST['last'], 'optin' => $_REQUEST['optin']));
    $entryResult = $entryObj->insertElseUpdate();
    // error?
    if ($entryResult === false) {
        $responseObj->setSuccess(false);
        $responseObj->setError($entryObj->getErrorObj()->getThrownErrorsWithDescriptions());
    } else {
        // save vote
        // vote object
        $voteObj = new App_Vote(array('fkEntryId' => $entryObj->getId(), 'fkGroupId' => $_REQUEST['group']));
        $voteResult = $voteObj->insert();
        if ($voteResult === false) {
            // error?
            $responseObj->setSuccess(false);
            $responseObj->setError($voteObj->getErrorObj()->getThrownErrorsWithDescriptions());
        } else {
Example #2
0
 /**
  * Validate fkEntryId
  * @return boolean
  */
 public function validateFkEntryId()
 {
     $entryObj = new App_Entry(array('id' => $this->getFkEntryId()));
     $result = $entryObj->fetchById();
     if ($result === false) {
         // not found
         $this->getErrorObj()->setError('VOTE_ENTRY_NOEXIST');
         return false;
     } else {
         return true;
     }
 }
Example #3
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/../inc/config.inc.php';
//load action
$entry = new App_Entry();
$data = array('email' => "*****@*****.**", 'first' => "Christian", 'last' => "Skelly");
$entry->insertEntry($data);
if ($entry->getResponse() === true) {
    echo "sucess";
} else {
    print_r($entry->getResponse());
}
Example #4
0
<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/../inc/config.inc.php';
//load action
//Add VOTE choice to data
$data = array('email' => $_REQUEST['email'], 'first' => $_REQUEST['firstname'], 'last' => $_REQUEST['lastname']);
//new entry
$entry = new App_Entry();
//check if record exists
$entry->emailExists($data['email']);
if ($entry->getResponse() === false) {
    $entry->insertEntry($data);
    //get last insert id
    //add vote
    $vote = new App_Vote();
    // direct to thankyou page -  set true to redirect
    $entry->setResponse(TRUE);
} else {
    $exists = $entry->getResponse();
    //get user id
    $id = $exists->id;
    //did they vote today?
    $vote = new App_Vote();
    //echo json_encode($record->id);
    $entry->setResponse(FALSE);
}
echo json_encode($entry->getResponse());
// if($exists)
//$entry->insertEntry($data);
//if($entry->getResponse() === true) {echo "success"; } else { echo json_encode($entry->getResponse());}
//echo json_encode($entry->getResponse());