<?php
function SporAudit($action,$inspector,$inputdate,$sign,$secret,$type){
    		// Проверка хеша
		$hash = md5($action.$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," ");        
        if($inspector==""){
			$arr ['code'] = 103;
			$arr ['message']='Error parameter';
			//$arr ['data'] = $hash;
			$result = json_encode($arr);
			echo $result;
			return;
		}


        $arr = Auditdata ($type,$inspector);
		foreach ($arr as $item){
        $data_array [] = [
            "fineid"=> $item['fineid'],
			"inputdate"=> $item['inputdate'],
			"reason"=> $item['reason'],
			"approved_by" => $item['approved_by'],
			"approved_date"=> $item['approved_date'],
			"Comment"=> $item['Comment'],
			"video"=> $item['video'],
			"photo" => $item['photo'],
			"additionalPhoto" => str_replace('http://217.11.177.108:9907','https://bda.dc.tj',$item['additionalPhoto']),
            "metaPlate" => str_replace('http://217.11.177.108:9907','https://bda.dc.tj',$item['metaPlate']),
            "Inputdate" =>$item['Inputdate'],
            "P2" =>$item['P2']
        ];
		//https://bda.dc.tj/Fines/invoiceImg.php?login=DC&path=c:/Shohin/2024/07/T-22198479_PhotoPlate.jpg&sign=a2baf76d399c8da91d2c9ed7636a5879
		}	
		$responce = ["code"=>"200","comment"=>"Success","result"=>$data_array];
        $result = json_encode($responce);
        echo $result;
        return;

},s.audit_status
,s.audit_by
,s.audit_date
,s.audit_comment

function AddAutitdata ($inspector,$fineid,$inputdate, $comment)
{
    global $con;
	$params = [$inspector,$inputdate,$comment,$fineid];
    $sql = "Update spor set 
		audit_status='10', 
			audit_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;
    }
}

?>