<?php defined('BASEPATH') or exit('No direct script access allowed');?>
<?php
class Adminlte extends CI_Controller{
    protected $limit, $offset;
    public $perpage,$search;

    public function __construct(){
      parent::__construct();
		    $this->load->library(['form_validation','bcrypt','email','session','pagination']);
        $this->load->helper(['html','form','url','security','string']);
        //$this->load->model('CommonModel','common_model');
        $this->load->model('admin/course/Coursemodel','course_model');
        $this->load->model('admin/account/Accountmodel','account_model');
        $this->load->model('admin/AdminlteModel','adminlte_model');
        $this->load->model('admin/master/Facultymodel','faculty_model');
        if(!$this->session->userdata('ad_id') ){return redirect('Admin/signin');}
        if($this->session->userdata('ts_id') ){return redirect('teacher/signin');}
        if($this->session->userdata('ss_id') ){return redirect('student/signin');}
        $list_id					=		$this->session->userdata('ad_id');
        $this->admin_data	        =		$this->adminlte_model->user_profile($list_id);
        $this->load->model('admin/student_master/StudentpaymentsModel','studentpayments_model');
        //echo $this->session->userdata('ad_id');die;
        error_reporting(0);
        date_default_timezone_set('Asia/Kolkata');

    }
    public function profiler_index() {

        //enable profiler
        $this->output->enable_profiler(TRUE);
        $this->load->view('adminlte/panel/header2',['userdata'=>$this->admin_data,'title'=>'Home']);
       $this->load->view('adminlte/panel/sidebar');
       $this->load->view('adminlte/main_dashboard',['list'=>$list,'link'=>$links,'list1'=>$list1,'link1'=>$links1,
           'list2'=>$list2,'link2'=>$links2
       ]);
       $this->load->view('adminlte/panel/footer2');
     }

     public function profiler_disable() {

        //disable profiler
        $this->output->enable_profiler(FALSE);
       $this->load->view('adminlte/panel/header2',['userdata'=>$this->admin_data,'title'=>'Home']);
       $this->load->view('adminlte/panel/sidebar');
       $this->load->view('adminlte/main_dashboard',['list'=>$list,'link'=>$links,'list1'=>$list1,'link1'=>$links1,
           'list2'=>$list2,'link2'=>$links2
       ]);
       $this->load->view('adminlte/panel/footer2');
     }

    /* public function reg_user(){
        $this->load->library(['form_validation','bcrypt']);
        //$hash = $this->bcrypt->hash_password($password);

        $fname='narender';
        $lname='rathore';
        $email='narender.rathore@deconindia.com';
        $password='ratedr_123#';
        $hash = $this->bcrypt->hash_password($password);

        $data=array('first_name'=> strtolower($fname),'last_name'=>strtolower($lname),
            'email'=>strtolower($email),'password'=>$hash);

        $insert_id=$this->admin_model->add_user($data);

        $this->session->set_flashdata('message', "<i class='icon fa fa-check'></i>User Added Successfully");
        return redirect('admin/Adminlte');
    } */
    public function index(){
        $this->benchmark->mark('code_start');

// Some code happens here

        $config = [
            'base_url'					     =>	  site_url('admin/Adminlte/index'),
            'total_rows'				     =>		$this->course_model->course_list_num_rows(),
            'per_page'				       =>	  $perpage,
            'display_pages'			     =>	  TRUE,
            'use_page_numbers'	     =>   TRUE,
            'uri_segment'				     =>	4,
            'num_links'					     =>	10,
            'full_tag_open'			     =>	"<ul class='pagination pagination-sm no-margin'>",
            'full_tag_close'		     =>	"</ul>",
            'first_tag_open'		     =>	'<li>',
            'first_tag_close'		     =>	'</li>',
            'last_tag_open'			     =>	'<li>',
            'last_tag_close'		     =>	'</li>',
            'next_tag_open'			     =>	'<li>',
            'next_tag_close'		     =>	'</li>',
            'prev_tag_open'		       =>	'<li>',
            'prev_tag_close'		     =>	'</li>',
            'num_tag_open'		       =>	'<li>',
            'num_tag_close'			     =>	'</li>',
            'cur_tag_open'			     =>	'<li class="page-item active"><a class="page-link">',
            'cur_tag_close'			     =>	'</a></li>',
        ];
        $this->pagination->initialize($config);
        $page 	                         =    ($this->uri->segment(4)) ? $this->uri->segment(4) : 1;
        $list 		                     =     $this->course_model->course_list($config['per_page'],$page);
        $links		                     =	  $this->pagination->create_links();

        $config1 = [
            'base_url'					=>	site_url('admin/Adminlte/index'),
            'total_rows'				=>	$this->account_model->latest_payments_student_dashboard_numrows(),
            'per_page'					=>	$perpage,
            'display_pages'			    =>	TRUE,
            'use_page_numbers'	        => 	TRUE,
            'uri_segment'				=>	5,
            'num_links'					=>	10,
            'page_query_string'         => 	FALSE,
            'full_tag_open'			    =>	"<ul attendee='pagination pagination-sm'>",
            'full_tag_close'		    =>	"</ul>",
            'first_tag_open'		    =>	'<li>',
            'first_tag_close'		    =>	'</li>',
            'last_tag_open'			    =>	'<li>',
            'last_tag_close'		    =>	'</li>',
            'next_tag_open'			    =>	'<li>',
            'next_tag_close'		    =>	'</li>',
            'prev_tag_open'			    =>	'<li>',
            'prev_tag_close'		    =>	'</li>',
            'num_tag_open'			    =>	'<li>',
            'num_tag_close'			    =>	'</li>',
            'cur_tag_open'			    =>	'<li attendee="page-item active"><a attendee="page-link">',
            'cur_tag_close'			    =>	'</a></li>',
        ];
        $this->pagination->initialize($config1);
        $page 		=      ($this->uri->segment(5)) ? $this->uri->segment(5) : 1;
        $list1 		=      $this->account_model->latest_payments_student_dashboard_list($config1['per_page'],$page);
        $links1		=	   $this->pagination->create_links();



        $config2 = [
            'base_url'					=>	site_url('admin/Adminlte/index'),
            'total_rows'				=>	$this->course_model->course_class_num_rows_weekly(),
            'per_page'					=>	$perpage,
            'display_pages'			    =>	TRUE,
            'use_page_numbers'	        => 	TRUE,
            'uri_segment'				=>	5,
            'num_links'					=>	10,
            'page_query_string'         => 	FALSE,
            'full_tag_open'			    =>	"<ul class='pagination pagination-sm'>",
            'full_tag_close'		    =>	"</ul>",
            'first_tag_open'		    =>	'<li>',
            'first_tag_close'		    =>	'</li>',
            'last_tag_open'			    =>	'<li>',
            'last_tag_close'		    =>	'</li>',
            'next_tag_open'			    =>	'<li>',
            'next_tag_close'		    =>	'</li>',
            'prev_tag_open'			    =>	'<li>',
            'prev_tag_close'		    =>	'</li>',
            'num_tag_open'			    =>	'<li>',
            'num_tag_close'			    =>	'</li>',
            'cur_tag_open'			    =>	'<li class="page-item active"><a class="page-link">',
            'cur_tag_close'			    =>	'</a></li>',
        ];
        $this->pagination->initialize($config2);
        $page 		=   ($this->uri->segment(5)) ? $this->uri->segment(5) : 1;
        $list2 		=   $this->course_model->course_class_list_weekly($config2['per_page'],$page);
        $links2		=	$this->pagination->create_links();

        $this->attendee_list                       		  =   $this->adminlte_model->attendee_list();
        $this->presenter_list                             =   $this->adminlte_model->presenter_list();
        $total_create_classes_this_year                   =   $this->course_model->course_list_running();
        //echo "<pre>";print_r($total_create_classes_this_year);
        foreach($total_create_classes_this_year as $cls){
            $this->courses_tel[]                                =   strtoupper($cls->course_name);
            $this->total_course_classes_[]                      =   $this->course_model->total_course_classes_($cls->id);
            $this->total_course_classes_over_till[]             =   $this->course_model->total_course_classes_over_till($cls->id);
            $this->total_course_classes_remain_till[]           =   $this->course_model->total_course_classes_remain_till($cls->id);
            $this->total_course_classes_runn_till[]            =   $this->course_model->total_course_classes_runn_till($cls->id);
            $this->total_course_classes_cancel_till[]           =   $this->course_model->total_course_classes_cancel_till($cls->id);
        }

        $this->total_attendee                             =   $this->adminlte_model->attendee_list_num_rows();
        $this->attendee_confirm                           =   $this->adminlte_model->attendee_num_confirmed();
        $this->total_presenter                            =   $this->adminlte_model->presenter_list_num_rows();
        $this->presenter_confirm                          =   $this->adminlte_model->presenter_num_confirmed();
        $this->presenter_confirm_approve                  =   $this->adminlte_model->presenter_num_confirmed_approved();
        $this->total_course                               =   $this->adminlte_model->course_num_rows();
        $this->total_course_running                       =   $this->adminlte_model->course_num_rows_running();
        $this->total_course_completed                     =   $this->adminlte_model->course_num_rows_completed();
        $this->total_course_remaining                     =   $this->adminlte_model->course_num_rows_remaning();
        $this->total_classes                              =   $this->adminlte_model->classes_num_rows_();
        $this->total_classes_over                         =   $this->adminlte_model->classes_num_rows_over();
        $this->total_classes_remaining                    =   $this->adminlte_model->classes_num_rows_remaining();
        $this->total_classes_now                          =   $this->adminlte_model->classes_num_rows_running_today_now();
        $this->total_classes_today                        =   $this->adminlte_model->classes_num_rows_today();
        $this->total_classes_today_over                   =   $this->adminlte_model->classes_num_rows_today_over();
        $this->total_classes_today_remaining              =   $this->adminlte_model->classes_num_rows_today_remaining();
        $this->total_classes_week                         =   $this->adminlte_model->classes_num_rows_this_week();
        $this->total_classes_last_week                    =   $this->adminlte_model->classes_num_rows_last_week();
        $this->total_classes_next_week                    =   $this->adminlte_model->classes_num_rows_next_week();
        $this->totalclasses_month                         =   $this->adminlte_model->classes_num_rows_this_month();
        $this->totalclasses_last_month                    =   $this->adminlte_model->classes_num_rows_last_month();
        $this->total_classes_next_month                   =   $this->adminlte_model->classes_num_rows_next_month();
        $this->totalclasses_year                          =   $this->adminlte_model->classes_num_rows_this_year();
        $this->totalclasses_last_year                     =   $this->adminlte_model->classes_num_rows_last_year();
        $this->total_classes_next_year                    =   $this->adminlte_model->classes_num_rows_next_year();
        $this->total_cancel_classes_this_month            =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_month('cancel');
        $this->total_cancel_classes_this_year             =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_year('cancel');
        $this->total_modify_classes_this_month            =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_month('modify');
        $this->total_modify_classes_this_year             =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_year('modify');
        $this->total_create_classes_this_month            =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_month('create');
        $this->total_create_classes_this_year             =   $this->adminlte_model->classes_num_rows_cancel_modify_create_this_year('create');
        $report_today_class                               =   $this->adminlte_model->classes_today_report_upcomming_classes();

        $this->student_request_for_course                 =   $this->adminlte_model->student_request_for_course();
        $this->student_course_enrolled                    =   $this->adminlte_model->student_course_enrolled();



        $this->load->view('adminlte/panel/header2',['userdata'=>$this->admin_data,'title'=>'Home']);
        $this->load->view('adminlte/panel/sidebar');
        $this->load->view('adminlte/main_dashboard',['list'=>$list,'link'=>$links,'list1'=>$list1,'link1'=>$links1,
            'list2'=>$list2,'link2'=>$links2
        ]);
        $this->load->view('adminlte/panel/footer2');

    $this->benchmark->mark('code_end');

    //echo $this->benchmark->elapsed_time('code_start', 'code_end');
    //echo "<br>";
   // echo $this->benchmark->memory_usage();


    }

