<?php  

include ('../includes/connection.php');  
if (isset($_POST['submit'])){
$class_id = $_POST['class_id'];
$teacher_roll_no = $_POST['teacher_roll_no'];   
$sub_id = $_POST['sub_id'];  
$exam_type = $_POST['exam_type']; 
$user_name = $_POST['user_name'];  
$year=date("Y");
 
 $filename = $_FILES['myfile']['name']; 
     $destination = 'upload/' . $filename; 
     $extension = pathinfo($filename, PATHINFO_EXTENSION);

     // the physical file on a temporary uploads directory on the server
     $file = $_FILES['myfile']['tmp_name'];
     $size = $_FILES['myfile']['size'];
     if (!in_array($extension, ['zip', 'pdf', 'docx']))
      {
        ?>  
        <script type="text/javascript">
         alert("You file extension must be .zip, .pdf or .docx");
        </script>
        <?php 
      } 
       elseif ($_FILES['myfile']['size'] > 1000000) { // file shouldn't be larger than
        ?>  
        <script type="text/javascript">
         alert("File too large!");
        </script>
        <?php  
       } 
       else {
         // move the uploaded (temporary) file to the specified destination
            if (move_uploaded_file($file, $destination)) {


                $query=mysqli_query($conn,"INSERT INTO `exam_report`(`teacher_roll_no`,`sub_id`, `class_id`, `user_name`,`exam_type`,`exam_file`,`year`) VALUES('$teacher_roll_no','$sub_id','$class_id','$user_name','$exam_type','$destination','$year' )");
                  
                  if($query){ 
                         ?>
                         <script type="text/javascript">
                             alert("Exam Successed Added");
                         </script>
                        <?php  
                      }  
                      else{
                        ?>  
                        <script type="text/javascript">
                         alert("Sorry Exam not Added Try Again");
                        </script>
                        <?php
                    }  
                  } else {
                ?>
                     <script type="text/javascript">
                         alert("Failed to upload file.");
                     </script>
                    <?php  
            }
         }
     }

if(isset($_GET['Id_3']))
{
$id=$_GET['Id_3'];
$status='Disabled'; 
$sql =mysqli_query($conn,"update exam_report set exam_status='$status' WHERE report_id='$id'");
header('location:admin.php?page=exam"');
}

if(isset($_GET['Id_2']))
{
$id=$_GET['Id_2'];
$status='Enable'; 
$sql =mysqli_query($conn,"update exam_report set exam_status='$status' WHERE report_id='$id'");
header('location:admin.php?page=exam"');
}  
?> 
 <!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>SARMS | SIKIRARI ACADEMIC RESURT MANAGEMENT SYSTEM</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">
   <link rel="stylesheet" type="text/css" href="../stp_con/parsley/parsley.css"/>
