diff --git a/Question.class.php b/Question.class.php index 9904b45..e81be18 100644 --- a/Question.class.php +++ b/Question.class.php @@ -63,12 +63,12 @@ class Question * @param $answer The answer string * @param $scrore The score given by this answer */ - private function gen_anode($answer, $score = 1) + private function gen_anode($treeXML, $answer, $score = 1) { - $anode = $this->treeXML->createElement("answer"); + $anode = $treeXML->createElement("answer"); - $qnode->setAttribute("answer", $answer); - $qnode->setAttribute("score", $score); + $anode->setAttribute("answer", $answer); + $anode->setAttribute("score", $score); return $anode; } @@ -87,8 +87,8 @@ class Question $qnode->setAttribute("course", $this->course); $qnode->setAttribute("question", $this->question); - foreach ($answers as $ans) - $qnode->appendChild(gen_anode($ans)); + foreach ($this->answers as $ans) + $qnode->appendChild($this->gen_anode($root, $ans)); return $qnode; } diff --git a/QuestionsFile.class.php b/QuestionsFile.class.php index 5cfc12a..743f600 100644 --- a/QuestionsFile.class.php +++ b/QuestionsFile.class.php @@ -6,6 +6,7 @@ class QuestionsFile { private $filename; private $treeXML; + private $root_node; public function __construct($filename) { @@ -22,7 +23,7 @@ class QuestionsFile $this->treeXML = new DOMDocument('1.0', 'UTF-8'); $this->treeXML->formatOutput = true; - if (isfile($this->filename)) + if (is_file($this->filename)) { $this->treeXML->load($this->filename); @@ -45,7 +46,7 @@ class QuestionsFile */ public function add_question($question) { - $this->root_node->appendChild($question->to_xml($this->root_node)); + $this->root_node->appendChild($question->to_xml($this->treeXML)); } /** diff --git a/questions.php b/questions.php index c0270b7..4e81225 100755 --- a/questions.php +++ b/questions.php @@ -3,7 +3,7 @@ define("FILENAME", "questions_file.nemubot"); include("Question.class.php"); -include("QuestionsFile.php"); +include("QuestionsFile.class.php"); if (isset ($_POST['send'])) {