<?php
include_once '../includes/session.php';
include_once '../includes/functions.php';
include_once '../includes/constants.php';

// Create and connect using modernized partners class
$partners = new partners;
$partners->connection($host, $user, $pass, $db);

// Sanitize GET parameters
$acno  = filter_input(INPUT_GET, 'acno', FILTER_SANITIZE_STRING);
$nname = filter_input(INPUT_GET, 'nname', FILTER_SANITIZE_STRING);
$ret   = filter_input(INPUT_GET, 'ret', FILTER_SANITIZE_STRING);

// If not coming from return flag, try fetching from egold table
if ($ret !== 'T') {
    $stmt = $partners->conn->prepare("SELECT egold_accno, egold_payeename FROM partners_egold WHERE egold_user_id = 0 LIMIT 1");
    $stmt->execute();
    $stmt->store_result();

    if ($stmt->num_rows > 0) {
        $stmt->bind_result($db_acno, $db_nname);
        $stmt->fetch();
        $acno  = $db_acno;
        $nname = $db_nname;
    }
    $stmt->close();
}
?>

<form method="POST" action="egold_validate.php">
  <table width="70%" class="tablebdr" cellspacing="0" cellpadding="0">
    <tr align="center">
      <td height="22" colspan="3" class="tdhead">Egold Details</td>
    </tr>
    <tr align="center">
      <td colspan="3"><font color="#FF0000"></font></td>
    </tr>
    <tr align="center">
      <td colspan="3">&nbsp;</td>
    </tr>
    <tr>
      <td align="right">Account No</td>
      <td align="right">&nbsp;</td>
      <td width="66%" align="left">
        <input name="txtacno" type="text" id="txtacno" value="<?= htmlspecialchars($acno ?? '') ?>" size="30">
      </td>
    </tr>
    <tr>
      <td width="32%" align="right">Payee Name</td>
      <td width="2%" align="right">&nbsp;</td>
      <td align="left">
        <input name="txtpayeename" type="text" id="txtpayeename" value="<?= htmlspecialchars($nname ?? '') ?>" size="30">
      </td>
    </tr>
    <tr><td colspan="3" height="19">&nbsp;</td></tr>
    <tr align="center">
      <td colspan="3">
        <input type="submit" name="Submit" value="Update">
      </td>
    </tr>
    <tr><td colspan="3" height="19">&nbsp;</td></tr>
    <tr>
      <td class="tdhead" height="22" colspan="3">&nbsp;</td>
    </tr>
  </table>
</form>