    public function course_chart_view($coursesid){
        $courses_tel                                =   strtoupper($coursesid);
        $total_course_classes_                      =   $this->course_model->total_course_classes_($coursesid);
        $total_course_classes_over_till             =   $this->course_model->total_course_classes_over_till($coursesid);
        $total_course_classes_remain_till           =   $this->course_model->total_course_classes_remain_till($coursesid);
        $total_course_classes_runn_till             =   $this->course_model->total_course_classes_runn_till($coursesid);

        //echo $courses_tel;
        $html	= "<h2>Chat History |     {$courses_tel} | {$total_course_classes_} | {$total_course_classes_over_till} | {$total_course_classes_remain_till} | {$total_course_classes_runn_till}</h2>
						<table id='example2' class='table table-bordered table-hover  table-responsive' style='font-family: sans-serif;font-size: 12px;'>
							<thead>
								<tr style='background-color: #428bca99 !important;color: #fff !important;'>
									<th>Query</th>
									<th>Query Date</th>
									<th>Admin Reply</th>
									<th>Reply date</th>
								</tr>
							</thead>
							<tbody style='height:50px;'>";

        $html	.= "		</tbody>
						</table>
					";
        echo $html;
    }
    public function download_excel_page(){

        header('Content-Type: application/force-download');
        header('Content-disposition: attachment; filename=report.xls'); // Fix for crappy IE bug in download.
        header("Pragma: ");
        header("Cache-Control: ");
        echo $_REQUEST['expo1'];

    }
    public function chart_report(){
       // $projectcode_list 									    = 	$this->taskpoinvoice_model->projectcode_list();
        $total_create_classes_this_year                   =   $this->adminlte_model->course_list_running();
        foreach($total_create_classes_this_year as $cls){
            $this->courses_tel[]                                      =   strtoupper($cls->course_id_tag);
            $this->total_course_classes_[]                      =   $this->adminlte_model->course_class_num_rows($cls->id);
            $this->total_course_classes_over_till[]             =   $this->adminlte_model->classes_num_rows_over_course($cls->id);
            $this->total_course_classes_remain_till[]           =   $this->adminlte_model->classes_num_rows_remaining_course($cls->id);
            $this->total_course_classes_runn_till[]             =   $this->adminlte_model->classes_num_rows_running_today_now_course($cls->id);

        }
        $this->load->view('adminlte/chart_report', []);
    }

    public function timeline_view(){
       // $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Home']);
        //$this->load->view('adminlte/panel/sidebar');
        $this->load->view('adminlte/timeline_view');
        //$this->load->view('adminlte/panel/footer');

    }

    public function profile_view(){
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Home']);
        $this->load->view('adminlte/panel/sidebar');
        $this->load->view('adminlte/profile');
        $this->load->view('adminlte/panel/footer');

    }
    public function logout(){
        $this->session->unset_userdata('ad_id');
        $this->session->sess_destroy();
        return redirect(site_url());
    }
    public function upload_profile(){
        $id             =  $this->session->userdata('ad_id');
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Home']);
        $this->load->view('adminlte/panel/sidebar');
        $data          =  array();
        if($this->input->post('fileSubmit') && !empty($_FILES['userFiles']['name'])){
            $filesCount = count($_FILES['userFiles']['name']);
            //echo $_FILES['userFiles']['name'];echo $filesCount;die;
            for($i = 0; $i < $filesCount; $i++){
                $_FILES['userFile']['name'] 	   = 	$_FILES['userFiles']['name'][$i];
                $_FILES['userFile']['type'] 	   = 	$_FILES['userFiles']['type'][$i];
                $_FILES['userFile']['tmp_name']    = 	$_FILES['userFiles']['tmp_name'][$i];
                $_FILES['userFile']['error'] 	   = 	$_FILES['userFiles']['error'][$i];
                $_FILES['userFile']['size'] 	   = 	$_FILES['userFiles']['size'][$i];
                $uploadPath 					   = 	"./uploads/admin/images/$id/profile/";
                if(!is_dir($uploadPath )){mkdir($uploadPath, 0777, TRUE );}
                $config['upload_path'] 			   = 	$uploadPath;
                $config['allowed_types'] 		   = 	'jpg|png|gif|jpeg|JPG|PNG|GIF';
                $config['overwrite'] 			   = 	'1';
                //$config['max_size']	           =    '100';
                //$config['max_width']             =    '1024';
                //$config['max_height']            =    '768';
                $this->load->library('upload', $config);
                $this->upload->initialize($config);
                if($this->upload->do_upload('userFile')){
                    $fileData = $this->upload->data();
                    $config1['image_library']      =   'gd2';
                    $config1['source_image']       =   $fileData['full_path'];
                    $config1['create_thumb']       =   TRUE;
                    $config1['maintain_ratio']     =   TRUE;
                    $config1['width']              =   62;
                    $config1['height']             =   58;
                    $this->load->library('image_lib', $config1);
                    if (!$this->image_lib->resize()) {
                        $this->handle_error($this->image_lib->display_errors());
                    }
                    $this->adminlte_model->update_profile_pic($id,$config['upload_path'].$fileData['file_name']);
                    //  print_r($fileData);die;
                    //  $this->student_model->update_profile_pic($id,$path);
                }
            }
            $this->session->set_flashdata('success', 'Profile Added Succesfully');
            return redirect("admin/adminlte");
        }
        else{
            $data['error'] = "Error occured";
            $this->load->view('adminlte/upload_profile', $data);
        }
        // $this->load->view('student/upload_profile', $data);
        $this->load->view('adminlte/panel/footer');
    }

    public function get_class_subject_course_(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject_course_($postData);
      //  $data = array('1'=>'1','2'=>'2');
        echo json_encode($data);
    }

    public function get_category_class(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_category_class($postData);
        echo json_encode($data);
    }
    public function get_class_subject(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject($postData);
        echo json_encode($data);
    }
    public function get_subject_chapter(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_subject_chapter($postData);
        echo json_encode($data);
    }
    public function get_chapter_topic(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_chapter_topic($postData);
        echo json_encode($data);
    }
    public function get_class_subject_faculty(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject_faculty($postData);
        echo json_encode($data);
    }
    public function get_class_subject_course_maded_list(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject_course_maded_list($postData);
        echo json_encode($data);
    }
    public function get_class_subject_course_classid_list(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject_course_classid_list($postData);
        echo json_encode($data);
    }
    public function get_class_subject_course_maded_info(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_subject_course_maded_info($postData);
        echo json_encode($data);
    }
    public function get_class_amount_info(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_amount_info($postData);
        echo json_encode($data);
    }
    public function get_class_amount_info_after_over_class(){
        $postData   =   $this->input->post();
        $data       =   $this->adminlte_model->get_class_amount_info_after_over_class($postData);
        echo json_encode($data);
    }

    public function course_create_teacher1(){
        $this->load->view('adminlte/course/material_date_time_picker');
    }

