<?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;
}
.amount{
   color: red;
    margin-top: 3px;
    margin-right: 80px;
    font-size: 17px;
}

</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">
                  <!-- /.box-header -->
                  <div class="box-body ">
                      <div class="row">
                         <div class="col-md-12">
                           <div  class="border_full ">
                           <h3  class="full_h3"><?=strtoupper($course->course_name);?>
                             <a href="<?=site_url('admin/course/Course');?>" class="course_lists pull-right btn btn-sm btn-social" style="background-color: #ffffff;"><i class="fa fa-list text-green"></i>Course List</a>

                           </h3>
                           <div class="table-responsive ">
                               <table class="table table-bordered" id="">
                                 <thead>
                                 <tr>
                                   <th>Faculty</th>
                                   <th>Hour Unit Price</th>
                                   <th>Total Student</th>
                                </tr>
                              </thead>
                                 <tbody >
                                 <tr >
                                   <td ><?=strtoupper($course->faculty);?></td>
                                   <td><i class="fa fa-fw fa-rupee"></i> <?=strtoupper($course->class_unit_price);?></td>
                                   <td><?=strtoupper($course->course_student);?></td>
                                </tr>
                              </tbody>
                         </table>
                         </div>
                         <h3 class="full_h3">Total active Studnet
                           <?php echo anchor("admin/course/Course/edit_course_student/{$course->id}",'<i class="fa fa-fw fa-user-plus text-white"></i> Edit Course Student',['title'=>'Edit Course Student','class'=>'btn btn-sm btn-danger pull-right']); ?>
                         </h3>

                         <div class="table-responsive1 no-padding" >
                           <table class="table table-bordered table-responsive" id="">
                           <thead>
                           <tr>
                             <th>Faculty</th>
                             <th>Student</th>
                             <th>Wallet Money</th>
                          </tr>
                        </thead>
                        <tbody>
                         <?php $jk=1; foreach($active_student as $act){?>
                            <tr>
                               <td><?=strtoupper($jk);?></td>
                           <td><input type="checkbox" checked disabled> <?=nbs(2);?><?=strtoupper($act->student_name);?></td>
                           <td><i class="fa fa-fw fa-inr"></i><?php if($act->student_wallet>0){echo $act->student_wallet;}else{echo "0";}?></td>
                            </tr>
                         <?php
                          $jk++;}
                          ?>
                        </tbody>
                   </table>
                   </div>
                 </div>
                       </div>
                     </div>
                           </div>
                           <div class="box">
                               <div class="box-body">
                                  <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="add_course">
                        <h3 class="add_h3">Assign Classes to Course/Student
                         <input type="submit" name="submit" id="submit" class="btn btn-primary btn-sm pull-right" value="Submit" />
                        </h3>
                            <div class="table-responsive">
                                <table class="table table-bordered" id="dynamic_field">
                                  <thead>
                                  <tr>
                                    <th>#</th>
                                    <th>Class Date</th>
                                    <th>Class Start Time</th>
                                    <th>Class duration</th>
                                    <th>Extend duration</th>
                                    <th>Faculty</th>
                                    <th>Remarks</th>
                                    <th>Class Price <i class="fa fa-fw fa-rupee"></i></th>
                                    <th>Action</th>
                                  </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 getprice','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 getprice2','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> <span class="priceval"> </span></td>
                                        <td><button type="button" name="add" id="add" class="btn btn-success">Add More</button></td>
                                    </tr>
                                  </tbody>
                                </table>
                                 <!-- <div class="final_amount">
                                <div class="amount pull-right">Final Amount : <span class="total_priceval"></span></div>
                              </div> -->
                            </div>
                         </form>
                          </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 getprice 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 getprice2 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> <span class="priceval"> </span></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();
                });

            //  $('.getprice').change(function () {
            $('.getprice').on('change', function(){
                   var hour_price = <?php echo $course->class_unit_price;?>;
                   var hr_cal   = this.value/60; //$('option:selected').val()/60;// $('#row'+i).find("select").val()/60;
                   //alert(hr_cal);
                   var hr_calculate;
                   hr_cal =parseFloat(hr_cal).toFixed(2);
                   if((hr_cal>=0.5)&&(hr_cal<0.75)){
                     hr_calculate = 0.5;
                   }
                   else if((hr_cal>=0.75)&&(hr_cal<1.25)){
                     hr_calculate =1;
                   }
                   else if((hr_cal>=1.25)&&(hr_cal<1.75)){
                     hr_calculate = 1.5;
                   }
                   else if((hr_cal>=1.75)&&(hr_cal<2.25)){
                     hr_calculate = 2;
                   }
                   else if((hr_cal>=2.25)&&(hr_cal<2.75)){
                     hr_calculate = 2.5;
                   }
                   else if((hr_cal>=2.75)&&(hr_cal<3.25)){
                     hr_calculate = 3;
                   }
                   else if((hr_cal>=3.25)&&(hr_cal<3.75)){
                     hr_calculate = 3.5;
                   }
                   else if((hr_cal>=3.75)&&(hr_cal<4.25)){
                     hr_calculate = 4;
                   }
                   else if((hr_cal>=4.25)&&(hr_cal<4.75)){
                     hr_calculate = 4.5;
                   }
                   else if((hr_cal>=4.75)&&(hr_cal<5.25)){
                     hr_calculate = 5;
                   }else{
                     hr_calculate = hr_cal;
                   }
                   //alert(hr_calculate*hour_price);
                  var $row = $(this).closest("tr");
                  var $tds = $row.find("td");
                  var $sp = $tds.find("span");
                  $($sp).empty();
                  $($sp).append(hr_calculate*hour_price);
                  //  $('.priceval').empty();
                   //$('.priceval').append(hr_calculate*hour_price);

                });

      }

      });


      $(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.');
                }
           });
      });

    });

    $(function () {
        $(".getprice").change(function () {
           var hour_price = <?php echo $course->class_unit_price;?>;
           var hr_cal   =  $('option:selected').val()/60;
           var hr_calculate;
           hr_cal =parseFloat(hr_cal).toFixed(2);
           if((hr_cal>=0.5)&&(hr_cal<0.75)){
             hr_calculate = 0.5;
           }
           else if((hr_cal>=0.75)&&(hr_cal<1.25)){
             hr_calculate =1;
           }
           else if((hr_cal>=1.25)&&(hr_cal<1.75)){
             hr_calculate = 1.5;
           }
           else if((hr_cal>=1.75)&&(hr_cal<2.25)){
             hr_calculate = 2;
           }
           else if((hr_cal>=2.25)&&(hr_cal<2.75)){
             hr_calculate = 2.5;
           }
           else if((hr_cal>=2.75)&&(hr_cal<3.25)){
             hr_calculate = 3;
           }
           else if((hr_cal>=3.25)&&(hr_cal<3.75)){
             hr_calculate = 3.5;
           }
           else if((hr_cal>=3.75)&&(hr_cal<4.25)){
             hr_calculate = 4;
           }
           else if((hr_cal>=4.25)&&(hr_cal<4.75)){
             hr_calculate = 4.5;
           }
           else if((hr_cal>=4.75)&&(hr_cal<5.25)){
             hr_calculate = 5;
           }else{
             hr_calculate = hr_cal;
           }
           //alert(hr_calculate*hour_price);
          var $row = $(this).closest("tr");
          var $tds = $row.find("td");
          var $sp = $tds.find("span");
          $($sp).empty();
          $($sp).append(hr_calculate*hour_price);
          //  $('.priceval').empty();
           //$('.priceval').append(hr_calculate*hour_price);
        });
    });

