<?php

include_once '../includes/processes.php';
$Process = new Login_Process;

$pageLink = basename($_SERVER['REQUEST_URI']);
$Process->check_status($pageLink);
if($_SESSION['dept_id']!=7) {
	
	header("location:../");
}
 require 'db_config/config.php';

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>I.T Asset Listing</title>
			 	<link rel="icon" type="image/ico" href="img/airicon.ico"/>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet"  href="customstyle.css">

    
  </head>
  <body>
    <header>
      <?php navigation("add_user"); ?>

    </header> 
    <div class="container padding-top-120">
    <div class="col-md-7 col-md-offset-2">
    <div class="panel panel-primary">
    <div class="panel-heading font-weight-bold initialism">Register User</div>
      <div class="panel-body">
      <form action="add_user.php" method="POST" >
      
        <label class="control-label" for="name">Name:</label>
          <div class="row">
          <div class="col-md-4">
           <input type="text" class="form-control" name="first_name" id="name" placeholder="First Name" required />
            </div>
            <div class="col-md-4">
              <input type="text" class="form-control" name="middle_name" id="name" placeholder="Middle Name"/>
            </div>
            <div class="col-md-4">
              <input type="text" class="form-control" name="last_name" id="name" placeholder="Last Name" required />
            </div>
        </div>
         <label class="control-label padding-top-10" for="male">Gender:</label>
              <label class="radio-inline">
                <input type="radio" name="gender" value="male" id="male" checked /><b>Male</b>
              </label>

              <label class="radio-inline">
                <input type="radio" name="gender" value="female" /><b>Female</b>
              </label>
              </br>
         
          <div class="row padding-top-10">
          <div class="col-md-6">
           <label class="control-label" for="email">Email:</label>
            <input type="text" class="form-control" name="email" placeholder="Email" id="email" required />
          </div>
          </div>
          <div class="row padding-top-10">
             <div class="col-md-6">
           <label class="control-label" for="username">Username:</label>
            <input type="text" class="form-control" name="username" placeholder="Username" id="username" required />
          </div>
          </div>
          <div>
            <div class="row padding-top-10">
              <div class="col-md-6">
                <label class="control-label" for="password">Password:</label>
            <input type="Password" class="form-control" name="password" placeholder="Password" id="password" required />
              </div>
              <div class="col-md-6">
                <label class="control-label" for="cpassword">Comfirm Password:</label>
            <input type="Password" class="form-control" name="cpassword" placeholder="Comfirm Password" id="cpassword" required />
              </div>
            </div>
          </div>
      <div class="row padding-top-70">
             <div class="col-md-3">
            <button type="submit" class=" btn btn-success control-label" name="submit_btn">Register</button>
            </div>
          </div>
      </form>
         <?php
		 
	    if(isset($_POST['submit_btn']))
		{
        $first_name =$_POST['first_name'];
        $middle_name =$_POST['middle_name'];
        $last_name =$_POST['last_name'];
        $gender =$_POST['gender'];
        $email =$_POST['email'];		 
        $username =	$_POST['username'];
		$password =	$_POST['password'];
		$cpassword = $_POST['cpassword'];
		
		
		if($password==$cpassword)
		{   
			$query= "SELECT * FROM user_info WHERE username='$username' AND email='$email'";
			
			$query_run = mysqli_query($connect,$query);
			if(mysqli_num_rows($query_run)>0)
			{
				//echo '<script type="text/javascript"> alert("Username or Email already exist try another one") </script>';
				echo "<br />";
			 echo '<div class="alert alert-warning">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   Item registered
				   </div>';
			}
			
			else
			{
				$passwordmd5 = md5($password);
				
			$query= "insert into user_info values('','$first_name','$middle_name','$last_name','$gender','$email','$username','$passwordmd5')";
            $query_run = mysqli_query($connect,$query); 
			if($query_run)
			{
			   //echo '<script type="text/javascript"> alert("User Registered") </script>';
			  echo "<br />";
			 echo '<div class="alert alert-success">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   User registered
				   </div>';
			}
			else
			{
			//echo '<script type="text/javascript"> alert("Error! Try again") </script>';
			echo "<br />";
			 echo '<div class="alert alert-danger">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   <strong>Error!</strong> Try again later
				   </div>';
			}
			}
		}	
			else
			{
			//echo '<script type="text/javascript"> alert("password does not match") </script>';
			echo "<br />";
			 echo '<div class="alert alert-success">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   Password does not match
				   </div>';
			}
		}
	 ?>
      </div>
    </div>
    </div>
    </div>


 
  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
    <script src="bootstrap/js/bootstrap.min.js"></script>
  </body>
</html>