Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- *
- * @author Sebastian Büttner <sebastian.buettner@powerserverplus.net>
- * @package void
- * @version 1.0.0
- * @copyright (c) 2013, powerserverplus.net
- */
- /**
- * Show the login view
- */
- function admin_auth()
- {
- $tpl = new Template('admin/auth', 'admin/index');
- $tpl->display();
- }
- /**
- * Do a login try
- */
- function admin_auth_do()
- {
- if (isset($_POST['login']) && isset($_POST['password']))
- {
- $login = $_POST['login'];
- $password = $_POST['password'];
- if (Admin::auth($login, $password))
- {
- Redirect::to('admin/start', array('flash_notice' => 'Erfolgreich angemeldet!'));
- }
- }
- Redirect::to('admin/auth', array('flash_error' => 'Login fehlerhaft!'));
- }
- /**
- * Show the overview
- */
- function admin_start()
- {
- $tpl = new Template('admin/home', 'admin/index');
- $games = Game::all();
- $tpl->assign('games', $games);
- $tracks = Place::getTracks();
- foreach ($tracks as &$track) {
- $hole = Track::getTrackInfo($track['number']);
- $holeInOnes = Track::getHoleInOnes($track['id']);
- $overEleven = Track::getOverEleven($track['id']);
- $track['avg_tries'] = $hole['average_tries'];
- $track['description'] = $hole['description'];
- $track['hinone'] = $holeInOnes;
- $track['overelev'] = $overEleven;
- $track['allhits'] = $hole['allhits'];
- }
- $tpl->assign('tracks', $tracks);
- $tpl->display();
- }
- /**
- * Reset a game by given gameId
- */
- function admin_delete_game($gameId)
- {
- $result = Game::delete($gameId);
- if ($result)
- Redirect::to('admin/start', array('flash_notice' => 'Das Spiel mit der Id '. (int)$gameId .' wurde gelöscht.'));
- else
- Redirect::to('admin/start', array('flash_error' => 'Fehler beim Löschen des Spiels.'));
- }
- /**
- *
- */
- function admin_game($gameId)
- {
- $tpl = new Template('admin/game', 'admin/index');
- $game = Game::get2($gameId);
- $tpl->assign('game', $game);
- $players = Game::getPlayers($gameId);
- $tpl->assign('players', $players);
- $scores = Game::getScores($gameId);
- $tpl->assign('scores', $scores);
- $tracks = Place::getTracks();
- $tpl->assign('tracks', $tracks);
- $tpl->display();
- }
- /**
- *
- */
- function admin_game_do($gameId)
- {
- $game = Game::get($gameId);
- $game['player_count'] = (int)$_POST['player_max'];
- $game['valid_from'] = $_POST['valid_from'];
- $game['valid_to'] = $_POST['valid_to'];
- Game::save($game);
- $message = 'Spiel mit der Id ' . (int)$gameId . ' erfolgreich bearbeitet.';
- Redirect::to('admin/start', array('flash_notice' => $message));
- }
- /**
- *
- */
- function admin_create_game()
- {
- $gameId = Game::create();
- Redirect::to('admin/game/' . $gameId);
- }
- /**
- *
- */
- function admin_track($trackId)
- {
- $tpl = new Template('admin/track', 'admin/index');
- $hole = Track::getHoleByTrackId($trackId);
- /* Get Track-Statistics */
- $track = Track::getTrackInfo($hole);
- if (!$track) {
- echo 'Track not found';
- return;
- }
- /* More stats */
- $holeInOnes = Track::getHoleInOnes($track['id']);
- $overEleven = Track::getOverEleven($track['id']);
- $tpl = new Template('admin/track', 'admin/index');
- $tpl->assign('hole', array(
- 'id' => $track['id'],
- 'path' => $track['path'],
- 'max_trys' => $track['max_trys'],
- 'number' => $track['number'],
- 'avg_tries' => $track['average_tries'],
- 'difficulty' => $track['difficulty'],
- 'description' => $track['description'],
- 'rating' => $track['rating'],
- 'hinone' => $holeInOnes,
- 'overelev' => $overEleven,
- 'allhits' => $track['allhits']
- )
- );
- $tpl->assign('diffuculty_levels', array('<Unbewertet>', 'Einfach', 'Fortgeschritten', 'Mittel', 'Hart', 'Schwer'));
- $tpl->display();
- }
- /**
- *
- */
- function admin_track_do($trackId)
- {
- $track = Track::get($trackId);
- $track['number'] = (int)$_POST['number'];
- $track['difficulty'] = (int)$_POST['difficulty'];
- //$track['path'] = $_POST['path'];
- $track['description'] = $_POST['description'];
- $track['max_trys'] = (int)$_POST['max_trys'];
- Track::save($track);
- $message = 'Bahn mit der Id ' . (int)$trackId . ' erfolgreich bearbeitet.';
- Redirect::to('admin/start', array('flash_notice' => $message));
- }
- /**
- *
- */
- function admin_create_track()
- {
- $trackId = Track::create();
- Redirect::to('admin/track/' . $trackId);
- }
- /**
- * Reset a game by given trackId
- */
- function admin_delete_track($trackId)
- {
- $result = Track::delete($trackId);
- if ($result)
- Redirect::to('admin/start', array('flash_notice' => 'Die Bahn mit der Id '. (int)$trackId .' wurde gelöscht.'));
- else
- Redirect::to('admin/start', array('flash_error' => 'Fehler beim Löschen der Bahn.'));
- }
- /**
- *
- */
- function admin_grant_player($playerId)
- {
- Player::grant($playerId);
- $gameId = Player::getGameId($playerId);
- Redirect::to('admin/game/' . $gameId);
- }
- /**
- *
- */
- function admin_remove_player($playerId)
- {
- $gameId = Player::getGameId($playerId);
- Player::removeFromGame($playerId);
- Redirect::to('admin/game/' . $gameId);
- }
- /* ---------------------------------------------------- */
- if ( ! Admin::is_auth() && $_GET['subpage'] != 'auth' )
- Redirect::to('admin/auth');
- $action = preg_replace('/\W/', '', $_GET['subpage']);
- $method = $_SERVER['REQUEST_METHOD'] == 'GET' ? '' : '_do';
- $func = 'admin_' . $action . $method;
- if (function_exists($func))
- {
- $params = array();
- if (isset($_GET['id']))
- {
- $params[] = (int)$_GET['id'];
- }
- call_user_func_array($func, $params);
- }
- else
- Redirect::to('admin/start');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement