session = \Config\Services::session(); } /** * Instance of the main Request object. * * @var CLIRequest|IncomingRequest */ protected $request; /** * An array of helpers to be loaded automatically upon * class instantiation. These helpers will be available * to all other controllers that extend BaseController. * * @var list */ protected $helpers = []; /** * Be sure to declare properties for any property fetch you initialized. * The creation of dynamic property is deprecated in PHP 8.2. */ // protected $session; /** * @return void */ public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger) { // Do Not Edit This Line parent::initController($request, $response, $logger); // Preload any models, libraries, etc, here. // E.g.: $this->session = \Config\Services::session(); } /** * This function used to check the user is logged in or not */ protected function isLoggedIn() { $isLoggedIn = $this->session->get('isLoggedIn'); if (!isset($isLoggedIn) || $isLoggedIn !== true) { // if ($this->request->uri->getSegment(2) === 'zohobooks_api_fetch_all') { // return redirect()->to('login/zohobooks_api_fetch_all'); // } return redirect()->to('login'); } else { log_message('error', '#####In BaseController - isLoggedIn function ci session: ' . $this->session->get('name')); $this->role = $this->session->get('role'); $this->vendorId = $this->session->get('userId'); $this->name = $this->session->get('name'); $this->roleText = $this->session->get('roleText'); $this->Designation = $this->session->get('Designation'); $this->DEPCode = $this->session->get('DEPCode'); $this->HeadDept = $this->session->get('HeadDept'); $this->DepartmentName = $this->session->get('DepartmentName'); $this->EmpID = $this->session->get('EmpID'); $this->depaccess = $this->session->get('depaccess'); $this->profilepic = $this->session->get('ProfilePic'); $this->CompanyName = $this->session->get('CompanyName'); // Set data to global array $this->global['name'] = $this->name; $this->global['role'] = $this->role; $this->global['role_text'] = $this->roleText; $this->global['DEPCode'] = $this->DEPCode; $this->global['Designation'] = $this->Designation; $this->global['DepAccesslist'] = $this->depaccess; $this->global['CompanyName'] = $this->CompanyName; } } /** * This function is used to check the access */ function isAdmin() { if ($this->role != ROLE_ADMIN) { return true; } else { return false; } } /** * This function is used to check the access */ function isTicketter() { if ($this->role != ROLE_ADMIN || $this->role != ROLE_MANAGER) { return true; } else { return false; } } /** * This function is used to load the set of views */ function loadThis() { $this->global['pageTitle'] = 'Resico : Access Denied'; $this->loadViews('access', $this->global); } /** * This function is used to load the set of views */ function pageNotFound() { $this->global['pageTitle'] = 'Resico : 404 - Page Not Found'; $this->loadViews("404", $this->global, NULL, NULL); } /** * This function is used to logged out user from system */ function logout() { $session = session()->destroy(); // $cacheFactory = new CacheFactory(); // $cache = $cacheFactory->getHandler(); // $cache->clean(); return redirect()->to('login'); } /** * This function used to load views * @param {string} $viewName : This is view name * @param {mixed} $headerInfo : This is array of header information * @param {mixed} $pageInfo : This is array of page information * @param {mixed} $footerInfo : This is array of footer information * @return {null} $result : null */ function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL) { if (!session()->has('name')) { // Session is not active, destroy session and redirect to login session()->destroy(); return redirect()->to('login'); } $headerInfo['pageTitle'] = $this->CompanyName ." : ".$headerInfo['pageTitle']; $header = view('includes/new_header', $headerInfo); $content = view($viewName, $pageInfo); $footer = view('includes/new_footer', $headerInfo); echo $header . $content . $footer; } }