<?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_ticket_master order by tstatus desc,taddedon 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))
		{
			 	$tmid=$rt['tmid'];
				$catedit="<a href='ticketedit.php?id=".$rt['tmid']."' 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='ticketdelete.php?id=".$rt['tmid']."' 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>";
				
				$tmessage=$rt['tmessage'];
				$taddedon=$rt['taddedon'];
				$brmid=$rt['brmid'];
				$tstatus=$rt['tstatus'];
				
				if($tstatus=="Pending")
				{
					
					$tstatus1="<a href='ticketstatus.php?id=".$rt['tmid']."' ><span class='label label-sm label-danger'>$tstatus</span></a>";
				}
				else
				{
					$tstatus1="<a href='ticketstatus.php?id=".$rt['tmid']."' ><span class='label label-sm label label-success '>$tstatus</span></a>";
				}
						$brname="";				
					$eve2 = "select * 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('tmid'=> $i, 'catedit'=> $catedit, 'catdelete'=> $catdelete, 'tmessage'=> $tmessage, 'taddedon'=> $taddedon,'brname'=> $brname, 'op'=> $op, 'tstatus1'=> $tstatus1);
				
				$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);	
?>