<?php defined('BASEPATH')or exit('NO direct Access is Allowed');?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<?php
$last = $this->uri->total_segments();
$courseid = $this->uri->segment($last);
 ?>
<div class="content-wrapper">
  <section class="content">
      <div class="row">
          <div class="col-xs-12">
              <div class="box">
                  <div class="box-header">
                      <?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;']); ?>
                  </div>
                  <!-- /.box-header -->
                  <div class="box-body">
                      <div class="row">
                        <div class="col-md-12">
                             <div class="col-md-3">
                                 <div class="form-group">
                                   <?php echo form_label('Course <span style="color:red"> *</span>','course',['for'=>'course','class'=>'']);?>
                                   <div class="input-group">
                                     <div class="input-group-addon"><i class="fa fa-fw fa-commenting text-red"></i></div>
                                     <?php echo form_input(['name'=>'course_name','class'=>'form-control ','id'=>'','placeholder'=>'Course Name',
                                     'value'=>set_value('course_name',$course->course_name." - ".strtoupper($course->faculty)),'disabled'=>'disabled']);?>
                                   </div>
                                 </div>
                             </div>
                             <div class="col-md-3">
                                 <div class="form-group">
                                   <?php echo form_label('unit price/Total course duration(HRS) <span style="color:red"> *</span>','course',['for'=>'course','class'=>'']);?>
                                   <div class="input-group">
                                     <div class="input-group-addon"><i class="fa fa-fw fa-commenting text-red"></i></div>
                                     <?php echo form_input(['name'=>'course_name','class'=>'form-control ','id'=>'','placeholder'=>'Course Name',
                                     'value'=>set_value('course_info',$course->class_unit_price."Rs. - ".strtoupper($course->course_duration_hours)." Hrs. - ".date("d-M-Y",strtotime($course->course_start_from))),'disabled'=>'disabled']);?>
                                   </div>
                                 </div>
                             </div>
                             <div class="col-md-3">
                                 <div class="form-group">
                                   <?php echo form_label('Attendee limit/Available <span style="color:red"> *</span>','course',['for'=>'course','class'=>'']);?>
                                   <div class="input-group">
                                     <div class="input-group-addon"><i class="fa fa-fw fa-commenting text-red"></i></div>
                                     <?php echo form_input(['name'=>'course_name','class'=>'form-control ','id'=>'','placeholder'=>'Course Name',
                                     'value'=>set_value('course_studnet',"Attendee - ".$course->attendee_limit." - ".$course->course_student),'disabled'=>'disabled']);?>
                                   </div>
                                 </div>
                             </div>
                             <div class="col-md-3">
                                 <div class="form-group">
                                   <?php echo form_label('Course Days <span style="color:red"> *</span>','course',['for'=>'course','class'=>'']);?>
                                   <div class="input-group">
                                     <div class="input-group-addon"><i class="fa fa-fw fa-commenting text-red"></i></div>
                                     <?php echo form_input(['name'=>'course_name','class'=>'form-control ','id'=>'','placeholder'=>'Course Name',
                                     'value'=>set_value('course_weekdays',$course->week_days),'disabled'=>'disabled']);?>
                                   </div>
                                 </div>
                             </div>
                         </div>
                      </div>
                  </div>
                  <hr />
                  <!---->
                  <form name="add_name"  method="post" action="admin/course/Course/add_course_student/<?=$courseid;?>" id="add_name">
                     <div class="table-responsive">
                         <table class="table table-bordered" id="dynamic_field">
                           <thead>
                           <tr>
                              <td>#</td>
                             <td>Student Name/Id</td>
                             <td>Joining date</td>
                             <td>Status</td>
                             <td>Remarks</td>
                           </tr>
                         </thead>
                         <tbody>
                             <tr>
                                 <!-- <td><input type="text" name="name[]" placeholder="Enter your Name" class="form-control name_list" required="" /></td> -->
                                 <input type="hidden" value="<?=$course->id;?>" name="course_id">
                                 <input type="hidden" value="<?=$course->attendee_limit;?>" name="studnet_limit">
                                  <?php $status = array('1'=>'Active','0'=>'Inactive');?>
                                  <td>1</td>
                                 <td><?php echo form_dropdown('student[]',$student,set_value('student'),['class'=>'form-control',
                                 'data-placeholder'=>"Select Student",'style'=>"width: 100%;",'tabindex'=>"-1", 'aria-hidden'=>"true",'required'=>'required']);?></td>
                                 <td><?php echo form_input(['name'=>'joining_date','class'=>'form-control','id'=>'datepicker','placeholder'=>'Joining Date',
                                 'value'=>set_value('joining_date[]'),'autocomplete'=>'off','required'=>'required']);?></td>
                                 <td><?php echo form_dropdown('status[]',$status,set_value('status',1),['class'=>'form-control status_check',
                                 'data-placeholder'=>"Select status",'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" value="Submit" />
                     </div>
                  </form>
                  <!------>
              </div>
          </div>
      </div>
  </section>
</div>


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



  $('#add').on('click',function(){
// 			 if(i>=limit){
// 				alert("This ");
// 			}
// 		    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><select name="student[]" class="form-control  name_list" data-placeholder="Select Student" style="" tabindex="-1" aria-hidden="true" required> \
					  <?php foreach($student as $p=>$b){ ?>\
                        <option value="<?=$p?>"> <?=$b?></option>\
                        <?php }?>\
					  </select></td> \
					  <td><input type="text" name="joining_date[]"  class="form-control datepick"  placeholder="Joining Date" autocomplete="off" required> </td> \
                      <td> \
                      <select name="status[]" class="form-control status_check"  data-placeholder="Select status" style="width: 100%;" tabindex="-1" aria-hidden="true" required> \
                      <option value="1" selected="selected">Active</option> \
                      <option value="0">Inactive</option> \
                      </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();
              });


      });


      $(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>
