<?php include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }
	
date_default_timezone_set('Asia/Calcutta');
$today = date("d-m-Y");
$time = date("h:i A"); 
$currentyear = date("Y");

function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();


?>
<?php 
$querylogin = "select * from  users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysqli_query($conn,$querylogin);
while($row=mysqli_fetch_array($resultlogin))
{
$user_id = $row['user_id'];
$first_name = $row['first_name'];
$login_type=$row['login_type'];
}

?>



  
<?php

include 'phpqrcode/qrlib.php';

// Function to generate QR code from URL
function generateQRCode($url, $filename = false, $size = 200) {
    // If no filename provided, generate a random one
    if (!$filename) {
        $filename = uniqid() . '.png';
    }
    
    // Generate QR code
    QRcode::png($url, $filename, QR_ECLEVEL_L, 10, 2);

    // Return filename of generated QR code
    return $filename;
}

// Example usage:



$event_name = $_POST['event_name'];
$Edate = $_POST['Edate'];
$Eplace = $_POST['Eplace'];
$stock = $_POST['stock'];
$coupon_name = $_POST['coupon_name'];
$coupon_discount = $_POST['coupon_discount'];




$query1 = "insert into event_master (event_name,Edate,Eplace,status,coupon_discount,coupon_name,unique_id) values ('$event_name','$Edate','$Eplace','1','$coupon_discount','$coupon_name','$unique_id')";
$result=mysqli_query($conn,$query1);


$qry4z = "select * from event_master where  unique_id='$unique_id'";
$re4z= mysqli_query($conn,$qry4z);
while($row=mysqli_fetch_array($re4z))
{  
$eventID = $row['eventID'];
}

//echo "<br>";

$url = 'https://crmsahavas.co.in/kanakveda/Book_An_Event.php?event_name='.$event_name.'&&eventID='.$eventID.''; // Replace with your URL
$filename = generateQRCode($url);

$queryleadqf="update event_master set QR_code='$filename'  where eventID = '$eventID'";
$resultleadqf=mysqli_query($conn,$queryleadqf);

//exit();

?>
<script>
javascript:window.location.href="view_all_event.php";
</script>
