Corrections Managers/Repo/ClientSide

This commit is contained in:
xdrm-brackets 2015-12-15 09:19:59 +01:00
parent 4d6164c519
commit 302a1b0747
6 changed files with 64 additions and 29 deletions

View File

@ -106,6 +106,7 @@ $answerType = (isset($_GET['type'])) ? $_GET['type'] : null;
<span>Choix du médecin traitant (optionnel)</span><br>
<select id='crMedecin' name='id_medecin'><?php
echo "<option value='.'>Médecins traitants</option>";
foreach(MedecinRepo::getAll() as $MEDECIN)
echo "<option value='".$MEDECIN['Id']."'>".$MEDECIN['Nom']." ".$MEDECIN['Prenom']."</option>";
?></select>

View File

@ -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 );
}

View File

@ -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){

View File

@ -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();
?>

View File

@ -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) && $variable<pow(2,32);
$checker = $checker && is_int($variable) && $variable<pow(2, 32);
break;
case 'SmallInteger':
$checker = $checker && is_int($variable) && $variable<pow(2,16);
$checker = $checker && is_int($variable) && $variable<pow(2, 16);
break;
case 'TinyInteger':
$checker = $checker && is_int($variable) && $variable<pow(2,8);
$checker = $checker && is_int($variable) && $variable<pow(2, 8);
break;
case 'BigInteger':
$checker = $checker && is_int($variable) && $variable<pow(2,64);
$checker = $checker && is_int($variable) && $variable<pow(2, 64);
break;
case 'Date':
$checker = $checker && is_string($variable) && preg_match('/(\d+)\/(\d+)\/(\d+)/is',$variable);
$checker = $checker && is_string($variable) && ( preg_match('/\d{2}\/\d{2}\/\d{4}/', $variable) || preg_match('/\d{4}-\d{2}-\d{2}/', $variable) );
break;
case 'Heure':

View File

@ -18,34 +18,56 @@ class PatientRepo
}
public static function add($civilite,$prenom,$nom,$adresse,$adresse2,$ville,$codePostal,$dateNaissance,$lieuNaissance,$numSecu,$medecinTraitant = null){
if(!StaticRepo::checkParam($civilite,'Civilite') && !StaticRepo::checkParam($prenom,'String45') && !StaticRepo::checkParam($nom,'String45')
&& !StaticRepo::checkParam($adresse,'String255') && !StaticRepo::checkParam($adresse2,'String255')&& !StaticRepo::checkParam($ville,'String50')
&& !StaticRepo::checkParam($codePostal,'String5') && !StaticRepo::checkParam($dateNaissance,'Date') && !StaticRepo::checkParam($lieuNaissance,'String50')
&& !StaticRepo::checkParam($numSecu,'String15')){return false;}
if($medecinTraitant != null && !StaticRepo::checkParam($medecinTraitant,'Integer')){return false;}
$correctTypes = StaticRepo::checkParam($civilite,'Civilite');
$correctTypes = $correctTypes && StaticRepo::checkParam($prenom,'String45');
$correctTypes = $correctTypes && StaticRepo::checkParam($prenom,'String45');
$correctTypes = $correctTypes && StaticRepo::checkParam($nom,'String45');
$correctTypes = $correctTypes && StaticRepo::checkParam($adresse,'String255');
$correctTypes = $correctTypes && ( $adresse2 == 'null' || StaticRepo::checkParam($adresse2, 'String255') );
$correctTypes = $correctTypes && StaticRepo::checkParam($ville,'String50');
$correctTypes = $correctTypes && StaticRepo::checkParam($codePostal,'String');
$correctTypes = $correctTypes && StaticRepo::checkParam($dateNaissance,'Date');
$correctTypes = $correctTypes && StaticRepo::checkParam($lieuNaissance,'String50');
$correctTypes = $correctTypes && ( $medecinTraitant == 'null' || StaticRepo::checkParam($medecinTraitant, 'Integer') );
if( !$correctTypes ) return false;
$dateNaissance = strtotime($dateNaissance);
$dateNaissance = Date('o-m-d',$dateNaissance);
$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' => $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;
}