Advertisement
bueddl

Untitled

Sep 29th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4.  *
  5.  *
  6.  * @author Sebastian Büttner <sebastian.buettner@powerserverplus.net>
  7.  * @package void
  8.  * @version 1.0.0
  9.  * @copyright (c) 2013, powerserverplus.net
  10.  */
  11.  
  12. /**
  13.  * Show the login view
  14.  */
  15. function admin_auth()
  16. {
  17.     $tpl = new Template('admin/auth', 'admin/index');
  18.  
  19.     $tpl->display();
  20. }
  21.  
  22. /**
  23.  * Do a login try
  24.  */
  25. function admin_auth_do()
  26. {
  27.     if (isset($_POST['login']) && isset($_POST['password']))
  28.     {
  29.         $login = $_POST['login'];
  30.         $password = $_POST['password'];
  31.  
  32.         if (Admin::auth($login, $password))
  33.         {
  34.             Redirect::to('admin/start', array('flash_notice' => 'Erfolgreich angemeldet!'));
  35.         }
  36.     }
  37.  
  38.     Redirect::to('admin/auth', array('flash_error' => 'Login fehlerhaft!'));
  39. }
  40.  
  41. /**
  42.  * Show the overview
  43.  */
  44. function admin_start()
  45. {
  46.     $tpl = new Template('admin/home', 'admin/index');
  47.  
  48.     $games = Game::all();
  49.  
  50.     $tpl->assign('games', $games);
  51.  
  52.     $tracks = Place::getTracks();
  53.  
  54.     foreach ($tracks as &$track) {
  55.         $hole = Track::getTrackInfo($track['number']);
  56.  
  57.         $holeInOnes = Track::getHoleInOnes($track['id']);
  58.         $overEleven = Track::getOverEleven($track['id']);
  59.  
  60.         $track['avg_tries'] = $hole['average_tries'];
  61.         $track['description'] = $hole['description'];
  62.         $track['hinone'] = $holeInOnes;
  63.         $track['overelev'] = $overEleven;
  64.         $track['allhits'] = $hole['allhits'];
  65.     }
  66.  
  67.     $tpl->assign('tracks', $tracks);
  68.  
  69.     $tpl->display();
  70. }
  71.  
  72. /**
  73.  * Reset a game by given gameId
  74.  */
  75. function admin_delete_game($gameId)
  76. {
  77.     $result = Game::delete($gameId);
  78.  
  79.     if ($result)
  80.         Redirect::to('admin/start', array('flash_notice' => 'Das Spiel mit der Id '. (int)$gameId .' wurde gelöscht.'));
  81.     else
  82.         Redirect::to('admin/start', array('flash_error' => 'Fehler beim Löschen des Spiels.'));
  83. }
  84.  
  85. /**
  86.  *
  87.  */
  88. function admin_game($gameId)
  89. {
  90.     $tpl = new Template('admin/game', 'admin/index');
  91.  
  92.     $game = Game::get2($gameId);
  93.     $tpl->assign('game', $game);
  94.  
  95.     $players = Game::getPlayers($gameId);
  96.     $tpl->assign('players', $players);
  97.  
  98.     $scores = Game::getScores($gameId);
  99.     $tpl->assign('scores', $scores);
  100.  
  101.     $tracks = Place::getTracks();
  102.     $tpl->assign('tracks', $tracks);
  103.  
  104.     $tpl->display();
  105. }
  106.  
  107. /**
  108.  *
  109.  */
  110. function admin_game_do($gameId)
  111. {
  112.     $game = Game::get($gameId);
  113.  
  114.     $game['player_count'] = (int)$_POST['player_max'];
  115.  
  116.     $game['valid_from'] = $_POST['valid_from'];
  117.  
  118.     $game['valid_to'] = $_POST['valid_to'];
  119.  
  120.     Game::save($game);
  121.  
  122.     $message = 'Spiel mit der Id ' . (int)$gameId . ' erfolgreich bearbeitet.';
  123.     Redirect::to('admin/start', array('flash_notice' => $message));
  124. }
  125.  
  126. /**
  127.  *
  128.  */
  129. function admin_create_game()
  130. {
  131.     $gameId = Game::create();
  132.  
  133.     Redirect::to('admin/game/' . $gameId);
  134. }
  135.  
  136. /**
  137.  *
  138.  */
  139. function admin_track($trackId)
  140. {
  141.     $tpl = new Template('admin/track', 'admin/index');
  142.  
  143.     $hole = Track::getHoleByTrackId($trackId);
  144.        
  145.     /* Get Track-Statistics */
  146.     $track = Track::getTrackInfo($hole);
  147.  
  148.     if (!$track) {
  149.         echo 'Track not found';
  150.         return;
  151.     }
  152.  
  153.     /* More stats */
  154.     $holeInOnes = Track::getHoleInOnes($track['id']);
  155.     $overEleven = Track::getOverEleven($track['id']);
  156.  
  157.  
  158.     $tpl = new Template('admin/track', 'admin/index');
  159.  
  160.     $tpl->assign('hole', array(
  161.         'id' => $track['id'],
  162.         'path' => $track['path'],
  163.         'max_trys' => $track['max_trys'],
  164.         'number' => $track['number'],
  165.         'avg_tries' => $track['average_tries'],
  166.         'difficulty' => $track['difficulty'],
  167.         'description' => $track['description'],
  168.         'rating' => $track['rating'],
  169.         'hinone' => $holeInOnes,
  170.         'overelev' => $overEleven,
  171.         'allhits' => $track['allhits']
  172.             )
  173.     );
  174.  
  175.     $tpl->assign('diffuculty_levels', array('<Unbewertet>', 'Einfach', 'Fortgeschritten', 'Mittel', 'Hart', 'Schwer'));
  176.  
  177.     $tpl->display();
  178. }
  179.  
  180. /**
  181.  *
  182.  */
  183. function admin_track_do($trackId)
  184. {
  185.     $track = Track::get($trackId);
  186.  
  187.     $track['number'] = (int)$_POST['number'];
  188.  
  189.     $track['difficulty'] = (int)$_POST['difficulty'];
  190.  
  191.     //$track['path'] = $_POST['path'];
  192.  
  193.     $track['description'] = $_POST['description'];
  194.  
  195.     $track['max_trys'] = (int)$_POST['max_trys'];
  196.  
  197.     Track::save($track);
  198.  
  199.     $message = 'Bahn mit der Id ' . (int)$trackId . ' erfolgreich bearbeitet.';
  200.     Redirect::to('admin/start', array('flash_notice' => $message));
  201. }
  202.  
  203. /**
  204.  *
  205.  */
  206. function admin_create_track()
  207. {
  208.     $trackId = Track::create();
  209.  
  210.     Redirect::to('admin/track/' . $trackId);
  211. }
  212.  
  213. /**
  214.  * Reset a game by given trackId
  215.  */
  216. function admin_delete_track($trackId)
  217. {
  218.     $result = Track::delete($trackId);
  219.  
  220.     if ($result)
  221.         Redirect::to('admin/start', array('flash_notice' => 'Die Bahn mit der Id '. (int)$trackId .' wurde gelöscht.'));
  222.     else
  223.         Redirect::to('admin/start', array('flash_error' => 'Fehler beim Löschen der Bahn.'));
  224. }
  225.  
  226. /**
  227.  *
  228.  */
  229. function admin_grant_player($playerId)
  230. {
  231.     Player::grant($playerId);
  232.  
  233.     $gameId = Player::getGameId($playerId);
  234.  
  235.     Redirect::to('admin/game/' . $gameId);
  236. }
  237.  
  238. /**
  239.  *
  240.  */
  241. function admin_remove_player($playerId)
  242. {
  243.     $gameId = Player::getGameId($playerId);
  244.  
  245.     Player::removeFromGame($playerId);
  246.  
  247.     Redirect::to('admin/game/' . $gameId);
  248. }
  249.  
  250. /* ---------------------------------------------------- */
  251.  
  252.  
  253. if ( ! Admin::is_auth() && $_GET['subpage'] != 'auth' )
  254.     Redirect::to('admin/auth');
  255.  
  256. $action = preg_replace('/\W/', '', $_GET['subpage']);
  257.  
  258. $method = $_SERVER['REQUEST_METHOD'] == 'GET' ? '' : '_do';
  259.  
  260. $func = 'admin_' . $action . $method;
  261.  
  262. if (function_exists($func))
  263. {
  264.     $params = array();
  265.  
  266.     if (isset($_GET['id']))
  267.     {
  268.         $params[] = (int)$_GET['id'];
  269.     }
  270.  
  271.     call_user_func_array($func, $params);
  272. }
  273. else
  274.     Redirect::to('admin/start');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement