/** * Save an entry * * @return void */ public function saveTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } $fields = Request::getVar('fields', array(), 'post'); // Save the poll parent information $row = Poll::oneOrNew($fields['id'])->set($fields); if (!$row->save()) { Notify::error($row->getError()); return $this->editTask($row); } $row->checkin(); // Save the poll options $options = Request::getVar('polloption', array(), 'post'); foreach ($options as $i => $text) { $option = new Option(); $option->set('poll_id', (int) $row->get('id')); $option->set('text', htmlspecialchars($text, ENT_QUOTES, 'UTF-8')); if ($fields['id']) { $option->set('id', (int) $i); } if (!$option->save()) { Notify::error($option->getError()); return $this->editTask($row); } } Notify::success(Lang::txt('COM_POLL_ITEM_SAVED')); if ($this->getTask() == 'apply') { return $this->editTask($row); } $this->cancelTask(); }