<?php 
require_once('header.php'); 
?>
<?php
if(isset($_POST['form1'])) {
	$valid = 1;

	if(empty($_POST['name'])) {
		$valid = 0;
		$error_message .= 'Name can not be empty<br>';
	}

	if(empty($_POST['code'])) {
		$valid = 0;
		$error_message .= 'Status Code can not be empty<br>';
	}
        
  

    if($valid==1)
    {
    
		$statement = $pdo->prepare("INSERT INTO tbl_status (`name`, `status_code`, `status`) VALUES (?,?,?)");
		$statement->execute(array($_POST['name'],$_POST['code'],1));
			
		$success_message = 'Status Details is added successfully!';

	
		unset($_POST['name']);
		unset($_POST['code']);
		
    }
	
}
?>


<section class="content">

        <div class="row">
    		<div class="col-md-4" style="text-align: left;">
    			<h4><i class="fa fa-map-marker"></i> Status Details</h4>
    		</div>
    		<div class="col-md-8" style="text-align: right;"> 
    		    <a href="status.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Status List</a>
    		</div>
    	</div> 
	<div class="row">
		<div class="col-md-12">

			<?php if($error_message): ?>
			<div class="callout callout-danger">
				<p>
					<?php echo $error_message; ?>
				</p>
			</div>
			<?php endif; ?>

			<?php if($success_message): ?>
			<div class="callout callout-success">
				<p><?php echo $success_message; ?></p>
			</div>
			<?php endif; ?>
			
			<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
				<div class="box box-info">
					<div class="box-body">
					   
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Name <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="name" value="<?php if(isset($_POST['name'])){echo $_POST['name'];} ?>">
							</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Code <span>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="code" id="code">
							</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label"></label>
							<div class="col-sm-6">
								<button type="submit" class="btn btn-success pull-left" name="form1">Submit</button>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>

</section>

<?php require_once('footer.php'); ?>