diff --git a/Question.class.php b/Question.class.php
index cf5f5a3..ab31650 100644
--- a/Question.class.php
+++ b/Question.class.php
@@ -121,6 +121,11 @@ class Question
$this->getNormalId();
}
+ public function getAddedTime()
+ {
+ return $this->added_time;
+ }
+
public function getId()
{
return $this->id;
@@ -143,6 +148,11 @@ class Question
return $this->validated;
}
+ public function isValidation()
+ {
+ return $this->id == md5($this->added_time.$this->validator) && $this->validator != $this->writer;
+ }
+
public function getCourse()
{
return Course::getCourse($this->course);
@@ -185,6 +195,28 @@ class Question
$this->writer = $writer->getId();
}
+ public function convert()
+ {
+ foreach (Course::getCourses() as $c)
+ {
+ if ($c->getCode() == $this->course)
+ {
+ $this->course = $c->getId();
+ return $c->getId();
+ }
+ }
+ return $this->course;
+ /*foreach (User::getUsers() as $u)
+ {
+ if ($u->getEmail() == $this->validator)
+ {
+ $this->validator = $u->getId();
+ return $u->getId();
+ }
+ }
+ return $this->validator;*/
+ }
+
public function setAnswer($answers)
{
if ($this->answers != $answers)
diff --git a/QuestionsFile.class.php b/QuestionsFile.class.php
index 456205a..a8f1755 100644
--- a/QuestionsFile.class.php
+++ b/QuestionsFile.class.php
@@ -47,6 +47,11 @@ class QuestionsFile
$this->tmp[$question->getId()] = $question;
}
+ public function del_question($question)
+ {
+ unset($this->tmp[$question->getId()]);
+ }
+
/**
* Get a question from its unique identifiant
*/
@@ -67,6 +72,28 @@ class QuestionsFile
return NULL;
}
+ public function get_ids()
+ {
+ $ret = array();
+
+ $qs = $this->treeXML->getElementsByTagName("question");
+ foreach($qs as $q)
+ $ret[] = $q->getAttribute("xml:id");
+
+ return $ret;
+ }
+
+ public function get_questions()
+ {
+ $ret = array();
+
+ $qs = $this->treeXML->getElementsByTagName("question");
+ foreach($qs as $q)
+ $ret[] = new Question($q);
+
+ return $ret;
+ }
+
/**
* Write changes into the real file
*/
@@ -84,8 +111,15 @@ class QuestionsFile
$this->treeXML->formatOutput = true;
$this->treeXML->save($this->filename);
}
-
-
}
+/*
+$file = new QuestionsFile("questions.xml");
+foreach ($file->get_ids() as $id)
+{
+ $q = $file->get_question($id);
+ echo $q->convert()."
";
+}
+$file->save();
+//*/
?>
\ No newline at end of file
diff --git a/User.class.php b/User.class.php
index 60c5fe9..f6a181d 100644
--- a/User.class.php
+++ b/User.class.php
@@ -8,6 +8,7 @@ class User
private $email;
private $registerdate;
private $validated = false;
+ private $admin = false;
public function __construct($node = null)
{
@@ -17,6 +18,8 @@ class User
$this->registerdate = $node->getAttribute("registerdate");
if (intval($node->getAttribute("validated")))
$this->validated = true;
+ if (intval($node->getAttribute("admin")))
+ $this->admin = true;
$this->username = $node->getAttribute("username");
$this->password = $node->getAttribute("password");
$this->email = $node->getAttribute("email");
@@ -31,7 +34,7 @@ class User
$u->email = $email;
$u->username = $username;
if (isset($password))
- $this->password = getPassword($username, $password);
+ $u->password = $u->getPassword($username, $password);
return $u;
}
@@ -78,9 +81,12 @@ class User
$treeXML = new DOMDocument('1.0', 'UTF-8');
if (@$treeXML->load($filename))
- return new User($treeXML->getElementById($id));
- else
- return null;
+ {
+ $u = $treeXML->getElementById($id);
+ if (!empty($u))
+ return new User($u);
+ }
+ return null;
}
public static function setUsers($users, $filename = "users.xml")
@@ -102,17 +108,17 @@ class User
$qnode->setAttribute("xml:id", $this->id);
$qnode->setAttribute("username", $this->username);
- $qnode->setAttribute("password", intval($this->password));
+ $qnode->setAttribute("password", $this->password);
$qnode->setAttribute("email", $this->email);
$qnode->setAttribute("registerdate", $this->registerdate);
- $qnode->setAttribute("validated", $this->validated);
+ $qnode->setAttribute("validated", intval($this->validated));
return $qnode;
}
public function canConnect($password)
{
- $hash = getPassword($this->username, $password);
+ $hash = $this->getPassword($this->username, $password);
return ($hash == $this->password);
}
@@ -146,6 +152,11 @@ class User
{
return $this->validated;
}
+
+ public function isAdmin()
+ {
+ return $this->admin;
+ }
}
/*
@@ -158,6 +169,14 @@ User::setUsers($us);
/*
$us = User::getUsers();
+$u = User::new_User("ircquizz@p0m.fr", "nemunaire", "u6tn84");
+$us[] = $u;
+
+User::setUsers($us);
+//*/
+/*
+$us = User::getUsers();
+
$u = User::new_User("bertrand@cournaud.fr", "Cccompany");
$us[] = $u;
diff --git a/addCourse.php b/addCourse.php
index 34bfad1..eb7d263 100644
--- a/addCourse.php
+++ b/addCourse.php
@@ -3,8 +3,10 @@ include ("header.html");
require_once("Course.class.php");
-//if (empty($_SESSION["connected"]))
-// die("
- Proposée par : get_writer()->getUsername(); ?>
+ get_writer() != null)
+ {?>Proposée par : get_writer()->getUsername(); ?>
Cours concerné : getCourse()->getName(); ?>
Question posée : getQuestion(); ?>
Réponses valides exhaustives :
@@ -41,7 +43,7 @@ else