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
Raw Normal View History

2012-05-22 09:18:26 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
</head>
2012-05-18 19:56:57 +00:00
2012-05-22 09:18:26 +00:00
<body>
<?php
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
include("Question.class.php");
include("QuestionsFile.class.php");
2012-05-18 19:56:57 +00:00
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();
2012-05-18 19:56:57 +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 07:38:37 +00:00
// @TODO: Find a validator (from the list of previous senders for example?)
2012-05-22 07:38:37 +00:00
// @TODO: Update the question and save the file
2012-05-22 07:38:37 +00:00
// @TODO: Send mail to the selected validator
2012-05-21 15:10:40 +00:00
2012-05-22 11:29:51 +00:00
/* This code works, perhaps should be placed in a method in Question class?*/
2012-05-22 09:18:26 +00:00
$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");
2012-05-22 11:29:51 +00:00
/* //*/
}
2012-05-18 19:56:57 +00:00
}
else
header("Location: ./");
2012-05-18 19:56:57 +00:00
?>
2012-05-22 09:18:26 +00:00
</body>
</html>