<?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 List </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')?>">Home</a>&nbsp;
                    <i class="fa fa-angle-right"></i></li>
                    <li class="active">Request List Subjects</li>
         </ol>
		      <div class="pull-left">
	            <a href="#" class="btn btn-sm btn-social btn-github pull-right " data-target="#remarksModal_search" data-toggle="modal">New Query</a>
              <!-- <i class="fa fa-fw fa-search  text-green"></i> -->
				</div>

</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>Category</th>
					<th>Class</th>
					<th>Subject</th>
					<th>Subject Code</th>
					<th>Month</th>
					<th>Year</th>
					<th>Request Date</th>
					<th>Status</th>
					<th>Message</th>
					<th>Chat History</th>
				</tr>
			</thead>
		   <tbody>
		   <?php if( count($list) ):$sn=1;
                $count = $this->uri->segment(4);
                foreach($list as $lists ): ?>
				<tr>
				<td><?php echo  $sn;?></td>
				<td><?php echo  strtoupper($lists->category);?></td>
				<td><?php echo  strtoupper($lists->class);?></td>
				<td><?php echo  strtoupper($lists->subject);?></td>
				<td><?php echo  strtoupper($lists->subject_code);?></td>
				<td><?php echo  strtoupper($lists->month);?></td>
				<td><?php echo  strtoupper($lists->year);?></td>
			 	<td><?php echo strtoupper(date('d-M-Y',strtotime($lists->create_at))); ?></td>
			 	<td><?php if((($lists->month)==(date('M')))&&((($lists->year)==(date('Y'))))){?>
                    <span class="label label-info label-mini" style="background: linear-gradient(45deg,#FF5370,#ff869a);">Request sent</span>
                    <?php } else{?>
                    <span class="label label-info label-mini" style="cursor:pointer;">Old Request</span>
                    <?php }?>
                </td>
                 <td>
                 <?php if((($lists->month)==(date('M')))&&((($lists->year)==(date('Y'))))){?>
                  <span class="label label-info label-mini" data-toggle="modal" data-target="#myModal-<?=$lists->id?>" style="cursor:pointer;">Send New Message</span>
                    <div class="modal-wrapper row">
                        <div class="pull-left">
                        <div class="modal fade" id="myModal-<?=$lists->id?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                          <div class="modal-dialog">
                        	<div class="modal-content">
                        	  <div class="modal-header">
                        		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        		<h4 class="modal-title" id="myModalLabel">
                        		<?php echo  strtoupper($lists->category)." | ".strtoupper($lists->class)." | ".strtoupper($lists->subject);?>
                        		<span style="color:#3498db"> | <?php echo  strtoupper($lists->category_code.$lists->class_code.$lists->subject_code);?></span>
                        		</h4>
                        	  </div>
                        	  <div class="modal-body">
                        	  	<?php echo form_open("Student/request_for_couse_chat_submit",['name'=>'login_form']);?>
                                    <?php echo  form_hidden("request_program_id",$lists->id);?>
                                   <p><input type="text" name="user_message" class="form-control" placeholder="please enter your Message"></p>
                                  <button type="submit" class="btn blue btn-lg pull-right" style="currsor:pointer;">Send Message</button>
                              </div>

                        	  <?php echo form_close();?>
                        	</div><!-- /.modal-content -->
                          </div><!-- /.modal-dialog -->
                        </div><!-- /.modal -->
                        	</div>
                        </div>
                        <?php }?>
                 </td>
                <td>
                	<!-- <a class="popper" id="dd" data-popbox="pop1" onmouseover="hello(<?=$lists->id?>)" onmouseout="$('#pop1').empty();" >hover</a> -->
                           <a class="popper" id="dd" data-popbox="pop1" onmouseover="hello(<?=$lists->id?>)" onmouseout="$('#pop1').empty();" >

                            <span class="label label-info label-mini"
                            style="background: linear-gradient(45deg,#FFa500,#ff869a);cursor:pointer;">Chat History</span>
                           </a>

                </td>
				</tr>
		<?php $sn++;//unset($lists);?>
        <?php endforeach; ?>
        <?php else : ?>
        <tr><td><a href="#">No Record Found</a></td></tr>
         <?php endif; ?>
		  </tbody><?php $count++; //echo  $link; ?>

	</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">

	function hello(id){
		$.ajax({
           type: "POST",
           url: "<?php echo site_url('Student/request_class_chat_history')?>/" + id,
           data:{action:'call_this'},
           success:function(html) {
             $('#pop1').append(html);
           }
      	});
    }
</script>

<div id="remarksModal_search" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
 <div class="modal-dialog">
 <div class="modal-content">
     <div class="modal-header modal_headers">
         <button type="button" class="close-change close" data-dismiss="modal" aria-hidden="true">
           <img src="<?=base_url('assets/web/images/close-pop.png');?>" alt="close-pop.png"></button>
         <h1 class="text-center text_change">Request For Class/Course</h1>
     </div>
     <div class="modal-body">
       <div class="content py-5 bg-light  ">
         <div class="container">
           <div class="row">

             <div class="col-md-12">
                   <span class="anchor" id="formChangePassword"></span>

                  <div id='response32' style="color:red;text-align:center;"></div>
                   <div class="card card-outline-secondary">
                       <div class="card-body">
                           <form class="form" role="form" id='request_subjectForm' method="post"  autocomplete="off">
                             <div class="form-group">
                                 <label for="inputPasswordOld">Class Topic</label>
                                 <!-- <input type="text" class="form-control" name="class_topic" value="" id="class_topic" required> -->
                                 <select id='sel_category' class="form-control input-sm" name="category_id">
                          				<option value="" >Select Category</option>
                          				<?php
                          				foreach($category as $category1){
                          					echo "<option value='".$category1['id']."'>".strtoupper($category1['category_code'])." | ".strtoupper($category1['category'])."</option>";
                          				}
                          				?>
                          		</select>
                             </div>
                             <div class="form-group">
                                 <label for="inputPasswordNew">Class Description</label>
                                 <select id='sel_class' class="form-control input-sm" name="class_id" >
                      							<option value="" >Select class</option>
                      						</select>
                             </div>
                             <div class="form-group">
                                 <label for="inputPasswordNew">Class Description</label>
                                 <select id='sel_subject' class="form-control input-sm" name="subject_id" >
                      							<option value="" >Select subject</option>
                      						</select>
                             </div>
                             <div class="form-group">
                                 <label for="inputPasswordNew">Class Description</label>
                                 <?php echo form_textarea(['name'=>'user_message','class'=>'form-control','id'=>'user_message','placeholder'=>'Query',
                                 'value'=>set_value('user_message'),'autocomplete'=>'off',"cols"=>"","rows"=>"5","maxlength"=>"250"]);?>
                                 <span class="form-text small text-muted">
                                         The Description must be 250 characters.
                                 </span>
                             </div>
                             <div class="form-group">
                                 <button type="submit" class="btn btn-success btn-lg float-right btn-block save_change">Save</button>
                             </div>
                         </form>
                       </div>
                   </div>
               </div>
           </div>
         </div>
       </div>
     </div>
 </div>
 </div>
</div>
