<?php
session_start();
error_reporting(0);
include('../../includes/config.php');
require_once("../../includes/dbcontroller.php");
$db_handle = new DBController();

$role= $_SESSION['role'];
if($role!='Admin'){
	header("location:$website_url/");
	exit();
}
if(isset($_POST['add'])){
	if(isset($_POST['truckNumber']) && !empty($_POST['truckNumber'])){
		$truckNumber=$_POST['truckNumber'];
		$truckName=$_POST['truckName'];
		$active=$_POST['active'];

		$insert = "INSERT into trucks(TruckNumber,TruckName,active) values('$truckNumber','$truckName',$active)";
		$result = $db_handle->executeQuery($insert);
		echo "<script>alert('Truck Added Sucessfully.')</script>";
		echo "<script>location.href = '$website_url$trucks_url';</script>";
	}
}
include('../../includes/menu.php');
?>

<div class="container main-cont single-add-user"><h2 class="page-title">Add Truck</h2>
	<div class="form-group">
		<form enctype="multipart/form-data" method="post" accept-charset="utf-8">
			<div class="col-lg-6 col-xs-12 col-sm-6  col-md-6 outer-cell">
				<div class="inner-cell">
					<div class="frm-item">
						<label for="truckNumber">TruckNumber</label>            
						<input type="text" name="truckNumber" value="" class="form-control" required>
					</div>
				</div>
			</div>
			<div class="clearfix"></div>
			<div class="col-lg-6 col-xs-12 col-sm-6  col-md-6 outer-cell">
				<div class="inner-cell">
					<div class="frm-item">
						<label for="truckName">TruckName</label>            
						<input type="text" name="truckName" value="" class="form-control" required>
					</div>
				</div>
			</div>
			<div class="clearfix"></div>
			<span style="color:red;" >
				<?php
				echo htmlentities($_SESSION['usererrmsg']);
				?>
				<?php
				echo htmlentities($_SESSION['usererrmsg']="");
				?>
			</span>
			<div class="clearfix"></div>
			
			<div class="form-group col-md-6">
				<label for="active">Active</label>
				<select name="active" id="active" class="form-control" >
					<option value="1">Yes</option>
					<option value="0">No</option>
				</select>
			</div>
			<div class="clearfix"></div>
			<span style="color:red;" >
				<?php
				echo htmlentities($_SESSION['passerrmsg']);
				?>
				<?php
				echo htmlentities($_SESSION['passerrmsg']="");
				?>
			</span>
			<div class="frm-btn">
				<input type="submit" name="add" value="Add" class="btn btn-primary btn-add">
			</div>
		</form>
	</div> 
</div>
<?php
include('../../includes/footer.php');
include('../../includes/webfooter.php');
?>