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

	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	 $eve = "select * from res_packagewisebookset_detail  group by packagemid";
	$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))
		 {
			 	
				$pbdid=$rt['pbdid'];
				$packagemid=$rt['packagemid'];
				$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='packagewisebooksetedit.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='packagewisebooksetdelete.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=$pidedit."&nbsp;&nbsp;&nbsp; ".$piddelete;
								
								
				
				
				$booksetname1='';
				 $eve2 = "select * from res_packagewisebookset_detail where packagemid=$packagemid";
				$re2 = mysqli_query($conn, $eve2);
				$packagename='';
				if(mysqli_num_rows($re2) > 0)
				{
					
					 while($rt2 = mysqli_fetch_assoc($re2))
					 {
							
						 $booksetmid=$rt2['booksetmid'];
						$eve3 = "select * from res_bookset_master where booksetmid=$booksetmid";
						$re3 = mysqli_query($conn, $eve3);
						$packagename='';
						if(mysqli_num_rows($re3) > 0)
						{
							
							 while($rt3 = mysqli_fetch_assoc($re3))
							 {
									
								$booksetname=$rt3['booksetname'];
							 }
						}
						if($booksetname1 != '')
						{
						$booksetname1 = $booksetname1.",".$booksetname;
						}else{
							$booksetname1 = $booksetname;
						}
					 }
				}
				
				
				$eve1 = "select * from res_package_master where packagemid=$packagemid";
				$re1 = mysqli_query($conn, $eve1);
				$packagename='';
				if(mysqli_num_rows($re1) > 0)
				{
					
					 while($rt1 = mysqli_fetch_assoc($re1))
					 {
							
						$packagename=$rt1['packagename'];
					 }
				}
				
								
				$posts[] = array('srno'=> $i++,'op'=> $op,'piddelete'=> $piddelete, 'booksetname'=> $booksetname1, 'package'=> $packagename);
		 }
		 
		$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);	
	
?>