<?php


ini_set('session.gc_maxlifetime', 30*60);

session_start();

include '../../../includes/config.php';



$TU_ID = $_GET['UT_ID'];
$Trip_ID = $_GET['Trip_ID'];
	$Max_Limit_Riders = $_GET['Max_Limit_Riders'];	
	$Gender = $_GET['Gender'];
	$Total_KM_Distance = $_GET['Total_KM_Distance'];	

	$Date = $_GET['Date'];
	$D_ID = $_GET['D_ID'];	


	$lng1 = $_GET['lng1'];	
	$lat1 = $_GET['lat1'];	
	$lng2 = $_GET['lng2'];	
	$lat2 = $_GET['lat2'];	
	$From_Location = $_GET['From_Location'];	
	$To_Location = $_GET['To_Location'];	



$sql1 = mysqli_query($dbConn,"update trips_users set Status='Accepted' WHERE ID='$TU_ID'");
$sql2 = mysqli_query($dbConn,"select * from trips_users where ID='$TU_ID'");
$row2 = mysqli_fetch_array($sql2);
$User_ID = $row2['User_ID'];








$sql2 = mysqli_query($dbConn,"select * from users where ID='$User_ID'");
$row2 = mysqli_fetch_array($sql2);
$Driver_Phone_Type = $row2['Phone_Type'];
$UU_ID = $row2['U_ID'];



if ($User_Phone_Type=='Android'){
	
	
	function sendMessage($UU_ID){
        
    
        $content = array(
            "en" => 'لقد تم قبول طلبك من السائق !'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            'include_player_ids' => array($UU_ID),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($UU_ID);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");
	
	
	
	
}else{
	
	
	
	 function sendMessage($UU_ID){
        
        
        
        
        
        $content = array(
            "en" => 'لقد تم قبول طلبك من السائق !'
            );
        
        $fields = array(
            'app_id' => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            'include_player_ids' => array($UU_ID),
            'data' => array("foo" => "bar"),
            'contents' => $content
        );
        
        $fields = json_encode($fields);
       // print("\nJSON sent:\n");
       // print($fields);
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

        $response = curl_exec($ch);
        curl_close($ch);
        
        return $response;
    }
    
    $response = sendMessage($UU_ID);
    $return["allresponses"] = $response;
    $return = json_encode( $return);
    
   // print("\n\nJSON received:\n");
   //    print($return);
   // print("\n");	
   
   
	
	
	
}

























	echo '<script language="JavaScript">
 document.location="shared-same-gender-4.php?Trip_ID='.$Trip_ID.'&Max_Limit_Riders='.$Max_Limit_Riders.'&Gender='.$Gender.'&Total_KM_Distance='.$Total_KM_Distance.'&Date='.$Date.'&D_ID='.$D_ID.'&lng1='.$lng1.'&lat1='.$lat1.'&lng2='.$lng2.'&lat2='.$lat2.'&From_Location='.$From_Location.'&To_Location='.$To_Location.'";
</script>';




?>
