diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index 0f1e7c1..4bc5f7f 100755 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -40,6 +40,13 @@ class AdminController { if(isset($_GET["id"])){ $id=intval($_GET["id"]); } + try{ + $this->verifierDonnees(); + } catch (Exception $ex){ + $dVueErreur[] = 'Erreur : '.$ex; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + return; + } $sci = new Scientifique( $id, $_POST["name"], @@ -92,6 +99,39 @@ class AdminController { } + private function verifierDonnees(){ + $sexe = new MdlSexe(); + $theme = new MdlThematique(); + $diff = new MdlDifficulte(); + $selectTheme=$theme->getFromId(intval($_POST["theme"])); + $selectDiff=$diff->getFromId(intval($_POST["difficulte"])); + $selectSexe=$sexe->getFromId(intval($_POST["sexe"])); + //todo : verifier les données, mettre dans une fonction et try catch + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["prenom"]) < 2){ + throw new Exception("prénom trop court"); + } + if(empty($_POST["url"])){ + throw new Exception("pas de photo"); + } + if(strlen($_POST["name"]) < 2){ + throw new Exception("nom trop court"); + } + if(strlen($_POST["description"]) < 20){ + throw new Exception("description trop courte "); + } + if($selectTheme==null){ + throw new Exception("thematique inconnue"); + } + if($selectSexe==null){ + throw new Exception("sexe inconnu"); + } + if($selectDiff==null){ + throw new Exception("difficulté inconnue"); + } + } } ?> \ No newline at end of file