public function startApp()
 {
     $rootLocation = "Location:http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
     $lv = new LayoutView();
     $ud = new userDAL();
     $sm = new SessionManager();
     $lm = new LoginModel($ud, $sm);
     if (!$lm->isUserLoggedIn()) {
         if ($lv->userWantsToRegister()) {
             $validate = new ValidateCredentials();
             $v = new RegisterView($validate, $sm);
             $c = new RegisterController($v, $ud, $sm);
             $c->userPost();
             if ($sm->SessionGetSuccessfulRegistration()) {
                 header($rootLocation);
             }
         } else {
             $v = new LoginView($lm, $sm);
             $c = new LoginController($v, $lm);
             $c->userPost();
         }
     }
     if ($lm->isUserLoggedIn()) {
         $c = new GameController($lm, $ud, $sm, $lv);
         $v = $c->startApp();
         if ($c->userWantsToLogout()) {
             header($rootLocation);
         }
     }
     $lv->render($v, $lm->isUserLoggedIn());
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return array
  */
 public function getCurrentRound()
 {
     if (Session::has('admin') || Session::has('user')) {
         $GameController = new GameController();
         $FighterController = new FighterController();
         $round = DB::table('rounds')->where('idgame', '=', Input::get('game'))->where('status', '=', 0)->first();
         if (!$round) {
             if (Session::has('admin')) {
                 $round = DB::table('rounds')->where('idgame', '=', Input::get('game'))->where('status', '=', 1)->first();
                 if (!$round) {
                     $lastRound = DB::table('rounds')->where('idgame', '=', Input::get('game'))->orderBy('idround', 'desc')->first();
                     if (!$lastRound) {
                         $lastRound = 1;
                     } else {
                         $lastRound = $lastRound->round + 1;
                     }
                     $round_id = DB::table('rounds')->insertGetId(array('idgame' => Input::get('game'), 'round' => $lastRound, 'status' => 0));
                     $GameController->change_status(Input::get('game'), 1);
                     $round = DB::table('rounds')->where('idgame', '=', Input::get('game'))->where('status', '=', 0)->first();
                     $game = $GameController->getGameById(Input::get('game'));
                     $fighters = $FighterController->get_all(Input::get('game'), $game->status);
                     return array('round' => $round, 'game' => $game, 'fighters' => $fighters);
                 } else {
                     return array('round' => $round, 'inBattle' => 1);
                 }
             } else {
                 return array('wait' => 1);
             }
         } else {
             $game = $GameController->getGameById(Input::get('game'));
             $fighters = $FighterController->get_all(Input::get('game'), $game->status);
             $action = '';
             $action2 = false;
             if (Session::has('user')) {
                 $user = Session::get('user');
                 $response = DB::table('actions')->where('iduser', '=', $user->iduser)->where('idgame', '=', Input::get('game'))->where('idround', '=', $round->round)->get();
                 $len = count($response);
                 if ($len > 0) {
                     $action = $response[0];
                     if (isset($response[1])) {
                         $action2 = $response[1];
                     }
                 }
             }
             if ($action2) {
                 return array('round' => $round, 'game' => $game, 'fighters' => $fighters, 'action' => $action, 'action2' => $action2);
             }
             return array('round' => $round, 'game' => $game, 'fighters' => $fighters, 'action' => $action);
         }
     } else {
         return 'not admin';
     }
 }
 public static function run()
 {
     // Perform actions related to Betting
     $action = array_key_exists('action', $_SESSION) ? $_SESSION['action'] : "";
     $arguments = $_SESSION['arguments'];
     switch ($action) {
         case "generate":
             GameController::generateNewGame();
             BetView::showGames();
             break;
         default:
             BetController::show();
     }
 }
Beispiel #4
0
<?php

include_once "include/session.php";
// must include session.php which include the User class before calling session_start
// since we're storing an user object in the session variable, php needs a way to un-serialize
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_list_games();
} else {
    header("Location: login.php");
}
Beispiel #5
0
<?php

