<?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 $Process->navigation("index"); ?>
    </header> 
    <div class="container padding-top-120">
    <div class="col-md-10 col-md-offset-1">
      <div class="panel panel-primary" >
      <div class="panel-heading initialism font-weight-bold">Register Your Item</div>
      <div class="panel-body">
        <form action="<?php $_SERVER['PHP_SELF']?>" method="post">
		
          <div class="row">
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
           <label for="user" class="control-label">User:</label>
          <input type="text" class="form-control" id="user" placeholder="user" name="user" required />
          </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
             <label for="user_status" class="control-label">User Status:</label>
            <select class="form-control" id="user_status" name="user_status" >
		  <?php
$query="SELECT * FROM user_status_admin ";

$get=mysqli_query($connect,$query);
while ($employee=mysqli_fetch_assoc($get))
{	
?>
<option><?php echo $employee["user_status"];?></option>
<?php 
}
?>
            </select>
            </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
           <label for="designation" class="control-label">Designation:</label>
          <input type="text" class="form-control" id="designation" placeholder="Designation" name="designation" required />
          </div>
          </div>

          <div class="row padding-top-10">
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
          <label for="location" class="control-label">Location:</label>
            <select class="form-control" id="location" name="location" required >
                 <?php
	$query="SELECT * FROM location_admin ";

$get=mysqli_query($connect,$query);
while ($employee=mysqli_fetch_assoc($get))
{	
?>
<option><?php echo $employee["location_admin"];?></option>
<?php 
}
 ?>

            </select>
            
          </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
          <label for="device" class="control-label">Device:</label>
            <select class="form-control" id="device" name="device" >
               <?php
	$query="SELECT * FROM device_admin ";

$get=mysqli_query($connect,$query);
while ($employee=mysqli_fetch_assoc($get))
{	
?>
<option><?php echo $employee["device_admin"];?></option>
<?php 
}
 ?>
            </select>
            
          </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
          <label for="brand" class="control-label">Brand:</label>
            <select class="form-control" id="brand" name="brand" >
      <?php
	$query="SELECT * FROM brand_admin ";

$get=mysqli_query($connect,$query);
while ($employee=mysqli_fetch_assoc($get))
{	
?>
<option><?php echo $employee["brand_admin"];?></option>
<?php 
}
 ?>
            </select>
            
          </div>
            
          </div>

          <div class="row padding-top-10">
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <label class="control-label" for="model">Model/Product Number</label>
              <input type="text" class="form-control" id="model" placeholder="model number" name="model_num" />
            </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <label class="control-label" for="asset_tagging">Asset Tagging</label>
             <select class="form-control" id="asset_tagging" name="asset_tagging" >
       <?php
	$query="SELECT * FROM asset_tag_admin ";

$get=mysqli_query($connect,$query);
while ($employee=mysqli_fetch_assoc($get))
{	
?>
<option><?php echo $employee["asset_tag_admin"];?></option>
<?php 
}
 ?>
            </select>
            </div>
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
              <label class="control-label" for="tagging_number">Tagging number</label>
              <input type="text" class="form-control" id="tagging_number" placeholder="tagging number" name="asset_tag" />
            </div>
          </div>

          <div class="row padding-top-10">
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
          <label class="control-label" for="date">Date Issued:</label>
          <input type="Date" class="form-control" id="date" name="date" required > 
          </div>
          </div>
          <div class="row padding-top-70">
             <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
            <button type="submit" id="btn_submit" class=" btn btn-success control-label" name="submit_btn">Register</button>
            </div>
          </div>
		  <br/><br/>
		  <div id="myalert" class="alert alert-danger collapse">
		  <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
		  <strong>error!</strong> there is a problem submitting your form
		  </div>
          <?php

 if(isset($_POST['submit_btn']))
 {
 require ('db_config/config.php');

	 $user= $_POST['user'];
	 $user_status= $_POST['user_status'];
	 $designation= $_POST['designation'];
	 $device = $_POST['device'];
	 $brand= $_POST['brand'];
	 $model_num= $_POST['model_num'];
	 $location= $_POST['location'];
	 $asset_tagging= $_POST['asset_tagging'];
	 $asset_tag= $_POST['asset_tag'];
	 $date= $_POST['date'];
	 
     $sqlinsert = "INSERT INTO asset_info (user,user_status,designation,device,brand,model_num,location,asset_tagging,asset_tag,date) VALUES 
	 ('$user','$user_status','$designation','$device', '$brand','$model_num','$location','$asset_tagging','$asset_tag','$date')";
 
	 if(!mysqli_query($connect,$sqlinsert))
	 {
		// die('error inserting');
		  echo "<br />";
			 echo '<div class="alert alert-danger">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   <strong>Error!</strong> inserting
				   </div>';
	 }
	 else{
		 //echo '<script type="text/javascript"> alert("Item Registered") </script>';
		  echo "<br />";
			 echo '<div class="alert alert-success">
			       <a id="linkclose" href="#" class="close" data-dismiss="alert">&times;</a>
				   Item registered
				   </div>';
	 }
	 }
?>
        </form>
      </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>