<?php namespace App\Controllers;
/**
 * File			: MyBaseController.php
 * Description  : Controller dasar untuk semua controller yang akan dibangun
 * Created By	: Hendi
 * Created Date : 6 Jan 2021
 * Last Update  : 19 Jan 2021
**/
class MyBaseController extends BaseController
{
	# default []; agar bisa dipake di controller dan views
	# agar bisa menggunakan helper form_open(), base_url(), dll
	protected $helpers = ['form', 'url']; 
	protected $session = null;
	
	public function __construct()
	{
		# manage cache
		# jika no-cache berarti setiap request browser langsung ke server
	    # jika pake cache berarti setiap request browser tidak langsung ke server,
		# tapi cek dl di local, ini akan menambah performance / kecepatan load
		# 1. tanpa cache
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("If-Modified-Since: Mon, 22 Jan 2008 00:00:00 GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Cache-Control: private");
		header("Pragma: no-cache");
		
		# 2. pakai cache
		/*Cache aset statis yang tidak dapat diubah untuk waktu yang lama, 
		seperti 30 hari = 2592000 detik.
		//header("Cache-Control: public, max-age=2592000");*/
		
		# jika error post/ajax, uncoment saja
        /*header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
        header('Access-Control-Max-Age: 1000');
        header('Access-Control-Allow-Headers: Content-Type');*/
		
		# load session
		# diusahakan OOP dan MVC
		# bisa menggunakan metode helper
		# $this->session = sessions()
		$this->session = \Config\Services::session();
		$this->form_validation = \Config\Services::validation();
	}
	
	public function isLoggedIn() 
	{
		if ($this->session->get('is_loggedin')) return true;
		return false;
	}
}