    public function contactVerify($contact, $otherField) {
        return ($contact != '' || $this->input->post($otherField) != '');
    }
    public function course_list(){

        $this->form_validation->set_rules('perpage_search', 'ALL', 'required');
        if($this->input->post('perpage')==""){$perpage=50;}		else{$perpage		=	$this->input->post('perpage');}
        $config = [
            'base_url'					 =>	site_url('admin/Adminlte/course_list'),
            'total_rows'				 =>	$this->adminlte_model->course_num_rows(),
            'per_page'				     =>	$perpage,
            'display_pages'			     =>	TRUE,
            'use_page_numbers'	         => TRUE,
            'uri_segment'				 =>	4,
            'num_links'					 =>	10,
            'full_tag_open'			     =>	"<ul class='pagination pagination-sm no-margin'>",
            'full_tag_close'		     =>	"</ul>",
            'first_tag_open'		     =>	'<li>',
            'first_tag_close'		     =>	'</li>',
            'last_tag_open'			     =>	'<li>',
            'last_tag_close'		     =>	'</li>',
            'next_tag_open'			     =>	'<li>',
            'next_tag_close'		     =>	'</li>',
            'prev_tag_open'		         =>	'<li>',
            'prev_tag_close'		     =>	'</li>',
            'num_tag_open'		         =>	'<li>',
            'num_tag_close'			     =>	'</li>',
            'cur_tag_open'			     =>	'<li class="page-item active"><a class="page-link">',
            'cur_tag_close'			     =>	'</a></li>',
        ];
        $this->pagination->initialize($config);
        $page 	           =    ($this->uri->segment(4)) ? $this->uri->segment(4) : 1;
        $list 		       =    $this->adminlte_model->course_list($config['per_page'],$page,$search);
        $links		       =	$this->pagination->create_links();
        $course_count	   =    $this->adminlte_model->course_num_rows();
		$category          =      $this->adminlte_model->getcategory();
		$subject_code      =      $this->adminlte_model->subject_code_lists();

       // echo "pre"; print_r($course_id_tag);

        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'courseList','list'=>$list,
            'link'=>$links,'course_count'=>$course_count,'course_id_list'=>$course_id_list]);
        $this->load->view('adminlte/panel/sidebar');
        $this->load->view('adminlte/course/course',['subject_code'=>$subject_code,'category'=>$category]);
        $this->load->view('adminlte/panel/footer');
    }
    public function course_class_list($courseid){

        $this->form_validation->set_rules('perpage_search', 'ALL', 'required');
        if($this->input->post('perpage')==""){$perpage=10;}		else{$perpage		=	$this->input->post('perpage');}
        $config = [
            'base_url'					 =>	site_url("admin/Adminlte/course_class_list/{$courseid}"),
            'total_rows'				 =>	$this->adminlte_model->course_class_num_rows($courseid),
            'per_page'				     =>	$perpage,
            'display_pages'			     =>	TRUE,
            'use_page_numbers'	         => TRUE,
            'uri_segment'				 =>	5,
            'num_links'					 =>	10,
            'full_tag_open'			     =>	"<ul class='pagination pagination-sm no-margin'>",
            'full_tag_close'		     =>	"</ul>",
            'first_tag_open'		     =>	'<li>',
            'first_tag_close'		     =>	'</li>',
            'last_tag_open'			     =>	'<li>',
            'last_tag_close'		     =>	'</li>',
            'next_tag_open'			     =>	'<li>',
            'next_tag_close'		     =>	'</li>',
            'prev_tag_open'		         =>	'<li>',
            'prev_tag_close'		     =>	'</li>',
            'num_tag_open'		         =>	'<li>',
            'num_tag_close'			     =>	'</li>',
            'cur_tag_open'			     =>	'<li class="page-item active"><a class="page-link">',
            'cur_tag_close'			     =>	'</a></li>',
        ];
        $this->pagination->initialize($config);
        $page 	                         =    ($this->uri->segment(5)) ? $this->uri->segment(5) : 1;
        $list 		                     =    $this->adminlte_model->course_class_list($config['per_page'],$page,$courseid);
        $links		                     =	  $this->pagination->create_links();
        $class_count	                 =    $this->adminlte_model->course_class_num_rows($courseid);
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Course Class List','list'=>$list,
            'link'=>$links,'class_count'=>$class_count]);
        $this->load->view('adminlte/panel/sidebar');
        $this->load->view('adminlte/course/course_class_list');
        $this->load->view('adminlte/panel/footer');
    }
    public function add_more_class_to_course($course_id){
       // print_r($_POST);die;
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Add More Classes to Course','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');

        $this->form_validation->set_message('contactVerify', 'Either Week Days or Custom Date is required');
        $this->form_validation->set_rules('course_duration'     , 'Course Duration'			, 'required|xss_clean|trim');
        $this->form_validation->set_rules('week_days[]'		    , 'Week Days'		        , 'callback_contactVerify[custom_date]|xss_clean|trim');
        $this->form_validation->set_rules('custom_date'		    , 'Custom Date'		        , 'callback_contactVerify[week_days[]]|xss_clean|trim');
        $this->form_validation->set_rules('class_start_time'	, 'Start Time'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_duration'	    , 'Class Duration'		    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('extend_duration'	    , 'Extend Duration'		    , 'xss_clean|trim');
        $this->form_validation->set_rules('faculty'		        , 'Faculty'                 , 'required|xss_clean|trim');
        $this->form_validation->set_rules('per_class_amount'	, 'CLass Basic Amount'		, 'required|xss_clean|trim');
        $class                                  =       $this->adminlte_model->getclass();
        $category                               =       $this->adminlte_model->getcategory();
        $list                                   =       $this->adminlte_model->course_view($course_id);
        $faculty                                =       $this->adminlte_model->faculty_list_course($list->category_id,$list->class_id,$list->subject_id);
        //$course_duration = array('1' =>'1 day', );//echo "<pre>";print_r($subject_with_class);die;
        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/add_more_classes_to_course',['faculty'=>$faculty,'category'=>$category,'lists'=>$list]);
        }
        else{
            $dt 							     = 	    new DateTime();
            $faculty				             =		strtolower($this->input->post('faculty'));
            $course_duration				     =		strtolower($this->input->post('course_duration'));
            $class_start_time					 =		date("H:i", strtotime($this->input->post('class_start_time')));
            $class_duration						 =		strtolower($this->input->post('class_duration'));
            $extend_duration					 =		strtolower($this->input->post('extend_duration'));
            $per_class_amount				     =		strtolower($this->input->post('per_class_amount'));
            $custom_date					     =		strtolower($this->input->post('custom_date'));
            $week_days							 =      implode(',',$_POST['week_days']);
            $custom_date_ls					     =		explode(',',$custom_date);
            $week_day_ls				         =	    $_POST['week_days'];

            $course_duration1                    =      explode('-',$course_duration);
            $course_from                         =      $course_duration1[0];
            $course_to                           =      $course_duration1[1];
            $time1 		                         =      strtotime($class_start_time);
            $endTime 	                         =      date("H:i", strtotime("+$class_duration minutes", $time1));

            $class_strength                      =      "09";

            $faculty_name                        =       $this->faculty_model->view_faculty($faculty);

            $data_course_extended				 =	    array(
                'main_course_id'=>$course_id,
                'ex_course_duration'=>$course_duration,
                'ex_course_start_date'=>date("Y-m-d",strtotime(strtolower($course_from))),
                'ex_course_end_date'=>date("Y-m-d",strtotime(strtolower($course_to))),
                'ex_class_start_time'=>$class_start_time,'ex_class_end_time'=>$endTime,
                'ex_class_duration_min'=>$class_duration,'ex_class_extend_time_min'=>$extend_duration,'ex_faculty_code'=>$faculty,
                'ex_per_class_amount'=>$per_class_amount,'ex_course_custom_date'=>$custom_date,
                'ex_course_week_days'=>$week_days,'ex_time_zone'=>"Asia/Kolkata"
            );
            $insert_id							 =	$this->adminlte_model->insert_v2_course_new_furthur_extended($data_course_extended);
            $this->adminlte_model->update_v2_course_new_field_value('course_furthur_extended','1',$course_id);

            if($insert_id){
                $course_from_time 			     = 	     date("m/d/Y", strtotime(strtolower($course_from)));
                $course_to_time 			     = 	     date("m/d/Y", strtotime(strtolower($course_to)));
                require_once APPPATH. '/plugins/wiziq/classCode/create.php';
                $schedule 					     =		new ScheduleClass();
                //$access_key					     =		"8/yu9bdKqQ0=";
				//$secretAcessKey				     =		"NH/c54MO0doFL6FK2k3Wsw==";
				$secretAcessKey				=	"yOEQY4Y6HJG2Swp2CZ+q2A==";
				$access_key					=	"7DpOH0SG9m8=";
                $webServiceUrl 				     =		"http://classapi.wiziqxt.com/apimanager.ashx";
                //date_default_timezone_set('UTC');
                date_default_timezone_set('Asia/Kolkata');
                $date                            =      $course_from_time;
                $end_date                        =      $course_to_time;
                $no_class_count                  =      "0";

                while (strtotime($date) <= strtotime($end_date)) {
                    if((empty($custom_date))&&(!empty($week_day_ls))){
                        $weeK_day_exist =    date('l',strtotime($date));
                        if(in_array($weeK_day_exist, $week_day_ls)){
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            $schedule->start_time 						=		$time;
                            $subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                                $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                                $schedule->duration 						=		$class_duration;
                                $schedule->time_zone 						=		"Asia/Kolkata";
                                $schedule->attendee_limit 				    =	    $class_strength;
                                $schedule->create_recording 			    =		'true';
                                $schedule->return_url 						=		site_url('lobby');
                                if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                                $schedule->status_ping_url 				    =		site_url('class-status');
                                $schedule->language_culture_name 	        =		"en-us";
                                $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);

                                if(empty($response['errorcode'])){
                                    $method			    =	$response['method'];
                                    $class_id			=	$response['class_id'];
                                    $recording_url		=	$response['recording_url'];
                                    $presenter_email	=	$response['presenter_email'];
                                    $presenter_url		=	$response['presenter_url'];

                                    $class_date         =   date("Y-m-d", strtotime($date));
                                    $data_class_info   =   array('course_id'=>$course_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                        "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$list->category_id,'class_id'=>$list->class_id,
                                        'subject_id'=>$list->subject_id,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                        'class_start_time'=>$class_start_time,
                                        'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,'class_extend_time_min'=>$extend_duration,
                                        'time_zone'=>"Asia/Kolkata",'part_of_course_extended'=>'1');
                                    $class_infoid      =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                    $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                        "presenter_url"=>   $presenter_url);
                                    $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);

                                    unset($class_date);

                                }else{
                                    $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                                    $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                    return redirect("admin/adminlte/course_list");
                                }
                                $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                        }
                    }
                    if((!empty($custom_date))&&(empty($week_day_ls))){
                        if(in_array($date, $custom_date_ls)){
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            $schedule->start_time 						=		$time;
                            $subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                                $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                                $schedule->duration 						=		$class_duration;
                                $schedule->time_zone 						=		"Asia/Kolkata";
                                $schedule->attendee_limit 				    =	    $class_strength;
                                $schedule->create_recording 			    =		'true';
                                $schedule->return_url 						=		site_url('lobby');
                                if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                                $schedule->status_ping_url 				    =		site_url('class-status');
                                $schedule->language_culture_name 	        =		"en-us";
                                $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);

                                if(empty($response['errorcode'])){
                                    $method			    =	$response['method'];
                                    $class_id			=	$response['class_id'];
                                    $recording_url		=	$response['recording_url'];
                                    $presenter_email	=	$response['presenter_email'];
                                    $presenter_url		=	$response['presenter_url'];

                                    $class_date         =   date("Y-m-d", strtotime($date));
                                    $data_class_info   =   array('course_id'=>$course_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                        "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$list->category_id,'class_id'=>$list->class_id,
                                        'subject_id'=>$list->subject_id,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                        'class_start_time'=>$class_start_time,
                                        'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,'class_extend_time_min'=>$extend_duration,
                                        'time_zone'=>"Asia/Kolkata",'part_of_course_extended'=>'1');
                                    $class_infoid      =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                    $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                        "presenter_url"=>   $presenter_url);
                                    $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);

                                    unset($class_date);

                                }else{
                                    $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                                    $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                    return redirect("admin/adminlte/course_list");
                                }
                                $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                        }
                    }
                    if((!empty($custom_date))&&(!empty($week_day_ls))){
                        $weeK_day_exist =    date('l',strtotime($date));
                        if((in_array($weeK_day_exist, $week_day_ls))&& (in_array($date, $custom_date_ls))){
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            $schedule->start_time 						=		$time;
                            $subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                                $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                                $schedule->duration 						=		$class_duration;
                                $schedule->time_zone 						=		"Asia/Kolkata";
                                $schedule->attendee_limit 				    =	    $class_strength;
                                $schedule->create_recording 			    =		'true';
                                $schedule->return_url 						=		site_url('lobby');
                                if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                                $schedule->status_ping_url 				    =		site_url('class-status');
                                $schedule->language_culture_name 	        =		"en-us";
                                $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);

                                if(empty($response['errorcode'])){
                                    $method			    =	$response['method'];
                                    $class_id			=	$response['class_id'];
                                    $recording_url		=	$response['recording_url'];
                                    $presenter_email	=	$response['presenter_email'];
                                    $presenter_url		=	$response['presenter_url'];

                                    $class_date         =   date("Y-m-d", strtotime($date));
                                    $data_class_info   =   array('course_id'=>$course_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                        "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$list->category_id,'class_id'=>$list->class_id,
                                        'subject_id'=>$list->subject_id,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                        'class_start_time'=>$class_start_time,
                                        'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,'class_extend_time_min'=>$extend_duration,
                                        'time_zone'=>"Asia/Kolkata",'part_of_course_extended'=>'1');
                                    $class_infoid      =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                    $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                        "presenter_url"=>   $presenter_url);
                                    $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);

                                    unset($class_date);

                                }else{
                                    $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                                    $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                    return redirect("admin/adminlte/course_list");
                                }
                                $this->adminlte_model->update_v2_course_new_furthur_extended_field_value('ex_class_count',$no_class_count,$course_id);
                        }
                    }
                    $date               =    date ("m/d/Y", strtotime("+1 day", strtotime($date)));
                    $no_class_count     =    $no_class_count+1;
                }//end while
                $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>course Extended Successfully");
                return redirect("admin/adminlte/course_list");
            }
            $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>course Extended  Successfully");
            return redirect("admin/adminlte/course_list");
        }
        $this->load->view('adminlte/panel/footer');
    }

    public function view_schedule(){
      //http://classapi.wiziqxt.com/?method=view_schedule
    }
    public function course_create(){

        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Add Activity','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');

        $this->form_validation->set_message('contactVerify', 'Either Week Days or Custom Date is required');
        //$this->form_validation->set_rules('phone', 'Phone', 'trim|callback_contactVerify[email]|xss_clean');
        //$this->form_validation->set_rules('email', 'Email', 'trim|callback_contactVerify[phone]|valid_email|xss_clean');
        $this->form_validation->set_rules('category'			, 'Category'				, 'required|xss_clean|trim');
        $this->form_validation->set_rules('class'			    , 'Class'				    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('subject'			    , 'Subject'				    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('faculty'		        , 'Faculty'                 , 'required|xss_clean|trim');
        $this->form_validation->set_rules('week_days[]'		    , 'Week Days'		        , 'callback_contactVerify[custom_date]|xss_clean|trim');
        $this->form_validation->set_rules('custom_date'		    , 'Custom Date'		        , 'callback_contactVerify[week_days[]]|xss_clean|trim');
        $this->form_validation->set_rules('course_duration'     , 'Course Duration'			, 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_start_time'	, 'Start Time'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_duration'	    , 'Class Duration'		    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('extend_duration'	    , 'Extend Duration'		    , 'xss_clean|trim');
        $this->form_validation->set_rules('per_class_amount'	, 'CLass Basic Amount'		, 'required|xss_clean|trim');
        $this->form_validation->set_rules('per_class_earning'	, 'Teacher Earning Per Class'		, 'required|xss_clean|trim');

        $class                                  =       $this->adminlte_model->getclass();
        $category                               =       $this->adminlte_model->getcategory();
        //$course_duration = array('1' =>'1 day', );//echo "<pre>";print_r($subject_with_class);die;
        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/add_course',['class'=>$class,'category'=>$category]);
        }
        else{
            //echo "<pre>";print_r($_POST);die;
            $dt 							     = 	    new DateTime();
            $category						     =		strtolower($this->input->post('category'));
            $class						         =		strtolower($this->input->post('class'));
            $subject							 =		strtolower($this->input->post('subject'));
            $faculty				             =		strtolower($this->input->post('faculty'));
            $course_duration				     =		strtolower($this->input->post('course_duration'));
            $class_start_time					 =		date("H:i", strtotime($this->input->post('class_start_time')));
            $class_duration						 =		strtolower($this->input->post('class_duration'));
            $extend_duration					 =		strtolower($this->input->post('extend_duration'));
            $per_class_amount				     =		strtolower($this->input->post('per_class_amount'));
            $custom_date					     =		strtolower($this->input->post('custom_date'));
            $per_class_earning_teacher		     =		strtolower($this->input->post('per_class_earning'));
            $week_days							 =      implode(',',$_POST['week_days']);
            $custom_date_ls					     =		explode(',',$custom_date);
            $week_day_ls				         =	    $_POST['week_days'];

            $course_duration1                    =      explode('-',$course_duration);
            $course_from                         =      $course_duration1[0];
            $course_to                           =      $course_duration1[1];
            $time1 		                         =      strtotime($class_start_time);
            $endTime 	                         =      date("H:i", strtotime("+$class_duration minutes", $time1));

            $class_strength                      =     "09";

            $faculty_name                        =       $this->faculty_model->view_faculty($faculty);

            $data_course						 =	    array(
                'course_duration'=>$course_duration,
                'course_start_date'=>date("Y-m-d",strtotime(strtolower($course_from))),
                'course_end_date'=>date("Y-m-d",strtotime(strtolower($course_to))),'category_id'=>$category,'class_id'=>$class,
                'subject_id'=>$subject,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                'class_start_time'=>$class_start_time,'class_end_time'=>$endTime,
                'class_duration_min'=>$class_duration,'class_extend_time_min'=>$extend_duration,'faculty_code'=>$faculty,
                'per_class_amount'=>$per_class_amount,'course_custom_date'=>$custom_date,'course_week_days'=>$week_days,'time_zone'=>"Asia/Kolkata"
            );
            $insert_id							 =	$this->adminlte_model->insert_v2_course_new($data_course);

            if($insert_id){
                $tag     =  strtolower($faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code.
                date("M",strtotime(strtolower($course_from))).date("d",strtotime(strtolower($course_from))).
                date("y",strtotime(strtolower($course_from))).$insert_id);
                //#course_id
                $this->adminlte_model->update_v2_course_new_coursetag($tag,$insert_id);

                $course_from_time 			     = 	     date("m/d/Y", strtotime(strtolower($course_from)));
                $course_to_time 			     = 	     date("m/d/Y", strtotime(strtolower($course_to)));
                require_once APPPATH.'/plugins/wiziq/classCode/create.php';

                //$myfile = fopen(APPPATH.'/plugins/wiziq/classCode/create.php', "r") or die("Unable to open file!");
               // echo fread($myfile,filesize(APPPATH.'/plugins/wiziq/classCode/create.php'));
                //fclose($myfile);
               // echo APPPATH.'/plugins/wiziq/classCode/create.php';die;
                $schedule 					     =		new ScheduleClass();
                $secretAcessKey					 =		"yOEQY4Y6HJG2Swp2CZ+q2A==";
				$access_key						 =		"7DpOH0SG9m8=";
                $webServiceUrl 				     =		"http://classapi.wiziqxt.com/apimanager.ashx";
                //date_default_timezone_set('UTC');
                date_default_timezone_set('Asia/Kolkata');
                $date                            =      $course_from_time;
                $end_date                        =      $course_to_time;
                $no_class_count                  =      "0";

                while (strtotime($date) <= strtotime($end_date)) {
                    //echo "$date\n";//('l', strtotime($date)); // echo  ('l', strtotime($date));//date('D', strtotime($x));
                    if((empty($custom_date))&&(!empty($week_day_ls))){
                        $weeK_day_exist =    date('l',strtotime($date));
                        if(in_array($weeK_day_exist, $week_day_ls)){
                            //echo $date ." - ". date('l',strtotime($date))."<br>";
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            //$time 									=		date("m/d/Y H:i", strtotime(strtolower($_POST['start_time'])));
                            $schedule->start_time 						=		$time;
                            $subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                                $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                            $schedule->duration 						=		$class_duration;
                            $schedule->time_zone 						=		"Asia/Kolkata";
                            $schedule->attendee_limit 				    =	    $class_strength;
                            //$schedule->control_category_id 		    =		"";
                            $schedule->create_recording 			    =		'true';
                            $schedule->return_url 						=		"https://theonlinegurukul.com/lobby";//site_url('lobby');
                            if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                            $schedule->status_ping_url 				    =		"https://theonlinegurukul.com/class-status";//site_url('class-status');
                            $schedule->language_culture_name 	        =		"en-us";
                            //echo "<pre>";print_r($schedule);die;
                            $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);
                            //echo "<pre>";print_r($response);die;//$file = 'log.txt';//$message = serialize($response)."\r\n";
                            //file_put_contents($file, $message, FILE_APPEND);//echo "<pre>";print_r($response);die;//$response['errormsg']
                            if(empty($response['errorcode'])){
                                $method			    =	$response['method'];
                                $class_id			=	$response['class_id'];
                                $recording_url		=	$response['recording_url'];
                                $presenter_email	=	$response['presenter_email'];
                                $presenter_url		=	$response['presenter_url'];

                                $class_date         =   date("Y-m-d", strtotime($date));
                                $data_class_info   =   array('course_id'=>$insert_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                    "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$category,'class_id'=>$class,
                                    'subject_id'=>$subject,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                    'class_start_time'=>$class_start_time,
                                    'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,'class_extend_time_min'=>$extend_duration,
                                    'time_zone'=>"Asia/Kolkata");
                                $class_infoid      =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                    "presenter_url"=>   $presenter_url,'per_class_earning'=>$per_class_earning_teacher);
                                $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);

                                unset($class_date);

                            }else{
                                $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                                $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                return redirect("admin/adminlte/course_list");
                            }
                            $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                        }
                    }
                    if((!empty($custom_date))&&(empty($week_day_ls))){
                        if(in_array($date, $custom_date_ls)){
                            //echo $date ." - ". date('l',strtotime($date))."<br>";
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            //$time 									=		date("m/d/Y H:i", strtotime(strtolower($_POST['start_time'])));
                            $schedule->start_time 						=		$time;
                            //$subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                            $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                            $schedule->duration 						=		$class_duration;
                            $schedule->time_zone 						=		"Asia/Kolkata";
                            $schedule->attendee_limit 				    =	    $class_strength;
                            //$schedule->control_category_id 		        =		"";
                            $schedule->create_recording 			    =		'true';
                            $schedule->return_url 						=		"https://theonlinegurukul.com/lobby";//site_url('lobby');
                            if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                            $schedule->status_ping_url 				    =		"https://theonlinegurukul.com/class-status";//site_url('class-status');
                            $schedule->language_culture_name 	        =		"en-us";
                            //echo "<pre>";print_r($schedule);die;
                            $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);
                            //echo "<pre>";print_r($response);die;//$file = 'log.txt';//$message = serialize($response)."\r\n";
                            //file_put_contents($file, $message, FILE_APPEND);//echo "<pre>";print_r($response);die;//$response['errormsg']
                            if(empty($response['errorcode'])){
                                $method			    =	$response['method'];
                                $class_id			=	$response['class_id'];
                                $recording_url		=	$response['recording_url'];
                                $presenter_email	=	$response['presenter_email'];
                                $presenter_url		=	$response['presenter_url'];

                                $class_date         =   date("Y-m-d", strtotime($date));
                                $data_class_info   =   array('course_id'=>$insert_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                    "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$category,'class_id'=>$class,
                                    'subject_id'=>$subject,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                    'class_start_time'=>$class_start_time,'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,
                                    'class_extend_time_min'=>$extend_duration,'time_zone'=>"Asia/Kolkata");
                                $class_infoid       =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                    "presenter_url"=>   $presenter_url,'per_class_earning'=>$per_class_earning_teacher);
                                $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);
                                unset($class_date);

                            }else{
                                $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                                $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                return redirect("admin/adminlte/course_list");
                            }
                            $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                        }
                    }
                    if((!empty($custom_date))&&(!empty($week_day_ls))){
                        $weeK_day_exist =    date('l',strtotime($date));
                        if((in_array($weeK_day_exist, $week_day_ls))&& (in_array($date, $custom_date_ls))){
                            //echo $date ." - ". date('l',strtotime($date))."<br>";
                            $schedule->presenter_id 					=		$faculty;
                            $schedule->presenter_name 				    =		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
                            $time										=		$date." ".$class_start_time;
                            //$time 									=		date("m/d/Y H:i", strtotime(strtolower($_POST['start_time'])));
                            $schedule->start_time 						=		$time;
                           // $subject_id									=		$this->adminlte_model->subject_name($subject);
                            $schedule->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
                            $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
                            $schedule->duration 						=		$class_duration;
                            $schedule->time_zone 						=		"Asia/Kolkata";
                            $schedule->attendee_limit 				    =	    $class_strength;
                            //$schedule->control_category_id 		        =		"";
                            $schedule->create_recording 			    =		'true';
                            $schedule->return_url 						=		"https://theonlinegurukul.com/lobby";//site_url('lobby');
                            if($extend_duration!=""){$schedule->extend_duration=$extend_duration;}
                            $schedule->status_ping_url 				    =		"https://theonlinegurukul.com/class-status";//site_url('class-status');
                            $schedule->language_culture_name 	        =		"en-us";
                            //echo "<pre>";print_r($schedule);die;
                            $response 									=		$schedule->createClass($secretAcessKey,$access_key,$webServiceUrl);
                            //echo "<pre>";print_r($response);die;//$file = 'log.txt';//$message = serialize($response)."\r\n";
                            //file_put_contents($file, $message, FILE_APPEND);//echo "<pre>";print_r($response);die;//$response['errormsg']
                            if(empty($response['errorcode'])){
                                $method			    =	$response['method'];
                                $class_id			=	$response['class_id'];
                                $recording_url		=	$response['recording_url'];
                                $presenter_email	=	$response['presenter_email'];
                                $presenter_url		=	$response['presenter_url'];

                                $class_date         =   date("Y-m-d", strtotime($date));
                                $data_class_info   =   array('course_id'=>$insert_id,'class_tag_id'=>$class_id,'recording_url'=>$recording_url,
                                    "class_date"=>$class_date,'class_strength'=>"0","method"=>$method,'category_id'=>$category,'class_id'=>$class,
                                    'subject_id'=>$subject,'subject_code'=>$faculty_name->category_code.$faculty_name->class_code.$faculty_name->subject_code,
                                    'class_start_time'=>$class_start_time,'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,
                                    'class_extend_time_min'=>$extend_duration,'time_zone'=>"Asia/Kolkata");
                                $class_infoid       =   $this->adminlte_model->insert_v2_course_class_detail($data_class_info);
                                $data_cl_presenter  =   array('class_id'=>$class_infoid,'class_presenter'=>$faculty,
                                    "presenter_url"=>   $presenter_url,'user_type'=>'dummy');
                                $pid                =   $this->adminlte_model->insert_v2_course_presenter_data($data_cl_presenter);
                                $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                                unset($class_date);

                            }else{
                                $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                                $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>course Not Added Successfully".$response['errorcode']." ".$response['errormsg']);
                                return redirect("admin/adminlte/course_list");
                            }
                            $this->adminlte_model->update_v2_course_new_class_count($no_class_count,$insert_id);
                        }
                    }
                    $date               =    date ("m/d/Y", strtotime("+1 day", strtotime($date)));
                    $no_class_count     =    $no_class_count+1;
                }//end while
                $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>course Added Successfully");
                return redirect("admin/adminlte/course_list");
            }
            $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>course Added Successfully");
            return redirect("admin/adminlte/course_list");
        }
        $this->load->view('adminlte/panel/footer');
    }
    public function class_modify($classid){
        if($classid==""){
            $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>Classid should not be blank");
            return redirect("admin/adminlte/course_list");
        }
       // echo "<pre>";print_r($_POST);die;
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'modify CLass','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');

        //$this->form_validation->set_rules('class'			    , 'Class'				    , 'required|xss_clean|trim');
        //$this->form_validation->set_rules('subject'			    , 'Subject'				    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('faculty'		        , 'Faculty'                 , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_date'		    , 'Class Date'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_start_time'	, 'Start Time'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_duration'	    , 'Class Duration'		    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('extend_duration'	    , 'Extend Duration'		    , 'xss_clean|trim');
        //$this->form_validation->set_rules('per_class_amount'	, 'CLass Basic Amount'		, 'required|xss_clean|trim');
        $category                               =       $this->adminlte_model->getcategory();
        $res                                    =       $this->adminlte_model->class_id_view($classid);
        $faculty                                =       $this->adminlte_model->faculty_list_course($res->category_id,$res->class_id,$res->subject_id);
        //print_r($res);die;
        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/modify_class',['category'=>$category,'lists'=>$res,'faculty'=>$faculty]);
        }
        else{
           // echo "<pre>";print_r($_POST);die;

           // $class						         =		strtolower($this->input->post('class'));
           // $subject							 =		strtolower($this->input->post('subject'));
            $faculty				             =		strtolower($this->input->post('faculty'));
            $class_date				             =		strtolower($this->input->post('class_date'));
            $class_start_time					 =		date("H:i", strtotime($this->input->post('class_start_time')));
            $class_duration						 =		strtolower($this->input->post('class_duration'));
            $extend_duration					 =		strtolower($this->input->post('extend_duration'));
            //$per_class_amount				     =		strtolower($this->input->post('per_class_amount'));
            $class_strength                      =      "09";
            $time1 		                         =      strtotime($class_start_time);
            $endTime 	                         =      date("H:i", strtotime("+$class_duration minutes", strtotime($class_start_time)));
            $faculty_name                        =       $this->faculty_model->view_faculty($faculty);

            require_once APPPATH. '/plugins/wiziq/classCode/ModifyClass.php';
            $modify 							 =	    new ModifyClass();
            $secretAcessKey				=	"yOEQY4Y6HJG2Swp2CZ+q2A==";
		 $access_key					=	"7DpOH0SG9m8=";
            $webServiceUrl 				         =		"http://classapi.wiziqxt.com/apimanager.ashx";
            date_default_timezone_set('Asia/Kolkata');

            $modify->class_id 					    =		$classid;
            $modify->presenter_id 					=		$faculty;
            $modify->presenter_name 				=		ucfirst($faculty_name->first_name).' '.ucfirst($faculty_name->last_name);
            $date                                   =       date("m/d/Y", strtotime($class_date));
            $time								    =		$date." ".$class_start_time;
            //$time 								=		date("m/d/Y H:i", strtotime(strtolower($_POST['start_time'])));
            $modify->start_time 					=		$time;
            //$subject_id						    =		$this->adminlte_model->subject_name($res->subject_id);
            $modify->title 							=		strtoupper($faculty_name->category_code.$faculty_name->class_code.
            $faculty_name->subject_code)." | ".strtoupper($faculty_name->class)." [ ".strtoupper($faculty_name->subject)." ]";
            //$subject_id->class." [ ".$subject_id->subject." ]";
            $modify->duration 						=		$class_duration;
            $modify->time_zone 						=		"Asia/Kolkata";
            $modify->attendee_limit 				=	    $class_strength;
            $modify->create_recording 			    =		'true';
            $modify->return_url 			        =		site_url('lobby');
            if($extend_duration!=""){$modify->extend_duration=$extend_duration;}
            $modify->status_ping_url 				=		site_url('class-status');
            $modify->language_culture_name 	        =		"en-us";

            //echo "<pre>";print_r($modify);die;
            $response 								=		$modify->Modify($secretAcessKey,$access_key,$webServiceUrl);
            //echo "<pre>";print_r($response);die;//$file = 'log.txt';//$message = serialize($response)."\r\n";
            //file_put_contents($file, $message, FILE_APPEND);//echo "<pre>";print_r($response);die;//$response['errormsg']
            if(empty($response['errorcode'])){
                $method			   =	$response['method'];
                $modify		       =	$response['modify'];
                $data_class_info   =    array(
                    "class_date"=>date("Y-m-d", strtotime($class_date)),'class_strength'=>"0","method"=>$method,
                    'method_info'=>$modify.','.date('Y-M-d'),
                    'class_start_time'=>$class_start_time,'class_end_time'=>$endTime,'class_duration_min'=>$class_duration,
                    'class_extend_time_min'=>$extend_duration,'time_zone'=>"Asia/Kolkata");
                $this->adminlte_model->update_class_content_modified($data_class_info,$classid);
                $this->adminlte_model->update_v2_course_presenter_data($classid,$faculty);
                $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>Class modified successfully for ".$time);
                return redirect("admin/adminlte/course_list");
            }else{
                $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>Class not modified".$response['errorcode']." ".$response['errormsg']);
                return redirect("admin/adminlte/course_list");
            }

        }
        $this->load->view('adminlte/panel/footer');
    }
    public function class_cancel($classid){

        require_once APPPATH. '/plugins/wiziq/classCode/CancelClass.php';
        $cancel 					     =		new CancelClass();
        $secretAcessKey				=	"yOEQY4Y6HJG2Swp2CZ+q2A==";
		 $access_key					=	"7DpOH0SG9m8=";
        $webServiceUrl 				     =		"http://classapi.wiziqxt.com/apimanager.ashx";


        $cancel->class_id 					=	$classid;
        $response 							=	$cancel->CancelEvent($secretAcessKey,$access_key,$webServiceUrl);
        if(empty($response['errorcode'])){
            $method			    =	$response['method'];
            $cancel		        =	$response['cancel'];
            $method_info        =   $cancel.",".date("Y-M-d");
            //echo "<pre>";print_r($response);die;
            $this->adminlte_model->update_v2_course_new_class_method($method,$method_info,$classid);
            $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>class Cancel Successfully".$method." ".$cancel);
            return redirect("admin/adminlte/course_list");
        }else{
        //$file 								= 	'logcancel.txt';
        //$message 							    = 	serialize($response)."\r\n";
       /// file_put_contents($file, $message, FILE_APPEND);
        //echo "<pre>";print_r($response);die;
        $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>Class not Cancel".$response['errorcode']." ".$response['errormsg']);
        return redirect("admin/adminlte/course_list");
        }
    }
    public function class_download_recording($classid){

        require_once APPPATH. '/plugins/wiziq/classCode/DownloadRecording.php';
        $download 					     =		new DownloadRecording();
        $secretAcessKey				=	"yOEQY4Y6HJG2Swp2CZ+q2A==";
		 $access_key					=	"7DpOH0SG9m8=";
        $webServiceUrl 				     =		"http://classapi.wiziqxt.com/apimanager.ashx";


        $download->class_id 			 =	$classid;
        $response 					     =	$download->Recording($secretAcessKey,$access_key,$webServiceUrl);
        if(empty($response['errorcode'])){
            $method			    =	$response['method'];
            $download_status    =	$response['download_status'];
            $message		    =	$response['message'];
            $status_xml_path    =	$response['status_xml_path'];

            $method_info        =   $message.",".date("Y-M-d");
            $requestParameters["recording_format"] = "zip";
            //$data = file_get_contents($status_xml_path);
           // echo "<pre>"; print_r($data);

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, htmlspecialchars($status_xml_path));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $XMLReturn = curl_exec($ch);
            curl_close($ch);

            if(!empty($XMLReturn))
            {
                try
                {
                    $objDOM = new DOMDocument();
                    $objDOM->loadXML($XMLReturn);
                }
                catch(Exception $e)
                {
                    echo $e->getMessage();
                }
                $status=$objDOM->getElementsByTagName("rsp")->item(0);
                $attribNode = $status->getAttribute("status");
                if($attribNode=="ok")
                {
                    $methodTag=$objDOM->getElementsByTagName("method");
                    $download_statusTag					=	$objDOM->getElementsByTagName("download_status");
                    $messageTag							=	$objDOM->getElementsByTagName("message");
                    $recording_download_pathTag			=	$objDOM->getElementsByTagName("recording_download_path");

                    $response1["method"]				=	$methodTag->item(0)->nodeValue;
                    $response1["download_status"]		=	$download_statusTag->item(0)->nodeValue;
                    $response1["message"]				=	$messageTag->item(0)->nodeValue;
                    $response1["recording_download_path"]=	str_replace('&','&amp;',$recording_download_pathTag->item(0)->nodeValue);
                    // return  $response;
                }
                else if($attribNode=="fail")
                {
                    $error=$objDOM->getElementsByTagName("error")->item(0);
                    $response1["errorcode"]				=	$error->getAttribute("code");
                    $response1["errormsg"]				=	$error->getAttribute("msg");
                    //return  $response;
                }
            }
            //file_get_contents($response1['recording_download_path']);
            //echo "<pre>";print_r($response);
            //echo "<pre>";print_r($response1);
            // die;

            echo '<script language="javascript">';
            echo "alert(".$response1['recording_download_path'].")";  //not showing an alert box.
            echo "alert(".$response1['download_status'].")";
            echo "alert(".$response1['message'].")";
            echo "alert(".$response1['method'].")";
            echo '</script>';
        }else{
            //$file 								= 	'logcancel.txt';
            //$message 							    = 	serialize($response)."\r\n";
            /// file_put_contents($file, $message, FILE_APPEND);
            //echo "<pre>";print_r($response);die;
            $this->session->set_flashdata('failure', "<i class='icon fa fa-check'></i>Class not Cancel".$response['errorcode']." ".$response['errormsg']);
            return redirect("admin/adminlte/course_list");
        }
    }


    public function view_session_left(){
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Session Left View','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');

        $this->form_validation->set_rules('week_days[]'		    , 'Week Days'		        , 'callback_contactVerify[custom_date]|xss_clean|trim');
        $this->form_validation->set_rules('custom_date'		    , 'Custom Date'		        , 'callback_contactVerify[week_days[]]|xss_clean|trim');
        $this->form_validation->set_rules('course_duration'     , 'Course Duration'			, 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_start_time'	, 'Start Time'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_duration'	    , 'Class Duration'		    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('extend_duration'	    , 'Extend Duration'		    , 'xss_clean|trim');
        $this->form_validation->set_rules('parallel_session'	, 'No of Parallel Session'	, 'required|xss_clean|trim');

        $category                               =       $this->adminlte_model->getcategory();
        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/view_session_left',['category'=>$category,'lists'=>$res,'faculty'=>$faculty]);
        }
        else{
            $parallel_session                    =		strtolower($this->input->post('parallel_session'));
            $course_duration				     =		strtolower($this->input->post('course_duration'));
            $class_start_time					 =		date("H:i", strtotime($this->input->post('class_start_time')));
            $class_duration						 =		strtolower($this->input->post('class_duration'));
            $extend_duration					 =		strtolower($this->input->post('extend_duration'));
            $per_class_amount				     =		strtolower($this->input->post('per_class_amount'));
            $custom_date					     =		strtolower($this->input->post('custom_date'));
            $week_days							 =      implode(',',$_POST['week_days']);
            $custom_date_ls					     =		explode(',',$custom_date);
            $week_day_ls				         =	    $_POST['week_days'];

            $course_duration1                    =      explode('-',$course_duration);
            $course_from                         =      $course_duration1[0];
            $course_to                           =      $course_duration1[1];
            $time1 		                         =      strtotime($class_start_time);

            if($extend_duration!=""){
                $endTime 	                     =      date("H:i", strtotime("+$class_duration minutes", $time1));
                $endTime 	                     =      date("H:i", strtotime("+$extend_duration minutes", strtotime($endTime)));
            }else{
                $endTime 	                     =      date("H:i", strtotime("+$class_duration minutes", $time1));
            }
            $course_from_time 			         = 	     date("Y-m-d", strtotime(strtolower($course_from)));
            $course_to_time 			         = 	     date("Y-m-d", strtotime(strtolower($course_to)));
            date_default_timezone_set('Asia/Kolkata');
            $date                                =      $course_from_time;
            $end_date                            =      $course_to_time;
            $no_class_count                      =      "0";

            while (strtotime($date) <= strtotime($end_date)) {
                //echo "$date\n";//('l', strtotime($date)); // echo  ('l', strtotime($date));//date('D', strtotime($x));
                $parallel_session1=$parallel_session;
                if((empty($custom_date))&&(!empty($week_day_ls))){
                    $weeK_day_exist          =    date('l',strtotime($date));
                    if(in_array($weeK_day_exist, $week_day_ls)){
                        $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));

                      foreach($classes as $check){
                           date_default_timezone_set('Asia/Kolkata');
                           $today_start      =   $date.' '.$class_start_time;
                           $today_end        =   $date.' '.$endTime;
                           $stars            =   $check->class_date.' '.$check->class_start_time;
                           $ends             =   $check->class_date.' '.$check->class_end_time;

                          $datetime1         =   new DateTime($today_start);
                          $datetime2         =   new DateTime($today_end);
                          $datetime3         =   new DateTime($stars);
                          $datetime4         =   new DateTime($ends);
                           if(
                              (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                             || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                             || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                             || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                              ){
                                  //                                    $interval = $datetime1->diff($datetime3);
                                  //                                   $elapsed = $interval->format('%y years %m months %a days %h hours %i minutes %s seconds');
                                  //                                   echo $today_start."  ".$stars." ".$class_duration." ";
                                  //                                   echo $elapsed."<br>";
                                  //                                   $interval1 = $datetime2->diff($datetime4);
                                  //                                   $elapsed1 = $interval1->format('%y years %m months %a days %h hours %i minutes %s seconds');
                                  //                                   echo $today_end."  ".$ends." ".$class_duration." ";
                                  //                                   echo $elapsed1."<br>";
                                  $left      = $parallel_session1-1;
                                  $ret[]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                  $check->class_end_time.",".$left." classes Avaliable";
                          }

                      }
                    }
                }
                if((!empty($custom_date))&&(empty($week_day_ls))){
                    if(in_array($date, $custom_date_ls)){
                        //echo $date."<br>";
                        $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));

                        foreach($classes as $check){
                            date_default_timezone_set('Asia/Kolkata');
                            $today_start      =   $date.' '.$class_start_time;
                            $today_end        =   $date.' '.$endTime;
                            $stars            =   $check->class_date.' '.$check->class_start_time;
                            $ends             =   $check->class_date.' '.$check->class_end_time;

                            $datetime1         =   new DateTime($today_start);
                            $datetime2         =   new DateTime($today_end);
                            $datetime3         =   new DateTime($stars);
                            $datetime4         =   new DateTime($ends);
                            if(
                                (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                ){
                                    $left      = $parallel_session1-1;
                                    $ret[]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                        $check->class_end_time.",".$left." classes Avaliable";
                            }
                        }
                     }
                 }
                 if((!empty($custom_date))&&(!empty($week_day_ls))){
                        $weeK_day_exist =    date('l',strtotime($date));
                        if((in_array($weeK_day_exist, $week_day_ls))&& (in_array($date, $custom_date_ls))){
                            $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));
                            foreach($classes as $check){
                                date_default_timezone_set('Asia/Kolkata');
                                $today_start      =   $date.' '.$class_start_time;
                                $today_end        =   $date.' '.$endTime;
                                $stars            =   $check->class_date.' '.$check->class_start_time;
                                $ends             =   $check->class_date.' '.$check->class_end_time;

                                $datetime1         =   new DateTime($today_start);
                                $datetime2         =   new DateTime($today_end);
                                $datetime3         =   new DateTime($stars);
                                $datetime4         =   new DateTime($ends);
                                if(
                                    (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                    || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                    || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                    || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                    ){
                                        $left      = $parallel_session1-1;
                                        $ret[]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                            $check->class_end_time.",".$left." classes Avaliable";
                                }
                            }
                        }
                    }
                    //$ret[]          = date("d-M-Y", strtotime($date)).",".$parallel_session." classes Avaliable";
                $date               =    date ("m/d/Y", strtotime("+1 day", strtotime($date)));
                $no_class_count     =    $no_class_count+1;
            }//end while
            $array[0]   =   $_POST;
            $array[1]   =   $ret;
            $this->session->set_flashdata('success',$array);
            return redirect("admin/adminlte/view_session_left");
        }
        $this->load->view('adminlte/panel/footer');
    }

    public function view_session_left_2(){
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Session Left View','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');

        $this->form_validation->set_rules('week_days[]'		    , 'Week Days'		        , 'callback_contactVerify[custom_date]|xss_clean|trim');
        $this->form_validation->set_rules('custom_date'		    , 'Custom Date'		        , 'callback_contactVerify[week_days[]]|xss_clean|trim');
        $this->form_validation->set_rules('course_duration'     , 'Course Duration'			, 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_start_time'	, 'Start Time'		        , 'required|xss_clean|trim');
        $this->form_validation->set_rules('class_duration'	    , 'Class Duration'		    , 'required|xss_clean|trim');
        $this->form_validation->set_rules('extend_duration'	    , 'Extend Duration'		    , 'xss_clean|trim');
        $this->form_validation->set_rules('parallel_session'	, 'No of Parallel Session'	, 'required|xss_clean|trim');

        $category                               =       $this->adminlte_model->getcategory();
        $para_ses_left                          =       $this->adminlte_model->no_parallel_session_purchased();
        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/view_session_left_2',['category'=>$category,'lists'=>$res,'faculty'=>$faculty,

                'para_ses_left'=>$para_ses_left]);
        }
        else{
            $parallel_session                    =		strtolower($this->input->post('parallel_session'));
            $course_duration				     =		strtolower($this->input->post('course_duration'));
            $class_start_time					 =		date("H:i", strtotime($this->input->post('class_start_time')));
            $class_duration						 =		strtolower($this->input->post('class_duration'));
            $extend_duration					 =		strtolower($this->input->post('extend_duration'));
            $per_class_amount				     =		strtolower($this->input->post('per_class_amount'));
            $custom_date					     =		strtolower($this->input->post('custom_date'));
            $week_days							 =      implode(',',$_POST['week_days']);
            $custom_date_ls					     =		explode(',',$custom_date);
            $week_day_ls				         =	    $_POST['week_days'];

            $course_duration1                    =      explode('-',$course_duration);
            $course_from                         =      $course_duration1[0];
            $course_to                           =      $course_duration1[1];
            $time1 		                         =      strtotime($class_start_time);

            if($extend_duration!=""){
                $endTime 	                     =      date("H:i", strtotime("+$class_duration minutes", $time1));
                $endTime 	                     =      date("H:i", strtotime("+$extend_duration minutes", strtotime($endTime)));
            }else{
                $endTime 	                     =      date("H:i", strtotime("+$class_duration minutes", $time1));
            }
            $course_from_time 			         = 	     date("Y-m-d", strtotime(strtolower($course_from)));
            $course_to_time 			         = 	     date("Y-m-d", strtotime(strtolower($course_to)));
            date_default_timezone_set('Asia/Kolkata');
            $date                                =      $course_from_time;
            $end_date                            =      $course_to_time;
            $no_class_count                      =      "0";

            while (strtotime($date) <= strtotime($end_date)) {
                $parallel_session1=$parallel_session;
                if((empty($custom_date))&&(!empty($week_day_ls))){
                    $weeK_day_exist          =    date('l',strtotime($date));
                    if(in_array($weeK_day_exist, $week_day_ls)){
                        $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));

                        foreach($classes as $check){
                            date_default_timezone_set('Asia/Kolkata');
                            $today_start      =   $date.' '.$class_start_time;
                            $today_end        =   $date.' '.$endTime;
                            $stars            =   $check->class_date.' '.$check->class_start_time;
                            $ends             =   $check->class_date.' '.$check->class_end_time;

                            $datetime1         =   new DateTime($today_start);
                            $datetime2         =   new DateTime($today_end);
                            $datetime3         =   new DateTime($stars);
                            $datetime4         =   new DateTime($ends);
                            if(
                                (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                ){
                                    $left      = $parallel_session1-1;
                                    $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                    $check->class_end_time.",".$left." classes Avaliable";
                            }
                        }
                        if (!array_key_exists(date("d-M-Y", strtotime($date)), $ret)) {
                            $left      = $parallel_session1;
                            $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                $check->class_end_time.",".$left." classes Avaliable";
                        }
                    }
                }
                if((!empty($custom_date))&&(empty($week_day_ls))){
                    if(in_array($date, $custom_date_ls)){
                        //echo $date."<br>";
                        $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));

                        foreach($classes as $check){
                            date_default_timezone_set('Asia/Kolkata');
                            $today_start      =   $date.' '.$class_start_time;
                            $today_end        =   $date.' '.$endTime;
                            $stars            =   $check->class_date.' '.$check->class_start_time;
                            $ends             =   $check->class_date.' '.$check->class_end_time;

                            $datetime1         =   new DateTime($today_start);
                            $datetime2         =   new DateTime($today_end);
                            $datetime3         =   new DateTime($stars);
                            $datetime4         =   new DateTime($ends);
                            if(
                                (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                ){
                                    $left      = $parallel_session1-1;
                                    $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                        $check->class_end_time.",".$left." classes Avaliable";
                            }
                        }

                        if (!array_key_exists(date("d-M-Y", strtotime($date)), $ret)) {
                            $left      = $parallel_session1;
                            $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                $check->class_end_time.",".$left." classes Avaliable";
                        }
                    }
                }
                if((!empty($custom_date))&&(!empty($week_day_ls))){
                    $weeK_day_exist =    date('l',strtotime($date));
                    if((in_array($weeK_day_exist, $week_day_ls))&& (in_array($date, $custom_date_ls))){
                        $classes             =     $this->adminlte_model->course_class_list_all(date("Y-m-d", strtotime($date)));
                        foreach($classes as $check){
                            date_default_timezone_set('Asia/Kolkata');
                            $today_start      =   $date.' '.$class_start_time;
                            $today_end        =   $date.' '.$endTime;
                            $stars            =   $check->class_date.' '.$check->class_start_time;
                            $ends             =   $check->class_date.' '.$check->class_end_time;

                            $datetime1         =   new DateTime($today_start);
                            $datetime2         =   new DateTime($today_end);
                            $datetime3         =   new DateTime($stars);
                            $datetime4         =   new DateTime($ends);
                            if(
                                (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1>=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2>=$datetime4))
                                || (($datetime1<=$datetime3)&&($datetime1<=$datetime4))&&(($datetime2>=$datetime3)&&($datetime2<=$datetime4))
                                ){
                                    $left      = $parallel_session1-1;
                                    $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                        $check->class_end_time.",".$left." classes Avaliable";
                            }
                        }
                        if (!array_key_exists(date("d-M-Y", strtotime($date)), $ret)) {
                            $left      = $parallel_session1;
                            $ret[date("d-M-Y", strtotime($date))]     = date("d-M-Y", strtotime($date)).",".$check->class_start_time.','.
                                $check->class_end_time.",".$left." classes Avaliable";
                        }
                    }

                }
                $date               =    date ("m/d/Y", strtotime("+1 day", strtotime($date)));
                $no_class_count     =    $no_class_count+1;
            }//end while
            $array[0]   =   $_POST;
            $array[1]   =   $ret;
            $this->session->set_flashdata('success',$array);
            return redirect("admin/adminlte/view_session_left_2");
        }
        $this->load->view('adminlte/panel/footer');
    }

    public function add_more_attendee_to_course($course_id){
        // print_r($_POST);die;
        $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'Add More Classes to Course','menu_auth'=>$this->menu_auth]);
        $this->load->view('adminlte/panel/sidebar');
        $this->form_validation->set_error_delimiters('<p class="font-bold text-red">', '</p>');
        $this->form_validation->set_rules('student[]'		    , 'Student'		        , 'xss_clean|trim');

        //$class                                =       $this->adminlte_model->getclass();
        //$category                             =       $this->adminlte_model->getcategory();
        $payed_student                          =       $this->adminlte_model->payment_done_st($course_id);
        $list                                   =       $this->adminlte_model->course_view($course_id);

        if($this->form_validation->run()==false){
            $this->load->view('adminlte/course/add_more_attendee_to_course',['payment_st_class'=>$payed_student,'lists'=>$list]);
        }
        else{
            //echo "<pre>";print_r($_POST);die;
            $dt 							     = 	    new DateTime();
            $student							 =      implode(',',$_POST['student']);
            $student_ls				             =	    $_POST['student'];
            $class_strength                      =      "09";
            $class_list                          =       $this->adminlte_model->class_list_for_courseid($course_id);
            //print_r($student_ls);die;
           // echo "<pre>";print_r($class_list);die;
            foreach($class_list as $class){
               // $class_id                      =       $class->class_tag_id;
                require_once APPPATH. '/plugins/wiziq/classCode/AddAttendee.php';
                $attendee 				    =	new AddAttendee();
                $count2 					= 	count($student_ls);

                $xml 						= 	new SimpleXMLElement('<attendee_list></attendee_list>');
                for($i=0;$i<$count2;$i++){
                   $st= $this->adminlte_model->payment_done_st_id_count($course_id,$student_ls[$i]);
                   //$st->student_id;$st->no_of_class_alot;

                   if($student_ls[$i]==$st->student_id){
                       $st->no_of_class_alot    =$st->no_of_class_alot-1;
                       if($st->no_of_class_alot!=0){

                           $attendee_id			      =	  "<![CDATA[".$student_ls[$i]."]]>";
                           $student_id				  =	  $this->adminlte_model->student_name($student_ls[$i]);
                           $screen_name			      =	  "<![CDATA[".$student_id->first_name.' '.$student_id->last_name."]]>";
                           $language_culture_name	  =	  "<![CDATA["."en-us"."]]>";

                           $person                    =    $xml->addChild('attendee');
                           $person->addChild('attendee_id', "$attendee_id");
                           $person->addChild('screen_name', "$screen_name");
                           $person->addChild('language_culture_name', "$language_culture_name");

                       }
                   }

                }
                print_r($xml->asXML());die;

                $XMLAttendee1				=	str_replace('<?xml version="1.0"?>',"",$xml->asXML());
                $XMLAttendee2				=	str_replace("&lt;","<",$XMLAttendee1);
                $attendee->XMLAttendee	    =	str_replace("&gt;",">",$XMLAttendee2);
                 print_r($attendee->XMLAttendee);//die;
                //$attendee->class_id			=	trim($class->class_tag_id);//"386549";
                //$response2            	    = 	$attendee->InsertAttendee($secretAcessKey,$access_key,$webServiceUrl);
               // $response3				    =   json_encode($response2);

                //$response['method'];
                //$response['attendee_class_id'];
                //$response['add_attendees_status'];
                //$response['attendee_urls'];

                /*  foreach($response2['attendee_urls']as $data){
                 $test_url    =	explode("<=>",$data);
                 $this->adminlte_model->update_master_user_url($test_url[0],$test_url[1]);
                 } */
            }
            die;
           //end while
                $this->session->set_flashdata('success', "<i class='icon fa fa-check'></i>course Extended Successfully");
                return redirect("admin/adminlte/course_list");

        }
        $this->load->view('adminlte/panel/footer');
    }

	public function course_list_search(){
	  //print_r($_POST);die;
	    $data_taskpo=array(
	        'course_id_tag'		   =>  strtolower(trim($this->input->post('course_id_tag')))
	    );
	    if(
	        (
	            (isset($data_taskpo['course_id_tag'])	&& !empty($data_taskpo['course_id_tag']))

	        )
	        &&(
	            (isset($data_taskpo['seach_term'])	&& !empty($data_taskpo['seach_term'])) 	|| (isset($data_taskpo['order_by'])&& !empty($data_taskpo['order_by']))
	            )
	        ){

	            $list             =		 $this->adminlte_model->course_list_search($data_taskpo);
	            $links='';
	            $category          =      $this->adminlte_model->getcategory();
				$subject_code      =      $this->adminlte_model->subject_code_lists();

	            $this->load->view('adminlte/panel/header',['userdata'=>$this->admin_data,'title'=>'category List','list'=>$list,
	                'link'=>$links,'menu_auth'=>$this->menu_auth]);
	            $this->load->view('adminlte/panel/sidebar');
	            //$this->load->view('adminlte/master/class/class',['category'=>$category,'data_taskpo'=>$data_taskpo]);
				$this->load->view('adminlte/adminlte/course_list',['category'=>$category,'subject_code'=>$subject_code,'course_id_tag'=>$course_id_tag,'data_taskpo'=>$data_taskpo]);
				$this->load->view('adminlte/panel/footer');
	    }
	    else{
	        return redirect('admin/adminlte/course_list');
	    }
	}




}





/* while (strtotime($date) <= strtotime($end_date)) {
 if((empty($custom_date))&&(!empty($week_day_ls))){
 $weeK_day_exist =    date('l',strtotime($date));
 if(in_array($weeK_day_exist, $week_day_ls)){
 echo $date ." - ". date('l',strtotime($date))."<br>";
 }
 }
 if((!empty($custom_date))&&(empty($week_day_ls))){
 if(in_array($date, $custom_date_ls)){
 echo $date."<br>";
 }
 }
 if((!empty($custom_date))&&(!empty($week_day_ls))){
 //echo "<pre>";print_r($custom_date_ls);print_r($week_day_ls);echo "week-custom";
 $weeK_day_exist =    date('l',strtotime($date));
 if((in_array($weeK_day_exist, $week_day_ls))&& (in_array($date, $custom_date_ls))){
 echo "and "; echo $date ." - ". date('l',strtotime($date))."<br>"; echo $date."<br>";
 }
 }
 $date = date ("m/d/Y", strtotime("+1 day", strtotime($date)));
 }
 die; */
