Ejemplo n.º 1
0
 /**
  * Method to save a record.
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries.
     Request::checkToken();
     // Access check.
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
         return $this->cancelTask();
     }
     // Initialise variables.
     $fields = Request::getVar('fields', array(), 'post', 'array');
     // The save2copy task needs to be handled slightly differently.
     if ($this->_task == 'save2copy') {
         // Reset the ID and then treat the request as for Apply.
         $fields['id'] = 0;
         $this->_task = 'apply';
     }
     $row = Link::oneOrNew($fields['id'])->set($fields);
     // Attempt to save the data.
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     Notify::success(Lang::txt('COM_REDIRECT_SAVE_SUCCESS'));
     if ($this->_task == 'apply') {
         return $this->editTask($row);
     }
     // Redirect the user
     $this->cancelTask();
 }
Ejemplo n.º 2
0
 /**
  * Display edit form
  *
  * @return  void
  */
 public function editTask($row = null)
 {
     // Access check.
     if (!User::authorise('core.edit', $this->_option)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'), 'error');
         return;
     }
     if (!is_object($row)) {
         // Incoming
         $id = Request::getVar('id', array(0));
         if (is_array($id) && !empty($id)) {
             $id = $id[0];
         }
         // Load the article
         $row = Link::oneOrNew($id);
     }
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->set('row', $row)->setLayout('edit')->display();
 }