<?php
$allow = array("94.199.52.160", "37.234.69.4"); //allowed IPs

function tomb2($t) {return "<pre style='color:red'>". print_r($t)."</pre>"; }

ini_set('display_errors', 'Off');
ini_set('error_reporting', E_ALL);


// if(in_array($_SERVER['REMOTE_ADDR'], $allow) ) {
$hostname_conDB = "localhost";
$database_conDB = "vetmedla_web";
$username_conDB = "vetmedla_web";
$password_conDB = "Siker1515";
$elotag = "zbt7h";

// Create connection
$CDB = new mysqli($hostname_conDB, $username_conDB, $password_conDB, $database_conDB);

// Check connection
if ($CDB->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 



$log = 'CALLBACK ('.$_SERVER['REMOTE_ADDR'].'): ';
	
	$d = json_decode(file_get_contents('php://input'), true);
	
	if ( $d['contract_id'] ) {

		$log .= $d['contract_id']." : ".$d['action']." - " ;

		$sql = "UPDATE ".$elotag."_ati_egyedi SET szeri_stat='".$d['action']."' WHERE szeri_id=".$d['contract_id'];
		$result = $CDB->query($sql);

		if ($d['action'] == 'done_signed_contract') {

			$sql = "SELECT * FROM ".$elotag."_ati_egyedi WHERE szamla_stat='paid' AND szeri_id=".$d['contract_id'];
			$ds = $CDB->query($sql);
		    $row = $ds->fetch_assoc(); 
		    if(count($row) ) {
				$sql = "INSERT ".$elotag."_user_usergroup_map SET user_id='".$row['user']."', group_id='".$row['group']."'";
				$result = $CDB->query($sql);
				//log
				$log .= $row['szamla_szama']." - User group kiosztva - ".$row['user']." :: ".$row['group'];
			}
		}
		
	}

		$sql = "INSERT ".$elotag."_ati_egyedi_log SET user='0', esemeny='".$log."'";
		$result = $CDB->query($sql);



// } else  die('NYET');
/*
 {
            "contract_id":174044,
            "action":"done_signed_contract",
            "contract_url":"https://www.eszerzodes.hu/####/#######.pdf"
         }
*/

?>