Modification de `call_log/unserialize` et `input.js` pour coller avec le fichier de sortie + optimisation des données.

This commit is contained in:
xdrm-brackets 2016-05-12 16:11:07 +02:00
parent b31983fa4b
commit 8821997b6b
10 changed files with 12102 additions and 1044 deletions

View File

@ -83,6 +83,7 @@
//
// }
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 );
@ -170,5 +171,12 @@
header("Pragma: no-cache");
header("Expires: 0");
readfile($fname);
}
$req = new ModuleRequest('call_log/unserialize', array('phone_number'=>'05 05 05 05 05'));
$res = $req->dispatch();
var_dump( $res->get('sms') );
?>

View File

@ -10,5 +10,7 @@
"js" : "/js",
"highcharts": "/js/lib/highcharts",
"sigma": "/js/lib/sigma"
"sigma": "/js/lib/sigma",
"upload": "/src/upload"
}

View File

@ -3,7 +3,6 @@
"directories": [
"call_log",
"local_data",
"spss",
"pspp"
"phone_storage"
]
}

View File

@ -1,5 +1,5 @@
{
"call_log": [
"logs": [
{ "contact":"1", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"2", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"3", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
@ -25,6 +25,7 @@
],
"contacts": [
{ "contact":"0", "number":"0102030405", "name":"", "sexe":"0", "age":"1", "studies":"1", "reltype":"1", "dist":"0" },
{ "contact":"1", "number":"0502030405", "name":"", "sexe":"0", "age":"1", "studies":"1", "reltype":"1", "dist":"0" },
{ "contact":"2", "number":"0502030561", "name":"", "sexe":"0", "age":"2", "studies":"2", "reltype":"2", "dist":"1" },
{ "contact":"3", "number":"0502030717", "name":"", "sexe":"0", "age":"3", "studies":"3", "reltype":"3", "dist":"2" },

View File

@ -2,7 +2,7 @@
"call_log": {
"direction": { "0": "INCOMING", "1": "OUTCOMING", "2": "MISSED" },
"direction": { "0": "INCOMING", "1": "OUTGOING", "2": "MISSED" },
"type": { "0": "PHONE", "1": "SMS" }
},

View File

@ -25,6 +25,7 @@
// On formatte le numéro de téléphone
$phone_number = Database::formatNumber($phone_number);
/* [0] On récupère dans la config le chemin du fichier
=========================================================*/
/* (1) On récupère le fichier */
@ -45,7 +46,51 @@
$prefix = 'call_log'; $extension = 'xml';
$path = __ROOT__.$uploadAuth['root']."/$prefix/".$_SESSION['username'].".$extension";
/* [1] On parse/récupère le xml
/* [1] On récupère le dictionnaire des valeurs
=========================================================*/
/* (1) On récupère le fichier */
$dict = ResourceDispatcher::getResource('f/json/dictionary/upload/phone_storage');
/* (2) Si une erreur pour le fichier de conf */
if( $dict === false )
return ManagerError::UnreachableResource;
/* (3) On récupère la config sous forme de tableau */
$dict = json_decode( $dict, true );
/* (4) Si erreur de PARSAGE */
if( !is_array($dict) )
return ManagerError::ParsingFailed;
/* [2] Fonction pour mettre la clé associée dans la dictionnaire
=========================================================*/
function dParse($dict, $path, $value){
// {0} On met en forme la clé //
$path = explode(':', $path);
// {1} Si mauvaise taille, on quitte //
if( count($path) != 2 )
return $value;
// {2} Si l'entrée n'existe pas, on retourne la valeur //
if( !isset($dict[$path[0]][$path[1]]) )
return $value;
// {3} On charche parmi les valeurs possibles //
foreach($dict[$path[0]][$path[1]] as $k=>$v)
if( $v == $value ) // Si on trouve la valeur, on retourne la clé associée
return $k;
// {4} On retourne la valeur tel quel si on ne trouve pas //
return $value;
};
/* [3] On parse/récupère le xml
=========================================================*/
// Si le fichier n'existe pas, on quitte
if( !file_exists($path) )
@ -62,114 +107,118 @@
if( $xml === false )
return array('ModuleError' => ManagerError::ParsingFailed);
/* [2] On lit chaque élément
/* [4] On lit chaque élément
=========================================================*/
$phone_directory = array(); // Contiendra les correspondances num->Nom
$phone_logs = array(); // Contiendra nos logs (appels/sms)
$id = array(); // Contiendra les correspondances numéro->id
$phone_directory = array(); // Contiendra les données des contacts (par id)
$call_logs = array(); // Contiendra nos logs (appels/sms)
foreach($xml->Item as $log){
/* (1) On formatte le numéro */
$number = Database::formatNumber($log['Number']);
/* (2) On enregistre le contact dans l'annuaire s'il y est pas déjà */
if( !isset($phone_directory[$number]) )
$phone_directory[$number] = array(
'name' => strlen($log['Name']) ? (string) $log['Name'] : null,
'calls' => 0,
if( !isset($id[$number]) ){
$id[$number] = count($id);
$cur_id = $id[$number];
$phone_directory[$cur_id] = array(
'id' => $cur_id,
'number' => $number,
'name' => is_string($log['Name']) ? (string) $log['Name'] : '',
'call' => 0,
'sms' => 0
);
}
// On récupère l'id courant
$cur_id = $id[$number];
/* (3) Si c'est un appel, on incrémente le compteur pour ce numéro */
if( strtolower($log['Type']) == 'phone' ) $phone_directory[$number]['calls']++;
if( strtolower($log['Type']) == 'phone' ) $phone_directory[$cur_id]['call']++;
/* (4) Si c'est un sms, on incrémente le compteur pour ce numéro */
else $phone_directory[$number]['sms']++;
else $phone_directory[$cur_id]['sms']++;
/* (5) On complète le log */
$phone_log = array(
'source' => ($log['Direction']!='OUTGOING') ? $number : Database::formatNumber($phone_number),
'target' => ($log['Direction']!='OUTGOING') ? Database::formatNumber($phone_number) : $number,
'missed' => $log['Direction']==['MISSED'],
'type' => strtolower($log['Type']),
$call_log = array(
'id' => $cur_id,
'direction' => dParse($dict, 'logs:direction', $log['Direction']),
'type' => dParse($dict, 'logs:type', strtoupper($log['Type'])),
'date' => strtotime($log['Date']),
'duration' => (int) $log['Duration']
);
array_push($phone_logs, $phone_log);
array_push($call_logs, $call_log);
}
/* [5] On trie les contacts par nombre d'apparition d'APPEL
=========================================================*/
$tmp = $phone_directory; // Permet de ne pas efface $phone_directory
$maxNumber = -1; // Contiendra le numéro du plus gros
$maxId = -1; // Contiendra l'id du plus gros
$maxVal = null; // Contiendra la valeur max (total calls)
$call_sorted = array(); // Contiendra l'annuaire trié par nombre d'interraction
/* (1) Tant qu'on a pas tout trié */
while( count($tmp) > 0 ){
$maxNumber = -1;
$maxId = -1;
$maxVal = null;
/* (2) On parcours toutes les entrées puor trouver le plus proche */
foreach($tmp as $number=>$data)
if( $data['calls'] > $maxVal || is_null($maxVal) ){
foreach($tmp as $cur_id=>$data)
if( $data['call'] > $maxVal || is_null($maxVal) ){
// On met à jour la valeur max
$maxVal = $data['calls'];
$maxVal = $data['call'];
// On met à jour l'indice
$maxNumber = $number;
$maxId = $cur_id;
}
/* (3) On supprime le plus proche qu'on a trouvé et on l'ajoute au tableau trié */
array_push($call_sorted, array(
'number' => $maxNumber,
'name' => $tmp[$maxNumber]['name'],
'count' => $tmp[$maxNumber]['calls']
));
array_push($call_sorted, $maxId);
unset($tmp[$maxNumber]);
unset($tmp[$maxId]);
}
/* [6] On trie les contacts par nombre d'apparition de SMS/MMS
=========================================================*/
$tmp = $phone_directory; // Permet de ne pas efface $phone_directory
$maxNumber = -1; // Contiendra le numéro du plus gros
$maxId = -1; // Contiendra le numéro du plus gros
$maxVal = null; // Contiendra la valeur max (total calls)
$sms_sorted = array(); // Contiendra l'annuaire trié par nombre d'interraction
/* (1) Tant qu'on a pas tout trié */
while( count($tmp) > 0 ){
$maxNumber = -1;
$maxId = -1;
$maxVal = null;
/* (2) On parcours toutes les entrées puor trouver le plus proche */
foreach($tmp as $number=>$data)
foreach($tmp as $cur_id=>$data)
if( $data['sms'] > $maxVal || is_null($maxVal) ){
// On met à jour la valeur max
$maxVal = $data['sms'];
// On met à jour l'indice
$maxNumber = $number;
$maxId = $cur_id;
}
/* (3) On supprime le plus proche qu'on a trouvé et on l'ajoute au tableau trié */
array_push($sms_sorted, array(
'number' => $maxNumber,
'name' => $tmp[$maxNumber]['name'],
'count' => $tmp[$maxNumber]['sms']
));
array_push($sms_sorted, $maxId );
unset($tmp[$maxNumber]);
unset($tmp[$maxId]);
}
/* [6] Gestion du retour
/* [7] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'directory' => $phone_directory,
'calls' => $call_sorted,
'call' => $call_sorted,
'sms' => $sms_sorted,
'logs' => $phone_logs
'logs' => $call_logs
);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
{
"logs": {
"direction": { "0": "INCOMING", "1": "OUTGOING", "2": "MISSED" },
"type": { "0": "PHONE", "1": "SMS" }
},
"contacts": {
"sexe": { "0":"Homme", "1":"Femme" },
"age": {
"0": "5 à 10", "1": "10 à 15", "2": "15 à 20", "3": "20 à 25", "4": "25 à 30",
"5": "30 à 35", "6": "35 à 40", "7": "40 à 45", "8": "45 à 50", "9": "50 à 55",
"10": "55 à 60", "11": "60 à 65", "12": "65 à 70", "13": "70 à 75", "14": "75 à 80",
"15": "80 à 85", "16": "85 à 90", "17": "90 à 95", "18": "95 à 100"
},
"studies": {
".": "Non défini",
"0": "Inconnu",
"1": "< BAC",
"2": "BAC",
"3": "BAC+2",
"4": "BAC+3",
"5": "BAC+4 et plus"
},
"reltype": {
"0": "Père, mère ou équivalent",
"1": "Frère ou soeur",
"2": "Autre membre de la famille",
"3": "Relation amoureuse",
"4": "Collègue",
"5": "Voisin",
"6": "Ami",
"7": "Ami proche",
"8": "Relation de service (médecin, ...)",
"9": "Inconnu"
},
"dist": {
"0": "- de 5 minutes",
"1": "de 5 à 15 minutes",
"2": "de 15 à 60 minutes",
"3": "+ d'une heure"
}
}
}

25
view/js/input-min.js vendored
View File

@ -1,16 +1,15 @@
var subjectManager,contactManager,miniManager,ficheManager,matriceManager;
function dynamicUpdate(b){var a=b instanceof Element,e=a&&"SPAN"==b.tagName&&"switch-left"==b.className,f=a&&"SPAN"==b.tagName&&"switch-both"==b.className,g=a&&"INPUT"==b.tagName&&"submit"==b.type,c=a&&"SPAN"==b.tagName&&("nav-mini"==b.parentNode.id||"nav-fiche"==b.parentNode.id),a=a&&"SPAN"==b.tagName&&"nav-contact"==b.parentNode.id;if(!(f||e||g||c||a)&&!0!==b)return!1;if(f)console.log("> switch firstname <-> lastname"),e=b.parentNode,b=e.children[8],e=e.children[10],f=b.value,b.value=e.value,e.value=
f;else if(e){console.log("> switch firstname+lastname -> username");e=b.parentNode;f=e.children[6];b=e.children[8];e=e.children[10];if(0<f.value.length||0==b.value.length&&0==e.value.length)return!1;f.value=b.value+" "+e.value;b.value="";e.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),ficheManager.sync(),miniManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),
matriceManager.storageToFields(),(g||a)&&contactManager.storageToFields()}function readableName(b,a,e){var f=a.length,g=e.length;return 0<b.length?0<f+g?b+" ("+(a+" "+e).trim()+")":b:0<f+g?(a+" "+e).trim():"Inconnu"}
function dynamicUpdate(a){var b=a instanceof Element,f=b&&"SPAN"==a.tagName&&"switch-left"==a.className,e=b&&"SPAN"==a.tagName&&"switch-both"==a.className,c=b&&"INPUT"==a.tagName&&"submit"==a.type,d=b&&"SPAN"==a.tagName&&("nav-mini"==a.parentNode.id||"nav-fiche"==a.parentNode.id),b=b&&"SPAN"==a.tagName&&"nav-contact"==a.parentNode.id;if(!(e||f||c||d||b)&&!0!==a)return!1;if(e)console.log("> switch firstname <-> lastname"),f=a.parentNode,a=f.children[8],f=f.children[10],e=a.value,a.value=f.value,f.value=
e;else if(f){console.log("> switch firstname+lastname -> username");f=a.parentNode;e=f.children[6];a=f.children[8];f=f.children[10];if(0<e.value.length||0==a.value.length&&0==f.value.length)return!1;e.value=a.value+" "+f.value;a.value="";f.value=""}else console.log("> dynamic update"),miniManager.fieldsToStorage(),ficheManager.fieldsToStorage(),contactManager.fieldsToStorage(),matriceManager.fieldsToStorage(),ficheManager.sync(),miniManager.sync(),miniManager.storageToFields(),ficheManager.storageToFields(),
matriceManager.storageToFields(),(c||b)&&contactManager.storageToFields()}function readableName(a,b,f){var e=b.length,c=f.length;return 0<a.length?0<e+c?a+" ("+(b+" "+f).trim()+")":a:0<e+c?(b+" "+f).trim():"Inconnu"}lsi.createDataset("logs");
include("/js/includes/input-phone-subject.js",function(){include("/js/includes/input-phone-contact.js",function(){include("/js/includes/input-phone-mini.js",function(){include("/js/includes/input-phone-fiche.js",function(){include("/js/includes/input-phone-matrice.js",function(){subjectManager=new inputPhoneSubject($('article.subject-panel [data-name="number"]'),$('article.subject-panel [data-name="username"]'),$('article.subject-panel [data-name="firstname"]'),$('article.subject-panel [data-name="lastname"]'),
$('article.subject-panel [data-name="submit"]'));subjectManager.attach();contactManager=new inputPhoneContact($("article.contact-panel"),$("#nav-contact"));contactManager.attach(dynamicUpdate);miniManager=new inputPhoneMini($("article.mini-relation-panel"),$("#nav-mini"));miniManager.attach(dynamicUpdate);ficheManager=new inputPhoneFiche($("article.relation-panel"),$("#nav-fiche"));ficheManager.attach(dynamicUpdate);matriceManager=new inputPhoneMatrice($("article.matrice-panel"));matriceManager.attach(dynamicUpdate);
$('input#call_log-import[type="file"]').addEventListener("click",function(b){b.target.value=null},!1);$('input#call_log-import[type="file"]').addEventListener("change",function(b){b={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:b.target.files[0]};api.send(b,function(a){console.log(a);var b=null;if(0!=a.ModuleError)9==a.ModuleError?Notification.error("Erreur","Il est n\u00e9cessaire de saisir les informations du <b>sujet</b> avant d'exporter son journal d'appel"):Notification.error("Erreur",
a.ModuleError);else{for(var b=Notification.info("Info","Chargement du journal d'appel"),f=0,g=[],c=0;c<a.calls.length&&10>c;c++)g.push(a.calls[c].number);for(c=0;c<g.length;c++){var d=[""];null!=a.directory[g[c]].name&&(d=a.directory[g[c]].name.split(" "));lsi.set("contacts",f,{uid:f,number:g[c],username:0<d.length?d[0]:"",firstname:0<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[g[c]].sms,countcall:a.directory[g[c]].calls,call:c,sms:-1});f++}for(var h=[],c=0;c<
a.sms.length&&10>c;c++)h.push(a.sms[c].number);for(c=0;c<h.length;c++)if(d=g.indexOf(h[c]),-1<d){var l=lsi.get("contacts",d);l.sms=c;lsi.set("contacts",d,l)}else d=[""],null!=a.directory[h[c]].name&&(d=a.directory[h[c]].name.split(" ")),lsi.set("contacts",f,{uid:f,number:h[c],username:0<d.length?d[0]:"",firstname:0<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[h[c]].sms,countcall:a.directory[h[c]].calls,call:-1,sms:c}),f++;for(var k in a.directory)-1<g.indexOf(k)||
-1<h.indexOf(k)||(d=(null===a.directory[k].name?"":a.directory[k].name).split(" "),lsi.set("contacts",f,{uid:f,number:k,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:a.directory[k].sms,countcall:a.directory[k].calls,call:-1,sms:-1}),f++);contactManager.storageToFields();dynamicUpdate(!0);null!=b&&b.click();Notification.success("OK","Chargement termin\u00e9")}})},!1);$("#clear-all").addEventListener("click",function(b){lsi.clear("subject");
lsi.clear("contacts");lsi.clear("mini-fiches");lsi.clear("fiches");lsi.clear("matrice");subjectManager.storageToFields();contactManager.storageToFields();miniManager.storageToFields();ficheManager.storageToFields();matriceManager.storageToFields();Notification.success("OK","Les donn\u00e9es ont \u00e9t\u00e9 supprim\u00e9es")},!1);$("#export-all").addEventListener("click",function(b){Notification.info("INFORMATION","Lancement du t\u00e9l\u00e9chargement de la sauvegarde");b={subject:lsi["export"]("subject")[0],
contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};var a=$("#download-target");a.download="local-data.json";a.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(b));a.click()},!1);$("#import-all").addEventListener("click",function(b){$("#local-upload").click()},!1);$("#local-upload").addEventListener("click",function(b){b.target.value=null},!1);$("#local-upload").addEventListener("change",function(b){b=
{path:"upload/local_data",file:$("#local-upload").files[0]};api.send(b,function(a){console.log(a);if(0!=a.ModuleError)return Notification.error("Erreur",a.ModuleError),!1;lsi.set("subject",0,a.local_data.subject);lsi["import"]("contacts",a.local_data.contacts);lsi["import"]("mini-fiches",a.local_data.mini);lsi["import"]("fiches",a.local_data.fiches);lsi.set("matrice",0,a.local_data.matrice);subjectManager.storageToFields();contactManager.storageToFields();matriceManager.storageToFields();dynamicUpdate(!0)})},
!1);$("#submit-all").addEventListener("click",function(b){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();if(!subjectManager.check())return Notification.warning("Attention","Vous devez saisir les informations du <i>sujet</i>"),!1;b=lsi["export"]("mini-fiches");for(var a in b)if(!b[a].valid)return Notification.warning("Attention","La <i>fiche rapide</i> <b>"+(parseInt(a)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),
!1;b=lsi["export"]("fiches");for(a in b)if(!b[a].valid)return Notification.warning("Attention","La <i>fiche compl\u00e8te</i> <b>"+(parseInt(a)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),!1;a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};api.send(a,function(a){if(0!=a.ModuleError)return Notification.error("ERREUR",a.ModuleError),!1;console.log(a)},
!1)},!1)})})})})});
$('input#call_log-import[type="file"]').addEventListener("click",function(a){a.target.value=null},!1);$('input#call_log-import[type="file"]').addEventListener("change",function(a){a={path:"upload/call_log",phone_number:$("#subject_phone_number").value,file:a.target.files[0]};api.send(a,function(b){console.log(b);var a=null;if(0!=b.ModuleError)9==b.ModuleError?Notification.error("Erreur","Il est n\u00e9cessaire de saisir les informations du <b>sujet</b> avant d'exporter son journal d'appel"):Notification.error("Erreur",
b.ModuleError);else{for(var a=Notification.info("Info","Chargement du journal d'appel"),e=0;e<b.call.length;e++){var c=b.directory[b.call[e]],d=c.name.split(" ");lsi.set("contacts",c.id,{uid:c.id,number:c.number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:c.sms,countcall:c.calls,call:e,sms:-1})}for(e=0;e<b.sms.length;e++)c=b.directory[b.sms[e]],-1<b.call.indexOf(b.sms[e])?(d=lsi.get("contacts",c.id),d.sms=e,lsi.set("contacts",c.id,
d)):(d=c.name.split(" "),lsi.set("contacts",c.id,{uid:c.id,number:c.number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:c.sms,countcall:c.calls,call:-1,sms:e}),uid++);for(var g in b.directory)-1<b.call.indexOf(g)||-1<b.sms.indexOf(g)||(c=b.directory[g],d=c.name.split(" "),lsi.set("contacts",c.id,{uid:c.id,number:c.number,username:1==d.length?d[0]:"",firstname:1<d.length?d[0]:"",lastname:1<d.length?d.splice(1).join(" "):"",countsms:c.sms,
countcall:c.calls,call:-1,sms:-1}));lsi["import"]("logs",b.logs);contactManager.storageToFields();dynamicUpdate(!0);null!=a&&a.click();Notification.success("OK","Chargement termin\u00e9")}})},!1);$("#clear-all").addEventListener("click",function(a){lsi.clear("subject");lsi.clear("logs");lsi.clear("contacts");lsi.clear("mini-fiches");lsi.clear("fiches");lsi.clear("matrice");subjectManager.storageToFields();contactManager.storageToFields();miniManager.storageToFields();ficheManager.storageToFields();
matriceManager.storageToFields();Notification.success("OK","Les donn\u00e9es ont \u00e9t\u00e9 supprim\u00e9es")},!1);$("#export-all").addEventListener("click",function(a){Notification.info("INFORMATION","Lancement du t\u00e9l\u00e9chargement de la sauvegarde");a={subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0],logs:lsi["export"]("logs")};var b=$("#download-target");b.download=
"local-data.json";b.href="data:application/octet-stream,"+encodeURIComponent(JSON.stringify(a));b.click()},!1);$("#import-all").addEventListener("click",function(a){$("#local-upload").click()},!1);$("#local-upload").addEventListener("click",function(a){a.target.value=null},!1);$("#local-upload").addEventListener("change",function(a){a={path:"upload/local_data",file:$("#local-upload").files[0]};api.send(a,function(a){console.log(a);if(0!=a.ModuleError)return Notification.error("Erreur",a.ModuleError),
!1;lsi.set("subject",0,a.local_data.subject);lsi["import"]("contacts",a.local_data.contacts);lsi["import"]("logs",a.local_data.logs);lsi["import"]("mini-fiches",a.local_data.mini);lsi["import"]("fiches",a.local_data.fiches);lsi.set("matrice",0,a.local_data.matrice);subjectManager.storageToFields();contactManager.storageToFields();matriceManager.storageToFields();dynamicUpdate(!0)})},!1);$("#submit-all").addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();
contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();if(!subjectManager.check())return Notification.warning("Attention","Vous devez saisir les informations du <i>sujet</i>"),!1;a=lsi["export"]("mini-fiches");for(var b in a)if(!a[b].valid)return Notification.warning("Attention","La <i>fiche rapide</i> <b>"+(parseInt(b)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),!1;a=lsi["export"]("fiches");for(b in a)if(!a[b].valid)return Notification.warning("Attention",
"La <i>fiche compl\u00e8te</i> <b>"+(parseInt(b)+1)+"</b> est incompl\u00e8te et/ou incorrecte"),!1;b={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiches:lsi["export"]("fiches"),matrice:lsi["export"]("matrice")[0]};api.send(b,function(a){if(0!=a.ModuleError)return Notification.error("ERREUR",a.ModuleError),!1;console.log(a)},!1)},!1)})})})})});

View File

@ -161,6 +161,7 @@ function readableName(u, f, l){
/* [2] Inclusion des scripts externes et lancement
=========================================================*/
lsi.createDataset('logs');
// TODO: Mettre les versions minifiées
include('/js/includes/input-phone-subject.js', function(){
include('/js/includes/input-phone-contact.js', function(){
@ -277,65 +278,55 @@ include('/js/includes/input-phone-matrice.js', function(){
loadingNotif = Notification.info('Info', 'Chargement du journal d\'appel');
var uid = 0; // Contiendra l'uid des contacts
/* (3) On récupère les contacts les plus APPELLÉS */
var most_called = [];
for( var i = 0 ; i < response.calls.length && i < 10 ; i++ )
most_called.push( response.calls[i].number );
/* (3) On crée les 10 contacts les plus APPELÉS */
for( var i = 0 ; i < response.call.length ; i++ ){
/* (4) On crée les 10 contacts les plus APPELÉS */
for( var i = 0 ; i < most_called.length ; i++ ){
// Données du cnotact
var conData = response.directory[ response.call[i] ];
var splittedName = [''];
if( response.directory[most_called[i]].name != null )
splittedName = response.directory[most_called[i]].name.split(' ');
var splittedName = conData.name.split(' ');
lsi.set('contacts', uid, {
uid: uid,
number: most_called[i],
username: splittedName.length > 0 ? splittedName[0] : '', // Si un seul mot -> pseudo
firstname: splittedName.length > 0 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
lsi.set('contacts', conData.id, {
uid: conData.id,
number: conData.number,
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
countsms: response.directory[most_called[i]].sms, // Nombre de sms
countcall: response.directory[most_called[i]].calls, // Nombre d'appels
countsms: conData.sms, // Nombre de sms
countcall: conData.calls, // Nombre d'appels
call: i, // classement dans le top 10 des APPELS
sms: -1 // classement dans le top 10 des SMS
});
uid++;
}
/* (5) On crée les 10 contacts les plus SMSÉS */
for( var i = 0 ; i < response.sms.length ; i++ ){
/* (5) On récupère les contacts les plus SMSÉS */
var most_sms = [];
for( var i = 0 ; i < response.sms.length && i < 10 ; i++ )
most_sms.push( response.sms[i].number );
// Données du cnotact
var conData = response.directory[response.sms[i]];
/* (6) On crée les 10 contacts les plus SMSÉS */
for( var i = 0 ; i < most_sms.length ; i++ ){
// Si le contact est déja dans le top 10 des appels, on lui ajoute juste le classement dans le top 10 des SMS
var callIndex = most_called.indexOf(most_sms[i]);
var callIndex = response.call.indexOf(response.sms[i]);
if( callIndex > -1 ){
var created = lsi.get('contacts', callIndex);
var created = lsi.get('contacts', conData.id);
created.sms = i;
lsi.set('contacts', callIndex, created);
lsi.set('contacts', conData.id, created);
continue;
}
var splittedName = [''];
if( response.directory[most_sms[i]].name != null )
splittedName = response.directory[most_sms[i]].name.split(' ');
var splittedName = conData.name.split(' ');
lsi.set('contacts', uid, {
uid: uid,
number: most_sms[i],
username: splittedName.length > 0 ? splittedName[0] : '', // Si un seul mot -> pseudo
firstname: splittedName.length > 0 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
lsi.set('contacts', conData.id, {
uid: conData.id,
number: conData.number,
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
countsms: response.directory[most_sms[i]].sms, // Nombre de sms
countcall: response.directory[most_sms[i]].calls, // Nombre d'appels
countsms: conData.sms, // Nombre de sms
countcall: conData.calls, // Nombre d'appels
call: -1, // classement dans le top 10 des APPELS
sms: i // classement dans le top 10 des SMS
});
@ -345,37 +336,39 @@ include('/js/includes/input-phone-matrice.js', function(){
/* (7) Pour chaque contact qui n'est pas dans le top 10, on l'ajoute */
for( var number in response.directory ){
for( var id in response.directory ){
// Si dans top 10 des APPELS, on ne l'ajoute pas
if( most_called.indexOf(number) > -1 )
if( response.call.indexOf(id) > -1 )
continue;
// Si dans top 10 des SMS, on ne l'ajoute pas
if( most_sms.indexOf(number) > -1 )
if( response.sms.indexOf(id) > -1 )
continue;
// On récupère les données du contact
var conData = response.directory[id];
// On découpe le nom par espaces
var name = response.directory[number].name===null ? '' : response.directory[number].name;
var splittedName = name.split(' ');
var splittedName = conData.name.split(' ');
lsi.set('contacts', uid, {
uid: uid,
number: number,
lsi.set('contacts', conData.id, {
uid: conData.id,
number: conData.number,
username: splittedName.length == 1 ? splittedName[0] : '', // Si un seul mot -> pseudo
firstname: splittedName.length > 1 ? splittedName[0] : '', // Si plusieurs mots -> le 1er est le prénom
lastname: splittedName.length > 1 ? splittedName.splice(1).join(' ') : '', // et les autres sont le nom
countsms: response.directory[number].sms, // Nombre de sms
countcall: response.directory[number].calls, // Nombre d'appels
countsms: conData.sms, // Nombre de sms
countcall: conData.calls, // Nombre d'appels
call: -1,
sms: -1
});
uid++;
}
/* (8) On enregistre les logs (appels/sms) */
lsi.import('logs', response.logs);
/* (8) On met à jour l'affichage */
contactManager.storageToFields();
dynamicUpdate(true);
@ -399,6 +392,7 @@ include('/js/includes/input-phone-matrice.js', function(){
$('#clear-all').addEventListener('click', function(e){
/* (1) On vide tous les dataset de données */
lsi.clear('subject');
lsi.clear('logs');
lsi.clear('contacts');
lsi.clear('mini-fiches');
lsi.clear('fiches');
@ -429,7 +423,8 @@ include('/js/includes/input-phone-matrice.js', function(){
contacts: lsi.export('contacts'),
mini: lsi.export('mini-fiches'),
fiches: lsi.export('fiches'),
matrice: lsi.export('matrice')[0]
matrice: lsi.export('matrice')[0],
logs: lsi.export('logs')
};
@ -478,6 +473,7 @@ include('/js/includes/input-phone-matrice.js', function(){
/* (3) On enregistre les données dans le 'localStorage' */
lsi.set('subject', 0, response.local_data.subject);
lsi.import('contacts', response.local_data.contacts);
lsi.import('logs', response.local_data.logs);
lsi.import('mini-fiches', response.local_data.mini);
lsi.import('fiches', response.local_data.fiches);
lsi.set('matrice', 0, response.local_data.matrice);