diff --git a/.gitignore b/.gitignore index 426c53c..600b07e 100755 --- a/.gitignore +++ b/.gitignore @@ -8,9 +8,6 @@ ehthumbs_vista.db # Dump file *.stackdump -# Folder config file -[Dd]esktop.ini - # Recycle Bin used on file shares $RECYCLE.BIN/ @@ -77,12 +74,6 @@ Temporary Items ##### GPG secring.* -##### Dropbox -# Dropbox settings and caches -.dropbox -.dropbox.attr -.dropbox.cache - ##### SynopsysVCS # Waveform formats *.vcd @@ -165,23 +156,11 @@ Sessionx.vim # Temporary .netrwhist -*~ # Auto-generated tag files tags # Persistent undo [._]*.un~ -##### Emacs -# -*- mode: gitignore; -*- -*~ -\#*\# -/.emacs.desktop -/.emacs.desktop.lock -*.elc -auto-save-list -tramp -.\#* - # Org-mode .org-id-locations *_archive @@ -254,10 +233,6 @@ bh_unicode_properties.cache # https://packagecontrol.io/packages/sublime-github GitHub.sublime-settings -##### Notepad++ -# Notepad++ backups # -*.bak - ##### TextMate *.tmproj *.tmproject @@ -280,7 +255,6 @@ tmtags **/nbproject/Package-*.bash build/ nbbuild/ -dist/ nbdist/ .nb-gradle/ @@ -289,27 +263,27 @@ nbdist/ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff -.idea/**/workspace.xml -.idea/**/tasks.xml -.idea/**/usage.statistics.xml -.idea/**/dictionaries -.idea/**/shelf +php/.idea/**/workspace.xml +php/.idea/**/tasks.xml +php/.idea/**/usage.statistics.xml +php/.idea/**/dictionaries +php/.idea/**/shelf # Generated files -.idea/**/contentModel.xml +php/.idea/**/contentModel.xml # Sensitive or high-churn files -.idea/**/dataSources/ -.idea/**/dataSources.ids -.idea/**/dataSources.local.xml -.idea/**/sqlDataSources.xml -.idea/**/dynamic.xml -.idea/**/uiDesigner.xml -.idea/**/dbnavigator.xml +php/.idea/**/dataSources/ +php/.idea/**/dataSources.ids +php/.idea/**/dataSources.local.xml +php/.idea/**/sqlDataSources.xml +php/.idea/**/dynamic.xml +php/.idea/**/uiDesigner.xml +php/.idea/**/dbnavigator.xml # Gradle -.idea/**/gradle.xml -.idea/**/libraries +php/.idea/**/gradle.xml +php/.idea/**/libraries # Gradle and Maven with auto-import # When using Gradle or Maven with auto-import, you should exclude module files, @@ -328,7 +302,7 @@ nbdist/ cmake-build-*/ # Mongo Explorer plugin -.idea/**/mongoSettings.xml +php/.idea/**/mongoSettings.xml # File-based project format *.iws @@ -343,7 +317,7 @@ out/ atlassian-ide-plugin.xml # Cursive Clojure plugin -.idea/replstate.xml +php/.idea/replstate.xml # Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml @@ -352,17 +326,15 @@ crashlytics-build.properties fabric.properties # Editor-based Rest Client -.idea/httpRequests +php/.idea/httpRequests # Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser +php/.idea/caches/build_file_checksums.ser ##### Eclipse .metadata bin/ tmp/ -*.tmp -*.bak *.swp *~.nib local.properties @@ -376,12 +348,6 @@ local.properties # Locally stored "Eclipse launch configurations" *.launch -# PyDev specific (Python IDE for Eclipse) -*.pydevproject - -# CDT-specific (C/C++ Development Tooling) -.cproject - # CDT- autotools .autotools @@ -410,11 +376,6 @@ local.properties .apt_generated/ .apt_generated_test/ -# Scala IDE specific (Scala & Java development for Eclipse) -.cache-main -.scala_dependencies -.worksheet - # Uncomment this line if you wish to ignore the project description file. # Typically, this file would be tracked if it contains build/dependency configurations: #.project @@ -452,12 +413,13 @@ gradle-app.setting # gradle/wrapper/gradle-wrapper.properties ##### Composer -composer.phar -/vendor/ +php/composer.phar +php/composer +php/vendor/ # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file -composer.lock +php/composer.lock ##### PHP CodeSniffer # gitignore for the PHP Codesniffer framework diff --git a/README.md b/README.md index a51568b..e69de29 100755 --- a/README.md +++ b/README.md @@ -1 +0,0 @@ -dqzdqd \ No newline at end of file diff --git a/php/.htaccess b/php/.htaccess index 095bf2a..9837fc7 100644 --- a/php/.htaccess +++ b/php/.htaccess @@ -1,6 +1,11 @@ - - RewriteEngine On - RewriteBase /php/public/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php [QSA,L] - +#RewriteEngine On +# +#RewriteCond %{REQUEST_FILENAME} !-f +#RewriteCond %{REQUEST_FILENAME} !-d +#RewriteRule ^(.*)$ index.php/$1 [L] + + +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule . index.php [L] + diff --git a/php/composer.json b/php/composer.json index 01808c9..38be522 100644 --- a/php/composer.json +++ b/php/composer.json @@ -1,6 +1,7 @@ { "require": { "twig/twig": "^3.0", + "twig/extensions": "^1.5", "ext-pdo": "*", "ext-fileinfo": "*" }, diff --git a/php/index.php b/php/index.php new file mode 100755 index 0000000..f0cf101 --- /dev/null +++ b/php/index.php @@ -0,0 +1,22 @@ + false, + 'debug' => true +]); +$twig->addExtension(new \Twig\Extension\DebugExtension()); +$twig->addGlobal('dir', '/SAE_2A_FA-Reseau_ALICA/php'); + + + + +$cont = new \App\controleur\FrontControleur(); diff --git a/php/public/assets/bandeau.png b/php/public/assets/bandeau.png new file mode 100644 index 0000000..ba1261e Binary files /dev/null and b/php/public/assets/bandeau.png differ diff --git a/php/public/css/connexion.css b/php/public/css/connexion.css index 4c14d1d..1853cc0 100755 --- a/php/public/css/connexion.css +++ b/php/public/css/connexion.css @@ -12,13 +12,14 @@ a{ body{ display: flex; + flex-direction: column; justify-content: center; align-items: center; min-height: 100vh; background: #fff; } -.container{ +.containerC{ position: relative; width: 500px; min-height: 500px; @@ -30,12 +31,13 @@ body{ -10px -10px 20px #ccc; border-radius: 30px; padding: 50px; + margin: 50px; } form{ position: relative; width: 100%; } -.container h3{ +.containerC h3{ color: #000; font-weight: 600; font-size: 2em; @@ -108,4 +110,4 @@ form{ color: #000; letter-spacing: 1px; font-size: 0.85em; -} \ No newline at end of file +} diff --git a/php/public/css/inscription.css b/php/public/css/inscription.css index 4c14d1d..fceb9de 100755 --- a/php/public/css/inscription.css +++ b/php/public/css/inscription.css @@ -12,13 +12,14 @@ a{ body{ display: flex; + flex-direction: column; justify-content: center; align-items: center; min-height: 100vh; background: #fff; } -.container{ +.containerC{ position: relative; width: 500px; min-height: 500px; @@ -30,12 +31,13 @@ body{ -10px -10px 20px #ccc; border-radius: 30px; padding: 50px; + margin: 50px; } form{ position: relative; width: 100%; } -.container h3{ +.containerC h3{ color: #000; font-weight: 600; font-size: 2em; diff --git a/php/public/css/offres.css b/php/public/css/offres.css index de4ce90..01fa053 100644 --- a/php/public/css/offres.css +++ b/php/public/css/offres.css @@ -49,3 +49,12 @@ .row3 img { align-self: flex-start; } + +a{ + text-decoration: none; +} + +.current{ + + border-bottom: 1px solid black; +} diff --git a/php/public/index.php b/php/public/index.php deleted file mode 100755 index f5d187c..0000000 --- a/php/public/index.php +++ /dev/null @@ -1,17 +0,0 @@ - false, - 'debug' => true -]); -$twig->addExtension(new \Twig\Extension\DebugExtension()); -$cont = new \App\controleur\FrontControleur(); - diff --git a/php/src/TwigExtensions.php b/php/src/TwigExtensions.php deleted file mode 100644 index 64fe288..0000000 --- a/php/src/TwigExtensions.php +++ /dev/null @@ -1,24 +0,0 @@ - [ - "supprimerCompte", "consulterSignalement","supprimerOffre" - ], - "Moderateur" => [ - //TODO - ], - "Membre" => [ - "deconnexion","proposerOffre","consulterProfil","modifierProfil","signaler", - ], - "Utilisateur" => [ - - "connexion", "getProfilByPage","inscription", "accueil", "consulterProfilLimite", "publierOffre", "listerEvenement", "creerEvenement", "supprimerEvenement", "avoirDetailEvenement", "rechercherEvenement" - ] - ); - - $action = \App\config\Validation::nettoyerString($_GET["action"] ?? ""); - if(in_array($action,$actions['Admin'])) { - if (!isset($_SESSION["role"]) || $_SESSION["role"]!="admin") { - $dVueErreur[] = 'Veuillez vous connecter'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new AdminControleur(); - } - } - else if(in_array($action,$actions['Moderateur'])) { - if (!isset($_SESSION["role"]) || ($_SESSION["role"]!="moderateur" && $_SESSION["role"]!="admin")) { - $dVueErreur[] = 'Veuillez vous connecter'; - echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new ModerateurControleur(); - } + + $router = new AltoRouter(); + + $router->setBasePath('/SAE_2A_FA-Reseau_ALICA/php'); + + $router->map('GET', '/', 'UtilisateurControleur'); + + $router->map('GET','/[a:action]?','UtilisateurControleur'); + + $router->map('POST','/[a:action]?','UtilisateurControleur'); + + $router->map('GET','/[a:action]/[i:id]?','UtilisateurControleur'); + + $router->map('GET|POST', '/user/[i:id]/[a:action]?', 'MembreControleur'); + + $router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'AdminControleur'); + + $id = 0; + + $match = $router->match(); + + $action = array(); + + $id = array(); + + $twig->render("accueil.html",[]); + + if (!$match) { + + $dVueErreur[] = "Error 404 Page not found"; + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); } - else if(in_array($action,$actions['Membre'])) { - if (!isset($_SESSION["utilisateur"])) { - $dVueErreur[] = 'Veuillez vous connecter'; + + if ($match) { + + $controller = $match['target'] ?? NULL; + $action = $match['params']['action'] ?? NULL; + $id = $match['params']['id'] ?? NULL; + + //var_dump($match); + + try { + if ($controller == "MembreControleur") { + if ($_SESSION["utilisateur"]->getRole() != "Admin" || $_SESSION["utilisateur"]->getRole() != "Membre") { + + echo $twig->render("connection.html",['msg' => 'Vous devez vous connecter pour effectuer cette action']); + } + } + + if ($controller == "AdminControleur") { + $Alumni = $_SESSION["utilisateur"]; + if ($Alumni->getRole() != "Admin") { + $dVueErreur = ["Erreur : Vous n'avez pas les privileges pour cette action"]; + + global $twig; + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); + return; + } + } else { + $namespace = 'App\\Controleur\\'; + $controller = $namespace . $controller; + $controller = new $controller(); + } + + if (is_callable(array($controller, $action))) { + + call_user_func(array($controller, $action), $match['params']); + } else { + + $dVueErreur = ['Erreur : Action inconnue']; + + echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); + } + + } catch (Error $error) { + $dVueErreur = ['Erreur : Action inconnue']; + + + echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); - } else{ - new MembreControleur(); } - }else{ - new UtilisateurControleur(); } } + } diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index 151c410..715c419 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -5,36 +5,12 @@ class MembreControleur extends UtilisateurControleur { public function __construct() { - global $twig; - if (!isset($_REQUEST["action"])) { - $action = NULL; - } else { - $action = \App\config\Validation::nettoyerString($_REQUEST["action"]); - } - switch ($action) { - case "deconnexion": - $this->deconnexion(); - break; - case "proposerOffre": - $this->proposerOffre(); - break; - case "consulterProfil": - $this->consulterProfil(); - break; - case "modifierProfil": - $this->modifierProfil(); - break; - case "signaler": - $this->signaler(); - break; - default: - parent::__construct(); - } } protected function deconnexion() { session_destroy(); + echo "on est passes ici"; header('Location: index.php?action=accueil'); exit(); } diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php index 08cd095..7e934fd 100755 --- a/php/src/controleur/UtilisateurControleur.php +++ b/php/src/controleur/UtilisateurControleur.php @@ -11,71 +11,9 @@ use App\modele\UtilisateurModele; class UtilisateurControleur { - public function __construct() - { - global $twig; - if (!isset($_REQUEST["action"])) { - $action = NULL; - } else { - $action = Validation::nettoyerString($_REQUEST["action"]); - } - switch ($action) { - case NULL: - case "accueil": - $this->accueil(); - break; - case "profil": - $this->profil(); - break; - case "getProfilByPage": - $this->getProfilByPage(); - break; - case "inscription_success": - $this->inscription_success(); - break; - case "connection": - $this->connection(); - break; - case "inscription": - $this->inscription(); - break; - case "consultOffers": - $this->consultOffers(); - break; - case "consulterProfilLimite": - $this->consulterProfilLimite(); - break; - case "createOffer": - $this->createOffer(); - break; - case "createOfferForm": - $this->createOfferForm(); - break; - case "displayOffer": - $this->displayOffer(); - break; - case "listerEvenement": - $this->listerEvenement(); - break; - case "creerEvenement": - $this->creerEvenement(); - break; - case "supprimerEvenement": - $this->supprimerEvenement(); - break; - case "avoirDetailEvenement": - $this->avoirDetailEvenement(); - break; - case "rechercherEvenement": - $this->rechercherEvenement(); - break; - default: - $dVueErreur[] = "Action inconnue ou non autorisée" . $action; - echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); - } } - protected function connection() + public function connection() { global $twig; $dVueErreur = []; // Tableau pour stocker les erreurs, le cas échéant @@ -89,7 +27,7 @@ class UtilisateurControleur if ($utilisateur instanceof Alumni) { $_SESSION['utilisateur'] = $utilisateur; - header('Location: index.php?action=accueil'); + header('Location: accueil'); exit(); } else { $dVueErreur[] = "L'adresse email ou le mot de passe est incorrect."; @@ -98,8 +36,9 @@ class UtilisateurControleur echo $twig->render('connection.html', ['dVueErreur' => $dVueErreur]); } - protected function inscription() + public function inscription() { + global $twig; $dVueErreur = []; // Tableau pour stocker les erreurs, le cas échéant $userModel = new UtilisateurModele(); @@ -120,21 +59,14 @@ class UtilisateurControleur $dVueErreur[] = "L'adresse email est déjà utilisée."; } } - try { - $nouvelUtilisateur = $userModel->inscription($prenom,$nom,$email, $hash); - if ($nouvelUtilisateur instanceof Alumni) { - header('Location: index.php?action=inscription_success'); - exit(); - } else { - $dVueErreur[] = "L'inscription a échoué, veuillez réessayer."; - } - } catch (\Exception $e) { + $nouvelUtilisateur = $userModel->inscription($prenom,$nom,$email, $hash); + + if ($nouvelUtilisateur instanceof Alumni) { + echo $twig->render('inscription_success.html'); + exit(); + } else { $dVueErreur[] = "L'inscription a échoué, veuillez réessayer."; - $twig->render('inscription.html', ['dVueErreur' => $dVueErreur]); } - - - } echo $twig->render('inscription.html', ['dVueErreur' => $dVueErreur]); } @@ -153,29 +85,35 @@ class UtilisateurControleur $nom = null; $id = null; } + $userModel = new UtilisateurModele(); + $evenements=$userModel->getEvenement(); //aller sur la page d'accueil avec le nom et prenom de l'utilisateur - echo $twig->render('accueil.html', ['prenom' => $prenom, 'nom' => $nom, 'id' => $id]); + echo $twig->render('accueil.html', ['prenom' => $prenom, 'nom' => $nom, 'id' => $id,"eventsList"=>$evenements]); } - protected function inscription_success() - { - global $twig; - echo $twig->render('inscription_success.html'); - } - protected function consulterProfilLimite() + public function consulterProfilLimite() { //TODO + echo 'not implemented yet'; } - protected function consultOffers() + public function consultOffers() { - $offerMdl = new OffreModele(); + + $userMdl = new UtilisateurModele(); global $twig; $niveauEtudes=null; $typeContrat=null; $exp = null; + $role = NULL; + if(isset($_SESSION['utilisateur'])) + { + $role = $_SESSION['utilisateur']->getRole() ; + } + + $nbOffers = 5 ; if(isset($_GET["niveauEtudes"]) && Validation::validateTypeStudies($_GET["niveauEtudes"])) { @@ -191,31 +129,30 @@ class UtilisateurControleur } if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $totalOffers = $offerMdl->getNbOffers(); + $totalOffers = $userMdl->getNbOffers(); } else { $params = array( 'typeContrat' => $typeContrat, 'exp' => $exp, 'niveauEtudes' => $niveauEtudes, + 'role' => $role ); - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $userMdl->getOffersWithFilters($params); $totalOffers = count($offers); } $numberPages = ceil($totalOffers / 5); - if($numberPages == 0 ) - { - - echo $twig->render("erreur.html",['dVueErreur' => ['Aucune Offre Trouvée']]); - return; + $msg = NULL; + if($numberPages == 0 ) { + $msg = 'Aucune Offre Trouvée'; } if (isset($_GET["page"]) && intval($_GET["page"]) != null) { $page = intval($_GET["page"]); if ($page > $numberPages || $page < 1) { $dVueErreur[] = "Page introuvable"; - echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur ]); return; } } else { @@ -225,11 +162,11 @@ class UtilisateurControleur $start = intval(($page - 1) * 5); if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $offers = $offerMdl->getOfferLimit($start, $nbOffers); + $offers = $userMdl->getOfferLimit($start, $nbOffers); } else { $params['start'] = $start; $params['nbOffers'] = 5; - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $userMdl->getOffersWithFilters($params); } /* echo "filtre :".$niveauEtudes."
"; @@ -237,25 +174,27 @@ class UtilisateurControleur echo "filtre :".$exp."
";*/ echo $twig->render('OffersList.html', [ + 'msg' => $msg, 'offres' => $offers, 'numberPages' => $numberPages, 'currentPage' => $page, - 'typeContrat' => (($typeContrat != null ? $typeContrat : "")), - 'experience' => (($exp != null ? $exp : "")), - 'niveauEtudes' => (($niveauEtudes != null ? $niveauEtudes : "")), - 'valContrat' => (($typeContrat != null ? "&typeContrat=".$typeContrat : "")), - 'valExp' => (($exp != null ? "&experience=".$exp : "")), - 'valEtudes' => (($niveauEtudes != null ? "&niveauEtudes=".$niveauEtudes : "")), + 'typeContrat' => (($typeContrat != null) ? $typeContrat : ""), + 'experience' => (($exp != null) ? $exp : ""), + 'niveauEtudes' => (($niveauEtudes != null) ? $niveauEtudes : ""), + 'valContrat' => (($typeContrat != null) ? "&typeContrat=".$typeContrat : ""), + 'valExp' => (($exp != null) ? "&experience=".$exp : ""), + 'valEtudes' => (($niveauEtudes != null) ? "&niveauEtudes=".$niveauEtudes : ""), + 'role' => $role ]); } - protected function createOfferForm() + public function createOfferForm() { global $twig; echo $twig->render("CreerOffre.html", []); } - protected function createOffer() + public function createOffer() { global $twig; $taberror = []; @@ -308,10 +247,10 @@ class UtilisateurControleur $saveImg1 = ImageSaver::SaveImage("image"); $saveImg2 = ImageSaver::SaveImage("logo"); if($saveImg1[0] && $saveImg2[0]) { - $offreMdl = new OffreModele(); + $mbrModel = new MembreModele(); - $offre = $offreMdl->publishOffer($saveImg1[1], $saveImg2[1]); + $offre = $mbrModel->publishOffer($saveImg1[1], $saveImg2[1]); echo $twig->render("OffreDetailTest.html", ['offre' => $offre]); } @@ -323,14 +262,14 @@ class UtilisateurControleur } } - public function displayOffer() + public function displayOffer(?array $params) { global $twig; - if (isset($_GET["id"]) && intval($_GET["id"]) != null) + if (isset($params['id']) && intval($params['id']) != null) { - $offreMdl = new OffreModele(); - $offre = $offreMdl->getOfferFromId(intval($_GET["id"])); + $uttilsMdl = new UtilisateurModele(); + $offre = $uttilsMdl->getOfferFromId(intval($params["id"])); if($offre != NULL) { echo $twig->render("OffreDetailTest.html",['offre' => $offre]); @@ -341,7 +280,7 @@ class UtilisateurControleur echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); } - protected function listerEvenement() + public function listerEvenement() { $mdl = new UtilisateurModele(); $evenements = $mdl->getEvenement(); @@ -350,7 +289,7 @@ class UtilisateurControleur echo $twig->render('evenement.html', ['evenements' => $evenements]); } - protected function creerEvenement() + public function creerEvenement() { global $twig; @@ -371,30 +310,37 @@ class UtilisateurControleur } } - protected function supprimerEvenement() + public function supprimerEvenement(?array $params) { $mdl = new UtilisateurModele(); - $mdl->deleteEvenement($_GET["id"]); + $mdl->deleteEvenement($params["id"]); $this->listerEvenement(); } - protected function avoirDetailEvenement() + public function avoirDetailEvenement(?array $params) { $mdl = new UtilisateurModele(); - $evenement = $mdl->getEvenementById($_GET["id"]); - global $twig; - echo $twig->render('detailEvenement.html', ['evenement' => $evenement]); + + if(isset($params['id'])) + { + $evenement = $mdl->getEvenementById($params['id']); + + + echo $twig->render('detailEvenement.html', ['evenement' => $evenement]); + } + else echo $twig->render('erreur.html', ['dVueErreur' => ['erreur id evenement']]); + + } - protected function rechercherEvenement() + public function rechercherEvenement() { $mdl = new UtilisateurModele(); $evenements = $mdl->getEvenement(); - if(isset($_POST["recherche"]) AND !empty($_POST["recherche"])) - { + if (isset($_POST["recherche"]) and !empty($_POST["recherche"])) { $recherche = Validation::nettoyerString($_POST["recherche"]); $evenements = $mdl->getEvenementByTitre($recherche); } diff --git a/php/src/gateway/AlumniGateway.php b/php/src/gateway/AlumniGateway.php index e9ae7b4..3d318d0 100644 --- a/php/src/gateway/AlumniGateway.php +++ b/php/src/gateway/AlumniGateway.php @@ -1,6 +1,9 @@ offreGw->getNewId(), + new Alumni("test.mail@icloud.fr","password","admin","prenom","nom"), + $nom, + $desc, + $img, + $logo, + $typeContrat, + $ville, + $entreprise, + $descposte, + $profilRecherche, + $exp, + $niveauEtudes, + $mail, + $num, + $site, + $remote, + $date); + + $this->offreGw->addOffers($offre); + + return $offre; + + } + + } \ No newline at end of file diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php deleted file mode 100644 index d37c17a..0000000 --- a/php/src/modele/OffreModele.php +++ /dev/null @@ -1,145 +0,0 @@ -offreGw = new OffreGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - } - - public function publishOffer(string $img, string $logo) - { - $desc = $_POST["description"]; - $descposte = $_POST["descriptPoste"]; - $nom = $_POST["name"]; - $ville = $_POST["ville"]; - $entreprise = $_POST["entreprise"]; - $profilRecherche = $_POST["profilRecherche"]; - $mail = $_POST["mail"]; - $num = $_POST["num"]; - $site = $_POST["site"]; - $exp = $_POST["choixExp"]; - $typeContrat = $_POST["typeContrat"]; - $niveauEtudes = $_POST["education"]; - $date = new \DateTime(); - - if(isset($_POST["fullRemote"])) - { - $remote = true; - } - else $remote = false; - - // à la place de NULL passer id utilisateur créateur offre - $offre = new Offre($this->offreGw->getNewId(), - new Alumni("test.mail@icloud.fr","password","admin","prenom","nom"), - $nom, - $desc, - $img, - $logo, - $typeContrat, - $ville, - $entreprise, - $descposte, - $profilRecherche, - $exp, - $niveauEtudes, - $mail, - $num, - $site, - $remote, - $date); - - $this->offreGw->addOffers($offre); - - return $offre; - - } - public function getOffers() : array - { - $res = $this->offreGw->getOffers(); - $offers = $this->CreateOffersFromGw($res); - return $offers; - } - - - public function getOfferFromId(int $id) : ?Offre - { - $res = $this->offreGw->getOfferFromId($id); - if($res != null) - return $this->CreateOffersFromGw($res)[0]; - return null; - } - - public function CreateOffersFromGw($res) : array - { - $alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - - $offers=[]; - foreach ($res as $row) - { - $resal = $alGw->ObtenirById($row['offreur']); - $profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); - $resProfl = $profilGw->getProfilById($row['offreur']); - - $alumni = new Alumni($resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]); - - $date = \DateTime::createFromFormat('Y-m-d', $row['date']); - - $offers[]=new Offre( - $row['id'], - $alumni, - $row['titre'], - $row['description'], - $row["image"], - $row["logo"], - $row['typeContrat'], - $row['ville'], - $row["entreprise"], - $row['descriptifPoste'], - $row['profil'], - $row['experience'], - $row['niveauEtudes'], - $row['mailContact'], - $row['numero'], - $row['websiteURL'], - $row['remote'], - $date); - } - - - return $offers; - } - - public function getOfferLimit($start, $nbOffers): array - { - $res = $this->offreGw->getOfferLimit($start, $nbOffers); - return $this->CreateOffersFromGw($res); - } - - public function getNbOffers() : int - { - return $this->offreGw->getNbOffers(); - } - - - - public function getOffersWithFilters($params) : array - { - return $this->offreGw->getOffersWithFilters($params); - } - -} \ No newline at end of file diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php index accb46b..1b42de7 100755 --- a/php/src/modele/UtilisateurModele.php +++ b/php/src/modele/UtilisateurModele.php @@ -3,20 +3,25 @@ namespace App\modele; use App\gateway\Connection; use App\gateway\EvenementGateway; +use App\gateway\OffreGateway; use App\metier\Evenement; use App\metier\Alumni; use App\gateway\AlumniGateway; use App\gateway\ProfilGateway; use App\metier\Profil; +use App\metier\Offre; class UtilisateurModele { private $con; + protected $offreGw; + public function __construct() { - $this->con = new Connection(DB_HOST, DB_USER, DB_PASS); + $this->con = new Connection(DB_HOST,DB_USER,DB_PASS); + $this->offreGw = new OffreGateway($this->con); } /** @@ -31,20 +36,22 @@ class UtilisateurModele $con = new Connection(DB_HOST, DB_USER, DB_PASS); $gate = new AlumniGateway($con); - // Récupation de l'utilisateur avec l'email - $utilisateur = $gate->findByEmail($email); - if ($utilisateur[0] != null) { - // L'utilisateur existe, vérification du mot de passe - if (password_verify($mdp, $utilisateur[0]['mdp'])) { - // Le mot de passe est correct, retournez l'utilisateur - return new Alumni($utilisateur[0]['id'], $utilisateur[0]['mail'], $utilisateur[0]['mdp'], $utilisateur[0]['role'], $utilisateur[0]['nom'], $utilisateur[0]['prenom']); - } else { - return null; - } - } else { - return null; - } - } + // Récupation de l'utilisateur avec l'email + $utilisateur = $gate->findByEmail($email); + if (isset($utilisateur[0])) { + // L'utilisateur existe, vérification du mot de passe + if (password_verify($mdp, $utilisateur[0]['mdp'])) { + // Le mot de passe est correct, retournez l'utilisateur + return new Alumni($utilisateur[0]['id'],$utilisateur[0]['mail'], $utilisateur[0]['mdp'], $utilisateur[0]['role'],$utilisateur[0]['nom'],$utilisateur[0]['prenom']); + } else { + // Le mot de passe est incorrect, renvoyez null + return null; + } + } else { + // L'utilisateur n'existe pas, renvoyez null + return null; + } + } /** * @description s'inscrire @@ -90,7 +97,7 @@ class UtilisateurModele } } - public function getEvenement(): array + public function getEvenement() : array { $gate = new EvenementGateway($this->con); @@ -135,9 +142,9 @@ class UtilisateurModele $gate->deleteEvenement($id); } - public function getEvenementById(int $id): Evenement + public function getEvenementById(int $id) : Evenement { - $gate = new EvenementGateway($this->con); + $gate = new EvenementGateway($this->con); $data = $gate->findById($id); @@ -154,15 +161,16 @@ class UtilisateurModele return $evenement; } - public function getEvenementByTitre(string $titre): array + public function getEvenementByTitre(string $titre) : array { - $gate = new EvenementGateway($this->con); + $gate = new EvenementGateway($this->con); $data = $gate->findByTitle($titre); $evenement = array(); - foreach ($data as $row) { + foreach($data as $row) + { $evenement[] = new Evenement( $row['id'], $row['organisateur'], @@ -201,4 +209,85 @@ class UtilisateurModele } return null; } + + + public function getOfferFromId(int $id) : ?Offre + { + $res = $this->offreGw->getOfferFromId($id); + if($res != null) + return $this->CreateOffersFromGw($res)[0]; + return null; + } + + + + + public function CreateOffersFromGw($res) : array + { + $alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); + + $offers=[]; + foreach ($res as $row) + { + $resal = $alGw->ObtenirById($row['offreur']); + + $profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS)); + $resProfl = $profilGw->getProfilById($row['offreur']); + + + $alumni = new Alumni(intval($resal[0]['id']),$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]); + + $date = \DateTime::createFromFormat('Y-m-d', $row['date']); + + $offers[]=new Offre( + $row['id'], + $alumni, + $row['titre'], + $row['description'], + $row["image"], + $row["logo"], + $row['typeContrat'], + $row['ville'], + $row["entreprise"], + $row['descriptifPoste'], + $row['profil'], + $row['experience'], + $row['niveauEtudes'], + $row['mailContact'], + $row['numero'], + $row['websiteURL'], + $row['remote'], + $date); + } + + + return $offers; + } + + public function getOfferLimit($start, $nbOffers): array + { + $res = $this->offreGw->getOfferLimit($start, $nbOffers); + return $this->CreateOffersFromGw($res); + } + + public function getNbOffers() : int + { + return $this->offreGw->getNbOffers(); + } + + + + public function getOffersWithFilters($params) : array + { + return $this->offreGw->getOffersWithFilters($params); + } + + public function getOffers() : array + { + $res = $this->offreGw->getOffers(); + $offers = $this->CreateOffersFromGw($res); + return $offers; + } + + } \ No newline at end of file diff --git a/php/src/router/AltoRouter.php b/php/src/router/AltoRouter.php new file mode 100644 index 0000000..3f7c952 --- /dev/null +++ b/php/src/router/AltoRouter.php @@ -0,0 +1,304 @@ + + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +class AltoRouter +{ + + /** + * @var array Array of all routes (incl. named routes). + */ + protected $routes = []; + + /** + * @var array Array of all named routes. + */ + protected $namedRoutes = []; + + /** + * @var string Can be used to ignore leading part of the Request URL (if main file lives in subdirectory of host) + */ + protected $basePath = ''; + + /** + * @var array Array of default match types (regex helpers) + */ + protected $matchTypes = [ + 'i' => '[0-9]++', + 'a' => '[0-9A-Za-z]++', + 'h' => '[0-9A-Fa-f]++', + '*' => '.+?', + '**' => '.++', + '' => '[^/\.]++' + ]; + + /** + * Create router in one call from config. + * + * @param array $routes + * @param string $basePath + * @param array $matchTypes + * @throws Exception + */ + public function __construct(array $routes = [], $basePath = '', array $matchTypes = []) + { + $this->addRoutes($routes); + $this->setBasePath($basePath); + $this->addMatchTypes($matchTypes); + } + + /** + * Retrieves all routes. + * Useful if you want to process or display routes. + * @return array All routes. + */ + public function getRoutes() + { + return $this->routes; + } + + /** + * Add multiple routes at once from array in the following format: + * + * $routes = [ + * [$method, $route, $target, $name] + * ]; + * + * @param array $routes + * @return void + * @author Koen Punt + * @throws Exception + */ + public function addRoutes($routes) + { + if (!is_array($routes) && !$routes instanceof Traversable) { + throw new RuntimeException('Routes should be an array or an instance of Traversable'); + } + foreach ($routes as $route) { + call_user_func_array([$this, 'map'], $route); + } + } + + /** + * Set the base path. + * Useful if you are running your application from a subdirectory. + * @param string $basePath + */ + public function setBasePath($basePath) + { + $this->basePath = $basePath; + } + + /** + * Add named match types. It uses array_merge so keys can be overwritten. + * + * @param array $matchTypes The key is the name and the value is the regex. + */ + public function addMatchTypes(array $matchTypes) + { + $this->matchTypes = array_merge($this->matchTypes, $matchTypes); + } + + /** + * Map a route to a target + * + * @param string $method One of 5 HTTP Methods, or a pipe-separated list of multiple HTTP Methods (GET|POST|PATCH|PUT|DELETE) + * @param string $route The route regex, custom regex must start with an @. You can use multiple pre-set regex filters, like [i:id] + * @param mixed $target The target where this route should point to. Can be anything. + * @param string $name Optional name of this route. Supply if you want to reverse route this url in your application. + * @throws Exception + */ + public function map($method, $route, $target, $name = null) + { + + $this->routes[] = [$method, $route, $target, $name]; + + if ($name) { + if (isset($this->namedRoutes[$name])) { + throw new RuntimeException("Can not redeclare route '{$name}'"); + } + $this->namedRoutes[$name] = $route; + } + + return; + } + + /** + * Reversed routing + * + * Generate the URL for a named route. Replace regexes with supplied parameters + * + * @param string $routeName The name of the route. + * @param array @params Associative array of parameters to replace placeholders with. + * @return string The URL of the route with named parameters in place. + * @throws Exception + */ + public function generate($routeName, array $params = []) + { + + // Check if named route exists + if (!isset($this->namedRoutes[$routeName])) { + throw new RuntimeException("Route '{$routeName}' does not exist."); + } + + // Replace named parameters + $route = $this->namedRoutes[$routeName]; + + // prepend base path to route url again + $url = $this->basePath . $route; + + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + foreach ($matches as $index => $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if ($pre) { + $block = substr($block, 1); + } + + if (isset($params[$param])) { + // Part is found, replace for param value + $url = str_replace($block, $params[$param], $url); + } elseif ($optional && $index !== 0) { + // Only strip preceding slash if it's not at the base + $url = str_replace($pre . $block, '', $url); + } else { + // Strip match block + $url = str_replace($block, '', $url); + } + } + } + + return $url; + } + + /** + * Match a given Request Url against stored routes + * @param string $requestUrl + * @param string $requestMethod + * @return array|boolean Array with route information on success, false on failure (no match). + */ + public function match($requestUrl = null, $requestMethod = null) + { + + $params = []; + + // set Request Url if it isn't passed as parameter + if ($requestUrl === null) { + $requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/'; + } + + // strip base path from request url + $requestUrl = substr($requestUrl, strlen($this->basePath)); + + // Strip query string (?a=b) from Request Url + if (($strpos = strpos($requestUrl, '?')) !== false) { + $requestUrl = substr($requestUrl, 0, $strpos); + } + + $lastRequestUrlChar = $requestUrl ? $requestUrl[strlen($requestUrl)-1] : ''; + + // set Request Method if it isn't passed as a parameter + if ($requestMethod === null) { + $requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET'; + } + + foreach ($this->routes as $handler) { + list($methods, $route, $target, $name) = $handler; + + $method_match = (stripos($methods, $requestMethod) !== false); + + // Method did not match, continue to next route. + if (!$method_match) { + continue; + } + + if ($route === '*') { + // * wildcard (matches all) + $match = true; + } elseif (isset($route[0]) && $route[0] === '@') { + // @ regex delimiter + $pattern = '`' . substr($route, 1) . '`u'; + $match = preg_match($pattern, $requestUrl, $params) === 1; + } elseif (($position = strpos($route, '[')) === false) { + // No params in url, do string comparison + $match = strcmp($requestUrl, $route) === 0; + } else { + // Compare longest non-param string with url before moving on to regex + // Check if last character before param is a slash, because it could be optional if param is optional too (see https://github.com/dannyvankooten/AltoRouter/issues/241) + if (strncmp($requestUrl, $route, $position) !== 0 && ($lastRequestUrlChar === '/' || $route[$position-1] !== '/')) { + continue; + } + + $regex = $this->compileRoute($route); + $match = preg_match($regex, $requestUrl, $params) === 1; + } + + if ($match) { + if ($params) { + foreach ($params as $key => $value) { + if (is_numeric($key)) { + unset($params[$key]); + } + } + } + + return [ + 'target' => $target, + 'params' => $params, + 'name' => $name + ]; + } + } + + return false; + } + + /** + * Compile the regex for a given route (EXPENSIVE) + * @param $route + * @return string + */ + protected function compileRoute($route) + { + if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route, $matches, PREG_SET_ORDER)) { + $matchTypes = $this->matchTypes; + foreach ($matches as $match) { + list($block, $pre, $type, $param, $optional) = $match; + + if (isset($matchTypes[$type])) { + $type = $matchTypes[$type]; + } + if ($pre === '.') { + $pre = '\.'; + } + + $optional = $optional !== '' ? '?' : null; + + //Older versions of PCRE require the 'P' in (?P) + $pattern = '(?:' + . ($pre !== '' ? $pre : null) + . '(' + . ($param !== '' ? "?P<$param>" : null) + . $type + . ')' + . $optional + . ')' + . $optional; + + $route = str_replace($block, $pattern, $route); + } + } + return "`^$route$`u"; + } +} diff --git a/php/templates/OffersList.html b/php/templates/OffersList.html index c86f465..2cf74e8 100644 --- a/php/templates/OffersList.html +++ b/php/templates/OffersList.html @@ -5,7 +5,7 @@ Alica - Offres - +
@@ -14,13 +14,17 @@
- Publier une offre + + {% if role == 'Membre' or role == 'Admin' %} + Publier une offre + {% endif %}
+
-
+

