Mysql($faqDB); $this->data = $data; } // Is this instance valid? function isValid() { if ($this->data["active"] <> "" && $this->data["title"] <> "" && $this->data["answer"] <> "") { return true; } else { return false; } } // Access to member variables function setID($i) { $this->data["id"] = $i; } function getID() { return $this->data["id"]; } function setActive($g) { $this->data["active"] = $g; } function getActive() { return $this->data["active"]; } function setTitle($p) { $this->data["title"] = $p; } function getTitle() { return $this->data["title"]; } function setAnswer($p) { $this->data["answer"] = $p; } function getAnswer() { return $this->data["answer"]; } function setVersion($p) { $this->data["version"] = $p; } function getVersions() { return $this->data["versions"]; } function setLastModDate($d) { $this->data["last_mod_date"] = $d; } function getLastModDate() { return $this->data["last_mod_date"]; } function setLastModUser($u) { $this->data["last_mod_user"] = $u; } function getLastModUser() { return $this->data["last_mod_user"]; } // Create a question (only if the question does not already exist) function create() { global $theUser; global $questTable; if (!$this->isValid()) return; // We're creating a new question, so get a sequence number $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $title = $this->getTitle(); $answer = $this->getAnswer(); $q = "INSERT INTO $questTable VALUES (1, NULL, " . ($this->getActive() ? "1" : "0") . ", '$title', '$answer', '" . "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@', '" . $this->getLastModDate() . "', '" . $this->getLastModUser() . "')"; $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } // Update a question (only if the question already exists) function update() { global $theUser; global $questTable; if (!$this->isValid()) return; // Set the right values $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $title = $this->getTitle(); $answer = $this->getAnswer(); $q = "UPDATE $questTable SET active = " . ($this->getActive() ? "1" : "0") . ", " . "title = '$title', " . "answer = '$answer', " . "versions = '" . $this->getVersions() . "', " . "last_mod_date = '" . $this->getLastModDate() . "', " . "last_mod_user = '" . $this->getLastModUser() . "' " . "WHERE id = " . $this->getID(); $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } } // Function to do a generic query and return an array of Questions function doQuestQuery($q, $want_rows) { global $faqDB; $m = new Mysql($faqDB); $quests = $m->do_query($q, $want_rows); if ($want_rows && $quests[0]->isValid()) for ($i = 0; $i < sizeof($quests); $i++) $ret[] = new Question($quests[$i]->getData()); else $ret[] = new Question(""); return $ret; } // Function to return an array of all questions in objects function getAllQuests() { global $questTable; return doQuestQuery("SELECT * FROM $questTable", 1); } // Function to return an array of all questions in objects in an // associative array by ID number function getAllQuestsAssoc() { global $questTable; $q = getAllQuests(); if ($q[0]->isValid()) for ($i = 0; $i < sizeof($q); $i++) $ret[$q[$i]->getID()] = $q[$i]; else $ret = $q; return $ret; } // Find a question by ID number function getQuestByID($id) { global $questTable; $cats = doQuestQuery("SELECT * FROM $questTable WHERE id = $id", 1); return $cats[0]; } // Delete a question by ID number function deleteQuestByID($id) { global $questTable; $cats = doQuestQuery("DELETE FROM $questTable WHERE id = $id", 0); // Must also delete all cross references deleteVerXrefByQID($id); deleteCatXrefByQID($id); return $cats[0]; } }