</head>
<body class="hold-transition sidebar-mini layout-fixed top-nav">
<!-- Site wrapper -->
<div class="wrapper"> 
   
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header btn-primary">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <a><strong>Add Examination</strong></a>
          </div> 
        </div>
      </div><!-- /.container-fluid -->
    </section>
  <br><br>
   <!-- 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="teacher">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-12">  
                    <div class="card">
                     <div class="card-header">
                      <h3 class="card-title">Examination List</h3>
                      <div class="float-right mb-2"> 
                        <a data-toggle="modal" href="#add" class="btn btn-success float-right ml-2" >
                            <script>
                               var sec = 25;
                                var time = setInterval(myTimer, 1000);

                                function myTimer() {
                                    document.getElementById('timer').innerHTML = sec + "    SEC left for Upload Exam";
                                    sec--;
                                    if (sec == -1) {
                                        clearInterval(time);
                                        alert("The examination will be start soon");
                                    }
                                }
                            </script> 
                             <div class="col-md-12 text-center">
                              Upload Before<hr>
                        <div class="countdown">
                       </div>
                       </div>
                        </a>
                        </div>
                         </div>
                         <!-- /.card-header -->
                          <div class="card-body">
                           <div class="table-responsive">
                            <table id="example1" class="table table-striped display table-bordered" >
                              <?php  
                                    $query= mysqli_query($conn,"select * from teacher_srms where user_contact_no = '$session_id'")or die(mysqli_error());
                                    $q = mysqli_fetch_array($query); 
                                    $categ="Academic Master";    
                                    ?> 
                               <?php
                              if ($q['user_type']=="$categ") {
                              ?>
                            <thead>  
                            <tr>
                                <th>#</th> 
                                <th>Subject Name</th>
                                <th>Class Name</th>
                                <th>Exam Type</th>  
                                <th>Date for Uploaded</th>
                                <th>Exam Added On</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody>
                               <?php 
                                    $i = 1;
                                   $school_query = mysqli_query($conn,"SELECT * FROM exam_report,general_subject,class_srms WHERE exam_report.sub_id=general_subject.sub_id AND exam_report.class_id=class_srms.class_id");
                                while($row = mysqli_fetch_array($school_query)){ 
                                $result=$row["exam_result_published"]; 
                             ?>  
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td> 
                              <td><?php echo $row['subject_name']; ?></td> 
                              <td><?php echo $row['class_name']; ?></td> 
                              <td><?php echo $row['exam_type']; ?></td>  
                              <td><?php echo $row['date']; ?></td>
                              <td><?php echo $row['user_name']; ?></td>
                              <td>
                            <?php
                              if($row["exam_status"] == 'Enable')
                                 {?>
                                <a href="admin.php?page=exam_time&Id_3=<?php echo $row['report_id']; ?>" onclick="return confirm('Are you sure you want to block a Exam?');" >  <button class="btn btn-primary">Enable</button>
                                <?php } else if($row["exam_status"]=='Disabled'){?>
                                  <a href="admin.php?page=exam_time&Id_2=<?php echo $row['report_id']; ?>" onclick="return confirm('Are you sure you want to active a Exam?');"><button class="btn btn-danger"> Disable</button> 
                                 <?php } ?>

                             </td>
                          <td>
                             <div class="btn-group">
                            <a  data-id='<?php echo $row['id'] ?>' href="admin.php?page=update_exam&id=<?php echo $row['report_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a>
                             <a href="delete_exam.php?del=<?php echo $row['report_id']; ?>" onclick="return confirm('Are you sure you want to delete?');" class="btn btn-danger btn-flat delete_student">
                              <i class="fas fa-trash"></i>
                            </a>  
                              <a  data-id='<?php echo $row['id'] ?>' href="admin.php?page=certificate&id=<?php echo $row['report_id']; ?>" class="btn btn-success btn-flat manage_class">
                              <i class="fas fa-download"></i>
                            </a> 
                           </div></td>

                          </tr> 
                            <?php }?>
                            </tbody>
                            <tfoot>
                            <tr>
                               <th>#</th> 
                                <th>Subject Name</th>
                                <th>Class Name</th>
                                <th>Exam Type</th>  
                                <th>Date for Uploaded</th>
                                <th>Exam Added On</th>
                                <th>Status</th>
                                <th>Action</th>
                            </tr>
                          </tfoot>
                           <?php }else{ ?>
                            <thead>  
                            <tr>
                                <th>#</th> 
                                <th>Subject Name</th>
                                <th>Class Name</th>
                                <th>Exam Type</th> 
                                <th>Exam Added On</th>
                                <th>Action</th>
                            </tr>
                            </thead>
                            <tbody>
                               <?php 
                                    $i = 1;
                                    $reg_number=$q['teacher_roll_no'];
                                   $school_query = mysqli_query($conn,"SELECT * FROM exam_report,general_subject,class_srms WHERE exam_report.sub_id=general_subject.sub_id AND exam_report.class_id=class_srms.class_id AND exam_report.teacher_roll_no='$reg_number'");
                                while($row = mysqli_fetch_array($school_query)){ 
                             ?>  
                            <tr>
                              <td class="text-center"><?php echo $i++ ?></td> 
                             <td><?php echo $row['subject_name']; ?></td> 
                              <td><?php echo $row['class_name']; ?></td> 
                              <td><?php echo $row['exam_type']; ?></td>  
                              <td><?php echo $row['date']; ?></td> 
                              <td> <div class="btn-group">
                                <a  data-id='<?php echo $row['id'] ?>' href="admin.php?page=update_exam&id=<?php echo $row['report_id']; ?>" class="btn btn-primary btn-flat manage_class">
                              <i class="fas fa-edit"></i>
                            </a> 
                           </div></td>   
                          </tr> 
                            <?php }?>
                            </tbody>
                            <tfoot>
                            <tr>
                               <th>#</th> 
                                <th>Subject Name</th>
                                <th>Class Name</th>
                                <th>Exam Type</th> 
                                <th>Exam Added On</th>
                                <th>Action</th> 
                            </tr>
                          </tfoot>
                           <?php } ?>
                        </table>
                        <div class="modal fade" id="add">
                          <div class="modal-dialog">
                            <form method="post" action="" enctype="multipart/form-data">
                                <div class="modal-content">
                                  <div class="modal-header">
                                      <h4 class="modal-title" id="modal_title">Add Exam Data</h4>
                                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                                  </div>
                                  <div class="modal-body">
                                  <span id="form_message"></span> 
                                  <div class="form-group">
                                        <label>Subject Name</label>
                                        <?php  
                                        $query = "SELECT * FROM general_subject ORDER BY subject_name ASC"; 
                                         $result = $conn->query($query);      
                                         ?> 
                                        <select name="sub_id" id="sub_id" class="form-control select2" data-dropdown-css-class="Select a Subject" style="width: 100%;" required>
                                            <option value="">Select Subject</option>
                                            <?php 
                                            if($result->num_rows > 0){ 
                                                while($row = $result->fetch_assoc()){  
                                                    echo '<option value="'.$row['sub_id'].'">'.$row['subject_name'].'</option>'; 
                                                } 
                                            }else{ 
                                                echo '<option value="">Subject not available</option>'; 
                                            } 
                                          ?>
                                        </select> 
                                    </div>
                                  <div class="form-group">
                                    <label>Class <span style="color: red;">*</span></label>
                                   <?php  
                                        // Fetch all the region data 
                                        $query = "SELECT * FROM class_srms WHERE class_status='Enable' ORDER BY class_name ASC"; 
                                        $result = $conn->query($query); 
                                    ?>
                                    <div class="select2-purple"> 
                                      <select class="form-control select2" id="class_id" name="class_id" data-dropdown-css-class="Select a Region" style="width: 100%;" required>
                                        <option selected="selected" value="_">Select a Class</option>
                                    <?php 
                                      if($result->num_rows > 0){ 
                                          while($row = $result->fetch_assoc()){  
                                              echo '<option value="'.$row['class_id'].'">'.$row['class_name'].'</option>';  
                                          } 
                                      }else{ 
                                          echo '<option value="">Class not available</option>'; 
                                      } 
                                      ?>
                                    </select>
                                    </div> 
                                  </div>  
                                  <div class="form-group">
                                    <label>Exam Type <span style="color: red;">*</span></label>
                                    <div class="select2-purple"> 
                                      <select class="form-control select2" id="exam_type" name="exam_type" data-dropdown-css-class="Select a District" style="width: 100%;" >
                                      <option  value="">Select Examination Type</option>
                                      <option  value="MONTHLY TEST">MONTHLY TEST</option> 
                                      <option  value="MID TERM">MID TERM</option> 
                                      <option  value="TERMINAL EXAMINATION">TERMINAL EXAMINATION</option> 
                                      <option  value="ANNUAL EXAMINATION">ANNUAL EXAMINATION</option>  
                                    </select>
                                    </div>  
                                  </div>  
                                   <div class="col-sm-12">
                                    <div class="form-group">
                                    <label>Select File <span style="color: red;">*</span></label>
                                    <div class="fallback">
                                        <input type="file" name="myfile"  required accept=".pdf"/>
                                    </div>
                                  </div>
                                </div>  
                                  </div>
                                <?php  
                                   $query= mysqli_query($conn,"select * from teacher_srms where user_contact_no = '$session_id'")or die(mysqli_error());
                                  $q1 = mysqli_fetch_array($query);     
                                  ?>  
                                               
                                  <input type="hidden" name="user_name" value=" <?php echo $q1['user_name']; ?>"> 
                                   <input type="hidden" name="teacher_roll_no" value="<?php echo $q1['teacher_roll_no']; ?>"> 
                                  <div class="modal-footer">  
                                      <button type="submit" name="submit" class="btn btn-success">ADD</button>
                                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                  </div>
                                </div>
                            </form>
                            </div>
                       </div><!-- /.modal -->
                       </div>
                     </div>
                    </div> <!-- end card body-->
                    </div> <!-- end card --> 
                    </div>
                  <!-- /.card -->
                  </div>
                 </div> 
                </div>
                <!-- /.tab-content -->
             </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
 <script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="../stp_con/datatables/jquery.dataTables.min.js"></script>
