$page = 'cards'; $title = 'Add card'; $desc = ''; require '../header.php'; if (!isset($user)) { fURL::redirect('/login.php?forward=/members/cards.php'); } if (isset($_POST['submit'])) { try { fRequest::validateCSRFToken($_POST['token']); $card = new Card(); $card->setUserId($user->getId()); $card->setAddedDate(time()); $card->setUid($_POST['uid']); $card->store(); fURL::redirect('/members/cards.php'); exit; } catch (fValidationException $e) { echo "<p>" . $e->printMessage() . "</p>"; } catch (fSQLException $e) { echo "<p>An unexpected error occurred, please try again later</p>"; trigger_error($e); } } ?> <h2>Add card</h2> <form method="POST"> <input type="hidden" name="token" value="<?php echo fRequest::generateCSRFToken();
private function display() { if (!$this->boobool) { //on relance la procédure de génération $this->process(); } else { if (isset($_POST['submit_form'])) { if (!$this->submit || $this->errors) { return false; } // insertion de la carte $forbidden = array(); for ($i = 1; isset($this->res['tabou' . $i]); $i++) { array_push($forbidden, $this->res['tabou' . $i]); } $carte = new Card($this->userlang, NULL, $this->res['nivcarte'], "nom", $this->oracle, $this->res['mot'], $forbidden, array()); $carte->store(); $this->card = $carte; unset($this->res); // affichage de la carte include './views/oracle.card.display.html'; } else { //si carte pas encore validée, c'est le premier passage dans la page : affichage de la page génération de carte include './views/oracle.alea.html'; } } return true; }
header('Content-Type: text/html; charset=UTF-8'); ?> <head> <style>.carte{float:left; padding:3px; background-color:lightgrey; margin-right:3px;display: flex;flex-direction: column;justify-content:space-between;width:250px} .carte div{margin:0;padding-bottom:4px; padding-top:4px; padding-left:1em; padding-right:1em;} .carte>div{padding:0;} .langue{font-weight:bold; background-color:grey;color:white;} .niveauMin{text-align: right; color:white; float:right; background-color:black} .categorie{background-color:white; margin-bottom:3px} .motCle{text-align:center} .motATrouver{font-weight:bold; background-color:#06AD45} .tabous{overflow:auto;height:250px} .themes{overflow:auto;height:30px} .carte + *:not(.carte){clear:both} .auteur{background-color:white; text-align:left;}</style> </head> <body> <?php error_reporting(E_ALL); //error_reporting(0); désactiver ini_set('display_errors', '1'); require 'models/card.class.php'; $test = new Card(1); echo $test; $test = new Card("es", NULL, "A1", "nom", "2", "Actor", array("Película", "Cine", "Interpretar", "Jugar", "Teatro", "Protagonista"), array("Profession", "Art")); $test->store(); $test2 = new Card(9); echo "{$test}<br />{$test2}"; ?> </body>
$tmpObj = new Card("it", NULL, "A2", "Nom", "1", "Art", array("Opera", "Scuola", "Colori", "Museo", "Dipingere"), array("Art")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "B1", "Nom", "1", "Traffico", array("Macchine", "Inquinamento", "Città", "Problema", "Rumore"), array("Ville")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "B1", "Nom", "1", "Volcano", array("Etna", "Vesuvio", "Uscire", "Fuoco", "Cenere"), array("Environnement", "Nature")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "B1", "Nom", "1", "Ingegnere", array("Edifici", "Costruire", "Lavoro", "Laurea", "Università"), array("Profession")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "A2", "Nom", "1", "Cinema", array("Art", "Film", "Vedere", "Telecamera", "Attore"), array("Divertissement", "Art")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "B1", "Nom", "1", "Stuzzicadente", array("Legno", "Dente", "Alimentation", "Johnny Stecchino", "Film"), array("Hygiène")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "B1", "Nom", "1", "Concerto", array("Musica", "Cantante", "Strumenti", "Ascoltare", "Teatro"), array("Divertissement")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "A2", "Nom", "1", "Arancio", array("Albero", "Fruita", "Arancione", "Clementine", "Pianta"), array("Alimentation")); $tmpObj->store(); $nb++; $tmpObj = new Card("it", NULL, "A2", "Nom", "1", "Anniversario", array("Ricorrenza", "Compleanno", "Matrimonio", "Auguri", "Celebrare"), array("Société")); $tmpObj->store(); $nb++; echo "<p><strong>{$nb}</strong> cards imported</p>"; ?> </body> </html>
private function validate() { if ($this->submit) { //Categorie always "nom" TODO… try { $forbidden = array(); for ($i = 1; isset($this->res['tabou' . $i]); $i++) { array_push($forbidden, $this->res['tabou' . $i]); } $carte = new Card($this->userlang, NULL, $this->res['nivcarte'], "nom", $this->createur, $this->res['mot'], $forbidden, array($this->res['theme_carte']), './views/card.inline.display.php'); $carte->store(); $_SESSION["LastStoredId"] = $carte->get_id(); $this->card = $carte; $this->res = array('carteID' => $_SESSION["LastStoredId"]); } catch (Exception $e) { echo $e; return false; } return true; } else { return false; } }