/** * Execute the action and returns a result * * @return array */ public function execute() { $obj = isset($_POST['obj']) ? $_POST['obj'] : (isset($_GET['obj']) ? $_GET['obj'] : null); if (is_null($obj)) { $this->_ajax->setSendMessage("Aucune référence d'objet valide", t41_Ajax::ERR); } $this->_obj = t41_Core::cacheGet($obj); $this->_ajax = new t41_Ajax(); $this->_ajax->setStatus(t41_Ajax::NOK); if (!$this->_obj instanceof t41_Form_Tagger) { $this->_ajax->setSendMessage("L'objet passé en référence n'a pas été retrouvé", t41_Ajax::ERR); } $func = isset($_POST['func']) ? $_POST['func'] : (isset($_GET['func']) ? $_GET['func'] : null); if (!is_null($func)) { $func = '_' . $func; if (method_exists($this, $func)) { return $this->{$func}(); } } return false; }
private function _submit() { $ajax = new t41_Ajax(); $ajax->setStatus(t41_Ajax::NOK); if (!isset($_POST['values'])) { $ajax->setSendMessage("Données manquantes"); } if (!isset($_POST['obj'])) { $ajax->setSendMessage("Référence d'objet manquante"); } /* @var $obj t41_Form_Mask */ $obj = t41_Core::cacheGet($_POST['obj']); $pairs = explode('&', $_POST['values']); $data = array(); foreach ($pairs as $pair) { $elem = explode('=', $pair); $data[$elem[0]] = urldecode($elem[1]); } try { $res = $obj->save($data); if ($res === false) { if ($obj->getParameter('redirect_on_failure')) { $ajax->addData('redirect', $obj->getParameter('redirect_on_failure')); } $ajax->setSendMessage($res); } else { if ($obj->getParameter('redirect_on_success')) { $ajax->addData('redirect', $obj->getParameter('redirect_on_success')); } $ajax->setSendMessage($res, t41_Ajax::OK); } } catch (Exception $e) { $ajax->setSendMessage($e->getMessage(), t41_Ajax::ERR); } exit; }