/** * Add action - add the new client * * @package las * @version 1.0 */ public function addAction() { $tariffs = Tariffs::find('status=' . Tariffs::ACTIVE); if (!count($tariffs)) { $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the tariff first") . ': ' . $this->tag->linkTo('admin/tariffs/add', __('Add'))); } // Set title, pick view and send variables $this->tag->setTitle(__('Clients') . ' / ' . __('Add')); $this->view->pick('clients/write'); $this->view->setVars(['tariffs' => $tariffs, 'status' => Clients::status(true)]); // Check if the form has been sent if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $client = new Clients(); $client->__set('tariffs', $tariffs); $valid = $client->write(); // Check if data are valid if ($valid instanceof Clients) { unset($_POST); $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The data has been saved.")); } else { $this->view->setVar('errors', $valid); $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } } }