<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Bremployeewageleveladmin extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see https://codeigniter.com/user_guide/general/urls.html
	 */
	var $menu;
	var $contactus;
	public function __construct() {
		parent::__construct();
		$this->load->library(array('session'));
		date_default_timezone_set('Asia/Hong_Kong');
		// $this->load->model('Section', 'section_model');
		// $this->menu = $this->section_model->buildTopMenuItem();
		// $this->breadcrumbs = [];
		// $this->load->model('ContactDetails', 'contactdetails_model');
		// $this->contactus = $this->contactdetails_model->getContactus();

		$this->load->model('Bremployeemodel', 'employee_model');
		$this->load->model('Brshopmodel', 'shop_model');
		$this->load->model('Bremployeegroupmodel', 'employeegroup_model');
		$this->load->model('Bremployeeincomemodel', 'employeeincome_model');
		$this->load->model('Bremployeewagelevelmodel', 'employeewage_model');
		if (!$this->session->userdata('logged_in')) {
			redirect('/at-cms/login');
		}

		$this->load->helper('form');

	}

	public function index() {

		$userid = $this->session->userdata('userid');
		// $user_data = $this->session->userdata('USER_ID');

		if (empty($userid)) {
			// $this->load->view('test1');
			redirect('/at-cms/login', 'refresh');
		}
		$this->load->helper('url');
		//testing
		// $currentURL = current_url(); //for simple URL
		// $params = $_SERVER['QUERY_STRING']; //for parameters
		// $fullURL = $currentURL . '?' . $params; //full URL with parameter
		//end testing

		//for pagination
		// or you can autoload it in config

// print base_url($this->uri->uri_string());
		// $config["base_url"] = base_url() . "adminmain/index/";
		$config["base_url"] = base_url() . "at-cms/folderadmin/index";
		// $config["total_rows"] = $this->Countries->record_count();

		// $config["total_rows"] = $this->shop_model->record_count();

		$config["uri_segment"] = 4;
		$config["per_page"] = 10;
		$config["page"] = 0;

		// $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

		$this->load->helper('url');
		if (!empty($this->uri->segment(4))) {
			$page = $this->uri->segment(4);
		} else {
			$page = $config["page"];
		}
		// get 11
		if (!empty($this->uri->segment(5))) {
			$perpage = $this->uri->segment(5);
		} else {
			$perpage = $config["per_page"];
		}
		// $perpage = $this->uri->segment(4);

		// $choice = $config["total_rows"] / $perpage;
		// $config["num_links"] = round($choice);
		// $config["num_links"] = ceil($choice);

		//end for pagination

		// $this->load->view('welcome_message');
		$data = array(
			'title' => 'My Title',
			'heading' => 'My Heading',
			'message' => 'My Message',
		);
		// $data['total_rows']=$config["total_rows"];
		$data['page'] = $page;
		$data['perpage'] = $perpage;
		// $data['num_links'] = $config["num_links"];
		// $data['record']=$this->folder_model->getfolderdata($perpage, $page);
		$data['base_url'] = $config["base_url"];
		$data['fullName'] = $this->session->userdata('fullName');
		$count = 1;
		// foreach($data['record'] as $row){
		//     $data['level1'][$count]=$this->folder_model->getlevel1data($row->id);
		//     $data['level1Record'][$count]=$this->folder_model->getflodercount($row->id);
		//     $countLevel2=1;
		//     foreach($data['level1'][$count] as $secondrow){
		//         $data['level2'][$count][$countLevel2]=$this->folder_model->getlevel2data($secondrow->id);
		//         $countLevel3=1;
		//         foreach($data['level2'][$count][$countLevel2] as $thirdrow){
		//             $data['level3'][$count][$countLevel2][$countLevel3]=$this->folder_model->getlevel3data($thirdrow->id);
		//             $countLevel3=$countLevel3+1;
		//         }
		//         $countLevel2=$countLevel2+1;
		//     }
		//     $count++;

		// }
		$data['shop'] = $this->shop_model->getAllShop();
		$data['currentshop'] = $this->session->userdata('currentshop');
		//get all employee data
		$data["employee_list"] = $this->employee_model->getEmployeeAll($this->session->userdata('currentshop')); //may add current login shop id
		//get all shop data
		$data["shop_list"] = $this->shop_model->getShopAll();

		//end get all shop data
		//end get all employee data
		$data['selectedmenu'] = 'bremployeeadmin';

		$this->load->view('/admin/bremployeewagelevelview', $data);
		// $contactusdata = $this->contactdetails_model->getContactus();
		//     $this->breadcrumbs[] = array (
		//         'label' => '聯絡我們',
		//         'link' => ''
		//     );
		//     $this->twig->display('main', array(
		//         'path' => array(
		//             'vendor' => $this->config->item('vendor_path'),
		//             'script' => $this->config->item('script_path'),
		//             'css' => $this->config->item('css_path'),
		//             'image' => $this->config->item('image_path')
		//         ),
		//         'breadcrumbs' => $this->breadcrumbs,
		//         'menus' => $this->menu,
		//         'contactusdata'=>$contactusdata,
		//         'session' => 'contact',
		//         'contactus' => $this->contactus,
		//         'page' => 'index'
		//     ));
	}
	public function add() {
		$userid = $this->session->userdata('userid');
		// $user_data = $this->session->userdata('USER_ID');

		if (empty($userid)) {
			// $this->load->view('test1');
			redirect('/at-cms/login', 'refresh');
		}
		$this->load->helper('url');

		//old data
		$config["base_url"] = base_url() . "at-cms/folderadmin/index";
		// $config["total_rows"] = $this->Countries->record_count();

		// $config["total_rows"] = $this->shop_model->record_count();

		$config["uri_segment"] = 4;
		$config["per_page"] = 10;
		$config["page"] = 0;

		// $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

		$this->load->helper('url');
		if (!empty($this->uri->segment(4))) {
			$page = $this->uri->segment(4);
		} else {
			$page = $config["page"];
		}
		// get 11
		if (!empty($this->uri->segment(5))) {
			$perpage = $this->uri->segment(5);
		} else {
			$perpage = $config["per_page"];
		}
		// $perpage = $this->uri->segment(4);

		// $choice = $config["total_rows"] / $perpage;
		// $config["num_links"] = round($choice);
		// $config["num_links"] = ceil($choice);

		//end for pagination

		// $this->load->view('welcome_message');
		$data = array(
			'title' => 'My Title',
			'heading' => 'My Heading',
			'message' => 'My Message',
		);
		// $data['total_rows']=$config["total_rows"];
		$data['page'] = $page;
		$data['perpage'] = $perpage;
		// $data['num_links'] = $config["num_links"];
		// $data['record']=$this->folder_model->getfolderdata($perpage, $page);
		$data['base_url'] = $config["base_url"];
		$data['fullName'] = $this->session->userdata('fullName');
		$count = 1;

		//end old data

		$data['shop'] = $this->shop_model->getAllShop();
		$data['currentshop'] = $this->session->userdata('currentshop');

		$data['pagemethod'] = 'add';

		//get shop list
		$data['shoplist'] = $this->shop_model->getShopAll();
		//end get shop list

		//get role list
		$data['employeegrouplist'] = $this->employeegroup_model->getEmployee_group();
		//end get role list

		$data['employeeincometypelist'] = $this->employeeincome_model->getEmployeeincome();

		$data['selectedmenu'] = 'bremployeeadmin';
		// $data="";
		$this->load->view('/admin/bremployeewageleveladdview', $data);
	}
	public function edit() {
		$userid = $this->session->userdata('userid');
		// $user_data = $this->session->userdata('USER_ID');

		if (empty($userid)) {
			// $this->load->view('test1');
			redirect('/at-cms/login', 'refresh');
		}
		$this->load->helper('url');

		//old data
		$config["base_url"] = base_url() . "at-cms/folderadmin/index";
		// $config["total_rows"] = $this->Countries->record_count();

		// $config["total_rows"] = $this->shop_model->record_count();

		$config["uri_segment"] = 4;
		$config["per_page"] = 10;
		$config["page"] = 0;

		// $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

		$this->load->helper('url');
		if (!empty($this->uri->segment(4))) {
			$page = $this->uri->segment(4);
		} else {
			$page = $config["page"];
		}
		// get 11
		if (!empty($this->uri->segment(5))) {
			$perpage = $this->uri->segment(5);
		} else {
			$perpage = $config["per_page"];
		}
		// $perpage = $this->uri->segment(4);

		// $choice = $config["total_rows"] / $perpage;
		// $config["num_links"] = round($choice);
		// $config["num_links"] = ceil($choice);

		//end for pagination

		// $this->load->view('welcome_message');
		$data = array(
			'title' => 'My Title',
			'heading' => 'My Heading',
			'message' => 'My Message',
		);
		// $data['total_rows']=$config["total_rows"];
		$data['page'] = $page;
		$data['perpage'] = $perpage;
		// $data['num_links'] = $config["num_links"];
		// $data['record']=$this->folder_model->getfolderdata($perpage, $page);
		$data['base_url'] = $config["base_url"];
		$data['fullName'] = $this->session->userdata('fullName');
		$count = 1;

		//end old data

		$data['pagemethod'] = 'edit';

		//get employee data
		$id = $this->uri->segment(4);
		$data['employeedetails'] = $this->employee_model->getEmployee($id);

		$data['shop'] = $this->shop_model->getAllShop();
		$data['currentshop'] = $this->session->userdata('currentshop');

		//get shop list
		$data['shoplist'] = $this->shop_model->getShopAll();
		//end get shop list

		//get role list
		$data['employeegrouplist'] = $this->employeegroup_model->getEmployee_group();
		//end get role list

		$data['employeeincometypelist'] = $this->employeeincome_model->getEmployeeincome();

		//end get employee data

		// get employee list
		$data['employeelist'] = $this->employee_model->getEmployeeAll($this->session->userdata('currentshop'));

		// end get employee list

		$data['selectedmenu'] = 'bremployeeadmin';

		$this->load->view('/admin/bremployeeaddview', $data);

	} //public function edit(){
	public function detail() {
		$userid = $this->session->userdata('userid');
		// $user_data = $this->session->userdata('USER_ID');

		if (empty($userid)) {
			// $this->load->view('test1');
			redirect('/at-cms/login', 'refresh');
		}
		$this->load->helper('url');

		//old data
		$config["base_url"] = base_url() . "at-cms/folderadmin/index";
		// $config["total_rows"] = $this->Countries->record_count();

		// $config["total_rows"] = $this->shop_model->record_count();

		$config["uri_segment"] = 4;
		$config["per_page"] = 10;
		$config["page"] = 0;

		// $page = ($this->uri->segment(3))? $this->uri->segment(3) : 0;

		$this->load->helper('url');
		if (!empty($this->uri->segment(4))) {
			$page = $this->uri->segment(4);
		} else {
			$page = $config["page"];
		}
		// get 11
		if (!empty($this->uri->segment(5))) {
			$perpage = $this->uri->segment(5);
		} else {
			$perpage = $config["per_page"];
		}
		// $perpage = $this->uri->segment(4);

		// $choice = $config["total_rows"] / $perpage;
		// $config["num_links"] = round($choice);
		// $config["num_links"] = ceil($choice);

		//end for pagination

		// $this->load->view('welcome_message');
		$data = array(
			'title' => 'My Title',
			'heading' => 'My Heading',
			'message' => 'My Message',
		);
		// $data['total_rows']=$config["total_rows"];
		$data['page'] = $page;
		$data['perpage'] = $perpage;
		// $data['num_links'] = $config["num_links"];
		// $data['record']=$this->folder_model->getfolderdata($perpage, $page);
		$data['base_url'] = $config["base_url"];
		$data['fullName'] = $this->session->userdata('fullName');
		$count = 1;

		//end old data

		$data['pagemethod'] = 'detail';

		//get employee data
		$id = $this->uri->segment(4);
		$data['employeedetails'] = $this->employee_model->getEmployee($id);

		$data['shop'] = $this->shop_model->getAllShop();
		$data['currentshop'] = $this->session->userdata('currentshop');
		//get shop list
		$data['shoplist'] = $this->shop_model->getShopAll();
		//end get shop list

		//get role list
		$data['employeegrouplist'] = $this->employeegroup_model->getEmployee_group();
		//end get role list

		$data['employeeincometypelist'] = $this->employeeincome_model->getEmployeeincome();

		//end get employee data
		$data['selectedmenu'] = 'bremployeeadmin';

		$this->load->view('/admin/bremployeeaddview', $data);
	}
	public function dispay() {
		echo "1";
		$this->load->helper('url');
		$page = $this->uri->segment(3); // get 11
		$perpage = $this->uri->segment(4);
		echo "page";
		echo $page;
		echo "perpage";
		echo $perpage;
	}
}