2009-07-16 16:12:17 +00:00
< ? php
require_once 'common/dates.php' ;
require_once 'common/curl.php' ;
2009-09-10 08:43:29 +00:00
isset ( $_REQUEST [ 'start' ]) ? $start = $_REQUEST [ 'start' ] : $start = 0 ;
isset ( $_REQUEST [ 'login' ]) ? $login = $_REQUEST [ 'login' ] : $login = '' ;
isset ( $_REQUEST [ 'date' ]) ? $date = substr ( $_REQUEST [ 'date' ], 3 , 4 ) . substr ( $_REQUEST [ 'date' ], 0 , 2 ) : $date = 0 ;
isset ( $_REQUEST [ 'url' ]) ? $url = $_REQUEST [ 'url' ] : $url = '' ;
( isset ( $_REQUEST [ 'details' ]) && $_REQUEST [ 'details' ] == 'true' ) ? $details = 1 : $details = 0 ;
( isset ( $_REQUEST [ 'all' ]) && $_REQUEST [ 'all' ] == 'true' ) ? $all = 1 : $all = 0 ;
isset ( $_REQUEST [ 'idClient' ]) ? $idClient = $_REQUEST [ 'idClient' ] : $idClient = 0 ;
//Debug
$firephp -> log ( $all , 'all' );
2009-07-17 13:16:09 +00:00
$firephp -> log ( $details , 'details' );
2009-09-10 08:43:29 +00:00
$firephp -> log ( $start , 'start' );
2009-07-16 16:12:17 +00:00
$return = '' ;
//Connection au webservice
$client = new SoapClient ( null , array ( 'trace' => 1 ,
'soap_version' => SOAP_1_1 ,
'location' => WEBSERVICE_URL ,
'uri' => WEBSERVICE_URI ,
'login' => $_SESSION [ 'tabInfo' ][ 'login' ],
'password' => $_SESSION [ 'tabInfo' ][ 'password' ],
));
//R<> cup<75> ration de l'url pour le t<> l<EFBFBD> chargement du fichier
if ( $start == 1 ){
try {
2009-09-10 08:43:29 +00:00
$O = $client -> getLogsClients ( $date , $details , $idClient , $login , $all );
2009-07-16 16:12:17 +00:00
$logs = $O [ 'result' ];
$url = $logs [ 'Url' ];
$return = $url ;
} catch ( SoapFault $fault ) {
require_once 'soaperror.php' ;
processSoapFault ( $client , $fault , $_SESSION [ 'tabInfo' ]);
exit ;
}
} else {
$firephp -> log ( $url , 'url' );
//R<> cup<75> ration du nom du fichier
$tableau = explode ( '/' , $url );
$file = $tableau [ sizeof ( $tableau ) - 1 ];
2009-08-21 14:10:21 +00:00
//Suppression du fichier si le temps de cache est d<> pass<73>
if ( file_exists ( PATH_DATA . '/conso/' . $file ) && filemtime ( PATH_DATA . '/conso/' . $file ) > mktime ( date ( " H " ) + 4 , date ( " i " ), date ( " s " ), date ( " m " ), date ( " d " ), date ( " Y " )) )
{
unlink ( PATH_DATA . '/conso/' . $file );
}
2009-07-16 16:12:17 +00:00
//R<> cup<75> ration du fichier sur le serveur
2009-08-21 14:10:21 +00:00
if ( ! file_exists ( PATH_DATA . '/conso/' . $file ))
{
2009-07-16 16:12:17 +00:00
$firephp -> info ( 'D<> marage recup<75> ration du fichier' );
//On check si le fichier est pr<70> sent sur l'url
( isset ( $_REQUEST [ 'url' ]) && url != '' ) ? $url = $_REQUEST [ 'url' ] : '' ;
$page = getUrl ( $url , '' , '' , '' , false );
//Fichier non disponible
2009-07-17 13:16:09 +00:00
if ( $page [ 'code' ] == 408 || $page [ 'code' ] == 400 || $page [ 'code' ] == 404 ){
2009-07-16 16:12:17 +00:00
$return = 'FALSE' ;
//Ecriture du fichier sur le serveur en local
} else {
$body = $page [ 'body' ];
$fp = fopen ( PATH_DATA . '/conso/' . $file , 'w' );
fwrite ( $fp , $body );
fclose ( $fp );
$return = 'FALSE' ;
}
}
2009-08-21 14:10:21 +00:00
2009-07-16 16:12:17 +00:00
//Le fichier existe sur l'extranet, etc....
if ( file_exists ( PATH_DATA . '/conso/' . $file ) && filesize ( PATH_DATA . '/conso/' . $file ) > 0 )
{
$firephp -> info ( 'Fichier sur le serveur local' );
$return = '<u><a title="T<> l<EFBFBD> charger le fichier" target="_blank" href="/datafile.php?q=' . $file . '&type=conso">Cliquez-ici pour t<> l<EFBFBD> charger le fichier.</a></u>' ;
2009-07-17 13:16:09 +00:00
} elseif ( file_exists ( PATH_DATA . '/conso/' . $file ) && filesize ( PATH_DATA . '/conso/' . $file ) == 0 ){
$return = 'Aucune consommation enregistr<74> .' ;
2009-07-16 16:12:17 +00:00
}
}
print $return ;