/** * Add action - add the new device * * @package las * @version 1.0 */ public function addAction() { $clients = Clients::find(['status!=:status:', 'bind' => ['status' => Clients::UNACTIVE]]); $networks = Networks::find(['status=:status:', 'bind' => ['status' => Networks::ACTIVE]]); if (!count($clients)) { $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the client first") . ': ' . $this->tag->linkTo('admin/clients/add', __('Add'))); } if (!count($networks)) { $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the network first") . ': ' . $this->tag->linkTo('admin/networks/add', __('Add'))); } // Set title, pick view and send variables $this->tag->setTitle(__('Devices') . ' / ' . __('Add')); $this->view->pick('devices/write'); $this->view->setVars(['clients' => $clients, 'networks' => $networks, 'type' => Devices::type(true), 'status' => Devices::status(true)]); // Check if the form has been sent if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $device = new Devices(); $device->__set('clients', $clients); $device->__set('networks', $networks); $valid = $device->write(); // Check if data are valid if ($valid instanceof Devices) { 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.")); } } }