<?php  
include ('../includes/connection.php'); 
$student_id=$_GET['id']; 
if (isset($_POST['update'])) {  
$student_id=$_GET['id']; 
$class_id = $_POST['class_id']; 
$student_name = $_POST['student_name'];
$year_of_study = $_POST['year_of_study'];
$student_gender = $_POST['student_gender'];
$student_dob = $_POST['student_dob'];   
$p_mobile = $_POST['p_mobile'];  

$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);

move_uploaded_file($_FILES["image"]["tmp_name"], "../assets/img/picture/" . $_FILES["image"]["name"]);
$adminthumbnails = "assets/img/picture/" . $_FILES["image"]["name"];  

$sql = "UPDATE `student_srms` SET `class_id`='$class_id',`student_name`='$student_name',`student_profile` ='$adminthumbnails',`year_of_study`='$year_of_study',`student_gender`='$student_gender',`student_dob`='$student_dob',`p_mobile`='$p_mobile'  WHERE student_id='$student_id'"; 
  if (mysqli_query($conn, $sql)) {
      ?>
       <script type="text/javascript">
           alert("Student successfully updated");
       </script>
      <?php  
  //header('location:tp_student.php');
          } 
        else {
            ?>
           <script type="text/javascript">
               alert("Failed to update Student Try Again.");
           </script>
          <?php  
        }
   } 

?> 

 
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/jpg" href="../assets/img/mzumbe1.jpg">
  <title>A PLUS | PRE & PRI</title> 
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../stp_con/fontawesome-free/css/all.min.css">
  <!-- daterange picker -->
  <link rel="stylesheet" href="../stp_con/daterangepicker/daterangepicker.css">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="../stp_con/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="../stp_con/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- Tempusdominus Bootstrap 4 -->
  <link rel="stylesheet" href="../stp_con/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- Select2 -->
  <link rel="stylesheet" href="../stp_con/select2/css/select2.min.css">
  <link rel="stylesheet" href="stp_con/select2-bootstrap4-theme/select2-bootstrap4.min.css">
  <!-- Bootstrap4 Duallistbox -->
  <link rel="stylesheet" href="../stp_con/bootstrap4-duallistbox/bootstrap-duallistbox.min.css">
  <!-- BS Stepper -->
  <link rel="stylesheet" href="../stp_con/bs-stepper/css/bs-stepper.min.css">
  <!-- dropzonejs -->
  <link rel="stylesheet" href="../stp_con/dropzone/min/dropzone.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../assets/css/adminlte.min.css">
</head>
<body class="hold-transition sidebar-mini layout-fixed top-nav">
<!-- Site wrapper -->
<div class="wrapper"> 
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h5><strong>Update Student</strong></h5>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item"><a href="#">USER MANAGEMENT</a></li>
              <li class="breadcrumb-item active">Student</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>
