120 lines
3.2 KiB
PHP
120 lines
3.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace manager\module;
|
||
|
use \manager\Database;
|
||
|
use \manager\ResourceDispatcher;
|
||
|
use \manager\sessionManager;
|
||
|
use \manager\ModuleRequest;
|
||
|
use \manager\ManagerError;
|
||
|
use \manager\Repo;
|
||
|
|
||
|
class download{
|
||
|
|
||
|
public static function phone($params){
|
||
|
extract($params);
|
||
|
|
||
|
// TODO: Implémenter proprement en utilisant le système de retour + utilisant la liste de sujets dans les paramètres
|
||
|
|
||
|
|
||
|
$file_name = sessionManager::sha1($subjects[0]);
|
||
|
|
||
|
$phone_log = json_decode( file_get_contents(__ROOT__.'/src/upload/phone_storage/'.$file_name.'.json'), true );
|
||
|
$dict = json_decode( file_get_contents(__ROOT__.'/src/upload/phone_storage/dictionary.json'), true );
|
||
|
|
||
|
// $output = $phone_log;
|
||
|
|
||
|
|
||
|
// Contiendra le résultat
|
||
|
$output = array( 'logs' => '', 'contacts' => '' );
|
||
|
|
||
|
|
||
|
// Dans le parsage en CSV, ajouter les valeurs du dictionnaire en option (paramétrable)
|
||
|
|
||
|
/* [1] Journal d'appel
|
||
|
=========================================================*/
|
||
|
foreach($phone_log['logs'] as $i=>$log){
|
||
|
|
||
|
/* (1) Colonnes */
|
||
|
$logid = 0;
|
||
|
if( $i == 0 )
|
||
|
foreach($log as $key=>$val){
|
||
|
$output['logs'] .= ($logid<count($log)-1) ? '"'.$key.'",' : '"'.$key.'"'."\r\n";
|
||
|
$logid++;
|
||
|
}
|
||
|
|
||
|
/* (2) Valeurs */
|
||
|
$logid = 0;
|
||
|
foreach($log as $key=>$val){
|
||
|
|
||
|
if( isset($dict['logs'][$key][$val]) )
|
||
|
$output['logs'] .= '"'.$dict['logs'][$key][$val].'"';
|
||
|
else
|
||
|
$output['logs'] .= '"'.$val.'"';
|
||
|
|
||
|
// Si pas dernier, on met une virgule, sinon retour à la ligne
|
||
|
$output['logs'] .= ($logid<count($log)-1) ? ',' : ''."\r\n";
|
||
|
|
||
|
$logid++;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/* [2] Contacts
|
||
|
=========================================================*/
|
||
|
foreach($phone_log['contacts'] as $i=>$log){
|
||
|
|
||
|
/* (1) Colonnes */
|
||
|
$logid = 0;
|
||
|
if( $i == 0 )
|
||
|
foreach($log as $key=>$val){
|
||
|
$output['contacts'] .= ($logid<count($log)-1) ? '"'.$key.'",' : $key.'"'."\r\n";
|
||
|
$logid++;
|
||
|
}
|
||
|
|
||
|
/* (2) Valeurs */
|
||
|
$logid = 0;
|
||
|
foreach($log as $key=>$val){
|
||
|
|
||
|
if( isset($dict['contacts'][$key][$val]) )
|
||
|
$output['contacts'] .= '"'.$dict['contacts'][$key][$val].'"';
|
||
|
else
|
||
|
$output['contacts'] .= '"'.$val.'"';
|
||
|
|
||
|
// Si pas dernier, on met une virgule, sinon retour à la ligne
|
||
|
$output['contacts'] .= ($logid<count($log)-1) ? ',' : ''."\r\n";
|
||
|
|
||
|
$logid++;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/* [3] Création de l'archive
|
||
|
=========================================================*/
|
||
|
$zip = new \ZipArchive();
|
||
|
$fname = '/tmp/'.time().'.zip';
|
||
|
$zip->open($fname, \ZipArchive::CREATE);
|
||
|
|
||
|
foreach($output as $name=>$content)
|
||
|
$zip->addFromString($name.'.csv', $content);
|
||
|
|
||
|
$zip->close();
|
||
|
|
||
|
/* [4] On lance le téléchargement
|
||
|
=========================================================*/
|
||
|
header("Content-type: application/zip");
|
||
|
header("Content-Disposition: attachment; filename=phone_data.zip");
|
||
|
header("Pragma: no-cache");
|
||
|
header("Expires: 0");
|
||
|
|
||
|
readfile($fname);
|
||
|
exit();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
?>
|