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

class Result extends CI_Controller {

	

	public function __construct()
	{
		parent::__construct();
		$this->load->model("User_model");
	}



	public function result()
	{
	    
		$data['title'] = "Result";	
        
        //echo "hello";exit;
        $student_id = $this->User_model->userInfo('student_id');
        //echo "<pre>";print_r($user_img);exit;
	   
		$user_img=@$this->db->select('img,img1,img2,img3,img4')
	                              ->from('student')
	                              ->where('id',$student_id['student_id'])
	                              ->get()->row_array();
	   //echo "<pre>";print_r($user_img);exit;
	   $data['user_img']=$user_img;
		$data['userInfo'] =  $this->User_model->userInfo("first_name,last_name,username,student_id");
    	
        $data['class'] = $this->db->query("SELECT promotion.class_id,class.class_name FROM promotion INNER JOIN class on promotion.class_id = class.class_id WHERE student_id = '".$student_id['student_id']."'")->result_array();
       
        //echo "<pre>";print_r($class_id);exit;
        $data['main'] = "result/index_view";
	 	$this->load->view('includes/main', $data);
	}



	public function viewResult()
	{
	        $class=$this->input->post('class');
            $exam=$this->input->post('exam');
            
     	   // var_dump($class );die();

	  		$data['title'] = "View Result";
	  		
            $data['userInfo'] = $this->User_model->userInfo();
            $student_id = $this->User_model->userInfo()['student_id'];
            
            $user_img=@$this->db->select('img,img1,img2,img3,img4')
	                              ->from('student')
	                              ->where('id',$student_id)
	                              ->get()->row_array();
	        //echo "<pre>";print_r($user_img);exit;
		
	        $data['user_img']=$user_img;
	   
	  		$promotion_id = $this->db->query("SELECT promotion.id FROM `promotion` WHERE student_id = $student_id and class_id=$class")->row()->id;
         
	  		$result_id = @$this->db->query("SELECT result.id FROM `result` 
	  	WHERE promotion_id = $promotion_id AND exam_id = $exam")
	  	->row()->id;
	
   		  // var_dump($result_id);
         //die();
   		   $data['result_subject']=$this->db->query("SELECT subject.name as subject_name,result_subject.total_marks,result_subject.obtained_marks,result_subject.passing_marks,result_subject.paper_date from `result_subject` inner join `subject` on subject.id=result_subject.subject_id where result_subject.is_delete=0 AND result_subject.result_id='$result_id' AND subject.is_deleted='0'")->result_array();
            
            $data['result']=$this->db->query("SELECT student.img,student.id as stid,student.sid as p_no,section.section_name,class.class_name,student.grno,student.student_name,student.father_name,student.father_contact,exam.name as exam_name,exam.start,exam.end,result.total_marks,result.total_marks,result.obtained_marks,position,result.attendance,result.grade from `result` inner join `promotion` on result.promotion_id=promotion.id inner join `student` ON `student`.`id`=`promotion`.`student_id` inner join `class` on class.class_id=promotion.class_id inner join `section` on section.section_id=promotion.section_id inner join `exam` on `exam`.`id`=`result`.`exam_id` where student.status='0' AND result.id='$result_id' AND promotion.is_delete='0'")->row_array();

            $var_subject = $data['result_subject'];
        
            $var_result = $data['result']; 
		//	var_dump($var_result);die();
			if (empty($var_result) && empty($var_subject)) {
				
				$this->session->set_flashdata('msg', 'No Record Found');
		 		redirect('Result/result');

			}else{
 				$data['userInfo'] =  $this->User_model->userInfo("first_name,last_name,username");;
				$data['main'] = "result/result_view";
			
			 	$this->load->view('includes/main', $data);
			 
			}
	
	}



}

/* End of file Result.php */
/* Location: ./application/controllers/Result.php */