Export excel en passant par .csv (dans automate.php)

This commit is contained in:
xdrm-brackets 2016-05-12 13:04:09 +02:00
parent ad1d781ab0
commit c1eb819c6f
5 changed files with 136 additions and 49 deletions

View File

@ -69,12 +69,10 @@
/* [3] Test de la vérification du format de fichier pour l'upload
=========================================================*/
?>
<!-- <form action='' method='POST' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='submit' value='Upload'>
</form> -->
<?php
// <!-- <form action='' method='POST' enctype='multipart/form-data'>
// <input type='file' name='file'>
// <input type='submit' value='Upload'>
// </form>
// var_dump($_FILES);
//
// if( isset($_FILES) ){
@ -85,5 +83,92 @@
//
// }
$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);
?>

View File

@ -1,27 +1,27 @@
{
"call_log": [
{ "contact":"1", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"2", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"3", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"4", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"5", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"6", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"7", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"8", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"9", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"10", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"11", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"INCOMING", "type":"SMS" },
{ "contact":"12", "date":"2014-02-28T15:00:10", "duration":"125", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"13", "date":"2014-02-15T23:06:46", "duration":"0", "direction":"INGOING", "type":"PHONE" },
{ "contact":"14", "date":"2014-02-15T23:06:18", "duration":"0", "direction":"INGOING", "type":"PHONE" },
{ "contact":"15", "date":"2014-02-15T21:08:34", "duration":"349", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"16", "date":"2014-02-15T20:51:38", "duration":"0", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"17", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"18", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"MISSED", "type":"PHONE" },
{ "contact":"19", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"20", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"21", "date":"2014-02-15T17:24:18", "duration":"276", "direction":"OUTGOING", "type":"PHONE" },
{ "contact":"22", "date":"2014-02-15T16:34:29", "duration":"36", "direction":"OUTGOING", "type":"PHONE" }
{ "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" },
{ "contact":"4", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"5", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"6", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"7", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"8", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"9", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"10", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"11", "date":"2014-05-28T14:43:25", "duration":"0", "direction":"0", "type":"0" },
{ "contact":"12", "date":"2014-02-28T15:00:10", "duration":"125", "direction":"1", "type":"1" },
{ "contact":"13", "date":"2014-02-15T23:06:46", "duration":"0", "direction":"0", "type":"1" },
{ "contact":"14", "date":"2014-02-15T23:06:18", "duration":"0", "direction":"0", "type":"1" },
{ "contact":"15", "date":"2014-02-15T21:08:34", "duration":"349", "direction":"1", "type":"1" },
{ "contact":"16", "date":"2014-02-15T20:51:38", "duration":"0", "direction":"1", "type":"1" },
{ "contact":"17", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
{ "contact":"18", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"2", "type":"1" },
{ "contact":"19", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
{ "contact":"20", "date":"2014-02-15T19:06:33", "duration":"657", "direction":"1", "type":"1" },
{ "contact":"21", "date":"2014-02-15T17:24:18", "duration":"276", "direction":"1", "type":"1" },
{ "contact":"22", "date":"2014-02-15T16:34:29", "duration":"36", "direction":"1", "type":"1" }
],
"contacts": [
@ -36,17 +36,17 @@
{ "contact":"9", "number":"0502031653", "name":"", "sexe":"0", "age":"9", "studies":"9", "reltype":"9", "dist":"8" },
{ "contact":"10", "number":"0502031809", "name":"", "sexe":"0", "age":"10", "studies":"10", "reltype":"10", "dist":"9" },
{ "contact":"11", "number":"0502031965", "name":"", "sexe":"0", "age":"11", "studies":"11", "reltype":"11", "dist":"10" },
{ "contact":"12", "number":"0502032121", "name":"", "sexe":"0", "age":"12", "studies":"12", "reltype":"12", "dist":"11" },
{ "contact":"13", "number":"0502032277", "name":"", "sexe":"0", "age":"13", "studies":"13", "reltype":"13", "dist":"12" },
{ "contact":"14", "number":"0502032433", "name":"", "sexe":"0", "age":"14", "studies":"14", "reltype":"14", "dist":"13" },
{ "contact":"15", "number":"0502032589", "name":"", "sexe":"0", "age":"15", "studies":"15", "reltype":"15", "dist":"14" },
{ "contact":"16", "number":"0502032745", "name":"", "sexe":"0", "age":"16", "studies":"16", "reltype":"16", "dist":"15" },
{ "contact":"17", "number":"0502032901", "name":"", "sexe":"0", "age":"17", "studies":"17", "reltype":"17", "dist":"16" },
{ "contact":"18", "number":"0502033057", "name":"", "sexe":"0", "age":"18", "studies":"18", "reltype":"18", "dist":"17" },
{ "contact":"19", "number":"0502033213", "name":"", "sexe":"0", "age":"19", "studies":"19", "reltype":"19", "dist":"18" },
{ "contact":"20", "number":"0502033369", "name":"", "sexe":"0", "age":"20", "studies":"20", "reltype":"20", "dist":"19" },
{ "contact":"21", "number":"0502033525", "name":"", "sexe":"0", "age":"21", "studies":"21", "reltype":"21", "dist":"20" },
{ "contact":"22", "number":"0502033681", "name":"", "sexe":"0", "age":"22", "studies":"22", "reltype":"22", "dist":"21" }
{ "contact":"12", "number":"0502032121", "name":"", "sexe":"1", "age":"12", "studies":"12", "reltype":"12", "dist":"11" },
{ "contact":"13", "number":"0502032277", "name":"", "sexe":"1", "age":"13", "studies":"13", "reltype":"13", "dist":"12" },
{ "contact":"14", "number":"0502032433", "name":"", "sexe":"1", "age":"14", "studies":"14", "reltype":"14", "dist":"13" },
{ "contact":"15", "number":"0502032589", "name":"", "sexe":"1", "age":"15", "studies":"15", "reltype":"15", "dist":"14" },
{ "contact":"16", "number":"0502032745", "name":"", "sexe":"1", "age":"16", "studies":"16", "reltype":"16", "dist":"15" },
{ "contact":"17", "number":"0502032901", "name":"", "sexe":"1", "age":"17", "studies":"17", "reltype":"17", "dist":"16" },
{ "contact":"18", "number":"0502033057", "name":"", "sexe":"1", "age":"18", "studies":"18", "reltype":"18", "dist":"17" },
{ "contact":"19", "number":"0502033213", "name":"", "sexe":"1", "age":"19", "studies":"19", "reltype":"19", "dist":"18" },
{ "contact":"20", "number":"0502033369", "name":"", "sexe":"1", "age":"20", "studies":"20", "reltype":"20", "dist":"19" },
{ "contact":"21", "number":"0502033525", "name":"", "sexe":"1", "age":"21", "studies":"21", "reltype":"21", "dist":"20" },
{ "contact":"22", "number":"0502033681", "name":"", "sexe":"1", "age":"22", "studies":"22", "reltype":"22", "dist":"21" }
]

View File

@ -18,7 +18,9 @@
"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"
},
@ -37,7 +39,7 @@
"dist": {
"0": "- de 5 minutes",
"1": "de 5 à 15 minutes",
"1": "de 5 à 15 minutes",
"2": "de 15 à 60 minutes",
"3": "+ d'une heure"
}

File diff suppressed because one or more lines are too long

View File

@ -243,40 +243,40 @@ ficheBuilder.setLayout(
"\t\t<span class='select-container'><select data-name='job'>\n"+
"\t\t\t<option value='.' disabled selected>Dernière profession exercée:</option>\n"+
"\t\t\t<option value='0'>Inconnue</option>\n"+
"\t\t\t<option value='1-' disabled>Agriculateur exploitants</option>\n"+
"\t\t\t<option value='.' disabled>Agriculateur exploitants</option>\n"+
"\t\t\t\t<option value='10'>Agriculteurs exploitants (Agriculteurs, maraîchers, viticulteurs…)</option>\n"+
"\t\t\t<option value='2-' disabled>Artisans, commerçants et chefs d'entreprises</option>\n"+
"\t\t\t<option value='.' disabled>Artisans, commerçants et chefs d'entreprises</option>\n"+
"\t\t\t\t<option value='21'>Artisans (Maçons, électriciens, couturiers, boulangers, garagistes, coiffeurs…)</option>\n"+
"\t\t\t\t<option value='22'>Commerçants et assimilés (Commerçants en détail ou en gros, buralistes, cafetiers, agents immobiliers…)</option>\n"+
"\t\t\t\t<option value='23'>Chefs d'entreprise de 10 salariés ou plus</option>\n"+
"\t\t\t<option value='3-' disabled>Cadres et professions intellectuelles supérieures</option>\n"+
"\t\t\t<option value='.' disabled>Cadres et professions intellectuelles supérieures</option>\n"+
"\t\t\t\t<option value='31'>Professions libérales et assimilés (Médecins, avocats, notaires, architectes libéraux…)</option>\n"+
"\t\t\t\t<option value='32'>Cadres de la fonction publique, professions intellectuelles et artistiques (Personnels administratifs</option>\n"+
"\t\t\t\t\t<option class='pad' value='32'>de catégorie A, professeurs de lenseignement secondaire ou supérieur, médecins hospitaliers, artistes…)</option>\n"+
"\t\t\t\t<option value='36'>Cadres d'entreprise (Cadres administratifs, cadres commerciaux, ingénieurs…)</option>\n"+
"\t\t\t<option value='4-' disabled>Professions Intermédiaires</option>\n"+
"\t\t\t<option value='.' disabled>Professions Intermédiaires</option>\n"+
"\t\t\t\t<option value='41'>Professions intermédiaires de l'enseignement, de la santé, de la fonction publique et assimilés </option>\n"+
"\t\t\t\t\t<option class='pad' value='41'>(Personnels administratifs de catégorie B, instituteurs, infirmiers, travailleurs sociaux…)</option>\n"+
"\t\t\t\t<option value='46'>Professions intermédiaires administratives et commerciales des entreprises (Comptables, chargés de clientèles…)</option>\n"+
"\t\t\t\t<option value='47'>Techniciens (Techniciens détudes, techniciens de contrôle, dessinateurs en bâtiment, géomètres…)</option>\n"+
"\t\t\t\t<option value='48'>Contremaîtres, agents de maîtrise (Conducteurs de travaux, chefs déquipe…)</option>\n"+
"\t\t\t<option value='5-' disabled>Employés</option>\n"+
"\t\t\t<option value='.' disabled>Employés</option>\n"+
"\t\t\t\t<option value='51'>Employés de la fonction publique (Personnels de catégorie C, agents administratifs, agents de service…)</option>\n"+
"\t\t\t\t<option value='54'>Employés administratifs d'entreprise (Secrétaires, agents daccueil…)</option>\n"+
"\t\t\t\t<option value='55'>Employés de commerce (Vendeurs, caissiers…)</option>\n"+
"\t\t\t\t<option value='56'>Personnels des services directs aux particuliers (Serveurs, coiffeurs, assistantes maternelles…)</option>\n"+
"\t\t\t<option value='6-' disabled>Ouvriers</option>\n"+
"\t\t\t<option value='.' disabled>Ouvriers</option>\n"+
"\t\t\t\t<option value='61'>Ouvriers qualifiés de type industriel ou artisanal (Mécaniciens, chauffeurs, cuisiniers…)</option>\n"+
"\t\t\t\t<option value='66'>Ouvriers non qualifiés de type industriel ou artisanal (Ouvrier de production, manœuvres…)</option>\n"+
"\t\t\t\t<option value='69'>Ouvriers agricoles (Bergers, ouvriers de la viticulture, bûcherons, ouvrier forestiers…)</option>\n"+
"\t\t\t<option value='7-' disabled>Retraités</option>\n"+
"\t\t\t<option value='.' disabled>Retraités</option>\n"+
"\t\t\t\t<option value='71'>Anciens agriculteurs exploitants</option>\n"+
"\t\t\t\t<option value='72'>Anciens artisans, commerçants, chefs d'entreprise</option>\n"+
"\t\t\t\t<option value='73'>Anciens cadres</option>\n"+
"\t\t\t\t<option value='74'>Anciennes professions intermédiaires</option>\n"+
"\t\t\t\t<option value='75'>Anciens employés</option>\n"+
"\t\t\t\t<option value='76'>Anciens ouvriers</option>\n"+
"\t\t\t<option value='8-' disabled>Sans activité professionnelle</option>\n"+
"\t\t\t<option value='.' disabled>Sans activité professionnelle</option>\n"+
"\t\t\t\t<option value='81'>Chômeurs n'ayant jamais travaillé</option>\n"+
"\t\t\t\t<option value='82'>Inactifs divers (autres que retraités)</option>\n"+
"\t\t</select></span>\n"+