<script src="../stp_con/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../stp_con/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../stp_con/jszip/jszip.min.js"></script> 
<script src="../stp_con/pdfmake/pdfmake.min.js"></script>
<script src="../stp_con/pdfmake/vfs_fonts.js"></script> 
<script src="../stp_con/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.colVis.min.js"></script>
<script type="text/javascript" src="../assets/js/jquery.countdown.js"></script>
<script src="../assets/js/adminlte.min.js"></script> 

<!-- Select2 -->
<script src="../stp_con/select2/js/select2.full.min.js"></script>
 
<script src="../stp_con/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
 
</body>

</html>
<script>
  $(function() {
    $(".countdown").countdown({
        date: "June 29, 2025 12:00",
        refresh: 1000,
        offset: 0,
        onEnd: function() {
          window.location.assign("admin.php?page=exam_time_e");
           
        }
    });
});
    </script>
 <script>
  $(function () {
    $("#example1").DataTable({
      "responsive": false, "lengthChange": true, "autoWidth": false,
      "buttons": ["copy", "csv", "excel",  "print", "colvis"]
    }).buttons().container().appendTo('#example1_wrapper .col-md-6:eq(0)'); 
  });
   $(function () {
    $("#example2").DataTable({
      "responsive": false, "lengthChange": true, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example2_wrapper .col-md-6:eq(0)'); 
  });
</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")
  })


    $('.toastrDefaultSuccess').click(function() {
      toastr.success('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.')
    });
    $('.toastrDefaultInfo').click(function() {
      toastr.info('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.')
    });
    $('.toastrDefaultError').click(function() {
      toastr.error('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.')
    });
    $('.toastrDefaultWarning').click(function() {
      toastr.warning('Lorem ipsum dolor sit amet, consetetur sadipscing elitr.')
    });

  // 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>
<script>
$(document).ready(function(){
    $('#login_form').parsley();
     $('#login_form2').parsley();
     $('#login_form3').parsley();
     $('#login_form4').parsley();
     $('#login_form5').parsley();
     $('#login_form6').parsley(); 
});

</script>
 