<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
error_reporting(1);

class login 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 http://codeigniter.com/user_guide/general/urls.html
     */
    public function __construct() {
        parent::__construct();
        $sec_res = session_id();
        $this->load->helper(array('url', 'form', 'date'));
        $this->load->library('form_validation');
        $this->load->library('session');
        $this->load->database();
        $this->load->model('jodoffer');
    }

    public function index($msg) {
        $data['msg'] = $msg;
        $this->load->view('login', $data);
    }

    function logincheck() {
        //echo'<pre>';print_r($_POST);exit;
        $user_name = $_POST['usrname'];
        $password = $_POST['pwd'];
        if ($user_name != NULL && $password != NULL) {
            $sql = "select * from  tbl_admin_login where usrname='$user_name' and  pwd='$password'";
//        echo $sql;exit;
            $res = mysql_query($sql) or die('dfsfd' . mysql_error());
            $row = mysql_fetch_array($res);

            $username1 = $row['usrname'];
            $password1 = $row['pwd'];
            $admin_email = $row['email'];

            if ($username1 == $user_name && $password1 == $password) {

                $admin = array(
                    'admin_username' => $username1,
                    'admin_email' => $admin_email,
                    'admin_session_set' => '1'
                );
                $this->session->set_userdata($admin);
                redirect('login/dashbord');
            } else {
                $msg = 'Invalid Login Name/Password.';
                $this->index($msg);
               // redirect('login/dashbord');
            }
        } else {
            $msg = 'Invalid Login Name/Password.';
            $this->index($msg);
        }
    }
    
    
      function dashbord(){
          $data['job_code']=$this->jodoffer->job_code();
        $this->load->view('dashbord',$data);
    }
    function download_excel(){
       //echo '<pre>';print_r($_POST);
        $job_id=$_POST['job_code'];
        
    // echo $job_id;
        //$data['download_excel']= $this->jodoffer->download_excel($job_id);
         $data['profile']=$this->jodoffer->download($job_id);
         $data['job_id']=  str_replace(' ','-',$job_id);
        $this->load->view('downloadexcel',$data);
    }
    function logout(){
         $this->session->unset_userdata('admin_session_set');
        $this->session->sess_destroy();
        redirect('login/index', 'refresh');
    }
  
}