pull/25/head
Maxime ROCHER 3 months ago
commit 7e553a63e7

@ -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';

Binary file not shown.

After

Width:  |  Height:  |  Size: 653 KiB

@ -115,3 +115,43 @@ function editFieldPassWd(id) {
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);
}

@ -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;

@ -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');

@ -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();
$this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user'])));
$this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar));
}
$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']];
}
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);
}
}

@ -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 .= "<html>
<body>
<img src=\"cid:image1\" alt=\"Image\" style=\"width: 400px; height: auto;\" />
<p>Bonjour $pseudo,</p>
<p>Merci de vous être inscrit sur notre site What The Fantasy. Cest avec grande joie que nous vous accueillons au sein de notre confrérie, pour découvrir ensemble...
</p>
<p>À bientôt !</p>
<p>L'équipe du site</p>
</body>
</html>\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: <image1>\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
}
}

@ -70,8 +70,5 @@ class CharacterEntity
$this->img_path = $img_path;
}
}

@ -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;
}
}

@ -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 );
}
}

@ -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;
}
}

@ -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;
}
}

@ -98,4 +98,8 @@ class QuestionGateway extends Gateway
return $this -> co -> getResults();
}
public function getQuestionQuoteSrc(string $l) : array{
}
}

@ -151,24 +151,39 @@ 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 ========================
//Probablement à déplacer dans un autre fichier

@ -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;
}
}

@ -182,8 +182,18 @@ Class UserGateway extends Gateway{
}
public function updateImg(string $username):array{
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();
}
}
?>

@ -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);
}

@ -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
{

@ -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;
}
}
}

@ -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);
}
}
?>

@ -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);
}
}

@ -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;
}

@ -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){

@ -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
]);
?>

@ -17,5 +17,6 @@
'srcEmail' => $p->getEmail(),
'srcImg' => $p->getImgPrfl(),
'error_message' => $error_message,
'images' => $listImg,
));
?>

@ -0,0 +1,16 @@
<?php
global $twig;
echo $twig->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"]
]);
?>

@ -1,11 +1,22 @@
<div class="creation">
<form class="add" method="post" action="{{racine}}/add">
<form class="add" method="post" action="{{racine}}/add" enctype="multipart/form-data">
{% if src == true and char == true %}
<input type="hidden" id="req" name="req" value="both"/>
<input type="hidden" id="content" name="content" value="{{ content }}"/>
{% elseif src == true %}
<input type="hidden" id="req" name="req" value="src"/>
<input type="hidden" id="character" name="character" value="{{ charId }}"/>
<input type="hidden" id="content" name="content" value="{{ content }}"/>
{% elseif char == true %}
<input type="hidden" id="req" name="req" value="src"/>
<input type="hidden" id="req" name="req" value="char"/>
<input type="hidden" id="src" name="src" value="{{ srcId }}"/>
<input type="hidden" id="content" name="content" value="{{ content }}"/>
{% endif %}
{% if src == true %}
<h1>Source</h1>
@ -15,16 +26,16 @@
<input type="number" id="date" name="date" min="1850" max="{{ "now"|date("Y") }}" required>
<label for="type">Type de source *</label>
<input type="radio" id="movie" name="type" value="Movie" checked>
<input type="radio" id="movie" name="type" value="movie" checked>
<label for="movie">Film</label><br>
<input type="radio" id="serie" name="type" value="Serie">
<input type="radio" id="serie" name="type" value="serie">
<label for="serie">Serie</label>
<input type="radio" id="vg" name="type" value="VideoGame">
<input type="radio" id="vg" name="type" value="video-game">
<label for="vg">Jeu Vidéo</label><br>
<input type="radio" id="anime" name="type" value="Anime">
<input type="radio" id="anime" name="type" value="anime">
<label for="anime">Anime</label>
{% endif %}
@ -34,7 +45,7 @@
<input type="text" class="champ" id="name" name="name" placeholder="Nom du personnage" required/>
<label for="name">Image du personnage *</label>
<input type="file" id="avatar" name="avatar" accept="image/png, image/jpeg" required/>
<input type="file" id="avatar" name="avatar" accept="image/png, image/jpeg, imag/jpg" required/>
{% endif %}
<input type="submit" class="btn" value="Soumettre"/>

@ -2,8 +2,26 @@
<div class="login">
<h1>▶ Profil ◀</h1>
<p name="image" id="image">
<button popovertarget="list-ChangeImg" name="image" class="ChangeImg"><img src="{{ srcImg }}" class="imageProfil"/></button>
</p>
<form method="post" action="{{ racine }}/changedata">
<button name="image" class="ChangeImg" value="1" type="Submit"><img src="{{ srcImg }}" class="imageProfil" onmousedown="return false"/></button>
<p name="imagePost" id="imagePost">
</p>
<div popover id="list-ChangeImg" >
{% if images|length > 0 %}
{% for image in images %}
<p class="ChangeImg" onclick="editFieldImage({{ image.idImg }},'{{ image.imgPath }}')">
<img src="{{ image.imgPath }}" class="imageProfil" />
</p>
{% endfor %}
{% else %}
<p>Aucune images n'a été trouvée.</p>
{% endif %}
</div>
{% if error_message is defined and error_message is not empty %}
<p style="color: red">{{ error_message }}</p>
@ -11,7 +29,9 @@
<p class="infoProfil" name="pseudo" id="username"> <strong>{{ srcUsername }}</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldUsername('username')"/></p>
<p class="infoProfil" name="email" id="email"> <strong> {{ srcEmail }}</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldEmail('email')"/></p>
<p class="infoProfil" name="email" id="email"> <strong> {{ srcEmail }}</strong>
<img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldEmail('email')"/>
</p>
<p class="infoProfil" name="mdp" id="passwd"> <strong>Votre mot de passe</strong><img class='imgModify' src='{{ racine }}/images/modify.svg' onclick="editFieldPassWd('passwd')"/></p>

@ -1,18 +1,3 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wiki Fantasy : Submit Quote</title>
<link id="favicon" rel="icon" href="../../images/iconeSombre.ico"> <!-- Par défaut sombre -->
<link rel="stylesheet" href="../../public/styles/styleSubmitQuote.css">
<script defer src="../../public/script/theme-toggle.js"></script>
</head>
<body>
{% include "bandeau.html.twig" %}
<h1>▶ Your quote has been submitted successfully ◀</h1>
<div>
@ -41,7 +26,7 @@
</div>
<div>
<button onclick="window.location.href='/';"> Revenir à l'acceuil</button>
<button onclick="window.location.href='{{racine}}/';"> Revenir à l'acceuil</button>
</div>
</div>

@ -43,8 +43,7 @@
<div id="contentField">
<p>Contenu *</p>
<textarea id="content" name="content" rows="5" cols="50" required>Ecrire une citation ...
</textarea>
<textarea id="content" name="content" rows="5" cols="50" required placeholder="écrire la citation..."></textarea>
</div>
</div>

Loading…
Cancel
Save