/** * Index Action * * @package las * @version 1.0 */ public function indexAction() { $this->tag->setTitle(__('Home')); $this->site_desc = __('Home'); $ip = \Las\Library\Info::ip(); $this->view->setVar('ip', $ip); if ($device = Devices::findFirst(['IP = :ip:', 'bind' => ['ip' => ip2long($ip)]])) { $client = $device->getClient(); $this->view->setVars(['device' => $device, 'client' => $client, 'tariff' => $client->getTariff(), 'balance' => Payments::sum(['conditions' => 'status=' . Payments::SUCCESS . ' AND client_id=' . $client->id, 'column' => 'amount'])]); } }
/** * Index Action * * @package las * @version 1.0 */ public function temporarilyAction() { $params = $this->router->getParams(); if (isset($params[0]) && ($id = $params[0])) { $ip = \Las\Library\Info::ip(); if ($device = Devices::findFirst(['IP = :ip:', 'bind' => ['ip' => ip2long($ip)]])) { $client = $device->getClient(); if ($client->id == $id && $client->status == Clients::INDEBTED) { $client->status = Clients::ACTIVE; $client->save(); } } $this->response->redirect('tasks/tmp'); } }
/** * Edit action - edit the device * * @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]) && ($device = Devices::findFirst($params[0]))) { $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') . ' / ' . __('Edit')); $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->__set('clients', $clients); $device->__set('networks', $networks); $valid = $device->write('update'); // Check if data are valid if ($valid instanceof Devices) { $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 { // Values to fill out the form $this->tag->setDefaults(['name' => $device->name, 'network' => $device->network_id, 'client' => $device->client_id, 'type' => $device->type, 'IP' => long2ip($device->IP), 'MAC' => $device->MAC, 'description' => $device->description, 'status' => $device->status]); } } else { parent::notFoundAction(); } }