<?php 
$query= mysqli_query($conn,"SELECT *  FROm  student_srms,class_srms WHERE student_srms.class_id=class_srms.class_id and student_srms.student_id='$student_id'")or die(mysqli_error());
$row = mysqli_fetch_array($query);   
?> 
   <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row"> 
          <!-- /.col -->
          <div class="col-md-12">
            <div class="card"> 
              <!-- /.card-header --> 
              <div class="card-body"> 
                <div class="tab-content">
                   <!-- /.tab-pane -->
                  <div class="active tab-pane" id="timeline">
                   <div class="card card-default">
                    <div class="card-header">
                      <h3 class="card-title">Update Student Detail For ID <strong><?php echo $row['student_roll_no']?></strong></h3> 
                      <div class="card-tools">
                        <button type="button" class="btn btn-tool" data-card-widget="collapse">
                          <i class="fas fa-minus"></i>
                        </button> 
                      </div>
                    </div>
                    <form action="" method="post" enctype="multipart/form-data"> 
                    <!-- /.card-header -->
                    <div class="card-body">
                      <div class="row">
                         <div class="col-sm-6">
                         <div class="form-group">
                            <label>Student Name<span style="color: red;">*</span></label>
                            <input type="text" name="student_name" id="student_name" class="form-control" value="<?php echo $row['student_name']?>" />
                          </div>
                        </div>
                       
                          <!-- /.form-group -->
                          <div class="col-sm-6">
                          <div class="form-group">
                            <label>Gender <span style="color: red;">*</span></label>
                            <div class="select2-purple"> 
                              <select class="form-control select2" name="student_gender" data-dropdown-css-class="Select a Program" style="width: 100%;" required> 
                              <option value="<?php echo $row['student_gender']?>"><?php echo $row['student_gender']?></option> 
                              <option value="Female">Female</option>
                              <option value="Male">Male</option>
                            </select>
                            </div> 
                          </div> 
                        </div>
                     
                          <!-- /.form-group -->
                        </div>
                        <!-- /.col -->
                         <div class="row"> 
                           <div class="col-sm-4">
                             <div class="form-group">
                              <label>Class Name</label>
                               <div class="select2-purple"> 
                                <?php  
                                $query = "SELECT * FROM class_srms ORDER BY class_name ASC"; 
                                $result = $conn->query($query);      
                                 ?> 
                               <select name="class_id" id="class_id" class="form-control select2"  >
                                <option value="<?php echo $row['class_id']?>"><?php echo $row['class_name']?></option>
                                  <?php 
                                if($result->num_rows > 0){ 
                                    while($row1 = $result->fetch_assoc()){  
                                        echo '<option value="'.$row1['class_id'].'">'.$row1['class_name'].'</option>'; 
                                    } 
                                }else{ 
                                    echo '<option value="">Class not available</option>'; 
                                } 
                                ?>
                              </select>
                            </div>
                            </div> 
                          </div>
                          <div class="col-sm-4">
                            <div class="form-group">
                              <label>Date of Birth<span style="color: red;">*</span></label>
                               <input type="date" name="student_dob" id="student_dob" class="form-control" value="<?php echo $row['student_dob']?>" />
                            </div>
                          </div>
                           <div class="col-sm-4">
                            <div class="form-group">
                              <label>YEAR OF STUDY <span style="color: red;">*</span></label>
                              <div class="select2-purple"> 
                              <select name="year_of_study" id="year_of_study" class="form-control select2" data-dropdown-css-class="Select a year" style="width: 100%;">
                                <option value="<?php echo $row['year_of_study']?>"><?php echo $row['year_of_study']?></option> 
                                    <option value="2020">2020</option> 
                                    <option value="2021">2021</option> 
                                    <option value="2022">2022</option>
                                    <option value="2023">2023</option> 
                                    <option value="2024">2024</option> 
                                    <option value="2025">2025</option>
                                    <option value="2026">2026</option>
                                    <option value="2027">2027</option>
                                    <option value="2028">2028</option> 
                                    <option value="2028">2029</option>   
                                </select>
                              </div> 
                            </div>
                          </div>  
                         </div>
                         <div class="row">  
                           <div class="col-sm-6">
                            <div class="form-group">
                              <label>Parent Mobile <span style="color: red;">*</span></label>
                              <div class="input-group">
                                 <div class="input-group-prepend">
                                  <span class="input-group-text"><i class="fas fa-phone"></i></span>
                               </div>
                              <input type="text" name="p_mobile" id="p_mobile" class="form-control" data-parsley-type="integer" data-parsley-minlength="10" data-parsley-maxlength="12" value="<?php echo $row['p_mobile']?>" pattern="[0]{1}[0-9]{9}" data-parsley-trigger="keyup" />
                           </div>
                            </div>
                          </div>
                          <div class="col-sm-6">
                            <div class="form-group">
                              <label>Upload pasport size <span style="color: red;">*</span></label>
                                <input type="file" class="form-control" name="image"  id="fileInput" type="file" placeholder="Change profile picture">
                              </div>
                            </div>  
                        </div>

                           <div class="modal-footer">  
                            <a class="btn btn-secondary" href="admin.php?page=student"><< Back </a>
                            <button type="submit" class="btn btn-primary" name="update">UPDATE </button>
                        </div>
                        <!-- /.row -->
                      </div> 
                    </form>
                 </div>
                   
                      <!-- /.card-body -->
                    </div>    
                  </div>
                  
                  <!-- /.tab-pane -->
                </div>
                <!-- /.tab-content -->
              </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  
<!-- ./wrapper -->
<script src="../stp_con/jquery.min.js"></script>
<script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Select2 -->
<script src="../stp_con/select2/js/select2.full.min.js"></script>
<!-- Bootstrap4 Duallistbox -->
<script src="../stp_con/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.min.js"></script>
<!-- InputMask -->
<script src="../stp_con/moment/moment.min.js"></script>
<script src="stp_con/inputmask/jquery.inputmask.min.js"></script>
<!-- date-range-picker -->
<script src="../stp_con/daterangepicker/daterangepicker.js"></script>
<!-- bootstrap color picker -->
<script src="../stp_con/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="../stp_con/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- BS-Stepper -->
<script src="../stp_con/bs-stepper/js/bs-stepper.min.js"></script>
<!-- dropzonejs -->
<script src="../stp_con/dropzone/min/dropzone.min.js"></script>
<!-- AdminLTE App -->
<script src="../assets/js/adminlte.min.js"></script>