Filtrer les offres

@@ -79,7 +83,7 @@
@@ -87,27 +91,29 @@

Offres d'emploi

+{% if msg %} +

{{ msg }}

+{% endif %}
{% for offre in offres %}
- logo + logo

{{ offre.getNom() }}

-

Julien Martin | {{ offre.getDateStringFr()}}

+

{{offre.getOffreur().Prenom()}}, {{offre.getOffreur().getNom() }} | {{ offre.getDateStringFr()}}

{{ offre.getDescription() }}

- location + location

{{offre.getVille()}}

+ onclick="window.location.href = '{{dir}}/displayOffer/{{offre.getId()}}'">En savoir plus
{% endfor %} @@ -115,19 +121,21 @@ @@ -136,8 +144,6 @@ - - diff --git a/php/templates/Offre.html b/php/templates/Offre.html deleted file mode 100644 index 7211ce4..0000000 --- a/php/templates/Offre.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Offre {{ offre.getNom() }} - - - - - \ No newline at end of file diff --git a/php/templates/OffreDetailTest.html b/php/templates/OffreDetailTest.html index e404b79..7e91b08 100644 --- a/php/templates/OffreDetailTest.html +++ b/php/templates/OffreDetailTest.html @@ -17,10 +17,10 @@
    -
  • Logo -
  • Offer Image
  • +
  • Logo +
  • Offer Image
  • -
  • Offreur: {{ offre.getOffreur().getNom() }}
  • +
  • Offreur: {{offre.getOffreur().Prenom()}} {{offre.getOffreur().getNom() }}
  • Nom de l'offre: {{ offre.getNom() }}
  • Entreprise : {{ offre.getEntreprise() }}
  • Description: {{ offre.getDescription() }}
  • diff --git a/php/templates/accueil.html b/php/templates/accueil.html index 0e83968..e947817 100755 --- a/php/templates/accueil.html +++ b/php/templates/accueil.html @@ -8,6 +8,7 @@ +
    {% include 'menu.html' %} @@ -33,8 +34,71 @@
{% endif %} +
+ +
+ +
+ {% for event in eventsList %} +
+
+ +
+
+
{{event.date}}
+
{{event.titre}}
+
{{event.description}}
+ S'inscrire +
+
+ {% endfor %} + + +
+ +
+
+ {% include 'footer.html' %} +
+ + + diff --git a/php/templates/connection.html b/php/templates/connection.html index c199201..577551e 100755 --- a/php/templates/connection.html +++ b/php/templates/connection.html @@ -4,11 +4,16 @@ Alica - Connexion - + + +{% if msg %} +

