<?php
function SporCancel($action,$inspector,$fineid,$inputdate,$comment,$sign,$secret){
    		// Проверка хеша
		$hash = md5($action.$inspector.$fineid.$inputdate.$secret);
		if($sign!=$hash){
			$arr ['code'] = 103;
			$arr ['message']='Error sign';
			//$arr ['data'] = $hash;
			$result = json_encode($arr);
			echo $result;
			return;
		}
        $inspector=trim($inspector," ");
        $comment=str_replace("\'","",$comment);
        if($inspector==""){
			$arr ['code'] = 103;
			$arr ['message']='Error parameter';
			//$arr ['data'] = $hash;
			$result = json_encode($arr);
			echo $result;
			return;
		}


        $arr = SporCancelDb ($inspector,$fineid,$inputdate, $comment);
        $result = json_encode($arr);
        echo $result;
        return;

}


function SporCancelDB ($inspector,$fineid,$inputdate, $comment)
{
    global $con;
	$params = [$inspector,$inputdate,$comment,$fineid];
    $sql = "Update spor set status='5', approved_by= ?,
            approved_date= ?,
            comment=?
            where fineid = ? ";
    try{
        $query = sqlsrv_query($con,$sql,$params);
        $arr = ["code"=>"100","message"=>$sql];
        if($query!=false)
        {
            $arr = ["code"=>"200","message"=>"Success cancel"];
        }
        else{
            $arr = ["code"=>"100","message"=>"Error cancel"];
        }
        return $arr;

    }catch(Exception $ex){
        $arr = ["code"=>"102","message"=>$ex->getMessage()];
        return $arr;
    }
}

?>