2012-05-22 09:18:26 +00:00
|
|
|
<!DOCTYPE html>
|
2012-05-22 14:05:46 +00:00
|
|
|
|
2012-05-23 14:02:40 +00:00
|
|
|
<?php
|
2012-05-22 09:18:26 +00:00
|
|
|
|
2012-05-23 14:02:40 +00:00
|
|
|
//error_reporting(E_ALL);
|
2012-05-18 20:11:42 +00:00
|
|
|
define("FILENAME", "questions_file.nemubot");
|
|
|
|
|
2012-05-22 09:18:26 +00:00
|
|
|
|
2012-05-22 01:34:24 +00:00
|
|
|
include("Question.class.php");
|
2012-05-22 08:44:16 +00:00
|
|
|
include("QuestionsFile.class.php");
|
2012-05-22 01:34:24 +00:00
|
|
|
|
2012-05-24 21:14:19 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-05-23 12:05:08 +00:00
|
|
|
|
2012-05-23 12:56:34 +00:00
|
|
|
// Change this variable depending on the server
|
2012-05-23 16:16:55 +00:00
|
|
|
$confirmationAddress = "confirmation.php?id=";
|
2012-05-23 12:56:34 +00:00
|
|
|
|
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;
|
2012-06-09 21:24:41 +00:00
|
|
|
else if (preg_match("#^answer#", $key) && $key != "")
|
2012-05-22 01:34:24 +00:00
|
|
|
$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-24 21:14:19 +00:00
|
|
|
else if (count($_POST['email']) <= 0 || !isInList($_POST['email']))
|
2012-05-23 16:16:55 +00:00
|
|
|
die("Veuillez indiquer une adresse mail valide");
|
2012-05-18 20:50:06 +00:00
|
|
|
else
|
|
|
|
{
|
2012-05-22 01:34:24 +00:00
|
|
|
$quest = Question::new_Question($question, $answers, $course);
|
2012-05-23 16:16:55 +00:00
|
|
|
$quest->set_validator($_POST['email']);
|
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 08:00:59 +00:00
|
|
|
$file = new QuestionsFile('questions.xml');
|
|
|
|
$file->add_question($quest);
|
|
|
|
$file->save();
|
2012-05-22 14:05:46 +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-23 13:36:16 +00:00
|
|
|
// Get an email from the list
|
|
|
|
|
2012-05-23 16:27:42 +00:00
|
|
|
/* This code works, perhaps should be placed in a method in Question class?*/
|
2012-05-23 16:16:55 +00:00
|
|
|
$to = $_POST['email'];
|
2012-05-24 12:19:45 +00:00
|
|
|
$subject = "[Nemubot] Confirmation d'une question";
|
2012-05-22 14:05:46 +00:00
|
|
|
$headers = "From: Nemubot <bot@nemunai.re>";
|
2012-05-24 13:20:56 +00:00
|
|
|
$message = "Bonjour,\n"
|
|
|
|
."Une nouvelle question a été proposée à Nemubot en utilisant
|
|
|
|
cette adresse email.\n\n"
|
2012-05-24 12:19:45 +00:00
|
|
|
|
2012-05-24 21:14:19 +00:00
|
|
|
."Rappels de la questions:\n"
|
|
|
|
.'Cours concerné : ' . $course . "\n"
|
|
|
|
.'La question est : ' . $question . "\n"
|
|
|
|
.'Les réponses sont : ' . print_r($answers, true) . "\n"
|
|
|
|
|
2012-05-24 13:20:56 +00:00
|
|
|
."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"
|
2012-05-24 12:19:45 +00:00
|
|
|
|
2012-05-24 13:20:56 +00:00
|
|
|
."Adresse de confirmation de la question:\n"
|
|
|
|
. "http://".$_SERVER["SERVER_NAME"]
|
2012-05-24 12:19:45 +00:00
|
|
|
. dirname($_SERVER["REQUEST_URI"])."/confirmation.php?id="
|
|
|
|
. $quest->getId()
|
|
|
|
|
2012-05-24 13:20:56 +00:00
|
|
|
. "\n\n Merci beaucoup de votre participation\n"
|
|
|
|
."Cordialement,\n"
|
2012-05-24 12:19:45 +00:00
|
|
|
|
2012-05-24 13:20:56 +00:00
|
|
|
."-- \nNemubot.";
|
2012-05-24 12:19:45 +00:00
|
|
|
;
|
|
|
|
|
2012-05-22 14:05:46 +00:00
|
|
|
|
2012-06-11 21:29:10 +00:00
|
|
|
if ($quest->mail_utf8($to, $subject, $message, $headers))
|
2012-05-22 14:05:46 +00:00
|
|
|
{
|
|
|
|
echo ("Email sent");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
echo ("Error with the email");
|
|
|
|
//*/
|
2012-05-18 20:50:06 +00:00
|
|
|
}
|
2012-05-25 09:14:34 +00:00
|
|
|
header("Location: ./thanks.php?id=" . $quest->getId());
|
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
|
|
|
|
|
|
|
?>
|
2012-05-25 09:14:34 +00:00
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta charset="utf8" />
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
</body>
|
|
|
|
</html>
|