Mysql($faqDB); $this->data = $data; } // Is this instance valid? function isValid() { if ($this->data["active"] <> "" && $this->data["major"] <> "" && $this->data["minor"] <> "" && $this->data["release"] <> "" && $this->data["beta"] <> "" && $this->data["patchlevel"] <> "" && $this->data["version_name"] <> "") { return true; } else { return false; } } // Access to member variables function getID() { return $this->data["id"]; } function setActive($g) { $this->data["active"] = $g; } function getActive() { return $this->data["active"]; } function setName($p) { $this->data["version_name"] = $p; } function getName() { return $this->data["version_name"]; } function setVersion($major, $minor, $release, $beta, $patchlevel) { $this->data["major"] = $major; $this->data["minor"] = $minor; $this->data["release"] = $release; $this->data["beta"] = $beta; $this->data["patchlevel"] = $patchlevel; } function getMajor() { return $this->data["major"]; } function getMinor() { return $this->data["minor"]; } function getRelease() { return $this->data["release"]; } function getBeta() { return $this->data["beta"]; } function getPatchlevel() { return $this->data["patchlevel"]; } 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 version (only if the version does not already exist) function create() { global $theUser; global $verTable; if (!$this->isValid()) return; // Ensure that this one doesn't already exist $name = $this->getName(); $q = "SELECT * FROM $verTable WHERE version_name = '$name'"; $foo = $this->do_query($q, 1); if ($foo[0]->isValid()) return; $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $q = "INSERT INTO $verTable VALUES (1, NULL, " . ($this->getActive() ? "1" : "0") . ", " . $this->getMajor() . ", " . $this->getMinor() . ", " . $this->getRelease() . ", " . $this->getBeta() . ", " . $this->getPatchlevel() . ", '$name', '" . $this->getLastModDate() . "', '" . $this->getLastModUser() . "')"; $this->do_query($q, 0); // Update the global "last updated" date $sys = new System(); $sys->update(); } // Update a version (only if the version already exists) function update() { global $theUser; global $verTable; if (!$this->isValid()) return; // Set the right values $this->setLastModDate(date("Y-m-d")); $this->setLastModUser($theUser->getID()); $name = $this->getName(); $q = "UPDATE $verTable SET active = " . ($this->getActive() ? "1" : "0") . ", " . "major = " . $this->getMajor() . ", " . "minor = " . $this->getMinor() . ", " . "release = " . $this->getRelease() . ", " . "beta = " . $this->getBeta() . ", " . "patchlevel = " . $this->getPatchlevel() . ", " . "version_name = '$name', " . "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 Versions function doVerQuery($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 Version($quests[$i]->getData()); else $ret[] = new Version(""); return $ret; } // Function to return an array of all versions in objects function getAllVers() { global $verTable; return doVerQuery("SELECT * FROM $verTable", 1); } // Function to return an array of all versions in objects in an // associative array, indexed by ID number function getAllVersAssoc() { global $verTable; $vers = getAllVers(); if ($vers[0]->isValid()) for ($i = 0; $i < sizeof($vers); $i++) $ret[$vers[$i]->getID()] = $vers[$i]; else $ret = $vers; return $ret; } // Find a version by ID number function getVerByID($id) { global $verTable; $vers = doVerQuery("SELECT * FROM $verTable WHERE id = $id", 1); return $vers[0]; } // Delete a version by ID number function deleteVerByID($id) { global $verTable; $vers = doVerQuery("DELETE FROM $verTable WHERE id = $id", 0); return $vers[0]; } }