/** * Edit action - edit the service * * @package las * @version 1.0 */ public function editAction() { // Get id from url params and check if record exist $params = $this->router->getParams(); if (isset($params[0]) && ($service = Services::findFirst($params[0]))) { $clients = Clients::find(['status=:status:', 'bind' => ['status' => Clients::ACTIVE]]); $devices = Devices::find(['status=:status:', 'bind' => ['status' => Devices::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($devices)) { $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the device first") . ': ' . $this->tag->linkTo('admin/devices/add', __('Add'))); } // Set title, pick view and send variables $this->tag->setTitle(__('Services') . ' / ' . __('Add')); $this->view->pick('services/write'); $this->view->setVars(['clients' => $clients, 'devices' => $devices, 'chain' => Services::chain(true), 'direction' => Services::direction(true), 'status' => Services::status(true), 'priority' => Services::priority(true), 'protocol' => Services::protocol(true), 'portDirection' => Services::portDirection(true)]); // Check if the form has been sent if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $service->__set('clients', $clients); $service->__set('devices', $devices); $valid = $service->write('update'); // Check if data are valid if ($valid instanceof Services) { $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.")); } } else { $diff = ['client' => $service->client_id, 'device' => $service->device_id, 'IP' => $service->IP ? long2ip($service->IP) : null]; // Values to fill out the form $this->tag->setDefaults(array_merge(get_object_vars($service), $diff)); } } else { parent::notFoundAction(); } }