<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Registration_Model extends CI_Model {


    
   


    public function update_organization_information($organization_id, $free_feature) {
        $this->db->set('feature_price_id', "$free_feature");
        $this->db->where('organization_id', $organization_id);
        $this->db->update('tbl_organization');
    }

    public function update_resource_person_information($data) {
        $payment_id = $data['payment_id'] . ',' . $data['payment_id'] . ',' . $data['payment_id'];
        $this->db->set('feature_price_payment_id', "$payment_id");
        $this->db->where('resource_person_id', $data['resource_person_id']);
        $this->db->update('tbl_resource_person');
    }




//    public function select_user_by_person_id($person_id) {
//        $this->db->select('*');
//        $this->db->from('tbl_person');
//        $this->db->where('person_id', $person_id);
//        $query_result = $this->db->get();
//        $result = $query_result->row();
//        return $result;
//    }

    /*public function check_captcha_word($give_text) {
        $captcha_time = date('H:i:s', $captcha_time);
        $sql = "SELECT * "
                . " FROM "
                . "     tbl_captcha"
                . " WHERE "
                . "         word = '$give_text' "
                . "     AND time = '$captcha_time'";
        $result = $this->db->query($sql)->row();
        return $result;
    }*/



    public function password_status_info($person_id) {
        $this->db->select('*');
        $this->db->from('tbl_person');
        $this->db->where('person_id', $person_id);
        $query_result = $this->db->get();
        $result = $query_result->row();
        return $result;
    }



    public function billing_payment_info($payment_id) {
        $this->db->select('*');
        $this->db->from('tbl_payment as py');
        $this->db->where('py.payment_id', $payment_id);
        $this->db->join('tbl_payment_details_information as pd', 'py.payment_id = pd.payment_id');
        $this->db->join('tbl_person as p', 'py.person_id = p.person_id');
//        $this->db->join('tbl_student as st', 'py.payment_id = st.payment_id');
//        $this->db->join('tbl_course as c', 'st.course_id = c.course_id');
        $query_result = $this->db->get();
        $result = $query_result->row();
        return $result;
    }

    public function request_invoice_by_payment_id($payment_id) {
        $this->db->set('payment_status', 5);
        $this->db->where('payment_id', $payment_id);
        $this->db->update('tbl_payment_details_information');
    }

    public function cancel_invoice_by_payment_id($payment_id) {
        $this->db->set('payment_status', 4);
        $this->db->where('payment_id', $payment_id);
        $this->db->update('tbl_payment_details_information');
    }

    /**
     * @Function            : select_video_course_student_information_by_student_id 
     * @Used IN             : @function-'view_video_course'      Welcome[@Controller],
     * @Description         : get all course registered student 
     * @Developed By        : MD Jaherul Islam
     * @Updated BY          : Md Mashqur Ul Alam [16-03-17 - Database field name changed]
     * @Start DateTime      : 13-04-2016 04:43 PM  
     * @Parameter           : $course_id[INTEGER], $type[INTEGER]
     * @Return              : all_studet_info        
     * @Status              : available      
     * */
    function select_all_course_registered_student($course_id, $type) {
        $sql = "SELECT group_concat(s.person_id) AS registered_student_id
                FROM 
                    tbl_student AS s
                WHERE 
                    s.student_type_id = '$course_id'
                    AND s.student_type = '$type'";
        return $this->db->query($sql)->row();
    }

    /**
     * @Function            : save_student_registration_info 
     * @Used IN             : @function-'enroll_course'     course[@Controller] - [412]
     * @Description         : save register student information
     * @Developed By        : MD Jaherul Islam
     * @Start DateTime      : 03-05-2016 10:08 AM  
     * @Parameter           : $course_id[INTEGER], $person_id[INTEGER], $course_type[INTEGER], $student_course_type[INTEGER]
     * @Return              : None    
     * @Status              : Available        
     * */
    function save_student_registration_info($course_id, $person_id, $course_type, $student_course_type) {
        $student_data = Array();
        $student_data['course_id'] = $course_id;
        $student_data['person_id'] = $person_id;
        $student_data['student_type'] = $course_type;
        $student_data['student_course_type'] = $student_course_type;
        $this->db->insert('tbl_student', $student_data);
        return $this->db->insert_id();
    }

  

}
