<?php defined('BASEPATH')or exit("NO DIRECT ACCESS iS ALLOWED");?>

<script type='text/javascript'>
        // baseURL variable
        var baseURL= "<?php echo site_url();?>";

        $(document).ready(function(){
            // on category -class change
            $('#sel_category').change(function(){
                var cat = $(this).val();

                // AJAX request
                $.ajax({
                    url:'<?=site_url("Student/get_category_class")?>',
                    method: 'post',
                    data: {category: cat},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_topic').find('option').not(':first').remove();
                        $('#sel_chapter').find('option').not(':first').remove();
                        $('#sel_subject').find('option').not(':first').remove();
                        $('#sel_class').find('option').not(':first').remove();
						 $('#sel_subject').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){
                            $('#sel_class').append('<option value="'+data['id']+'">'+data['class_code']+' | '+data['class']+'</option>');
                        });
                    }
                });
            });

            // on subject -faculty change
            $('#sel_class').change(function(){
                var cl = $(this).val();

                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>Student/get_class_subject',
                    method: 'post',
                    data: {classes: cl},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_topic').find('option').not(':first').remove();
                        $('#sel_chapter').find('option').not(':first').remove();
                        $('#sel_subject').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){
                            $('#sel_subject').append('<option value="'+data['id']+'">'+data['subject_code']+' | '+data['subject']+'</option>');
                        });
                    }
                });
            });
            $('#sel_subject').change(function(){
                var sub = $(this).val();

                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>Student/get_subject_chapter',
                    method: 'post',
                    data: {subject: sub},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_topic').find('option').not(':first').remove();
                        $('#sel_chapter').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){
                            $('#sel_chapter').append('<option value="'+data['id']+'">'+data['chapter_code']+' | '+data['chapter']+'</option>');
                        });
                    }
                });
            });
            //for faculty
            $('#sel_subject').change(function(){
                var sub = $(this).val();

                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>Student/get_class_subject_faculty',
                    method: 'post',
                    data: {subject: sub},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_faculty').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){
                            $('#sel_faculty').append('<option value="'+data['id']+'">'+data['first_name']+' '+data['last_name']+' | '+data['email']+'</option>');
                        });
                    }
                });
            });
          //for payment made course Residtration all course list
            $('#sel_subject').change(function(){
                var sub = $(this).val();
                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>Student/get_class_subject_course_maded_list',
                    method: 'post',
                    data: {subject: sub},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_classid_list').find('option').not(':first').remove();
                        $('#sel_course_list').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){ //alert(data['id']);
                            $('#sel_course_list').append('<option value="'+data['id']+'">'+data['course_id_tag'].toUpperCase()+' | '+data['course_start_date']+' | '+data['course_end_date']+' | '+data['subject_code'].toUpperCase()+'</option>');
                        });
                    }
                });
            });
            $('#sel_course_list').change(function(){
                var course = $(this).val();
                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>Student/get_class_subject_course_classid_list',
                    method: 'post',
                    data: {courseid: course},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_classid_list').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){ //alert(data['id']);
                            $('#sel_classid_list').append('<option value="'+data['id']+'">'+data['class_tag_id'].toUpperCase()+' | '+data['class_date2']+' | '+data['class_start_time2']+' | '+data['class_end_time2'].toUpperCase()+' | '+data['class_strength'].toUpperCase()+' | '+data['faculty'].toUpperCase()+'</option>');
                        });
                    }
                });
            });
             $('#select_all').click(function() {
                $('#sel_classid_list option').prop('selected', true);
            });

          // $('#sel_course_list').change(function(){
           //    var course_it_tag = $(this).val();
                // AJAX request
           //     $.ajax({
            //        url:'<?=site_url()?>admin/Adminlte/get_class_subject_course_maded_info',
            //        method: 'post',
             //       data: {course_id: course_it_tag},
             //       dataType: 'json',
              //      success: function(response){
                        // Remove options
               //         $('#sel_course_info').find('option').not(':first').remove();
                        // Add options
              //          $.each(response,function(index,data){ //alert(data['id']);
                 //           $('#sel_course_info').append('<option value="'+data['id']+'">'+data['course_id_tag'].toUpperCase()+' | '+data['course_start_date']+' | '+data['course_end_date']+' | '+data['subject_code'].toUpperCase()+'</option>');
              //          });
              //      }
           //  //   });
           // });
               $('#sel_course_list').change(function(){
                  var course_it_tag = $(this).val();
                   $.ajax({
                        url:'<?=site_url()?>admin/Adminlte/get_class_amount_info',
                       method: 'post',
                       data: {course_id: course_it_tag},
                       dataType: 'json',
                       success: function(response){
                    	   $('#per_class_amount').val(response['per_class_amount']);
                    	   $('#total_classes').val(response['total_classes']);
                    	   $('#full_course_amount').val(response['total_amount']);
                       }
                   });
               });
               $('#sel_course_list').change(function(){
                   var course_it_tag = $(this).val();
                    $.ajax({
                         url:'<?=site_url()?>admin/Adminlte/get_class_amount_info_after_over_class',
                        method: 'post',
                        data: {course_id: course_it_tag},
                        dataType: 'json',
                        success: function(response){
                     	   //$('#per_class_amount').val(response['per_class_amount']);
                     	   $('#total_classes_remain').val(response['total_classes_remain']);
                     	   $('#current_course_amount').val(response['current_course_amount']);
                        }
                    });
                });

           $('#sel_course_list').change(function(){
                var course_it_tag = $(this).val();
                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>admin/Adminlte/get_class_subject_course_maded_info',
                    method: 'post',
                    data: {course_id: course_it_tag},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                      //  $('#sel_course_info').find('option').not(':first').remove();
                     // $('#sel_course_info').remove(trHTML);
                        // Add options
                        var trHTML = '';

                        var i	=	1;
                        $.each(response,function(index,data){ //alert(data['id']);
                            //$('#sel_course_info').append('<option value="'+data['id']+'">'+data['course_id_tag'].toUpperCase()+' | '+data['course_start_date']+' | '+data['course_end_date']+' | '+data['subject_code'].toUpperCase()+'</option>');
                        	trHTML +=
                                '<tr><td>'
                                + i
                                + '</td><td>'
                                + data['course_id_tag'].toUpperCase()
                                + '</td><td>'
                                + data['course_start_date'].toUpperCase()
                                + '</td><td>'
                                + data['course_end_date'].toUpperCase()
                                + '</td><td>'
                                + data['subject_code'].toUpperCase()
                                + '</td><td>'
                                + data['faculty_code'].toUpperCase()
                                + '</td><td>'
                                + data['class_count'].toUpperCase()
                                + '</td><td>'
                                + data['per_class_amount'].toUpperCase()
                                + '</td><td>'
                                + data['class_tag_id'].toUpperCase()
                                + '</td><td>'
                                + data['class_strength'].toUpperCase()
                                + '</td><td>'
                                + data['class_date'].toUpperCase().fontcolor("#ffa500")
                                + '</td><td>'
                                + data['class_start_time'].toUpperCase()
                                + '</td><td>'
                                + data['class_end_time'].toUpperCase()
                                + '</td><td>'
                                + data['class_duration_min'].toUpperCase()
                                + '</td><td>'
                                + data['class_extend_time_min'].toUpperCase()
                                + '</td><td>'
                                + data['method'].toUpperCase()
                                + '</td></tr>';
                                i++;
                             });
                        $('#sel_course_info').append(trHTML);
                    }

                });
            });
            $('#sel_chapter').change(function(){
                var ch = $(this).val();

                // AJAX request
                $.ajax({
                    url:'<?=site_url()?>admin/Adminlte/get_chapter_topic',
                    method: 'post',
                    data: {chapter: ch},
                    dataType: 'json',
                    success: function(response){
                        // Remove options
                        $('#sel_topic').find('option').not(':first').remove();
                        // Add options
                        $.each(response,function(index,data){
                            $('#sel_topic').append('<option value="'+data['id']+'">'+data['topic_code']+' | '+data['topic']+'</option>');
                        });
                    }
                });
            });

        });

    </script>