{{msg}}

+{% endif %} +
- +

Connexion

Identifiant @@ -37,9 +42,7 @@
-
- -
+ S'inscrire
{% if dVueErreur is not empty %} diff --git a/php/templates/creerEvenement.html b/php/templates/creerEvenement.html index 7b7b28d..74145cf 100644 --- a/php/templates/creerEvenement.html +++ b/php/templates/creerEvenement.html @@ -9,7 +9,7 @@

Créer un Événement

-
+
diff --git a/php/templates/creerOffre.html b/php/templates/creerOffre.html index 8a1e867..54d0710 100644 --- a/php/templates/creerOffre.html +++ b/php/templates/creerOffre.html @@ -15,7 +15,7 @@

Publier Une Offre

- + {% if tabError is defined %} {% for error in tabError %} diff --git a/php/templates/detailEvenement.html b/php/templates/detailEvenement.html index fd9e78d..5e1924c 100644 --- a/php/templates/detailEvenement.html +++ b/php/templates/detailEvenement.html @@ -22,9 +22,9 @@

Organisateur: {{ evenement.organisateurId }}

Date: {{ evenement.date }}

Description: {{ evenement.description }}

- Event Image + Event Image

Places disponibles: {{ evenement.nbPlaceMax }}

- Retour + Retour
{% else %}

