<?php defined('BASEPATH')or exit('NO direct Access is Allowed');?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.css" rel="stylesheet"/>
<link href="https://code.jquery.com/ui/1.12.1/themes/pepper-grinder/jquery-ui.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<script src="https://cdn.rawgit.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/master/jquery-ui.multidatespicker.js"></script>
<style>
.bootstrap-timepicker-widget table td input {
    width: 100%;
  }
  .border_full{
    border: 2px solid #ccc;

  }
  .full_h3{
    margin-top: -4px;
    background-color: #999;
    color: #fff;
    padding: 9px;
  }
  .add_course{
    margin-top: 15px;
    border: 2px solid #ccc;
  }
  .add_h3{
    margin-top: -4px;
    background-color: #dd4b39;
    color: #fff;
    padding: 9px;
}

</style>
<?php
  $last     = $this->uri->total_segments();
  $courseid = $this->uri->segment($last);
  date_default_timezone_set('Asia/Kolkata');
?>

<div class="content-wrapper">
  <section class="content">
      <div class="row">
          <div class="col-xs-12">
              <div class="box">
                  <div class="box-header">
                      <!--<h3 class="box-title">Add Products</h3>-->
                      <div class="col-md-12" id="respose">
                      <?php if ($this->session->flashdata('failure') == TRUE): ?>
                            <div class="alert alert-error"><?php echo $this->session->flashdata('failure'); ?></div>
                            <?php endif; ?>
                            <?php if ($this->session->flashdata('success') == TRUE): ?>
                            <div class="alert alert-success"><?php echo $this->session->flashdata('success'); ?></div>
                        <?php endif; ?>
                      </div>
                  </div>
                  <!-- /.box-header -->
                  <div class="box-body">
                      <div class="row">
                         <div class="col-md-12">
                           <div  class="border_full">
                           <h3  class="full_h3">Course Info
                             <?php echo anchor('admin/course/Course','<i class="fa fa-fw fa-list"></i> Course List',['class'=>'btn btn-default pull-right',
                             'style'=>'background-color: #ffffff;']); ?>
                           </h3>
                           <div class="table-responsive">
                               <table class="table table-bordered" id="">
                                 <thead>
                                 <tr>
                                   <th>Course Start From</th>
                                   <th>Course Name</th>
                                   <th>Faculty</th>
                                   <th>Hour Unit Price</th>
                                   <th>Total Duration Hrs</th>
                                   <th>Total Student</th>
                                </tr>
                              </thead>
                                 <tbody>
                                 <tr>
                                   <td><?=strtoupper(date("d-M-Y",strtotime($course->course_start_from)));?></td>
                                   <td><?=strtoupper($course->course_name);?></td>
                                   <td><?=strtoupper($course->faculty);?></td>
                                   <td><?=strtoupper($course->class_unit_price);?></td>
                                   <td><?=strtoupper($course->course_duration_hours);?></td>
                                   <td><?=strtoupper($course->course_student);?></td>
                                </tr>
                              </tbody>
                         </table>
                         </div>
                         <h3 class="full_h3">Total active Studnet </h3>
                         <div class="table-responsive">
                             <table class="table table-bordered" id="">

                               <tr>
                            <?php foreach($active_student as $act){?>
                              <td><input type="checkbox" checked disabled> <?=nbs(2);?><?=strtoupper($act->student_name);?></td>
                            <?php
                             }
                             ?>
                           </tr>
                       </table>
                       </div>

                       <h3 class="full_h3">Class Detail </h3>
                       <div class="table-responsive">
                         <table class="table table-bordered" id="">
                           <thead>
                           <tr>
                             <th>Class Id</th>
                             <th>Class Date</th>
                             <th>Class Start Time</th>
                             <th>Class End Time</th>
                             <th>Class Duration</th>
                             <th>Faculty</th>
                             <th>Student Total/Available/Left</th>
                          </tr>
                        </thead>
                           <tbody>
                           <tr>
                             <?php //print_r($class);?>
                             <td><?=strtoupper($class->class_name);?></td>
                             <td><?=strtoupper(date("d-M-Y",strtotime($class->class_date)));?></td>
                             <td><?=strtoupper(date("g:i a",strtotime($class->class_start_time)));?></td>
                             <td><?=strtoupper(date("g:i a",strtotime($class->class_end_time)));?></td>
                             <td><?php if($class->class_extended_min!=""){echo strtoupper($class->class_duration_min+$class->class_extended_min." Min");}else{echo strtoupper($class->class_duration_min." Min");}?></td>
                             <td><?=strtoupper($class->faculty);?></td>
                             <td><?php echo strtoupper($course->course_student);?> / <?=$class->student_inside_class;?> / <?=$course->course_student-$class->student_inside_class;?></td>
                          </tr>
                        </tbody>
                   </table>
                     </div>
                 </div>
                       </div>

                      <div class="col-md-12">
                        <div class="add_course">
                        <h3 class="add_h3">Add Student to Class </h3>
                         <form name="add_name"  method="post" action='<?=site_url("admin/course/Course/add_class_as_well_student_to_course/{$courseid}");?>' id="add_name">
                            <div class="table-responsive">
                                <table class="table table-bordered" id="dynamic_field">
                                  <thead>
                                  <tr>
                                     <td>#</td>
                                    <td>Class Date</td>
                                    <td>Class Start Time</td>
                                    <td>Class duration</td>
                                    <td>Extend duration</td>
                                    <td>Faculty</td>
                                    <td>Remarks</td>
                                    <td>Action</td>
                                  </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <!-- <td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" required="" /></td> -->
                                        <?php foreach($active_student as $act){?>
                                        <input type="hidden" name="student_id[]" value="<?=$act->student_id?>">
                                        <?php
                                         }
                                         ?>
                                        <input type="hidden" value="<?=$course->id;?>" name="course_id">
                                        <input type="hidden" value="<?=$course->attendee_limit;?>" name="studnet_limit">
                                         <td>1</td>
                                         <td><?php echo form_input(['name'=>'class_date[]','class'=>'form-control','id'=>'datepicker','placeholder'=>'Class Date',
                                         'value'=>set_value('class_date',date('m/d/Y')),'autocomplete'=>'off','required'=>'required']);?></td>
                                        <td>
                                           <div class="bootstrap-timepicker"><div class="bootstrap-timepicker-widget dropdown-menu"><table><tbody><tr><td><a href="#" data-action="incrementHour"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-up"></i></a></td></tr><tr><td><span class="bootstrap-timepicker-hour">08</span></td> <td class="separator">:</td><td><span class="bootstrap-timepicker-minute">45</span></td> <td class="separator">&nbsp;</td><td><span class="bootstrap-timepicker-meridian">AM</span></td></tr><tr><td><a href="#" data-action="decrementHour"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator"></td><td><a href="#" data-action="decrementMinute"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-down"></i></a></td></tr></tbody></table></div>
                                          <?php echo form_input(['name'=>'class_start_time[]','class'=>'form-control timepicker','placeholder'=>'Enter class Start Time',
                                       'value'=>set_value('class_start_time'),'autocomplete'=>'off','required'=>'required']);?></td>

                                        <td><?php  $course_duration  = array(''=>"Select class Duration",
                                                  '15'=>'15 Min','30'=>'30 Min','45'=>'45 Min','60'=>'1 Hour',
                                                  '75'=>'1 Hour 15 min','90'=>'1 Hour 30 min','105'=>'1 Hour 45 min',
                                                  '120'=>'2 Hour','135'=>'2 Hour 15 min','150'=>'2 Hour 30 min','165'=>'2 Hour 45 min',
                                                  '180'=>'3 Hour','195'=>'3 Hour 15 min','210'=>'3 Hour 30 min','225'=>'3 Hour 45 min',
                                                  '240'=>'4 Hour','255'=>'4 Hour 15 min','270'=>'4 Hour 30 min','285'=>'4 Hour 45 min',
                                                  '300'=>'5 Hour'); ?>
                                        <?php echo form_dropdown('class_duration_mins[]',$course_duration,set_value('class_duration_mins','60'),['class'=>'form-control','autocomplete'=>'off','required'=>'required']);?>
                                      </td>
                                        <td>   <?php $extend_duration  = array(''=>"Select Extend Duration",'05'=>'05 Min','10'=>'10 Min','15'=>'15 Min','20'=>'20 Min','25'=>'25 Min','30'=>'30 min');?>
                                        <?php echo form_dropdown('extend_duration_mins[]',$extend_duration,set_value('extend_duration_mins'),['class'=>'form-control','autocomplete'=>'off']);?>
                                    </td>
                                    <td> <?php echo form_dropdown('faculty[]',$faculty,set_value('faculty',$course->faculty_id),['class'=>'form-control','autocomplete'=>'off','required'=>'required']);?></td>
                                    <td>  <?php echo form_textarea(['name'=>'remarks[]','class'=>'form-control','id'=>'','placeholder'=>'Remarks',
                                      'value'=>set_value('remarks'),'rows'=> '1','cols' => '10','autocomplete'=>'off']);?></td>
                                        <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
                                    </tr>
                                  </tbody>
                                </table>
                                <input type="submit" name="submit" id="submit" class="btn btn-info pull-right" value="Submit" />
                            </div>
                         </form>
                          </div>
                      </div>
                    </div>
                  </div>
                  <hr />

              </div>
          </div>
      </div>
  </section>