<div class="col-md-12  padding_sidebar">
<div class="row" style="margin-right:0px ;margin-left:0px;">
		<div class="card-head profile-categories_bread">
    		<!-- <header>Course Enrolled Detail </header> -->
    			<div class="pull-left"><?php echo  $link;?></div>
    		 <ol class="breadcrumb page-breadcrumb pull-right">
                    <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item" href="<?=site_url('Student')?>"><?=ucfirst($list[0]->category);?></a>&nbsp;<i class="fa fa-angle-right"></i>
                    </li>
                    <li><a class="parent-item" href="#"><?=ucfirst($list[0]->class);?></a>&nbsp;<i class="fa fa-angle-right"></i></li>
                     <li><a class="parent-item" href="#"><?=ucfirst($list[0]->subject);?></a>&nbsp;<i class="fa fa-angle-right"></i></li>
                    <li class="active"><?=strtoupper($list[0]->course_id_tag);?></li>
             </ol>
    	</div>
    <div class="card card-topline-purple">
    	<div class="card-head">

    	</div>
 	<div class="table-responsive">
	   <div id="tableContainer2" class="container-tb">
	     <table class="table" style="font-family: sans-serif;font-size: 12px;">
			<thead>
				<tr>
					<th>#</th>
					<th>Class Id</th>
					<th>Date</th>
          <th>Start At</th>
          <th>End At</th>
					<th>Status</th>
          <th>Recording</th>
					<th>Subject Code</th>
          <th>Faculty</th>

				</tr>
			</thead>
		   <tbody>
		   <?php if( count($list) ):$sn=1;
        $count = $this->uri->segment(4);
        foreach($list as $lists ): ?>

         <?php
         $asia_calcutta_date_start = DateTime::createFromFormat('Y-m-d H:i',date("Y-m-d H:i",strtotime($lists->class_date." ".$lists->class_start_time)),new DateTimeZone('Asia/Calcutta'));
         $user_timezone_start = clone $asia_calcutta_date_start;
         $user_timezone_start->setTimeZone(new DateTimeZone($this->session->userdata('user_timezone')));

         $asia_calcutta_date_end = DateTime::createFromFormat('Y-m-d H:i',date("Y-m-d H:i",strtotime($lists->class_date." ".$lists->class_end_time)),new DateTimeZone('Asia/Calcutta'));
         $user_timezone_end = clone $asia_calcutta_date_end;
         $user_timezone_end->setTimeZone(new DateTimeZone($this->session->userdata('user_timezone')));
         //echo 'UTC:  ' . $asia_calcutta_date->format('Y-m-d g:i A');  // UTC:  2011-04-27 2:45 AM
         //echo 'ACST: ' . $acst_date->format('Y-m-d g:i A'); // ACST: 2011-04-27 12:15 PM
         $todays_date       =   date("Y-m-d H:i");
         $today             =   strtotime($todays_date);
         $starts            =   strtotime($user_timezone_start->format('Y-m-d H:i'));
         $ends              =   strtotime($user_timezone_end->format('Y-m-d H:i'));
         $time1             =   $starts - (10 * 60);
         $less_10_min_start_time = date("Y-m-d H:i", $time1);
         $stars             =    strtotime($less_10_min_start_time);
        ?>
				<tr>
					<td><?php echo ucfirst($sn);?></td>
					<td><?php echo $lists->class_tag_id;?></td>
          <td><?php echo  $user_timezone_start->format('d-M-Y');?></td>
          <td><?php echo  $user_timezone_start->format('g:i A');?></td>
          <td><?php echo  $user_timezone_end->format('g:i A');?></td>
					<td>
            <?php if(($today>=$stars)&&($today<$ends)){?>
            <a href='<?=$lists->attendee_url?>' class="label label-mini" style="background: linear-gradient(45deg,#FFB64D,#ffcb80);cursor:pointer;" >Join</a>
            <?php }else if(($today<$stars)&&($today<$ends)){?>
            <a href='#' class="label label-info label-mini" style="cursor:default;">Upcoming</a>
            <?php    }else if ($today>=$ends){?>
            <a href='#' class="label label-mini" style="background: linear-gradient(45deg,#FF5370,#ff869a);cursor:default;">Over</a>
            <?php    }else{?>
            <a href='#' class="label label-mini" style="background: linear-gradient(45deg,#FF5370,#ff869a);cursor:default;">Status not Found </a>
            <?php    }?>
					</td>
          <td>
         <?php if($today>$ends){?>
          <a href='<?=$lists->recording_url;?>' target="blank" class="label label-mini" style="background: linear-gradient(45deg,#FFB64D,#ffcb80);cursor:pointer;" >Recording</a>
          <?php }else{?>
              <a href='#' class="label label-mini" style="background: linear-gradient(45deg,#FF5370,#ff869a);cursor:default;">Not Available</a>
          <?php    } ?>
					</td>
          <td><?php echo     strtoupper($lists->subject_code);?></td>
          <td><?php echo     ucwords($lists->presenter);?></td>
				</tr>
		<?php $sn++;unset($json2);unset($user_id);unset($user_url);unset($stars);unset($ends);unset($today);?>
        <?php endforeach; ?>
        <?php else : ?>
        <tr><td><a href="#">No Record Found</a></td></tr>
         <?php endif; ?>
		  </tbody><?php $count++; ?>

	</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
