Submit Quote

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

@ -13,10 +13,10 @@ $login = '';
$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';
$repImg='/home/UCA/kemondejar/public_html/WF-Website/public/images/';
//$repImg='/';
//Vues
$vues['erreur'] = 'vue/erreur.php';

@ -16,7 +16,7 @@ Class FrontControler{
global $twig,$racine;
$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')];
$dVueEreur = [];
@ -52,6 +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', '/add', 'UserControler', 'add');

@ -21,6 +21,8 @@ use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Verification\Verification;
use Enum\TypeSourceEnum;
use Model\ImageModel;
use Gateway\ImageGateway;
class UserControler {
@ -30,6 +32,7 @@ class UserControler {
private CharacterModel $caMod;
private SourceModel $srcMod;
private QuestionModel $questMod;
private ImageModel $iMod;
public function __construct() {
global $co;
@ -39,6 +42,7 @@ class UserControler {
$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));
}
public function profil() {
@ -337,47 +341,23 @@ 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;
}
/**
@ -391,6 +371,8 @@ class UserControler {
global $vues;
$src = true;
$char = true;
$srcId = null;
$charId = null;
require_once $vues['create'];
exit();
}
@ -398,6 +380,8 @@ class UserControler {
global $vues;
$src = true;
$char = false;
$srcId = null;
$charId = $_POST['character'];
require_once $vues['create'];
exit();
}
@ -405,32 +389,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']))
@ -445,15 +420,17 @@ class UserControler {
}
public function add(){
global $vues;
global $vues, $repImg;
$error = [];
$src = false;
$char = false;
var_dump($_FILES);
if($_POST['req'] == "both"){
$src = true;
$char = true;
}
elseif($_POST['req'] == "src" or $src == true){
$src = true;
$char = false;
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"]);
@ -465,8 +442,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";
@ -485,24 +460,57 @@ class UserControler {
$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 == []){
$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"], 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"]);
}
require_once($vues["recap"]); //A changer pour recapSubmitQuote
$this -> toSubmit(Verification::VerifChar($_POST["content"]),$idC,$idS);
}
else{
require_once($vues["create"]);

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

@ -9,14 +9,13 @@ class ImageGateway extends Gateway
public function createImgGateway(int $idImg, string $imgPath, bool $isImgProfile) : 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),
]);
}
@ -78,4 +77,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;
}
}

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

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

@ -13,6 +13,13 @@ class ImageModel extends Model
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
{
$res = $this -> gateway -> findImgById($idImg);

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

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

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

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

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

@ -1,5 +1,5 @@
<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"/>
@ -8,13 +8,13 @@
{% elseif src == true %}
<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 }}"/>
{% elseif char == true %}
<input type="hidden" id="req" name="req" value="src"/>
{#<input type="hidden" id="src" name="src" value="{{ }}"/> a completer #}
<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 %}
@ -45,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"/>

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