Merging dev
This commit is contained in:
commit
536fe47d91
|
@ -262,6 +262,15 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
"iexplorer_convert": {
|
||||||
|
"description": "Convertisseur .txt (iExplorer) vers .xml (Call Log)",
|
||||||
|
"permissions": ["admin"],
|
||||||
|
"parameters": {
|
||||||
|
"file": { "description": "Fichier exporté de iExplorer", "type": "FILE" }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
"local_data": {
|
"local_data": {
|
||||||
"description": "Upload d'une sauvegarde de formulaire local au format .json.",
|
"description": "Upload d'une sauvegarde de formulaire local au format .json.",
|
||||||
"permissions": ["admin"],
|
"permissions": ["admin"],
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"root": "/src/upload",
|
"root": "/src/upload",
|
||||||
"directories": [
|
"directories": [
|
||||||
"call_log",
|
"call_log",
|
||||||
"local_data"
|
"local_data",
|
||||||
|
"convert_iexplorer"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ function inputPhoneMatrice(a){this.container=a}inputPhoneMatrice.prototype={cont
|
||||||
inputPhoneMatrice.prototype.fieldsToStorage=function(){console.log("MATRICE: FIELDS TO STORAGE");var a=(new FormDeflater(this.container,["input"],["data-name"])).deflate();crc32(JSON.stringify(a));var d={},b;for(b in a)if(a[b]instanceof Array)for(var e in a[b])null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b][e]));else null!==a[b]&&(null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b])));lsi.set("p_matrice",0,d)};
|
inputPhoneMatrice.prototype.fieldsToStorage=function(){console.log("MATRICE: FIELDS TO STORAGE");var a=(new FormDeflater(this.container,["input"],["data-name"])).deflate();crc32(JSON.stringify(a));var d={},b;for(b in a)if(a[b]instanceof Array)for(var e in a[b])null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b][e]));else null!==a[b]&&(null==d[b]&&(d[b]=[]),d[b].push(parseInt(a[b])));lsi.set("p_matrice",0,d)};
|
||||||
inputPhoneMatrice.prototype.storageToFields=function(){console.log("MATRICE: STORAGE TO FIELDS");var a=lsi["export"]("p_fiches"),d=lsi.get("p_matrice",0),b=lsi["export"]("p_contacts"),e=[],c;for(c in a)-1==e.indexOf(a[c].contact)&&e.push(a[c].contact);a="<table class='line'>";for(c=0;c<e.length;c++){var g=b[c],a=a+"<tr>";0<c?(a+='<td style="text-align: right;">',a+=g.username,a+="</td>"):a+="<td></td>";for(var f=0;f<e.length;f++)if(f<e.length-1){var h=b[f];0==c?(a+="<td>",a+='<span style="writing-mode: vertical-lr; text-align: right;">',
|
inputPhoneMatrice.prototype.storageToFields=function(){console.log("MATRICE: STORAGE TO FIELDS");var a=lsi["export"]("p_fiches"),d=lsi.get("p_matrice",0),b=lsi["export"]("p_contacts"),e=[],c;for(c in a)-1==e.indexOf(a[c].contact)&&e.push(a[c].contact);a="<table class='line'>";for(c=0;c<e.length;c++){var g=b[c],a=a+"<tr>";0<c?(a+='<td style="text-align: right;">',a+=g.username,a+="</td>"):a+="<td></td>";for(var f=0;f<e.length;f++)if(f<e.length-1){var h=b[f];0==c?(a+="<td>",a+='<span style="writing-mode: vertical-lr; text-align: right;">',
|
||||||
a+=h.username,a+="</span>"):f<c?(a+="<td>",a+="<input type='checkbox' name='matrice_"+g.uid+"_"+h.uid+"' data-name='"+g.uid+"' value='"+h.uid+"' id='matrice_"+g.uid+"_"+h.uid+"'",null!=d[c]&&-1<d[c].indexOf(f)&&(a+=" checked"),a+=" >",a+="<label for='matrice_"+g.uid+"_"+h.uid+"'></label>"):a+="<td class='hidden'>";a+="</td>"}a+="</tr>"}this.container.innerHTML=a+"</table>"};
|
a+=h.username,a+="</span>"):f<c?(a+="<td>",a+="<input type='checkbox' name='matrice_"+g.uid+"_"+h.uid+"' data-name='"+g.uid+"' value='"+h.uid+"' id='matrice_"+g.uid+"_"+h.uid+"'",null!=d[c]&&-1<d[c].indexOf(f)&&(a+=" checked"),a+=" >",a+="<label for='matrice_"+g.uid+"_"+h.uid+"'></label>"):a+="<td class='hidden'>";a+="</td>"}a+="</tr>"}this.container.innerHTML=a+"</table>"};
|
||||||
inputPhoneMatrice.prototype.attach=function(){console.log("MATRICE: ATTACH");lsi.createDataset("p_matrice");this.storageToFields();var a=this;this.container.addEventListener("click",function(d){a.fieldsToStorage();a.storageToFields()},!1)};
|
inputPhoneMatrice.prototype.attach=function(){console.log("MATRICE: ATTACH");lsi.createDataset("p_matrice");this.storageToFields();var a=this;this.container.addEventListener("click",function(d){a.fieldsToStorage();a.storageToFields()},!1);this.snake()};inputPhoneMatrice.prototype.snake=function(){this.sVelocity=[0,0];this.sLength=0;this.sStack=[]};
|
||||||
|
|
|
@ -170,4 +170,26 @@ inputPhoneMatrice.prototype.attach = function(){
|
||||||
ptr.fieldsToStorage();
|
ptr.fieldsToStorage();
|
||||||
ptr.storageToFields();
|
ptr.storageToFields();
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
this.snake();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
inputPhoneMatrice.prototype.snake = function(){
|
||||||
|
|
||||||
|
/* [0] On écrit les fonctions principales
|
||||||
|
=========================================================*/
|
||||||
|
this.sVelocity = [0, 0];
|
||||||
|
this.sLength = 0;
|
||||||
|
this.sStack = [];
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -364,6 +364,127 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* CONVERTISSEUR .txt de iExplorer vers .xml de Call Log
|
||||||
|
*
|
||||||
|
* @file<FILE> Pointeur vers $_FILES['']
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function iexplorer_convert($params){
|
||||||
|
extract($params);
|
||||||
|
|
||||||
|
/* [1] Gestion de l'upload du fichier et de la vérification du format
|
||||||
|
=========================================================*/
|
||||||
|
$uploadError = self::simpleFile(
|
||||||
|
'convert_iexplorer',// nom du dossier d'upload
|
||||||
|
'txt', // format du fichier
|
||||||
|
$file, // Fichier lui-même
|
||||||
|
function($content){
|
||||||
|
$lines = explode("\n", $content);
|
||||||
|
|
||||||
|
foreach($lines as $l=>$line)
|
||||||
|
if( strlen($line) > 0 && !preg_match('/^([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) *$/u', $line) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/* (1) Si erreur d'upload, on la renvoie */
|
||||||
|
if( $uploadError != ManagerError::Success )
|
||||||
|
return array( 'ModuleError' => $uploadError );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* [2] On récupère les colonnes avec la premiére ligne
|
||||||
|
=========================================================*/
|
||||||
|
/* (1) On met un handler sur le fichier pour le lire */
|
||||||
|
$path = __ROOT__."/src/upload/convert_iexplorer/".$_SESSION['username'].".txt";
|
||||||
|
|
||||||
|
$handler = new \SplFileObject($path, 'r');
|
||||||
|
|
||||||
|
/* (2) On récupère pour chaque colonne, la position dans le chaine, et la valeur */
|
||||||
|
$data = array();
|
||||||
|
$lineCount = 0;
|
||||||
|
while( !$handler->eof() ){
|
||||||
|
$line = $handler->fgets();
|
||||||
|
|
||||||
|
/* (1) Si première ligne, c'est les intitulés */
|
||||||
|
if( $lineCount == 0 ){
|
||||||
|
// Si erreur dans les intitulés, on retourne une erreur
|
||||||
|
if( !preg_match('/^([\w\(\):\.@-]+(?: [\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: [\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: [\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: [\w\(\):\.@-]+)*) *$/u', $line, $matches) )
|
||||||
|
return array( 'ModuleError' => ManagerError::FormatError );
|
||||||
|
|
||||||
|
// On récupère les colonnes
|
||||||
|
$columns = array_slice($matches, 1);
|
||||||
|
|
||||||
|
// On récupére les positions des colonnes
|
||||||
|
$colpos = array();
|
||||||
|
foreach($columns as $column)
|
||||||
|
array_push($colpos, strpos($line, $column));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* (2) S'il reconnait pas la ligne, on passe à la suivante */
|
||||||
|
if( !preg_match('/^([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) +([\w\(\):\.@-]+(?: {1,3}[\w\(\):\.@-]+)*) *$/u', $line, $matches) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* (3) On enregistre les données sinon */
|
||||||
|
$cur = array();
|
||||||
|
foreach($columns as $c=>$column)
|
||||||
|
$cur[$column] = $matches[$c+1];
|
||||||
|
|
||||||
|
array_push($data, $cur);
|
||||||
|
|
||||||
|
|
||||||
|
$lineCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$handler = null;
|
||||||
|
|
||||||
|
/* (3) Restitution du retour de `unserialize` */
|
||||||
|
return array(
|
||||||
|
'ModuleError' => ManagerError::Success,
|
||||||
|
'data' => $data
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,111 @@
|
||||||
|
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
||||||
|
require_once __ROOT__.'/manager/autoloader.php';
|
||||||
|
|
||||||
|
use \manager\ModuleRequest;
|
||||||
|
use \manager\ResourceDispatcher;
|
||||||
|
use \manager\sessionManager;
|
||||||
|
use \manager\ManagerError;
|
||||||
|
|
||||||
|
debug();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Fonction pour corriger les dates
|
||||||
|
function correctDates($date){
|
||||||
|
$date = str_replace('janv.', 'jan.', $date);
|
||||||
|
$date = str_replace('févr.', 'feb.', $date);
|
||||||
|
$date = str_replace('mars', 'march', $date);
|
||||||
|
$date = str_replace('avr.', 'apr.', $date);
|
||||||
|
$date = str_replace('mai', 'may', $date);
|
||||||
|
$date = str_replace('juin', 'june', $date);
|
||||||
|
$date = str_replace('juil.', 'july', $date);
|
||||||
|
$date = str_replace('août', 'aug.', $date);
|
||||||
|
|
||||||
|
return strtotime($date);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [0] Upload du fichier
|
||||||
|
=========================================================*/
|
||||||
|
if( isset($_FILES) && isset($_FILES['file']) ){
|
||||||
|
|
||||||
|
$request = new ModuleRequest('upload/iexplorer_convert');
|
||||||
|
$response = $request->dispatch();
|
||||||
|
|
||||||
|
// Si erreur, on l'affiche
|
||||||
|
if( $response->error != ManagerError::Success )
|
||||||
|
var_dump( ManagerError::explicit($response->error) );
|
||||||
|
|
||||||
|
// On récupère les données
|
||||||
|
$logs = $response->get('data');
|
||||||
|
|
||||||
|
/* [1] On associe un faux numéro à chaque utilisateur
|
||||||
|
=========================================================*/
|
||||||
|
$falseNumbers = array(0); // Contiendra les numéros attribués
|
||||||
|
$alreadyNumbered = array(); // Contiendra aux mêmes indices que les numéros, les noms des personnes les ayant utilisé
|
||||||
|
|
||||||
|
// Pour chaque utilisateur
|
||||||
|
foreach($logs as $i=>$log){
|
||||||
|
|
||||||
|
// On évite la première ligne
|
||||||
|
if( $i == 0 ){
|
||||||
|
unset($logs[$i]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$numberIndex = array_search($log['Number'], $alreadyNumbered);
|
||||||
|
|
||||||
|
/* (1) Si pas encore de numéro, on en attribue un */
|
||||||
|
if( $numberIndex === false ){
|
||||||
|
$lastnumIndex = count($falseNumbers) - 1;
|
||||||
|
$newNumber = ++$falseNumbers[$lastnumIndex];
|
||||||
|
$numberIndex = array_push($falseNumbers, $newNumber ) - 1;
|
||||||
|
$alreadyNumbered[$numberIndex] = $log['Number'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$logs[$i]['Name'] = $logs[$i]['Number'];
|
||||||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (2) On convertit les numéros en string */
|
||||||
|
foreach($falseNumbers as $n=>$number){
|
||||||
|
$stringNumber = "0600000000"; $snlen = strlen($stringNumber);
|
||||||
|
$stringValue = strval($number); $svlen = strlen($stringValue);
|
||||||
|
|
||||||
|
$stringNumber = substr($stringNumber, 0, $snlen-$svlen);
|
||||||
|
$stringNumber .= $stringValue;
|
||||||
|
|
||||||
|
$falseNumbers[$n] = $stringNumber;
|
||||||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($logs as $i=>$log){
|
||||||
|
$numberIndex = array_search($log['Name'], $alreadyNumbered);
|
||||||
|
$logs[$i]['Number'] = $falseNumbers[$numberIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* [2] On rédige les headers
|
||||||
|
=========================================================*/
|
||||||
|
header('Content-type: text/xml');
|
||||||
|
header('Content-Disposition: attachment; filename=call-log.xml');
|
||||||
|
|
||||||
|
|
||||||
|
/* [3] On rédige le contenu du fichier XML
|
||||||
|
=========================================================*/
|
||||||
|
echo "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\n";
|
||||||
|
echo "<Logs>\n";
|
||||||
|
|
||||||
|
// Pour chaque utilisateur
|
||||||
|
foreach($logs as $i=>$log)
|
||||||
|
echo "<Item Number='${log['Number']}' Name='${log['Name']}' Date='".correctDates($log['Date'])."' Duration='".strtotime("1970-01-01 ${log['Duration']} UTC")."' Direction='".strtoupper($log['Call Type'])."' Type='PHONE' />\n";
|
||||||
|
|
||||||
|
echo "</Logs>\n";
|
||||||
|
|
||||||
|
// Si aucun fichier
|
||||||
|
}else{ ?>
|
||||||
|
<form action='' method='POST' enctype='multipart/form-data'>
|
||||||
|
<input type='file' name='file'>
|
||||||
|
<input type='submit' value='Convertir en call-log'>
|
||||||
|
</form>
|
||||||
|
<?php }
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue