diff --git a/config/config.php b/config/config.php index 87e7c39..51313b4 100644 --- a/config/config.php +++ b/config/config.php @@ -12,6 +12,8 @@ $base = ''; $login = ''; $mdp = ''; +$racine='/~kemondejar/WF-Website'; + //Vues $vues['erreur'] = 'vue/erreur.php'; $vues['accueil'] = 'vue/accueil.php'; diff --git a/index.php b/index.php index 20ae47d..a0bc58c 100644 --- a/index.php +++ b/index.php @@ -24,7 +24,9 @@ $twig = new \Twig\Environment($loader, [ 'cache' => false, ]); -$twig->addGlobal('racine','/~kemondejar/WF-Website'); // /~kekentin/WF/WF-Website +global $racine; +$twig->addGlobal('racine',$racine); // /~kekentin/WF/WF-Website + $cont = new Controleur\FrontControler($co); diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index 1c9b8a9..59be5c8 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -10,16 +10,17 @@ Class FrontControler{ private Connection $co; public function __construct($co){ - global $twig; + global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','/supFav'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav'), 'admin' => array('null')]; $dVueEreur = []; $router = new \AltoRouter(); - $router->setBasePath('/~kemondejar/WF-Website'); ///~kekentin/WF/WF-Website + + $router->setBasePath($racine); ///~kekentin/WF/WF-Website $router->map('GET', '/', 'VisitorControler','accueil'); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index ca4a3fe..6e8f688 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -47,9 +47,10 @@ class UserControler { public function addComment(){ + global $racine; $id = $_POST['idQuote']; $this->cMod->createComment($_POST['content'],$_POST['idQuote'],$this->uMod->getIdByUsername($_SESSION['user'])); - header("Location: /~lebeaulato/WF-Website/quote/$id"); + header("Location:".$racine."/quote/$id"); } @@ -64,10 +65,11 @@ class UserControler { } public function unlog(){ + global $racine; session_unset(); session_destroy(); $_SESSION = array(); - header("Location: /~lebeaulato/WF-Website/"); + header("Location:".$racine); } public function quiz(array $args){ @@ -103,13 +105,14 @@ class UserControler { */ public function continueQuiz(int $id_quiz, int $total_questions) : void { + global $racine; $score = $_SESSION['score']; $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1; if ($_SESSION['no_question'] >= $total_questions) { session_destroy(); $this->endQuiz($id_quiz, $score); } - else header("Location: /~lebeaulato/WF-Website/quiz/$id_quiz"); ///~kekentin/WF/WF-Website + else header("Location: ".$racine."/quiz/$id_quiz"); ///~kekentin/WF/WF-Website } @@ -193,15 +196,17 @@ class UserControler { } public function addFav(array $arg){ + global $racine; $id= $arg['id'] ?? 1; $this->uMod->addFavorite($_SESSION["user"],$id); - header("Location: /~lebeaulato/WF-Website/quote/$id"); + header("Location:" . $racine . "/quote/$id"); } public function supFav(array $arg){ + global $racine; $id= $arg['id'] ?? 1; $this->uMod->supFavorite($_SESSION["user"],$id); - header("Location: /~lebeaulato/WF-Website/quote/$id"); + header("Location:". $racine ."/quote/$id"); } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 1167483..a3f8350 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -13,6 +13,7 @@ use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Error\SyntaxError; + Class VisitorControler { private QuoteModel $qMod; @@ -68,7 +69,7 @@ Class VisitorControler { global $vues; $type = ($_POST['type'] ?? ""); - $search = ($_POST['search'] ?? NULL); + $search = ( $_POST['search'] ?? NULL); $filtre = ($arg['filtre'] ?? []); @@ -111,7 +112,7 @@ Class VisitorControler { public function validlogin() : void { - global $vues; + global $vues,$racine; if ($_POST) { $pseudo = $_POST['pseudo'] ?? null; @@ -125,7 +126,7 @@ Class VisitorControler { { $_SESSION['user'] = $pseudo; $_SESSION['role'] = 'user'; - header("Location: /~lebeaulato/WF-Website/"); ///~kekentin/WF/WF-Website/ + header("Location: ". $racine); ///~kekentin/WF/WF-Website/ exit(); }else { @@ -152,7 +153,7 @@ Class VisitorControler { */ public function validsignin() : void { - global $vues; + global $vues,$racine; if ($_POST) { $pseudo = $_POST['pseudo'] ?? null; @@ -193,7 +194,7 @@ Class VisitorControler { $_SESSION["role"] = 'user'; $_SESSION["user"] = $pseudo; - header("Location: /~kekentin/WF/WF-Website/profil"); + header("Location: ". $racine); } } } \ No newline at end of file diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index fe31192..a211518 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -141,17 +141,26 @@ Class UserGateway extends Gateway{ $query = 'SELECT count(*) FROM Favorite f JOIN Users u ON f.users = u.id_user WHERE u.username = :user AND f.quote = :id'; $this->co->executeQuery($query, array(':user'=>array($username, PDO::PARAM_STR),':id'=>array($idq, PDO::PARAM_INT))); $result = $this->co->getResults(); - return !isset($result); + return ($result[0]['count'] >= 1); } public function addFavorite(string $username, int $id){ - $query = 'INSERT INTO Favortie VALUE ((SELECT id_user FROM User WHERE Username = :username), :id)'; + $query = 'INSERT INTO Favorite VALUES ((SELECT id_user FROM Users WHERE username = :username), :id)'; $this->co->executeQuery($query, array(':username' => array($username,PDO::PARAM_STR), ':id' => array($id,PDO::PARAM_INT))); + $query = 'UPDATE Quote SET likes = (likes + 1) WHERE id_quote = :id'; + $this->co->executeQuery($query, array(':id' => array($id,PDO::PARAM_INT))); } public function supFavorite(string $username, int $id){ - $query = 'DELETE FROM Favortie VALUE WHERE quote = :id ,user = (SELECT id_user FROM User WHERE Username = :username)'; - $this->co->executeQuery($query, array(':username' => array($username,PDO::PARAM_STR), ':id' => array($id,PDO::PARAM_INT))); + $query = 'SELECT id_user FROM Users WHERE username = :username'; + $this->co->executeQuery($query, array(':username' => array($username,PDO::PARAM_STR))); + $result = $this->co->getResults()[0]['id_user']; + var_dump($result); + var_dump($id); + $query = 'DELETE FROM Favorite WHERE users = :user AND quote = :id;'; + $this->co->executeQuery($query, array(':user' => array($result,PDO::PARAM_INT), ':id' => array($id,PDO::PARAM_INT))); + $query = 'UPDATE Quote SET likes = (likes - 1) WHERE id_quote = :id'; + $this->co->executeQuery($query, array(':id' => array($id,PDO::PARAM_INT))); } } ?> diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php new file mode 100644 index 0000000..a607afa --- /dev/null +++ b/src/Verification/Verification.php @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/vue/quote.php b/vue/quote.php index dd3b59e..30ec5be 100644 --- a/vue/quote.php +++ b/vue/quote.php @@ -16,5 +16,6 @@ 'dateSortie' => $q->getDateSrc(), 'nbLike' => $q->getLike(), 'idQuote' => $q->getId(), - 'com' => $c,)); + 'com' => $c, + 'fav' => $f)); ?> \ No newline at end of file