<?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:../");
}

?>
<!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>Repair Track sheet</title>
	<link rel="icon" type="image/ico" href="img/airicon.ico"/>
    <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet"  href="css/customstyle.css">
  </head>
  <body>
   <header>
  <div class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#example">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
          <a href="" class="navbar-brand">Repair Track Sheet</a>
        </div>
        <div class="collapse navbar-collapse" id="example">
          <ul class="nav navbar-nav">
            <li class="active"><a href="index.php"><span  class="glyphicon glyphicon-home"></span> Home</a></li>
            <li><a href="display.php"><span class="glyphicon glyphicon-list-alt"></span> View List</a></li>
          </ul>
           <form action="search.php" method="POST" class="navbar-form navbar-right" role="search">
            <div class="form-group ">
              <input type="text" name="search" class="form-control" placeholder="Search Here">
            </div>
            <button name="submit" type="submit" class="btn btn-primary "><span class="glyphicon glyphicon-search"></span></button>
          </form>
        </div>
      </div>
    </div>
    </header>
    <div class="container padding-top-120 col-md-offset-2">
    <div class="col-md-8">
      <div class="panel panel-default" >
      <div class="panel-heading initialism font-weight-bold">Register Item</div>
      <div class="panel-body">
        <form action="<?php $_SERVER['PHP_SELF']?>" method="post">

     <div class="row">
             <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
           <label for="name" class="control-label">Name of item:</label>
          <input type="text" class="form-control" id="name" placeholder="Name of item" name="name" required />
          </div>
             <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
             <label for="serial_number" class="control-label">Serial number:</label>
			<input type="text" class="form-control" id="serial_number" placeholder="Serial number" name="serial_number" required />
            </div>
	</div>
   <div class="row padding-top-10">
             <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
           <label for="station" class="control-label">Originating station/user:</label>
          <input type="text" class="form-control" id="station" placeholder="Originating Station/user" name="station" required />
          </div>
             <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
          <label for="problem" class="control-label">Problem:</label>
          <input type="text" class="form-control" id="problem" placeholder="Problem" name="problem" required />
          </div>
		  </div>
    <div class="row padding-top-10">

             <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
          <label for="date_in" class="control-label">Date in:</label>
            <input type="date" class="form-control" id="date_in" placeholder="Date in" name="date_in" required />
          </div>
           <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
          <label for="date_sent" class="control-label">Date sent to procurement:</label>
           <input type="date" class="form-control" id="date_sent" placeholder="Date sent" name="date_sent" 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-primary 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');

	 $name= $_POST['name'];
	 $serial_number= $_POST['serial_number'];
	 $station= $_POST['station'];
	 $problem = $_POST['problem'];
	 $date_in= $_POST['date_in'];
	 $date_sent= $_POST['date_sent'];

     $sqlinsert = "INSERT INTO repair_list (name_of_item,serial_number,originating_station,problem,date_in,date_sent) VALUES
	 ('$name','$serial_number','$station','$problem', '$date_in','$date_sent')";

	 if(!mysql_query($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>
