<?php
include('../includes/session.php');
include('../includes/config.php');
include('../template/tngweb/header.php');
$fee    = $udata['voter_advance_fee'];
checkServiceStatus($udata, 'voter_advance_fee_status');
?>
<!--start page wrapper -->
<div class="page-wrapper">
	<div class="page-content">
	

		<div class="row">
			<div class="col-xl-10 mx-auto">
			        <div class="mb-4">
        <a href="javascript:history.back()" class="back-btn">
            <i class="bi bi-arrow-left-circle"></i> Go Back
        </a>
    </div>
				<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

$data = fetchvotercaptcha();

$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 echo $fee; ?>
											</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/tngweb/footer.php'); ?>
<script src="../template/tngweb/assets/js/bootstrap.bundle.min.js"></script>
<script src="../template/tngweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
<script src="../template/tngweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
<script src="../template/tngweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
<script src="../template/tngweb/assets/js/app.js"></script>
