<?php
// This file is used to validate if project id (url parameters) exists and if the payment is succuessful 

include_once("CUserSession.php");
include_once("CUtil.php");
include_once("CPayments.php");
include_once("CPurchase.php");

function validate_and_navigate_payments($project_id){
	$url = split("payments.php",$_SERVER['REQUEST_URI']);
	if(!is_valid_project($project_id)){
		// navigate to dashboard
		header("Location: ".$url[0]."projectDashboard-copy.php");
        return false;
	}
	else{
		$result=get_ubf_billing_info($project_id);
        if($result["payment_result"] == 1){
            $order_id = $result['order_id'];
            $project_id = $result['project_id'];
            header("Location: ".$url[0]."payment_success.php?p=".$project_id."&ord=".$order_id);
            return false;
        }
        else if($result["payment_result"] == 2){
            // Show a popup stating that transaction is declined
            $order_id = $result['order_id'];
            $project_id = $result['project_id'];
            header("Location: ".$url[0]."payment_error.php?p=".$project_id."&ord=".$order_id);
            return false;
        }
	}
    return true;
}

function is_valid_project($project_id){
	if(empty($project_id))
		return false;
	// submitProjectCheck($project_id,"");
	return true;
}

?>