<?php  
include ('../includes/connection.php');
$ex_id=$_GET['Id_2'];


if (isset($_POST['add_marks'])){
$student_roll_no = $_POST['student_roll_no']; 
$class_id = $_POST['class_id']; 
$exam_id = $_POST['exam_id']; 
$subject_id = $_POST['subject_id']; 
$marks = $_POST['marks'];
$year_of_study = date("Y"); 
$year=date("Y");  
$result_added_by = $_POST['result_added_by'];
$teacher_roll_no = $_POST['teacher_roll_no'];

$sub_identity= mysqli_query($conn,"SELECT identity FROM general_subject where sub_id='$subject_id'")or die(mysqli_error());
$sub_i = mysqli_fetch_array($sub_identity);
$check_sub=$sub_i['identity'];
 
  
$Level= mysqli_query($conn,"SELECT * FROM class_srms where class_id='$class_id'")or die(mysqli_error());
$level_class = mysqli_fetch_array($Level);
$check_level=$level_class['level'];

if ($check_level=="O-level") {
if ($marks>= 75) {
        $T_point=1; 
      }elseif ($marks>= 65) {
        $T_point=2; 
      }elseif ($marks>= 45) {
        $T_point=3; 
      }elseif ($marks>= 30) {
        $T_point=4; 
      }else{
        $T_point=5; 
      }   
if ($marks>= 75) {
        $grade="A"; 
      }elseif ($marks>= 65) {
        $grade="B"; 
      }elseif ($marks>= 45) {
        $grade="C"; 
      }elseif ($marks>= 30) {
        $grade="D"; 
      }else{
        $grade="F"; 
}
 if ($marks>= 75) {
        $pass_marks="EXCELLENT"; 
      }elseif ($marks>= 65) {
        $pass_marks="VERY GOOD"; 
      }elseif ($marks>= 45) {
        $pass_marks="GOOD"; 
      }elseif ($marks>= 30) {
        $pass_marks="AVERAGE"; 
      }else{
        $pass_marks="FAIL"; 
 }
}else{
if ($marks>= 80) {
        $T_point=1; 
      }elseif ($marks>= 70) {
        $T_point=2; 
      }elseif ($marks>= 60) {
        $T_point=3; 
      }elseif ($marks>= 50) {
        $T_point=4; 
      }elseif ($marks>= 40) {
        $T_point=5; 
      }elseif ($marks>= 35) {
        $T_point=6; 
      }else{
        $T_point=7; 
      }   
if ($marks>= 80) {
        $grade="A"; 
      }elseif ($marks>= 70) {
        $grade="B"; 
      }elseif ($marks>= 60) {
        $grade="C"; 
      }elseif ($marks>= 50) {
        $grade="D"; 
      }elseif ($marks>= 40) {
        $grade="E"; 
      }elseif ($marks>= 35) {
        $grade="S"; 
      }else{
        $grade="F"; 
}
 if ($marks>= 80) {
        $pass_marks="EXCELLENT"; 
      }elseif ($marks>= 70) {
        $pass_marks="VERY GOOD"; 
      }elseif ($marks>= 60) {
        $pass_marks="GOOD"; 
      }elseif ($marks>= 50) {
        $pass_marks="AVERAGE"; 
      }elseif ($marks>= 40) {
        $pass_marks="SARTISFACTORY"; 
      }elseif ($marks>= 35) {
        $pass_marks="SUBSIDIARY"; 
      }else{
        $pass_marks="FAIL"; 
 }
}

$student= mysqli_query($conn,"SELECT subject_id,class_id,student_roll_no,exam_id FROM marks_srms WHERE class_id='$class_id' and exam_id='$exam_id' AND subject_id='$subject_id' and student_roll_no='$student_roll_no'")or die(mysqli_error());
$row1 = mysqli_fetch_array($student);
$check=$row1['subject_id'];

if ($check!=$subject_id) {
    
$query=mysqli_query($conn,"INSERT INTO `marks_srms`(`teacher_roll_no`, `class_id`, `exam_id`, `grade`, `pass_marks`, `subject_id`, `student_roll_no`, `marks`,`identity_sub`, `point`, `result_added_by`, `year_of_study`, `Year`) VALUES ('$teacher_roll_no', '$class_id','$exam_id','$grade','$pass_marks','$subject_id','$student_roll_no','$marks','$check_sub','$T_point','$result_added_by','$year_of_study','$year')"); 
  if($query){  
         ?>
         <script type="text/javascript">
             alert("Result Success Fully Added");
         </script>
        <?php  
      }  
      else{
        ?>  
        <script type="text/javascript">
         alert("Result not Success please try again");
        </script>
        <?php
    }
    }else{
      ?>
         <script type="text/javascript">
             alert("Sorry Result Already added");
         </script>
    <?php 
  } 
  
}

