112 lines
3.6 KiB
PHP
112 lines
3.6 KiB
PHP
|
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||
|
require_once __ROOT__.'/manager/autoloader.php';
|
||
|
|
||
|
use \manager\ModuleRequest;
|
||
|
use \manager\ResourceDispatcher;
|
||
|
use \manager\sessionManager;
|
||
|
use \manager\ManagerError;
|
||
|
|
||
|
debug();
|
||
|
|
||
|
|
||
|
|
||
|
// Fonction pour corriger les dates
|
||
|
function correctDates($date){
|
||
|
$date = str_replace('janv.', 'jan.', $date);
|
||
|
$date = str_replace('févr.', 'feb.', $date);
|
||
|
$date = str_replace('mars', 'march', $date);
|
||
|
$date = str_replace('avr.', 'apr.', $date);
|
||
|
$date = str_replace('mai', 'may', $date);
|
||
|
$date = str_replace('juin', 'june', $date);
|
||
|
$date = str_replace('juil.', 'july', $date);
|
||
|
$date = str_replace('août', 'aug.', $date);
|
||
|
|
||
|
return strtotime($date);
|
||
|
}
|
||
|
|
||
|
/* [0] Upload du fichier
|
||
|
=========================================================*/
|
||
|
if( isset($_FILES) && isset($_FILES['file']) ){
|
||
|
|
||
|
$request = new ModuleRequest('upload/iexplorer_convert');
|
||
|
$response = $request->dispatch();
|
||
|
|
||
|
// Si erreur, on l'affiche
|
||
|
if( $response->error != ManagerError::Success )
|
||
|
var_dump( ManagerError::explicit($response->error) );
|
||
|
|
||
|
// On récupère les données
|
||
|
$logs = $response->get('data');
|
||
|
|
||
|
/* [1] On associe un faux numéro à chaque utilisateur
|
||
|
=========================================================*/
|
||
|
$falseNumbers = array(0); // Contiendra les numéros attribués
|
||
|
$alreadyNumbered = array(); // Contiendra aux mêmes indices que les numéros, les noms des personnes les ayant utilisé
|
||
|
|
||
|
// Pour chaque utilisateur
|
||
|
foreach($logs as $i=>$log){
|
||
|
|
||
|
// On évite la première ligne
|
||
|
if( $i == 0 ){
|
||
|
unset($logs[$i]);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
$numberIndex = array_search($log['Number'], $alreadyNumbered);
|
||
|
|
||
|
/* (1) Si pas encore de numéro, on en attribue un */
|
||
|
if( $numberIndex === false ){
|
||
|
$lastnumIndex = count($falseNumbers) - 1;
|
||
|
$newNumber = ++$falseNumbers[$lastnumIndex];
|
||
|
$numberIndex = array_push($falseNumbers, $newNumber ) - 1;
|
||
|
$alreadyNumbered[$numberIndex] = $log['Number'];
|
||
|
}
|
||
|
|
||
|
$logs[$i]['Name'] = $logs[$i]['Number'];
|
||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||
|
}
|
||
|
|
||
|
/* (2) On convertit les numéros en string */
|
||
|
foreach($falseNumbers as $n=>$number){
|
||
|
$stringNumber = "0600000000"; $snlen = strlen($stringNumber);
|
||
|
$stringValue = strval($number); $svlen = strlen($stringValue);
|
||
|
|
||
|
$stringNumber = substr($stringNumber, 0, $snlen-$svlen);
|
||
|
$stringNumber .= $stringValue;
|
||
|
|
||
|
$falseNumbers[$n] = $stringNumber;
|
||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||
|
}
|
||
|
|
||
|
foreach($logs as $i=>$log){
|
||
|
$numberIndex = array_search($log['Name'], $alreadyNumbered);
|
||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||
|
}
|
||
|
|
||
|
/* [2] On rédige les headers
|
||
|
=========================================================*/
|
||
|
header('Content-type: text/xml');
|
||
|
header('Content-Disposition: attachment; filename=call-log.xml');
|
||
|
|
||
|
|
||
|
/* [3] On rédige le contenu du fichier XML
|
||
|
=========================================================*/
|
||
|
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
|
||
|
echo "<Logs>\n";
|
||
|
|
||
|
// Pour chaque utilisateur
|
||
|
foreach($logs as $i=>$log)
|
||
|
echo "<Item Number='${log['Number']}' Name='${log['Name']}' Date='".correctDates($log['Date'])."' Duration='".strtotime("1970-01-01 ${log['Duration']} UTC")."' Direction='".strtoupper($log['Call Type'])."' Type='PHONE' />\n";
|
||
|
|
||
|
echo "</Logs>\n";
|
||
|
|
||
|
// Si aucun fichier
|
||
|
}else{ ?>
|
||
|
<form action='' method='POST' enctype='multipart/form-data'>
|
||
|
<input type='file' name='file'>
|
||
|
<input type='submit' value='Convertir en call-log'>
|
||
|
</form>
|
||
|
<?php }
|
||
|
|
||
|
?>
|