diff --git a/config/config.php b/config/config.php index 332f3ca..aedf257 100644 --- a/config/config.php +++ b/config/config.php @@ -12,7 +12,8 @@ $base = ''; $login = ''; $mdp = ''; -$racine='/~kekentin/WF/WF-Website'; +$racine='/~marocher8/WF-Website'; + //Vues $vues['erreur'] = 'vue/erreur.php'; diff --git a/index.php b/index.php index 90a1657..a0bc58c 100644 --- a/index.php +++ b/index.php @@ -23,10 +23,12 @@ $loader = new \Twig\Loader\FilesystemLoader('vue/templates'); $twig = new \Twig\Environment($loader, [ 'cache' => false, ]); + global $racine; $twig->addGlobal('racine',$racine); // /~kekentin/WF/WF-Website + $cont = new Controleur\FrontControler($co); diff --git a/public/styles/style.css b/public/styles/style.css index 05bfef8..9276d19 100644 --- a/public/styles/style.css +++ b/public/styles/style.css @@ -82,7 +82,7 @@ body.dark-mode .nav img:hover { } body.dark-mode .search { - background: linear-gradient(to right, #4a148c, #7b1fa2); + background: white; } /* Mode clair */ @@ -92,7 +92,7 @@ body.light-mode { } body.light-mode .header { - background-color: #F7F7EB; + background-color: #F4F1DE; } body.light-mode .header img { @@ -104,63 +104,5 @@ body.light-mode .nav img:hover { } body.light-mode .search { - background: linear-gradient(180deg, rgba(187,211,249,1) 0%, rgba(199,246,196,1) 100%); -} - -/* Media queries for responsiveness */ - -/* For tablets and small devices */ -@media (max-width: 768px) { - .header { - flex-direction: column; - text-align: center; - } - - .nav, .logo, .user { - width: 100%; - margin-bottom: 10px; - } -} - -/* For mobile phones */ -@media (max-width: 480px) { - body { - margin-top: 100px; - } - - .nav img, .logo img { - width: 50px; - height: auto; - } - - .container { - padding: 10px; - } - - form { - width: 100%; - } - - form input { - width: 100%; - padding: 10px; - margin-bottom: 10px; - } -} - -/* Banner images should be responsive */ -.header img { - max-width: 100%; - height: auto; -} - -/* Media queries for different screen sizes */ -@media (max-width: 768px) { - .header { - flex-direction: column; - } - .header img { - width: 80px; - height: auto; - } + background: black; } diff --git a/public/styles/styleAccueil.css b/public/styles/styleAccueil.css index cbe8a48..2e4d384 100644 --- a/public/styles/styleAccueil.css +++ b/public/styles/styleAccueil.css @@ -18,9 +18,9 @@ h2 { margin: 0 auto; } /* Citation du jour - toujours en pleine largeur */ -.citation-du-jour { +body.dark-mode .citation-du-jour { width: 97.5%; /* Prend toute la largeur */ - background: linear-gradient(to right, #ff5722, #ff9800); /* Dégradé spécial pour la citation du jour */ + background: linear-gradient(45deg, #4a148c, #7b1fa2); padding: 0; margin-left: 1.25%; overflow: hidden; @@ -28,3 +28,12 @@ h2 { height: 150px; } +body.light-mode .citation-du-jour { + width: 97.5%; + background-image: linear-gradient(-28deg, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%); + padding: 0; + margin-left: 1.25%; + overflow: hidden; + margin-bottom: 20px; + height: 150px; +} diff --git a/public/styles/styleQuote.css b/public/styles/styleQuote.css index 3b9c192..f9d5985 100644 --- a/public/styles/styleQuote.css +++ b/public/styles/styleQuote.css @@ -2,12 +2,8 @@ /* ====== DARK MODE ====== */ body.dark-mode .card { - position: relative; + /* position: relative; */ background-color: black; - border-radius: 15px; - width: 60%; - display: flex; - margin-left: 5%; border: 2px solid transparent; } @@ -20,38 +16,34 @@ body.dark-mode .card-content { body.dark-mode .likes { - margin-left: 85%; font-size: 20px; color: #fff; } body.dark-mode .like-icon { - position: absolute; - top: 10px; - right: 10px; - font-size: 35px; color: #fff; cursor: pointer; } body.dark-mode .share-icon { - position: absolute; - top: 70px; - right: 10px; - font-size: 35px; color: #fff; cursor: pointer; } +body.dark-mode .commentaire{ + background-color: black; + border: 2px solid transparent; +} + +body.dark-mode .likeLien{ + color:white; +} + /* ====== LIGHT MODE ====== */ body.light-mode .card { - position: relative; + /* position: relative; */ background-color: white; - border-radius: 15px; - width: 60%; - display: flex; - margin-left: 5%; border: 2px solid black; } @@ -63,48 +55,169 @@ body.light-mode .card-content { body.light-mode .likes { - margin-left: 85%; font-size: 20px; color: black; } body.light-mode .like-icon { - position: absolute; - top: 10px; - right: 10px; - font-size: 35px; color: black; cursor: pointer; } body.light-mode .share-icon { - position: absolute; - top: 70px; - right: 10px; - font-size: 35px; color: black; cursor: pointer; } +body.light-mode .commentaire{ + background-color: #fff; + border: 2px solid black; +} + +body.light-mode .likeLien{ + color:black; +} + /* ====== DEFAULT ====== */ + +.central_container{ + display: flex; + justify-content: space-around; +} + +.card { + margin-top: 5vh; + border-radius: 15px; + width: 70vw; + height: 70vh; + display: flex; + flex-direction: column; +} + +.commentaire{ + margin-top: 5vh; + border-radius: 15px; + width: 25vw; + height: 70vh; + display: flex; + padding: 1%; + flex-direction: column; + flex-wrap: wrap; +} + .infoQuote { list-style: none; font-size: 25px; line-height: 40px; - margin-top: 35%; - margin-left: -45%; - margin-bottom: 20px; } .card-image { border-radius: 10px; - width: 310px; - height: 270px; + width: 20vw; + height: 35vh; + object-fit: cover; } .quote { - margin-top: 10px; + margin-top: 2vh; font-size: 35px; font-weight: bold; font-style: italic; - margin-bottom: 15px; +} + +.comAdd{ + width : 20vw; + height : 4vh; + padding-left: 1vh; + border: none; + border-radius: 20px; +} + +.btn{ + width : 2vw; + height : 4vh; + padding-left: 1vh; + border: none; + border-radius: 20px; + text-align: center; +} + +.formulaire{ + display : flex; + flex-direction: row; +} + +.comment_section{ + margin-top: 2vh; + display: flex; + flex-direction: column; + overflow-y: scroll; + height: 55vh; +} + +.com{ + background-color: #fff; + color: black; + display: flex; + flex-direction: column; + margin-top: 1vh; + margin-bottom: 1vh; + border-radius: 20px; + padding : 2%; +} + +.date{ + margin-bottom: 0.5vh; + font-size: small; +} + +.icons{ + margin: 2vh; +} + +.like-icon{ + font-size: 50px; + margin-bottom: 2vh; +} + +.share-icon{ + font-size: 50px; +} + +.part1{ + display: flex; +} + +.part2{ + display: flex; + justify-content: space-between; +} + +.likes{ + align-self: self-end; + padding: 2vh; +} + +.infoQuote{ + margin: 2vh; + height: 31vh; +} + +.userName{ + font-size: large; + display: inline-block; +} + +.infCom{ + display: flex; + justify-content: space-between; + margin-bottom: 1vh; +} + +.comAdd :focus { + outline: none; /* Supprime la bordure bleue */ + box-shadow: none; /* Supprime également toute ombre ajoutée */ +} + +.likeLien{ + text-decoration: none; } \ No newline at end of file diff --git a/public/styles/styleQuoteLittle.css b/public/styles/styleQuoteLittle.css index 1d75ed5..9dc26cd 100644 --- a/public/styles/styleQuoteLittle.css +++ b/public/styles/styleQuoteLittle.css @@ -77,13 +77,13 @@ a.link-citation { /* Mode sombre */ body.dark-mode .quote { - background: linear-gradient(to right, #4a148c, #7b1fa2); + background: linear-gradient(45deg, #4a148c, #7b1fa2); color:white; } /* Mode clair */ body.light-mode .quote { - background: linear-gradient(180deg, rgba(187,211,249,1) 0%, rgba(199,246,196,1) 100%); + background-image: linear-gradient(-28deg, #f3e7e9 0%, #e3eeff 99%, #e3eeff 100%); color:black; /* Changer le texte en noir pour le mode clair */ } diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index fa48b4c..59be5c8 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -13,13 +13,15 @@ Class FrontControler{ global $twig,$racine; $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), - 'user' => array('quiz','commentary','logout','addComment','favorite','profil'), + 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav'), 'admin' => array('null')]; $dVueEreur = []; $router = new \AltoRouter(); + $router->setBasePath($racine); ///~kekentin/WF/WF-Website + $router->map('GET', '/', 'VisitorControler','accueil'); /* @@ -43,6 +45,8 @@ Class FrontControler{ $router->map('GET|POST', '/signin', 'VisitorControler','signin'); $router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin'); $router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin'); + $router->map('GET|POST', '/addFav/[i:id]', 'UserControler','addFav'); + $router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav'); $match = $router->match(); diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 36db5e4..6e8f688 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -194,4 +194,19 @@ class UserControler { $mdl = new QuizModel($gw); return $mdl->getQuiz($id)->getNbQuestions(); } + + public function addFav(array $arg){ + global $racine; + $id= $arg['id'] ?? 1; + $this->uMod->addFavorite($_SESSION["user"],$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:". $racine ."/quote/$id"); + } } diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index 5273afe..ccbc7f3 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -24,7 +24,7 @@ Class VisitorControler { private UserGateway $gw; - private UserModel $mdl; + private UserModel $uMod; private array $errors; @@ -38,8 +38,7 @@ Class VisitorControler { $this->qMod = new QuoteModel(new QuoteGateway($co)); $this->cMod = new CommentaryModel(new CommentaryGateway($co)); $this->sMod = new SearchModel(new QuoteGateway($co)); - $this->gw = new UserGateway($co); - $this->mdl = new UserModel($this->gw); + $this->uMod = new UserModel(new UserGateway($co)); } public function accueil(){ @@ -56,6 +55,7 @@ Class VisitorControler { public function quote(array $arg){ global $vues; $id= $arg['idQuote'] ?? 1; + $f = $this->uMod->isFavorite($_SESSION["user"],$id); $q = $this->qMod->searchId($id); $c = $this->cMod->getComment($id); require_once $vues['quote']; @@ -119,7 +119,7 @@ Class VisitorControler { $pseudo = $_POST['pseudo'] ?? null; $mdp = $_POST['mdp'] ?? null; - $user = $this -> mdl -> getUsername($pseudo); + $user = $this -> uMod -> getUsername($pseudo); if ($user) { @@ -171,8 +171,8 @@ Class VisitorControler { $option = ['cost' => 12]; $hmdp = password_hash($mdp, PASSWORD_BCRYPT, $option); - $isUserAlreadyUsed = $this -> mdl -> getUsername($pseudo); - $isEmailAlreadyUsed = $this -> mdl -> getEmail($email); + $isUserAlreadyUsed = $this -> uMod -> getUsername($pseudo); + $isEmailAlreadyUsed = $this -> uMod -> getEmail($email); if ($isUserAlreadyUsed and !$isEmailAlreadyUsed) { $errors[0] = "Pseudo déjà utilisé"; @@ -190,7 +190,7 @@ Class VisitorControler { require_once $vues['signin']; exit(); } - else echo $this->mdl->insertUser($pseudo, $email, $hmdp); + else echo $this->uMod->insertUser($pseudo, $email, $hmdp); $_SESSION["role"] = 'user'; $_SESSION["user"] = $pseudo; diff --git a/src/Entity/CommentaryEntity.php b/src/Entity/CommentaryEntity.php index eec3c18..eb8eb8f 100644 --- a/src/Entity/CommentaryEntity.php +++ b/src/Entity/CommentaryEntity.php @@ -13,11 +13,12 @@ class CommentaryEntity { * @param string $comment * @param string $date */ - public function __construct(int $id_comment, string $comment, string $date) + public function __construct(int $id_comment, string $comment, string $date, string $user) { $this->id_comment = $id_comment; $this->comment = $comment; $this->date = $date; + $this->user = $user; } /** diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php index e6362b2..a211518 100644 --- a/src/Gateway/UserGateway.php +++ b/src/Gateway/UserGateway.php @@ -137,5 +137,30 @@ Class UserGateway extends Gateway{ return $result; } + public function inFavorite(string $username, int $idq):bool{ + $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 ($result[0]['count'] >= 1); + } + + public function addFavorite(string $username, int $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 = '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/Model/UserModel.php b/src/Model/UserModel.php index 40b6eca..a976f56 100644 --- a/src/Model/UserModel.php +++ b/src/Model/UserModel.php @@ -108,6 +108,24 @@ $res = $this->gateway->getIdUser($username); return $res[0]['id_user']; } + + public function isFavorite(string $username, int $idq): bool { + if($_SESSION["user"] == null){ + return false; + } + else{ + $res = $this->gateway->inFavorite($_SESSION["user"],$idq); + return $res; + } + } + + public function addFavorite(string $username, int $id){ + $this->gateway->addFavorite($username,$id); + } + + public function supFavorite(string $username, int $id){ + $this->gateway->supFavorite($username,$id); + } } ?> 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 diff --git a/vue/templates/login.html b/vue/templates/login.html deleted file mode 100644 index 361f604..0000000 --- a/vue/templates/login.html +++ /dev/null @@ -1,37 +0,0 @@ - -
-