responseFormat = SGL_RESPONSEFORMAT_JSON; } function &singleton() { static $instance; // If the instance is not there, create one if (!isset($instance)) { $class = __CLASS__; $instance = new $class(); } return $instance; } function vote() { SGL::logMessage(null, PEAR_LOG_DEBUG); $this->responseFormat = SGL_RESPONSEFORMAT_JSON; $req = &SGL_Request::singleton(); $vote = (object)$req->get('vote'); $oVote = new SGL_Vote(false); $oVote->setFrom($vote); // make sure they dont tamper the form data // so init user/ip/date $oVote->init(); $oVoting = new SGL_Voting(); if ($oVoting->getById($oVote->voting_id) === false) { return $this->_returnError('No such voting'); } if (($isValid = $oVoting->validateVote($oVote)) !== true) { return $this->_returnError($isValid); } $success = $oVoting->addVote($oVote); if ($success !== false) { //SGL::raiseMsg('vote successfull', false, SGL_MESSAGE_INFO); return array('message'=>'vote successfull','status'=>1); } else { return $this->_returnError('vote not successfull'); } } function _returnError($msg) { return array( 'status' => -1, 'message' => $msg ); } } ?>