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

class Userrights_m extends CI_Model {

    
public function userrights(){
//echo '<pre>';
//print_R($_POST);exit;
     
         
          foreach($_POST as $key => $rs){
              if($key != 'user') {
                        $data=array("Emp_Id"=>$_POST['user'],
                            "Form_Name"=>$key,
                            "Add_Form"=>$rs,
                            
                            "Inserted_SI"=>$this->session->userdata('id'),
                        "Inserted_BY"=>$this->session->userdata('name'),
                        "Inserted_DT"=>date('Y-m-d H:i:s'));
                    $c=$this->db->insert('userrights_tb',$data);
              }
              
          }
          
          
}
public function updateuserright($user){
//echo '<pre>';
//print_R($_POST);exit;
     
    $this->db->where('Deleted_DT IS NULL')->where('Emp_Id', $_POST['user'])->update('userrights_tb', array('Add_Form' => 0));     
          foreach($_POST as $key => $rs){
              if($key != 'user') {
                        $data=array("Emp_Id"=>$_POST['user'],
                            "Form_Name"=>$key,
                            "Add_Form"=>$rs,
                            
                            "Inserted_SI"=>$this->session->userdata('id'),
                        "Inserted_BY"=>$this->session->userdata('name'),
                        "Inserted_DT"=>date('Y-m-d H:i:s'));
                    $c=$this->db->insert('userrights_tb',$data);
              }
              
          }
    
    
    if(isset($_POST['LCLRow'])){
        foreach($_POST['LCLRow'] as $rskey => $rs)
        {
            $check_1 = isset($rs[1]) ? 1 : 0;
            $check_2 = isset($rs[2]) ? 2 : 0;
            $check_3 = isset($rs[3]) ? 3 : 0;
            $check_4 = isset($rs[4]) ? 4 : 0;
           	$data=array("Form_Name"=>$rs[0],
            			"Add_Form"=>$check_1,
            			"Update_Form"=>$check_2,
            			"View_Form"=>$check_3,
            			"Delete_Form"=>$check_4,
            			"Modified_SI"=>$this->session->userdata('empuniq'),
                        "Modified_BY"=>$this->session->userdata('name'),
                        "Modified_DT"=>date('Y-m-d H:i:s'));
            $c=$this->db->where('Userright_Id',$rs[5])->update('userrights_tb',$data);
            
            if(empty($rs[5])){
                $data=array("Emp_Id"=>$user,
                			"Form_Name"=>$rs[0],
                			"Add_Form"=>$check_1,
                			"Update_Form"=>$check_2,
                			"View_Form"=>$check_3,
                			"Delete_Form"=>$check_4,
                			"Inserted_SI"=>$this->session->userdata('empuniq'),
                            "Inserted_BY"=>$this->session->userdata('name'),
                            "Inserted_DT"=>date('Y-m-d H:i:s'));
                $c=$this->db->insert('userrights_tb',$data);
            }
            
        }

    }
}

    

}