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

class Crud extends CI_Model{


  function insertData($data,$table){

    $query=$this->db->insert($table, $data);

    if ($query) {
     return true;
   }else return false;

 }

 function insertmultipleData($data,$table){

  $query=$this->db->insert_batch($table, $data);

  if ($query) {
   return true;
 }else return false;

}

function insertReturnData($data,$table){

  $query=$this->db->insert($table, $data);

  if ($query) {

    return $this->db->insert_id();

  }else return false;

}
function updatemultipleData($id,$data,$where,$table){

  $this->db->where_in($where,$id);
  $query=$this->db->update($table, $data);

  if ($query) {

    return true;
  }else return false;

}

	function deleteData($id, $where, $table)
	{

		$this->db->where($where, $id);
		$query = $this->db->delete($table);


		if ($query) {

			return true;
		} else return false;
	}

function deletemultipleData($id,$where,$table){

// Sub Query
  $this->db->select('submitted_user')->where_in('submitted_user',$id)->from('panel_form_master');
  $subQuery =  $this->db->get_compiled_select();

// Main Query
  $this->db->where_in('user_id',$id)
  ->where("user_id NOT IN ($subQuery)", NULL, FALSE);
  $this->db->delete('panel_users');
  $query=$this->db->affected_rows();

  if($query>0){

    return true;

  }else{

    return false;

  }


}

function dateDump_without_restrict($id,$where,$table){

  $this->db->where($where, $id);
  $query=$this->db->delete($table);


  if ($query) {

    return true;

  }else return false;


}

public function getIDProcessing($sha1,$col,$table) {
	$this->db->select("$col");
	$this->db->where('sha1('.$col.')',$sha1);
	$query = $this->db->get($table);
	return $query->row();
}

function updateData($id,$data,$where,$table){
  $this->db->where($where, $id);
  $query=$this->db->update($table, $data);
  if ($query) {
   return true;
 }else return false;
}

function updateDataAnother($id,$data,$where,$table){
  $this->db->where("sha1($where)", $id);
  $query=$this->db->update($table, $data);
  if ($query) {
    return true;
  }else return false;

}


function updateData_multiple_clause($id_one,$id_two,$data,$where_one,$where_two,$table){



  $this->db->where($where_one, $id_one);
  $this->db->where($where_two, $id_two);
  $query=$this->db->update($table, $data);

  if ($query) {

   return true;

 }
 else {
   return false;
 }




}





}
