2016-05-24 06:58:37 +00:00
|
|
|
<?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
|
2016-05-24 07:09:55 +00:00
|
|
|
if( $response->error != ManagerError::Success ){
|
2016-05-24 06:58:37 +00:00
|
|
|
var_dump( ManagerError::explicit($response->error) );
|
2016-05-24 07:09:55 +00:00
|
|
|
exit();
|
|
|
|
}
|
2016-05-24 06:58:37 +00:00
|
|
|
|
|
|
|
// 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');
|
2016-05-24 06:59:33 +00:00
|
|
|
header('Content-Disposition: attachment; filename=call-log.xml');
|
2016-05-24 06:58:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* [3] On rédige le contenu du fichier XML
|
|
|
|
=========================================================*/
|
2016-05-24 06:59:33 +00:00
|
|
|
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
|
|
|
|
echo "<Logs>\n";
|
2016-05-24 06:58:37 +00:00
|
|
|
|
|
|
|
// Pour chaque utilisateur
|
|
|
|
foreach($logs as $i=>$log)
|
2016-05-24 06:59:33 +00:00
|
|
|
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";
|
2016-05-24 06:58:37 +00:00
|
|
|
|
2016-05-24 06:59:33 +00:00
|
|
|
echo "</Logs>\n";
|
2016-05-24 06:58:37 +00:00
|
|
|
|
|
|
|
// 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 }
|
|
|
|
|
|
|
|
?>
|