<link rel="stylesheet" href="<?php echo admin_css(); ?>plugins/bs-stepper/css/bs-stepper.min.css">
<link rel="stylesheet" href="<?php echo admin_css(); ?>plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css">
<script src="<?php echo admin_css(); ?>dist/js/webcamjs-master/webcam.min.js"></script>
 <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark">Course Details</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="<?php echo base_url() ?>admin/admin/dashboard">Dashboard</a></li>
              <li class="breadcrumb-item"><a href="#">Student</a></li>
              <li class="breadcrumb-item active">Course Details</li>

            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">

        <div class="row">
          <div class="col-sm-12">
            <div class="card card-default">
              <div class="card-header">
                <h3 class="card-title">Course Details</h3>
                <div class="card-tools">
                  <a href="<?php echo base_url()?>admin/students/admitted_student" class="btn btn-primary btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> View Student</a>
                </div>
              </div>
              <!-- /.card-header -->
              <?php echo form_open_multipart('admin/students/update_adminssion_student/'.$student->user_id, ['id' => 'inq_form']); ?>
              <div class="card-body p-0">
                 <div class="bs-stepper">
                    
                    <div class="bs-stepper-content">
                      
                       <?php 
                        $this->db->select('a.*, b.title, b.price');
                        $this->db->from('student_course a');
                        $this->db->join('course b', 'b.id = a.st_course_course_id');
                        $this->db->where('a.st_course_student_id', $student->user_id);
                        $course_data = $this->db->get()->result();
                       ?>

                       <div id="course-details" class="content active" role="tabpanel" aria-labelledby="information-part-trigger">
                          <div class="row">
                            <div class="col-sm-8">
                              <div class="form-group">
                                <label for="exampleInputEmail1">Select A Course</label>
                                <select type="text" class="form-control" placeholder="Enter Student Dist" id="course_list">
                                  <option value="">Select</option>
                                  <?php foreach ($all_course as $key => $course_d):?>
                                    <option value="<?php echo $course_d->id; ?>"><?php echo $course_d->title; ?></option>
                                  <?php endforeach; ?>
                                </select>
                              </div>
                            </div>
                            <div class="col-sm-4">
                              <button type="button" onclick="add_new_course()" style="position:absolute;bottom:20px" class="btn btn-success align-self-end mt-auto">Add Course</button>
                            </div>
                            <div class="col-sm-12">
                              <table id="example2" class="table table-bordered table-striped">
                                <thead>
                                <tr>
                                  <td>No</td>
                                  <th>Course Name</th>
                                  <th>Admission Date</th>
                                  <th>Payment Status</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php $b=1; foreach ($course_data as $course):?>
                                <tr>
                                  <td><?php echo $b; ?></td>
                                  <td><?php echo $course->title ?></td>
                                  <td><input class="form-control" type="date" value="<?php echo $course->st_course_date ?>" id="course_admission_date_<?php echo $course->st_course_id; ?>">
                                    <button class="btn btn-success btn-xs" type="button" onclick="update_admission_date(<?php echo $course->st_course_id; ?>)">Update</button>
                                </td>
                                  <td>
                                    <?php if($course->st_course_status == 0): ?>
                                      <button data-toggle="modal" data-target="#payment_model<?php echo $course->st_course_id; ?>" type="button" class="btn btn-warning btn-xs"><b>Confirm Admission </b></button>
                                    <?php else: ?>
                                      <span class="badge badge-success">Admission Complete</span>
                                    <?php endif;?>
                                  </td>
                                </tr>
                                <?php $b++; ?>
                                <?php endforeach; ?>
                                </tbody>
                              </table>
                            </div>
                          </div>
                       </div>

                       </div>
                    </div>
                 </div>
              </div>
            </div>
          </div>
      </div>
    </div>
  </section>
</div>
<?php $b=1; foreach ($course_data as $course):?>
<?php if($course->st_course_status == 0): ?>
<div class="modal fade" id="payment_model<?php echo $course->st_course_id; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Admission Fee Details</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <form id>
      <div class="modal-body">
        <table class="table-s">
          <tr>
            <th class="text-center">Description</th>
            <th class="text-center">Amount</th>
          </tr>
          <tr>
            <td>Student Registration Fee</td>
            <td><b class="float-right">
              <?php echo $main_amt = $course->price;?>
            </td>
          </tr>
          <!-- <tr>
            <td>Do You Want Digital Certificate 
              <select onclick="calculate(this.value, <?php //echo $course->st_course_id; ?>, <?php //echo $main_amt; ?>)" id="is_digital_certificate_<?php //echo $course->st_course_id; ?>">
                <option value="2">No</option>
                <option value="1">Yes</option>
              </select>
            </td>
            <td><b class="float-right" id="digi_amt_<?php //echo $course->st_course_id; ?>">0</b></td>
          </tr> -->
          <tr>
            <td><b>Total</b></td>
            <td><b class="float-right" id="main_amt_<?php echo $course->st_course_id; ?>"><?php echo $main_amt; ?></b></td>
          </tr>
        </table>
        <input type="hidden" name="main_amt" id="amt_main_<?php echo $course->st_course_id; ?>" value="<?php echo $main_amt; ?>">
        <input type="hidden" name="st_course_id" value="<?php echo $course->st_course_id; ?>">
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" onclick="student_course_payment(<?php echo $course->st_course_id; ?>)" class="btn btn-primary">Pay Now</button>
      </div>
    </div>
  </div>
