while ($scor = $db->fetch_row($scora)) {
        $unams = $db->fetch_row($db->query("SELECT username FROM users WHERE userid={$scor['userid']}"));
        print "<tr><td>{$unams['username']}</td><td>{$scor['score']} points</td><td>&nbsp;<a href=?act=view&id={$scor['gameid']}>View</a>&nbsp;</td></tr>";
    }
    print "</table>";
}
if ($_GET['act'] == 'replay') {
    $gameid = $_GET['id'];
    $db->query("INSERT INTO {$gpre}game (userid) VALUES({$userid})");
    $pp = $db->query("SELECT * FROM {$gpre}game WHERE gameover=0 AND userid={$userid}");
    setup_game($userid);
    $_GET['act'] = 'play';
    $pany = 1;
}
$id = abs((int) $_GET['id']);
if ($_GET['act'] == 'view') {
    $vgs = $db->query("SELECT * FROM {$gpre}scores WHERE gameid={$id}");
    if (!$db->num_rows($vgs)) {
        die;
    }
    $vg = $db->fetch_row($vgs);
    print "<h2>" . userid_to_username($vg['userid']) . " scored " . number_format($vg['score']) . "</h2>\n\t&gt; <a href='s_pp_game.php?act=highscores'>Back to High Scores</a><br />";
    draw_board($ir['userid'], $id, 1);
}
if ($pany && $_GET['act'] == 'play') {
    $p = $db->fetch_row($pp);
    $gameid = $p['id'];
    print "\n        <center><div id = \"gamediv\">\n        <img src='images/pp/s14.gif' onerror=\"refreshPage();\" onload=\"refreshPage();\" onclick=\"refreshPage();\">\n        <br /><button type=\"button\" onclick=\"refreshPage();\">Begin Playing</button>\n        </div>";
}
print "</center>";
$h->endpage();
//This code is essentially the code that executes in the if($pany && $_GET['act']=='play') statement within s_pp_game.php
if ($pany) {
    $p = $db->fetch_row($pp);
    print "<h2>Poker Patience</h2><a href='s_pp_game.php?act=highscores'><b><font color=green>View Highscores</font></b></a> | \n\t<b>How to play:</b><br /><font size=1> Get the best 5 card hand possible on each row, column, and the two diagonals. <br />\n\tYour final score is the total points you earned from all 12 of those hands.<br />\n\tClick one of the two decks at top to select a card to play, and click an open square to play it.</font><br /><br />\n\t<div id = \"gamediv\">";
    $gameid = $p['id'];
    $boardtxt = draw_board($userid, $gameid);
    if ($move != 0 && $p['gameover'] == 0) {
        make_move($move, $userid);
        $points = check_win($userid);
        if ($points > 0) {
            $ins = $db->query("SELECT * FROM pp_scores WHERE userid={$userid} AND {$points}<score");
            $insn = $db->num_rows($ins);
            //keep old score only if there's a score in the DB that has a higher value than $points
            if (!$insn) {
                $db->query("DELETE FROM pp_scores WHERE userid={$userid}");
                $db->query("DELETE FROM pp_game WHERE userid={$userid} AND id!={$gameid}");
                $db->query("INSERT INTO pp_scores (userid, score, gameid) VALUES({$userid}, {$points}, {$gameid})");
            }
            print "Game over, you got <b>{$points} points</b>  <br /><br>";
            print "<form method='post' action='?act=replay'>\n\t\t\t<input type='submit' value='New Game?'>\n\t\t\t</form><br /><br />";
            print "<form method='post' action='?act=post'>\n\t\t\tVictory Message (optional): <input type=text name='victory'><br />\n\t\t\t<input type='submit' value='Post to Facebook?'>\n\t\t\t</form>";
        }
    }
    if ($select != 0) {
        card_select($select, $userid);
    }
    $boardtxt = draw_board($userid, $gameid);
    print $boardtxt;
    print "</div>";
}
print "</center>";
    player_ready($begin, $userid, $roomid);
}
if ($setup) {
    place_piece($setup, $userid, $roomid);
}
if ($endturn) {
    end_turn($userid, $roomid);
}
print "<h1>{$gamename}</h1>";
if ($waittxt) {
    print "{$waittxt}";
} else {
    if ($defaultwin) {
        print "{$defaultwin}";
    } else {
        print "{$vstxt}{$wintxt}{$topturntxt}";
        if ($displayreplay) {
            if ($badreplaymsg) {
                print "You don't have enough money to play again.<br />";
            } else {
                if ($gi['replay'] == $ir['userid']) {
                    print "Asking opponent to play again...<br />";
                } else {
                    replay_option($roomid);
                }
            }
        }
        print $timetxt;
        draw_board($roomid, $userid, $ga['turn']);
    }
}