<?php  
session_start();
	if(!isset($_SESSION['atcrmsuloginsesion']))
	{
		header('Location: index.php');
		return;
	}
	if($_SESSION['atcrmsutype']!='Superuser'){
			header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
	
	$eve = "select * from res_suggestion_master order by sstatus desc,saddedon desc";
	$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))
		{
			 	$smid=$rt['smid'];
				$catedit="<a href='suggestionedit.php?id=".$rt['smid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-pencil fa-md'>  </a>";
				//$tdelete="<a href='Projectdelete.php?id=".$rt['rmid']."' > Delete </a>";
				$catdelete="<a href='suggestiondelete.php?id=".$rt['smid']."' data-toggle='tooltip' data-placement='top' title='Delete' class='fa fa-trash-o fa-md' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);'> </a>";
				 $op=$catedit."&nbsp;&nbsp;&nbsp; ".$catdelete;
				//$cdelete="<a href='customeredit.php?id=$bumid' onClick=\"return confirm('are you sure you want to delete??');\">Delete</a>";
				
				$smessage=$rt['smessage'];
				$saddedon=$rt['saddedon'];
				$brmid=$rt['brmid'];
				$sstatus=$rt['sstatus'];
				
				if($sstatus=="Pending")
				{
					
					$sstatus1="<a href='suggestionstatus.php?id=".$rt['smid']."' ><span class='label label-sm label-danger'>$sstatus</span></a>";
				}
				else
				{
					$sstatus1="<a href='suggestionstatus.php?id=".$rt['smid']."' ><span class='label label-sm label label-success '>$sstatus</span></a>";
				}
						$brname="";				
					$eve2 = "select brname,brmobile from res_businessregister_master where brmid=$brmid";
					$re2 = mysqli_query($conn, $eve2);
					 while($rt2 = mysqli_fetch_assoc($re2))
					{
						$brname=$rt2['brname'].' ('.$rt2['brmobile'].')';
					}
				$posts[] = array('smid'=> $i, 'catedit'=> $catedit, 'catdelete'=> $catdelete, 'smessage'=> $smessage, 'saddedon'=> $saddedon,'brname'=> $brname, 'op'=> $op, 'sstatus1'=> $sstatus1);
				
				$i++;
	
		}
		 
		$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);	
?>