<?php include('database_connection.php');
date_default_timezone_set("Asia/Muscat");
if(isset($_GET['action']))
{
if($_GET['action']=="getFeedBack")
{
$data=array();  
	if(isset($_GET['GodownID']))
	$GodownID=$_GET['GodownID'];
	else
	$GodownID=0;	
	
   $sql="select ID,CustomerName,Email,Phone,FDate,Comments,(case when Ranks=1 then 'POOR' when  Ranks=2 then 'AVERAGE'   when Ranks=3 then 'GOOD'  when Ranks=4 then 'EXCELLENT' end )  as col_Action,(select Name from Godowns where GodownID=convert(numeric(3),BranchCode)) as BranchName from feedback1 where Branchcode=$GodownID order by ID desc";
  $result=odbc_exec($connection,$sql) or die(odbc_error().$sql);
     while($row=odbc_fetch_array($result))
    {


    $data[]=$row; 
    }
  //  print_r($data);
    echo json_encode($data); 
return;
}
 // echo "Inside=".$_GET['action'];
  if($_GET['action']=="SaveFeedBack")
  {
$data=$_POST['data'];
//print_r($data);
$data=json_decode($data);
$ID=getmaxId('feedback1','ID',$connection)+1;
//$ID=1;
$Active=1;
$FDate=date("Y-m-d H:i:s");
$CustomerName=(isset($data->CustomerName) && $data->CustomerName!="")?$data->CustomerName:'';
$Email=(isset($data->Email) && $data->Email!="")?$data->Email:'';
$Phone=(isset($data->Mobile) && $data->Mobile!="")?$data->Mobile:'';
$Comments=(isset($data->comments) && $data->comments!="")?$data->comments:'';
$BranchCode=(isset($data->BranchCode) && $data->BranchCode!="")?$data->BranchCode:'';
$Rank=(isset($data->Rank) && $data->Rank!="")?$data->Rank:'';
  odbc_autocommit($connection, FALSE);
 $sql="insert into feedback1 (ID,CustomerName,Email,Phone,Comments,FDate,Active,BranchCode,Ranks) values($ID,'$CustomerName','$Email','$Phone','$Comments','$FDate',$Active,'$BranchCode',$Rank)";
odbc_exec($connection,$sql);
 if (!odbc_error())
   {
      odbc_commit($connection);
      $res=array('status'=>"ok",'description'=>'Data Saved Sucessfully');
  }
else
{
      odbc_rollback($connection);
      $res=array('status'=>"Error",'description'=>'Invoice Can Not BE Deleted');

}
    echo json_encode($res);
  }

}
?>
