public function register_kill() { import('trouble.kill'); import('core.validation'); try { $validator = \Core\Validator::validator('\\Trouble\\Kill'); $validator->validate($_POST, \Trouble\Kill::validation()); $this->_game_action(function ($agent_id) { $now = new \DateTime(); if (empty($_POST['when_happened_date'])) { $date = $now->format('Y-m-d'); } else { $date = $_POST['when_happened_date']; } if (empty($_POST['when_happened_time'])) { $time = $now->format('H:i'); } else { $time = $_POST['when_happened_time']; } $_POST['when_happened'] = new \DateTime($date . $time); $game = \Trouble\Game::container()->get_by_id($_POST['game_id'])->kill_agent_target($agent_id, $_POST); }, 'Kill registered.'); } catch (\Trouble\GameIncorrectPKNError $e) { echo $this->_return_message("Error", "Incorrect PKN. If believed to be correct, please contact game administrator."); } catch (\Trouble\KillTooEarlyError $e) { echo $this->_return_message("Error", "Kill date too early for game."); } catch (\Trouble\KillTooLateError $e) { echo $this->_return_message("Error", "Kill date too late for game."); } catch (\Trouble\KillInFutureError $e) { echo $this->_return_message("Error", "Kill date in future. We don't allow time travellers."); } catch (\Core\ValidationError $e) { echo $this->_return_message("Error", "Validation error(s):", $e->get_errors()); } catch (\Exception $e) { $this->_unhandled_exception($e); } }
protected function _edit_article($tok, $author, $id=False) { $t = \Plugins\Articles\Plugin::get_template('admin/edit.php'); $t->admin_url = "/admin"; $t->tok = $tok; try { if($id) { $t->title = "Edit Article"; $article = \Plugins\Articles\Article::container() ->get_by_id($id); } else { $t->title = "Create Article"; $t->new = True; $article = \Plugins\Articles\Article::create($_POST, True); } if($_POST['_do'] == '1' && $this->_confirmed_request) { $article->overwrite($_POST); $article->form_values(); $validator = \Core\Validator::validator('\Plugins\Articles\Article'); $validator->validate($_POST, \Plugins\Articles\Article::validation()); if($t->new) { $article->author = $author; } \Core\Storage::container() ->get_storage('Article') ->save($article); } $t->article = $article; } catch(\Core\ValidationError $e) { return $this->_return_message("Fail", "Validation error(s):", $e->get_errors(), $t); } return $t->render(); }