<?php
session_start(); 

	if(!isset($_SESSION['linkarisesuloginsesion']))
	{
		header('Location: index.php');
		return;
	}
	
	include("connect.php");
include 'phpqrcode/qrlib.php'; 
	date_default_timezone_set("Asia/Singapore");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y');
	$umid=$_SESSION['linkarisesumid'];
	
	
	$trolleyweight=$_POST['trolleytareweight'];
	$trolleyno=$_POST['trolleyno'];
	$trolleycolor=$_POST['trolleycolor'];



	
	$evemaxq = "SELECT max(trolleyno) AS maxcmno FROM res_trolley_master";
	$remaxq = mysqli_query($conn, $evemaxq);
	while($rtmaxq = mysqli_fetch_assoc($remaxq))
	{
		$cmno=$rtmaxq['maxcmno'];
	}
	$cmno1=$cmno+1;
       
        $trolleyqrcode =$trolleyno;

       
    
	
	
	
	$eve1 = "INSERT INTO res_trolley_master (trolleyno,trolleynumber,trolleyqrcode,trolleytareweight,trolleycolor,trolleyaddedon,trolleyaddedby,trolleyupdatedon,trolleyupdatedby) 
	VALUES('$cmno1','$trolleyno','$trolleyqrcode','$trolleyweight','$trolleycolor','$mdate1','$umid','$mdate1','$umid')";	
	if ($conn->query($eve1) === TRUE)
	{
		$last_id = $conn->insert_id;
		
		$eve = "select trolleyno, trolleynumber from res_trolley_master where trolleymid=$last_id";
        $re = mysqli_query($conn, $eve);
        $rate = 123;

        if (mysqli_num_rows($re) > 0) {
            $i = 1;
            while ($rt = mysqli_fetch_assoc($re)) {
              
                $trolleyno = $rt['trolleyno'];
                $trolleynumber = $rt['trolleynumber'];

                // Generate QR code image
                $qrCodeImagePath = "images/$trolleynumber.png"; // Provide a suitable path

                QRcode::png(stripcslashes($trolleynumber), $qrCodeImagePath, QR_ECLEVEL_L,5);

              
            }
        }
		$_SESSION['msg'] = "Record has been added successfully";
	}
	else
	{
		$_SESSION['msg1'] = "Error";
	}

	header('Location: trolley.php');
?>