setMessage(""); $this->setGames(array(0,0,0,0)); if ( isset($_GET['gamepackid']) && is_numeric($_GET['gamepackid']) ) { $this->setFolderid($_GET['gamepackid']); } else if ( isset($_SESSION['gamepackid']) && is_numeric($_SESSION['gamepackid']) ) { $this->setFolderid($_SESSION['gamepackid']); } } else { global $kdb; $this->kdb = $kdb; $typeData = $kdb->getTypeData($rid, self::$table); $this->setMessage($typeData['message']); $this->setGames(unserialize($typeData['games'])); } } public function getGamepackid() { return $this->folderid; } protected function setGames($d) { $this->games = $d; } public function getGames() { return $this->games; } protected function setMessage($d) { $this->message = $d; } public function getMessage() { return $this->message; } public function getUrl() { return "index.php?rid=".$this->getResourceID(); } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function setGameToSlot($slot, $gid) { $games = $this->getGames(); $games[$slot-1] = (int) $gid; $this->kdb->query("UPDATE psyhvel_gamesheet SET games='".serialize($games)."' WHERE resourceID=".$this->getResourceID()); } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function removeGameSlot($slot) { $games = $this->getGames(); $games[$slot-1] = 0; $this->kdb->query("UPDATE psyhvel_gamesheet SET games='".serialize($games)."' WHERE resourceID=".$this->getResourceID()); } /** * @Secured('roles' = {'authenticated'}, 'valid' = {}) * */ public function getGameObjects() { $gids = $this->getGames(); $obs = array(); foreach ($gids as $gid) { if ($gid) { $obs []= $this->kdb->getResourceByRID($gid); } else { $obs []= false; } } return $obs; } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function actionSave() { $mode = "view"; if ($this->getResourceID() == "new"){ $mode = "compile"; } $this->updateData($_POST); $this->save(); $_SESSION['psyhvel_notice'] = gettext("Saved"); return array('rid' => $this->getResourceID(), 'mode' => $mode); } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function actionCopy() { global $kdb; $this->updateData($_POST); $rid = $this->getResourceID(); parent::copy(); if ($this->getResourceID() != $rid){ $res = $kdb->query("INSERT INTO psyhvel_gamesheet (resourceID, games, message) values (".$this->getResourceID().", '".serialize($this->getGames())."', '".$this->getMessage()."')"); if ($res) { $_SESSION['psyhvel_notice'] = gettext("You have new copy of")." \"".gettext("Gamesheet")."\""; } else { $_SESSION['psyhvel_notice'] = gettext("Making copy failed"); } } return array('rid' => $this->getResourceID(), 'mode' => 'view'); } protected function save() { global $kdb; $rid = $this->getResourceID(); parent::save(); if ($rid == "new" || $this->getResourceID() != $rid){ $kdb->query("INSERT INTO psyhvel_gamesheet (resourceID, games, message) values (".$this->getResourceID().", '".serialize($this->getGames())."', '".$this->getMessage()."')"); } } /** * @Secured('roles' = {'member'}, 'valid' = {}) * */ public function actionCompile() { $_SESSION['psyhvel_notice'] = gettext("Problem"); if (isset($_POST['message'])) { $this->setMessage($_POST['message']); } $res = $this->kdb->query("UPDATE psyhvel_gamesheet SET games='".serialize($this->getGames())."', message='".$this->getMessage()."' WHERE resourceID=".$this->getResourceID()); if ($res) { $_SESSION['psyhvel_notice'] = gettext("Saved"); } return array('rid' => $this->getResourceID(), 'mode' => "compile"); } } if ( isset($_GET['rid']) && is_numeric($_GET['rid']) && isset($_GET['removeslot']) && is_numeric($_GET['removeslot']) ) { $gs = NEW Gamesheet($_GET['rid']); $gs->removeGameSlot($_GET['removeslot']); return array('rid' => $gs->getResourceID(), 'mode' => "compile"); } ?>