<?php  
session_start(); 
if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	include("mylibrary.php");
	$eve = "select * from res_offer_master";
	$re = mysqli_query($conn, $eve);	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if(mysqli_num_rows($re) > 0)
	{
		$i=1;
		 while($rt = mysqli_fetch_assoc($re))
		 {
			 ;	
				$offermid=$rt['offermid'];
				$branchmid=$rt['branchmid'];
				$offerstartdate=date("d-m-Y",strtotime($rt['offerstartdate']));
				$offervalidtill=date("d-m-Y",strtotime($rt['offervalidtill']));
				$branchname='';
				 $eve2 = "select * from res_branch_master where branchmid='$branchmid'";
				$re2 = mysqli_query($conn, $eve2);
				if(mysqli_num_rows($re2) > 0)
				{
					
					while($rt2 = mysqli_fetch_assoc($re2))
					{
							$branchname=$rt2['branchname'];
					}
				}
				$subservicemid=$rt['subservicemid'];
				$subservicename='';
				 $eve3 = "select * from res_subservice_master where subservicemid='$subservicemid'";
				$re3 = mysqli_query($conn, $eve3);
				if(mysqli_num_rows($re3) > 0)
				{
					
					while($rt3 = mysqli_fetch_assoc($re3))
					{
							$subservicename=$rt3['subservicename'];
					}
				}
				
				$pidedit='';
				$currentfile1 = basename($_SERVER['PHP_SELF']);
				 $currentfile = ltrim($currentfile1, 'json');
											$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and maedit=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$pidedit="<a href='offeredit.php?id=".$rt['offermid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
				
				
				}
				
				$piddelete='';
				$eve23 = "select * from res_moduleallocation_detail where smodulemid in (select smodulemid from res_submodule_master where smfilename='$currentfile') and madelete=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				
				$eve11 = "select offermid from res_studentinquiry_detail where offermid=$offermid";
				$re11 = mysqli_query($conn, $eve11);
	
				if(mysqli_num_rows($re11)>0 )
					{
					}else{
				$piddelete="<a href='offerdelete.php?id=".$rt['offermid']."'onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";	
					}
					}					
                $op=$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				$offername=checkvalidstring ($rt['offername']);
				
				$offerdiscount=checkvalidstring ($rt['offerdiscount']);
				
				$offercouponcode=checkvalidstring ($rt['offercouponcode']);
				
				
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op,'piddelete'=> $piddelete, 'offername'=> $offername, 'branchname'=> $branchname, 'subservicename'=> $subservicename, 'offervalidtill'=> $offervalidtill, 'offerstartdate'=> $offerstartdate, 'offerdiscount'=> $offerdiscount, 'offercouponcode'=> $offercouponcode);
		 }
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		mysqli_close($conn);
		return;
	}
	
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }   
	mysqli_close($conn);	
	
?>