include_once "include/session.php";
// must include session.php which include the User class before calling session_start
// since we're storing an user object in the session variable, php needs a way to un-serialize
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_cancel_join();
} else {
    header("Location: login.php");
}
Beispiel #6
0
				
				$params = [<br>
				&nbsp;&nbsp;\'opponent\' => \'John\',<br>
				&nbsp;&nbsp;\'location\' => \'Outside\',<br>
				&nbsp;&nbsp;\'outcome\'  => \'L\',<br>
				&nbsp;&nbsp;\'datetime\' => \'2015-12-07 10:00:00\',<br>
				];<br><br>
				
				$game->setId($id);<br>
				$game = GameController::edit($game, $params);<br>
			</div>
		';
        $game = new Game();
        $params = ['opponent' => 'John', 'location' => 'Outside', 'outcome' => 'L', 'datetime' => '2015-12-07 10:00:00'];
        $game->setId($id);
        $game = GameController::edit($game, $params);
        $test_data .= '<div class="bg-success pad">';
        foreach ($game as $key => $value) {
            $test_data .= $key . ' : ' . $value . '<br>';
        }
        $test_data .= '</div>';
        $body = '
			<ol class="breadcrumb">
				<li><a href="index.php">Getting Started</a></li>
				<li><a class="active">Initial Testing</a></li>
			</ol>

			<div class="row">
				<div class="col-md-8">
					<p>Now that your scripts are generated, we will test the generated code. There are a set of default queries that can be used for basic CRUD. These will be our main focus to ensure the files were setup correctly.</p>
					' . $test_data . '
Beispiel #7
0
});
// Pelin esittelysivu
$routes->get('/game/:gameid', 'check_logged_in', function ($gameid) {
    GameController::show($gameid);
});
// Pelin muokkauslomakkeen esittäminen
$routes->get('/game/:gameid/edit', 'check_logged_in', function ($gameid) {
    GameController::edit($gameid);
});
// Pelin muokkaaminen
$routes->post('/game/:gameid/edit', 'check_logged_in', function ($gameid) {
    GameController::update($gameid);
});
// Radan poisto
$routes->post('/game/:gameid/destroy', 'check_logged_in', function ($gameid) {
    GameController::destroy($gameid);
});
// Käyttäjä
// Kirjautumislomakkeen esittäminen
$routes->get('/login', function () {
    UserController::login();
});
// Kirjautumisen käsittely
$routes->post('/login', function () {
    UserController::handle_login();
});
// Uloskirjautuminen
$routes->post('/logout', function () {
    UserController::logout();
});
// Rekisteröitymislomakkeen esittäminen
Beispiel #8
0
 public static function showGames()
 {
     $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : "";
     //echo '<div class="container">';
     echo '<h1>Bet On These Active Games</h1>';
     //$games = (array_key_exists('activegames', $_SESSION))?$_SESSION['activegames']:array();
     $games = GameDB::getGamesBy('pending', 1);
     if (empty($games)) {
         //echo '</div>';
         return;
     }
     echo '<div class="table-responsive">';
     echo '<table class="table">';
     echo '<thead>';
     echo '<tr>';
     echo '<th>GameID</th>';
     echo '<th>User1</th>';
     echo '<th>User2</th>';
     echo '<th>User3</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>User4</th>';
     echo '<th>User5</th>';
     echo '<th>User6</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>Length</th>';
     echo '</tr>';
     echo '</thead>';
     echo '<tbody>';
     $authenticatedUser = array_key_exists('authenticatedUser', $_SESSION) ? $_SESSION['authenticatedUser'] : null;
     //iterate through all games
     foreach ($games as $game) {
         //If the game is not finished or had a bad/cancel don't show here
         if ($game->getPending() != 1) {
             continue;
         }
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
         if (empty($teams)) {
             break;
         }
         $team1 = $teams[0];
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
         if (empty($teams)) {
             break;
         }
         $team2 = $teams[0];
         if (is_null($team1) || is_null($team2)) {
             break;
         }
         if (!is_null($authenticatedUser)) {
             $bets = BetDB::findBet($game->getID(), $authenticatedUser->getHockName());
             if (!empty($bets)) {
                 continue;
             }
         }
         $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
         //team1
         $user1 = HockUserDB::getUserByID_NameAndHome($team1->getUID1());
         $user2 = HockUserDB::getUserByID_NameAndHome($team1->getUID2());
         $user3 = HockUserDB::getUserByID_NameAndHome($team1->getUID3());
         //team2
         $user4 = HockUserDB::getUserByID_NameAndHome($team2->getUID1());
         $user5 = HockUserDB::getUserByID_NameAndHome($team2->getUID2());
         $user6 = HockUserDB::getUserByID_NameAndHome($team2->getUID3());
         if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
             break;
         }
         $user1 = $user1[0];
         $user2 = $user2[0];
         $user3 = $user3[0];
         $user4 = $user4[0];
         $user5 = $user5[0];
         $user6 = $user6[0];
         $start = new DateTime($game->getStart());
         $end = new DateTime(date("Y-m-d H:i:s"));
         $length = $end->diff($start);
         $timestr = "";
         if ($length->m != 0) {
             $timestr = $timestr . $length->m . "mo ";
         }
         if ($length->d != 0) {
             $timestr = $timestr . $length->d . "d ";
         }
         if ($length->h != 0) {
             $timestr = $timestr . $length->h . "h ";
         }
         $timestr = $timestr . $length->i . "m " . $length->s . "s";
         echo '<tr class="' . $game->getServer() . '">';
         echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
         echo '<td class="' . $user1->getHome() . '"><a href="' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
         echo '<td class="' . $user2->getHome() . '"><a href="' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
         echo '<td class="' . $user3->getHome() . '"><a href="' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
         echo '<td>' . $game->getTeamSkill1() . '</td>';
         echo '<td class="edge">+' . $worth[0] . '/-' . $worth[1] . '</td>';
         echo '<td class="' . $user4->getHome() . '"><a href="' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
         echo '<td class="' . $user5->getHome() . '"><a href="' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
         echo '<td class="' . $user6->getHome() . '"><a href="' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
         echo '<td>' . $game->getTeamSkill2() . '</td>';
         echo '<td>+' . $worth[1] . '/-' . $worth[0] . '</td>';
         echo '<td>' . $timestr . '</td>';
         echo '</tr>';
     }
     echo '</tbody>';
     echo '</table>';
     echo '</div>';
     //end table
     //echo '</div>'; //end container
 }
