Gestion du module 'download' uniquement quand appelé dans une page (grace à 'exit()'), fonctionnr pour l'export du .zip
This commit is contained in:
parent
331775c3a9
commit
23c458d0b7
91
automate.php
91
automate.php
|
@ -83,100 +83,11 @@
|
|||
//
|
||||
// }
|
||||
|
||||
function uploadZippedPhoneData(){
|
||||
$phone_log = json_decode( file_get_contents('doc/phone_log.json'), true );
|
||||
$dict = json_decode( file_get_contents('doc/phone_log_dict.json'), true );
|
||||
|
||||
// Contiendra le résultat
|
||||
$output = array( 'call_log' => '', 'contacts' => '' );
|
||||
|
||||
|
||||
|
||||
/* [1] Journal d'appel
|
||||
=========================================================*/
|
||||
foreach($phone_log['call_log'] as $i=>$log){
|
||||
|
||||
/* (1) Colonnes */
|
||||
$logid = 0;
|
||||
if( $i == 0 )
|
||||
foreach($log as $key=>$val){
|
||||
$output['call_log'] .= ($logid<count($log)-1) ? '"'.$key.'",' : '"'.$key.'"'."\r\n";
|
||||
$logid++;
|
||||
}
|
||||
|
||||
/* (2) Valeurs */
|
||||
$logid = 0;
|
||||
foreach($log as $key=>$val){
|
||||
|
||||
if( isset($dict['call_log'][$key][$val]) )
|
||||
$output['call_log'] .= '"'.$dict['call_log'][$key][$val].'"';
|
||||
else
|
||||
$output['call_log'] .= '"'.$val.'"';
|
||||
|
||||
// Si pas dernier, on met une virgule, sinon retour à la ligne
|
||||
$output['call_log'] .= ($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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
$req = new ModuleRequest('call_log/unserialize', array('phone_number'=>'05 05 05 05 05'));
|
||||
$req = new ModuleRequest('download/phone', array('subjects'=>[1]));
|
||||
$res = $req->dispatch();
|
||||
|
||||
var_dump( $res->get('sms') );
|
||||
?>
|
||||
|
|
|
@ -231,5 +231,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
"download": {
|
||||
|
||||
"phone": {
|
||||
"description": "Download des données relatives à une enquête téléphonique.",
|
||||
"permissions": ["admin"],
|
||||
"parameters": {
|
||||
"subjects": { "description": "Identifiants des sujets à intégrer.", "type": "array<id>" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ a.uid+'"] ~ h5>input[type="radio"][data-name="sexe"]'),b=0;b<c.length;b++)c[b].v
|
|||
for(b=0;b<c.length;b++)c[b].value==a.reltype?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="loc"]');for(b=0;b<c.length;b++)c[b].value==a.loc?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="context"]');for(b=0;b<c.length;b++)c[b].value==a.context?
|
||||
c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="freq"]');for(b=0;b<c.length;b++)-1<a.freq.indexOf(c[b].value)?c[b].setAttribute("checked","checked"):c[b].removeAttribute("checked");c=$$('article.fiche-relation input[data-name="uid"][value="'+a.uid+'"] ~ h5>input[type="radio"][data-name="connect"]');for(b=0;b<c.length;b++)-1<a.connect.indexOf(c[b].value)?c[b].setAttribute("checked",
|
||||
"checked"):c[b].removeAttribute("checked")};inputPhoneFiche.prototype.storageToFields=function(){console.log("FICHE: STORAGE TO FIELDS");var a=lsi["export"]("fiches");this.container.innerHTML="";for(var b in a)a[b].uid==this.selected&&this.add(a[b]);this.updateNavBar()};
|
||||
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");var a=lsi["export"]("contacts"),b=[],c;for(c in a){if(-1<a[c].call){var e=a[c].call;b.push(e);console.warn("call",e);var d=lsi.get("fiches",e);null==d&&(d=this.defaultData);d.uid=e;d.contact=parseInt(c);lsi.set("fiches",e,d)}-1<a[c].sms&&(e=10+a[c].sms,b.push(e),console.warn("sms",e),d=lsi.get("fiches",e),null==d&&(d=this.defaultData),d.uid=e,d.contact=parseInt(c),lsi.set("fiches",e,d))}e=20>lsi.keys("contacts").length?lsi.keys("contacts").length:
|
||||
20;if(b.length<e)for(c in a){for(a=0;-1<b.indexOf(a)&&a<e;)a++;console.warn("fill",a);b.push(a);d=lsi.get("fiches",a);null==d&&(d=this.defaultData);d.uid=a;d.contact=parseInt(c);lsi.set("fiches",a,d);if(b.length>=e)break}for(var f in d)b=lsi.get("contacts",d[f].contact),null!=b&&-1!=b.sms&&-1!=b.call&&(b=10>parseInt(f)?10+b.sms:b.call,b=d[b],b.timestamp>=d[f].timestamp||(c=d[f],c.uid=b.uid,lsi.set("fiches",b.uid,c)))};
|
||||
inputPhoneFiche.prototype.sync=function(){console.log("FICHE: SYNC");var a=lsi["export"]("contacts"),b=[],c;for(c in a){if(-1<a[c].call){var e=a[c].call;b.push(e);var d=lsi.get("fiches",e);null==d&&(d=this.defaultData);d.uid=e;d.contact=parseInt(c);lsi.set("fiches",e,d)}-1<a[c].sms&&(e=10+a[c].sms,b.push(e),d=lsi.get("fiches",e),null==d&&(d=this.defaultData),d.uid=e,d.contact=parseInt(c),lsi.set("fiches",e,d))}e=20>lsi.keys("contacts").length?lsi.keys("contacts").length:20;if(b.length<e)for(c in a){for(a=
|
||||
0;-1<b.indexOf(a)&&a<e;)a++;b.push(a);d=lsi.get("fiches",a);null==d&&(d=this.defaultData);d.uid=a;d.contact=parseInt(c);lsi.set("fiches",a,d);if(b.length>=e)break}for(var f in d)b=lsi.get("contacts",d[f].contact),null!=b&&-1!=b.sms&&-1!=b.call&&(b=10>parseInt(f)?10+b.sms:b.call,b=d[b],b.timestamp>=d[f].timestamp||(c=d[f],c.uid=b.uid,lsi.set("fiches",b.uid,c)))};
|
||||
inputPhoneFiche.prototype.nav=function(a){if(null==a||!1===a.getData("n")||isNaN(a.getData("n"))||"nav-fiche"!=a.parentNode.id)return!1;for(var b=$$("#nav-fiche > span.active"),c=0;c<b.length;c++)b[c].remClass("active");a.addClass("active");this.selected=parseInt(a.getData("n"))};
|
||||
inputPhoneFiche.prototype.updateNavBar=function(){var a=lsi["export"]("fiches");this.nav_container.innerHTML="";for(var b=Object.keys(a),c=0;c<b.length;c++){var e=parseInt(b[c]);0==e&&(this.nav_container.innerHTML+="<span>APPELS</span>");10>e&&c<b.length-1&&10<=b[c+1]?this.nav_container.innerHTML+='<span data-n="'+e+'" class="lc">'+(e%10+1)+"</span> ":(10==e&&(this.nav_container.innerHTML+='<span class="fc">SMS</span>'),this.nav_container.innerHTML+='<span data-n="'+e+'">'+(e%10+1)+"</span>")}for(var d in a)b=
|
||||
$('#nav-fiche [data-n="'+a[d].uid+'"]'),null!=b&&(!0===a[d].valid?b.addClass("done"):b.remClass("done"));this.nav($('#nav-fiche [data-n="'+this.selected+'"]'))};
|
||||
|
|
|
@ -315,7 +315,6 @@ inputPhoneFiche.prototype.sync = function(){
|
|||
// On calcule le rang de la fiche en fonction du classement
|
||||
var ficheIndex = contacts[uid].call;
|
||||
addedFicheUids.push(ficheIndex);
|
||||
console.warn('call', ficheIndex);
|
||||
|
||||
// On récupère les informations de la FICHE (si elle existe) */
|
||||
var ficheData = lsi.get('fiches', ficheIndex);
|
||||
|
@ -336,7 +335,6 @@ inputPhoneFiche.prototype.sync = function(){
|
|||
// On calcule le rang de la fiche en fonction du classement
|
||||
var ficheIndex = 10+contacts[uid].sms;
|
||||
addedFicheUids.push(ficheIndex);
|
||||
console.warn('sms', ficheIndex);
|
||||
|
||||
// On récupère les informations de la FICHE (si elle existe) */
|
||||
var ficheData = lsi.get('fiches', ficheIndex);
|
||||
|
@ -375,7 +373,6 @@ inputPhoneFiche.prototype.sync = function(){
|
|||
while( addedFicheUids.indexOf(ficheUid) > -1 && ficheUid < nbMaxFiche )
|
||||
ficheUid++;
|
||||
|
||||
console.warn('fill', ficheUid);
|
||||
// On enregistre le nouvel UID dans les uid crées
|
||||
addedFicheUids.push(ficheUid);
|
||||
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
<?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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -249,7 +249,7 @@
|
|||
return array( 'ModuleError' => ManagerError::ModuleError );
|
||||
|
||||
/* (7) On renomme le fichier avec le nouvel identifiant */
|
||||
if( !rename('/tmp/phone_storage_'.$subject['tmp_id'].'.json', '/tmp/phone_storage_'.$subject_id.'.json') )
|
||||
if( !rename('/tmp/phone_storage_'.$subject['tmp_id'].'.json', '/src/upload/phone_storage/'.$subject_id.'.json') )
|
||||
return array( 'ModuleError' => ManagerError::ModuleError ); // si erreur -> erreur
|
||||
|
||||
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
// On definit la racine __ROOT__ si c'est pas deja fait
|
||||
if( !defined('__ROOT__') ) define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||
|
||||
// On charge l'autoloader
|
||||
require_once __ROOT__.'/manager/autoloader.php';
|
||||
|
||||
use \manager\ResourceDispatcher;
|
||||
|
||||
|
||||
define('__HOST__')
|
||||
|
||||
|
||||
/* [1] Si on est en local, on charge les données locales
|
||||
=========================================================*/
|
||||
if( !checkdnsrr($_SERVER['SERVER_NAME'], 'NS') ){
|
||||
$config_file = ResourceDispatcher::getResource('f/json/server-local/confs');
|
||||
|
||||
if( !$config_file )
|
||||
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"logs": [
|
||||
{ "id":"1", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"2", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"3", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"4", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"5", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"6", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"7", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"8", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"9", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"10", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"11", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
|
||||
{ "id":"12", "date":"2014-02-28T15:00:10", "duration":"125", "direction":"1", "type":"1" },
|
||||
{ "id":"13", "date":"2014-02-15T23:06:46", "duration":"0", "direction":"0", "type":"1" },
|
||||
{ "id":"14", "date":"2014-02-15T23:06:18", "duration":"0", "direction":"0", "type":"1" },
|
||||
{ "id":"15", "date":"2014-02-15T21:08:34", "duration":"349", "direction":"1", "type":"1" },
|
||||
{ "id":"16", "date":"2014-02-15T20:51:38", "duration":"0", "direction":"1", "type":"1" },
|
||||
{ "id":"17", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
|
||||
{ "id":"18", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"2", "type":"1" },
|
||||
{ "id":"19", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
|
||||
{ "id":"20", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
|
||||
{ "id":"21", "date":"2014-02-15T17:24:18", "duration":"276", "direction":"1", "type":"1" },
|
||||
{ "id":"22", "date":"2014-02-15T16:34:29", "duration":"36", "direction":"1", "type":"1" }
|
||||
],
|
||||
|
||||
"contacts": [
|
||||
{ "id":"0", "number":"0102030405", "name":"", "sexe":"0", "age":"1", "studies":"1", "reltype":"1", "dist":"0" },
|
||||
{ "id":"1", "number":"0502030405", "name":"", "sexe":"0", "age":"1", "studies":"1", "reltype":"1", "dist":"0" },
|
||||
{ "id":"2", "number":"0502030561", "name":"", "sexe":"0", "age":"2", "studies":"2", "reltype":"2", "dist":"1" },
|
||||
{ "id":"3", "number":"0502030717", "name":"", "sexe":"0", "age":"3", "studies":"3", "reltype":"3", "dist":"2" },
|
||||
{ "id":"4", "number":"0502030873", "name":"", "sexe":"0", "age":"4", "studies":"4", "reltype":"4", "dist":"3" },
|
||||
{ "id":"5", "number":"0502031029", "name":"", "sexe":"0", "age":"5", "studies":"5", "reltype":"5", "dist":"4" },
|
||||
{ "id":"6", "number":"0502031185", "name":"", "sexe":"0", "age":"6", "studies":"6", "reltype":"6", "dist":"5" },
|
||||
{ "id":"7", "number":"0502031341", "name":"", "sexe":"0", "age":"7", "studies":"7", "reltype":"7", "dist":"6" },
|
||||
{ "id":"8", "number":"0502031497", "name":"", "sexe":"0", "age":"8", "studies":"8", "reltype":"8", "dist":"7" },
|
||||
{ "id":"9", "number":"0502031653", "name":"", "sexe":"0", "age":"9", "studies":"9", "reltype":"9", "dist":"8" },
|
||||
{ "id":"10", "number":"0502031809", "name":"", "sexe":"0", "age":"10", "studies":"10", "reltype":"10", "dist":"9" },
|
||||
{ "id":"11", "number":"0502031965", "name":"", "sexe":"0", "age":"11", "studies":"11", "reltype":"11", "dist":"10" },
|
||||
{ "id":"12", "number":"0502032121", "name":"", "sexe":"1", "age":"12", "studies":"12", "reltype":"12", "dist":"11" },
|
||||
{ "id":"13", "number":"0502032277", "name":"", "sexe":"1", "age":"13", "studies":"13", "reltype":"13", "dist":"12" },
|
||||
{ "id":"14", "number":"0502032433", "name":"", "sexe":"1", "age":"14", "studies":"14", "reltype":"14", "dist":"13" },
|
||||
{ "id":"15", "number":"0502032589", "name":"", "sexe":"1", "age":"15", "studies":"15", "reltype":"15", "dist":"14" },
|
||||
{ "id":"16", "number":"0502032745", "name":"", "sexe":"1", "age":"16", "studies":"16", "reltype":"16", "dist":"15" },
|
||||
{ "id":"17", "number":"0502032901", "name":"", "sexe":"1", "age":"17", "studies":"17", "reltype":"17", "dist":"16" },
|
||||
{ "id":"18", "number":"0502033057", "name":"", "sexe":"1", "age":"18", "studies":"18", "reltype":"18", "dist":"17" },
|
||||
{ "id":"19", "number":"0502033213", "name":"", "sexe":"1", "age":"19", "studies":"19", "reltype":"19", "dist":"18" },
|
||||
{ "id":"20", "number":"0502033369", "name":"", "sexe":"1", "age":"20", "studies":"20", "reltype":"20", "dist":"19" },
|
||||
{ "id":"21", "number":"0502033525", "name":"", "sexe":"1", "age":"21", "studies":"21", "reltype":"21", "dist":"20" },
|
||||
{ "id":"22", "number":"0502033681", "name":"", "sexe":"1", "age":"22", "studies":"22", "reltype":"22", "dist":"21" }
|
||||
|
||||
]
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue