diff --git a/Patients.php b/Patients.php
index 1f1c3d8..48caa84 100755
--- a/Patients.php
+++ b/Patients.php
@@ -106,6 +106,7 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
Choix du médecin traitant (optionnel)
diff --git a/js/lib/API.js b/js/lib/API.js
index 319c529..82b8b71 100755
--- a/js/lib/API.js
+++ b/js/lib/API.js
@@ -44,8 +44,10 @@ APIClass.prototype = {
else // IE5, IE6
this.xhr[i] = new ActiveXObject('Microsoft.XMLHttpRequest');
+
console.log(pRequest);
+
var ptrAPI = this;
this.xhr[i].onreadystatechange = function(){
if( ptrAPI.xhr[i].readyState == 4 ){ // si la requête est terminée
@@ -74,6 +76,8 @@ APIClass.prototype = {
form.append(obj, pRequest[obj]);
this.xhr[i].open('POST', '/managers/', true);
+ // on définit le HEADER
+ this.xhr[i].setRequestHeader('X-Requested-With', 'XMLHttpRequest');
this.xhr[i].send( form );
}
diff --git a/js/patients.js b/js/patients.js
index 2de5999..2cf2a28 100755
--- a/js/patients.js
+++ b/js/patients.js
@@ -168,13 +168,13 @@ sbCreer.addEventListener('click', function(e){
nom: inNom.value,
civilite: (inCivil[0].checked) ? inCivil[0].value : inCivil[1].value,
adresse: inAdr.value,
- adresse2: inAdr2.value,
+ adresse2: (inAdr2.value.length>0) ? inAdr2.value : null,
code_postal: inCP.value,
ville: inVille.value,
date_naissance: inDN.value,
lieu_naissance: inLN.value,
num_secu: inSecu.value,
- medecin_traitant: inMedecin.value
+ medecin_traitant: (inMedecin.value!='.') ? inMedecin.value : null
};
API.send('Patient:add', request, function(e){
diff --git a/managers/index.php b/managers/index.php
index d2ec853..560789a 100755
--- a/managers/index.php
+++ b/managers/index.php
@@ -37,6 +37,12 @@ if(isset($_POST['command'])){
$objectResponse->send();
}
+}else{
+ $response = json_encode(['result' => false,
+ 'message' => "Variable POST command inexistante"]);
+ $objectResponse = new Response(404);
+ $objectResponse->write($response);
+ $objectResponse->send();
}
ob_end_clean();
?>
diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php
index a923d17..26c4eee 100755
--- a/repositories/StaticRepo.php
+++ b/repositories/StaticRepo.php
@@ -109,10 +109,12 @@ class StaticRepo{
=============================================================*/
$checker = true; // contiendra VRAI si la vérification s'avère correcte
$matches = [];
+ $len = 8;
+
//si on a un type scalairexlongueur, on traite
- if(preg_match_all('/((?:[a-z][a-z]+))(\\d+)/is',$dbtype,$matches)){
+ if(preg_match_all('/([A-Z][a-z]+)(\d+)/s', $dbtype,$matches)){
$dbtype = $matches[1][0];
- isset($matches[2][0])? $len = $matches[2][0] : $len = 8;
+ $len = $matches[2][0];
}
switch($dbtype){
@@ -123,27 +125,27 @@ class StaticRepo{
// [2] Chaine de caractère (longueur variable)
case 'String':
- $checker = $checker && is_string($variable) && strlen($variable)<$len;
+ $checker = $checker && is_string($variable) && strlen($variable) <= $len;
break;
case 'Integer':
- $checker = $checker && is_int($variable) && $variableprepare('INSERT INTO Patient VALUES (DEFAULT,:civilite,:nom,:prenom,:adresse,:adresse2,:ville,:codePostal,:dateNaissance,:lieuNaissance,:numSecu,:medecin)');
- $result = $req->execute(['civilite' => $civilite,
- 'nom' => $nom,
- 'prenom' => $prenom,
- 'adresse' => $adresse,
- 'adresse2' => $adresse2,
- 'ville' => $ville,
- 'codePostal' => $codePostal,
+ $req = StaticRepo::getConnexion()->prepare("INSERT INTO Patient
+ VALUES(DEFAULT,
+ :civilite,
+ :nom,
+ :prenom,
+ :adresse,
+ :adresse2,
+ :ville,
+ :codePostal,
+ :dateNaissance,
+ :lieuNaissance,
+ :numSecu,
+ :medecin
+ )");
+ $result = $req->execute([
+ 'civilite' => $civilite,
+ 'nom' => $nom,
+ 'prenom' => $prenom,
+ 'adresse' => $adresse,
+ 'adresse2' => (strlen($adresse2)>0) ? $adresse2 : NULL,
+ 'ville' => $ville,
+ 'codePostal' => $codePostal,
'dateNaissance' => $dateNaissance,
'lieuNaissance' => $lieuNaissance,
- 'numSecu' => $numSecu,
- 'medecin' => $medecinTraitant ]);
+ 'numSecu' => $numSecu,
+ 'medecin' => $medecinTraitant
+ ]);
+
//PDO renvoie un ID sous forme de char, on transtype
$id = StaticRepo::getConnexion()->lastInsertId();
settype($id,'integer');
- if($result){return $id;}
- else{return false;}
+
+ if($result)return $id;
+ else return false;
}