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

class Main extends CI_Controller {

	function __construct()
    {
        parent::__construct();
        error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));        
        $tastname = $this->uri->segment("1");
        
        if($tastname!="" && ($tastname!="checklogin" && $tastname!="admin"))
        {			
			if(!$this->session->userdata('operatorLoggedIn'))
			{
				redirect();
				exit;
			}
		}
		
		$this->lguserinfo = $this->session->userdata('operatorLoggedIn');
		$this->clientid = $this->lguserinfo["sessCLIENTID"];
		$this->company = $this->lguserinfo["sessCompanyname"];
		$this->outletid = $this->lguserinfo["sessOUTLETID"];
		$this->outletname = $this->lguserinfo["sessOTLName"];
		$this->userid = $this->lguserinfo["sessID"];
		
		$this->load->library('Ajax_pagination');
		$this->load->library("email");
		$this->perPage = 100;		
    }
    
    function index()
    {
		redirect("admin");
		exit;
	}

	function admin()
	{
		
		if($this->session->userdata('clinetLoggedIn'))
		{
			redirect('account/dashboard');
		}
		else
		{
			if($this->input->post("username")!="" && $this->input->post("userpass")!="") // login request
			{
				$this->load->model('account_model');
				if($this->account_model->checklogin()==true)
				{
					redirect('account/dashboard');
				}
				else
				{
					$this->session->set_flashdata("message", "Invalid username or password!");
					$this->session->set_flashdata("msgclass", "alert-danger");
					redirect(base_url().'admin');
					exit;
				}
			}
			else
			{
				
				$this->load->view('account/login');
			}
		}
	}

}
