2016-05-12 20:13:37 +00:00
|
|
|
<?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 );
|
2016-05-13 09:14:41 +00:00
|
|
|
|
|
|
|
// Si erreur
|
|
|
|
if( $phone_log == null )
|
|
|
|
return array( 'ModuleError' => ManagerError::ParsingFailed );
|
|
|
|
|
2016-05-12 20:13:37 +00:00
|
|
|
$dict = json_decode( file_get_contents(__ROOT__.'/src/upload/phone_storage/dictionary.json'), true );
|
|
|
|
|
2016-05-13 09:14:41 +00:00
|
|
|
// Si erreur
|
|
|
|
if( $dict == null )
|
|
|
|
return array( 'ModuleError' => ManagerError::ParsingFailed );
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-12 20:13:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2016-05-12 21:29:25 +00:00
|
|
|
|
2016-05-12 20:13:37 +00:00
|
|
|
/* [4] On lance le téléchargement
|
|
|
|
=========================================================*/
|
2016-05-12 21:29:25 +00:00
|
|
|
return array(
|
|
|
|
'ModuleError' => ManagerError::Success,
|
|
|
|
'headers' => array(
|
|
|
|
'Content-Type' => 'application/zip',
|
|
|
|
'Content-Disposition' => 'attachment; filename=phone_data.zip',
|
|
|
|
'Pragma' => 'no-cache',
|
|
|
|
'Expires' => '0'
|
|
|
|
),
|
|
|
|
'body' => file_get_contents($fname)
|
|
|
|
);
|
2016-05-12 20:13:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|