L'événement n'existe pas ou n'est pas disponible.

diff --git a/php/templates/erreur.html b/php/templates/erreur.html index ea207e5..d8fd4c1 100755 --- a/php/templates/erreur.html +++ b/php/templates/erreur.html @@ -3,25 +3,23 @@ - + Alica - Erreur - - {% include "menu.html" %} +
+ {% include "menu.html" %} +
+

Erreur

{% if dVueErreur is defined %} {% for value in dVueErreur %}

{{value}}

{% endfor %} {% endif %} - +
diff --git a/php/templates/evenement.html b/php/templates/evenement.html index 8d45c2e..addb02d 100644 --- a/php/templates/evenement.html +++ b/php/templates/evenement.html @@ -5,7 +5,7 @@ Liste des Événements - + @@ -15,14 +15,14 @@
-
+

Liste des Événements

- Publier événement + Publier événement
    @@ -34,13 +34,13 @@

    Organisateur: {{ evenement.getNomOrganisateur() }}

    Date: {{ evenement.date }}

    Description: {{ evenement.description }}

    - {{ evenement.titre }} + {{ evenement.titre }}

    Places disponibles: {{ evenement.nbPlaceMax }}

    - Détails + Détails
-
+
diff --git a/php/templates/inscription.html b/php/templates/inscription.html index a22ee4b..b23c9e4 100755 --- a/php/templates/inscription.html +++ b/php/templates/inscription.html @@ -4,11 +4,11 @@ Alica - Inscription - +
-
+

S'inscrire

Prénom : @@ -18,27 +18,23 @@
-
-
-
- Nom : -
-
-
-
-
-
- Email -
-
- +
+ Nom : +
+
+ +
+
-
+
+ Email +
+
+ +
@@ -62,9 +58,7 @@
-
- -
+ Se Connecter
{% if dVueErreur is not empty %} diff --git a/php/templates/inscription_success.html b/php/templates/inscription_success.html index 3e1f2b3..d3db6a7 100644 --- a/php/templates/inscription_success.html +++ b/php/templates/inscription_success.html @@ -3,7 +3,7 @@ Success - +

Inscription effectuée avec succès, vous pouvez désormais vous connecter

@@ -15,7 +15,7 @@
diff --git a/php/templates/menu.html b/php/templates/menu.html index 3e29b53..7e48b0e 100644 --- a/php/templates/menu.html +++ b/php/templates/menu.html @@ -1,13 +1,13 @@ - +