Beispiel #9
0
<?php

include_once "include/session.php";
// must include session.php which include the User class before calling session_start
// since we're storing an user object in the session variable, php needs a way to un-serialize
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_delete_game();
} else {
    header("Location: login.php");
}
Beispiel #10
0
 public static function showAllDetails()
 {
     $base = $_SESSION['base'];
     $games = array_key_exists('games', $_SESSION) ? $_SESSION['games'] : array();
     echo '<div class="container">';
     echo '<h1>All Games This Season</h1>';
     echo '<div class="table-responsive">';
     echo '<table class="table">';
     echo '<thead>';
     echo '<tr>';
     echo '<th>GameID</th>';
     echo '<th>User1</th>';
     echo '<th>User2</th>';
     echo '<th>User3</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>User4</th>';
     echo '<th>User5</th>';
     echo '<th>User6</th>';
     echo '<th>TeamSkill</th>';
     echo '<th>+/-</th>';
     echo '<th>Length</th>';
     echo '</tr>';
     echo '</thead>';
     echo '<tbody>';
     //iterate through all games
     foreach ($games as $game) {
         //If the game is not finished or had a bad/cancel don't show here
         if ($game->getPending() != 0) {
             continue;
         }
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
         if (empty($teams)) {
             break;
         }
         $team1 = $teams[0];
         $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
         if (empty($teams)) {
             break;
         }
         $team2 = $teams[0];
         if (is_null($team1) || is_null($team2)) {
             break;
         }
         $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
         $plusminus = 0;
         //Put all winning teams on left side of table
         if (strcmp($game->getWinReports(), 'team1') == 0) {
             //team1 won
             $plusminus = $worth[0];
             //team1
             $user1 = HockUserDB::getUsersBy('id', $team1->getUID1());
             $user2 = HockUserDB::getUsersBy('id', $team1->getUID2());
             $user3 = HockUserDB::getUsersBy('id', $team1->getUID3());
             //team2
             $user4 = HockUserDB::getUsersBy('id', $team2->getUID1());
             $user5 = HockUserDB::getUsersBy('id', $team2->getUID2());
             $user6 = HockUserDB::getUsersBy('id', $team2->getUID3());
             $winnerskill = $game->getTeamSkill1();
             $loserskill = $game->getTeamSkill2();
         } else {
             //team2 won
             $plusminus = $worth[1];
             //team1
             $user4 = HockUserDB::getUsersBy('id', $team1->getUID1());
             $user5 = HockUserDB::getUsersBy('id', $team1->getUID2());
             $user6 = HockUserDB::getUsersBy('id', $team1->getUID3());
             //team2
             $user1 = HockUserDB::getUsersBy('id', $team2->getUID1());
             $user2 = HockUserDB::getUsersBy('id', $team2->getUID2());
             $user3 = HockUserDB::getUsersBy('id', $team2->getUID3());
             $winnerskill = $game->getTeamSkill2();
             $loserskill = $game->getTeamSkill1();
         }
         if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
             break;
         }
         $user1 = $user1[0];
         $user2 = $user2[0];
         $user3 = $user3[0];
         $user4 = $user4[0];
         $user5 = $user5[0];
         $user6 = $user6[0];
         $start = new DateTime($game->getStart());
         $end = new DateTime($game->getEnd());
         $length = $start->diff($end);
         echo '<tr class="' . $game->getServer() . '">';
         echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
         echo '<td class="' . $user1->getHome() . '"><a href="/' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
         echo '<td class="' . $user2->getHome() . '"><a href="/' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
         echo '<td class="' . $user3->getHome() . '"><a href="/' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
         echo '<td>' . $winnerskill . '</td>';
         echo '<td class="plus">+' . $plusminus . '</td>';
         echo '<td class="' . $user4->getHome() . '"><a href="/' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
         echo '<td class="' . $user5->getHome() . '"><a href="/' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
         echo '<td class="' . $user6->getHome() . '"><a href="/' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
         echo '<td>' . $loserskill . '</td>';
         echo '<td class="minus">-' . $plusminus . '</td>';
         echo '<td>' . $length->i . 'm ' . $length->s . 's</td>';
         echo '</tr>';
     }
     echo '</tbody>';
     echo '</table>';
     echo '</div>';
     //end table
     echo '</div>';
     //end container
 }
