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

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	$eve = "select * from res_package_master where ptype='Country'";
	$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))
		 {
			 
				$packagemid=$rt['packagemid'];
				$packagename=$rt['packagename'];
				$pcurrency=$rt['pcurrency'];
				$pcurrencyrate=$rt['pcurrencyrate'];
				$pcurrencyinr=$rt['pcurrencyinr'];
				$countrymid=$rt['countrymid'];
				$subservicemid=$rt['subservicemid'];
				$eve2= "select countryname from res_country_master where countrymid=$countrymid";
					$re2 = mysqli_query($conn, $eve2);
					 while($rt2 = mysqli_fetch_assoc($re2))
					{
						$countryname=$rt2['countryname'];
					}
					$subservicename = '';
				$eve2= "select subservicename from res_subservice_master where subservicemid=$subservicemid";
					$re2 = mysqli_query($conn, $eve2);
					 while($rt2 = mysqli_fetch_assoc($re2))
					{
						$subservicename=$rt2['subservicename'];
					}
					
				$pidedit='';
				$piddetail='';
				$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 maview=1 and  rolemid = ".$_SESSION['userrolemid'];
											$re23 = mysqli_query($conn, $eve23);
	
				if(mysqli_num_rows($re23)>0 || $_SESSION['utype'] == 'admin')
					{
				$piddetail="<a href='countrywisepackagedetail.php?id=".$rt['packagemid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-eye fa-lg'>  </a>";
					}
											$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='countrywisepackageedit.php?id=".$rt['packagemid']."' 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')
					{
				
				
				$piddelete="<a href='countrywisepackagedelete.php?id=".$rt['packagemid']."'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=$piddetail."&nbsp;&nbsp;&nbsp; ".$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				
				
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op, 'packagename'=> $packagename, 'pcurrency'=> $pcurrency, 'pcurrencyrate'=> $pcurrencyrate, 'pcurrencyinr'=> $pcurrencyinr, 'countryname'=> $countryname, 'subservicename'=> $subservicename);
		 }
		 
		$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);	
	
?>