load($id); } } function load($id) { if (is_numeric($id)) { $data = query_row("SELECT * FROM " . DB_PREFIX . "answer WHERE id='{$id}'"); if ($data) { $this->id = $id; $this->setExaminee($data->examinee); $this->setTest($data->test); $this->setBegin($data->begin); $this->setEnd($data->end); $this->setLastPage($data->last_page); $this->setCurrentPage($data->current_page); $this->setChapter($data->chapter); return $data; } } return false; } function create() { $this->setExaminee(get_examinee()->getId()); $insert = query_insert("INSERT INTO " . DB_PREFIX . "answer (test, examinee, begin) values (".$this->getTest().", ".$this->getExaminee().", NOW() )"); return $insert; } function createChapter($chap) { $this->setExaminee(get_examinee()->getId()); $insert = query_insert("INSERT INTO " . DB_PREFIX . "chapter (answer, examinee, chapter) values (".$this->getId().", ".$this->getExaminee().", ".$chap.")"); return $insert; } function hasChapter($chap) { $examinee = get_examinee()->getId(); $q = query_row("SELECT * FROM " . DB_PREFIX . "chapter WHERE !locked AND examinee=".$examinee." AND chapter=".$chap." AND answer=".$this->getId()); if ($q) return true; return false; } function closeChapter() { if (get_examinee()->getId()==$this->examinee) { return query_update("UPDATE " . DB_PREFIX . "chapter SET locked=1 WHERE chapter=".$this->chapter." AND answer=".$this->getId()." AND examinee=".$this->examinee); } return false; } function stop() { if (get_examinee()->getId()==$this->examinee) { return $update = query_update("UPDATE " . DB_PREFIX . "answer SET end=NOW() WHERE id=".$this->getId()); } return false; } function nextChapter($chap) { if ($chap != $this->getChapter() && get_examinee()->getId()==$this->examinee) { return $update = query_update("UPDATE " . DB_PREFIX . "answer SET chapter=".$chap." WHERE id=".$this->getId()); } return false; } function resetChapter() { if (get_examinee()->getId()==$this->examinee) { $this->closeChapter(); return $update = query_update("UPDATE " . DB_PREFIX . "answer SET chapter=NULL, last_page=-1, current_page=0 WHERE id=".$this->getId()); } } function nextPage() { if (get_examinee()->getId()==$this->examinee) { return $update = query_update("UPDATE " . DB_PREFIX . "answer SET last_page=last_page+1, current_page=current_page+1 WHERE id=".$this->getId()); } return false; } function delete() { if (is_numeric($this->getId()) && $this->getId() > 0) { if (is_admin()) { return query("DELETE FROM " . DB_PREFIX . "answer WHERE id=".$this->getId()); } } return false; } public function getId() { return $this->id; } public function getType() { return $this->type; } public function getName() { return $this->name; } function getExaminee() { return $this->examinee; } function setExaminee($examinee) { $this->examinee = $examinee; } public function getTest() { return $this->test; } function setTest($test) { $this->test = $test; } public function getBegin() { return $this->begin; } function setBegin($begin) { $this->begin = $begin; } public function getEnd() { return $this->end; } function setEnd($end) { $this->end = $end; } public function getLastPage() { return $this->last_page; } function setLastPage($last_page) { $this->last_page = $last_page; } public function getCurrentPage() { return $this->current_page; } function setCurrentPage($current_page) { $this->current_page = $current_page; } public function getChapter() { return $this->chapter; } function setChapter($chap) { $this->chapter = $chap; } } ?>