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

class Examination extends Admin_Core_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model', 'user');
        $this->load->model('examination_modal', 'examination');
    }


    public function assign_exam()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_course'] = $this->course->get_all_course();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/assign_exam');
        $this->load->view('admin/include/footer');
    }

    function add_new_assign_exam()
    {
        if ($this->examination->add_new_assign_exam()) 
        {
            $this->session->set_userdata('success', "Exam Successfully Assign");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', " Exam Assign Failed");
            redirect($this->agent->referrer());
        }
    }

    function add_new_assign_exam_exam()
    {
        if ($this->examination->add_new_assign_exam_exam()) 
        {
            $this->session->set_userdata('success', "Exam Successfully Assign");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', " Exam Assign Failed");
            redirect($this->agent->referrer());
        }
    }

    public function viva_and_practical()
    {
        $atp_id = user()->user_id;
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_student'] = $this->examination->get_all_assign_exam_students($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/viva_and_practical');
        $this->load->view('admin/include/footer');
    }

    public function add_viva_prc_marks($id)
    {
        if ($this->examination->add_viva_prc_marks($id)) 
        {
            $this->session->set_userdata('success', "Number Successfully Added");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', " Number Successfully Added Failed");
            redirect($this->agent->referrer());
        }
    }

    public function result()
    {
        $atp_id = user_id();
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_student'] = $this->examination->get_all_student_for_print_certificate_and_marksheet($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/result');
        $this->load->view('admin/include/footer');
    }

    public function print_certificate_and_marksheet()
    {
        $atp_id = user_id();
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_student'] = $this->examination->get_all_student_for_print_certificate_and_marksheet($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/print_certificate_and_marksheet');
        $this->load->view('admin/include/footer');
    }

    public function print_result($id, $course_id)
    {
        $this->load->helper('pdf_helper');

        $this->db->select('course_mode');
        $this->db->where('id', $course_id);
        $c_mode = $this->db->get('course')->row();
        $data['reg_id'] = $id;
        $data['course_id'] = $course_id;
        if($c_mode->course_mode == 3)
        {
            $html = $this->load->view('admin/exam/download_typing_result', $data, true);
        }
        else
        {
            $html = $this->load->view('admin/exam/download_online_result', $data, true);
        }
            // echo $html;

        generate_pdf($html, 'result');
        
    }

    public function print_marksheet($id, $course_id)
    {
        $this->db->select('course_mode');
        $this->db->where('id', $course_id);
        $c_mode = $this->db->get('course')->row();
        $data['reg_id'] = $id;
        $data['course_id'] = $course_id;
        if($c_mode->course_mode == 3)
        {
            $this->load->view('admin/exam/marksheetprint_for_typing', $data);
        }
        else
        {
            $this->load->view('admin/exam/marksheetprint', $data);
        }
        
    }

    public function print_certificate($id, $course_id)
    {
        $this->db->select('course_mode');
        $this->db->where('id', $course_id);
        $c_mode = $this->db->get('course')->row();
        $data['reg_id'] = $id;
        $data['course_id'] = $course_id;
        if($c_mode->course_mode == 3)
        {
            $this->load->view('admin/exam/certificateprint_for_typing', $data);
        }
        else
        {
            $this->load->view('admin/exam/certificateprint', $data);
        }
        
    }

    public function print_hall_ticket()
    {
        $atp_id = user_id();
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_student'] = $this->examination->get_all_student_for_hall_ticket_print($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/print_hall_ticket');
        $this->load->view('admin/include/footer');
    }

    public function extend()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_programm'] = $this->course->get_all_course_programm_by_atp_id();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/extend');
        $this->load->view('admin/include/footer');
    }

    public function re_exam()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_programm'] = $this->course->get_all_course_programm_by_atp_id();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/re_exam');
        $this->load->view('admin/include/footer');
    }

    function add_new_assign_re_exam()
    {
        if ($this->examination->add_new_assign_re_exam()) 
        {
            $this->session->set_userdata('success', "Exam Successfully Assign");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', " Exam Assign Failed");
            redirect($this->agent->referrer());
        }
    }

    public function view_question_paper()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_course'] = $this->course->get_all_course_for_admission_by_atp_id(user_id());
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/view_question_paper');
        $this->load->view('admin/include/footer');
    }

    public function set_question_paper()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_course'] = $this->course->get_all_course_for_admin_with_out_typing_course();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/set_question_paper');
        $this->load->view('admin/include/footer');
    }

    function add_question_paper()
    {
        if ($this->examination->add_question_paper()) 
        {
            $this->session->set_userdata('success', "Question Paper Successfully Added");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', " Question Paper Added Failed");
            redirect($this->agent->referrer());
        }
    }

    public function current_exam()
    {
        $atp_id = user_id();
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_student'] = $this->examination->get_all_student_for_current_exam($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/current_exam');
        $this->load->view('admin/include/footer');
    }

    public function view_question_bank()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_course'] = $this->course->get_all_course_for_question_bank();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/view_question_bank');
        $this->load->view('admin/include/footer');
    }

    public function download_hall_ticket($user_id, $course_id)
    {
        $this->load->helper('pdf_helper');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['student'] = $this->examination->get_student_for_hall_ticket_print_by_reg_id($user_id, $course_id);


        $html = $this->load->view('admin/exam/download_hall_ticket', $data, true);
        generate_pdf($html, 'hall_ticket_'.$data['student']->user_name);
    }

    function manual_exam()
    {
        
        $this->load->model('user_model');
        
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_atp'] = $this->user_model->get_all_atp_for_admin_for_manual_exam();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/exam/manual_exam');
        $this->load->view('admin/include/footer');
    }



}
