<?php  
error_reporting(E_ERROR | E_PARSE);
	include("../connect.php");
	include ("../superpanel/phpqrcode/qrlib.php"); 
	$par1=$_GET['mobile'];
	$par2=$_GET['password'];
	$par3=$_GET['tno'];
	$par4=$_GET['tareweight'];
	$par5=$_GET['tcolor'];

	$response = array();
	$posts = array();
	
	
	//date_default_timezone_set("Asia/Singapore");
	date_default_timezone_set("Asia/Singapore");
	//$mdate= date('Y-m-d H:i:s');
	$mdate= date('Y/m/d H:i:s');
	$myObj2 = new stdClass();
    $eve1 = "SELECT * FROM res_user_master where  userloginid='$par1' and userpassword='$par2' and userstatus='Active' and userdesignation='User' limit 0,1";
	$re1 = mysqli_query($conn,$eve1);
																	
	if(mysqli_num_rows($re1) > 0)
	{
		 while($rt1 = mysqli_fetch_assoc($re1))
		 {
				$result="1";
				
				$umid = $rt1['usermid'];
			 $query1 = "select * from res_trolley_master where trolleynumber='$par3'";
			$stmt1=mysqli_query($conn,$query1);
			
			if(mysqli_num_rows($stmt1) > 0)
			{
				$result="0";
				$msg="Already Registered";
				
				$posts[] = array('result'=> $result,'msg'=> $msg);
				echo stripslashes(json_encode( array('item' => $posts)));
			}
			else
			{
				$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;
			 // Generate a random 10-digit trolley QR code
				$trolleyqrcode = $par3;
			
				 $evenewpass = "INSERT INTO res_trolley_master (trolleyno,trolleynumber,trolleyqrcode,trolleytareweight,trolleycolor,trolleyaddedby,trolleyaddedon,trolleyupdatedon) VALUES('$cmno1','$par3','$trolleyqrcode','$par4','$par5',$umid,'$mdate','$mdate')";
					
				
				if ($conn->query($evenewpass) === 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 = "../superpanel/images/$trolleynumber.png"; // Provide a suitable path

							QRcode::png(stripcslashes($trolleynumber), $qrCodeImagePath, QR_ECLEVEL_L,5);
						}
					}
					$result="1";
					$msg = "Success";
					
					$posts[] = array('result'=> $result,'msg'=> $msg);
					echo stripslashes(json_encode( array('item' => $posts)));			
				}	
			}
		}
   }
   else
   {
		$result="0";
		$msg="Failure";
		
		$posts[] = array('result'=> $result,'msg'=> $msg);
		echo stripslashes(json_encode( array('item' => $posts)));

   }
	mysqli_close($conn);
?>
