/** * Edit this player's character name */ function edit_name($player_id = 0) { $page = $this->page; // Player must exist $this->load->model('playermodel'); $player = $this->playermodel->get_by_id($player_id); validate_exists($player->player_id, 'No such player.', 'home/dashboard'); // Player must be owned by the currently logged in user validate_matches($player->user_id, $page['user']->id, 'You don\'t own that ', 'home/dashboard'); // Validate form $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Name', 'required|max_length[200]'); if ($this->form_validation->run() == FALSE) { // Show the form $page['player'] = $player; $page['content'] = 'player_edit_name_form'; $this->load->view('template', $page); } else { // Update the player $playerupdate = new stdClass(); $playerupdate->name = $this->input->post('name'); $this->playermodel->update($player_id, $playerupdate); $this->session->set_flashdata('notice', 'Player Name Updated.'); redirect('player/view/' . $player_id, 'refresh'); } }
/** * Delete an order */ function delete($command_id = 0, $order_id = 0) { $page = $this->page; // Command and orders must exist $this->load->model('commandmodel'); $command = $this->commandmodel->get_by_id($command_id); validate_exists($command->command_id, 'No such command.', 'home/dashboard'); $this->load->model('ordermodel'); $order = $this->ordermodel->get_by_id($order_id); validate_exists($order->order_id, 'No such order.', 'command/view/' . $command_id); // Must be playing on the commands faction and have permission $this->load->model('gamemodel'); $game = $this->gamemodel->get_by_id($command->game_id); $this->load->model('playermodel'); $player = $this->playermodel->get_by_user_game($page['user']->id, $game->game_id); validate_matches($command->faction_id, $player->faction_id, 'Not authorized.', 'game/view/' . $game->game_id); $this->load->model('ordermodel'); $this->ordermodel->delete($order_id); $this->session->set_flashdata('notice', 'Order deleted.'); redirect('command/view/' . $command_id, 'refresh'); }