Beispiel #11
0
<?php

include_once "include/session.php";
// must include session.php which include the User class before calling session_start
// since we're storing an user object in the session variable, php needs a way to un-serialize
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_select_player();
} else {
    header("Location: login.php");
}
Beispiel #12
0
$_SESSION['action'] = $action;
$_SESSION['arguments'] = $arguments;
if (!isset($_SESSION['authenticated'])) {
    $_SESSION['authenticated'] = false;
}
switch ($control) {
    case "login":
        LoginController::run();
        break;
    case "logout":
        LogoutController::run();
        break;
    case "bet":
        BetController::run();
        break;
    case "signup":
        SignupController::run();
        break;
    case "user":
        UserController::run();
        break;
    case "game":
        GameController::run();
        break;
    default:
        HomeView::show(null);
}
ob_end_flush();
?>
	
Beispiel #13
0
    GraphController::index();
});
// Käyttäjä
// Kirjautumislomakkeen esittäminen
$routes->get('/login', function () {
    UserController::login();
});
// Kirjautumisen käsittely
$routes->post('/login', function () {
    UserController::handle_login();
});
// Uloskirjautuminen
$routes->post('/logout', function () {
    UserController::logout();
});
// Rekisteröitymislomakkeen esittäminen
// $routes->get('/register', function(){
//   UserController::register();
// });
// Rekisteröitymisen käsittely
// $routes->post('/register', function(){
//   UserController::handle_register();
// });
// Add multiple csv files
$routes->get('/csv_import', 'check_admin_logged_in', function () {
    GameController::csv_import_show();
});
// Process multiple csv files
$routes->post('/csv_import', 'check_admin_logged_in', function () {
    GameController::csv_import_process();
});
<?php

