<?php 
	include "../../conn.php";
	include "../../functions2.php";

	header('Content-Type: application/json; charset=utf-8');
	header('Strict-Transport-Security: max-age=31536000');
	header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization');
	header('Access-Control-Allow-Credentials: true');
	$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
	header('Access-Control-Allow-Origin: ' . $origin);
	header('vary: Origin');
	
	date_default_timezone_set('Asia/Kolkata');
	$shnunc = date("Y-m-d H:i:s");
	$res = [
		'code' => 11,
		'msg' => 'Method not allowed',
		'msgCode' => 12,
		'serviceNowTime' => $shnunc,
	];
	$shonubody = file_get_contents("php://input");
	$shonupost = json_decode($shonubody, true);
	if ($_SERVER['REQUEST_METHOD'] != 'GET') {
		if (isset($shonupost['bannerId']) && isset($shonupost['language']) && isset($shonupost['random']) && isset($shonupost['signature']) && isset($shonupost['timestamp'])) {
			$bannerId = htmlspecialchars(mysqli_real_escape_string($conn, $shonupost['bannerId']));
			$language = htmlspecialchars(mysqli_real_escape_string($conn, $shonupost['language']));
			$random = htmlspecialchars(mysqli_real_escape_string($conn, $shonupost['random']));
			$signature = htmlspecialchars(mysqli_real_escape_string($conn, $shonupost['signature']));
			$shonustr = '{"bannerId":'.$bannerId.',"language":'.$language.',"random":"'.$random.'"}';
			$shonusign = strtoupper(md5($shonustr));
			if($shonusign == $signature){
				$bearer = explode(" ", $_SERVER['HTTP_AUTHORIZATION']);
				$author = $bearer[1];				
				$is_jwt_valid = is_jwt_valid($author);
				$data_auth = json_decode($is_jwt_valid, 1);
				if($data_auth['status'] === 'Success') {
					$sesquery = "SELECT akshinak
					  FROM shonu_subjects
					  WHERE akshinak = '$author'";
					$sesresult=$conn->query($sesquery);
					$sesnum = mysqli_num_rows($sesresult);
					if($sesnum == 1){
						if($bannerId == 7){
							$data['title'] = 'Invitation Bonus';
							$data['img'] = '[{"Id":"17225024498060d979egil58","Url":"https://bluewin.sbs/banner/invitationbig.jpg"}]';
							$data['coverUrl'] = 'https://bluewin.sbs/banner/invitation.jpg';
							$data['jumpType'] = 3;
						}else if($bannerId == 7){
							$data['title'] = 'Winstrike bonus for agents and members';
							$data['img'] = '[{"Id":"17225024498060d979egil58","Url":"https://bluewin.sbs/banner/gamebig.jpg"}]';
							$data['coverUrl'] = 'https://bluewin.sbs/banner/game.jpg';
							$data['jumpType'] = 3;
						}
						else if($bannerId == 6){
							$data['title'] = 'Agent Salary';
							$data['img'] = '[{"Id":"17225024498060d979egil58","Url":"https://bluewin.sbs/banner/agentsalarybig.jpg"}]';
							$data['coverUrl'] = 'https://bluewin.sbs/banner/agentsalary.jpg';
							$data['jumpType'] = 3;
						}
                      	else if($bannerId == 5){
							$data['title'] = 'Partner Reward';
							$data['img'] = '[{"Id":"17225024498060d979egil58","Url":"https://bluewin.sbs/banner/adsfund.jpg"}]';
							$data['coverUrl'] = 'https://bluewin.sbs/bactivity/IMG_20251107_134514_253.jpg';
							$data['jumpType'] = 3;
						}
						else if($bannerId == 4){
							$data['title'] = 'Winning Streak Bonus';
							$data['img'] = '[{"Id":"17225024498060d979egil58","Url":"https://i.postimg.cc/tg8CgZKf/Wining-streak-2.png"}]';
							$data['coverUrl'] = 'https://bluewin.sbs/uploads/activity banners/1758567495_Wining streak 1.png';
							$data['jumpType'] = 3;
						}
						else if($bannerId == 55){
							$data['title'] = 'Download theTASHANWIN app to share 100000000RS red envelope';
							$data['img'] = '<p><font style=""><font color="#ff9c00" style="font-weight: bold;">🎉🎉🎉</font><b style=""><font color="#ff9c00">Join the official channel now and share a </font><font color="#ff0000">100,000,000rs</font><font color="#ff9c00"> rupee bonus🧧🧧🧧</font></b><br></font></p><p><font style=""><b style=""><br></b><b><font color="#ff9c00">🧧🧧🧧</font></b><b style=""><font color="#ff9c00">👉👉</font><a href="https://t.me/TaShanGAMEWIN" target="_blank" style=""><font color="#0000ff">https://t.me/TaShanGAMEWIN</font></a><font color="#ff9c00">👈👈</font></b></font><b style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><font color="#ff9c00">🧧🧧🧧</font></b></p><p><font style=""><b style=""><font color="#ff9c00" style=""><br></font></b></font><img src="https://ossimg.tashanedc.com/Tashanwin/editor/editor_20250417170955c3lq.png" style="width: 810px;"><br></p>';
							$data['coverUrl'] = 'https://ossimg.tashanedc.com/Tashanwin/banner/Banner_20250417171000vues.png';
							$data['jumpType'] = 1;
						}
						else if($bannerId == 36){
							$data['title'] = "WELCOME TO TASHANWIN GAMES";
							$data['img'] = '[{"Id":"1744269124839k3cior8elcf","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250411141013mg9m.png"}]';
                            $data['coverUrl'] = 'https://ossimg.tashanedc.com/Tashanwin/banner/Banner_20250411141013fsd6.png';
							$data['jumpType'] = 3;
						}
						else if($bannerId == 44){
							$data['title'] = "Daily sign-in recharge reward";
                            $data['img'] = '[{"Id":"1744360913477z1wje5nerub","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250411141202ee3y.png"}]';
                          
							$data['coverUrl'] = 'https://ossimg.tashanedc.com/Tashanwin/banner/Banner_20250411141202mscc.png';
							$data['jumpType'] = 3;
						}
						else if($bannerId == 42){
						$data = [
    "title" => "15-day cumulative recharge reward\t\t",
    "img" => '[{"Id":"1744269450925nmw0elvpsac","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250411141130f1g7.png"}]',
    "coverUrl" => "https://ossimg.tashanedc.com/Tashanwin/banner/Banner_2025041114113062h8.png",
    "jumpType" => 3
];
						}else if($bannerId == 48){
						$data = [
    "title" => "Wingo winning streak reward",
    "img" => '[{"Id":"17445316677327h34j09ugd","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250413133757hla4.png"}]',
    "coverUrl" => "https://ossimg.tashanedc.com/Tashanwin/banner/Banner_20250413133757y7on.png",
    "jumpType" => 3
];

						}else if($bannerId == 49){
						$data = [
    "title" => "Pilot special challenge",
    "img" => '[{"Id":"174453170159389znps5uq95","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250413133835f7we.png"}]',
    "coverUrl" => "https://ossimg.tashanedc.com/Tashanwin/banner/Banner_202504131338354j4n.png",
    "jumpType" => 3
];

						}else if($bannerId == 50){
						$data = [
    "title" => "CREATIVE VIDEO BONUS",
    "img" => '[{"Id":"1744532150747scjv11zwc7d","Url":"https://ossimg.tashanedc.com/Tashanwin/banner/Active_20250413134610fpsb.png"}]',
    "coverUrl" => "https://ossimg.tashanedc.com/Tashanwin/banner/Banner_20250413134610gas4.png",
    "jumpType" => 3
];
}
						$res['data'] = $data;
						$res['code'] = 0;
						$res['msg'] = 'Succeed';
						$res['msgCode'] = 0;
						http_response_code(200);
						echo json_encode($res);			
					}
				}
			}
			else{
				$res['code'] = 5;
				$res['msg'] = 'Wrong signature';
				$res['msgCode'] = 3;
				http_response_code(200);
				echo json_encode($res);
			}
		}
		else{
			$res['code'] = 7;
			$res['msg'] = 'Param is Invalid';
			$res['msgCode'] = 6;
			http_response_code(200);
			echo json_encode($res);
		}		
	} else {		
		http_response_code(405);
		echo json_encode($res);
	}	
?>