?> 
<?php

if (isset($_POST['add_list_marks'])) {

    $class_id = $_POST['class_id'];
    $exam_id = $_POST['exam_id'];
    $subject_id = $_POST['subject_id'];
    $result_added_by = $_POST['result_added_by'];
    $teacher_roll_no = $_POST['teacher_roll_no'];

    $year_of_study = date("Y");
    $year = date("Y");

    // SUBJECT IDENTITY
    $sub_identity = mysqli_query($conn,
    "SELECT identity FROM general_subject
    WHERE sub_id='$subject_id'");

    $sub_i = mysqli_fetch_array($sub_identity);
    $check_sub = $sub_i['identity'];

    // CLASS LEVEL
    $Level = mysqli_query($conn,
    "SELECT * FROM class_srms
    WHERE class_id='$class_id'");

    $level_class = mysqli_fetch_array($Level);
    $check_level = $level_class['level'];

    // LOOP ALL STUDENTS
    foreach($_POST['student_roll_no'] as $key => $student_roll_no){

    $marks = $_POST['marks'][$key];

    // Skip empty marks
    if($marks == ""){
        continue;
    }

    /* =========================
       O-LEVEL GRADING
    ========================= */

    if ($check_level=="O-level") {

        if ($marks>=75){
            $T_point=1;
            $grade="A";
            $pass_marks="EXCELLENT";

        }elseif ($marks>=65){
            $T_point=2;
            $grade="B";
            $pass_marks="VERY GOOD";

        }elseif ($marks>=45){
            $T_point=3;
            $grade="C";
            $pass_marks="GOOD";

        }elseif ($marks>=30){
            $T_point=4;
            $grade="D";
            $pass_marks="AVERAGE";

        }else{
            $T_point=5;
            $grade="F";
            $pass_marks="FAIL";
        }

    } else {

        /* =========================
           A-LEVEL GRADING
        ========================= */

        if ($marks>=80){
            $T_point=1;
            $grade="A";
            $pass_marks="EXCELLENT";

        }elseif ($marks>=70){
            $T_point=2;
            $grade="B";
            $pass_marks="VERY GOOD";

        }elseif ($marks>=60){
            $T_point=3;
            $grade="C";
            $pass_marks="GOOD";

        }elseif ($marks>=50){
            $T_point=4;
            $grade="D";
            $pass_marks="AVERAGE";

        }elseif ($marks>=40){
            $T_point=5;
            $grade="E";
            $pass_marks="SATISFACTORY";

        }elseif ($marks>=35){
            $T_point=6;
            $grade="S";
            $pass_marks="SUBSIDIARY";

        }else{
            $T_point=7;
            $grade="F";
            $pass_marks="FAIL";
        }
    }

    // CHECK RECORD
    $check_query = mysqli_query($conn,
    "SELECT * FROM marks_srms
    WHERE
    class_id='$class_id'
    AND exam_id='$exam_id'
    AND subject_id='$subject_id'
    AND student_roll_no='$student_roll_no'");

    // UPDATE
    if(mysqli_num_rows($check_query) > 0){

        $update = mysqli_query($conn,
        "UPDATE marks_srms SET

        teacher_roll_no='$teacher_roll_no',
        grade='$grade',
        pass_marks='$pass_marks',
        marks='$marks',
        identity_sub='$check_sub',
        point='$T_point',
        result_added_by='$result_added_by',
        year_of_study='$year_of_study',
        Year='$year'

        WHERE
        class_id='$class_id'
        AND exam_id='$exam_id'
        AND subject_id='$subject_id'
        AND student_roll_no='$student_roll_no'
        ");

        if(!$update){
            die(mysqli_error($conn));
        }

    } else {

        // INSERT
        $insert = mysqli_query($conn,
        "INSERT INTO marks_srms
        (
        teacher_roll_no,
        class_id,
        exam_id,
        grade,
        pass_marks,
        subject_id,
        student_roll_no,
        marks,
        identity_sub,
        point,
        result_added_by,
        year_of_study,
        Year
        )

        VALUES
        (
        '$teacher_roll_no',
        '$class_id',
        '$exam_id',
        '$grade',
        '$pass_marks',
        '$subject_id',
        '$student_roll_no',
        '$marks',
        '$check_sub',
        '$T_point',
        '$result_added_by',
        '$year_of_study',
        '$year'
        )");

        // SHOW SQL ERROR
        if(!$insert){
            die(mysqli_error($conn));
        }
    }
}

    echo "<script>alert('All Results Saved Successfully');</script>";
    echo $student_roll_no." - ".$marks."<br>";
}
 
?>
<!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 bg-info" style=" color: white;">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <a><strong>Level For Examination Result</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">
              <div class="card-header p-2">
                <ul class="nav nav-pills ">
                       <?php  
                        $query= mysqli_query($conn,"SELECT * FROM exam_srms,class_srms where exam_srms.class_id=class_srms.class_id AND exam_srms.exam_id='$ex_id'")or die(mysqli_error());
                          $class1 = mysqli_fetch_array($query);
                          $class_id=$class1['class_id']; 

                          $sub= mysqli_query($conn,"SELECT * FROM general_subject,subject,teacher_course where general_subject.sub_id=subject.sub_id AND general_subject.sub_id=teacher_course.code and subject.class_id=teacher_course.class_id AND subject.class_id='$class_id' AND teacher_course.teacher_roll_no='$teacher_roll_no'")or die(mysqli_error());
                            $sub_1 = mysqli_fetch_array($sub);
                            $subject_name=$sub_1['subject_name'];
                           
                            $fit = mysqli_query($conn,"SELECT * FROM marks_srms WHERE exam_id='$ex_id' AND class_id='$class_id'");
                                 $level_year = mysqli_fetch_array($fit);
                                 $check_year=$level_year['year_of_study'];
                                 $subject_id=$level_year['subject_id'];
                            
                              if(isset($_POST['filta']))
                              { 
                                $year = $_POST['year'];  
                                if ($check_year==$year) {
                               ?>
                                <script type="text/javascript"> 
                                window.location.href = 'views/report.php?Id_1=<?php echo $class_id ?>&Id_2=<?php echo $subject_id ?>&Id_3=<?php echo $year ?>&Id_4=<?php echo $ex_id ?>';
                               </script>
                              <?php 
                              }else{
                                  ?>
                                  <script type="text/javascript">
                                     alert("Sorry! The year selected is not Uploaded");
                                 </script>
                                <?php  
                                }
                            }
                          ?>    
                         <li class="nav-item "><a class="nav-link active" href="#class_one" data-toggle="tab"><?php echo $class1['exam_name']; ?>-<?php echo $class1['class_name']; ?></a></li>  
                        <?php 
                        $q = mysqli_fetch_array($query1); 
                        $categ="Academic Master";    
                    ?> 
                </ul>
              </div>

              <!-- /.card-header --> 
              <div class="card-body"> 
              <div class="tab-content">
              <!-- /.tab-pane -->
              <div class="active tab-pane" id="class_one">
              <div class="container-fluid">
                <div class="row">
                  <div class="col-sm-12">  
                    <div class="card"> 
                      <div class="card-header">
                      <h3 class="card-title">Examination Result List For <b style="color: orange;"><?php echo $subject_name; ?></b></h3>
                      <div class="float-right mb-2">
                        <a data-toggle="modal" href="#class_2" class="btn btn-info btn-xs float-right ml-2" >
                            <i class="fa fa-plus"></i> Add Result Here
                        </a> 
                         <a data-toggle="modal" href="#class_1" class="btn btn-secondary btn-xs float-right ml-2" >
                            <i class="fa fa-list"></i> Add list of Result
                        </a>
                        <a data-toggle="modal" href="#exel" class="btn btn-success btn-xs float-right ml-2" >
                            <i class="fa fa-upload"></i> Upload CSV File
                        </a>
                       
                        </div>
                          </div>  
                       <!-- /.card-header -->
                        <div class="card-body">
                        <div class="table-responsive"> 
                            <table id="example1" class="table table-striped display table-bordered">
                                <thead>
                                  <tr>
                                      <th>#</th>
                                      <th>ADM NUMBER <?php echo $row['marks']; ?></th> 
                                      <th>Student Name</th> 
                                      <th>Student Gender</th>
                                      <th>Marks</th> 
                                      <th>Grade</th>
                                      <th>YEAR</th> 
                                  </tr>
                                  </thead>
                          <tbody>  
                           <?php  
                            $i = 1; 
                            $selecte5_1 = mysqli_query($conn,"SELECT * FROM student_srms,marks_srms WHERE student_srms.student_roll_no=marks_srms.student_roll_no AND marks_srms.class_id='$class_id' AND marks_srms.exam_id='$ex_id' AND marks_srms.teacher_roll_no = '$teacher_roll_no';");
                             while($row = mysqli_fetch_array($selecte5_1)){  
                            ?> 
                           <tr>
                            <td class="text-center"><?php echo $i++ ?></td>
                            <td ><?php echo $row['student_roll_no']; ?></td>
                            <td ><?php echo $row['student_name']; ?></td>
                            <td ><?php echo $row['student_gender']; ?></td>
                            <td class="text-center"><?php echo $row['marks']; ?></td>
                            <td class="text-center"><?php echo $row['grade']; ?></td> 
                            <td class="text-center"><?php echo $row['Year']; ?></td>  
                        </tr>
                      <?php } ?>
                      </tbody> 
                           <tfoot>
                             <tr> 
                                <th>#</th>
                                <th>ADM NUMBER</th> 
                                <th>Student Name</th>
                                <th>Student Gender</th>
                                <th>Marks</th> 
                                <th>Grade</th>
                                <th>YEAR</th> 
                            </tr> 
                          </tfoot> 
                        </table>
                            <!-- /.add class one result -->
                       <div id="class_1" class="modal fade ">
                        <div class="modal-dialog modal-lg">
                          <form method="post" action="" id="login_form">
                              <div class="modal-content">
                                <div class="modal-header bg-info">
                                    <h4 class="modal-title" id="modal_title"><i class="nav-icon fas fa-bullhorn"></i>  Upload Result For <?php echo $subject_name; ?></h4>
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                </div> 
                                <div class="modal-body"> 
                                
                                   <div class="row">
                                    <div class="col-md-6">
                                      <div class="info-box card-info card-outline">
                                        <span class="info-box-icon bg-info"><i class="fas fa-university"></i></span>

                                        <div class="info-box-content">
                                          <span class="info-box-text">Class</span> 
                                          <?php  
                                          $ToDayyear=date("Y"); 
                                            $query = mysqli_query($conn,"SELECT * FROM class_srms where class_id='$class_id' AND  class_status='Enable' ORDER BY class_name ASC");
                                            $clas = mysqli_fetch_array($query); 
                                            ?> 
                                          <span class="info-box-number"><?php echo $clas['class_name']; ?></span>
                                        </div>
                                        <!-- /.info-box-content -->
                                      </div>
                                      <!-- /.info-box -->
                                    </div>
                                    <!-- /.col -->
                                    <div class="col-md-6 ">
                                      <div class="info-box card-success card-outline"> 
                                        <span class="info-box-icon bg-success"><i class="fas fa-users"></i></span> 
                                        <div class="info-box-content">
                                          <span class="info-box-text">Student Registered</span>
                                          <?php  
                                          $ToDayyear=date("Y"); 
                                            $tutor = mysqli_query($conn,"SELECT count(student_roll_no) as user_name FROM student_srms where class_id= '$class_id' and year_of_study='$ToDayyear'and student_status ='Enable'");
                                            $sel = mysqli_fetch_array($tutor); 
                                            ?> 
                                          <span class="info-box-number"><?php echo $sel['user_name']; ?></span>
                                        </div>
                                        <!-- /.info-box-content --> 
                                    </div>
                                      <!-- /.info-box -->
                                    </div> 
                                  </div>
                                    <div class="form-group"> 
                                      </div>   
                                        <?php   
                                         $code= mysqli_query($conn,"SELECT code FROM teacher_course where class_id = '$class_id' AND teacher_roll_no='$teacher_roll_no'")or die(mysqli_error());
                                        $code_1 = mysqli_fetch_array($code);     
                                        ?>    
                                        <input type="hidden" name="subject_id" value="<?php echo $code_1['code']; ?>"> 
                                        <?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="class_id" value="<?php echo $clas['class_id']; ?>">
                                        <input type="hidden" name="teacher_roll_no" value="<?php echo $q1['teacher_roll_no']; ?>">            
                                        <input type="hidden" name="result_added_by" value="<?php echo $q1['user_name']; ?>">  
                                        <input type="hidden" name="exam_id" value="<?php echo $ex_id; ?>">  
                                      </div> 
                                    <div class="col-lg-12"> 
                                        <div class="card-body table-responsive p-0" style="height: 400px;">
                                            <table class="table table-bordered overflow-hidden" id="tab_logic">
                                                <thead>
                                                    <tr class="single-item">
                                                        <th class="text-center">#</th>
                                                        <th class="text-center wd-450">R-NUMBER</th>
                                                        <th class="text-center wd-150">Candidate Name</th>
                                                        <th class="text-center wd-150">Score</th> 
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                 <?php

                                              // GET STUDENTS
                                              $students = mysqli_query($conn,
                                              "SELECT  *  FROm  student_srms,class_srms,students_to_subject WHERE student_srms.class_id=class_srms.class_id AND student_srms.student_roll_no=students_to_subject.student_roll_no AND class_srms.class_id='$class_id' and student_srms.year_of_study='$ToDayyear' and student_srms.student_status ='Enable' ORDER BY student_srms.student_name ASC");

                                              $i = 1;

                                              while($row2 = mysqli_fetch_array($students)){

                                              ?>

                                              <tr id="addr0">

                                              <td><?php echo $i++; ?></td>

                                              <td><?php echo $row2['student_roll_no']; ?></td>

                                              <td><?php echo $row2['student_name']; ?></td>

                                              <td>
                                                <input type="hidden"name="student_roll_no[]"value="<?php echo $row2['student_roll_no']; ?>">
                                              <input type="number" name="marks[]" id="marks"  class="form-control" min="0" max="100"   placeholder="Marks <= 100"> 
                                              <div class="status"></div>

                                              </td> 

                                              </tr>

                                              <?php } ?>
                                                    
                                                </tbody>
                                            </table>
                                        </div> 
                                    </div>  
                                    <div class="modal-footer">  
                                    <button type="submit" name="add_list_marks" class="btn btn-info">ADD RESULT</button>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                </div>
                              </div> 
                          </form>
                        </div>
                    </div>
                    <div id="class_2" class="modal fade">
                        <div class="modal-dialog">
                          <form method="post" action="" id="login_form">
                              <div class="modal-content">
                                <div class="modal-header bg-info">
                                    <h4 class="modal-title" id="modal_title"><i class="nav-icon fas fa-bullhorn"></i>  Upload Result</h4>
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                </div> 
                                <div class="modal-body"> 
                                <?php  
                                  $query = "SELECT * FROM class_srms where class_id='$class_id' AND  class_status='Enable' ORDER BY class_name ASC"; 
                                  $result = $conn->query($query);      
                                   ?>
                                   
                                    <div class="form-group">
                                        <label>Class <span style="color: red;">*</span></label>
                                         <?php 
                                          if($result->num_rows > 0){ 
                                              while($row = $result->fetch_assoc()){  
                                                  echo '
                                                  <input type="hidden" name="class_id" value="'.$row['class_id'].'" class="form-control" required>
                                                  <input type="text" value="'.$row['class_name'].'" class="form-control" disabled>'; 
                                              } 
                                          }else{ 
                                              echo '<input type="text" disabled class="form-control" placeholder="Class not available Contuct to admin">'; 
                                          } 
                                        ?>
                                      </div>  
                                        <div class="form-group">
                                            <label>Student Name<span style="color: red;">*</span></label>
                                            <div class="select2-purple"> 
                                            <?php  
                                              $query = "SELECT  *  FROm  student_srms,class_srms,students_to_subject WHERE student_srms.class_id=class_srms.class_id AND student_srms.student_roll_no=students_to_subject.student_roll_no AND class_srms.class_id='$class_id' and student_srms.year_of_study='$ToDayyear' and student_srms.student_status ='Enable' ORDER BY student_srms.student_name ASC"; 
                                              $result = $conn->query($query);         
                                               ?> 

                                              <select name="student_roll_no" class="form-control select2" style="width: 100%;" required>
                                                <option value="" disabled selected>-- Select Student --</option> 
                                                  <?php 
                                                  if($result->num_rows > 0){
                                                   
                                                      while($row = $result->fetch_assoc()){  
                                                          echo '<option value="'.$row['student_roll_no'].'">'.$row['student_name'].' | '.$row['student_roll_no'].'</option>';

                                                      }
                                                     
                                                  }else{ 
                                                      echo '<option value="">Student not available</option>'; 
                                                  } 
                                                ?>
                                            </select>
                                          </div>
                                        </div> 
                                        <?php   
                                         $code= mysqli_query($conn,"SELECT code FROM teacher_course where class_id = '$class_id' AND teacher_roll_no='$teacher_roll_no'")or die(mysqli_error());
                                        $code_1 = mysqli_fetch_array($code);     
                                        ?>    
                                        <input type="hidden" name="subject_id" value="<?php echo $code_1['code']; ?>"> 
                                        <?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="teacher_roll_no" value="<?php echo $q1['teacher_roll_no']; ?>">            
                                        <input type="hidden" name="result_added_by" value="<?php echo $q1['user_name']; ?>">  
                                        <input type="hidden" name="exam_id" value="<?php echo $ex_id; ?>"> 
                                          <div class="form-group">
                                          <label>SCORE <span style="color: red;">*</span></label>
                                           <input type="text" name="marks" id="marks" class="form-control" required data-parsley-max="100" required data-parsley-type="integer"  data-parsley-trigger="keyup"  placeholder="Hint: Marks <= 100"/>
                                          </div> 
                                      </div>
                                    <div class="modal-footer">  
                                    <button type="submit" name="add_marks" class="btn btn-info">ADD RESULT</button>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                </div>
                              </div> 
                          </form>
                        </div>
                    </div>
                           <div id="exel" class="modal fade">
                        <div class="modal-dialog">
                          <form action="views/import.php" method="post" name="upload_excel" enctype="multipart/form-data">
                              <div class="modal-content">
                                <div class="modal-header">
                                    <h4 class="modal-title" id="modal_title">Upload Result</h4>
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                </div> 
                                <div class="modal-body"> 
                                <?php  
                                  $query = "SELECT * FROM class_srms where class_id='$class_id' AND  class_status='Enable' ORDER BY class_name ASC"; 
                                  $result = $conn->query($query);      
                                   ?>
                                   
                                    <div class="form-group">
                                        <label>Class <span style="color: red;">*</span></label>
                                         <?php 
                                          if($result->num_rows > 0){ 
                                              while($row = $result->fetch_assoc()){  
                                                  echo '
                                                  <input type="hidden" name="class_id" value="'.$row['class_id'].'" class="form-control" required>
                                                  <input type="text" value="'.$row['class_name'].'" class="form-control" disabled>'; 
                                              } 
                                          }else{ 
                                              echo '<input type="text" disabled class="form-control" placeholder="Class not available Contuct to admin">'; 
                                          } 
                                        ?>
                                      </div> 
                                      <div class="form-group">
                                          <label>Choose File <span style="color: red;">*</span></label>
                                        
                                          <input type="file" name="file" accept=".xls,.xlsx,.CSV" id="file" class="form-control" placeholder="Select excel file.." required>
                                        </div>
                                        <?php   
                                         $code= mysqli_query($conn,"SELECT code FROM teacher_course where class_id = '$class_id' AND teacher_roll_no='$teacher_roll_no'")or die(mysqli_error());
                                        $code_1 = mysqli_fetch_array($code);     
                                        ?>    
                                        <input type="hidden" name="subject_id" value="<?php echo $code_1['code']; ?>"> 
                                        <?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="teacher_roll_no" value="<?php echo $q1['teacher_roll_no']; ?>">   
                                          <input type="hidden" name="exam_id" value="<?php echo $ex_id; ?>"> 
                                        <input type="hidden" name="result_added_by" value="<?php echo $q1['user_name']; ?>"> 
                                    <div class="modal-footer">  
                                    <button type="submit" id="submit" name="Import" class="btn btn-success">UPLOAD AND IMPORT</button>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                </div>
                              </div> 
                          </form>
                        </div>
                    </div>
                

                 </div>
                 </div> 
              </div> <!-- end card body-->
            </div> <!-- end card --> 
            </div>
            <!-- /.card -->
          </div>
          </div>
          <!-- END OF CLASS ONE --->
    
 

             </div>
                <!-- /.tab-content -->
             </div><!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
   <!-- /.content-wrapper -->
 <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 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 () {
    $("#example1").DataTable({
      "responsive": false, "lengthChange": true, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
    }).buttons().container().appendTo('#example1_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>