include_once "include/session.php";
// must include session.php which include the User class before calling session_start
// since we're storing an user object in the session variable, php needs a way to un-serialize
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_interest();
} else {
    header("Location: login.php");
}
Beispiel #15
0
    public static function showGames()
    {
        $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : "";
        //echo '<div class="container">';
        echo '<h1>Bet On These Active Games</h1>';
        //$games = (array_key_exists('activegames', $_SESSION))?$_SESSION['activegames']:array();
        $games = GameDB::getGamesBy('pending', 1);
        if (empty($games)) {
            //echo '</div>';
            return;
        }
        echo '<div class="table-responsive">';
        echo '<table class="table">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>GameID</th>';
        echo '<th>User1</th>';
        echo '<th>User2</th>';
        echo '<th>User3</th>';
        echo '<th>TeamSkill</th>';
        echo '<th>+/-</th>';
        echo '<th>User4</th>';
        echo '<th>User5</th>';
        echo '<th>User6</th>';
        echo '<th>TeamSkill</th>';
        echo '<th>+/-</th>';
        echo '<th>Length</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';
        //iterate through all games
        foreach ($games as $game) {
            //If the game is not finished or had a bad/cancel don't show here
            if ($game->getPending() != 1) {
                continue;
            }
            $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
            if (empty($teams)) {
                break;
            }
            $team1 = $teams[0];
            $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
            if (empty($teams)) {
                break;
            }
            $team2 = $teams[0];
            if (is_null($team1) || is_null($team2)) {
                break;
            }
            $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
            //team1
            $user1 = HockUserDB::getUsersBy('id', $team1->getUID1());
            $user2 = HockUserDB::getUsersBy('id', $team1->getUID2());
            $user3 = HockUserDB::getUsersBy('id', $team1->getUID3());
            //team2
            $user4 = HockUserDB::getUsersBy('id', $team2->getUID1());
            $user5 = HockUserDB::getUsersBy('id', $team2->getUID2());
            $user6 = HockUserDB::getUsersBy('id', $team2->getUID3());
            if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
                break;
            }
            $user1 = $user1[0];
            $user2 = $user2[0];
            $user3 = $user3[0];
            $user4 = $user4[0];
            $user5 = $user5[0];
            $user6 = $user6[0];
            $start = new DateTime($game->getStart());
            $end = new DateTime(date("Y-m-d H:i:s"));
            $length = $start->diff($end);
            echo '<tr class="' . $game->getServer() . '">';
            echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
            echo '<td class="' . $user1->getHome() . '"><a href="/' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
            echo '<td class="' . $user2->getHome() . '"><a href="/' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
            echo '<td class="' . $user3->getHome() . '"><a href="/' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
            echo '<td>' . $game->getTeamSkill1() . '</td>';
            echo '<td class="edge">+' . $worth[0] . '/-' . $worth[1] . '</td>';
            echo '<td class="' . $user4->getHome() . '"><a href="/' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
            echo '<td class="' . $user5->getHome() . '"><a href="/' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
            echo '<td class="' . $user6->getHome() . '"><a href="/' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
            echo '<td>' . $game->getTeamSkill2() . '</td>';
            echo '<td>+' . $worth[1] . '/-' . $worth[0] . '</td>';
            echo '<td>' . $length->i . 'm ' . $length->s . 's</td>';
            echo '</tr>';
        }
        echo '</tbody>';
        echo '</table>';
        echo '</div>';
        //end table
        //echo '</div>'; //end container
        return;
        ?>
				<h3> Active games </h3>
				(29678)  Team1: Sergio ace lymp (4502) +10/-10    Team2: zoop bizarre staniol (4480)  +10/-10    0:02:56.805000
				<br>
				<h3>Place bet:</h3>
				<form action="bet" method="post">
				Game to bet on: <input type="text" name="game" tabindex="1" <?php 
        if (!is_null($bet)) {
            echo 'value = "' . $bet->getGame() . '"';
        }
        ?>
 required>
				<span class="error">
				   <?php 
        if (!is_null($bet)) {
            echo $bet->getError('game');
        }
        ?>
				</span>
				<br>
				Amount to bet: <input type="text" name="betAmount" tabindex="2" <?php 
        if (!is_null($bet)) {
            echo 'value = "' . $bet->getBetAmount() . '"';
        }
        ?>
 required>
				<span class="error">
				   <?php 
        if (!is_null($bet)) {
            echo $bet->getError('betAmount');
        }
        ?>
				</span>
				<br>
				<input type="submit" value="Submit" tabindex="3">
				</form>
			<?php 
    }
Beispiel #16
0
<?php

