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

class Mainpage extends CI_Controller {	
    public function __construct() {

        parent::__construct();
		$this->load->model('login/m_login');
        if($this->session->userdata("login") !== TRUE) {	
            redirect("login", "refresh");
            die;
        }else{
            $is_login = $this->m_login->get_session_id($this->session->userdata('session_id'),$this->session->userdata('username'));
            if($is_login == false){
                $username       = $this->session->userdata('username');
                $session_id     = $this->session->userdata('session_id');
                $this->m_login->delete_session($username,$session_id);
                $this->session->sess_destroy();
                redirect(base_url() . 'login', 'refresh');
            }
        }
    }
	
    public function index(){
        $data['menu']       = $this->m_menu->get_all_menu();
        $data['submenu']    = $this->m_menu->get_all_menu(2);
		
        $this->load->model('setup/m_changepassword'); //<-- models popup password

        $group_menu = $this->session->userdata('group_menu');
        $arr_group_id = $this->m_menu->get_menu_by_group($group_menu, 0);
		
		if($arr_group_id == 0){
			$data['enable_menu']        = "";
		}
		else{
			$data['enable_menu']        = array_unique($arr_group_id);
		}
		
        
        $data['password_info']      = '';
        $data['password_info']      = $this->m_changepassword->getinfo_userlogin($this->session->userdata('username')); //<-- models popup password
        $data['model_roll_over']    = 'm_roll_over';

        $this->load->view('v_header');
        $this->load->view('v_mainpage',$data);
        $this->load->view('v_popup');
//        $this->load->view('activities/job_cost/roll_over/v_rollover', $data);
        $this->load->view('v_footer');
    }
	
    public function print_page($page = NULL){		
        if($page == NULL) {
            die;				
        }
        else{
            //get page url to print
            $this->load->helper('my_url_helper');
            $total_url=$this->uri->total_segments();
            $url=$this->uri->segment_array();
            $data['page']=get_url_to_string($url,3,$total_url);
            //--------------------
            $this->load->view('v_header');					
            $this->load->view('v_printviewer',$data);
            $this->load->view('v_footer');	
        }

    }	
}