<?php
include('../includes/session.php');
include('../includes/config.php');
include('../template/ahkweb/header.php');
?>
<!--start page wrapper -->
<div class="page-wrapper">
	<div class="page-content">
		<!--breadcrumb-->
		<div class="page-breadcrumb d-none d-sm-flex align-items-center mb-3">
			<div class="breadcrumb-title pe-3">Home </div>
			<div class="ps-3">
				<nav aria-label="breadcrumb">
					<ol class="breadcrumb mb-0 p-0">
						<li class="breadcrumb-item"><a href="javascript:;"><i class="bx bx-home-alt"></i></a></li>
						<li class="breadcrumb-item active" aria-current="page">New APPLY</li>
					</ol>
				</nav>
			</div>
		</div>
		<!--end breadcrumb-->

		<div class="row">
			<div class="col-xl-10 mx-auto">
				<h6 class="mb-0 text-uppercase">Voter Advance</h6>
				<hr />
				<div class="card border-top border-0 border-4 border-primary">
					<div class="card-body p-5">
						<div class="card-title d-flex align-items-center">
							<div><i class="bx bxs-id-card me-1 font-22 text-primary"></i></div>
							<h5 class="mb-0 text-primary">Enter Voter Details</h5>
						</div>
						<hr>

						<form method="post" name="form" autocomplete="off" enctype="multipart/form-data" action="Voter_advance_print_captcha_info.php" style="width:100%">
							<div class="row dgnform">
								<div class="col-md-13 col-sm-12 col-xs-12">
									<div class="row">
										<div class="col-sm-4 col-xs-20">
											<label>Epic No.</label>
											<div class="form-group">
												<input class="form-control" name="epicno" type="text" placeholder="Enter Epic No" required="">
											</div>
										</div>
									</div>

									<!-- Upload Photo -->
									<label>Upload Photo </label>
									<input type='file' id="filedata" name="" onchange="readURL(this);" />
									<input class="form-control" id="blah1" name="filedata" type="hidden" value="" required>

									<br><br>

									<?php

$apiUrl = "$tng_apiurl/votercaptcha2";
$response = file_get_contents($apiUrl);
$data = json_decode($response, true);

$captchaImg = "";
$captchaId  = "";

if ($data && isset($data['captcha'])) {
    $captchaImg = "data:image/jpeg;base64," . $data['captcha'];
    $captchaId  = $data['id'];
}
?>

<!-- Captcha Section -->
<div class="row mt-3">
  <div class="col-sm-6">
    <label>Captcha</label>
    <div class="d-flex align-items-center">
      <?php if ($captchaImg): ?>
        <img id="captchaImage" src="<?= $captchaImg ?>" alt="Captcha" 
             style="border:1px solid #ddd; padding:5px; width:180px; height:60px;">
      <?php else: ?>
        <span style="color:red;">Captcha load failed</span>
      <?php endif; ?>

      <!-- Refresh button (reloads page) -->
      <button type="button" class="btn btn-outline-primary btn-sm ms-2" onclick="window.location.reload();">
        <i class="bx bx-refresh"></i>
      </button>
    </div>

    <!-- Hidden captchaId -->
    <input type="hidden" name="captcha_id" value="<?= htmlspecialchars($captchaId) ?>">

    <!-- Captcha Text -->
    <input type="text" class="form-control mt-2" name="captcha_text" placeholder="Enter Captcha" required>
  </div>
</div>


									<br><br>

									<div class="row" style="margin-top:25px;">
										<div class="col-12 ml-4">
											<h5 class="text-warning">Application Fee: 
												<?php  
													$price = mysqli_fetch_assoc(mysqli_query($ahk_conn,"SELECT price FROM pricing WHERE service_name='voter_advance_fee'")); 
													echo "₹" .$price['price'];
												?>
											</h5>
										</div>
									</div>

									<label>&nbsp;</label>
									<div class="form-group">
										<input type="submit" id="submit" name="submit" class="btn btn-success btn-block" value="Submit">
										<div id="result"></div>
									</div>
								</div>
							</div>
						</form>

					</div>
				</div>
			</div>
		</div>

<?php include('../template/ahkweb/footer.php'); ?>
<script src="../template/ahkweb/assets/js/bootstrap.bundle.min.js"></script>
<script src="../template/ahkweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
<script src="../template/ahkweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
<script src="../template/ahkweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
<script src="../template/ahkweb/assets/js/app.js"></script>
