__guest($data->url ?? ''); } public function index() { $this->showPage(['slug' => 'adminSupervisorIndex']); } public function showPage($params) { $this->setPageTitle('Admin Supervisor'); $this->breadcrumbs->addCrumb('Admin Supervisor'); $this->seo->add('title', 'Admin Supervisor'); $data = []; $slug = $params['slug']; if (!in_array($slug, ["adminSupervisorIndex"])) { echo 'Invalid Page Slug ' . $slug; return ''; } if ($slug == 'adminSupervisorIndex') { $render_file = '_adminSupervisorIndex'; } $this->_render($render_file, $data); } public function showForm($params) { $adminSupervisorNewModel = new AdminSupervisorNewModel(); $slug = trim($params['slug']); $data = []; $data['isAjax'] = $this->request->isAjax(); $data['id'] = isset($params['id']) ? intval($params['id']) : null; $data['adminSupervisorData'] = null; $data['slug'] = $slug; $this->setPageTitle('Admin Supervisor'); $this->breadcrumbs->addCrumb('Admin Supervisor'); $this->seo->add('title', 'Admin Supervisor'); /** * ------------------------------------------------------------------- * CHECK Valid Form Slug * ------------------------------------------------------------------- */ if (!in_array($slug, ['adminSupervisorForm', 'supervisorMultiAdminForm'])) { echo 'Invalid Form Slug ' . $params['slug']; return ''; } // ------------------------------------------------------------------- /** * ------------------------------------------------------------------- * GET DATA * ------------------------------------------------------------------- */ if (!empty($data['id'])) { $data['adminSupervisorData'] = $adminSupervisorNewModel->db->where('id', $data['id'])->getOne('admin_supervisor'); if (empty($data['adminSupervisorData'])) { // Set Log Here..... echo 'You can not access this data'; return ''; } } // ------------------------------------------------------------------- $this->_render('_' . $slug, $data); } public function save($params) { $slug = $params['slug']; $postParams = $this->request->getPostParams(); $adminSupervisorNewModel = new AdminSupervisorNewModel(); $id = (isset($postParams['id']) && is_numeric($postParams['id'])) ? intval($postParams['id']) : null; if (!in_array($slug, ['adminSupervisorForm', 'supervisorMultiAdminForm'])) { $this->response('Invalid Form Slug', false); } if ($slug == 'adminSupervisorForm') { //----------------------------------------------------------------// // clear undefined post fields for security.. //----------------------------------------------------------------// $filterFormFields = ["id", "id_user", "id_user_supervisor", "status"]; $saveData = array_intersect_key($postParams, array_flip($filterFormFields)); // ---------------------------------------------------------------- if (empty($saveData['id_user']) || empty($saveData['id_user_supervisor'])) { $this->response('Admin or super visor data can not be empty', false); } if ($saveData['id_user'] == $saveData['id_user_supervisor']) { $this->response('Admin can not be same with Supervisor', false); } if ($saveData['id_user'] == $saveData['id_employee']) { $this->response('Admin can not be same with Employee', false); } $checkExistData = $adminSupervisorNewModel->db ->where('id_user', $saveData['id_user']) ->where('id_user_supervisor', $saveData['id_user_supervisor']) ->getOne('admin_supervisor'); if (!empty($checkExistData) && !empty($id)) { $this->response('There is already same record', false); } $adminSupervisorNewModel->isNew = empty($saveData['id']) ? true : false; $adminSupervisorNewModel->data = $saveData; $saveResult = $adminSupervisorNewModel->save(); if ($saveResult == false) { $this->response($adminSupervisorNewModel->getErrors(), false); } $this->response('Saved'); } else if ($slug == 'supervisorMultiAdminForm') { /** * Add admin to supervisor with multi data */ //----------------------------------------------------------------// // clear undefined post fields for security.. //----------------------------------------------------------------// $filterFormFields = ["id_users", "id_user_supervisor", "status"]; $saveData = array_intersect_key($postParams, array_flip($filterFormFields)); // ---------------------------------------------------------------- $idUsers = $saveData['id_users']; $id_user_supervisor = $saveData['id_user_supervisor']; if (empty($idUsers)) { $this->response('Admin data can not be empty', false); } if (empty($id_user_supervisor)) { $this->response('Supervisor data can not be empty', false); } foreach ($idUsers as $key => $id_user) { if ($id_user == $id_user_supervisor) { unset($idUsers[$key]); continue; //$this->response('Admin can not be same with Supervisor', false); } $checkExistData = $adminSupervisorNewModel->db ->where('id_user', $id_user) ->where('id_user_supervisor', $id_user_supervisor) ->getOne('admin_supervisor'); if (!empty($checkExistData) && !empty($id)) { $this->response('There is already same record', false); } } if (!empty($idUsers)) { foreach ($idUsers as $id_user) { $adminSupervisorInsert = [ 'id_user' => $id_user, 'id_user_supervisor' => $id_user_supervisor, ]; $adminSupervisorNewModel->isNew = true; $adminSupervisorNewModel->data = $adminSupervisorInsert; $adminSupervisorNewModel->save(); } } $this->response('Saved'); } } public function readAdminSupervisorTable() { $adminSupervisorNewModel = new AdminSupervisorNewModel(); $getParams = $this->request->getQueryParams(); $_SESSION['draw'] = (int)($draw = $_SESSION['draw'] ?? 1) + 1; $start = intval($_POST['start'] ?? $_GET['start'] ?? 0); $length = intval($_POST['length'] ?? $_GET['length'] ?? 200); if (!empty($_POST['order'])) { $orderByField = $_POST['order'][0]['name']; $orderbyDirection = $_POST['order'][0]['dir']; $adminSupervisorNewModel->db->orderBy($orderByField, $orderbyDirection); } /** * Datatable Search Form */ $formFilter = $_POST['formFilter'] ?? null; $filterArray = null; if (!empty($formFilter) && is_string($formFilter)) { parse_str($formFilter, $filterArray); } /** * General Search */ if (!empty(trim($filterArray['generalSearch']))) { $generalSearch = filter_var($filterArray['generalSearch'], FILTER_SANITIZE_STRING); $generalSearch = trim($generalSearch); $adminSupervisorNewModel->db->where('(' . "admin_supervisor.id = '{$generalSearch}' " . "admin_supervisor.id_employee = '{$generalSearch}' " . ')'); } /** * ------------------------ * id_user * ------------------------ */ if (isset($filterArray['id_user'])) { $id_user = $filterArray['id_user']; if (is_numeric($id_user) && $id_user > 0) { $adminSupervisorNewModel->db->where('admin_supervisor.id_user', intval($id_user)); } } /** * ------------------------ * id_user_supervisor * ------------------------ */ if (isset($filterArray['id_user_supervisor'])) { $id_user_supervisor = $filterArray['id_user_supervisor']; if (is_numeric($id_user_supervisor) && $id_user_supervisor > 0) { $adminSupervisorNewModel->db->where('admin_supervisor.id_user_supervisor', intval($id_user_supervisor)); } } /** * ------------------------ * id_employee * ------------------------ */ if (isset($filterArray['id_user'])) { $id_user = $filterArray['id_employee']; if (is_numeric($id_user) && $id_user > 0) { $adminSupervisorNewModel->db->where('admin_supervisor.id_employee', intval($id_employee)); } } $adminSupervisorNewModel->db->join('admin', 'admin.id_user=admin_supervisor.id_user', 'left'); $adminSupervisorNewModel->db->join('user', 'user.id_user=admin_supervisor.id_user', 'left'); $adminSupervisorNewModel->db->join('admin adminVisor', 'adminVisor.id_user=admin_supervisor.id_user_supervisor', 'left'); $adminSupervisorNewModel->db->join('user userVisor', 'userVisor.id_user=admin_supervisor.id_user_supervisor', 'left'); $adminSupervisorNewModel->db->join('admin employeeVisor', 'employeeVisor.id_user=admin_supervisor.id_employee', 'left'); $dbData = $adminSupervisorNewModel->db ->withTotalCount() ->objectBuilder() ->groupBy('admin_supervisor.id') ->get('admin_supervisor', [$start, $length], "admin_supervisor.*, admin.firstname as admin_firstname, admin.lastname as admin_lastname, admin.fullname as admin_fullname, user.id_representative as employee_id_representative, adminVisor.firstname as adminVisor_firstname, adminVisor.lastname as adminVisor_lastname, adminVisor.fullname as adminVisor_fullname, userVisor.id_representative as adminVisor_employee_id_representative, employeeVisor.fullname as employeeVisor_fullname, employeeVisor.firstname as employeeVisor_firstname, employeeVisor.lastname as employeeVisor_lastname "); $totalCount = $adminSupervisorNewModel->db->totalCount; if (!empty($dbData)) { foreach ($dbData as $key => $value) { $dbData[$key]->DT_RowId = $value->id; } } $array = [ 'draw' => $_SESSION['draw'], 'recordsTotal' => $totalCount, 'recordsFiltered' => $totalCount, 'data' => $dbData, ]; $this->response($array); } public function update($params) { $id = intval($params['id']); $postParams = $this->request->getPostParams(); $adminSupervisorNewModel = new AdminSupervisorNewModel(); if (empty($id)) { $this->response('NO ID', false); } //----------------------------------------------------------------// // clear undefined post fields for security.. //----------------------------------------------------------------// $filterFormFields = ['status']; $upData = array_intersect_key($postParams, array_flip($filterFormFields)); // ---------------------------------------------------------------- $upData['id'] = $id; $adminSupervisorNewModel->isNew = false; $adminSupervisorNewModel->data = $upData; $saveResult = $adminSupervisorNewModel->save(); if (!$saveResult) { $this->response($adminSupervisorNewModel->getErrors(), false); } $this->response('Updated'); } public function delete($params) { $id = $params['id'] ?? null; if (!is_numeric($id)) { $this->response('Invalid ID', false); } $adminSupervisorNewModel = new AdminSupervisorNewModel(); $saveResult = $adminSupervisorNewModel->db ->where('id', $id) ->delete('admin_supervisor'); if (!$saveResult) { $this->response($adminSupervisorNewModel->getError(), false); } $this->response('Deleted'); } public function fileupload() { $responseFile = File::save($_FILES, 'adminSupervisor', '', true); if (empty($responseFile['haveError'])) { $this->response(['upload_data' => $responseFile['data']]); } else { $this->response($responseFile['haveError'], false); } } public function showStat($params) { $slug = $params['slug']; if ($slug === 'general') { $this->setPageTitle('Statistic'); $this->breadcrumbs->addCrumb('Statistic'); $this->seo->add('title', 'Statistic'); $this->_render('_statGeneral'); } else if ($slug === 'personel') { $this->setPageTitle('Personel Statistic'); $this->breadcrumbs->addCrumb('Personel Statistic'); $this->seo->add('title', 'Personel Statistic'); $this->_render('_statPersonel'); } } private function _render($file, $data = []) { if ($this->request->isAjax()) { echo $this->render('management/adminSupervisor/' . $file, $data); } else { $this->layoutLoader('header'); echo $this->render('management/adminSupervisor/' . $file, $data); $this->layoutLoader('footer'); } } }