<?php 
require_once("header.php");
require_once("cookie_check.php");
?>

<?php
$fetch_service = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `sc_subcategory` WHERE `subcategory_id` = '".$_REQUEST['subcategory_id']."'"));
$fetch_service1 = mysqli_fetch_array(mysqli_query($connection,"SELECT * FROM `sc_category` WHERE `category_id` = '".$_REQUEST['category_id']."'"));
?>

<?php
if(isset($_POST['send']))
{	
	$sql_insert = "INSERT INTO `sc_quotations` SET `category_id` = '".$_POST['hid_category_id']."',`subcategory_id` = '".$_POST['hid_subcategory_id']."',`user_id` = '".$_COOKIE['USER_ID']."',`message` = '".addslashes($_POST['message'])."',`quantity` = '".$_POST['hid_qty']."',`post_date` = '".date('Y-m-d H:i:s',time())."'";
	$exe_insert = mysqli_query($connection,$sql_insert);
	
	$_SESSION['qp_succ_msg'] = 'Message successfully sent to administrator. We will get back you soon';
	header("location: get-quotation.php?category_id=".$_POST['hid_category_id']."&subcategory_id=".$_POST['hid_subcategory_id']);
	exit;
}
?>

		<script language="javascript" type="text/javascript">
		function form_validation()
		{
			if(document.getElementById('message').value == "")
			{
				alert("Please enter message");
				document.getElementById('message').focus();
				return false;
			}
			
			return true;
		}
		</script>

		<!-- content area start -->
		<section id="about">
			<div class="container mt-0 pb-0 pt-10">	
				<div class="row">
					<div class="col-lg-12">
				        <h1 class="title mt-0 mb-5" style="text-align:center;">Get Quotation</h1>
				        <h4 class="title mt-0 mb-10" style="text-align:center; color:#c91215; font-weight:500;"><?php echo stripslashes($fetch_service['subcategory_name']);?> > <?php echo stripslashes($fetch_service1['category_name']);?></h4>
						<?php if(isset($_SESSION['qp_succ_msg'])) { ?>
						<p style="text-align:center; margin-bottom:10px;"><img src="images/tick.png" alt="" /> <?php echo $_SESSION['qp_succ_msg'];?></p>
						<?php 
						unset($_SESSION['qp_succ_msg']);
						} 
						?>	
						<form id="" action="" method="post" enctype="multipart/form-data" class="contact-form" onsubmit="return form_validation();">
						<div class="row">
							<div class="col-lg-12 form-group">
								<textarea name="message" id="message" class="common-input form-control" placeholder="Enter Message *" style="height:150px;"></textarea>
							</div>
							<div class="col-lg-12 form-group">
								<button class="btn btn-flat btn-theme-colored border-left-theme-color-2-4px" type="submit" style="float: left;">Submit</button>
							</div>
						</div>
						<input type="hidden" name="hid_category_id" id="hid_category_id" value="<?php echo $_GET['category_id'];?>">
						<input type="hidden" name="hid_subcategory_id" id="hid_subcategory_id" value="<?php echo $_GET['subcategory_id'];?>">
						<input type="hidden" name="hid_qty" id="hid_qty" value="<?php echo $_GET['qty'];?>">
						<input type="hidden" name="send" id="send" value="1" />
						</form>	
					</div>
				</div>
			</div>	
		</section>
		<!-- content area end -->

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