<?php
require("../mainconfig.php");

if (isset($_POST['category'])) {
	$post_cat = mysqli_real_escape_string($db, $_POST['category']);
	$check_service = mysqli_query($db, "SELECT * FROM services WHERE category = '$post_cat' AND status = 'Active' ORDER BY price ASC");
	?>
	<option value="0">Select one...</option>
	<?php
	while ($data_service = mysqli_fetch_assoc($check_service)) {
	?>
	<option value="<?php echo $data_service['sid'];?>"><?php echo $data_service['service'];?></option>
	<?php
	}
} else if (isset($_POST['service1'])) {
	$post_sids = mysqli_real_escape_string($db, $_POST['service1']);
	$check_service = mysqli_query($db, "SELECT * FROM services WHERE sid = '$post_sids' AND status = 'Active'");
	if (mysqli_num_rows($check_service) == 1) {
		$data_service = mysqli_fetch_assoc($check_service);
	?>
	                               <div class="row">
                                    <div class="col">
                                      <div class="mb-3">
										<div class="alert alert-info">
													<b>Note:</b> <?php echo $data_service['note']; ?><br />
													<b>Price/1000:</b> Rp <?php echo number_format($data_service['price'],0,',','.'); ?><br />
													<b>Min. Order:</b> <?php echo number_format($data_service['min'],0,',','.'); ?><br />
													<b>Max. Order:</b> <?php echo number_format($data_service['max'],0,',','.'); ?><br />
													<b>Kecepatan Rata²:</b> <?php echo $data_service['average']; ?>
												</div>
												</div>
                                                </div>
                                              </div>
	<?php
	} else {
	?>
										<div class="alert alert-danger">
											<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
													<i class="mdi mdi-block-helper"></i>
													<b>Error:</b> Service not found.
												</div>
	<?php
	}
} else if (isset($_POST['service'])) {
	$post_sid = mysqli_real_escape_string($db, $_POST['service']);
	$check_service = mysqli_query($db, "SELECT * FROM services WHERE sid = '$post_sid' AND status = 'Active'");
	if (mysqli_num_rows($check_service) == 1) {
		$data_service = mysqli_fetch_assoc($check_service);
		if (($data_service['min'] == 1) && ($data_service['max'] == 1)) {
		    $result = $data_service['price'];
		} else {
		    $result = $data_service['price'] / 1000;
		}
		echo $result;
	} else {
		die("0");
	}
} else {
?>
<option value="0">Error.</option>
<?php
}