128 lines
3.1 KiB
PHP
Executable File
128 lines
3.1 KiB
PHP
Executable File
<!DOCTYPE html>
|
|
|
|
<?php
|
|
|
|
//error_reporting(E_ALL);
|
|
define("FILENAME", "questions_file.nemubot");
|
|
|
|
|
|
include("Question.class.php");
|
|
include("QuestionsFile.class.php");
|
|
|
|
function isInList($mail)
|
|
{
|
|
$file = fopen('email.txt', 'r');
|
|
$number = fgets($file);
|
|
$i = 0;
|
|
$file_mail = fgets($file);
|
|
|
|
while ($i < $number)
|
|
{
|
|
if (trim($mail) == trim($file_mail))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
$file_mail = fgets($file);
|
|
$i++;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Change this variable depending on the server
|
|
$confirmationAddress = "confirmation.php?id=";
|
|
|
|
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) && $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 if (count($_POST['email']) <= 0 || !isInList($_POST['email']))
|
|
die("Veuillez indiquer une adresse mail valide");
|
|
else
|
|
{
|
|
$quest = Question::new_Question($question, $answers, $course);
|
|
$quest->set_validator($_POST['email']);
|
|
|
|
// @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
|
|
|
|
// Get an email from the list
|
|
|
|
/* This code works, perhaps should be placed in a method in Question class?*/
|
|
$to = $_POST['email'];
|
|
$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"
|
|
|
|
."Rappels de la questions:\n"
|
|
.'Cours concerné : ' . $course . "\n"
|
|
.'La question est : ' . $question . "\n"
|
|
.'Les réponses sont : ' . print_r($answers, true) . "\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"
|
|
|
|
."Adresse de confirmation de la question:\n"
|
|
. "http://".$_SERVER["SERVER_NAME"]
|
|
. dirname($_SERVER["REQUEST_URI"])."/changeQuestion.php?id="
|
|
. $quest->getId()
|
|
|
|
. "\n\n Merci beaucoup de votre participation\n"
|
|
."Cordialement,\n"
|
|
|
|
."-- \nNemubot.";
|
|
;
|
|
|
|
|
|
if ($quest->mail_utf8($to, $subject, $message, $headers))
|
|
{
|
|
echo ("Email sent");
|
|
}
|
|
else
|
|
echo ("Error with the email");
|
|
//*/
|
|
}
|
|
header("Location: ./thanks.php?id=" . $quest->getId());
|
|
}
|
|
else
|
|
header("Location: ./");
|
|
|
|
?>
|
|
|
|
<html>
|
|
<head>
|
|
<meta charset="utf8" />
|
|
</head>
|
|
|
|
<body>
|
|
</body>
|
|
</html>
|