TransWar File Browser

Path: C:\

<?php
  ini_set('max_execution_time',259200);
  ini_set('memory_limit' , '-1' ) ;
	$reg_veic = $reg_veiculo = array();
	$tipo['00'] = 'Não Aplicável';
	$tipo['01'] = 'Truck';
	$tipo['02'] = 'Toco';
	$tipo['03'] = 'Cavalo Mecânico';
	$tipo['04'] = 'VAN';
	$tipo['05'] = 'Utilitário';
	$tipo['06'] = 'Outros';	
	$url_veic = URL_SIIMP."/vehicles/search?active=on&page=1";
	$curl_veic = curl_init($url_veic);
	curl_setopt($curl_veic, CURLOPT_URL, $url_veic);
	curl_setopt($curl_veic, CURLOPT_RETURNTRANSFER, true);
	$headers_veic = array(
	   "accept: application/json",
	   "x-api-key: ".KEY_SIIMP,
	);
	curl_setopt($curl_veic, CURLOPT_HTTPHEADER, $headers_veic);
	curl_setopt($curl_veic, CURLOPT_SSL_VERIFYHOST, false);
	curl_setopt($curl_veic, CURLOPT_SSL_VERIFYPEER, false);
	curl_setopt($curl_veic, CURLOPT_HEADER, 1);
	$resp_veic = curl_exec($curl_veic);
	$info_veic = curl_getinfo($curl_veic, CURLINFO_HTTP_CODE);
	curl_close($curl_veic);
  if($info_veic!==200){
    echo 'Info Veiculos: '.$info_veic.'<br>';
    $fopen  = fopen('logs/veiculos.txt','a');
    $fwrite = fwrite($fopen,'datetime: '.$DT1.';Resposta HTTP: '.$info_veic.PHP_EOL);
    fclose($fopen);
    $log=false;
  }else{
		$out = preg_split('/(\r?\n){2}/', $resp_veic, 2);
		$headers = $out[0];
		$body[1] = $out[1];
		$headersArray = preg_split('/\r?\n/', $headers);
		$headersArray = array_map(function($h) {
		  return preg_split('/:\s{1,}/', $h, 2);
		}, $headersArray);
		$tmp = [];
		foreach($headersArray as $h) {
	    $tmp[strtolower($h[0])] = isset($h[1]) ? $h[1] : $h[0];
		}
		$headersArray = $tmp; $tmp = null;
		$body[0]=$headersArray['x-ratelimit-remaining'];
	  $reg_veic0=json_decode($body[1], true);
	  $resta=$body[0];if($resta<=5){sleep(20);}
		//echo '<br><strong>Restam <font size="5" color="red">'.$resta.'</font> consultas dentro do limite de tempo!</strong><br>';
		//echo $url_veic.'<br>';
	  if ($reg_veic0['success']==1){
	  	$total=$reg_veic0['total'];
	    $p1=$p2=0;
			$pagina=array();
	    $npage=ceil($total/40);
			//echo '<strong>Para listar <font size="5" color="red">'.$npage.'</font> páginas com <font size="5" color="red">'.$total.'</font> registros.</strong><br>';
	    if($npage>=1){
	    	for($i=1;$i<=$npage;$i++){   		// em produção totas as páginas
					$url_veic = URL_SIIMP."/vehicles/search?active=on&page=".$i;
					$curl_veic = curl_init($url_veic);
					curl_setopt($curl_veic, CURLOPT_URL, $url_veic);
					curl_setopt($curl_veic, CURLOPT_RETURNTRANSFER, true);
					$headers_veic = array(
					   "accept: application/json",
					   "x-api-key: ".KEY_SIIMP,
					);
					curl_setopt($curl_veic, CURLOPT_HTTPHEADER, $headers_veic);
					curl_setopt($curl_veic, CURLOPT_SSL_VERIFYHOST, false);
					curl_setopt($curl_veic, CURLOPT_SSL_VERIFYPEER, false);
					curl_setopt($curl_veic, CURLOPT_HEADER, 1);
					$resp_veic = curl_exec($curl_veic);
					curl_close($curl_veic);
					$out = preg_split('/(\r?\n){2}/', $resp_veic, 2);
					$headers = $out[0];
					$body[1] = $out[1];
					$headersArray = preg_split('/\r?\n/', $headers);
					$headersArray = array_map(function($h) {
					  return preg_split('/:\s{1,}/', $h, 2);
					}, $headersArray);
					$tmp = [];
					foreach($headersArray as $h) {
				    $tmp[strtolower($h[0])] = isset($h[1]) ? $h[1] : $h[0];
					}
					$headersArray = $tmp; $tmp = null;
					$body[0]=$headersArray['x-ratelimit-remaining'];
				  $reg_veic[]=json_decode($body[1], true);
				  $resta=$body[0];if($resta<=5){sleep(20);}
					//echo $url_veic.'<br>';
	    	}
	    	foreach($reg_veic as $row1 => $col1){
	    		foreach($col1['data'] as $row2 => $col2){
	    			if($col2['active']=='on'){
	    				if(isset($col2['fleet'])){
	    					if(strripos($col2['fleet'], 'TW') !== false or strripos($col2['fleet'], 'AGREGADO') !== false){
		    					$placa=$col2['license_plate'];
		    					$reg_veiculo[$placa]['frota']=strtok($col2['fleet'], " ");
			    				if($col2['type']==1){$reg_veiculo[$placa]['tipo']='Carreta';}
			    				else{$reg_veiculo[$placa]['tipo']=$tipo[$col2['wheel_type']];}
		    					$reg_veiculo[$placa]['marca']=$col2['vehicle_specification']['manufacturer'];
		    					$reg_veiculo[$placa]['modelo']=$col2['vehicle_specification']['model'];
			    			}
		    			}
	    			}
	    		}
	    	}
	    }
	  }
    $log=true;
	}
?>