</script>
<script>
$(document).ready(function(){
  // val ar =   $(".getprice").val();
  // //alert(ar);

  $(".getprice").each(function () {

      var hour_price = <?php echo $course->class_unit_price;?>;
      var hr_cal   =  $(this).val()/60;
      var hr_calculate;
      hr_cal =parseFloat(hr_cal).toFixed(2);
      if((hr_cal>=0.5)&&(hr_cal<0.75)){
        hr_calculate = 0.5;
      }
      else if((hr_cal>=0.75)&&(hr_cal<1.25)){
        hr_calculate =1;
      }
      else if((hr_cal>=1.25)&&(hr_cal<1.75)){
        hr_calculate = 1.5;
      }
      else if((hr_cal>=1.75)&&(hr_cal<2.25)){
        hr_calculate = 2;
      }
      else if((hr_cal>=2.25)&&(hr_cal<2.75)){
        hr_calculate = 2.5;
      }
      else if((hr_cal>=2.75)&&(hr_cal<3.25)){
        hr_calculate = 3;
      }
      else if((hr_cal>=3.25)&&(hr_cal<3.75)){
        hr_calculate = 3.5;
      }
      else if((hr_cal>=3.75)&&(hr_cal<4.25)){
        hr_calculate = 4;
      }
      else if((hr_cal>=4.25)&&(hr_cal<4.75)){
        hr_calculate = 4.5;
      }
      else if((hr_cal>=4.75)&&(hr_cal<5.25)){
        hr_calculate = 5;
      }else{
        hr_calculate = hr_cal;
      }

      $('.priceval').empty();
      $('.priceval').append(hr_calculate*hour_price);



  })
});



// $(document).ready(function(){
//       var sum=0;
//   $(".priceval").each(function () {
//         var value  = $(this).text();
//         sum+= parseInt(value);
//       $('.total_priceval').append(sum);
//   })
// });
</script>
