<?php
session_start();
if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	include("connect.php");	header("Access-Control-Allow-Origin: *");
		$brmid=$_SESSION['linkarisebranchid'];
		$cmpmid=$_SESSION['linkarisecmpmid'];
			$umid = $_SESSION['linkariseumid'];

	
		$tt="";
		if($_SESSION['linkariseutype']<>'Admin')
		{
			$tt=" and umid=$umid";
		}
	 $eve = "select * from res_party_master where cmpmid=$cmpmid and partytype in ('Inquiry') $tt order by partymid 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))
		{
			 	$partymid=$rt['partymid'];
			 	$partyno=$rt['partyno'];
			 	$umid=$rt['umid'];

			
				$iedit="<a href='inquiryedit.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>";
			
				$idelete="<a href='inquirydelete.php?id=".$rt['partymid']."' 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>";
				
				$idetail="<a href='inquirystatus.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Detail' class='fa fa-eye fa-lg'>  </a>";
			

				$op=$idetail."&nbsp".$iedit."&nbsp".$idelete;



				$isname=$rt['partyinqsource'];
				$bumid=$rt['partymid'];
				$partystage=$rt['partystage'];
				$cmpname=$rt['partyname'];
				$cname=$rt['partycpname'];
				$mobilenumber=$rt['partymobile'];
				$email=$rt['partyemail'];
				$mobile=$rt['partymobile'];
				$mobilenumber=$rt['partymobile'];
				$idate=date("d-m-Y", strtotime($rt['partyinqdate']));  
				$itype=$rt['partytype'];
				$idetails=$rt['partyrequirement'];
				$function=$rt['function'];
				$spotmid=$rt['spotmid'];
				$fdate=date("d-m-Y", strtotime($rt['fstartdate']));
			
				$idetails=substr($idetails,0,100);
				if(strlen($idetails)>=99)
				{
					$idetails=$idetails."...";
				}
				$partyinqstatus=$rt['partyinqstatus'];
				$ibudge=$rt['partyinqbudget'];
				$partyinqstatus2="<a href='inquirystatus.php?id=$partymid' >Click Here</a>";
				$uname="";
				$eve7="select * from res_user_master where umid=$umid";
					$re7 = mysqli_query($conn, $eve7);
					while($rt7 = mysqli_fetch_assoc($re7))
					{
						$uname=$rt7['uname'];
						
					}

$spotname="";
				$eve71="select * from res_spot_master where spotmid=$spotmid";
					$re71 = mysqli_query($conn, $eve71);
					while($rt71 = mysqli_fetch_assoc($re71))
					{
						$spotname=$rt71['spotname'];
						
					}

				$idetails=str_replace ("'","'",$idetails);
				$idetails=str_replace ('"','\"',$idetails);
				if($partystage=="New")
				{
					
					$partystage="<span class='label label-sm label-success'>New </span>";
				}
				else if($partystage=="Completed")
				{
					
					$partystage="<span class='label label-sm label-success'>Completed</span>";
				}
				else if($partystage=="Hold")
				{
					
					$partystage="<span class='label label-sm label-danger'>Hold</span>";
				}
				else if($partystage=="In Progress")
				{
					
					$partystage="<span class='label label-sm label-warning'>In Progress</span>";
				}
				$partyinqstatus1="";
				$partyinqstge1="<a href='inquirystatus.php?id=".$rt['partymid']."' >$partystage</a>";
			
			
				if($partyinqstatus=="Pending")
				{

					$partyinqstatus1="<span class='label label-sm label-info'>Pending <span class='fa fa-edit fa-lg'></span></span>";
				}
				else if($partyinqstatus=="Converted To Sales")
				{

					$partyinqstatus1="<span class='label label-sm label-success'>Converted <span class='fa fa-edit fa-lg'></span></span>";
				}
				else
				{
					$partyinqstatus1="<span class='label label-sm label label-danger '>$partyinqstatus  <span class='fa fa-edit fa-lg'></span> </span>";
				}
				$partyinqstatus1="<a href='inquiryfollowupaddnext.php?id=".$rt['partymid']."' data-toggle='tooltip' data-placement='top' title='Detail' >$partyinqstatus1  </a>";


			//$imid1="@".$imid;
			$imid1="$i";

				$posts[] = array('partymid'=> $partymid,'partyno'=> $partyno, 'op'=> $op,'cname'=> $cname,'cmpname'=> $cmpname,'idate'=> $idate,'itype'=> $itype,'idetails'=> $idetails,'partyinqstatus1'=> $partyinqstatus1,'isname'=> $isname,'email'=>$email,'mobile'=>$mobile,'ibudge'=>$ibudge,'istatus2'=>$partyinqstatus2,'mobilenumber'=>$mobilenumber,'uname'=>$uname,'partyinqstge1'=>$partyinqstge1,'function'=>$function,'spotname'=>$spotname,'fdate'=>$fdate);

			$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);
?>