include_once "include/session.php";
session_start();
$user = get_loggedin_user();
if (isset($user)) {
    // if the user is currently logged in
    include_once "controller/game.php";
    $game_controller = new GameController();
    $game_controller->invoke_view_game();
} else {
    // if the user is currently not logged in
    header("Location: login.php");
}
 public static function destroy($courseid)
 {
     // Destroy both the course and its holes.
     // Also destroy all games and scores on the course.
     $course = Course::find($courseid);
     $holes = Hole::course_holes($course->courseid);
     $games = Game::course_games($courseid);
     foreach ($games as $game) {
         GameController::destroy_no_redirect($game->gameid);
     }
     foreach ($holes as $hole) {
         $hole->destroy();
     }
     $course->destroy();
     Redirect::to('/course', array('message' => 'Rata ja sen väylät poistettu. Kaikki radan pelit poistettu.'));
 }
Beispiel #18
0
    public static function showDetails($webuser, $hockuser)
    {
        $base = array_key_exists('base', $_SESSION) ? $_SESSION['base'] : "";
        ?>
 
<div class="container-fluid">
<h2><?php 
        if (!is_null($hockuser)) {
            echo $hockuser->getUserName();
        }
        ?>
's Profile</h2>
<p>Saved img name is: <?php 
        if (!is_null($webuser)) {
            echo $webuser->getPicture();
        }
        ?>
</p>
</div>
<section>
<?php 
        if (!is_null($hockuser)) {
            echo '<div class="container-fluid">';
            echo '<h4>Stats</h4>';
            echo '<div class="table">';
            echo '<table class="table" id="stats1">';
            echo '<thead>';
            echo '<tr>';
            echo '<th>Wins</th>';
            echo '<th>Losses</th>';
            echo '<th>Streak</th>';
            echo '<th>ELO</th>';
            echo '</tr>';
            echo '</thead>';
            echo '<tbody>';
            echo '<tr>';
            echo '<td>' . $hockuser->getWins() . '</td>';
            echo '<td>' . $hockuser->getLosses() . '</td>';
            echo '<td>' . $hockuser->getStreak() . '</td>';
            echo '<td>' . $hockuser->getSkill() . '</td>';
            echo '</tr>';
            echo '</tbody>';
            echo '</table>';
            echo '</div>';
            //end table
            echo '</div>';
            //end container
        } else {
            echo "No stats to display for this non existent user";
        }
        ?>
</section>
<section>
<?php 
        $allgames = array_key_exists('allgames', $_SESSION) ? $_SESSION['allgames'] : null;
        if (!empty($allgames)) {
            echo '<div class="container-fluid">';
            echo '<h4>Recent Games</h4>';
            echo '<div class="table-responsive">';
            echo '<table class="table" id="games">';
            echo '<thead>';
            echo '<tr>';
            echo '<th>GameID</th>';
            echo '<th>User1</th>';
            echo '<th>User2</th>';
            echo '<th>User3</th>';
            echo '<th>TeamSkill</th>';
            echo '<th>+/-</th>';
            echo '<th>User4</th>';
            echo '<th>User5</th>';
            echo '<th>User6</th>';
            echo '<th>TeamSkill</th>';
            echo '<th>+/-</th>';
            echo '<th>Length</th>';
            echo '</tr>';
            echo '</thead>';
            echo '<tbody>';
            foreach ($allgames as $game) {
                //If the game is not finished or had a bad/cancel don't show here
                if ($game->getPending() != 0) {
                    continue;
                }
                $teams = TeamDB::getTeamsBy('id', $game->getTeamID1());
                if (empty($teams)) {
                    break;
                }
                $team1 = $teams[0];
                $teams = TeamDB::getTeamsBy('id', $game->getTeamID2());
                if (empty($teams)) {
                    break;
                }
                $team2 = $teams[0];
                if (is_null($team1) || is_null($team2)) {
                    break;
                }
                //Put all winning teams on left side of table
                $worth = GameController::calcWorth($game->getTeamSkill1(), $game->getTeamSkill2());
                $plusminus = 0;
                if (strcmp($game->getWinReports(), 'team1') == 0) {
                    //team1 won
                    //team1
                    $plusminus = $worth[0];
                    $user1 = HockUserDB::getUsersBy('id', $team1->getUID1());
                    $user2 = HockUserDB::getUsersBy('id', $team1->getUID2());
                    $user3 = HockUserDB::getUsersBy('id', $team1->getUID3());
                    //team2
                    $user4 = HockUserDB::getUsersBy('id', $team2->getUID1());
                    $user5 = HockUserDB::getUsersBy('id', $team2->getUID2());
                    $user6 = HockUserDB::getUsersBy('id', $team2->getUID3());
                    $winnerskill = $game->getTeamSkill1();
                    $loserskill = $game->getTeamSkill2();
                } else {
                    //team2 won
                    //team1
                    $user4 = HockUserDB::getUsersBy('id', $team1->getUID1());
                    $user5 = HockUserDB::getUsersBy('id', $team1->getUID2());
                    $user6 = HockUserDB::getUsersBy('id', $team1->getUID3());
                    //team2
                    $user1 = HockUserDB::getUsersBy('id', $team2->getUID1());
                    $user2 = HockUserDB::getUsersBy('id', $team2->getUID2());
                    $user3 = HockUserDB::getUsersBy('id', $team2->getUID3());
                    $winnerskill = $game->getTeamSkill2();
                    $loserskill = $game->getTeamSkill1();
                    $plusminus = $worth[1];
                }
                if (empty($user1) || empty($user2) || empty($user3) || empty($user4) || empty($user5) || empty($user6)) {
                    break;
                }
                $user1 = $user1[0];
                $user2 = $user2[0];
                $user3 = $user3[0];
                $user4 = $user4[0];
                $user5 = $user5[0];
                $user6 = $user6[0];
                $start = new DateTime($game->getStart());
                $end = new DateTime($game->getEnd());
                $length = $start->diff($end);
                echo '<tr class="' . $game->getServer() . '">';
                echo '<td class="' . $game->getServer() . '">' . $game->getID() . '</td>';
                echo '<td class="' . $user1->getHome() . '"><a href="/' . $base . '/user/show/' . $user1->getUserName() . '">' . $user1->getUserName() . '</td>';
                echo '<td class="' . $user2->getHome() . '"><a href="/' . $base . '/user/show/' . $user2->getUserName() . '">' . $user2->getUserName() . '</td>';
                echo '<td class="' . $user3->getHome() . '"><a href="/' . $base . '/user/show/' . $user3->getUserName() . '">' . $user3->getUserName() . '</td>';
                echo '<td>' . $winnerskill . '</td>';
                echo '<td class="plus">+' . $plusminus . '</td>';
                echo '<td class="' . $user4->getHome() . '"><a href="/' . $base . '/user/show/' . $user4->getUserName() . '">' . $user4->getUserName() . '</td>';
                echo '<td class="' . $user5->getHome() . '"><a href="/' . $base . '/user/show/' . $user5->getUserName() . '">' . $user5->getUserName() . '</td>';
                echo '<td class="' . $user6->getHome() . '"><a href="/' . $base . '/user/show/' . $user6->getUserName() . '">' . $user6->getUserName() . '</td>';
                echo '<td>' . $loserskill . '</td>';
                echo '<td class="minus">-' . $plusminus . '</td>';
                echo '<td>' . $length->i . 'm ' . $length->s . 's</td>';
                echo '</tr>';
            }
            echo '</tbody>';
            echo '</table>';
            echo '</div>';
            //end table
            echo '</div>';
            //end container
        }
        ?>
</section>
<section>
<h4>Contact information</h4>
<ul>
	<li><b>Email:</b> <?php 
        if (!is_null($webuser)) {
            echo $webuser->getEmail();
        }
        ?>
</li>
	<li><b>URL:</b> <a href="<?php 
        if (!is_null($webuser)) {
            echo $webuser->getURL();
        }
        ?>
"><?php 
        if (!is_null($webuser)) {
            echo $webuser->getURL();
        }
        ?>
</a></li>
</ul>
</section>

<?php 
    }
Beispiel #19
0
<?php

// Index
$app->get('/', function () use($app) {
    $app->response->headers->set('Content-Type', 'text/html; charset=utf-8');
    $app->render('home.php');
});
// API
$app->get('/api/:warrior/:item', function ($warrior, $item) use($app) {
    $app->response->headers->set('Content-Type', 'application/json');
    $response = GameController::getIndex($warrior, $item);
    $app->response->setBody(json_encode($response));
});