<?php 
include 'dheader.php';
$success = "";
$danger = "";
if (isset($_POST['submitf'])) {
 	# code...
 	extract($_POST, EXTR_OVERWRITE);
 	$countQuery = $db->query("SELECT count(*) totalCount FROM store");
	$rowcount = $countQuery->fetchArray();
	$totalCount = $rowcount['totalCount'];
	if ($totalCount < 1) {
 		$sql = $db->query("INSERT INTO store (name, address, city, phone, ntn, email, url, policy_ins) VALUES ('$company_name', '$address', '$city', '$phone', '$ntn', '$email', '$url', '$policy_ins')");

 		if ($sql) {
 			$success = "<strong>Success!</strong> Company Setup successfully."; 
 		}else{
 			$danger = "<strong>Warning!</strong> Something went wrong.";
 		}
 	}else{
 		$sql = $db->query("UPDATE store SET name = '$company_name', address = '$address', city = '$city', phone = '$phone', ntn = '$ntn', email = '$email', url = '$url', policy_ins = '$policy_ins' ");

 		if ($sql) {
 			$success = "<strong>Success!</strong> Company Setup successfully."; 
 		}else{
 			$danger = "<strong>Warning!</strong> Something went wrong.";
 		}
 	} 
 } 

$select = $db->query("SELECT * FROM store");
$fdata = $select->fetchArray();
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">

<div class="row" id="form">
	<div class="spinner" id="grid-loader" style="display:none">
	  <div class="rect1"></div>
	  <div class="rect2"></div>
	  <div class="rect3"></div>
	</div>
	
	<div class="col-md-12">
		<form action="" id="customer_form" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8" novalidate="novalidate" autocomplete="off">
			<div class="col-md-12">
	<div class="panel panel-piluku">
		<div class="panel-heading">
                <h3 class="panel-title">
                    <i class="ion-edit"></i> 
                    	Store Config						<small>(Fields in red are required)</small>
                </h3>
        </div>

			<div class="panel-body">
				<?php
                    if (isset($_POST['submitf'])) {
                    ?>
                    <div class="alert alert-<?php echo ($success) ? "success" : "danger"; ?>"> 
                            <?php echo ($success) ? $success : $danger; ?>                          
                    </div>
                 <?php } ?>
              <div class="form-group">
					<label for="Company" class="col-sm-3 col-md-3 col-lg-2 control-label required">Company Name :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="company_name" autofocus="on"  value="<?php echo @$fdata['name']; ?>" class="form-control" id="company_name">
					</div>
				</div>

				<div class="form-group">
					<label for="Address" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Address :</label>						<div class="col-sm-9 col-md-9 col-lg-10">
						<textarea name="address" style="width: 100%; height: 100px;"><?php echo @$fdata['address']; ?></textarea>
					</div>
				</div>

				<div class="form-group">
					<label for="Address" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Policy/Ins :</label>						<div class="col-sm-9 col-md-9 col-lg-10">
					<textarea name="policy_ins" id="policy_ins"  style="height:400px;" class="policy_ins"><?php echo @$fdata['policy_ins']; ?></textarea>
					</div>
				</div>
				


				 <div class="form-group">
					<label for="city" class="col-sm-3 col-md-3 col-lg-2 control-label required">City :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="city" value="<?php echo @$fdata['city']; ?>" class="form-control" id="city">
					</div>
				</div>

				<div class="form-group">
					<label for="phone" class="col-sm-3 col-md-3 col-lg-2 control-label required">Phone :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="phone" value="<?php echo @$fdata['phone']; ?>" class="form-control" id="phone">
					</div>
				</div>

				<div class="form-group">
					<label for="ntn" class="col-sm-3 col-md-3 col-lg-2 control-label required">NTN :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="ntn" value="<?php echo @$fdata['ntn']; ?>" class="form-control" id="ntn">
					</div>
				</div>


				<div class="form-group">
					<label for="email" class="col-sm-3 col-md-3 col-lg-2 control-label required">Email :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="email" value="<?php echo @$fdata['email']; ?>" class="form-control" id="email">
					</div>
				</div>

				<div class="form-group">
					<label for="url" class="col-sm-3 col-md-3 col-lg-2 control-label required">URL :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="url" value="<?php echo @$fdata['url']; ?>" class="form-control" id="url">
					</div>
				</div>

				<div class="form-actions pull-right">
										&nbsp;
					<input type="submit" name="submitf" value="Submit" id="submitf" class="submit_button btn btn-primary">
				</div>

			
							</div><!--/panel-body -->
		</div><!-- /panel-piluku -->


	</div>
			
		</form>
			</div>
		</div><!-- /row -->


	

			
<?php include 'dfooter.php'; ?>