<?php
require_once('../../include/config.php');
require_once('../../include/phpqrcode/qrlib.php');

if(!isset($_POST['badge_id'])) exit;

$id = intval($_POST['badge_id']);
$res = $conn->query("SELECT * FROM exhibitors_badges WHERE id=$id");
if($res->num_rows==0) exit("Not found");

$row = $res->fetch_assoc();

/* ===== QR CODE ===== */
$qrText = "https://yourdomain.com/exhibitor-profile.php?id=".$row['id'];
$qrDir = "../../uploads/qrcodes/";
if(!is_dir($qrDir)) mkdir($qrDir,0777,true);
$qrFile = $qrDir."badge_".$row['id'].".png";
if(!file_exists($qrFile)){
    QRcode::png($qrText,$qrFile,QR_ECLEVEL_L,6);
}
$qrUrl = "uploads/qrcodes/badge_".$row['id'].".png";
?>

<div id="badge" style="
 width:350px;height:620px;margin:auto;position:relative;
 background:url('https://polymertubing.in/Shubham_Codes/admin-panel/assets/images/exhibitor-badge.png')
 no-repeat center;background-size:cover;">

<!-- COMPANY NAME -->
<div style="
 position:absolute;top:230px;left:50%;
 transform:translateX(-50%);
 width:85%;text-align:center;
 font-size:22px;font-weight:bold;">
 <?= htmlspecialchars($row['cmp_name']); ?>
</div>

<!-- QR CODE -->
<img src="<?= $qrUrl; ?>" crossorigin="anonymous"
 style="position:absolute;bottom:120px;left:50%;
 transform:translateX(-50%);width:120px;height:120px;">
</div>

<div class="mt-3">
  <button class="btn btn-primary btn-sm me-2" onclick="downloadPNG()">PNG</button>
  <button class="btn btn-danger btn-sm" onclick="downloadPDF()">PDF</button>
</div>
