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

class Attendance extends CI_Controller {

	
	public function __construct()
	{
		parent::__construct();
		$this->load->library('session');
		$this->load->helper(array('form', 'url'));
		$this->load->library('form_validation');
		$this->load->model('User_model');
		$this->user_model->check_login("Attendance");

	}


	public function index()
	{
		$data['title'] = "Attendance";	
		$data['userInfo'] = $this->User_model->userInfo("id,first_name,last_name");
		$data['main'] = "portalview/attendance/index_view";
	 	$this->load->view('portalview/includes/main', $data);
	}



	public function view_attendance()
	{
		
		$date = $this->input->post('date');

		$student_id = $this->User_model->userInfo()['student_id'];
			
		$query = $this->db->query("SELECT student.student_name,student.grno,student.roll_no,class.class_name,section.section_name,studentatt.date,studentatt.id,attendancestatus.status FROM `studentatt` inner join `student` on studentatt.student_id = student.id inner join `promotion` on promotion.student_id = student.id inner join `class` on promotion.class_id = class.class_id  inner join `section` on promotion.section_id = section.section_id inner join `attendancestatus` on attendancestatus.id = studentatt.status_id  WHERE studentatt.date like '%$date%' AND  student.id = '$student_id' AND is_deleted='0' ");
		
			$result = $query->result_array();
			

		if(empty($result) ){

			$this->session->set_flashdata('msg', 'No record found');
		 	redirect('Portal/Attendance/index');

		}else{
			
				$data['title'] = "View Attendance";	
		                $data['userInfo'] = $this->User_model->userInfo("id,first_name,last_name");
				$data['student_attendance'] = $result;
			 	$data['main'] = "portalview/attendance/attendance_view";
				$this->load->view('portalview/includes/main', $data);
		}


	}



}

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