/View/Play.php
PHP | 569 lines | 481 code | 64 blank | 24 comment | 46 complexity | f7a53a9d2b65eda39e66fd33bcba4dc2 MD5 | raw file
Possible License(s): LGPL-2.1
- <?php
- require '../Model/Connect.php';
- require '../Control/RegisterLogic.php';
- require '../Control/LoginLogic.php';
- require '../Control/SendNotification.php';
- require '../Control/CreateClubLogic.php';
- require '../Control/DBCreate.php';
-
- ob_start();
- $UserNm=$_SESSION['username'];
- $Role = $_SESSION['role'];
- if(isset($_GET['id'])) {
- $SearchName = $_GET['id'];
- $SearchID = GetSearchID($SearchName);
- } else {
- $SearchID = $UserNm;
- }
-
- function GetSearchID($SearchName) {
- $GetID = "SELECT mp_username FROM memberprofile WHERE mp_fullname = '".$SearchName."' ";
- $ResultID = mysql_query($GetID);
- if ($ResultID) {
- $rows = mysql_num_rows($ResultID);
- while($info = mysql_fetch_assoc( $ResultID)) {
- return $info['mp_username'];
- }
- }
- }
-
- function GetPlayerName($PlayerID) {
- $Player = mysql_query("SELECT DISTINCT m.mp_fullname FROM memberprofile m,user u WHERE u.us_id = ".$PlayerID." AND u.us_username = m.mp_username");
- $ChessPlayer = mysql_result($Player, 0);
- return $ChessPlayer;
- }
-
- $_SESSION['isSharedPC'] = false;
- ?>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Online Chess Portal :: Play Chess</title>
- <!-- CSS Files -->
- <link href="css/reset.css" rel="stylesheet" type="text/css" />
- <link href="css/Form.css" rel="stylesheet" type="text/css" />
- <link href="css/style.css" rel="stylesheet" type="text/css" />
- <link href="css/screen.css" rel="stylesheet" type="text/css" />
- <link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen" />
- <link rel="stylesheet" type="text/css" href="css/jquery.gritter.css" />
- <style type="text/css">
- .sf-sub-indicator {
- behavior: url(css/iepngfix.htc)
- }
- .accordion {
- width: 900%px;
- border-bottom: solid 1px #c4c4c4;
- }
- .accordion h3 {
- background: #e9e7e7 url(../images/arrow-square.gif) no-repeat right -51px;
- padding: 7px 15px;
- margin: 0;
- font: bold 120%/100% Arial, Helvetica, sans-serif;
- border: solid 1px #c4c4c4;
- border-bottom: none;
- cursor: pointer;
- }
- .accordion h3 {
- background-color:#f0f0f0;
- }
- .accordion h3:hover{
- background-color:#999;
- font:Tahoma, Geneva, sans-serif;
- }
- .accordion h3.active {
- background-position: right 5px;
- }
- .accordion p {
- background: #f7f7f7;
- margin: 0;
- padding: 10px 15px 20px;
- border-left: solid 1px #c4c4c4;
- border-right: solid 1px #c4c4c4;
- }
- table {
- border-color: #ccc;
- border-spacing: 0px;
- border-style: solid;
- border-width: 1px;
- cell-spacing: 0px;
- border-collapse:collapse;
- width:700px;
- }
-
- td, th {
- font-family: Tahoma, Geneva, sans-serif;
- font-size: 12px;
- padding: 5px;
- text-align:center;
- /*white-space: nowrap;*/
- }
-
- td.numeric {
- text-align: right;
- }
-
- th {
- background-color: #c0c0c0;
- text-align:center;
- }
-
- th.mainHeader {
- background-color: #808080;
- color: #fff;
- text-align: left;
- }
-
- th a {
- color: #000080;
- text-decoration: none;
- }
-
- th a:visited {
- color: #000080;
- }
-
- th a:active, th a:hover {
- color: #800000;
- text-decoration: underline;
- }
-
- tr.alternateRow {
- background-color: #e0e0e0;
- }
-
- td.sortedColumn {
- background-color: #f0f0f0;
- }
-
- th.sortedColumn {
- background-color: #b0b0b0;
- }
-
- tr.alternateRow td.sortedColumn {
- background-color: #d0d0d0;
- }
-
-
- ;
- </style>
- <!-- End of CSS Files -->
- <!-- Javascript Files -->
- <script type="text/javascript" src="javascript/jquery1.3.2.js"></script>
- <script type="text/javascript" src="javascript/jquery.cycle.all.js"></script>
- <script type="text/javascript" src="js/jquery.min.js"></script>
- <script type="text/javascript" src="js/jquery.js"></script>
- <script type="text/javascript" src="http://www.google.com/jsapi"></script>
- <script type="text/javascript">google.load('jquery', '1.5');</script>
- <script type="text/javascript" src="js/jquery.gritter.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
-
- $(".accordion h3:first").addClass("active");
- $(".accordion div:not(:first)").hide();
-
- $(".accordion h3").click(function(){
- $(this).next("div").slideToggle("slow")
- .siblings("div:visible").slideUp("slow");
- $(this).toggleClass("active");
- $(this).siblings("h3").removeClass("active");
- });
- });
- </script>
- <script type="text/javascript">
- function RedirectToGame(Id) {
- //alert(Id);
- if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- } else {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function() {
- if (xmlhttp.readyState==4 && xmlhttp.status==200) {
- //alert(xmlhttp.responseText);
- location.href = "Play.php";
- }
- }
- xmlhttp.open("GET","../Control/AcceptGameRequest.php?Id="+Id,true);
- xmlhttp.send();
- }
- </script>
- <script type="text/javascript">
- function RejectGameReq(Id) {
- //alert(Id);
- if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- } else {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function() {
- if (xmlhttp.readyState==4 && xmlhttp.status==200) {
- //alert(xmlhttp.responseText);
- location.href = "Play.php";
- }
- }
- xmlhttp.open("GET","../Control/DeclineGameRequest.php?Id="+Id,true);
- xmlhttp.send();
- }
- </script>
- <script type="text/javascript">
- function LoadGame(GameID)
- {
- alert(GameID);
- if (document.existingGames.rdoShare[0].checked)
- document.existingGames.action = "opponentspassword.php";
- document.existingGames.GameID.value = GameID;
- document.existingGames.submit();
- }
-
- <!--choose opponent-->
- var time_interval = setInterval(
- function ()
- {
- $('#opponents').load('../Control/ChooseOpponent.php').fadeIn("slow");
- }, 1000); // refresh every 1000 milliseconds
-
- <!--popup-->
- var time_interval = setInterval(
- function ()
- {
- $('#popup').load('../Control/Notification.php').fadeIn("slow");
- }, 5000); // refresh every 5000 milliseconds
-
- </script>
-
- <!-- End of Javascript Files -->
- </head>
- <body>
- <!-- Wrapper -->
- <div id="wrapper">
- <div id="topbar">
- <img src="images/icon1.png" alt="logo" width="42" height="41" class="logo" id='test' /><img src="images/logo.gif" alt="logo" width="322" height="41" class="logo1" id='test' />
-
- <div id="secnav">
- <ul>
- <li> <a href="../Control/LogoutLogic.php?Reason=Normal">SIGN OUT</a> </li>
- <li class="noimg"></li>
- </ul>
- </div>
-
- <div class="menu">
- <ul class="sf-menu">
-
- <li> <?php if($_SESSION['role'] == 'SiteAdmin') {
- ?> <a href="SiteAdminProfile.php">
- <?php } else { ?>
- <a href="MemberProfile.php">
- <?php }
- $result = mysql_query("SELECT mp_fullname FROM memberprofile WHERE mp_username='".$_SESSION['username']."' ");
- $row = mysql_fetch_array($result);
- $Rows = mysql_num_rows($result);
- if($_SESSION['role'] == 'SiteAdmin' || $Rows == 0) {
- echo 'Profile';
- } else {
- echo $row['mp_fullname'];
- }?></a>
- </li>
- </ul>
-
- </div> </div><!-- menu end-->
-
- <div id="content_guest">
- <div class="froms">
- <span id="popup"></span>
- <div class="accordion">
- <h3>Active Games</h3>
- <div class="menu_form_body">
- <h1><?php echo gettext("Continue a game in progress");?></h1><br/>
- <label class="inputlabel">Select a game by click on the game ID</label>
- <form name="existingGames" action="webchs/chess.php" method="post">
- <table align="center">
- <thead>
- <tr><th class="mainHeader" colspan="8"><?php echo gettext("Games in Progress");?></th></tr>
- <tr><th style="text-align:left;display:none;"><?php echo gettext("Rank");?></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 1, true);" title="Game Id"><?php echo gettext("Id");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 2, true);" title="White's handle"><?php echo gettext("White");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 3, true);" title="Black's handle"><?php echo gettext("Black");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 4, true);" title="Moves" ><?php echo gettext("Mvs");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 5, true);" title="Current Turn" ><?php echo gettext("Current Turn");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 6, true);" title="Start Date of the Game"><?php echo gettext("Start Date");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inProgrTblBdy', 7, true);" title="Date of Last Move" ><?php echo gettext("Last Move");?></a></th>
- </tr>
- </thead>
- <tbody id="inProgrTblBdy">
- <?php
- $tmpGames = mysql_query("SELECT * FROM games WHERE ga_gamemessage = '' AND (ga_whiteplayer =".$_SESSION['playerID']." OR ga_blackplayer = ".$_SESSION['playerID']." ) ORDER BY ga_datecreated");
- $OutputRows = mysql_num_rows($tmpGames);
- if ($OutputRows == 0) {
- echo("<tr><td colspan=\"6\">" . gettext("You do not currently have any games in progress") . "</td></tr>\n");
- } else {
- $rowNbr = 0;
- while($tmpGame = mysql_fetch_array($tmpGames, MYSQL_ASSOC))
- {
- if($rowNbr %2 == 0) {
- echo('<tr class="alternateRow">');
- } else {
- echo('<tr>');
- }
- $rowNbr++;
- echo ('<td style="display:none;"></td>');
- echo('<td>');
- echo("<a href=\"javascript:LoadGame(".$tmpGame['ga_gameid'].")\">".$tmpGame['ga_gameid']."</a>");
- /* get white's nick */
- $WhitePlayer = GetPlayerName($tmpGame['ga_whiteplayer']);
- echo ('</td><td>');
- echo($WhitePlayer);
-
- /* get black's nick */
- $BlackPlayer = GetPlayerName($tmpGame['ga_blackplayer']);
- echo ('</td><td>');
- echo($BlackPlayer);
-
- /* Your Color */
- if ($tmpGame['ga_whiteplayer'] == $_SESSION['username']) {
- $tmpColor = "white";
- } else {
- $tmpColor = "black";
- }
-
- /* get number of moves from history */
- $tmpNumMoves = mysql_query("SELECT COUNT(hi_gameid) FROM history WHERE hi_gameid = ".$tmpGame['ga_gameid']);
- $numMoves = mysql_result($tmpNumMoves,0);
- echo ('</td><td class="numeric">');
- echo(floor($numMoves / 2));
- /* Current Turn */
- /* based on number of moves, output current color's turn */
- if (($numMoves % 2) == 0)
- $tmpCurMove = "white";
- else
- $tmpCurMove = "black";
-
- echo ("</td><td>");
- if ($tmpCurMove == $tmpColor)
- echo(gettext("Your move"));
- else
- echo(gettext("Opponent"));
-
- /* Start Date */
- echo ("</td><td>".substr($tmpGame['ga_datecreated'], 0, -3));
-
- /* Last Move */
- echo ("</td><td>".substr($tmpGame['ga_lastmove'], 0, -3)."</td></tr>\n");
- }
- }
- ?>
- </tbody>
- </table><br/>
- <div class="inputlabel" style="padding-top:10px;"><?php echo gettext("Will both players play from the same computer?");?></div>
- <div class="inputbox">
- <div><input name="rdoShare" type="radio" value="" /> <?php echo gettext("Yes");?></div>
- <div><input name="rdoShare" type="radio" value="no" checked="checked" /> <?php echo gettext("No");?></div>
- </div>
- <input type="hidden" name="GameID" value="" />
- <input type="hidden" name="sharePC" value="no" />
- <input type="hidden" name="pref_theme" value="beholder" />
-
- </form>
- </div>
-
- <h3>Pending Chalenges</h3>
- <div class="menu_form_body">
- <h1><?php echo gettext("Pending challenges");?></h1><br/>
- <label class="content" >This is an overview of all your pending challenges. Accept or decline an invitation to a new game or withdraw your invitations to others.</label><br/><br/>
- <table align="center"><thead>
- <tr><th class="mainHeader" colspan="6"><?php echo gettext("Challenges from other players");?></th></tr>
- <tr>
- <th style="text-align:left;display:none;"><?php echo gettext("Rank");?></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('respInviteTblBdy', 1, true);" title="Game Id"><?php echo gettext("Id");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('respInviteTblBdy', 2, true);" title="White's handle"><?php echo gettext("White");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('respInviteTblBdy', 3, true);" title="Black's handle"><?php echo gettext("Black");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('respInviteTblBdy', 4, true);" title="Date when the challenge was issued"><?php echo gettext("Issued");?></a></th>
- <th style="text-align:center;"><?php echo gettext("Action");?></th>
- </tr>
- </thead>
- <tbody id="respInviteTblBdy">
- <?php
- $tmpQuery = "SELECT * FROM games WHERE ga_gamemessage = 'playerInvited' AND ((ga_whiteplayer = '".$_SESSION['playerID']."' AND ga_messagefrom = 'black') OR (ga_blackplayer = '".$_SESSION['playerID']."' AND ga_messagefrom = 'white')) ORDER BY ga_datecreated";
- $tmpGames = mysql_query($tmpQuery);
-
- $rowNbr = 0;
- if (mysql_num_rows($tmpGames) == 0)
- echo("<tr><td colspan=\"3\">" . gettext("You are not currently invited to any games") . "</td></tr>\n");
- else
- while($tmpGame = mysql_fetch_array($tmpGames, MYSQL_ASSOC))
- {
- if($rowNbr %2 == 0)
- echo('<tr class="alternateRow">');
- else
- echo('<tr>');
- $rowNbr++;
-
- echo ('<td style="display:none;"></td>');
- echo("<td>");
- echo($tmpGame['ga_gameid']);
-
- /* get white's nick */
- $WhitePlayer = GetPlayerName($tmpGame['ga_whiteplayer']);
- echo ('</td><td>');
- echo($WhitePlayer);
-
- /* black's nick */
- $BlackPlayer = GetPlayerName($tmpGame['ga_blackplayer']);
- echo ('</td><td>');
- echo($BlackPlayer);
-
- /* Date issued */
- echo ("</td><td>".substr($tmpGame['ga_datecreated'], 0, -3));
-
- /* Response */
- echo ("</td><td align='center'>");
- echo ("<input class=\"button\" type=\"button\" value=\"" . gettext("Accept") . "\" onclick=\"RedirectToGame(".$tmpGame['ga_gameid'].")\" />");
- echo ("<input class=\"button\" type=\"button\" value=\"" . gettext("Decline") . "\" onclick=\"RejectGameReq(".$tmpGame['ga_gameid'].")\" />");
- echo("</td></tr>\n");
- }
- ?>
- </tbody>
- </table><br/>
- <input type="hidden" name="response" value="" />
- <input type="hidden" name="messageFrom" value="" />
- <input type="hidden" name="gameID" value="" />
- </form>
-
- <form name="withdrawRequestForm" action="mainmenu.php" method="post">
- <div class="form-block">
- <table><thead>
- <tr><th class="mainHeader" colspan="7"><?php echo gettext("Pending challenges from you");?></th> </tr>
- <tr>
- <th style="text-align:left;display:none;"><?php echo gettext("Rank");?></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inviteTblBdy', 1, true);" title="Game Id"><?php echo gettext("Id");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inviteTblBdy', 2, true);" title="White's handle"><?php echo gettext("White");?></a></th>
- <th style="text-align:left;"><a href="" onclick="this.blur(); return sortTable('inviteTblBdy', 3, true);" title="Black's handle"><?php echo gettext("Black");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inviteTblBdy', 4, true);" title="Status" ><?php echo gettext("Status");?></a></th>
- <th><a href="" onclick="this.blur(); return sortTable('inviteTblBdy', 5, true);" title="Date when the challenge was issued"><?php echo gettext("Issued");?></a></th>
- <th style="text-align:center;"><?php echo gettext("Action");?></th>
- </tr>
- </thead>
- <tbody id="inviteTblBdy">
- <?php
- /* if game is marked playerInvited and the invite is from the current player */
- $tmpQuery = "SELECT * FROM games WHERE (ga_gamemessage = 'playerInvited' AND ((ga_whiteplayer = '".$_SESSION['username']."' AND ga_messagefrom = 'white') OR ( ga_blackplayer = '".$_SESSION['username']."' AND ga_messagefrom = 'black'))";
-
- /* OR game is marked inviteDeclined and the response is from the opponent */
- $tmpQuery .= ") OR (ga_gamemessage = 'inviteDeclined' AND ((ga_whiteplayer = '".$_SESSION['username']."' AND ga_messagefrom = 'black') OR ( ga_blackplayer = '".$_SESSION['username']."' AND ga_messagefrom = 'white'))) ORDER BY ga_datecreated";
-
- $tmpGames = mysql_query($tmpQuery);
-
- $rowNbr = 0;
- if (mysql_num_rows($tmpGames) == 0)
- echo("<tr><td colspan=\"4\">" . gettext("You have no current unanswered invitations") . "</td></tr>\n");
- else
- while($tmpGame = mysql_fetch_array($tmpGames, MYSQL_ASSOC))
- {
- if($rowNbr %2 == 0)
- echo('<tr class="alternateRow">');
- else
- echo('<tr>');
- $rowNbr++;
- echo ('<td style="display:none;"></td>');
- echo("<td>");
- echo($tmpGame['ga_ID']);
-
- /* get white's nick */
- $WhitePlayer = GetPlayerName($tmpGame['ga_whiteplayer']);
- echo ('</td><td>');
- echo($WhitePlayer);
-
- /* black's nick */
- $BlackPlayer = GetPlayerName($tmpGame['ga_blackplayer']);
- echo ('</td><td>');
- echo($BlackPlayer);
-
- /* Status */
- echo ("</td><td>");
- if ($tmpGame['ga_gamemessage'] == 'playerInvited')
- echo ("Response pending");
- else if ($tmpGame['ga_gamemessage'] == 'inviteDeclined')
- echo ("Invitation declined");
-
- /* Date issued */
- echo ("</td><td>".substr($tmpGame['ga_datecreated'], 0, -3));
-
- /* Withdraw Request */
- echo ("</td><td align=\"center\">");
- echo ("<input class=\"button\" type=\"button\" value=\"" . gettext("Withdraw") . "\" onclick=\"withdrawRequest(".$tmpGame['gameID'].")\" />");
-
- echo("</td></tr>\n");
- }
- ?>
- </tbody>
- </table><br/>
- </div>
- <input type="hidden" name="gameID" value="" />
- </form>
- </div>
-
- <h3>Replay</h3>
- <div class="menu_form_body">
- </br></br>
- </div>
-
- <h3>Challenge Others</h3>
- <div class="menu_form_body">
- <span id="opponents"></span>
- </br></br>
- </div>
- </div>
- </div>
- </div>
-
- <!-- topbar-->
- <layer>
- <ul id="navigation">
- <li class="home"><a href="Home_Login.php" title="Home"></a></li>
- <li class="play"><a href="Play.php" title="Play Chess"></a></li>
- <li class="photos"><a href="Inbox.php" title="Inbox"></a></li>
- <li class="club"><a href="SearchClub.php" title="Clubs"></a></li>
- <li class="settings"><a href="Settings.php" title="Settings"></a></li>
-
- </ul>
-
- </layer>
-
- <script type="text/javascript">
- $(function() {
- $('#navigation a').stop().animate({'marginLeft':'-90px'},100);
-
- $('#navigation > li').hover(
- function () {
- $('a',$(this)).stop().animate({'marginLeft':'-70px'},100);
- },
- function () {
- $('a',$(this)).stop().animate({'marginLeft':'-90px'},100);
- }
- );
- });
- </script>
- <!--new code end -->
- <div class="clear"></div>
- <div id="footers">
-
-
- <div style="float:right"><div class="fotterlast">
- <a href="#" title="About Us">About Us</a>
- |
- <a href="#" title="Terms of Service">Terms of Service</a>
- |
- <a href="#" title="Privacy Statement">Privacy</a>
- |
- <a href="#" title="Contact Us">Contact Us</a>
- </div></div>
-
- <div style="float:Left"><div class="fotterlastdesing">Designed by SEP_WE_05 Team.</div></div>
-
- </div>
- </div>
- </div>
- </div>
- </body>
- </html>