</div>
<?php endif; 
endforeach; ?>
<script type="text/javascript">
function calculate(val, id, main_amt) 
{
    if(val == 2)
    {
      $('#digi_amt_'+id).html(0)
      $('#main_amt_'+id).html(main_amt);
      $('#amt_main_'+id).val(main_amt);
    }
    else
    {
      $('#digi_amt_'+id).html(<?php echo $app_setting->digital_cer_royalty_amount?>);
      $('#main_amt_'+id).html(main_amt + <?php echo $app_setting->digital_cer_royalty_amount?>);
      $('#amt_main_'+id).val(main_amt + <?php echo $app_setting->digital_cer_royalty_amount?>);

    }
}
</script>
<style type="text/css">
#my_camera
{
  border:2px dotted;
}
.bs-stepper-content
{
  padding:20px;
}
.image-wrapper {
  text-align: center;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.table-s, .table-s td, .table-s th {
  border: 1px solid black;
  padding: 5px;
}

.table-s {
  border-collapse: collapse;
  width: 100%;
}
</style>
<script language="JavaScript">
function add_new_course() 
{
  var course_id = $('#course_list').val();
  var student_id = "<?php echo $student->user_id; ?>";
  var atp_id = "<?php echo $student->user_atp; ?>";
  if(confirm("Are you sure you want Add This Course?"))
  {
      $.ajax({
        beforeSend: function() {
           $(".loader").show();
        },
        type: "POST",
        dataType:"JSON",
        async: true,
        data : {course_id:course_id, student_id:student_id, atp_id:atp_id},
        url: '<?php echo base_url(); ?>/admin/students/add_new_course_for_student',
        success: function (data) 
        {
            if(data == 1)
            {
              swal('Done!', "Course Successfully Added", 'success');
              $("#example2").load(location.href + " #example2");
              $(".loader").hide();
            }
            else
            {
              swal('Oops!', "Course Already Added", 'error');
              $(".loader").hide();
            }
            
        },
        error: function () {
          swal('Oops!', "Course Already Added", 'error');
          $(".loader").hide();
        }
      });
  }
  else
  {
      return false;
  }
}
function student_course_payment(e) 
{
  if(confirm("Are you sure you want to Confirm This Admission?"))
  {
    var is_digital_certificate = $('#is_digital_certificate_'+e).val();
    var amt_main = $('#amt_main_'+e).val();
    var course_id = e;

      $.ajax({
        beforeSend: function() {
          $('#payment_model'+e).modal('hide');
           $(".loader").show();
        },
        type: "POST",
        dataType:"JSON",
        async: true,
        data : {is_digital_certificate:is_digital_certificate, amt_main:amt_main, course_id:course_id},
        url: '<?php echo base_url(); ?>/admin/students/student_course_payment',
        success: function (data) 
        {
            swal('Done!', "Admission Done", 'success');
            $("#example2").load(location.href + " #example2");
            $(".loader").hide();
        },
        error: function () {
          $(".loader").hide();
        }
      });
  }
  else
  {
      return false;
  }
}
imgInp.onchange = evt => {
  const [file] = imgInp.files
  if (file) {
    document.getElementById('results').innerHTML = '<img height="100px" src="'+URL.createObjectURL(file)+'"/>';
  }
}
Webcam.set({
    width: 100,
    height: 140,
    image_format: 'jpeg',
    jpeg_quality: 90,
    force_flash: false
});
Webcam.attach( '#my_camera' );
function take_snapshot() {
    Webcam.snap( function(data_uri) {
        $(".image-tag").val(data_uri);
        document.getElementById('results').innerHTML = '<img src="'+data_uri+'"/>';
    });
}
function form_submit() 
{
  var name = $('#student_name').val();
  var student_mobile = $('#student_mobile').val();
  var student_course = $('#student_course').val();
  var inq_lead_source = $('#inq_lead_source').val();
  var assign_to = $('#assign_to').val();
  var inq_date = $('#inq_date').val();

  if(name == '')
  {
    swal('Opps!', 'Please Enter Student Name', 'error');
    return false;
  }
  if(student_mobile == '')
  {
    swal('Opps!', 'Please Enter Student Mobile No.', 'error');
    return false;
  }

  $( "#inq_form" ).submit();

}

document.addEventListener('DOMContentLoaded', function () {
  window.stepper = new Stepper(document.querySelector('.bs-stepper'))
});
</script>
<script src="<?php echo admin_css(); ?>plugins/bs-stepper/js/bs-stepper.min.js"></script>

<script type="text/javascript">
$('body').on('change', '#pin_code', function () {
    let pin_code = $('#pin_code').val();
    if (pin_code == 0) {
            swal ( "Oops" ,  "Please Enter Pin Code!" ,  "warning" );
        return false;
    }
    $.ajax({
      beforeSend: function() {
         $(".loader").show();
      },
      type: "GET",
      dataType:"JSON",
      async: true,
      url: '<?php echo base_url(); ?>/admin/admin/get_aadress_detaile_by_pin_code/'+pin_code,
      success: function (data) 
      {
          $('#area').html(data.area);
          $('#city').val(data.city);
          $('#state').val(data.state);
          $(".loader").hide();
      },
      error: function () {
        $(".loader").hide();
      }
    });
});
$(function () {
    $("#example2").DataTable({
      "responsive": true, "lengthChange": true, "autoWidth": false,  "searching": false, info: false, paging: false,
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)');
  });
function update_admission_date(id) 
{
  var adm_date = $('#course_admission_date_'+id).val();
  $.ajax({
    beforeSend: function() {
       $(".loader").show();
    },
    type: "POST",
    dataType:"JSON",
    async: true,
    data: {adm_date:adm_date, id:id},
    url: '<?php echo base_url(); ?>/admin/students/update_admission_date',
    success: function (data) 
    {
        swal('Done!', 'Admissio Date Successfully Update', 'success');
        $(".loader").hide();
    },
    error: function () {
      $(".loader").hide();
    }
  });
}
</script>