<?php
ob_start();
 session_start();
require_once('operations.php');
require_once('login.php');

$month = date("n");
$year = date("Y");

if($month == 19 || $month == 101 || $month == 11 || $month == 12){

$session1 = $year . "/". ($year + 1);
$term1 = "First";
}


else if($month == 1 || $month == 2 || $month == 3  || $month == 4 || $month == 5){
$session1 = ($year-1)."/".$year;
 $term1 = "Second";
//$term1 = "First";
}

 else if($month == 15 || $month == 6 || $month == 7 || $month == 8 || $month == 9  || $month == 10){
$session1 = ($year-1)."/".$year;
$term1 = "Third";
 //$term1 = "Second";
}

$db = new Operations();
$db2 = new Login();


if (!isset($_SESSION['mod'])) {
   header( "Location: index.php" );
}

$username = $_SESSION['mod'];

$db2->getUsersPassword2($username);


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

    $old = strtoupper($_POST['old']);

    $oldpass = $db2->password;


    $password2 = $db2->getUsersPassword($username);
    $role = $db2->role;
    
    
    $verfy = password_verify($old,$password2);
    
    //$verfy = password_verify($_POST['password'],$password2);
    
    if($verfy && ($role == 'admin')){
	
	



    $password = strtoupper($_POST['password']);
    $password1 = $_POST['password1'];
    
    
        
        
            
            
            
           if(!$db2->updateStaffLoginDetails($username,$password)){
              
            
              
              ?>
              
            <script>alert('Password Updated Successfully');</script>  
              
              <?php
              }
            
            else {
                
                ?>
              <script>alert('Error Updating Password');</script>   
                <?php
                
                }

               
            }
            
            else {

                ?>
                <script>alert('old password is wrong');</script>   
                  <?php
                  
                  }

            }
        


   
    



?>
<!--
=========================================================
* Argon Dashboard - v1.2.0
=========================================================
* Product Page: https://www.creative-tim.com/product/argon-dashboard


