diff --git a/config/config.php b/config/config.php
index 4fba116..6124e81 100644
--- a/config/config.php
+++ b/config/config.php
@@ -12,8 +12,11 @@ $base = '';
$login = '';
$mdp = '';
-//$racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website
-$racine='/WF-Website';
+$racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website
+//$racine='/WF-Website';
+$repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/';
+//$repImg='/';
+
//Vues
@@ -29,9 +32,11 @@ $vues['create'] = 'vue/create.php';
$vues['quiz'] = 'vue/quiz.php';
$vues['endQuiz'] = 'vue/endQuiz.php';
$vues['submitQuote'] = 'vue/submitQuote.php';
+$vues['recap'] = 'vue/recap.php';
$vues['accueilQuiz'] = 'vue/accueilQuiz.php';
+
//Style css
$style['accueil'] = 'public/styles/styleAccueil.css';
diff --git a/public/images/Baneer.png b/public/images/Baneer.png
new file mode 100644
index 0000000..9c60579
Binary files /dev/null and b/public/images/Baneer.png differ
diff --git a/public/script/changeData.js b/public/script/changeData.js
index c9a3583..187346d 100644
--- a/public/script/changeData.js
+++ b/public/script/changeData.js
@@ -114,4 +114,44 @@ function editFieldPassWd(id) {
pElement.appendChild(saveButton);
inputNewPass.focus();// Mettre le focus sur le premier champ de saisie
+}
+function editFieldImage(id,path) {
+ var pElement = document.getElementById('imagePost');
+
+ var inputImage = document.createElement('input');
+ inputImage.type = 'hidden';
+ inputImage.name='image';
+ inputImage.value=id;
+
+
+ var buttonSubmit = document.createElement('button');
+ buttonSubmit.textContent = 'Valider';
+ buttonSubmit.classList.add('saveButtonPasswd');
+ buttonSubmit.type ="submit";
+
+ pElement.innerHTML = '';
+ pElement.appendChild(inputImage);
+ pElement.appendChild(buttonSubmit);
+
+ inputImage.focus(); // Mettre le focus sur le champ de saisie
+
+ ///////////////////////////////////////////////
+
+ var pEle = document.getElementById('image');
+
+ var image = document.createElement('img');
+ image.src=path;
+ image.classList.add('imageProfil');
+
+ var popover = document.getElementById("list-ChangeImg");
+ popover.hidePopover();
+
+ var button = document.createElement('button');
+ button.popoverTargetElement= popover;
+ button.name="image";
+ button.classList.add('ChangeImg');
+ button.appendChild(image);
+
+ pEle.innerHTML = '';
+ pEle.appendChild(button);
}
\ No newline at end of file
diff --git a/public/styles/styleProfil.css b/public/styles/styleProfil.css
index abca93f..b459c22 100644
--- a/public/styles/styleProfil.css
+++ b/public/styles/styleProfil.css
@@ -9,6 +9,10 @@ body.dark-mode p{
color : var(--main-dark-text-color);
}
+body.dark-mode :popover-open {
+ background: var(--main-dark-gradient);
+ color: var(--main-dark-text-color);
+}
body.dark-mode .buttonSudmite{
background: var(--main-dark-gradient);
@@ -49,6 +53,11 @@ body.light-mode p{
}
+body.light-mode :popover-open {
+ background: var(--main-light-gradient);
+ color: var(--main-light-text-color);
+}
+
body.light-mode .buttonSubmit{
background: var(--main-light-gradirent);
color: var(--main-light-text-color);
@@ -91,6 +100,17 @@ p{
font-family: "Lemon", serif;
}
+::backdrop {
+ backdrop-filter: blur(3px);
+}
+:popover-open {
+ width: 70%;
+ height: 60%;
+ font-size: 15px;
+ text-align: center;
+ font-family: "Lemon", serif;
+
+}
.buttonSudmite{
font-family: "Lemon", serif;
diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php
index 64a058a..ad40e9e 100644
--- a/src/Controleur/FrontControler.php
+++ b/src/Controleur/FrontControler.php
@@ -52,7 +52,7 @@ Class FrontControler{
$router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav');
$router->map('GET|POST', '/changedata', 'UserControler','changedata');
$router->map('GET|POST', '/submit', 'UserControler', 'submit');
- $router->map('GET|POST', '/validsubmit', 'UserControler', 'validsubmit');
+ $router->map('GET|POST', '/validsubmit', 'UserControler','validsubmit');
$router->map('GET|POST', '/add', 'UserControler', 'add');
$router->map('GET|POST', '/accueilQuiz', 'UserControler', 'accueilQuiz');
diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php
index a1c7e3f..34c093c 100644
--- a/src/Controleur/UserControler.php
+++ b/src/Controleur/UserControler.php
@@ -21,25 +21,30 @@ use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Verification\Verification;
use Enum\TypeSourceEnum;
+use Model\ImageModel;
+use Gateway\ImageGateway;
class UserControler {
private CommentaryModel $cMod;
private UserModel $uMod;
private QuoteModel $qMod;
- private QuestionModel $mdl;
private CharacterModel $caMod;
private SourceModel $srcMod;
+ private QuestionModel $questMod;
+ private ImageModel $iMod;
private QuizModel $quizModel;
+
public function __construct() {
global $co;
$this->cMod = new CommentaryModel(new CommentaryGateway($co));
$this->uMod = new UserModel(new UserGateway($co));
$this->qMod = new QuoteModel(new QuoteGateway($co));
- $this -> mdl = new QuestionModel(new QuestionGateway($co));
+ $this -> questMod = new QuestionModel(new QuestionGateway($co));
$this -> caMod = new CharacterModel(new CharacterGateway($co));
$this->srcMod = new SourceModel(new SourceGateway($co));
+ $this->iMod = new ImageModel(new ImageGateway($co));
$this->quizModel = new QuizModel(new QuizGateway($co));
}
@@ -53,6 +58,7 @@ class UserControler {
global $vues;
$p = $this->uMod->getUsername($_SESSION["user"]);
+ $listImg = $this->iMod->getAllImg() ;
// Pour les messages d'erreur
$error_message = null;
@@ -125,8 +131,7 @@ class UserControler {
* @throws RuntimeError
* @throws LoaderError
*/
- public function continueQuiz(int $id_quiz, int $total_questions) : void
- {
+ public function continueQuiz(int $id_quiz, int $total_questions) : void{
global $racine;
$score = $_SESSION['score'];
$_SESSION['no_question'] = Verification::verifChar( isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1);
@@ -144,8 +149,7 @@ class UserControler {
* @throws RuntimeError
* @throws LoaderError
*/
- public function endQuiz(int $id_quiz, int $score) : void
- {
+ public function endQuiz(int $id_quiz, int $score) : void{
global $vues,$co;
$gw = new QuizGateway($co);
@@ -159,8 +163,7 @@ class UserControler {
require_once $vues['endQuiz'];
}
- public function CorrectAnswer() : bool
- {
+ public function CorrectAnswer() : bool{
$answera = Verification::verifChar($_POST['answera'] ?? null);
$answerb = Verification::verifChar($_POST['answerb'] ?? null);
$answerc = Verification::verifChar($_POST['answerc'] ?? null);
@@ -182,12 +185,11 @@ class UserControler {
$answer = explode('-', $answerd)[0];
$id = (int) explode('-', $answerd)[1];
}
- $res = $this->mdl->getQuestion($id);
+ $res = $this->questMod->getQuestion($id);
return $answer == $res->getCanswer();
}
- public function GetQuestion(int $id): array
- {
+ public function GetQuestion(int $id): array{
global $co;
$gw = new QuizQuestionGateway($co);
$mdl = new QuizQuestionModel($gw);
@@ -199,8 +201,7 @@ class UserControler {
* @throws SyntaxError
* @throws LoaderError
*/
- public function showQuestion(int $id, int $num) : void
- {
+ public function showQuestion(int $id, int $num) : void{
global $vues,$twig;
$q = $this->GetQuestion($id);
$question = $q[$num] ?? $q[0];
@@ -220,8 +221,7 @@ class UserControler {
}
- public function getNumberOfQuestion(int $id) : int
- {
+ public function getNumberOfQuestion(int $id) : int{
global $co;
$gw = new QuizGateway($co);
$mdl = new QuizModel($gw);
@@ -244,8 +244,8 @@ class UserControler {
}
- // ===================== UPDATE DATA USER FUNCTION =====================
+ // ===================== UPDATE DATA USER FUNCTION =====================
public function changedata() : void{
global $vues, $racine;
if ($_POST)
@@ -263,12 +263,13 @@ class UserControler {
}
else if($newEmail){//Modif l'email
$this->updateEmail($newEmail);
+ $this->sendEmailChangeLogin($newEmail); //Envoie un email confirmant le changement d'email
}
else if($newMdpFirst && $newMdpSecond){ //Modif le mot de passe
$this->updatePassWd($oldPasswd, $newMdpFirst,$newMdpSecond);
}
else if($newImage){//Modif l'image
- $this->updateImg();
+ $this->updateImg($newImage);
}
}
header("Location: ". $racine."/profil");
@@ -325,8 +326,8 @@ class UserControler {
}
}
- public function updateImg(){
- $user = $this->uMod->setImage($_SESSION['user']);
+ public function updateImg(string $newImage){
+ $user = $this->uMod->setImage($_SESSION['user'],$newImage);
}
@@ -340,8 +341,7 @@ class UserControler {
* @throws RuntimeError
* @throws LoaderError
*/
- public function submit() : void
- {
+ public function submit() : void{
global $vues;
$p = $this->caMod->getAllPerso();
$s = $this->srcMod->getAllSources();
@@ -353,47 +353,24 @@ class UserControler {
* @throws RuntimeError
* @throws LoaderError
*/
- public function toSubmit() : ?array
+
+ public function toSubmit(string $content,string $character, string $source)
{
global $co;
if ($_POST)
{
- $content = $_POST['content'] ?? null;
- $character = $_POST['character'] ?? null;
- $source = $_POST['src'] ?? null;
- //$img = $_POST['img'] ?? null;
-
$errors = [null, null];
- $gw = new CharacterGateway($co);
- $mdl = new CharacterModel($gw);
-
- $character = $mdl -> getCharacterById($character);
-
- $gw = new SourceGateway($co);
- $mdl = new SourceModel($gw);
-
- $source = $mdl -> getSourceById($source);
+ $nameSrc = $this->srcMod->getSourceById($source)->getTitle();
+ $nameChar = $this->caMod->getCharacterById($character)->getName();
if (!$character)
$errors[0] = "Personnage inexistant";
if (!$source)
$errors[1] = "Source inexistante";
- if ($errors[0] || $errors[1])
- {
- global $twig;
- $this->submit();
- exit();
- }
-
- $gw = new QuoteGateway($co);
- $mdl = new QuoteModel($gw);
-
- //$mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter());
-
- return [$content, $_POST['character'], $_POST['src']];
+ $this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user'])));
+ $this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar));
}
- return null;
}
/**
@@ -407,6 +384,8 @@ class UserControler {
global $vues;
$src = true;
$char = true;
+ $srcId = null;
+ $charId = null;
require_once $vues['create'];
exit();
}
@@ -414,6 +393,8 @@ class UserControler {
global $vues;
$src = true;
$char = false;
+ $srcId = null;
+ $charId = $_POST['character'];
require_once $vues['create'];
exit();
}
@@ -421,32 +402,23 @@ class UserControler {
global $vues;
$src = false;
$char = true;
+ $srcId = $_POST['src'];
+ $charId = null;
require_once $vues['create'];
exit();
}
- if($_POST)
- $recap = $this -> toSubmit();
- if ($recap)
- {
- $this -> recapSubmitQuote($recap);
- }
+ $recap = $this -> toSubmit($_POST['content'],$_POST['character'],$_POST['src']);
+ }
+
+ public function recapSubmitQuote(array $recap){
+ global $vues;
+ require_once($vues["recap"]);
}
// ===================== SUBMIT QUOTE FUNCTION =====================
- /**
- * @throws RuntimeError
- * @throws SyntaxError
- * @throws LoaderError
- */
- public function recapSubmitQuote(?array $recap) : void
- {
- global $twig;
- echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]);
- }
-
public function getIdOfUser() : ?int
{
if (isset($_SESSION['user']))
@@ -461,17 +433,18 @@ class UserControler {
}
public function add(){
- global $vues;
- var_dump($_POST);
+ global $vues, $repImg;
$error = [];
+ $src = false;
+ $char = false;
+ var_dump($_FILES);
if($_POST['req'] == "both"){
$src = true;
$char = true;
}
- elseif($_POST['req'] == "src"){
- $src = true;
- $char = false;
- $type = array("Movie","Serie","VideoGame","Anime");
+
+ if($_POST['req'] == "src" or $src == true){
+ $type = array("movie","serie","video-game","anime");
if(Verification::verifNotNull($_POST["titre"])){
$_POST["titre"] = Verification::verifChar($_POST["titre"]);
if($this->srcMod->existSource($_POST["titre"],$_POST["type"])){
@@ -482,8 +455,6 @@ class UserControler {
$error[] = "Le titre doit être définit";
}
if(Verification::verifNotNull($_POST["date"])){
- $src = true;
- $char = false;
$_POST["date"] = Verification::verifChar($_POST["date"]);
if(intval($_POST["date"],10) < 1850 or intval($_POST["date"],10) > date( "Y", time() )){
$error[] = "La date est invalide";
@@ -502,27 +473,100 @@ class UserControler {
$error[] = "Le type doit être définit";
}
}
- elseif($_POST['req'] == "char"){
- $src = false;
- $char = true;
- if(Verification::verifNotNull($_POST[""])){
+
+ if($_POST['req'] == "char" or $char == true){
+ if(Verification::verifNotNull($_POST["name"])){
+ $_POST["name"] = Verification::verifChar($_POST["name"]);
+ }
+ else{
+ $error[] = "Le nom doit être définit";
+ }
+ // upload de la photo
+ if (isset($_FILES['avatar'])) {
+
+ $tabExtension = explode('.', $_FILES['avatar']['name']);
+ $extension = strtolower(end($tabExtension));
+ $extensions = ['jpg', 'png', 'jpeg'];
+ if(in_array($extension, $extensions)){
+ move_uploaded_file($_FILES['avatar']['tmp_name'], $repImg.$_FILES['avatar']['name']);
+ $filePath = $repImg.$_FILES['avatar']['name'];
+ }
+ else{
+ $error[] = "Mauvaise extension";
+ exit();
+ }
+ }
+ else{
+ $error[] = "Aucune photo";
}
+
}
+
if($error == []){
+ $recap['content'] = $_POST['content'];
if($_POST['req'] == "both"){
-
+ $this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
+ $idImg = $this->iMod->createImgModelWithoutId($filePath);
+ $this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
+ $idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
+ $idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
}
elseif($_POST['req'] == "src"){
- $this->srcMod->createSource($_POST["titre"], $_POST["date"], $_POST["type"]);
+ $this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_POST["type"]));
+ $idC = Verification::VerifChar($_POST["character"]);
+ $idS = $this -> srcMod -> getSourceByTitle($_POST["titre"])->getIdSource();
}
elseif($_POST['req'] == "char"){
-
+ $idImg = $this->iMod->createImgModelWithoutId($filePath);
+ $this->caMod->createCharacterWithoutId($_POST["name"], $idImg);
+ $idC = $this-> caMod -> getCharacterByName($_POST["name"])->getIdCharacter();
+ $idS = Verification::VerifChar($_POST["src"]);
}
+ $this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS);
}
else{
require_once($vues["create"]);
var_dump($error);
}
}
+
+ // Quiz aléatoire
+
+ // argument = Langue / type question / type reponse
+ public function quizAleatoire(){
+ global $vues;
+ if(!isset($_POST["nbVie"])){
+ $vie = 3;
+ }
+ $question = $questMod->getRandomQuestion([$_POST["questionType"],$_POST["awnserType"]],$_POST["langue"]);
+ addTab($question);
+ if($question == null){
+ $require_once($vues["erreur"]);
+ }
+ else{
+ $require_once($vues['quiz']);
+ }
+ }
+
+ public function questionSuivantAleatoire(){
+
+ }
+
+ public function sendEmailChangeLogin(string $email) : void{
+ $to = $email; // Adresse email de destination
+ $subject = "What The Fantasy - Changement d'Email"; // Sujet de l'email
+ $message = "
+ Bonjour,
+
+ L'adresse mail $email est désormais votre nouvelle adresse.
+
+
+ L'équipe du site
+ "; // Contenu de l'email
+ $headers = "From: noreply@whatTheFantasy.com"; // Adresse email de l'expéditeur
+
+ // Envoyer l'email
+ mail($to, $subject, $message, $headers);
+ }
}
diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php
index 99589af..523c3c5 100644
--- a/src/Controleur/VisitorControler.php
+++ b/src/Controleur/VisitorControler.php
@@ -117,6 +117,7 @@ Class VisitorControler {
public function validlogin() : void
{
+
global $vues,$racine;
if ($_POST)
{
@@ -160,6 +161,7 @@ Class VisitorControler {
{
global $vues,$racine;
+
if ($_POST) {
$pseudo = Verification::verifChar($_POST['pseudo'] ?? null);
$email = Verification::verifChar($_POST['email'] ?? null);
@@ -196,10 +198,68 @@ Class VisitorControler {
}
else echo $this->uMod->insertUser($pseudo, $email, $hmdp);
+ $this->sendEmailSubmit($email, $pseudo);
+
+
$_SESSION["role"] = Verification::verifChar('user');
$_SESSION["user"] = Verification::verifChar($pseudo);
header("Location: ". $racine);
}
}
+
+
+ function sendEmailSubmit(string $email, string $pseudo) {
+ // Génère les données du message
+ $sujet = "What The Fantasy - Création de compte";
+ $urlImage = "public/images/Baneer.png";
+
+
+ // Génère une frontière unique pour l'email
+ $boundary = "-----=" . md5(uniqid(mt_rand()));
+
+ //Instancie les headers
+ $headers = "From: noreply@whatTheFantasy.com\r\n";
+ $headers .= "MIME-Version: 1.0\r\n";
+ $headers .= "Content-Type: multipart/related; boundary=\"$boundary\"\r\n";
+
+
+ // Corps de l'email HTML avec l'image intégrée
+ $corpsMessage = "--$boundary\r\n";
+ $corpsMessage .= "Content-Type: text/html; charset=UTF-8\r\n";
+ $corpsMessage .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
+
+ // Ajoute le message HTML
+ $corpsMessage .= "
+
+
+ Bonjour $pseudo,
+
+ Merci de vous être inscrit sur notre site What The Fantasy. C’est avec grande joie que nous vous accueillons au sein de notre confrérie, pour découvrir ensemble...
+
+ À bientôt !
+ L'équipe du site
+
+ \r\n";
+
+ // Ajoute l'image en pièce jointe avec un CID
+ $corpsMessage .= "--$boundary\r\n";
+ $corpsMessage .= "Content-Type: image/jpeg; name=\"image.jpg\"\r\n";
+ $corpsMessage .= "Content-Transfer-Encoding: base64\r\n";
+ $corpsMessage .= "Content-ID: \r\n\r\n";
+
+
+ $imageContent = file_get_contents($urlImage);// Lecture et encodage de l'image en base64
+ if ($imageContent === false) {
+ return "Impossible de charger l'image spécifiée.";
+ }
+ $corpsMessage .= chunk_split(base64_encode($imageContent)) . "\r\n";
+
+
+ $corpsMessage .= "--$boundary--";// Fin du corps de l'email
+
+
+ mail($email, $sujet, $corpsMessage, $headers);// Envoi de l'email
+
+ }
}
\ No newline at end of file
diff --git a/src/Entity/CharacterEntity.php b/src/Entity/CharacterEntity.php
index e64ee67..e43cafe 100644
--- a/src/Entity/CharacterEntity.php
+++ b/src/Entity/CharacterEntity.php
@@ -70,8 +70,5 @@ class CharacterEntity
$this->img_path = $img_path;
}
-
-
-
}
diff --git a/src/Entity/ImageEntity.php b/src/Entity/ImageEntity.php
index 8bdf70a..1b9ea56 100644
--- a/src/Entity/ImageEntity.php
+++ b/src/Entity/ImageEntity.php
@@ -5,18 +5,16 @@ class ImageEntity
{
private int $idImg;
private string $imgPath;
- private string $isImgProfile;
/**
* @param int $idImg
* @param string $imgPath
* @param string $isImgProfile
*/
- public function __construct(int $idImg, string $imgPath, string $isImgProfile)
+ public function __construct(int $idImg, string $imgPath)
{
$this->idImg = $idImg;
$this->imgPath = $imgPath;
- $this->isImgProfile = $isImgProfile;
}
public function getIdImg(): int
@@ -39,15 +37,5 @@ class ImageEntity
$this->imgPath = $imgPath;
}
- public function getIsImgProfile(): string
- {
- return $this->isImgProfile;
- }
-
- public function setIsImgProfile(string $isImgProfile): void
- {
- $this->isImgProfile = $isImgProfile;
- }
-
}
diff --git a/src/Entity/quizEntity.php b/src/Entity/QuizEntity.php
similarity index 100%
rename from src/Entity/quizEntity.php
rename to src/Entity/QuizEntity.php
diff --git a/src/Enum/TypeSourceEnum.php b/src/Enum/TypeSourceEnum.php
index 4a20ac1..b971c05 100644
--- a/src/Enum/TypeSourceEnum.php
+++ b/src/Enum/TypeSourceEnum.php
@@ -6,4 +6,14 @@ enum TypeSourceEnum : string {
case VideoGame = 'video-game';
case Anime = 'anime';
case Serie = 'serie';
+
+ public static function fromName(string $name): string
+ {
+ foreach (self::cases() as $status) {
+ if( $name === $status->name ){
+ return $status->value;
+ }
+ }
+ throw new \ValueError("$name is not a valid backing value for enum " . self::class );
+ }
}
\ No newline at end of file
diff --git a/src/Gateway/CharacterGateway.php b/src/Gateway/CharacterGateway.php
index 9d4c1b7..0f7b2ef 100644
--- a/src/Gateway/CharacterGateway.php
+++ b/src/Gateway/CharacterGateway.php
@@ -18,7 +18,7 @@ class CharacterGateway extends Gateway
return $this -> co -> executeQuery($query, [
'id_caracter' => array($id_character, PDO::PARAM_INT),
'caracter' => array($name, PDO::PARAM_STR),
- 'id_img' => array($img_char, PDO::PARAM_STR)
+ 'id_img' => array($img_char, PDO::PARAM_INT)
]);
}
@@ -61,8 +61,24 @@ class CharacterGateway extends Gateway
return $this -> co -> executeQuery($query, [
"id_c" => array($id_char, PDO::PARAM_INT),
"caracter" => array($name, PDO::PARAM_STR),
- "i" => array($img_char, PDO::PARAM_STR)
+ "i" => array($img_char, PDO::PARAM_INT)
]);
}
+ public function getLastId():int{
+ $query = "SELECT id_caracter FROM Caracter;";
+ $this -> co -> executeQuery($query);
+ $res = $this -> co -> getResults();
+ foreach($res as $r){
+ $tab[] = $r["id_caracter"];
+ }
+ $id = 1;
+ while(in_array($id,$tab))
+ {
+ $id=$id+1;
+ }
+ return $id;
+ }
+
+
}
\ No newline at end of file
diff --git a/src/Gateway/ImageGateway.php b/src/Gateway/ImageGateway.php
index e05609a..4e6d0af 100644
--- a/src/Gateway/ImageGateway.php
+++ b/src/Gateway/ImageGateway.php
@@ -6,25 +6,24 @@ use PDO;
class ImageGateway extends Gateway
{
- public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool
+ public function createImgGateway(int $idImg, string $imgPath) : bool
{
$query = "
- INSERT INTO Images
- VALUES (:id_img, :img_path, :is_img_profile)
+ INSERT INTO Image
+ VALUES (:id_img, :img_path)
";
return $this -> co -> executeQuery($query, [
'id_img' => array($idImg, PDO::PARAM_INT),
'img_path' => array($imgPath, PDO::PARAM_STR),
- 'is_img_profile' => array($isImgProfile, PDO::PARAM_BOOL),
]);
}
public function findImgById(int $idImg) : array
{
$query = "
- SELECT * FROM Images
- WHERE id_image = :id_img
+ SELECT * FROM Image
+ WHERE id_img = :id_img
";
$this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]);
@@ -35,19 +34,7 @@ class ImageGateway extends Gateway
public function findAllImg() : array
{
$query = "
- SELECT * FROM Images
- ";
-
- $this -> co -> executeQuery($query);
-
- return $this -> co -> getResults();
- }
-
- public function findAllImgProfile() : array
- {
- $query = "
- SELECT * FROM Images
- WHERE is_img_prfl
+ SELECT * FROM Image
";
$this -> co -> executeQuery($query);
@@ -58,8 +45,8 @@ class ImageGateway extends Gateway
public function deleteImgGateway(int $idImg) : bool
{
$query = "
- DELETE FROM Images
- WHERE id_image = :id_img
+ DELETE FROM Image
+ WHERE id_img = :id_img
";
return $this -> co -> executeQuery($query, ['id_img' => array($idImg, PDO::PARAM_INT)]);
@@ -68,8 +55,8 @@ class ImageGateway extends Gateway
public function updateImgGateway(int $idImg, string $imgPath) : bool
{
$query = "
- UPDATE Images
- SET img_path = :img_path
+ UPDATE Image
+ SET imgPath = :img_path
WHERE id_image = :id_img
";
@@ -78,4 +65,19 @@ class ImageGateway extends Gateway
'img_path' => array($imgPath, PDO::PARAM_STR)
]);
}
+
+ public function getLastId():int{
+ $query = "SELECT id_img FROM Image;";
+ $this -> co -> executeQuery($query);
+ $res = $this -> co -> getResults();
+ foreach($res as $r){
+ $tab[] = $r["id_img"];
+ }
+ $id = 1;
+ while(in_array($id,$tab))
+ {
+ $id=$id+1;
+ }
+ return $id;
+ }
}
\ No newline at end of file
diff --git a/src/Gateway/QuestionGateway.php b/src/Gateway/QuestionGateway.php
index d67e175..946ee4e 100644
--- a/src/Gateway/QuestionGateway.php
+++ b/src/Gateway/QuestionGateway.php
@@ -98,4 +98,8 @@ class QuestionGateway extends Gateway
return $this -> co -> getResults();
}
+ public function getQuestionQuoteSrc(string $l) : array{
+
+ }
+
}
diff --git a/src/Gateway/QuoteGateway.php b/src/Gateway/QuoteGateway.php
index d5ace1f..92adefd 100644
--- a/src/Gateway/QuoteGateway.php
+++ b/src/Gateway/QuoteGateway.php
@@ -151,23 +151,38 @@ Class QuoteGateway extends Gateway{
return ($this -> co ->getResults())[0]['id'];
}
- public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
- {
- $query = "
- INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path)
- VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path)
- ";
-
- return $this->co->executeQuery($query, [
- ':id' => array($this->autoincrement(), PDO::PARAM_INT),
- ':content' => array($content, PDO::PARAM_STR),
- ':img_path' => array($img_path, PDO::PARAM_STR),
- ':langage' => array($langage, PDO::PARAM_STR),
- ':user' => array($user, PDO::PARAM_INT),
- ':reason' => array('À vérifier', PDO::PARAM_STR),
- ':source' => array($source, PDO::PARAM_STR),
- ':character' => array($character, PDO::PARAM_STR)
- ]);
+ public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){
+ $id = $this->getLastId();
+ $query = "INSERT INTO Quote Values (:id,:content,0,:lang,false,'',:charac,:src,:user);";
+ try {
+ $this->co->executeQuery($query,[
+ ':id' => [$id,PDO::PARAM_INT],
+ ':content' => [$content,PDO::PARAM_STR],
+ ':lang' => [$lang,PDO::PARAM_STR],
+ ':charac' => [$idChar,PDO::PARAM_INT],
+ ':src' => [$idSrc,PDO::PARAM_INT],
+ ':user' => [$idUsr,PDO::PARAM_INT],
+ ]);
+ }
+ catch (PDOException $e){
+ $error['501'] = 'Erreur lors de la création de la citation';
+ return error;
+ }
+ }
+
+ public function getLastId():int{
+ $query = "SELECT id_quote FROM Quote;";
+ $this -> co -> executeQuery($query);
+ $res = $this -> co -> getResults();
+ foreach($res as $r){
+ $tab[] = $r["id_quote"];
+ }
+ $id = 1;
+ while(in_array($id,$tab))
+ {
+ $id=$id+1;
+ }
+ return $id;
}
//======================== PARTI ADMIN ========================
diff --git a/src/Gateway/SourceGateway.php b/src/Gateway/SourceGateway.php
index 402d30b..456eab7 100644
--- a/src/Gateway/SourceGateway.php
+++ b/src/Gateway/SourceGateway.php
@@ -10,10 +10,11 @@ class SourceGateway extends Gateway{
{
$query = "
INSERT INTO Source
- VALUES( :title, :date)
+ VALUES(:id, :title, :date)
";
return $this -> co -> executeQuery($query, [
+ "id" => array($s->getIdSource(), PDO::PARAM_INT),
"title" => array($s->getTitle(), PDO::PARAM_STR),
"date" => array($s->getDate(), PDO::PARAM_STR),
#"type" => array($s->getType(), PDO::PARAM_STR)
@@ -81,4 +82,19 @@ class SourceGateway extends Gateway{
]);
}
+ public function getLastId():int{
+ $query = "SELECT id_source FROM Source;";
+ $this -> co -> executeQuery($query);
+ $res = $this -> co -> getResults();
+ foreach($res as $r){
+ $tab[] = $r["id_source"];
+ }
+ $id = 1;
+ while(in_array($id,$tab))
+ {
+ $id=$id+1;
+ }
+ return $id;
+ }
+
}
diff --git a/src/Gateway/UserGateway.php b/src/Gateway/UserGateway.php
index cee829e..f66e9a1 100644
--- a/src/Gateway/UserGateway.php
+++ b/src/Gateway/UserGateway.php
@@ -182,8 +182,18 @@ Class UserGateway extends Gateway{
}
- public function updateImg(string $username):array{
- $id_image = $this->randomImg();
+ public function updateImg(string $username,string $newImage):array{
+ if($newImage==null){
+ $id_image = $this->randomImg();
+ }
+ else if(is_int((int)$newImage)){
+ $id_image=(int)$newImage;
+ }
+ else{
+ $id_image = $this->randomImg();
+ }
+
+
//Update l'image du user passé en paramètre
$query = 'UPDATE Users SET img=:id_image WHERE username=:username';
$this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':id_image'=> array($id_image, PDO::PARAM_INT)));
@@ -200,5 +210,11 @@ Class UserGateway extends Gateway{
$query = 'UPDATE Users SET password=:newPassWd WHERE username=:username';
$this->co->executeQuery($query, array(':username'=>array($username, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR)));
}
+
+ public function emailWithUser(string $user):array{
+ $query = 'SELECT email FROM Users WHERE username = :user';
+ $this->co->executeQuery($query, array(':user'=>array($user, PDO::PARAM_STR)));
+ return $this->co->getResults();
+ }
}
?>
diff --git a/src/Model/CharacterModel.php b/src/Model/CharacterModel.php
index 5259c60..ac0655a 100644
--- a/src/Model/CharacterModel.php
+++ b/src/Model/CharacterModel.php
@@ -9,11 +9,17 @@ use Gateway\Gateway;
class CharacterModel extends Model
{
- public function createCharacter(int $id_character, string $name , string $img_char) : bool
+ public function createCharacter(int $id_character, string $name , int $img_char) : bool
{
return $this -> gateway -> create($id_character, $name, $img_char);
}
+ public function createCharacterWithoutId(string $name , int $img_char) : bool
+ {
+ $id_character = $this -> gateway -> getLastId();
+ return $this -> gateway -> create($id_character, $name, $img_char);
+ }
+
public function getCharacterById(int $id_character) : ?CharacterEntity
{
$c = $this -> gateway -> findById($id_character);
@@ -72,7 +78,7 @@ class CharacterModel extends Model
return $this -> gateway -> delete($id_character);
}
- public function updateCharacter(int $id_character, string $name, string $img_char) : bool
+ public function updateCharacter(int $id_character, string $name, int $img_char) : bool
{
return $this -> gateway -> update($id_character, $name, $img_char);
}
diff --git a/src/Model/ImageModel.php b/src/Model/ImageModel.php
index e9ac02b..74a8330 100644
--- a/src/Model/ImageModel.php
+++ b/src/Model/ImageModel.php
@@ -8,9 +8,16 @@ use Gateway\Gateway;
class ImageModel extends Model
{
- public function createImgModel(int $idImg, string $imgPath, bool $isImgProfile) : bool
+ public function createImgModel(int $idImg, string $imgPath) : bool
{
- return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile);
+ return $this -> gateway -> createImgGateway($idImg, $imgPath);
+ }
+
+ public function createImgModelWithoutId (string $imgPath) : int
+ {
+ $idImg = $this->gateway ->getLastId() ;
+ $this -> gateway -> createImgGateway($idImg, $imgPath, false);
+ return $idImg;
}
public function getImgById(int $idImg) : ?ImageEntity
@@ -20,9 +27,8 @@ class ImageModel extends Model
if ($res)
{
return new ImageEntity(
- $res[0]['id_image'],
- $res[0]['img_path'],
- $res[0]['is_img_prfl']
+ $res[0]['id_img'],
+ $res[0]['imgpath']
);
}
return null;
@@ -37,30 +43,13 @@ class ImageModel extends Model
foreach ($res as $img)
{
$images[] = new ImageEntity(
- $img['id_image'],
- $img['img_path'],
- $img['is_img_prfl']
+ $img['id_img'],
+ $img['imgpath']
);
}
return $images;
}
- public function getAllImgProfile() : array
- {
- $res = $this -> gateway -> findAllImgProfile();
-
- $images = [];
-
- foreach ($res as $img)
- {
- $images[] = new ImageEntity(
- $img['id_image'],
- $img['img_path'],
- $img['is_img_prfl']
- );
- }
- return $images;
- }
public function deleteImgModel(int $idImg) : bool
{
diff --git a/src/Model/QuestionModel.php b/src/Model/QuestionModel.php
index d560b18..1e6db0a 100644
--- a/src/Model/QuestionModel.php
+++ b/src/Model/QuestionModel.php
@@ -79,4 +79,39 @@ class QuestionModel extends Model
);
return null;
}
+
+ public function getRandomQuestion(string $quesType, string $repType, string $langue) : ?QuestionEntity{
+ switch([$questType,$repType]){
+ case ["Quote","Src"]:
+ $q = $this -> gateway -> getQuestionQuoteSrc($langue);
+ return new QuestionEntity(
+ $q[], //idQuote
+ $q[], //Quote
+ $q[], //SrcJuste
+ $q[], //rndSrc 1
+ $q[], //rndSrc 2
+ $q[], //rndSrc 3
+ $q[], //SrcJuste
+ );
+ case ["Quote","Charac"]:
+ $q = $this -> gateway -> getQuestionQuoteCharac($langue);
+
+ case ["Charac","Src"]:
+ $q = $this -> gateway -> getQuestionCharacSrc($langue);
+
+ case ["Charac","Quote"]:
+ $q = $this -> gateway -> getQuestionCharacQuote($langue);
+
+ case ["Src","Quote"]:
+ $q = $this -> gateway -> getQuestionSrcQuote($langue);
+
+ case ["Src","Charac"]:
+ $q = $this -> gateway -> getQuestionSrcCharac($langue);
+
+ case ["Test","Test"]:
+ return new QuestionEntity(-1,"1","1","2","3","4","1");
+ default :
+ return null;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/Model/QuoteModel.php b/src/Model/QuoteModel.php
index b0bcff3..e2f5946 100644
--- a/src/Model/QuoteModel.php
+++ b/src/Model/QuoteModel.php
@@ -46,11 +46,9 @@
return $tabQ;
}
- public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool
- {
- return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character);
+ public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){
+ $this -> gateway -> addQuote($content,$lang,$idChar,$idSrc,$idUsr);
}
-
}
?>
diff --git a/src/Model/SourceModel.php b/src/Model/SourceModel.php
index d43579b..9c54cce 100644
--- a/src/Model/SourceModel.php
+++ b/src/Model/SourceModel.php
@@ -8,8 +8,8 @@ class SourceModel extends Model
public function createSource(string $title, string $date, TypeSourceEnum $type) : bool
{
- $q = new SourceEntity(-1,$title, $date, TypeSourceEnum::Movie/*$type*/);
-
+ $id = $this -> gateway -> getLastId();
+ $q = new SourceEntity($id,$title, $date, $type);
return $this -> gateway -> create($q);
}
@@ -106,7 +106,7 @@ class SourceModel extends Model
public function existSource(string $name, string $type) : bool{
$q = $this -> getSourceByTitle($name);
- return isset($q[0]);
+ return isset($q);
}
}
diff --git a/src/Model/UserModel.php b/src/Model/UserModel.php
index 28f0c23..5dd1edc 100644
--- a/src/Model/UserModel.php
+++ b/src/Model/UserModel.php
@@ -85,6 +85,11 @@
return $res[0]['id_user'];
}
+ public function getEmailWithUser(string $user){
+ $res = $this->gateway->emailWithUser($user);
+ return $res[0]['email'];
+ }
+
// ===================== Bool FUNCTION =====================
public function IsExisteUsername(string $username):bool{
@@ -145,8 +150,8 @@
}
- public function setImage(string $username){
- $res = $this->gateway->updateImg($username);
+ public function setImage(string $username,string $newImage){
+ $res = $this->gateway->updateImg($username,$newImage);
$src[] = $res[0]['img'];
return $src;
}
diff --git a/src/Verification/Verification.php b/src/Verification/Verification.php
index eef98ab..e8ae8ba 100644
--- a/src/Verification/Verification.php
+++ b/src/Verification/Verification.php
@@ -7,8 +7,8 @@ namespace Verification;
if($text==NULL){
return NULL;
}
- $charInterdi=['|','/','\\','%','$','=','<','>','(',')'];
- $chaineInterdi=["AND","OR","WHERE","FROM","SELECT"];
+ $charInterdi=['|','/','\\','%','$','=','<','>','(',')',';'];
+ $chaineInterdi=["AND","OR","WHERE","FROM","SELECT","DROP","DELETE","TABLE","Users"];
$textVerif="";
foreach( str_split($text,1) as $char){
diff --git a/vue/create.php b/vue/create.php
index e0a16eb..f7c7f5b 100644
--- a/vue/create.php
+++ b/vue/create.php
@@ -14,6 +14,9 @@ echo $twig->render('bandeau.html.twig');
echo $twig->render('create.html.twig', [
'src' => $src,
- 'char' => $char
+ 'char' => $char,
+ 'content' => $_POST['content'],
+ 'charId' => $charId,
+ 'srcId' => $srcId
]);
?>
diff --git a/vue/profil.php b/vue/profil.php
index 8dc5208..a587a97 100644
--- a/vue/profil.php
+++ b/vue/profil.php
@@ -17,5 +17,6 @@
'srcEmail' => $p->getEmail(),
'srcImg' => $p->getImgPrfl(),
'error_message' => $error_message,
+ 'images' => $listImg,
));
?>
\ No newline at end of file
diff --git a/vue/recap.php b/vue/recap.php
new file mode 100644
index 0000000..2d9115e
--- /dev/null
+++ b/vue/recap.php
@@ -0,0 +1,16 @@
+render('head.html.twig', array(
+ 'title' => "Recap Quote",
+ 'style' => "public/styles/styleSubmitQuote.css",
+ 'scripts' => array("public/script/theme-toggle.js")
+ ));
+ echo $twig->render('bandeau.html.twig');
+ echo $twig -> render("recapSubmitQuote.html.twig", [
+ 'content' => $recap["content"],
+ 'character' => $recap["character"],
+ 'source' => $recap["src"]
+ ]);
+?>
\ No newline at end of file
diff --git a/vue/templates/create.html.twig b/vue/templates/create.html.twig
index 4eae2d1..f64a582 100644
--- a/vue/templates/create.html.twig
+++ b/vue/templates/create.html.twig
@@ -1,11 +1,22 @@