</div>

<script type="text/javascript">
    $(document).ready(function(){
    //  var postURL = "/addmore.php";
      var i=1;
	  var limit= 5;

  $('#add').on('click',function(){
			 if(i>=limit){
				alert("You dont have right to add more than "+limit+" class at obe time");
			}
		    else{

				i++;
           // $('#dynamic_field').append('<tr id="row'+i+'" class="dynamic-added"><td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" required /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');
                      $('#dynamic_field').append('<tr id="row'+i+'" class="dynamic-added"> \
                      <td>'+i+'</td> \
					            <td><input type="text" name="class_date[]"  class="form-control datepick"  placeholder="Class Date" autocomplete="off" required> </td> \
                      <td> \
                         <div class="bootstrap-timepicker"><div class="bootstrap-timepicker-widget dropdown-menu"><table><tbody><tr><td><a href="#" data-action="incrementHour"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="glyphicon glyphicon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"> \
                         <i class="glyphicon glyphicon-chevron-up"></i></a></td></tr><tr><td><span class="bootstrap-timepicker-hour">08</span></td> <td class="separator">:</td><td><span class="bootstrap-timepicker-minute">45</span></td> <td class="separator">&nbsp;</td><td><span class="bootstrap-timepicker-meridian">AM</span></td></tr><tr><td><a href="#" data-action="decrementHour"><i class="glyphicon glyphicon-chevron-down"></i></a></td> \
                         <td class="separator"></td><td><a href="#" data-action="decrementMinute"><i class="glyphicon glyphicon-chevron-down"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="glyphicon glyphicon-chevron-down"></i></a></td></tr></tbody></table></div> \
                      <input type="text" name="class_start_time[]"  class="form-control timepicker"  placeholder="Class Start Time" autocomplete="off" required> </td> \
                      <td><select name="class_duration_mins[]" class="form-control  name_list" data-placeholder="Select Class Duration" style="" tabindex="-1" aria-hidden="true" required> \
                      <?php foreach($course_duration as $p=>$b){ ?>\
                                  <option value="<?=$p?>"> <?=$b?></option>\
                                  <?php }?>\
                      </select></td> \
                      <td><select name="extend_duration_mins[]" class="form-control  name_list" data-placeholder="Select Extend class Duration" style="" tabindex="-1" aria-hidden="true" > \
                      <?php foreach($extend_duration as $p=>$b){ ?>\
                                  <option value="<?=$p?>"> <?=$b?></option>\
                                  <?php }?>\
                      </select></td> \
                      <td><select name="faculty[]" class="form-control  name_list" data-placeholder="Select Faculty" style="" tabindex="-1" aria-hidden="true" required> \
                      <?php foreach($faculty as $p=>$b){ ?>\
                                  <option value="<?=$p?>"> <?=$b?></option>\
                                  <?php }?>\
                      </select></td> \
                      <td> <textarea name="remarks[]" cols="10" rows="1" class="form-control" id="" placeholder="Remarks" autocomplete="off"></textarea></td> \
                      <td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">X</button></td></tr>');

              $('.datepick').each(function(){
                $(this).datepicker();
              });
              $('.timepicker').each(function(){
                showInputs: false;
                minuteStep: 5;
                $(this).timepicker();
                });

      }

      });


      $(document).on('click', '.btn_remove', function(){
           var button_id = $(this).attr("id");
           $('#row'+button_id+'').remove();
      });


      $('#submit').click(function(){
           $.ajax({
                url:postURL,
                method:"POST",
                data:$('#add_name').serialize(),
                type:'json',
                success:function(data)
                {
                  	i=1;
                  	$('.dynamic-added').remove();
                  	$('#add_name')[0].reset();
    				        alert('Record Inserted Successfully.');
                }
           });
      });

    });
</script>
