2012-05-18 19:56:57 +00:00
|
|
|
<?php
|
|
|
|
|
2012-05-18 20:11:42 +00:00
|
|
|
define("FILENAME", "questions_file.nemubot");
|
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
include("Question.class.php");
|
|
|
|
|
2012-05-18 19:56:57 +00:00
|
|
|
if (isset ($_POST['send']))
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
//Gets parameters: course, question and answers
|
|
|
|
$course = "";
|
|
|
|
$answers = array();
|
|
|
|
foreach ($_POST as $key => $value)
|
2012-05-18 20:50:06 +00:00
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
if ($key == "question")
|
|
|
|
$question = $value;
|
|
|
|
else if ($key == "course")
|
|
|
|
$course = $value;
|
|
|
|
else if (preg_match("#^answer#", $key))
|
|
|
|
$answers[] = $value;
|
2012-05-18 20:50:06 +00:00
|
|
|
}
|
2012-05-22 01:34:24 +00:00
|
|
|
|
|
|
|
//Check we have at least a question and an answer
|
|
|
|
if (empty($question))
|
|
|
|
die("Veuillez indiquer une question !");
|
|
|
|
else if (count($answers) <= 0)
|
|
|
|
die("Veuillez indiquer au moins une réponse correcte !");
|
2012-05-18 20:50:06 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
$quest = Question::new_Question($question, $answers, $course);
|
|
|
|
$quest->print_test();
|
2012-05-18 19:56:57 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
// @TODO: Create/Load a QuestionFile and add the question (it must be unique)
|
2012-05-22 07:38:37 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
// @TODO: Find a validator (from the list of previous senders for example?)
|
2012-05-22 07:38:37 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
// @TODO: Update the question and save the file
|
2012-05-22 07:38:37 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
// @TODO: Send mail to the selected validator
|
2012-05-21 15:10:40 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
/* This code works, perhaps should be placed in a method in Question class?
|
2012-05-21 15:19:32 +00:00
|
|
|
$to = "bertrand.cournaud@gmail.com";
|
2012-05-22 01:34:24 +00:00
|
|
|
$subject = "[Nemubot] Validation d'une question";
|
|
|
|
$headers = "From: Nemubot <bot@nemunai.re>";
|
|
|
|
$message = "Bonjour,\n";
|
2012-05-21 15:19:32 +00:00
|
|
|
|
2012-05-21 15:33:12 +00:00
|
|
|
if (mail($to, $subject, $message, $headers))
|
2012-05-21 15:19:32 +00:00
|
|
|
{
|
|
|
|
echo ("Email sent");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
echo ("Error with the email");
|
2012-05-22 01:34:24 +00:00
|
|
|
//*/
|
2012-05-18 20:50:06 +00:00
|
|
|
}
|
2012-05-18 19:56:57 +00:00
|
|
|
}
|
2012-05-22 01:34:24 +00:00
|
|
|
else
|
|
|
|
header("Location: ./");
|
2012-05-18 19:56:57 +00:00
|
|
|
|
|
|
|
?>
|