<?php 

class Exam_model extends CI_Model {
	
	public function _consruct(){
		parent::_construct();
 	}
 	function addExams($examData){

 		/*$check_exam_name = $this->db->get_where('tbl_exams',array('exam_procedure'=>$examData['exam_procedure']));
 		if($check_exam_name->num_rows() > 0){
 			return false;
 		}else{*/
 			$exam_procedure = ucfirst($examData['exam_procedure']);
 			$observation = ucfirst($examData['observation']);
 			
 			if($this->db->query("INSERT INTO `tbl_exams`(`exam_procedure`, `observation`) VALUES (AES_ENCRYPT('".$exam_procedure."','Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA'),AES_ENCRYPT('".$observation."','Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA'))")){
 				return true; 	
 			}
 			// if($this->db->insert('tbl_exams',array('exam_procedure'=>encrypt_data(ucfirst($examData['exam_procedure'])),'observation'=>encrypt_data(ucfirst($examData['observation']))))) {
 			// 	return true;
 			// }
 		//}
 	}
 	function get_all_exams(){
 		$this->db->select("CAST(AES_DECRYPT(`exam_procedure`,'Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA') as CHAR) as exam_procedure,id,CAST(AES_DECRYPT(`observation`,'Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA') as CHAR) as observation");
 		$all_exams = $this->db->get('tbl_exams');
 		if($all_exams->num_rows() > 0){
 			$result = $all_exams->result_array();
 			/*echo $this->db->last_query();exit();
 			print_r($result);exit();*/
 			return $result;
 		}
 	}
 	function delete_exams($id){
 		if($this->db->delete('tbl_exams',array('id'=>$id))){
 			return true;
 		}
 	}
 	function get_single_exam($id){
 		$this->db->select("CAST(AES_DECRYPT(`exam_procedure`,'Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA') as CHAR) as exam_procedure,id,CAST(AES_DECRYPT(`observation`,'Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA') as CHAR) as observation ");
 		$single_exams = $this->db->get_where('tbl_exams',array('id' => $id));
 		if($single_exams->num_rows() > 0){
 			return $single_exams->row_array();
 		}
 	}
 	function update_exam($data,$id){
 		/*$this->db->where('exam_procedure',$data['exam_procedure']);
 		$this->db->where('id !=',$id);
 		$res = $this->db->get('tbl_exams')->row();
 		if($res){
          return false;
 		}else{*/
 			$exam_procedure = ucfirst($data['exam_procedure']);
 			$observation = ucfirst($data['observation']);
 			if($this->db->query("update `tbl_exams` set `exam_procedure` = AES_ENCRYPT('".$exam_procedure."','Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA'),`observation` = AES_ENCRYPT('".$observation."','Ptf/PWNWrULQT72syxfaaBRTS9JbiKrj9dfuVEvT3rA') where id = $id ")) {
 				return true; 	
 			}
	 		/*if($this->db->update('tbl_exams',array('exam_procedure'=>encrypt_data(ucfirst($data['exam_procedure'])),'observation'=>encrypt_data(ucfirst($data['observation']))),array('id'=>$id))){
	 			return true;
	 		}*/
 		//}
 	}
 }