* Copyright  Creative Tim (http://www.creative-tim.com)
* Coded by www.creative-tim.com



=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-->
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Start your development with a Dashboard for Bootstrap 4.">
  <meta name="author" content="Creative Tim">
  <title>Exam App</title>
  <!-- Favicon 
  <link rel="icon" href="assets/img/brand/favicon.png" type="image/png">
  -->
  <!-- Fonts -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700">
  <!-- Icons -->
  <link rel="stylesheet" href="assets/vendor/nucleo/css/nucleo.css" type="text/css">
  <link rel="stylesheet" href="assets/vendor/@fortawesome/fontawesome-free/css/all.min.css" type="text/css">
  <!-- Page plugins -->
  <!-- Argon CSS -->
  <link rel="stylesheet" href="assets/css/argon.css?v=1.2.0" type="text/css">

  <style>
            .field-icon {
  float: right;
  margin-left: -25px;
  margin-top: -25px;
  position: relative;
  z-index: 2;
}
            </style>
            <script>



function checkPass()
{
    //Store the password field objects into variables ...
    var pass1 = document.getElementById('password');
    var pass2 = document.getElementById('password1');
    //Store the Confimation Message Object ...
    var message = document.getElementById('confirmMessage');
    //Set the colors we will be using ...
    var goodColor = "#66cc66";
    var badColor = "#ff6666";
    //Compare the values in the password field 
    //and the confirmation field
    if(password.value == password1.value){
        //The passwords match. 
        //Set the color to the good color and inform
        //the user that they have entered the correct password 
        password1.style.backgroundColor = goodColor;
        message.style.color = goodColor;
        message.innerHTML = "Passwords Match!"
    }else{
        //The passwords do not match.
        //Set the color to the bad color and
        //notify the user.
        password1.style.backgroundColor = badColor;
        message.style.color = badColor;
        message.innerHTML = "Passwords Do Not Match!"
    }
}  

</script>
</head>

<body>
  <!-- Sidenav -->
  <nav class="sidenav navbar navbar-vertical  fixed-left  navbar-expand-xs navbar-light bg-white" id="sidenav-main">
    <div class="scrollbar-inner">
      <!-- Brand -->
      <div class="sidenav-header  align-items-center">
        <a class="navbar-brand" href="javascript:void(0)">
          <h4>Exam App</h4>
        </a>
      </div>
      <div class="navbar-inner">
        <!-- Collapse -->
        <div class="collapse navbar-collapse" id="sidenav-collapse-main">
          <!-- Nav items -->
          <?php include('modmenu.html')  ?>
          <!-- Divider -->
          <hr class="my-3">
          <!-- Heading -->
          
        </div>
      </div>
    </div>
  </nav>
  <!-- Main content -->
  <div class="main-content" id="panel">
    <!-- Topnav -->
    <nav class="navbar navbar-top navbar-expand navbar-dark bg-primary border-bottom">
      <div class="container-fluid">
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
          <!-- Search form -->
          <form class="navbar-search navbar-search-light form-inline mr-sm-3" id="navbar-search-main">
            <div class="form-group mb-0">
              <div class="input-group input-group-alternative input-group-merge">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="fas fa-search"></i></span>
                </div>
                <input class="form-control" placeholder="Search" type="text">
              </div>
            </div>
            <button type="button" class="close" data-action="search-close" data-target="#navbar-search-main" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </form>
          <!-- Navbar links -->
          
          
        </div>
      </div>
    </nav>
    <!-- Header -->
    <!-- Header -->
    <div class="header bg-primary pb-6">
      <div class="container-fluid">
        <div class="header-body">
          <div class="row align-items-center py-4 text-white">
            
          <h1>Moderator Module </h1>
          </div>
          <!-- Card stats -->
         
          <!-- put content  -->




          
    <!-- Page content -->

    <div class="card " >
    <div class="card-body">
   
    <div class="col text-right">
                  <a href="#!" class="btn btn-sm btn-primary">Staff Dash board</a>
                </div>

    <h2>Welcome to Moderator module of Dcube CBT App 1.0</h2>
    
    <form role="form" method = "post" action = "">
                   


                    <div class="row">
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Old Password</label>
                        <input type="password" id="input-username"  class="form-control"  name = "old"  required>
                      </div>
                    </div>
                    </div>


                    <div class="row">
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">New Password</label>
                        <input type="password"   class="form-control" placeholder="new password" name = "password" id = "password"  required>
                      </div>
                    </div>
                    </div>


                    <div class="row">
                    <div class="col-lg-6">
                      <div class="form-group">
                        <label class="form-control-label" for="input-username">Confirm Password</label>
                        <input class="form-control" name = "password1"  type = "password" id = "password1" 
                                                    onkeyup="checkPass(); return false;" required>
                                                    <span id="confirmMessage" class="confirmMessage"></span>
                      </div>
                    </div>
                    </div>
             
               
                    <div class="text-center">
                  <button type="submit" name = "submit" class="btn btn-primary my-4">Change Password</button>
                </div>
                  </form>

    
       
</div>

</div>
  

    <div class="container-fluid mt--6">
      
       
      
        </div>
      </div>
      <!-- Footer -->
      <footer class="footer pt-0">
        <div class="row align-items-center justify-content-lg-between">
          <div class="col-lg-6">
            
          </div>
          <div class="col-lg-6">
            
          </div>
        </div>
      </footer>
    </div>
  </div>
  <!-- Argon Scripts -->
  <!-- Core -->
  <script src="assets/vendor/jquery/dist/jquery.min.js"></script>
  <script src="assets/vendor/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/js-cookie/js.cookie.js"></script>
  <script src="assets/vendor/jquery.scrollbar/jquery.scrollbar.min.js"></script>
  <script src="assets/vendor/jquery-scroll-lock/dist/jquery-scrollLock.min.js"></script>
  <!-- Optional JS -->
  <script src="assets/vendor/chart.js/dist/Chart.min.js"></script>
  <script src="assets/vendor/chart.js/dist/Chart.extension.js"></script>
  <!-- Argon JS -->
  <script src="js/argon.js?v=1.2.0"></script>
</body>

</html>