Submit Quote

pull/25/head
kevin.modejar 5 months ago
parent 60e2f0729f
commit fda3d1e68f

@ -13,10 +13,10 @@ $login = '';
$mdp = ''; $mdp = '';
$racine='/~lebeaulato/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website $racine='/~kemondejar/WF-Website'; // /~kekentin/WF/WF-Website /~lebeaulato/WF-Website /~kemondejar/WF-Website
//$racine='/WF-Website'; //$racine='/WF-Website';
$repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/';
//$repImg='/';
//Vues //Vues
$vues['erreur'] = 'vue/erreur.php'; $vues['erreur'] = 'vue/erreur.php';

@ -16,7 +16,7 @@ Class FrontControler{
global $twig,$racine; global $twig,$racine;
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'), $this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'add'), 'user' => array('quiz','commentary','logout','addComment','favorite','profil','addFav','supFav','changedata', 'submit', 'validsubmit', 'add'),
'admin' => array('null')]; 'admin' => array('null')];
$dVueEreur = []; $dVueEreur = [];
@ -52,6 +52,7 @@ Class FrontControler{
$router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav'); $router->map('GET|POST', '/supFav/[i:id]', 'UserControler','supFav');
$router->map('GET|POST', '/changedata', 'UserControler','changedata'); $router->map('GET|POST', '/changedata', 'UserControler','changedata');
$router->map('GET|POST', '/submit', 'UserControler', 'submit'); $router->map('GET|POST', '/submit', 'UserControler', 'submit');
$router->map('GET|POST', '/validsubmit', 'UserControler','validsubmit');
$router->map('GET|POST', '/add', 'UserControler', 'add'); $router->map('GET|POST', '/add', 'UserControler', 'add');

@ -21,6 +21,8 @@ use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError; use Twig\Error\SyntaxError;
use Verification\Verification; use Verification\Verification;
use Enum\TypeSourceEnum; use Enum\TypeSourceEnum;
use Model\ImageModel;
use Gateway\ImageGateway;
class UserControler { class UserControler {
@ -30,6 +32,7 @@ class UserControler {
private CharacterModel $caMod; private CharacterModel $caMod;
private SourceModel $srcMod; private SourceModel $srcMod;
private QuestionModel $questMod; private QuestionModel $questMod;
private ImageModel $iMod;
public function __construct() { public function __construct() {
global $co; global $co;
@ -39,6 +42,7 @@ class UserControler {
$this -> questMod = new QuestionModel(new QuestionGateway($co)); $this -> questMod = new QuestionModel(new QuestionGateway($co));
$this -> caMod = new CharacterModel(new CharacterGateway($co)); $this -> caMod = new CharacterModel(new CharacterGateway($co));
$this->srcMod = new SourceModel(new SourceGateway($co)); $this->srcMod = new SourceModel(new SourceGateway($co));
$this->iMod = new ImageModel(new ImageGateway($co));
} }
public function profil() { public function profil() {
@ -337,47 +341,23 @@ class UserControler {
* @throws RuntimeError * @throws RuntimeError
* @throws LoaderError * @throws LoaderError
*/ */
public function toSubmit() : ?array public function toSubmit(string $content,string $character, string $source)
{ {
global $co; global $co;
if ($_POST) if ($_POST)
{ {
$content = $_POST['content'] ?? null;
$character = $_POST['character'] ?? null;
$source = $_POST['src'] ?? null;
//$img = $_POST['img'] ?? null;
$errors = [null, null]; $errors = [null, null];
$gw = new CharacterGateway($co); $nameSrc = $this->srcMod->getSourceById($source)->getTitle();
$mdl = new CharacterModel($gw); $nameChar = $this->caMod->getCharacterById($character)->getName();
$character = $mdl -> getCharacterById($character);
$gw = new SourceGateway($co);
$mdl = new SourceModel($gw);
$source = $mdl -> getSourceById($source);
if (!$character) if (!$character)
$errors[0] = "Personnage inexistant"; $errors[0] = "Personnage inexistant";
if (!$source) if (!$source)
$errors[1] = "Source inexistante"; $errors[1] = "Source inexistante";
if ($errors[0] || $errors[1]) $this -> qMod -> addQuote($content,'fr',$character,$source,$this->uMod->getIdByUsername(Verification::VerifChar($_SESSION['user'])));
{ $this -> recapSubmitQuote(array('content' => $content, 'src' => $nameSrc, 'character' => $nameChar));
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']];
}
return null;
} }
/** /**
@ -391,6 +371,8 @@ class UserControler {
global $vues; global $vues;
$src = true; $src = true;
$char = true; $char = true;
$srcId = null;
$charId = null;
require_once $vues['create']; require_once $vues['create'];
exit(); exit();
} }
@ -398,6 +380,8 @@ class UserControler {
global $vues; global $vues;
$src = true; $src = true;
$char = false; $char = false;
$srcId = null;
$charId = $_POST['character'];
require_once $vues['create']; require_once $vues['create'];
exit(); exit();
} }
@ -405,32 +389,23 @@ class UserControler {
global $vues; global $vues;
$src = false; $src = false;
$char = true; $char = true;
$srcId = $_POST['src'];
$charId = null;
require_once $vues['create']; require_once $vues['create'];
exit(); exit();
} }
if($_POST) $recap = $this -> toSubmit($_POST['content'],$_POST['character'],$_POST['src']);
$recap = $this -> toSubmit();
if ($recap)
{
$this -> recapSubmitQuote($recap);
} }
public function recapSubmitQuote(array $recap){
global $vues;
require_once($vues["recap"]);
} }
// ===================== SUBMIT QUOTE FUNCTION ===================== // ===================== 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 public function getIdOfUser() : ?int
{ {
if (isset($_SESSION['user'])) if (isset($_SESSION['user']))
@ -445,15 +420,17 @@ class UserControler {
} }
public function add(){ public function add(){
global $vues; global $vues, $repImg;
$error = []; $error = [];
$src = false;
$char = false;
var_dump($_FILES);
if($_POST['req'] == "both"){ if($_POST['req'] == "both"){
$src = true; $src = true;
$char = true; $char = true;
} }
elseif($_POST['req'] == "src" or $src == true){
$src = true; if($_POST['req'] == "src" or $src == true){
$char = false;
$type = array("movie","serie","video-game","anime"); $type = array("movie","serie","video-game","anime");
if(Verification::verifNotNull($_POST["titre"])){ if(Verification::verifNotNull($_POST["titre"])){
$_POST["titre"] = Verification::verifChar($_POST["titre"]); $_POST["titre"] = Verification::verifChar($_POST["titre"]);
@ -465,8 +442,6 @@ class UserControler {
$error[] = "Le titre doit être définit"; $error[] = "Le titre doit être définit";
} }
if(Verification::verifNotNull($_POST["date"])){ if(Verification::verifNotNull($_POST["date"])){
$src = true;
$char = false;
$_POST["date"] = Verification::verifChar($_POST["date"]); $_POST["date"] = Verification::verifChar($_POST["date"]);
if(intval($_POST["date"],10) < 1850 or intval($_POST["date"],10) > date( "Y", time() )){ if(intval($_POST["date"],10) < 1850 or intval($_POST["date"],10) > date( "Y", time() )){
$error[] = "La date est invalide"; $error[] = "La date est invalide";
@ -485,24 +460,57 @@ class UserControler {
$error[] = "Le type doit être définit"; $error[] = "Le type doit être définit";
} }
} }
elseif($_POST['req'] == "char" or $char == true){
$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 == []){ if($error == []){
$recap['content'] = $_POST['content'];
if($_POST['req'] == "both"){ 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"){ elseif($_POST['req'] == "src"){
$this->srcMod->createSource($_POST["titre"], $_POST["date"], TypeSourceEnum::from($_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"){ 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"]);
} }
require_once($vues["recap"]); //A changer pour recapSubmitQuote $this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS);
} }
else{ else{
require_once($vues["create"]); require_once($vues["create"]);

@ -18,7 +18,7 @@ class CharacterGateway extends Gateway
return $this -> co -> executeQuery($query, [ return $this -> co -> executeQuery($query, [
'id_caracter' => array($id_character, PDO::PARAM_INT), 'id_caracter' => array($id_character, PDO::PARAM_INT),
'caracter' => array($name, PDO::PARAM_STR), '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, [ return $this -> co -> executeQuery($query, [
"id_c" => array($id_char, PDO::PARAM_INT), "id_c" => array($id_char, PDO::PARAM_INT),
"caracter" => array($name, PDO::PARAM_STR), "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;
}
} }

@ -9,14 +9,13 @@ class ImageGateway extends Gateway
public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : bool
{ {
$query = " $query = "
INSERT INTO Images INSERT INTO Image
VALUES (:id_img, :img_path, :is_img_profile) VALUES (:id_img, :img_path)
"; ";
return $this -> co -> executeQuery($query, [ return $this -> co -> executeQuery($query, [
'id_img' => array($idImg, PDO::PARAM_INT), 'id_img' => array($idImg, PDO::PARAM_INT),
'img_path' => array($imgPath, PDO::PARAM_STR), 'img_path' => array($imgPath, PDO::PARAM_STR),
'is_img_profile' => array($isImgProfile, PDO::PARAM_BOOL),
]); ]);
} }
@ -78,4 +77,19 @@ class ImageGateway extends Gateway
'img_path' => array($imgPath, PDO::PARAM_STR) '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;
}
} }

@ -151,24 +151,39 @@ Class QuoteGateway extends Gateway{
return ($this -> co ->getResults())[0]['id']; return ($this -> co ->getResults())[0]['id'];
} }
public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){
{ $id = $this->getLastId();
$query = " $query = "INSERT INTO Quote Values (:id,:content,0,:lang,false,'',:charac,:src,:user);";
INSERT INTO Quote (id_quote, content, langue, reason, id_source, id_caracter, id_user_verif, img_path) try {
VALUES (:id, :content, :langage, :reason, :source, :character, :user, :img_path) $this->co->executeQuery($query,[
"; ':id' => [$id,PDO::PARAM_INT],
':content' => [$content,PDO::PARAM_STR],
return $this->co->executeQuery($query, [ ':lang' => [$lang,PDO::PARAM_STR],
':id' => array($this->autoincrement(), PDO::PARAM_INT), ':charac' => [$idChar,PDO::PARAM_INT],
':content' => array($content, PDO::PARAM_STR), ':src' => [$idSrc,PDO::PARAM_INT],
':img_path' => array($img_path, PDO::PARAM_STR), ':user' => [$idUsr,PDO::PARAM_INT],
':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)
]); ]);
} }
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 ======================== //======================== PARTI ADMIN ========================
//Probablement à déplacer dans un autre fichier //Probablement à déplacer dans un autre fichier

@ -9,11 +9,17 @@ use Gateway\Gateway;
class CharacterModel extends Model 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); 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 public function getCharacterById(int $id_character) : ?CharacterEntity
{ {
$c = $this -> gateway -> findById($id_character); $c = $this -> gateway -> findById($id_character);
@ -72,7 +78,7 @@ class CharacterModel extends Model
return $this -> gateway -> delete($id_character); 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); return $this -> gateway -> update($id_character, $name, $img_char);
} }

@ -13,6 +13,13 @@ class ImageModel extends Model
return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile); return $this -> gateway -> createImgGateway($idImg, $imgPath, $isImgProfile);
} }
public function createImgModelWithoutId (string $imgPath) : int
{
$idImg = $this->gateway ->getLastId() ;
$this -> gateway -> createImgGateway($idImg, $imgPath, false);
return $idImg;
}
public function getImgById(int $idImg) : ?ImageEntity public function getImgById(int $idImg) : ?ImageEntity
{ {
$res = $this -> gateway -> findImgById($idImg); $res = $this -> gateway -> findImgById($idImg);

@ -46,11 +46,9 @@
return $tabQ; return $tabQ;
} }
public function insert4User(string $content, string $img_path, string $langage, int $user, int $source, int $character) : bool public function addQuote(string $content, string $lang, int $idChar, int $idSrc, int $idUsr){
{ $this -> gateway -> addQuote($content,$lang,$idChar,$idSrc,$idUsr);
return $this->gateway->insert4User($content, $img_path, $langage, $user, $source, $character);
} }
} }
?> ?>

@ -106,7 +106,7 @@ class SourceModel extends Model
public function existSource(string $name, string $type) : bool{ public function existSource(string $name, string $type) : bool{
$q = $this -> getSourceByTitle($name); $q = $this -> getSourceByTitle($name);
return isset($q[0]); return isset($q);
} }
} }

@ -7,8 +7,8 @@ namespace Verification;
if($text==NULL){ if($text==NULL){
return NULL; return NULL;
} }
$charInterdi=['|','/','\\','%','$','=','<','>','(',')']; $charInterdi=['|','/','\\','%','$','=','<','>','(',')',';'];
$chaineInterdi=["AND","OR","WHERE","FROM","SELECT"]; $chaineInterdi=["AND","OR","WHERE","FROM","SELECT","DROP","DELETE","TABLE","Users"];
$textVerif=""; $textVerif="";
foreach( str_split($text,1) as $char){ foreach( str_split($text,1) as $char){

@ -15,6 +15,8 @@ echo $twig->render('bandeau.html.twig');
echo $twig->render('create.html.twig', [ echo $twig->render('create.html.twig', [
'src' => $src, 'src' => $src,
'char' => $char, 'char' => $char,
'content' => $_POST['content'] 'content' => $_POST['content'],
'charId' => $charId,
'srcId' => $srcId
]); ]);
?> ?>

@ -4,13 +4,13 @@
echo $twig->render('head.html.twig', array( echo $twig->render('head.html.twig', array(
'title' => "Recap Quote", 'title' => "Recap Quote",
'style' => "../public/styles/styleSubmitQuote.css", 'style' => "public/styles/styleSubmitQuote.css",
'scripts' => array("../../public/script/theme-toggle.js") 'scripts' => array("public/script/theme-toggle.js")
)); ));
echo $twig->render('bandeau.html.twig'); echo $twig->render('bandeau.html.twig');
echo $twig -> render("recapSubmitQuote.html.twig", [' echo $twig -> render("recapSubmitQuote.html.twig", [
content' => $_POST["content"], 'content' => $recap["content"],
'character' => $_POST["character"], 'character' => $recap["character"],
'source' => $_POST["src"] 'source' => $recap["src"]
]); ]);
?> ?>

@ -1,5 +1,5 @@
<div class="creation"> <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 %} {% if src == true and char == true %}
<input type="hidden" id="req" name="req" value="both"/> <input type="hidden" id="req" name="req" value="both"/>
@ -8,13 +8,13 @@
{% elseif src == true %} {% elseif src == true %}
<input type="hidden" id="req" name="req" value="src"/> <input type="hidden" id="req" name="req" value="src"/>
{# <input type="hidden" id="character" name="character" value="{{ }}"/> a completer #} <input type="hidden" id="character" name="character" value="{{ charId }}"/>
<input type="hidden" id="content" name="content" value="{{ content }}"/> <input type="hidden" id="content" name="content" value="{{ content }}"/>
{% elseif char == true %} {% 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="{{ }}"/> a completer #} <input type="hidden" id="src" name="src" value="{{ srcId }}"/>
<input type="hidden" id="content" name="content" value="{{ content }}"/> <input type="hidden" id="content" name="content" value="{{ content }}"/>
{% endif %} {% endif %}
@ -45,7 +45,7 @@
<input type="text" class="champ" id="name" name="name" placeholder="Nom du personnage" required/> <input type="text" class="champ" id="name" name="name" placeholder="Nom du personnage" required/>
<label for="name">Image du personnage *</label> <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 %} {% endif %}
<input type="submit" class="btn" value="Soumettre"/> <input type="submit" class="btn" value="Soumettre"/>

@ -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> <h1>▶ Your quote has been submitted successfully ◀</h1>
<div> <div>
@ -41,7 +26,7 @@
</div> </div>
<div> <div>
<button onclick="window.location.href='/';"> Revenir à l'acceuil</button> <button onclick="window.location.href='{{racine}}/';"> Revenir à l'acceuil</button>
</div> </div>
</div> </div>

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

Loading…
Cancel
Save