<script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })

    //Datemask dd/mm/yyyy
    $('#datemask').inputmask('dd/mm/yyyy', { 'placeholder': 'dd/mm/yyyy' })
    //Datemask2 mm/dd/yyyy
    $('#datemask2').inputmask('mm/dd/yyyy', { 'placeholder': 'mm/dd/yyyy' })
    //Money Euro
    $('[data-mask]').inputmask()

    //Date picker
    $('#reservationdate').datetimepicker({
        format: 'L'
    }); 
    //Date range picker
    $('#reservation').daterangepicker()
    //Date range picker with time picker
    $('#reservationtime').daterangepicker({
      timePicker: true,
      timePickerIncrement: 30,
      locale: {
        format: 'MM/DD/YYYY hh:mm A'
      }
    })
    //Date range as a button
    $('#daterange-btn').daterangepicker(
      {
        ranges   : {
          'Today'       : [moment(), moment()],
          'Yesterday'   : [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
          'Last 7 Days' : [moment().subtract(6, 'days'), moment()],
          'Last 30 Days': [moment().subtract(29, 'days'), moment()],
          'This Month'  : [moment().startOf('month'), moment().endOf('month')],
          'Last Month'  : [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
        },
        startDate: moment().subtract(29, 'days'),
        endDate  : moment()
      },
      function (start, end) {
        $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'))
      }
    )

    //Timepicker
    $('#timepicker').datetimepicker({
      format: 'LT'
    })

    //Bootstrap Duallistbox
    $('.duallistbox').bootstrapDualListbox()

    //Colorpicker
    $('.my-colorpicker1').colorpicker()
    //color picker with addon
    $('.my-colorpicker2').colorpicker()

    $('.my-colorpicker2').on('colorpickerChange', function(event) {
      $('.my-colorpicker2 .fa-square').css('color', event.color.toString());
    })
  })
  // BS-Stepper Init
  document.addEventListener('DOMContentLoaded', function () {
    window.stepper = new Stepper(document.querySelector('.bs-stepper'))
  })

  // DropzoneJS Demo Code Start
  Dropzone.autoDiscover = false

  // Get the template HTML and remove it from the doumenthe template HTML and remove it from the doument
  var previewNode = document.querySelector("#template")
  previewNode.id = ""
  var previewTemplate = previewNode.parentNode.innerHTML
  previewNode.parentNode.removeChild(previewNode)

  var myDropzone = new Dropzone(document.body, { // Make the whole body a dropzone
    url: "/target-url", // Set the url
    thumbnailWidth: 80,
    thumbnailHeight: 80,
    parallelUploads: 20,
    previewTemplate: previewTemplate,
    autoQueue: false, // Make sure the files aren't queued until manually added
    previewsContainer: "#previews", // Define the container to display the previews
    clickable: ".fileinput-button" // Define the element that should be used as click trigger to select files.
  })

  myDropzone.on("addedfile", function(file) {
    // Hookup the start button
    file.previewElement.querySelector(".start").onclick = function() { myDropzone.enqueueFile(file) }
  })

  // Update the total progress bar
  myDropzone.on("totaluploadprogress", function(progress) {
    document.querySelector("#total-progress .progress-bar").style.width = progress + "%"
  })

  myDropzone.on("sending", function(file) {
    // Show the total progress bar when upload starts
    document.querySelector("#total-progress").style.opacity = "1"
    // And disable the start button
    file.previewElement.querySelector(".start").setAttribute("disabled", "disabled")
  })

  // Hide the total progress bar when nothing's uploading anymore
  myDropzone.on("queuecomplete", function(progress) {
    document.querySelector("#total-progress").style.opacity = "0"
  })

  // Setup the buttons for all transfers
  // The "add files" button doesn't need to be setup because the config
  // `clickable` has already been specified.
  document.querySelector("#actions .start").onclick = function() {
    myDropzone.enqueueFiles(myDropzone.getFilesWithStatus(Dropzone.ADDED))
  }
  document.querySelector("#actions .cancel").onclick = function() {
    myDropzone.removeAllFiles(true)
  }
  // DropzoneJS Demo Code End
</script>
 
 
