/** * Used to start/finish adding a link between a system and an owner * Optionally add a new system using the Systems model class * * @param array $options */ public function sysaddAction($options) { // get system object $system = new \Videogames\Model\Systems(); if (isset($_POST) && sizeof($_POST) > 0 && isset($_POST['own_id'])) { if (!isset($_POST['sys_id']) || $_POST['sys_id'] == '0') { if (!isset($_POST['sys_long']) || !isset($_POST['sys_short'])) { $this->errorMsg['error_msg'] = "No system passed!"; $this->render($this->errorPage, $this->errorMsg, $this->stdHeader); exit; } // Check if a system is known with given code $temp = $system->getSystemByCode($_POST['sys_short']); // No system exists, then add it if ($temp === false) { $system->add($_POST); $sys_id = \Videogames\Db::getInstance()->lastInsertId(); } else { // otherwise use this system (for now give an error) // $sys_id = $temp['sys_id']; $this->errorMsg['error_msg'] = "Abbreviation " . $_POST['sys_short'] . " already exsists!"; $this->render($this->errorPage, $this->errorMsg, $this->stdHeader); exit; } } else { $sys_id = $_POST['sys_id']; } $own_id = $_POST['own_id']; if ($this->data->addSystem(['own_id' => $own_id, 'sys_id' => $sys_id])) { header("Location: /owner/syslist/" . $own_id); exit; } else { $this->errorMsg['error_msg'] = "Add failed."; $this->render($this->errorPage, $this->errorMsg, $this->stdHeader); exit; } } if (!isset($options['own_id']) || empty($options['own_id'])) { $this->errorMsg['error_msg'] = "No owner ID passed!"; $this->render($this->errorPage, $this->errorMsg, $this->stdHeader); exit; } $owner = $this->data->getOwner($options['own_id']); if ($owner === false) { $this->errorMsg['error_msg'] = "Owner not found!"; $this->render($this->errorPage, $this->errorMsg, $this->stdHeader); exit; } $systems = $system->getAllSystems(); $sysown = $this->data->getSystems($options['own_id']); $this->render("owner/addsystem.phtml", ['owner' => $owner, 'systems' => $systems, 'sysown' => $sysown], $this->stdHeader); }
/** * Used to start/finish adding a game row to the database * $_POST is used to check/retrieve submitted data * * @param array $options * Can contain a game_id that is a placeholder for a sys_id */ public function addAction($options) { $_system = new \Videogames\Model\Systems(); if (isset($options['sys_id'])) { $this->actHeader = $this->altHeader; } if (isset($_POST) && sizeof($_POST) > 0) { $temp = $_system->getSystem($_POST['sys_id']); if ($temp === false) { $this->errorMsg['error_msg'] = "Can't find system!"; $this->render($this->errorPage, $this->errorMsg, $this->actHeader); exit; } $temp = $this->data->getGameByTitle($_POST['sys_id'], $_POST['game_title']); if ($temp === false) { if ($this->data->add($_POST)) { if (isset($options['sys_id'])) { header("Location: /games/" . $options['sys_id']); } else { header("Location: /game/list"); } exit; } else { $this->errorMsg['error_msg'] = "Add failed."; $this->render($this->errorPage, $this->errorMsg, $this->actHeader); exit; } } else { $this->errorMsg['error_msg'] = "Title " . $temp['game_title'] . "(" . $temp['sys_short'] . ") already exsists!"; $this->render($this->errorPage, $this->errorMsg, $this->actHeader); } } if (isset($options['sys_id'])) { $systems = $_system->getSystem($options['sys_id']); } else { $systems = $_system->getAllSystems(); } $this->render("game/add.phtml", ['systems' => $systems, 'games' => "dummy"], $this->actHeader); }