Gestion de l'upload de `local_data` (sauvegarde de formulaire local), reste à faire la récupération du contenu en javascript

This commit is contained in:
xdrm-brackets 2016-05-03 11:11:41 +02:00
parent 256c7bf813
commit 2c3cabec61
8 changed files with 143 additions and 1035 deletions

View File

@ -69,16 +69,16 @@
/* [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> -->
<?php //
// var_dump($_FILES);
//
// if( isset($_FILES) ){
//
// $request = new ModuleRequest('upload/call_log', array() );
// $request = new ModuleRequest('upload/local_data', array() );
// $response = $request->dispatch();
// var_dump( ManagerError::explicit($response->error) );
//

View File

@ -207,7 +207,16 @@
"description": "Upload d'un journal d'appel au format .xml.",
"permissions": ["admin"],
"parameters": {
"file": { "description": "Fichier du journal d'appel", "type": "FILE" }
"file": { "description": "Fichier du journal d'appel.", "type": "FILE" }
}
},
"local_data": {
"description": "Upload d'une sauvegarde de formulaire local au format .json.",
"permissions": ["admin"],
"parameters": {
"file": { "description": "Fichier du de sauvegarde de formulaire local.", "type": "FILE" }
}
}

View File

@ -65,9 +65,8 @@
/* (2) Sinon, on vérifie le format */
$file_content = file_get_contents($file['tmp_name']);
/* (3) On retourne 'Success' si format ok, sinon 'FormatError' */
if( $tester($file_content) ) return ManagerError::Success;
else return ManagerError::FormatError;
/* (3) On retourne 'FormatError' si erreur de format */
if( !$tester($file_content) ) return ManagerError::FormatError;
/* [4] Construction du chemin
@ -158,7 +157,7 @@
* @file<FILE> Pointeur vers $_FILES['']
*
*/
public static function call_log($params){
public static function local_data($params){
extract($params);
return array(
@ -172,13 +171,91 @@
if( $json == null )
return false; // Si erreur de parsage, on retourne une erreur
/* (2) Vérification du contenu de premier niveau */
$checkLevel0 = isset($json['subject']) && is_array($json['subject']);
$checkLevel0 = $checkLevel0 && isset($json['contacts']) && is_array($json['contacts']);
$checkLevel0 = $checkLevel0 && isset($json['mini']) && is_array($json['mini']);
$checkLevel0 = $checkLevel0 && isset($json['fiches']) && is_array($json['fiches']);
/* (3) Si tout s'est bien passé, le format est bon */
// Erreur si level 0 incorrect
if( !$checkLevel0 )
return false;
/* (3) Vérification du sujet */
$checkSubject = isset($json['subject']['username']) && is_string($json['subject']['username']);
$checkSubject = $checkSubject && isset($json['subject']['firstname']) && is_string($json['subject']['firstname']);
$checkSubject = $checkSubject && isset($json['subject']['lastname']) && is_string($json['subject']['lastname']);
$checkSubject = $checkSubject && isset($json['subject']['number']) && is_string($json['subject']['number']);
// Erreur des attributs du sujet incorrects ou manquants
if( !$checkSubject )
return false;
/* (4) Vérification des contacts */
foreach($json['contacts'] as $contact){
$checkContact = isset($contact['username']) && is_string($contact['username']);
$checkContact = $checkContact && isset($contact['firstname']) && is_string($contact['firstname']);
$checkContact = $checkContact && isset($contact['lastname']) && is_string($contact['lastname']);
$checkContact = $checkContact && isset($contact['number']) && ( is_numeric($contact['number']) || is_string($contact['number']) );
// Si erreur des attributs du contact incorrects ou manquants
if( !$checkContact )
return false;
}
/* (5) Vérification des mini-fiches */
foreach($json['mini'] as $mini){
$checkMini = isset($mini['uid']) && is_numeric($mini['uid']);
$checkMini = $checkMini && isset($mini['username']) && is_string($mini['username']);
$checkMini = $checkMini && isset($mini['firstname']) && is_string($mini['firstname']);
$checkMini = $checkMini && isset($mini['lastname']) && is_string($mini['lastname']);
$checkMini = $checkMini && isset($mini['sexe']) && is_array($mini['sexe']);
$checkMini = $checkMini && isset($mini['age']) && is_string($mini['age']);
$checkMini = $checkMini && isset($mini['job']) && is_string($mini['job']);
$checkMini = $checkMini && isset($mini['loc']) && is_array($mini['loc']);
// Si erreur des attributs des mini-fiches incorrects ou manquants
if( !$checkMini )
return false;
}
/* (6) Vérification des fiches */
foreach($json['fiches'] as $fiches){
$checkFiche = isset($fiches['uid']) && is_numeric($fiches['uid']);
$checkFiche = $checkFiche && isset($fiches['username']) && is_string($fiches['username']);
$checkFiche = $checkFiche && isset($fiches['firstname']) && is_string($fiches['firstname']);
$checkFiche = $checkFiche && isset($fiches['lastname']) && is_string($fiches['lastname']);
$checkFiche = $checkFiche && isset($fiches['sexe']) && is_array($fiches['sexe']);
$checkFiche = $checkFiche && isset($fiches['age']) && is_string($fiches['age']);
$checkFiche = $checkFiche && isset($fiches['job']) && is_string($fiches['job']);
$checkFiche = $checkFiche && isset($fiches['loc']) && is_array($fiches['loc']);
$checkFiche = $checkFiche && isset($fiches['loc2']) && is_array($fiches['loc2']);
$checkFiche = $checkFiche && isset($fiches['studies']) && is_string($fiches['studies']);
$checkFiche = $checkFiche && isset($fiches['famsit']) && is_array($fiches['famsit']);
$checkFiche = $checkFiche && isset($fiches['reltype']) && is_array($fiches['reltype']);
$checkFiche = $checkFiche && isset($fiches['reltypeSpecial']) && is_string($fiches['reltypeSpecial']);
$checkFiche = $checkFiche && isset($fiches['city']) && is_string($fiches['city']);
$checkFiche = $checkFiche && isset($fiches['duration']) && is_array($fiches['duration']);
$checkFiche = $checkFiche && isset($fiches['context']) && is_array($fiches['context']);
$checkFiche = $checkFiche && isset($fiches['contextSpecial']) && is_array($fiches['contextSpecial']);
$checkFiche = $checkFiche && isset($fiches['freq']) && is_array($fiches['freq']);
$checkFiche = $checkFiche && isset($fiches['connect']) && is_array($fiches['connect']);
$checkFiche = $checkFiche && isset($fiches['connectSpecial']) && is_array($fiches['connectSpecial']);
// Si erreur des attributs des fiches incorrects ou manquants
if( !$checkFiche )
return false;
}
return true;
}
)

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -41,7 +41,14 @@
<h4 class='self color2' data-icon='e'>
<a style='display:none' id='download-target'></a>
<input type='submit' class='primary' id='export-all' value='Exporter les données'><br>
</h4>
<h4 class='self color2' data-icon='e'>
<input type='file' id='local-upload' style='display: none;'>
<input type='submit' class='primary' id='import-all' value='Importer des données'><br>
</h4>
<h4 class='self color2' data-icon='e'>
<input type='submit' class='primary' id='clear-all' value='Tout effacer'>
</h4>
<span data-space></span>
@ -67,7 +74,7 @@
<span data-space></span>
<h5 data-text="Seuls les fichiers au format XML et spécifiques sont pris en compte."></h5>
<h4 data-icon='u' class='color2'>
<input type='file' id='call_log-import' value='test'>
<input type='file' id='call_log-import'>
<span class='file-input'>Importer un journal d'appels</span>
</h4>
<span data-space></span>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long