Add classes to abstract Users and Courses
Can refuse a question (email the author) Can modify question before validation
This commit is contained in:
parent
6e9554e2f2
commit
42fec70edf
14 changed files with 667 additions and 401 deletions
|
@ -53,6 +53,16 @@ class Course
|
|||
return $courses;
|
||||
}
|
||||
|
||||
public static function getCourse($id, $filename = "courses.xml")
|
||||
{
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (@$treeXML->load($filename))
|
||||
return new Course($treeXML->getElementById($id));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function setCourses($courses, $filename = "courses.xml")
|
||||
{
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
include_once("User.class.php");
|
||||
include_once("Course.class.php");
|
||||
|
||||
class Question
|
||||
{
|
||||
private $id;
|
||||
|
@ -9,6 +12,7 @@ class Question
|
|||
private $added_time;
|
||||
private $validated = false;
|
||||
private $validator = "";
|
||||
private $writer = "";
|
||||
|
||||
public function __construct($node = null)
|
||||
{
|
||||
|
@ -19,6 +23,7 @@ class Question
|
|||
if (intval($node->getAttribute("validated")))
|
||||
$this->validated = true;
|
||||
$this->validator = $node->getAttribute("validator");
|
||||
$this->writer = $node->getAttribute("writer");
|
||||
$this->question = $node->getAttribute("question");
|
||||
$this->course = $node->getAttribute("course");
|
||||
|
||||
|
@ -50,20 +55,19 @@ class Question
|
|||
return $q;
|
||||
}
|
||||
|
||||
public function regen_id()
|
||||
{
|
||||
$this->id = md5(time().$this->question.$this->validator);
|
||||
}
|
||||
|
||||
public function set_validator($val)
|
||||
{
|
||||
$this->validator = $val;
|
||||
$this->regen_id();
|
||||
$this->validator = $val->getId();
|
||||
}
|
||||
|
||||
public function get_writer()
|
||||
{
|
||||
return User::getUser($this->writer);
|
||||
}
|
||||
|
||||
public function get_validator()
|
||||
{
|
||||
return $this->validator;
|
||||
return User::getUser($this->validator);
|
||||
}
|
||||
|
||||
public function print_test()
|
||||
|
@ -99,6 +103,7 @@ class Question
|
|||
$qnode->setAttribute("addedtime", $this->added_time);
|
||||
$qnode->setAttribute("validated", intval($this->validated));
|
||||
$qnode->setAttribute("validator", $this->validator);
|
||||
$qnode->setAttribute("writer", $this->writer);
|
||||
$qnode->setAttribute("course", $this->course);
|
||||
$qnode->setAttribute("question", $this->question);
|
||||
|
||||
|
@ -111,6 +116,9 @@ class Question
|
|||
public function validated()
|
||||
{
|
||||
$this->validated = true;
|
||||
|
||||
//Return to normal ID
|
||||
$this->getNormalId();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
@ -118,6 +126,18 @@ class Question
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
public function getValidatorId()
|
||||
{
|
||||
$this->id = md5($this->added_time.$this->validator);
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getNormalId()
|
||||
{
|
||||
$this->id = md5($this->added_time.$this->writer);
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function isValidated()
|
||||
{
|
||||
return $this->validated;
|
||||
|
@ -125,12 +145,12 @@ class Question
|
|||
|
||||
public function getCourse()
|
||||
{
|
||||
return $this->course;
|
||||
return Course::getCourse($this->course);
|
||||
}
|
||||
|
||||
public function setCourse($course)
|
||||
{
|
||||
$this->course = $course;
|
||||
$this->course = $course->getId();
|
||||
}
|
||||
|
||||
public function getQuestion()
|
||||
|
@ -148,17 +168,31 @@ class Question
|
|||
return $this->answers;
|
||||
}
|
||||
|
||||
public function getAnswersMail()
|
||||
{
|
||||
$str = "";
|
||||
foreach($this->answers as $a)
|
||||
$str .= " * ".$a."\n";
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function set_writer($writer)
|
||||
{
|
||||
$this->writer = $writer->getId();
|
||||
}
|
||||
|
||||
public function setAnswer($answers)
|
||||
{
|
||||
$this->answers = array();
|
||||
if (!empty($answers))
|
||||
{
|
||||
if (is_array($answers))
|
||||
{
|
||||
foreach ($answers as $ans)
|
||||
$q->answers[] = $ans;
|
||||
$this->answers[] = $ans;
|
||||
}
|
||||
else
|
||||
$q->answers[] = $answers;
|
||||
$this->answers[] = $answers;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
181
User.class.php
Normal file
181
User.class.php
Normal file
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
|
||||
class User
|
||||
{
|
||||
private $id;
|
||||
private $username;
|
||||
private $password;
|
||||
private $email;
|
||||
private $registerdate;
|
||||
private $validated = false;
|
||||
|
||||
public function __construct($node = null)
|
||||
{
|
||||
if (isset($node))
|
||||
{
|
||||
$this->id = $node->getAttribute("xml:id");
|
||||
$this->registerdate = $node->getAttribute("registerdate");
|
||||
if (intval($node->getAttribute("validated")))
|
||||
$this->validated = true;
|
||||
$this->username = $node->getAttribute("username");
|
||||
$this->password = $node->getAttribute("password");
|
||||
$this->email = $node->getAttribute("email");
|
||||
}
|
||||
}
|
||||
|
||||
public static function new_User($email, $username = "", $password = null)
|
||||
{
|
||||
$u = new User();
|
||||
$u->id = sha1($email);
|
||||
$u->registerdate = time();
|
||||
$u->email = $email;
|
||||
$u->username = $username;
|
||||
if (isset($password))
|
||||
$this->password = getPassword($username, $password);
|
||||
|
||||
return $u;
|
||||
}
|
||||
|
||||
public static function getUsers($filename = "users.xml")
|
||||
{
|
||||
$users = array();
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (@$treeXML->load($filename))
|
||||
{
|
||||
$nodes = $treeXML->getElementsByTagName("user");
|
||||
foreach($nodes as $node)
|
||||
{
|
||||
$u = new User($node);
|
||||
$users[$u->id] = $u;
|
||||
}
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public static function getValidatedUsers($filename = "users.xml")
|
||||
{
|
||||
$users = array();
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (@$treeXML->load($filename))
|
||||
{
|
||||
$nodes = $treeXML->getElementsByTagName("user");
|
||||
foreach($nodes as $node)
|
||||
{
|
||||
$u = new User($node);
|
||||
if ($u->isValidated())
|
||||
$users[] = $u;
|
||||
}
|
||||
}
|
||||
|
||||
return $users;
|
||||
}
|
||||
|
||||
public static function getUser($id, $filename = "users.xml")
|
||||
{
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
|
||||
if (@$treeXML->load($filename))
|
||||
return new User($treeXML->getElementById($id));
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function setUsers($users, $filename = "users.xml")
|
||||
{
|
||||
$treeXML = new DOMDocument('1.0', 'UTF-8');
|
||||
$root_node = $treeXML->createElement("users");
|
||||
$treeXML->appendChild($root_node);
|
||||
|
||||
foreach ($users as $user)
|
||||
$root_node->appendChild($user->to_xml($treeXML));
|
||||
|
||||
$treeXML->formatOutput = true;
|
||||
$treeXML->save($filename);
|
||||
}
|
||||
|
||||
public function to_xml($root)
|
||||
{
|
||||
$qnode = $root->createElement("user");
|
||||
|
||||
$qnode->setAttribute("xml:id", $this->id);
|
||||
$qnode->setAttribute("username", $this->username);
|
||||
$qnode->setAttribute("password", intval($this->password));
|
||||
$qnode->setAttribute("email", $this->email);
|
||||
$qnode->setAttribute("registerdate", $this->registerdate);
|
||||
$qnode->setAttribute("validated", $this->validated);
|
||||
|
||||
return $qnode;
|
||||
}
|
||||
|
||||
public function canConnect($password)
|
||||
{
|
||||
$hash = getPassword($this->username, $password);
|
||||
|
||||
return ($hash == $this->password);
|
||||
}
|
||||
|
||||
private function getPassword($username, $password)
|
||||
{
|
||||
return hash("whirlpool", $username.':'.$password);
|
||||
}
|
||||
|
||||
public function set_validated($validated)
|
||||
{
|
||||
$this->validated = $validated;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function isValidated()
|
||||
{
|
||||
return $this->validated;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
$us = User::getUsers();
|
||||
|
||||
foreach($us as $u)
|
||||
$u->set_validated(true);
|
||||
User::setUsers($us);
|
||||
//*/
|
||||
/*
|
||||
$us = User::getUsers();
|
||||
|
||||
$u = User::new_User("bertrand@cournaud.fr", "Cccompany");
|
||||
$us[] = $u;
|
||||
|
||||
$u = User::new_User("colona@ycc.fr", "colona");
|
||||
$us[] = $u;
|
||||
|
||||
$u = User::new_User("ircquizz@23.tf", "maxence23");
|
||||
$us[] = $u;
|
||||
|
||||
$u = User::new_User("ircquizz@p0m.fr", "nemunaire");
|
||||
$us[] = $u;
|
||||
|
||||
$u = User::new_User("quentin.courtel@epita.fr", "Bob");
|
||||
$us[] = $u;
|
||||
|
||||
$u = User::new_User("ghost_anarky@hotmail.com", "Anarky");
|
||||
$us[] = $u;
|
||||
|
||||
User::setUsers($us);
|
||||
//*/
|
||||
?>
|
|
@ -1,7 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<script language="javascript">
|
||||
var nbAnswer = 1;
|
||||
<!DOCTYPE html><html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<title>Every Questions (BETA)</title>
|
||||
<script type="text/javascript">
|
||||
function add()
|
||||
{
|
||||
var element = document.createElement("input");
|
||||
|
@ -16,102 +18,84 @@
|
|||
foo.appendChild(element);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</header>
|
||||
<?php
|
||||
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
|
||||
$id = $_GET['id'];
|
||||
|
||||
$fileQ = new QuestionsFile("questions.xml");
|
||||
$question = $fileQ->get_question($id);
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="Stylesheet" href="style.css" />
|
||||
<title>Every AskWeb (BETA)</title>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div id="main_title">
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot AskWeb (BETA)</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="introduction">
|
||||
<article>
|
||||
<h2>Dernière chance pour changer d'avis</h2>
|
||||
Voici le rappel de votre question :<br/><br/>
|
||||
<?php $question->print_test(); ?>
|
||||
|
||||
<p>
|
||||
<strong>Cours concerné :</strong> <?php echo $question->getCourse()->getName(); ?><br><br>
|
||||
<strong>Question posée :</strong> <?php echo $question->getQuestion(); ?><br><br>
|
||||
<strong>Réponses valides exhaustives :</strong>
|
||||
</p>
|
||||
<?php
|
||||
echo "<ul>";
|
||||
foreach($question->getAnswer() as $a)
|
||||
echo "<li>".$a."</li>";
|
||||
echo "</ul>";
|
||||
?>
|
||||
<p>
|
||||
Vous avez la possibilité de modifier votre question avant de la
|
||||
faire valider. Faites vous plaisir.<br/>
|
||||
faire valider.<br>
|
||||
Faites vous plaisir.
|
||||
</p>
|
||||
</article>
|
||||
|
||||
<article>
|
||||
<h2>Modifier la question... (cette partie ne fonctionn pas ...</h2>
|
||||
<form id="formulaire" method="post" action="validateChangeQuestion.php">
|
||||
|
||||
<input type="hidden" name="id" id="id" value=<?php echo $question->getId() ?> />
|
||||
|
||||
<label for="course">De quelle matière s'agit-il ?</label><br/>
|
||||
|
||||
<h2>Modifier la question ...</h2>
|
||||
<form method="post" action="questions.php">
|
||||
<input type="hidden" name="id" value=<?php echo $question->getId(); ?>>
|
||||
<input type="hidden" name="email" value=<?php echo $question->get_writer()->getEmail(); ?>>
|
||||
<label for="course">De quelle matière s'agit-il ?</label><br>
|
||||
<select name="course" id="course">
|
||||
<?php
|
||||
include_once("Course.class.php");
|
||||
$cs = Course::getCourses();
|
||||
$qc = $question->getCourse();
|
||||
|
||||
<optgroup label="Cours communs">
|
||||
<option value="SGBD">SGBD</option>
|
||||
<option value="CompressionDeDonnées">
|
||||
Compression de données</option>
|
||||
<option value="ProtocolesDeLiaisons">
|
||||
Protocoles De Liaisons</option>
|
||||
<option value="TYLA">TYLA</option>
|
||||
<option value="ActiveDirectory">
|
||||
Active Directory</option>
|
||||
<option value="GrapheFlotReseau">
|
||||
Graphes Flots Reseaux</option>
|
||||
</optgroup>
|
||||
foreach($cs as $c)
|
||||
{
|
||||
if ($qc->getId() == $c->getId())
|
||||
print '<option selected="selected" value="'.$c->getId().'">'.$c->getName().'</option>';
|
||||
else
|
||||
print '<option value="'.$c->getId().'">'.$c->getName().'</option>';
|
||||
}
|
||||
|
||||
<optgroup label="Electif">
|
||||
<option value="RXAN">RXAN</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="TDA">
|
||||
<option value="TYLA">TYLA</option>
|
||||
<option value="CCMP">CCMP</option>
|
||||
<option value="SLPS">SLPS</option>
|
||||
<option value="FMPS">FMPS</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="MTM">
|
||||
<option value="ITIL">ITIL</option>
|
||||
<option value="Qualite">Qualité</option>
|
||||
</optgroup>
|
||||
|
||||
<optgroup label="Autre">
|
||||
<option value="Autre" selected>Autre</option>
|
||||
</optgroup>
|
||||
?>
|
||||
</select>
|
||||
|
||||
<p id="questionPart">
|
||||
<label id="q" for="question">
|
||||
Quelle est votre question ? </label><br/>
|
||||
<textarea id="question" name="question"
|
||||
rows="3" cols="70"><?php echo $question->getQuestion()?>
|
||||
</textarea>
|
||||
<label id="q" for="question">Quelle est votre question ? </label><br>
|
||||
<textarea id="question" name="question" rows="3" cols="70"><?php echo nl2br(htmlentities($question->getQuestion())); ?></textarea>
|
||||
</p>
|
||||
<p id="answerList">
|
||||
<label for="answer">Quelle est la réponse ? </label><br/>
|
||||
<input id="answer" name="answer0" type="text" />
|
||||
<label for="answer">Quelle est la réponse ?</label><br>
|
||||
<?php
|
||||
$max = 1;
|
||||
foreach($question->getAnswer() as $k => $a)
|
||||
{
|
||||
echo '<input type="text" name="answer'.$k.'" value="'.$a.'">';
|
||||
if ($max < $k)
|
||||
$max = $k;
|
||||
}
|
||||
print '<script type="text/javascript">var nbAnswer = '.($max+1).';</script>';
|
||||
?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
@ -121,26 +105,23 @@ $question = $fileQ->get_question($id);
|
|||
<p>
|
||||
<input type="submit" name="send" value="Envoyer" />
|
||||
</p>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
</article>
|
||||
|
||||
<article>
|
||||
<h2>... Ou la confirmer telle quelle</h2>
|
||||
|
||||
<h2>... ou la confirmer telle quelle !</h2>
|
||||
<p>
|
||||
Si la question vous semble corect, vous pouvez directement
|
||||
la confirmer ici:<br/>
|
||||
|
||||
<a href=<?php echo "http://".$_SERVER["SERVER_NAME"]
|
||||
. dirname($_SERVER["REQUEST_URI"])."/confirmation.php?id="
|
||||
. $question->getId() ?>>Confirmer la question</a>
|
||||
|
||||
|
||||
la confirmer ici :<br>
|
||||
</p>
|
||||
<form method="post"
|
||||
class="validation"
|
||||
action="confirmation.php">
|
||||
<input type="hidden" name="id" value="<?php echo $question->getId() ?>">
|
||||
<input type="submit" value="Je confirme">
|
||||
</form>
|
||||
<span style="clear: both; display: block;"></span>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<?php include('footer.html') ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -3,63 +3,53 @@
|
|||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
$id = $_GET['id'];
|
||||
@$id = $_POST['id'];
|
||||
|
||||
$fileQ = new QuestionsFile("questions.xml");
|
||||
$question = $fileQ->get_question($id);
|
||||
|
||||
if (!empty($question))
|
||||
{
|
||||
$dest_mail = $question->get_validator();
|
||||
$src_mail = $question->get_validator()->getEmail();
|
||||
|
||||
// Uncomment the following part for random email
|
||||
//Build email list
|
||||
$users = User::getValidatedUsers();
|
||||
$nbUsers = count($users);
|
||||
|
||||
//Pick a random email
|
||||
do
|
||||
{
|
||||
$file = fopen('email.txt', 'r');
|
||||
$number = fgets($file);
|
||||
|
||||
$random = rand(1, intval($number));
|
||||
|
||||
for ($i = 0; $i < $random; $i++)
|
||||
{
|
||||
$dest_mail = fgets($file);
|
||||
$random = rand(1, $nbUsers)-1;
|
||||
}
|
||||
fclose($file);
|
||||
}
|
||||
while ($dest_mail == $question->get_validator());
|
||||
while ($src_mail == $users[$random]->getEmail());
|
||||
|
||||
$question->set_validator($dest_mail);
|
||||
echo $dest_mail;
|
||||
$validationAddress = "/validation.php?id=".$question->getId();
|
||||
$random = 3;
|
||||
|
||||
$question->set_validator($users[$random]);
|
||||
|
||||
/* This code works, perhaps should be placed in a method in Question class?*/
|
||||
$to = $dest_mail;
|
||||
$subject = "[Nemubot] Validation d'une question";
|
||||
$headers = "From: Nemubot <bot@nemunai.re>\n";
|
||||
$message = "Bonjour,\n"
|
||||
."Une nouvelle question a été proposée à Nemubot.\n\n"
|
||||
|
||||
."Vous avez été sélectionné pour valider la question.\n\n"
|
||||
|
||||
."Rappels de la questions:\n"
|
||||
.'Cours concerné : ' . $question->getCourse() . "\n"
|
||||
.'La question est : ' . $question->getQuestion() . "\n"
|
||||
.'Les réponses sont : ' . print_r($question->getAnswer(), true) . "\n"
|
||||
."Voici la question :\n"
|
||||
.' - Cours concerné : ' . $question->getCourse()->getName() . "\n"
|
||||
.' - Question posée : ' . $question->getQuestion() . "\n"
|
||||
." - Les réponses valides sont :\n" . $question->getAnswersMail() . "\n"
|
||||
|
||||
|
||||
."Adresse de confirmation de la question :\n"
|
||||
. "http://".$_SERVER["SERVER_NAME"]
|
||||
. dirname($_SERVER["REQUEST_URI"]) . $validationAddress
|
||||
."http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"])
|
||||
."validation.php?id=".$question->getValidatorId()
|
||||
|
||||
."\n\nMerci beaucoup de votre participation\n"
|
||||
."Cordialement,\n"
|
||||
|
||||
."Cordialement,\n\n"
|
||||
|
||||
."-- \nNemubot.";
|
||||
."-- \nNemubot\nQCM accessible sur le réseau IRC rezosup, cannal #epita-qcm";
|
||||
|
||||
|
||||
if ($question->mail_utf8($to, $subject, $message, $headers))
|
||||
if ($question->mail_utf8($users[$random]->getEmail(), $subject, $message, $headers))
|
||||
{
|
||||
$fileQ->save();
|
||||
header("Location: ./thanksConfirmation.php");
|
||||
|
@ -67,9 +57,6 @@ if (!empty($question))
|
|||
else
|
||||
die("Une erreur s'est produite lors de l'envoie du mail");
|
||||
}
|
||||
//*/
|
||||
else
|
||||
{
|
||||
die("ID de question invalide ou déjà validé.");
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
2
|
||||
bertrand.cournaud@gmail.com
|
||||
bertrand@cournaud.fr
|
||||
|
||||
colona@ycc.fr
|
||||
ircquizz@23.tf
|
||||
ircquizz@p0m.fr
|
||||
quentin.courtel@epita.fr
|
|
@ -112,7 +112,7 @@
|
|||
</section>
|
||||
|
||||
<section id="hello">
|
||||
<h2>Nouvelle question</h2>
|
||||
<h2 id="newquestion">Nouvelle question</h2>
|
||||
<form id="formulaire" method="post" action="questions.php">
|
||||
<section id="Form">
|
||||
<aside id="info">
|
||||
|
|
130
questions.php
130
questions.php
|
@ -1,50 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<?php
|
||||
|
||||
//error_reporting(E_ALL);
|
||||
define("FILENAME", "questions_file.nemubot");
|
||||
|
||||
define("FILENAME", "questions.xml");
|
||||
|
||||
include("User.class.php");
|
||||
include("Course.class.php");
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
function isInList($mail)
|
||||
function isInUsersList($mail)
|
||||
{
|
||||
$file = fopen('email.txt', 'r');
|
||||
$number = fgets($file);
|
||||
$i = 0;
|
||||
$file_mail = fgets($file);
|
||||
$us = User::getUsers();
|
||||
|
||||
while ($i < $number)
|
||||
foreach($us as $u)
|
||||
{
|
||||
if (trim($mail) == trim($file_mail))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$file_mail = fgets($file);
|
||||
$i++;
|
||||
if ($u->getEmail() == $mail && $u->isValidated())
|
||||
return $u;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isInCoursesList($course)
|
||||
{
|
||||
return Course::getCourse($course);
|
||||
}
|
||||
|
||||
// Change this variable depending on the server
|
||||
$confirmationAddress = "confirmation.php?id=";
|
||||
|
||||
if (isset($_POST['send']))
|
||||
{
|
||||
//Gets parameters: course, question and answers
|
||||
$course = "";
|
||||
$question = $_POST["question"];
|
||||
$answers = array();
|
||||
|
||||
foreach ($_POST as $key => $value)
|
||||
{
|
||||
if ($key == "question")
|
||||
$question = $value;
|
||||
else if ($key == "course")
|
||||
$course = $value;
|
||||
else if (preg_match("#^answer#", $key) && $key != "")
|
||||
if (preg_match("#^answer[0-9]+$#", $key))
|
||||
if (!empty($value))
|
||||
$answers[] = $value;
|
||||
}
|
||||
|
||||
|
@ -53,76 +47,68 @@ if (isset ($_POST['send']))
|
|||
die("Veuillez indiquer une question !");
|
||||
else if (count($answers) <= 0)
|
||||
die("Veuillez indiquer au moins une réponse correcte !");
|
||||
else if (count($_POST['email']) <= 0 || !isInList($_POST['email']))
|
||||
die("Veuillez indiquer une adresse mail valide");
|
||||
else if (empty($_POST["email"]) || ($usr = isInUsersList($_POST["email"])) == null)
|
||||
die("Veuillez indiquer une adresse électronique valide !");
|
||||
else if (empty($_POST["course"]) || ($course = isInCoursesList($_POST["course"])) == null)
|
||||
die("Veuillez indiquer un cours valide !");
|
||||
else
|
||||
{
|
||||
$quest = Question::new_Question($question, $answers, $course);
|
||||
$quest->set_validator($_POST['email']);
|
||||
if (!empty($_POST["id"]))
|
||||
{
|
||||
$file = new QuestionsFile("questions.xml");
|
||||
$quest = $file->get_question($_POST["id"]);
|
||||
|
||||
$quest->setQuestion($question);
|
||||
$quest->setAnswer($answers);
|
||||
$quest->setCourse($course);
|
||||
}
|
||||
else
|
||||
{
|
||||
$quest = Question::new_Question($question, $answers, $course->getId());
|
||||
|
||||
// @TODO: Create/Load a QuestionFile and add the question (it must be unique)
|
||||
$file = new QuestionsFile('questions.xml');
|
||||
$file->add_question($quest);
|
||||
}
|
||||
$quest->set_writer($usr);
|
||||
$quest->set_validator($usr);
|
||||
|
||||
$file->save();
|
||||
|
||||
// @TODO: Find a validator (from the list of previous senders for example?)
|
||||
|
||||
// @TODO: Update the question and save the file
|
||||
|
||||
// @TODO: Send mail to the selected validator
|
||||
|
||||
// Get an email from the list
|
||||
|
||||
/* This code works, perhaps should be placed in a method in Question class?*/
|
||||
$to = $_POST['email'];
|
||||
//Send confirmation to sender
|
||||
$subject = "[Nemubot] Confirmation d'une question";
|
||||
$headers = "From: Nemubot <bot@nemunai.re>";
|
||||
$message = "Bonjour,\n"
|
||||
."Une nouvelle question a été proposée à Nemubot en utilisant
|
||||
cette adresse email.\n\n"
|
||||
."Une nouvelle question a été proposée à Nemubot en utilisant cette \n"
|
||||
."adresse email.\n\n"
|
||||
|
||||
."Rappels de la questions:\n"
|
||||
.'Cours concerné : ' . $course . "\n"
|
||||
.'La question est : ' . $question . "\n"
|
||||
.'Les réponses sont : ' . print_r($answers, true) . "\n"
|
||||
."Rappel de la question :\n"
|
||||
." - Cours concerné : " . $course->getName() . "\n"
|
||||
." - Question posée : " . $question . "\n"
|
||||
." - Les réponses valides sont :\n".$quest->getAnswersMail()."\n"
|
||||
|
||||
."Si vous avez effectivement posé cette question, merci "
|
||||
."de cliquer sur le lien ci-dessous pour confirmer.\n"
|
||||
."Si vous ne comprenez rien à cet email ou que vous n'avez pas "
|
||||
."posté de nouvelles questions, vous pouvez supprimer ce message.\n\n"
|
||||
."Si vous avez effectivement posé cette question, merci de cliquer sur \n"
|
||||
."le lien ci-dessous pour confirmer.\n"
|
||||
."Si vous ne comprenez rien à cet email ou que vous n'avez pas posté de \n"
|
||||
."nouvelles questions, vous pouvez supprimer ce message.\n\n"
|
||||
|
||||
."Adresse de confirmation de la question :\n"
|
||||
. "http://".$_SERVER["SERVER_NAME"]
|
||||
. dirname($_SERVER["REQUEST_URI"])."/changeQuestion.php?id="
|
||||
. $quest->getId()
|
||||
."http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"])
|
||||
."changeQuestion.php?id=".$quest->getId()
|
||||
|
||||
. "\n\n Merci beaucoup de votre participation\n"
|
||||
. "\n\nMerci beaucoup de votre participation.\n"
|
||||
."Cordialement,\n"
|
||||
|
||||
."-- \nNemubot.";
|
||||
;
|
||||
."-- \nNemubot\nQCM accessible sur le réseau IRC rezosup, cannal #epita-qcm";
|
||||
|
||||
|
||||
if ($quest->mail_utf8($to, $subject, $message, $headers))
|
||||
{
|
||||
echo ("Email sent");
|
||||
}
|
||||
else
|
||||
echo ("Error with the email");
|
||||
//*/
|
||||
}
|
||||
if (!empty($_POST["id"]))
|
||||
header("Location: ./changeQuestion.php?id=".$quest->getId());
|
||||
else if ($quest->mail_utf8($usr->getEmail(), $subject, $message, $headers))
|
||||
header("Location: ./thanks.php?id=" . $quest->getId());
|
||||
else
|
||||
echo ("Une erreur s'est produite lors de l'envoi du courrier de confirmation. Veuillez contacter l'administrateur du service.");
|
||||
}
|
||||
}
|
||||
else
|
||||
header("Location: ./");
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
28
style.css
28
style.css
|
@ -123,6 +123,34 @@ footer a
|
|||
padding-top: 10px;
|
||||
}
|
||||
|
||||
form.validation
|
||||
{
|
||||
float: left;
|
||||
margin-top: 10px;
|
||||
margin-left: 25%;
|
||||
}
|
||||
form.invalidation
|
||||
{
|
||||
float: right;
|
||||
margin-top: 10px;
|
||||
margin-right: 25%;
|
||||
}
|
||||
form.validation input, form.invalidation input
|
||||
{
|
||||
border-radius: 10px;
|
||||
height: 32px;
|
||||
font-weight: bold;
|
||||
width: 160px;
|
||||
}
|
||||
form.validation input
|
||||
{
|
||||
background: #00BB40;
|
||||
}
|
||||
form.invalidation input
|
||||
{
|
||||
background: #BB0020;
|
||||
}
|
||||
|
||||
#hideShow, #hideShowExp
|
||||
{
|
||||
float: right;
|
||||
|
|
57
thanks.php
57
thanks.php
|
@ -1,5 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html><html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<title>Every Questions (BETA)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</header>
|
||||
<?php
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
@ -7,46 +19,29 @@
|
|||
$id = $_GET['id'];
|
||||
$file = new QuestionsFile("questions.xml");
|
||||
$question = $file->get_question($id);
|
||||
|
||||
if (isset($question))
|
||||
{
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="Stylesheet" href="style.css" />
|
||||
<title>Every Questions (BETA)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div id="main_title">
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</div>
|
||||
</header>
|
||||
<section id="introduction">
|
||||
<article id="validate">
|
||||
<h2>Merci de votre participation !</h2>
|
||||
<p>
|
||||
Votre question a bien été ajoutée à la liste.<br/>
|
||||
Un email vous a été envoyé pour que vous confirmiez que
|
||||
Vous êtes bien l'auteur de la question.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Rappels de la question :<br/>
|
||||
<?php $question->print_test(); ?>
|
||||
Votre question a bien été enregistrée et est en attente de
|
||||
validation.<br>
|
||||
Un courrier électronique vient de vous ê envoyé pour que vous
|
||||
confirmiez que vous êtes bien l'auteur de la question.
|
||||
</p>
|
||||
<p>
|
||||
Vous pouvez proposer de nouvelles questions en cliquant
|
||||
sur le lien ci-dessous.<br/>
|
||||
<a href="index.php">Proposer une nouvelle question</a>
|
||||
<a href="./#newquestion">ici</a> !
|
||||
</p>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<?php include('footer.html') ?>
|
||||
|
||||
<?php
|
||||
}
|
||||
else
|
||||
header("Location: ./");
|
||||
include('footer.html') ?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,30 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="Stylesheet" href="style.css" />
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
|
||||
<title>AskWeb (BETA)</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div id="main_title">
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="introduction">
|
||||
<article>
|
||||
<h2>Merci de votre participation</h2>
|
||||
<p>
|
||||
Votre question a bien été prise en compte.<br/>
|
||||
Un email a été envoyé à une personne du chan pour
|
||||
qu'elle valide votre question.
|
||||
Votre question a bien été prise en compte.<br>
|
||||
Un courrier électronique a été envoyé à un membre aléatoire pour
|
||||
qu'il valide votre question.
|
||||
</p>
|
||||
<p>
|
||||
Nemubot vous remercie de l'aider à agrandir sa base de donnée
|
||||
Nemubot vous remercie de l'aider à agrandir sa base de données.<br>
|
||||
</p>
|
||||
<p>
|
||||
Vous pouvez proposer de nouvelles questions en cliquant
|
||||
<a href="./#newquestion">ici</a> !
|
||||
</p>
|
||||
</article>
|
||||
</section>
|
||||
|
|
74
thanksRefused.php
Normal file
74
thanksRefused.php
Normal file
|
@ -0,0 +1,74 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<title>Every Questions (BETA)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</header>
|
||||
<section id="introduction">
|
||||
<article id="validate">
|
||||
<h2><?php
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
if (isset($_POST['id']))
|
||||
{
|
||||
$id = $_POST['id'];
|
||||
$file = new QuestionsFile("questions.xml");
|
||||
$question = $file->get_question($id);
|
||||
|
||||
if (!isset($question) || $question->isValidated())
|
||||
echo 'Votre question à déjà été validée, merci de ne pas vous acharner.';
|
||||
else
|
||||
{
|
||||
//Send confirmation to sender
|
||||
$subject = "[Nemubot] Refus d'une question";
|
||||
$headers = "From: Nemubot <bot@nemunai.re>";
|
||||
$message = "Bonjour,\n"
|
||||
."L'une de vos questions proposée à Nemubot vient d'etre refusée.\n\n"
|
||||
|
||||
."Rappel de la question :\n"
|
||||
." - Cours concerné : " . $question->getCourse()->getName() . "\n"
|
||||
." - Question posée : " . $question->getQuestion() . "\n"
|
||||
." - Les réponses valides sont :\n".$question->getAnswersMail()."\n"
|
||||
|
||||
."Vous pouvez modifier la question à cette adresse :\n"
|
||||
."http://".$_SERVER["SERVER_NAME"].dirname($_SERVER["REQUEST_URI"])
|
||||
."changeQuestion.php?id=".$question->getNormalId()
|
||||
|
||||
. "\n\nMerci beaucoup de votre participation.\n"
|
||||
."Cordialement,\n"
|
||||
|
||||
."-- \nNemubot\nQCM accessible sur le réseau IRC rezosup, cannal #epita-qcm";
|
||||
|
||||
|
||||
if ($question->mail_utf8($question->get_writer()->getEmail(), $subject, $message, $headers))
|
||||
{
|
||||
$file->save();
|
||||
echo 'Question refusée !';
|
||||
}
|
||||
else
|
||||
echo ("Une erreur s'est produite lors de l'envoi du courrier de confirmation. Veuillez contacter l'administrateur du service.");
|
||||
}
|
||||
}
|
||||
else
|
||||
header("Location: ./");
|
||||
?></h2>
|
||||
<p>
|
||||
La question vient d'être retournée à son auteur,
|
||||
il pourra la resoumettre dès qu'il l'aura corrigée.<br><br>
|
||||
|
||||
<span style="text-decoration:line-through;">Amusez-vous</span> Révisez bien !
|
||||
</p>
|
||||
</article>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
|
@ -1,66 +1,50 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<?php
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
$id = $_GET['id'];
|
||||
$file = new QuestionsFile("questions.xml");
|
||||
$question = $file->get_question($id);
|
||||
|
||||
if ($question->isValidated() == 1)
|
||||
{
|
||||
$message = 'Votre question à déjà été validée'
|
||||
. ' Merci de ne pas vous acharner.';
|
||||
}
|
||||
else
|
||||
{
|
||||
$question->validated();
|
||||
$file->save();
|
||||
$message = 'Question validée';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="Stylesheet" href="style.css" />
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<title>Every Questions (BETA)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div id="main_title">
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="introduction">
|
||||
<article id="validate">
|
||||
<h2><?php
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
<h2><?php echo $message ?></h2>
|
||||
if (isset($_POST['id']))
|
||||
{
|
||||
$id = $_POST['id'];
|
||||
$file = new QuestionsFile("questions.xml");
|
||||
$question = $file->get_question($id);
|
||||
|
||||
if (!isset($question) || $question->isValidated())
|
||||
echo 'Votre question à déjà été validée, merci de ne pas vous acharner.';
|
||||
else
|
||||
{
|
||||
$question->validated();
|
||||
$file->save();
|
||||
echo 'Question validée !';
|
||||
}
|
||||
}
|
||||
else
|
||||
header("Location: ./");
|
||||
?></h2>
|
||||
<p>
|
||||
Votre question a été validée !<br/>
|
||||
Nemubot vous remercie de l'aider à agrandir sa base de données.<br/>
|
||||
|
||||
Vous pouvez vous aussi poser des questions à
|
||||
<a href="index.html" >cette adresse</a>,
|
||||
où bien simplement essayer de répondre aux
|
||||
questions déjà posées en tapant "!qcm" sur le chan.<br/>
|
||||
|
||||
Amusez vous bien.
|
||||
Nemubot vous remercie de l'aider à agrandir sa base de données.<br><br>
|
||||
Vous pouvez vous aussi poser des questions à <a href="./" >cette adresse</a>,
|
||||
où bien simplement essayer de répondre aux questions déjà posées en tapant
|
||||
<code>!qcm</code> sur un cannal où nemubot est présent.<br><br>
|
||||
|
||||
<span style="text-decoration:line-through;">Amusez-vous</span> Révisez bien !
|
||||
</p>
|
||||
|
||||
<p>
|
||||
On vous rappelle quand même la question un dernière fois :<br/>
|
||||
<?php $question->print_test(); ?>
|
||||
</p>
|
||||
<p>
|
||||
</article>
|
||||
</section>
|
||||
</body>
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="Stylesheet" href="style.css">
|
||||
<title>Every Questions (BETA)</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions (BETA)</h1>
|
||||
</header>
|
||||
<?php
|
||||
|
||||
include("Question.class.php");
|
||||
include("QuestionsFile.class.php");
|
||||
|
||||
|
@ -9,44 +23,42 @@ $file = new QuestionsFile("questions.xml");
|
|||
$question = $file->get_question($id);
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8" />
|
||||
<link rel="Stylesheet" href="style.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div id="main_title">
|
||||
<a href="http://www.h2g2.com" target="_blank">
|
||||
<img src="marvin-robot_normal.png" alt="" id="banner"/>
|
||||
</a>
|
||||
<h1>Nemubot Questions</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section id="introduction">
|
||||
<article>
|
||||
<h2>Validation de la question</h2>
|
||||
<strong>Rappel de la question</strong><br/><br/>
|
||||
<?php if (!$question)
|
||||
{
|
||||
<h3>Rappel de la question</h3>
|
||||
<?php
|
||||
if (!isset($question))
|
||||
echo "La question n'existe pas.";
|
||||
}
|
||||
else
|
||||
{
|
||||
$question->print_test();
|
||||
|
||||
echo "\n\n";
|
||||
}
|
||||
?><br/>
|
||||
|
||||
<a href='thanksValidation.php?id=<?php echo $question->getId() ?>'>
|
||||
Valider la question
|
||||
</a>
|
||||
?>
|
||||
<p>
|
||||
<strong>Cours concerné :</strong> <?php echo $question->getCourse()->getName(); ?><br><br>
|
||||
<strong>Question posée :</strong> <?php echo $question->getQuestion(); ?><br><br>
|
||||
<strong>Réponses valides exhaustives :</strong>
|
||||
</p>
|
||||
<?php
|
||||
echo "<ul>";
|
||||
foreach($question->getAnswer() as $a)
|
||||
echo "<li>".$a."</li>";
|
||||
echo "</ul>";
|
||||
?>
|
||||
<form method="post"
|
||||
class="invalidation"
|
||||
action="thanksRefused.php">
|
||||
<input type="hidden" name="id" value="<?php echo $question->getId() ?>">
|
||||
<input type="submit" value="Refuser la question">
|
||||
</form>
|
||||
<form method="post"
|
||||
class="validation"
|
||||
action="thanksValidation.php">
|
||||
<input type="hidden" name="id" value="<?php echo $question->getId() ?>">
|
||||
<input type="submit" value="Valider la question">
|
||||
</form>
|
||||
<span style="clear: both; display: block;"></span>
|
||||
<?php } ?>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
</body>
|
||||
<body>
|
||||
</html>
|
||||
|
|
Reference in a new issue