Gestion côté server+bdd en cours

This commit is contained in:
xdrm-brackets 2016-04-30 12:19:51 +02:00
parent 4d5b58c378
commit d130da42c8
7 changed files with 95 additions and 12 deletions

View File

@ -185,6 +185,22 @@
},
"input": {
"phone": {
"description": "Enregistre les données d'une enquête téléphonique.",
"permissions": ["admin"],
"parameters": {
"subject": { "description": "Données sur le sujet de l'enquête.", "type": "array" },
"contacts": { "description": "Données des contacts de l'enquête.", "type": "array<array>" },
"mini": { "description": "Mini fiches relations sur les contacts de l'enquête.", "type": "array<array>" },
"fiches": { "description": "Fiches relation sur les plus proches contacts de l'enquête.", "type": "array<array>" }
}
}
},
"upload": {
"call_log": {

View File

@ -1,3 +1,3 @@
function inputPhoneSubject(a,b,c,d,e){this.number=a;this.username=b;this.firstname=c;this.lastname=d;this.store_button=e}inputPhoneSubject.prototype={store_button:this.store_button,number:this.number,username:this.username,firstname:this.firstname,lastname:this.lastname};
inputPhoneSubject.prototype.fieldsToStorage=function(){console.log("SUBJECT: FIELDS TO STORAGE");var a=0<this.number.value.length,a=a&&0<this.username.value.length+this.firstname.value.length+this.lastname.value.length;if(!a)return!1;lsi.set("subject","form",{number:this.number.value,username:this.username.value,firstname:this.firstname.value,lastname:this.lastname.value})};
inputPhoneSubject.prototype.storageToFields=function(){console.log("SUBJECT: STORAGE TO FIELDS");var a=lsi.get("subject","form");null!=a&&(this.number.value=a.number,this.username.value=a.username,this.firstname.value=a.firstname,this.lastname.value=a.lastname)};inputPhoneSubject.prototype.attach=function(){console.log("SUBJECT: ATTACH");lsi.createDataset("subject");var a=this;this.store_button.addEventListener("click",function(b){a.fieldsToStorage()},!1);this.storageToFields()};
inputPhoneSubject.prototype.fieldsToStorage=function(){console.log("SUBJECT: FIELDS TO STORAGE");var a=0<this.number.value.length,a=a&&0<this.username.value.length+this.firstname.value.length+this.lastname.value.length;if(!a)return!1;lsi.set("subject",0,{number:this.number.value,username:this.username.value,firstname:this.firstname.value,lastname:this.lastname.value})};
inputPhoneSubject.prototype.storageToFields=function(){console.log("SUBJECT: STORAGE TO FIELDS");var a=lsi.get("subject",0);null!=a&&(this.number.value=a.number,this.username.value=a.username,this.firstname.value=a.firstname,this.lastname.value=a.lastname)};inputPhoneSubject.prototype.attach=function(){console.log("SUBJECT: ATTACH");lsi.createDataset("subject");var a=this;this.store_button.addEventListener("click",function(b){a.fieldsToStorage()},!1);this.storageToFields()};

View File

@ -43,7 +43,7 @@ inputPhoneSubject.prototype.fieldsToStorage = function(){
};
// {3} On enregistre les données dans le 'localStorage' //
lsi.set('subject', 'form', obj);
lsi.set('subject', 0, obj);
};
@ -58,7 +58,7 @@ inputPhoneSubject.prototype.storageToFields = function(){
console.log('SUBJECT: STORAGE TO FIELDS');
// {1} On récupère les informations du sujet //
var subjectData = lsi.get('subject', 'form');
var subjectData = lsi.get('subject', 0);
if( subjectData == null ) return;

View File

@ -245,13 +245,17 @@
case 'sha1':
return $checker && is_string($value) && preg_match('/^[\da-f]{40}$/i', $value);
break;
break;
// Numéro de téléphone
case 'phone_number':
return $checker && is_string($value) && preg_match('/^(?:0|\+33 ?|0?0?33 ?|)([1-9] ?(?:[0-9] ?){8})$/i', $value);
break;
// Tableau non vide
case 'array':
return $checker && is_array($value) && count($value) > 0;
break;
default:
return false;
break;

63
manager/module/input.php Normal file
View File

@ -0,0 +1,63 @@
<?php
namespace manager\module;
use \manager\sessionManager;
use \manager\Database;
use \manager\ManagerError;
use \manager\ModuleRequest;
use \manager\Repo;
class input{
/* TRAITE LES DONNÉES D'UN FORMULAIRE DE TYPE TÉLÉPHONIQUE
*
* @data<Array> Tableau contenant les données du formulaire
*
* @return subject_id<int> Retourne l'id sujet de l'enquête
*
*/
public static function phone($params){
extract($params);
var_dump($params);
/* [1] On crée le sujet de l'enquête
=========================================================*/
/* (1) On rédige la requête */
$create_subject_request = new ModuleRequest('subject/create', array(
'username' => $subject['username'],
'firstname' => $subject['firstname'],
'lastname' => $subject['lastname'],
'id_facebook' => null,
'number' => $subject['number']
));
/* (2) On exécute la requête (création) */
$create_subject_response = $create_subject_request->dispatch();
/* (3) Gestion de l'erreur, si erreur de création */
if( $create_subject_response->error != ManagerError::Success )
return array( 'ModuleError' => $create_subject_response->error );
/* (4) On récupère l'id du sujet */
$subject_id = $create_subject_response->get('id_subject');
/* [2] Gestion du retour
=========================================================*/
return array(
'ModuleError' => ManagerError::Success,
'subject_id' => $subject_id
);
}
}
?>

View File

@ -5,5 +5,5 @@ function checkRadioValue(a){for(var c=0,b=0;b<a.length;b++)!0===a[b].status&&c++
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(){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);importCallLog.addEventListener("change",function(a){api.send({path:"upload/call_log",file:importCallLog.files[0]},function(a){console.log(a);
0==a.ModuleError&&(importCallLog.addClass("active"),a={path:"call_log/unserialize",phone_number:$("#subject_phone_number").value},api.send(a,function(a){console.log(a);if(0==a.ModuleError){for(var d=0;d<a.directory.length;d++){var c=(null===a.directory[d].name?"":a.directory[d].name).split(" ");lsi.set("contacts","form"+d,{uid:d,number:a.directory[d].number,username:1==c.length?c[0]:"",firstname:1<c.length?c[0]:"",lastname:1<c.length?c.splice(1).join(" "):""})}contactManager.storageToFields();dynamicUpdate(!0)}}))})},
!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!1);submitAllButton.addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();a={subject:lsi["export"]("subject"),contact:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiche:lsi["export"]("fiches")};console.log(a);api.send({path:"input/phone",data:a},function(a){console.log(a)},
!1);clearAllButton.addEventListener("click",function(a){localStorage.clear();reload()},!1);submitAllButton.addEventListener("click",function(a){console.log("> GATHERING ALL DATA");subjectManager.fieldsToStorage();contactManager.fieldsToStorage();miniManager.fieldsToStorage();ficheManager.fieldsToStorage();console.log({});a={path:"input/phone",subject:lsi["export"]("subject")[0],contacts:lsi["export"]("contacts"),mini:lsi["export"]("mini-fiches"),fiche:lsi["export"]("fiches")};api.send(a,function(a){console.log(a)},
!1)},!1)})})})});

View File

@ -291,17 +291,17 @@ include('/js/includes/input-phone-fiche.js', function(){
/* (2) On construit un objet qui contiendra toutes les données */
var data = {
subject: lsi.export('subject'),
contact: lsi.export('contacts'),
mini: lsi.export('mini-fiches'),
fiche: lsi.export('fiches')
};
console.log( data );
/* (3) On prépare la requête */
/* (3) On prépare la requête avec toutes les données*/
var request = {
path: 'input/phone',
data: data
subject: lsi.export('subject')[0],
contacts: lsi.export('contacts'),
mini: lsi.export('mini-fiches'),
fiche: lsi.export('fiches')
};
/* (4) On envoie la requête et traite la réponse */