This repository has been archived on 2020-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
nemubot-askweb/questions.php

75 lines
1.7 KiB
PHP
Executable File

<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
</head>
<body>
<?php
error_reporting(E_ALL);
define("FILENAME", "questions_file.nemubot");
include("Question.class.php");
include("QuestionsFile.class.php");
if (isset ($_POST['send']))
{
//Gets parameters: course, question and answers
$course = "";
$answers = array();
foreach ($_POST as $key => $value)
{
if ($key == "question")
$question = $value;
else if ($key == "course")
$course = $value;
else if (preg_match("#^answer#", $key))
$answers[] = $value;
}
//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 !");
else
{
$quest = Question::new_Question($question, $answers, $course);
$quest->print_test();
// @TODO: Create/Load a QuestionFile and add the question (it must be unique)
$file = new QuestionsFile('questions.xml');
$file->add_question($quest);
$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
/* This code works, perhaps should be placed in a method in Question class?*/
$to = "bertrand.cournaud@gmail.com";
$subject = "[Nemubot] Validation d'une question";
$headers = "From: Nemubot <bot@nemunai.re>";
$message = "Bonjour,\n";
if (mail($to, $subject, $message, $headers))
{
echo ("Email sent");
}
else
echo ("Error with the email");
/* //*/
}
}
else
header("Location: ./");
?>
</body>
</html>