######################################################################
Chess.php
######################################################################
<?php
session_start();
$sController = 'chess';
/* load settings */
require_once './includes/config.inc.php';
require_once './includes/common.inc.php';
if ($bPIncludeSequence) $firephp->fb('chess|' . $sController, FirePHP::INFO);
$firephp->fb('chess|' . $sController, FirePHP::INFO);
require_once('./ob.lib.php');
if ($COMPRESSION) {
$ob_mode = PMA_outBufferModeGet();
if ($ob_mode) {
PMA_outBufferPre($ob_mode);
}
}
/* define constants */
require_once './includes/chessconstants.inc.php';
/* include outside functions */
if (!isset($_CHESSUTILS))
require_once './includes/chessutils.inc.php';
require_once './includes/gui.inc.php';
require_once './includes/chessdb.inc.php';
require_once './includes/move.inc.php';
require_once './includes/undo.inc.php';
/* allow WebChess to be run on PHP systems < 4.1.0, using old http vars */
fixOldPHPVersions();
/* check session status */
require_once './includes/sessioncheck.inc.php';
/* check if loading game */
if (isset($_POST['gameID']))
$_SESSION['gameID'] = $_POST['gameID'];
/* debug flag */
define ("DEBUG", 0);
/* connect to database */
require_once './includes/connectdb.inc.php';
/* Language selection */
require_once "includes/languageselection.inc.php";
/* load game */
$isInCheck = ($_POST['isInCheck'] == 'true');
$isCheckMate = false;
$isPromoting = false;
$isUndoing = false;
loadHistory();
loadGame();
$p = mysql_query("SELECT * from games WHERE gameID='".$_SESSION['gameID']."'");
if (mysql_num_rows($p) ==0){
//The game was deleted
echo "<script>window.location='./mainmenu.php'</script>";
exit;
}
$row = mysql_fetch_array($p);
$white = $row['whitePlayer'];
$black = $row['blackPlayer'];
$timeLimit = $row['timelimit'];
$flagFall = $row['flagFall'];
$official = $row['oficial'];
$blitz = $row['blitz'];
$team = $row['team'];
if ($row['whitePlayer'] == $_SESSION['playerID']) {
$MyRating = getRating($row['whitePlayer']);
$OpponentRating = getRating($row['blackPlayer']);
$MyPV = $row['PVWhite'];
$OpponentPV = $row['PVBlack'];
$myID = $row['whitePlayer'];
$oppID = $row['blackPlayer'];
} else {
$MyRating = getRating($row['blackPlayer']);
$OpponentRating = getRating($row['whitePlayer']);
$MyPV = $row['PVBlack'];
$OpponentPV = $row['PVWhite'];
$myID = $row['blackPlayer'];
$oppID = $row['whitePlayer'];
}
processMessages();
/* Verify permission */
if (!isBoardDisabled()){
if (($white != $_SESSION['playerID']) && ($black != $_SESSION['playerID']))
die(_("youdonthavepermission"));
}
if (($numMoves == -1) || ($numMoves % 2 == 1)){
$mycolor2 = "white";
}
else{
$mycolor2 = "black";
}
/* find out if it's the current player's turn */
if (( (($numMoves == -1) || (($numMoves % 2) == 1)) && ($playersColor == "white"))
|| ((($numMoves % 2) == 0) && ($playersColor == "black")))
$isPlayersTurn = true;
else
$isPlayersTurn = false;
if ($white == $_SESSION['playerID'])
$opponent = $black;
else $opponent = $white;
if (!isBoardDisabled() && !$isCheckMate && $timeLimit > 0)
if (tempoEsgotado($mycolor2)){
saveRanking($_SESSION['gameID'],"resign",$mycolor2,1);
updateTimestamp();
// Update the opponent time
if ($mycolor2 == "white")
mysql_query("UPDATE games set timeWhite=$timeLimit*60 WHERE gameID=".$_SESSION['gameID']);
else
mysql_query("UPDATE games set timeBlack=$timeLimit*60 WHERE gameID=".$_SESSION['gameID']);
echo "<script>
alert('"._("theflaghasfallen")." $mycolor2 " . _("lost") . "');
window.location='chess.php';
</script>\n";
exit;
}
if ($isUndoing)
{
doUndo();
saveGame();
}
else if ($CFG_ENABLE_CHAT && isset($_POST['chat_msg'])){
if ($_POST[chat_msg] != ""){
if (!get_magic_quotes_gpc())
$_POST[chat_msg] = addslashes($_POST[chat_msg]);
$_POST[chat_msg] = wordwrap($_POST[chat_msg], 35, " ", 1);
mysql_query("insert into chat (fromID,msg,gameID) VALUES ('".$_SESSION[playerID]."','".$_POST[chat_msg]."','".$_SESSION[gameID]."')");
}
}
else if ($_POST[note_msg] != ""){
if (!get_magic_quotes_gpc())
$_POST[note_msg] = addslashes($_POST[note_msg]);
$p2 = mysql_query("SELECT count(*) from history WHERE gameID='".$_SESSION[gameID]."'");
$row2 = mysql_fetch_array($p2);
$rounds = floor(($row2[0]+1)/2);
$color = "b";
if ($rounds == (($row2[0]+1)/2)) $color = "w";
if ($rounds != 0) $rounds = $rounds.$color;
$notemsg = $_POST[note_msg];
$temparray = array($notemsg, $rounds);
$_POST[note_msg] = implode(" - Move #", $temparray);
mysql_query("insert into notes (fromID,note,gameID,hora) VALUES ('".$_SESSION[playerID]."','".$_POST[note_msg]."','".$_SESSION[gameID]."',now())");
}
elseif (($_POST['promotion'] != "") && ($_POST['toRow'] != "") && ($_POST['toCol'] != ""))
{
savePromotion();
$board[$_POST['toRow']][$_POST['toCol']] = $_POST['promotion'] | ($board[$_POST['toRow']][$_POST['toCol']] & BLACK);
saveGame();
}
elseif (($_POST['fromRow'] != "") && ($_POST['fromCol'] != "") && ($_POST['toRow'] != "") && ($_POST['toCol'] != ""))
{
/* ensure it's the current player moving */
/* NOTE: if not, this will currently ignore the command... */
/* perhaps the status should be instead? */
/* (Could be confusing to player if they double-click or something */
$tmpIsValid = true;
if (($numMoves == -1) || ($numMoves % 2 == 1))
{
/* White's move... ensure that piece being moved is white */
if ((($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) != 0) || ($board[$_POST['fromRow']][$_POST['fromCol']] == 0))
/* invalid move */
$tmpIsValid = false;
}
else
{
/* Black's move... ensure that piece being moved is black */
if ((($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) != BLACK) || ($board[$_POST['fromRow']][$_POST['fromCol']] == 0))
/* invalid move */
$tmpIsValid = false;
}
if ($tmpIsValid)
{
saveHistory();
doMove();
saveGame();
}
}
?>
<!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" />
<link rel="stylesheet"
href="themes/<?=$_SESSION["pref_colortheme"]?>/styles.css"
type="text/css" />
<link rel="stylesheet"
href="boardcolor/<?=$_SESSION["pref_board"]?>/board.css"
type="text/css" />
<!-- gameID: <?=$_SESSION['gameID']?> -->
<?php
/* find out if it's the current player's turn */
if (( (($numMoves == -1) || (($numMoves % 2) == 1)) && ($playersColor == "white"))
|| ((($numMoves % 2) == 0) && ($playersColor == "black")))
$isPlayersTurn = true;
else
$isPlayersTurn = false;
if ($white == $_SESSION['playerID'])
$opponent = $black;
else $opponent = $white;
if ($_SESSION['isSharedPC'])
echo("<title>".$CFG_SITE_NAME."</title>\n");
else if ($isPlayersTurn)
echo("<title>".$CFG_SITE_NAME." - "._("yourturn")."</title>\n");
else
echo("<title>".$CFG_SITE_NAME." - "._("opponentturn")."</title>\n");
echo("<meta HTTP-EQUIV='Pragma' CONTENT='no-cache'>\n");
echo '<meta http-equiv="cache-control" content="no-cache">';
echo '<meta http-equiv="expires" content="-1">';
/* if it's not the player's turn, enable auto-refresh*/
/* if (!$isPlayersTurn && !isBoardDisabled())
{
echo ("<META HTTP-EQUIV=Refresh CONTENT='");
if ($_SESSION['pref_autoreload'] >= $CFG_MINAUTORELOAD)
echo ($_SESSION['pref_autoreload']);
else
echo ($CFG_MINAUTORELOAD);
echo ("; URL=chess.php?autoreload=yes'>\n");
} */
?>
<script type="text/javascript">
<? writeJSboard(); ?>
<? writeJShistory(); ?>
if (DEBUG)
alert("Game initilization complete!");
stopTimer = 0;
function refreshwindow(){
if (stopTimer == 0)
window.location='chess.php';
}
function loadnextGame(gameID)
{
//if (document.allhisgames.rdoShare[0].checked)
// document.allhisgames.action = "modules/webchess/opponentspassword.php";
document.allhisgames.gameID.value = gameID;
document.allhisgames.submit();
}
</script>
<script type="text/javascript" src="javascript/chessutils.js">
/* these are utility functions used by other functions */
</script>
<script type="text/javascript" src="javascript/commands.js">
// these functions interact with the server
</script>
<script type="text/javascript" src="javascript/validation.js">
// these functions are used to test the validity of moves
</script>
<script type="text/javascript" src="javascript/isCheckMate.js">
// these functions are used to test the validity of moves
</script>
<script type="text/javascript" src="javascript/squareclicked.js">
// this is the main function that interacts with the user everytime they click on a square
</script>
<script>
function MessagePlayer(playerID)
{
var where="sendmessage.php?<?=$ssname?>=<?=$ssid?>&to="+playerID;
var height=320;
var width=470;
var left=(screen.availWidth/2)-(width/2);
var top=(screen.availHeight/2)-(height/2)-100;
window.open(where,"","height="+height+",width="+width+",left="+left+",top="+top);
}
</script>
<script language="JavaScript">
var on= "#008000";
var off= "#800000";
var blinkspeed= 400;
function blink()
{
if( document.all.blink.style.color == off) {
document.all.blink.style.color = on;
}
else {
document.all.blink.style.color = off;
}
}
</script>
<SCRIPT language="JavaScript">
<!-- Idea by: Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL: http://fineline.xs.mw -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=250,left = 162,top = 184');");
}
// End -->
</script>
<script language="JavaScript">
<!-- Idea by: Nic Wolfe (Nic@TimelapseProductions.com) -->
<!-- Web URL: http://fineline.xs.mw -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
function popUp2(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=700,height=600,left = 162,top = 10');");
}
// End -->
</script>
<script type="text/javascript" src="themes/lighter/tools.js"></script>
<script type="text/javascript" src="themes/lighter/Lighter.js"></script>
<script type="text/javascript" src="themes/lighter/Fuel.css.js"></script>
<script type="text/javascript" src="themes/lighter/Fuel.html.js"></script>
<script type="text/javascript" src="themes/lighter/Fuel.js.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
$$('code').light({
altLines: 'hover',
path: 'lighter/',
mode: 'ol',
fuel: 'js',
indent: 4
});
});
</script>
<link rel="stylesheet" href="themes/css/multibox.css" type="text/css" media="screen" />
<!--[if IE 6]>
<link rel="stylesheet" href="themes/css/multibox-ie6.css" type="text/css" media="screen" />
<![endif]-->
<script type="text/javascript" src="javascript/overlay.js"></script>
<script type="text/javascript" src="javascript/Assets.js"></script>
<script type="text/javascript" src="javascript/multibox.js"></script>
<script type="text/javascript">
window.addEvent('domready', function(){
var box = new multiBox('mb', {
overlay: new overlay()
});
var advanced = new multiBox('advanced', {
overlay: new overlay(),
descClassName: 'advancedDesc'
});
});
</script>
<style>
TABLE {
font-size: 12;
font-family: verdana;
}
</style>
<meta http-equiv="refresh" content="5000" />
</head>
<body>
<script type="text/javascript" src="javascript/wz_tooltip.js"></script>
<center>
<table class="bodyline" border="0" align="center" width="100%">
<tr>
<td colspan=3 align="center" width="98%">
<table border="0" align="center" width="100%" class='MYGAMESMENUTABLE'>
<tr>
<td colspan=3 align="center" width="100%"><?
$title= $_SESSION['gameID'];
echo '<table width="98%" class="TABLE" align="center">';
echo "<tr>
<th class='THTOP'>" . _("My Info") . "</th>
<th class='THTOP'>" . _("Game No") . "</th>
<th class='THTOP'>" . _("Game Type") . "</th>
<th class='THTOP'>" . _("(W-D-L") . ")</th>
<th class='THTOP'>" . _("Status") . "</th>
<th class='THTOP'>" . _("Opponent Info") . "</th>
</tr>
<tr>
<td align='center' class='TD'>";
$p = mysql_query("SELECT nick,playerID,engine,lastUpdate FROM players WHERE playerID='$white'");
$row = mysql_fetch_array($p);
$p = mysql_query("SELECT nick,playerID,engine,lastUpdate FROM players WHERE playerID='$black'");
$row2 = mysql_fetch_array($p);
$row[0] = $row[0]." "._("whitestats")."";
$row2[0] = $row2[0]." "._("blackstats")."";
$row[3] = $row[3];
$row2[3] = $row2[3];
if ($row["engine"] == "1" || $row2["engine"] == "1")
$isEngine=true;
$p = mysql_query("SELECT value FROM preferences WHERE preference='language' AND playerID=$opponent");
$r = mysql_fetch_array($p);
if ($_SESSION['pref_language'] != $r[0])
$opponent_language = strtoupper($r[0]);
else $opponent_language = "";
$rt = mysql_query("SELECT * FROM players WHERE playerID='$_SESSION[playerID]'");
$mr = mysql_fetch_array($rt);
$fn = mysql_query("SELECT * FROM players WHERE playerID='$opponent'");
$opp = mysql_fetch_array($fn);
echo " <img src='images/flags/".$_SESSION['country'].".gif'> ";
if ($mr['lastUpdate'] >= (time()-300))
$oimg="online";
else
$oimg="offline";
$xpw = getXPW($MyRating,$OpponentRating,getPV($_SESSION['playerID']));
$xpl = getXPL($OpponentRating,$MyRating,getPV($opponent));
$xpd = getXPD($MyRating,$OpponentRating);
?> <img src="http://www.tutorials.de/forum/images/<?= $oimg ?>.gif" /> <div id="advanced"><a
href="quick_stats.php?cod=<?=$_SESSION['playerID']?>" rel="width:780,height:400" class="advanced" title="<?= $_SESSION['nick'] ?>"><?= $_SESSION['nick'] ?>
</a> <?= $mr['rating'] ?></td>
<td class='TD' align='center'
onmouseover="Tip('<center><br /> <?= _("Current Ratings") ?>: <?=$mr['nick']?> = <?= $MyRating ?>, <?=$opp['nick']?> = <?=$OpponentRating ?> <br /><br /> <?= _("Rating points if you win")?>: (+<?=$xpw?>)<br /> <?= _("Rating points if you draw")?>: (<?=$xpd?>)<br /> <?= _("Rating points if you lose")?>: (-<?=$xpl?>)<br /><br />')"
onmouseout="UnTip()"><strong><?=$_SESSION['gameID']?></strong><br />
<br />
<img class="<?= ($official)?"officialgame":"inofficialgame" ?>" src='images/info.gif' /></td>
<?php
$pt = mysql_query("SELECT * from games WHERE gameID='".$_SESSION['gameID']."'");
$tmpGame = mysql_fetch_array($pt);
if ($tmpGame['tournament'] != 0)
{
$bTournament = TRUE;
$t = mysql_fetch_array(mysql_query("SELECT id,name FROM tournaments WHERE id = '".$tmpGame['tournament']."'"));
$t['name'] = stripslashes($t['name']);
echo "<td align='center' class='TD'><a href='tournaments.php?action=view&id=".$t[id]."'>" . _("RR Tournament Game") . "</a></td>";
}
elseif ($tmpGame['swiss'] != 0)
{
$t2 = mysql_fetch_array(mysql_query("SELECT id,tourneyname FROM swiss WHERE id = '".$tmpGame['swiss']."'"));
$t2['tourneyname'] = stripslashes($t2['tourneyname']);
echo "<td align='center' class='TD'><a href='swiss.php?action=show&id=".$t2['id']."'>" . _("Swiss Tournament Game") . "</a></td>";
}
elseif($tmpGame['team'] != 0)
{
echo "<td align='center' class='TD'><a href='stats_matches.php?cod=$tmpGame[team]'><strong>" . _("Team Match Game") . "</strong></a> <img src='images/groupevent.gif' border='0'></td>";
}
elseif($tmpGame['blitz'] == 1)
{
echo "<td align='center' class='TD'><strong>" . _("LIVE GAME!") . "</strong> <img src='images/flag.gif' border='0'></td>";
}
elseif($tmpGame['thematic'] == 1){
echo "<td align='center' class='TD'><strong>" . _("alekhine_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 2){
echo "<td align='center' class='TD'><strong>" . _("birds_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 3){
echo "<td align='center' class='TD'><strong>" . _("budapest_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 4){
echo "<td align='center' class='TD'><strong>" . _("catalan_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 5){
echo "<td align='center' class='TD'><strong>" . _("carokann_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 6){
echo "<td align='center' class='TD'><strong>" . _("cochranegambit_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 7){
echo "<td align='center' class='TD'><strong>" . _("dutchdefense_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 8){
echo "<td align='center' class='TD'><strong>" . _("leningraddutch_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 9){
echo "<td align='center' class='TD'><strong>" . _("fourknights_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 10){
echo "<td align='center' class='TD'><strong>" . _("frenchdefense_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 11){
echo "<td align='center' class='TD'><strong>" . _("frenchadvance_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 12){
echo "<td align='center' class='TD'><strong>" . _("frenchclassical_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 13){
echo "<td align='center' class='TD'><strong>" . _("frenchrubinstein_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 14){
echo "<td align='center' class='TD'><strong>" . _("frenchwinawer_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 15){
echo "<td align='center' class='TD'><strong>" . _("frenchtarrasch_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 16){
echo "<td align='center' class='TD'><strong>" . _("grob_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 17){
echo "<td align='center' class='TD'><strong>" . _("grunfeld_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 52){
echo "<td align='center' class='TD'><strong>" . _("halloween_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 18){
echo "<td align='center' class='TD'><strong>" . _("kingsgambit_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 54){
echo "<td align='center' class='TD'><strong>" . _("falkbeer_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 55){
echo "<td align='center' class='TD'><strong>" . _("kieseritzky_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 23){
echo "<td align='center' class='TD'><strong>" . _("muziogambit_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 19){
echo "<td align='center' class='TD'><strong>" . _("kingsindian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 20){
echo "<td align='center' class='TD'><strong>" . _("italiangame_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 21){
echo "<td align='center' class='TD'><strong>" . _("larsens_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 53){
echo "<td align='center' class='TD'><strong>" . _("latvian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 57){
echo "<td align='center' class='TD'><strong>" . _("london_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 22){
echo "<td align='center' class='TD'><strong>" . _("modernbenoni_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 24){
echo "<td align='center' class='TD'><strong>" . _("nimzoindian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 58){
echo "<td align='center' class='TD'>Owens Defense</strong></td>\n";
}elseif ($tmpGame[thematic] == 25){
echo "<td align='center' class='TD'><strong>" . _("petroff_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 49){
echo "<td align='center' class='TD'><strong>" . _("pirc_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 26){
echo "<td align='center' class='TD'><strong>" . _("philidor_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 27){
echo "<td align='center' class='TD'><strong>" . _("queensgambit1_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 28){
echo "<td align='center' class='TD'><strong>" . _("queensgambit2_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 29){
echo "<td align='center' class='TD'><strong>" . _("queensindian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 30){
echo "<td align='center' class='TD'><strong>" . _("ruylopez_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 50){
echo "<td align='center' class='TD'><strong>" . _("ruylopez_bird_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 31){
echo "<td align='center' class='TD'><strong>" . _("scandinavian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 32){
echo "<td align='center' class='TD'><strong>" . _("scotch_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 33){
echo "<td align='center' class='TD'><strong>" . _("sicilian_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 34){
echo "<td align='center' class='TD'><strong>" . _("sicilianalapin_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 35){
echo "<td align='center' class='TD'><strong>" . _("sicilianclosed_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 36){
echo "<td align='center' class='TD'><strong>" . _("siciliansveshnikov_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 37){
echo "<td align='center' class='TD'><strong>" . _("siciliansimagin_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 38){
echo "<td align='center' class='TD'><strong>" . _("sicilianpaulsen_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 39){
echo "<td align='center' class='TD'><strong>" . _("sicilianrichterrauzer_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 40){
echo "<td align='center' class='TD'><strong>" . _("siciliandragon_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 41){
echo "<td align='center' class='TD'><strong>" . _("sicilianscheveningen_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 42){
echo "<td align='center' class='TD'><strong>" . _("siciliansozin_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 43){
echo "<td align='center' class='TD'><strong>" . _("siciliannajdorf_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 51){
echo "<td align='center' class='TD'><strong>" . _("siciliansmithmorra_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 44){
echo "<td align='center' class='TD'><strong>" . _("slav_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 56){
echo "<td align='center' class='TD'><strong>" . _("semislav_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 45){
echo "<td align='center' class='TD'><strong>" . _("sokolsky1_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 46){
echo "<td align='center' class='TD'><strong>" . _("tarrasch_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 47){
echo "<td align='center' class='TD'><strong>" . _("vienna_2") . "</strong></td>\n";
}elseif ($tmpGame[thematic] == 48){
echo "<td align='center' class='TD'><strong>" . _("volgagambit_2") . "</strong></td>\n";
} else
{
echo "<td align='center' class='TD'><strong>" . _("Challenge Game") . " </strong></td>";
}
?>
<td align='center' class='TD'><strong><?= get_record($_SESSION['playerID'],$opponent)?></strong></td>
<td align='center' class='TD'><?=writeStatus()?></td>
<td align='center' class='TD'><?php
$fn = mysql_query("SELECT nick,playerID,rating,pais,lastUpdate FROM players WHERE playerID='$opponent'");
$nam = mysql_fetch_array($fn);
echo " <img src='images/flags/".$nam['pais'].".gif'> ";
if ($nam['lastUpdate'] >= (time()-300))
$oimg="online";
else
$oimg="offline";
?> <img src="http://www.tutorials.de/forum/images/<?= $oimg ?>.gif" /> <div id="advanced"><a
href="quick_stats.php?cod=<?=$nam[playerID]?>" rel="width:770,height:280" class="advanced" title="<?=$nam['nick']?>"><?=$nam['nick']?></a>
<?= $nam['rating']?></div></td>
</tr>
<tr>
<td align='center' colspan=6 class='TD'><strong>::</strong> <a
href="mainmenu.php"><?= _("My Games") ?></a> <strong>::</strong>
<a href="chessboard.php" rel="width:780,height:540" class="advanced" title="<?= _("Chessboard Settings") ?>"><?= _("Chessboard Settings") ?></a>
<?
$msg = mysql_query("SELECT * FROM players WHERE playerID='".$nam['playerID']."'");
$sendmsg = mysql_fetch_array($msg);
$msgid = $sendmsg['playerID'];
$ignore = mysql_query("SELECT * FROM ignoreplayer WHERE ((player1='".$_SESSION['playerID']."' AND player2='".$nam['playerID']."') OR (player1='".$nam['playerID']."' AND player2='".$_SESSION['playerID']."'))");
$ignore2 = mysql_fetch_array($ignore);
$ignorelist = $ignore2['player2'];
if ($ignorelist > 0){
//todo show ignore list?
echo "";
} else { ?> <strong>::</strong> <a
href="sendmessage.php?cod=<?=$nam['playerID']?>" rel="width:780,height:505" class="advanced" title="<?= _("Message Opponent") ?>"><?= _("Message Opponent") ?></a></div>
<?
}
$m = ("SELECT ack,toID FROM communication WHERE (toID = ".$_SESSION['playerID']." OR toID = NULL) AND ack = 0 and listed <> 1");
$numresults=mysql_query($m);
$numrows=mysql_num_rows($numresults);
if ($numrows != 0){
echo "<strong>::</strong> <a href='messages.php'><strong>" . _("You have new mail!") . "</strong></a>";
}
?></td>
</tr>
</table>
</td>
</tr>
<tr valign="top" align="center">
<td align="center">
<form name="gamedata" method="post" action="chess.php"><input
type=hidden name="gameID" value="<?=$_SESSION["gameID"]?>" /><?php
/* Verify if the promotion process was completed */
if ($playersColor == "white"){
$promotionRow = 7;
$otherRow = 0;
}
else{
$promotionRow = 0;
$otherRow = 7;
}
for ($i = 0; $i < 8; $i++)
if (($board[$promotionRow][$i] & COLOR_MASK) == PAWN){
$isPromoting = true;
$p = mysql_query("SELECT * FROM history where toCol='$i' AND toRow='$promotionRow' AND curPiece='pawn' and curColor='$playersColor' and gameID='$_SESSION[gameID]' ORDER BY timeOfMove DESC limit 1")
OR new cMyErrors(cMyErrors::THROW_MYSQL, 'c698');
$row = mysql_fetch_array($p);
$_POST['fromRow'] = $row[fromRow];
$_POST['fromCol'] = $row[fromCol];
$_POST['toRow'] = $row[toRow];
$_POST['toCol'] = $row[toCol];
}
for ($i = 0; $i < 8; $i++)
if (($board[$otherRow][$i] & COLOR_MASK) == PAWN){
writeWaitPromotion();
$isPromoting = 1;
$otherTurn = 1;
}
if ($isPromoting && !$otherTurn)
writePromotion();
?> <?
if ($isUndoRequested)
writeUndoRequest();
if ($isDrawRequested)
writeDrawRequest();
if (isBoardDisabled() OR ($numMoves < 0) OR ($bTournament AND $CFG_ENABLE_UNDO_TOURNAMENT)) $bButtonDisabled ='disabled="disabled';
?> <br />
<input type="button" name="btnReload" value="<?=_("refresh2")?>"
onclick="window.open('chess.php', '_self')" /> <input type="button"
value="<?=_("Analyze")?>"
onclick="window.open('analyze.php?whocolor=<?=$playersColor?>&game=<?=$_SESSION['gameID']?>', '_blank', 'scrollbars=1,width=900,height=660')"
<?= $bButtonDisabled ?> /> <input type="button" name="btnReload"
value="<?=_("undomove")?>" onclick="undo('<?= _("undowarning")?>')"
<?php if (isBoardDisabled()) echo("disabled='yes'") ?> /> <input type="button" name="btnDraw"
value="<?=_("askdraw")?>"
<?php if (isBoardDisabled()) echo("disabled='yes'"); elseif ($isPlayersTurn == true) echo("onclick='drawrequestwithoutmove(\"" . _("drawrequestwithoutmovingfirst") . "\")'"); else echo ("onclick='draw($CFG_MIN_ROUNDS,\""._("roundwarning")."\")'"); ?> /><input
type="button" name="btnResign" value="<?=_("resign")?>"
<?php if (isBoardDisabled()) echo("disabled='yes'"); else echo ("onclick='resigngame($CFG_MIN_ROUNDS,\""._("roundwarning")."\")'"); ?> />
<br />
<table border="0" cellpadding="0">
<tr valign="top" align="center">
<td align="center"><?php drawboard(); ?></td>
</tr>
</table>
<table width="325" class="MYGAMESMENUTABLE">
<?php
//Pieces out:
$black = StartPieces();
$white = StartPieces();
$p = mysql_query("SELECT * FROM pieces WHERE gameID = ".$_SESSION['gameID']." order by color,piece");
$wmaterial = 0;
$bmaterial = 0;
while ($row = mysql_fetch_array($p)){
if ($row['color'] == "white"){
$white[$row['piece']]--;
$tempmaterial=0;
if ($row['piece']=="pawn" AND $row['color']=="white")
$tempmaterial=1;
if ($row['piece']=="knight" AND $row['color']=="white")
$tempmaterial=3;
if ($row['piece']=="bishop" AND $row['color']=="white")
$tempmaterial=3;
if ($row['piece']=="rook" AND $row['color']=="white")
$tempmaterial=5;
if ($row['piece']=="queen" AND $row['color']=="white")
$tempmaterial=9;
$wmaterial=$wmaterial+$tempmaterial;}
else {
$black[$row['piece']]--;
$tempmaterial=0;
if ($row['piece']=="pawn" AND $row['color']=="black")
$tempmaterial=1;
if ($row['piece']=="knight" AND $row['color']=="black")
$tempmaterial=3;
if ($row['piece']=="bishop" AND $row['color']=="black")
$tempmaterial=3;
if ($row['piece']=="rook" AND $row['color']=="black")
$tempmaterial=5;
if ($row['piece']=="queen" AND $row['color']=="black")
$tempmaterial=9;
$bmaterial=$bmaterial+$tempmaterial;}
}
?>
<tr>
<td align=center><strong><?= _("Captured Pieces") ?></strong></td>
<td align=center style="width: 4em"><strong><?= _("Material") ?></strong>
</td>
</tr>
<tr>
<td align="left""><?php
while(list($piece,$num) = each($white))
if ($num > 0)
for ($y=0; $y<$num; $y++)
echo "<img src='images/pieces/".$_SESSION['pref_theme']."/white_".$piece.".gif' height='25'> ";
$wmaterial = 39 - $wmaterial;
echo '</td><td align="center">';
echo "<font size=-1>".$wmaterial."</font>";
echo "</td></tr>";
echo '<tr><td align="left">';
while(list($piece,$num) = each($black))
if ($num > 0)
for ($y=0; $y<$num; $y++)
echo "<img src='images/pieces/".$_SESSION['pref_theme']."/black_".$piece.".gif' height='25'> ";
$bmaterial = 39 - $bmaterial;
?></td>
<td align="center"><font size=-1><?=$bmaterial ?></font></td>
</tr>
</table>
<!-- table border="0">
<tr><td --> <?
$p = mysql_query("SELECT nick,playerID,engine FROM players WHERE playerID='$white'");
$row = mysql_fetch_array($p);
$p = mysql_query("SELECT nick,playerID,engine FROM players WHERE playerID='$black'");
$row2 = mysql_fetch_array($p);
$row[0] = $row[0]." "._("whitestats")."";
$row2[0] = $row2[0]." "._("blackstats")."";
$row[3] = $row[3];
$row2[3] = $row2[3];
if ($row["engine"] == "1" || $row2["engine"] == "1")
$isEngine=true;
$p = mysql_query("SELECT value FROM preferences WHERE preference='language' AND playerID=$opponent");
$r = mysql_fetch_array($p);
if ($_SESSION['pref_language'] != $r[0])
$opponent_language = strtoupper($r[0]);
else $opponent_language = "";
echo "<br />";
if ($tmpGame['blitz'] == 1) {
?> <br />
<table style='border: 0; background-color: FFFFFF; width: 90'>
<tr>
<td bgcolor='<?=$bgcolor8 ?>'><img src='images/flag.gif' /> <font
id=blink><strong><?= _("Live Game!") ?></strong></font></td>
</tr>
</table>
<script>
setInterval("blink()",blinkspeed);
</script> <?php } ?> <input type="hidden" name="requestUndo"
value="no" /> <input type="hidden" name="requestDraw" value="no" /> <input
type="hidden" name="resign" value="no" /> <input type="hidden"
name="fromRow" value="<?=$_POST['fromRow']?>" /> <input type="hidden"
name="fromCol" value="<?=$_POST['fromCol']?>" /> <input type="hidden"
name="toRow" value="<?=$_POST['toRow']?>" /> <input type="hidden"
name="toCol" value="<?=$_POST['toCol']?>" /> <input type="hidden"
name="isInCheck" value="false" /> <input type="hidden"
name="isCheckMate" value="false" /> <?php
if ($isPromoting && $isEngine) {
echo "<script>promotepawn();</script>";
} ?></form>
</td>
<td align="center">
<form name="allhisgames" action="chess.php" method="post"><br />
<table class='TABLE' align='center'>
<tr>
<th class='THTOP'><?= _("My Games")?></th>
</tr>
<tr>
<td>
<div style='width: 247; overflow: auto; height: 100'>
<table border='1' width='227' align='center' cellspacing='0'
cellpadding='4' bgcolor="<?=$bgcolor6?>">
<?php
$tmpGames = mysql_query("SELECT games.*,DATE_FORMAT(dateCreated, '%d/%m/%y %H:%i') as created, DATE_FORMAT(lastMove, '%d/%m/%y %H:%i') as lastm FROM games WHERE gameMessage = '' AND (whitePlayer = ".$_SESSION['playerID']." OR blackPlayer = ".$_SESSION['playerID'].") ORDER BY lastMove");
if (mysql_num_rows($tmpGames) > 0){
$l = 0;
while($tmpGame = mysql_fetch_array($tmpGames, MYSQL_ASSOC))
{
/* get opponent's nick */
if ($tmpGame['whitePlayer'] == $_SESSION['playerID'])
$tmpOpponent = mysql_query("SELECT nick,lastUpdate,engine,playerID FROM players WHERE playerID = ".$tmpGame['blackPlayer']);
else
$tmpOpponent = mysql_query("SELECT nick,lastUpdate,engine,playerID FROM players WHERE playerID = ".$tmpGame['whitePlayer']);
$row = mysql_fetch_array($tmpOpponent);
$opponent = substr($row[0],0,25);
if ($tmpGame['whitePlayer'] == $_SESSION['playerID'])
$tmpColor = "white";
else
$tmpColor = "black";
if ($row[2] >= (time()-300))
$img = "online";
else
$img = "offline";
$tmpNumMoves = mysql_query("SELECT COUNT(gameID) FROM history WHERE gameID = ".$tmpGame['gameID']);
$numMoves_2 = mysql_result($tmpNumMoves,0);
$yourturn = false;
if (($numMoves_2 % 2) == 0){
$tmpCurMove = "white";
if ($tmpColor == "white")
$yourturn = true;
}else{
$tmpCurMove = "black";
if ($tmpColor == "black")
$yourturn = true;
}
if (($yourturn || $img == "online") && $tmpGame['gameID'] != $_SESSION['gameID']){
$l++;
if ($l == 1){
echo '<tr>
<th align="center" bgcolor='.$bgcolor8.'> </th>
<th align="center" bgcolor='.$bgcolor8.'>';?>
<?=_("opponent")?>
<?
echo '</th>
<th align="center" bgcolor='.$bgcolor8.'>';?>
<?=_("turn")?>
<?
echo '</th>
</tr>';
}
echo "<tr>";
echo "<td bgcolor='#EEEEEE' align=center><input style='font-size:11' type=button value='"._("play")."' onclick='loadnextGame(".$tmpGame['gameID'].")'></td>";
/* Opponent */
echo("<td bgcolor='#EEEEEE' align='center'>");
//$lasttouch = date("d.m.y, H:i", $row[2]);
echo("<a href='stats_user.php?cod=".$row['playerID']."'><strong><font color=blue>".$opponent."</font></strong>"."</a>"."<br /> ".$lasttouch);
//echo $opponent;
/* Your Color */
echo ("</td><td bgcolor='#EEEEEE' align=center>");
$tmpGameMsg = mysql_query("select * from messages where gameID = ".$tmpGame['gameID']);
$gameMsg = mysql_fetch_array($tmpGameMsg);
$gameMsgExist = 0;
if ($gameMsg['msgType'] <> ""){
$gameMsgExist = 1;
if ($gameMsg['msgType'] == "undo") {?>
<strong><font color=red><?= _("Undo Pending") ?></font></strong>
<?}
if ($gameMsg['msgType'] == "draw") {?>
<strong><font color=red><?= _("Draw Offer") ?></font></strong>
<?}
}
if ($gameMsgExist == 0){
if ($yourturn)
echo("<strong><font color=red>"._("yourturn")."</font></strong>");
else
echo _("waiting"); }
echo ("</td>");
echo "</tr>\n";
}
}
if ($l ==0)
echo("<tr><td width='250' bgcolor='#EEEEEE' align=center><font color=black>" . _("There are no games where it is your turn.") . "</font></td></tr>\n");
/* share PC */
//echo ("<tr><td colspan='3'>Will both players play from the same PC?</td>");
//echo ("<td><input type='radio' name='rdoShare' value='yes'> Yes</td>");
//echo ("<td><input type='radio' name='rdoShare' value='no' checked> No</td></tr>\n");
}
?>
</table>
</div>
</td>
</tr>
</table>
<br />
<form method="post" action="chess.php" name=chess><input type=hidden
name="gameID" value="<?=$_SESSION["gameID"]?>" />
<table border="0" width="250" class='TABLE' align="center">
<tr>
<th class='THTOP'><?=_("Game Notes") ?></th>
</tr>
<tr>
<td>
<div style='width: 247; overflow: auto; height: 100'>
<table border='1' width='227' align='center' cellspacing='0'
cellpadding='1'>
<tr>
<td bgcolor="#EEEEEE" align="center"><input type=text
name=note_msg size=20 onclick="stopTimer=1" /><input type=submit
value="<?=_("write")?>" /></td>
</tr>
<tr>
<td bgcolor="#EEEEEE" align="left"><?= writeNote($_SESSION['gameID'])?>
</table>
</div>
</table>
</form>
<?php
$ignoreplayer = mysql_query("SELECT * FROM ignoreplayer WHERE ((player1='".$_SESSION['playerID']."' AND player2='".$nam['playerID']."') OR (player1='".$nam['playerID']."' AND player2='".$_SESSION['playerID']."'))");
$ignoreplayer2 = mysql_fetch_array($ignoreplayer);
$ignoreplayerlist = $ignoreplayer2['player2'];
$ignoreplayerlist2 = $ignoreplayer2['player1'];
if ($ignoreplayerlist > 0) {
// echo "";
}
else if ($ignoreplayerlist2 > 0) {
//
}
else {
if ($CFG_ENABLE_CHAT && !isBoardDisabled()) {
?>
<form method="post" action="chess.php" name=chess><input type=hidden
name="gameID" value="<?=$_SESSION["gameID"]?>" />
<table border="0" width="250" class='TABLE' align="center">
<tr>
<th class='THTOP'>Chat</th>
</tr>
<tr>
<td>
<div style='width: 247; overflow: auto; height: 100'>
<table border='1' width='227' align='center' cellspacing='0'
cellpadding='4' bgcolor='6699CC'>
<tr>
<td bgcolor="#EEEEEE" align="center"><input type=text
name=chat_msg size=20 onclick="stopTimer=1" /><input type=submit
value="<?=_("write")?>" /></td>
</tr>
<tr>
<td bgcolor="#EEEEEE" align="left"><?= writeChat($_SESSION['gameID'])?>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
<?php }
}
?>
</td>
<td align="center"><?
echo "<br />";
$p = mysql_query("SELECT whitePlayer,blackPlayer,dateCreated,ratingWhite,ratingBlack,ratingBlackM,ratingWhiteM,oficial,PVBlack,PVWhite,gameMessage,team,blitz FROM games WHERE gameID='$_SESSION[gameID]'");
$row = mysql_fetch_array($p);
$xDateCreated = $row[2];
$blitz = $row['blitz'];
if ($blitz == 0)
{
blitzTime();
}
elseif ($blitz == 1)
{
writeTime();
}
?> <br />
<!-- <input type="button" style="font-size: 8pt; font-weight: bold; font-family: verdana; cursor: hand" value="<?=_("resign")?>" <? if (isBoardDisabled()) echo("disabled='yes'"); else echo ("onclick='resigngame($CFG_MIN_ROUNDS,\""._("roundwarning")."\")'"); ?>>
<input type="button" style="font-size: 8pt; font-weight: bold; font-family: verdana; cursor: hand" value="<?=_("askdraw")?>" <? if (isBoardDisabled()) echo("disabled='yes'"); else echo ("onclick='draw($CFG_MIN_ROUNDS,\""._("roundwarning")."\")'"); ?>> -->
<?= writeHistory(); ?> <br />
<input type='hidden' name='rdoShare' value='no'><input type="hidden"
name="gameID" value="" /><input type="hidden" name="sharePC"
value="no" />
</form>
</td>
</tr>
<tr>
<td align="center">
<p align=left><font face=verdana size=1 color=#EEEEEE> <script>
curDir = -1;
if (isInCheck('<?=$mycolor2?>')){
document.write("<?=$mycolor2?> is in Check<br />");
}
curDir = -1;
if (isCheckMate('<?=$mycolor2?>')){
document.write("<?=$mycolor2?> is in Check-Mate<br />");
}
curDir = -1;
if (isDraw('<?=$mycolor2?>')&&!isCheckMate('<?=$mycolor2?>')){
document.write('Javascript result: The game ends in a Draw!');
}
</script> <?
if (!isBoardDisabled() && !$_SESSION['isSharedPC'])
{
if ($_SESSION['pref_autoreload'] >= $CFG_MINAUTORELOAD)
$autoreload = $_SESSION['pref_autoreload'];
else
$autoreload = $CFG_MINAUTORELOAD;
echo "<script>
setTimeout(\"refreshwindow()\",".($autoreload*30).")
</script>";
}
?> </font></p>
</td>
<td align="center"> </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<?
if (isset($COMPRESSION) && $COMPRESSION && isset($ob_mode) && $ob_mode) {
PMA_outBufferPost($ob_mode);
}
?>
######################################################################
giu.php
'######################################################################
<?php
// trace runtime
if ($bPIncludeSequence) $firephp->fb('gui.inc|' . $sController, FirePHP::INFO);
/* functions for outputting to html and javascript */
#
#-----[ AFTER ADD ]------------------------------------------
#
function gameeachtime($sekunden) {
$seconds = 0;
$hours = 0;
$minutes = 0;
if($sekunden % 86400 > 0)
{
$rest = ($sekunden % 86400);
$days = ($sekunden - $rest) / 86400;
if( $rest % 3600 > 0 )
{
$rest1 = ($rest % 3600);
$hours = ($rest - $rest1) / 3600;
if( $rest1 % 60 > 0 )
{
$rest2 = ($rest1 % 60);
$minutes = ($rest1 - $rest2) / 60;
$seconds = $rest2;
}else
$minutes = $rest1 / 60;
}else
$hours = $rest / 3600;
}else
$days = $sekunden / 86400;
return array( "days" => $days, "hours" => $hours, "minutes" => $minutes, "seconds" => $seconds);
}
$smilie = array(
"/" . preg_quote(":b)", "/") . "/",
"/" . preg_quote(":)", "/") . "/",
"/" . preg_quote(":(", "/") . "/",
"/" . preg_quote(";)", "/") . "/",
"/" . preg_quote(":P", "/") . "/",
"/" . preg_quote(":e", "/") . "/",
"/" . preg_quote("8)", "/") . "/",
"/" . preg_quote(":bad:", "/") . "/",
"/" . preg_quote(":good:", "/") . "/",
);
$img = array (
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/biggrin.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/smiley.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/sad.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/wink.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/tongue.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/eek.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/cool.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/bad.gif" border="0">',
'<img src="./smilies/space.gif" border="0" width="3" height="0"><img src="./smilies/good.gif" border="0">'
);
function show_avatar($avatar) {
global $extensions, $def_avatar, $AVATAR_LOCATION;
if ($AVATAR_LOCATION == "directory"){
$img = $def_avatar;
$root = dirname(__FILE__);
while (list($key, $val) = each($extensions)) {
$imgpath = 'images/avatars/' . $avatar . '.' . $val;
if (file_exists($imgpath)) {
$img = $avatar . '.' . $val;
}
}
echo '<img src="./images/avatars/' . $img . '">';
}
else{
echo '<img src="./show_avatar.php?id=' . $avatar . '">';
}
}
function show_avatar_team($avatar) {
global $extensions, $def_avatar, $AVATAR_LOCATION;
if ($AVATAR_LOCATION == "directory"){
$img = $def_avatar;
$root = dirname(__FILE__);
while (list($key, $val) = each($extensions)) {
$imgpath = 'images/teamlogo/' . $avatar . '.' . $val;
if (file_exists($imgpath)) {
$img = $avatar . '.' . $val;
}
}
echo '<img src="./images/teamlogo/' . $img . '">';
}
else{
echo '<img src="./show_avatar_team.php?id=' . $avatar . '">';
}
}
function show_avatar_club($avatar) {
global $extensions, $def_avatar, $AVATAR_LOCATION;
if ($AVATAR_LOCATION == "directory"){
$img = $def_avatar;
$root = dirname(__FILE__);
while (list($key, $val) = each($extensions)) {
$imgpath = 'images/clublogo/' . $avatar . '.' . $val;
if (file_exists($imgpath)) {
$img = $avatar . '.' . $val;
}
}
echo '<img src="./images/clublogo/' . $img . '">';
}
else{
echo '<img src="./show_avatar_club.php?id=' . $avatar . '">';
}
}
function smilies($str) {
global $smilie, $img;
$str = preg_replace($smilie, $img, $str);
return $str;
}
function smilielist() {
global $smilie, $img;
$list = '';
for ($i = 0; $i < count($smilie); $i++) {
$smile = ereg_replace("/", "", $smilie[$i]);
$list .= '<a href="#" onclick="chess.chat_msg.value+= \'' . $smile . '\'">' . $img[$i] . '</a>';
} // for
return $list;
}
function riphtml ($out) {
$out=str_replace ("<", "<", $out);
$out=str_replace (">", ">", $out);
return $out;
}
function writepublicChat($gameID){
global $_SESSION, $MSG_LANG;
$p = mysql_query("SELECT p.*, c.*, UNIX_TIMESTAMP(c.hora) AS hora from testchat c
LEFT JOIN players p ON p.playerID = c.fromID
order BY c.hora DESC LIMIT 185");
$chat = "";
while($row = mysql_fetch_array($p)){
if ($_SESSION['playerID'] == $row[fromID])
$cor="#FFFFFF";
else
$cor="brown";
$zeit = date("m/d/Y, H:i", $row['hora']);
$msg = strip_tags($row[msg], '<a><b><i><u>');
$msg = smilies($msg);
if ($row['fromID'] == 0) {
$row['nick'] = "Chat";
$msg = str_replace("event-enter", _("entersthechat"), $msg);
$msg = str_replace("event-leave", _("leavesthechat"), $msg);
$msg = "<b>" . $msg . "</b>";
}
$chat .= "<B>$row[nick]</B>: " . $msg . " <i>" . $zeit . "</i><br />";
}
return $chat;
}
function writeChat($gameID){
global $_SESSION;
$p = mysql_query("SELECT * from chat,players where playerID=fromID AND gameID=$gameID order BY hora DESC LIMIT 10");
$chat = "";
while($row = mysql_fetch_array($p)){
$timestamp = $row[hora];
$month1 = $timestamp[4];
$month2 = $timestamp[5];
$day1 = $timestamp[6];
$day2 = $timestamp[7];
$hour1 = $timestamp[8];
$hour2 = $timestamp[9];
$minute1 = $timestamp[10];
$minute2 = $timestamp[11]; if ($_SESSION['playerID'] == $row[fromID])
$cor="blue";
else
$cor="red";
$chat .= "<font color=black><b>$row[nick]:</b></font><font color=$cor> ".stripslashes($row[msg])."</font><font size=-3><font color=black> <I> ($timestamp)</I></font> <br />";
//$chat .= "<font color=$cor>$row[nick]: ".stripslashes($row[msg])."</font><font size=-3><font color=black><I> (".$month1."".$month2."/".$day1."".$day2." ".$hour1."".$hour2.":".$minute1."".$minute2.")</I></font></font><br />";
}
return $chat;
}
function writechatclub2($groupID){
global $_SESSION;
$p = mysql_query("SELECT * from chat_club,group_members where playerID=fromID AND group_id=$groupID order BY hora DESC LIMIT 20");
$chat = "";
while($row = mysql_fetch_array($p)){
$cplay = mysql_query("SELECT playerID,nick FROM players WHERE playerID = '".$row['playerID']."'");
$cp = mysql_fetch_array($cplay);
$timestamp = $row[hora];
$month1 = $timestamp[4];
$month2 = $timestamp[5];
$day1 = $timestamp[6];
$day2 = $timestamp[7];
$hour1 = $timestamp[8];
$hour2 = $timestamp[9];
$minute1 = $timestamp[10];
$minute2 = $timestamp[11]; if ($_SESSION['playerID'] == $row[fromID])
$cor="#9966ff";
$cor1="#00FFFF";
$chat .= " <img src=./images/games.gif border=0> <font color=$cor><B>$cp[nick]</B> --</font><font color=$cor1><b> ".($row[msg])."</b></font> <I> ($timestamp)</I> <br />";
}
return $chat;
}
function writeNote($gameID){
global $_SESSION;
$p = mysql_query("SELECT notes.*,DATE_FORMAT(hora, '%m/%d/%Y %H:%i') as tmstamp from notes where fromID='".$_SESSION['playerID']."' AND gameID=$gameID order BY hora DESC LIMIT 10");
$note = "";
while($row = mysql_fetch_array($p)){
$cor="black";
$note .= "<font color=$cor>-- ".stripslashes($row[note])."</font> <I> ($row[tmstamp])</I><br />";
}
return $note;
}
function drawboard()
{
global $board, $playersColor, $numMoves, $MSG_LANG, $CFG_CONFIRM_MOVE, $history;
if ($CFG_CONFIRM_MOVE == FALSE || $_SESSION['pref_confirmmove'] == "off")
$CFG_CONFIRM_MOVE = 0;
elseif ($CFG_CONFIRM_MOVE == FALSE || $_SESSION['pref_confirmmove'] == 'on')
$CFG_CONFIRM_MOVE = 1;
elseif ($CFG_CONFIRM_MOVE == TRUE || $_SESSION['pref_confirmmove'] == "off")
$CFG_CONFIRM_MOVE = 0;
else $CFG_CONFIRM_MOVE = 1;
/* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
if (!minimum_version("4.1.0"))
global $_POST, $_GET, $_SESSION;
/* find out if it's the current player's turn */
if (( (($numMoves == -1) || (($numMoves % 2) == 1)) && ($playersColor == "white"))
|| ((($numMoves % 2) == 0) && ($playersColor == "black")) )
$isPlayersTurn = true;
else
$isPlayersTurn = false;
/* determine who's perspective of the board to show */
if ($_SESSION['isSharedPC'] && !$isPlayersTurn)
{
if ($playersColor == "white")
$perspective = "black";
else
$perspective = "white";
}
else
{
$perspective = $playersColor;
}
/* NOTE: if both players are using the same PC, in a sense it's always the players turn */
if ($_SESSION['isSharedPC'])
$isPlayersTurn = true;
/* determine if board is disabled */
$isDisabled = isBoardDisabled();
echo ("<table border='0' style='border-collapse: collapse' bordercolor='#111111'>\n");
if ($isDisabled)
echo ("<tr class='CHESSTD'>");
else
echo ("<tr class='CHESSTD'>");
/* setup vars to show player's perspective of the board */
if ($perspective == "white")
{
$topRow = 7;
$bottomRow = 0;
$rowStep = -1;
$leftCol = 0;
$rightCol = 7;
$colStep = 1;
}
else
{
$topRow = 0;
$bottomRow = 7;
$rowStep = 1;
$leftCol = 7;
$rightCol = 0;
$colStep = -1;
}
/* column headers */
echo ("<td align=center class='CHESSTD'> </td>");
/* NOTE: end condition is ($rightCol + $colStep) since we want to output $rightCol */
for ($i = $leftCol; $i != ($rightCol + $colStep); $i += $colStep)
echo ("<td align=center class='CHESSTD'>".chr($i + 97)."</td>");
echo ("</tr>\n");
/* for each row... */
/* NOTE: end condition is ($bottomRow + $rowStep) since we want to output $bottomRow */
for ($i = $topRow; $i != ($bottomRow + $rowStep); $i += $rowStep)
{
echo ("<tr>\n");
if ($isDisabled)
echo ("<th width='20' class='CHESSTD'>".($i+1)."</th>\n");
else
echo ("<td align=center class='CHESSTD' width='20'>".($i+1)."</td>\n");
/* for each col... */
/* NOTE: end condition is ($rightCol + $colStep) since we want to output $rightCol */
for ($j = $leftCol; $j != ($rightCol + $colStep); $j += $colStep)
{
echo (" <td ");
/* if board is disabled, show board in grayscale */
if ($isDisabled)
{
if (($j + ($i % 2)) % 2 == 0)
echo ("class='disabled-dark' class='CHESSTD'>");
else
echo ("class='disabled-light' class='CHESSTD'>");
}
else
{
$p = mysql_query("select showHL from players where playerID = '".$_SESSION['playerID']."'");
$row = mysql_fetch_array($p);
$showHLight = $row[0];
if ($showHLight == '1'){
$p = mysql_query("select showHLcolor from players where playerID = '".$_SESSION['playerID']."'");
$row = mysql_fetch_array($p);
$showHLcolor = $row[0];
if (($i == $history[$numMoves]['fromRow'] && $j == $history[$numMoves]['fromCol']) ||
($i == $history[$numMoves]['toRow'] && $j == $history[$numMoves]['toCol']))
$cor = "bgcolor='".$showHLcolor."'";
else{
if (($j + ($i % 2)) % 2 == 0)
$cor = "class='enabled-dark' bgcolor='#955F22'";
else
$cor = "class='enabled-light' bgcolor='#E3C58C'";
}
echo ("$cor>");
}
else{
if (($j + ($i % 2)) % 2 == 0)
echo ("class='enabled-dark' bgcolor='#955F22'>");
else
echo ("class='enabled-light' bgcolor='#E3C58C'>");
}
}
//#772222
//#CCBBBB
// Highlight last move:
// if (($numMoves >=0)&&(($i == $history[$numMoves]['fromRow'] && $j == $history[$numMoves]['fromCol']) ||
// ($i == $history[$numMoves]['toRow'] && $j == $history[$numMoves]['toCol'])))
// $cor = "bgcolor='#FFFF00'";
// else{
// if (($j + ($i % 2)) % 2 == 0)
// $cor = "class='enabled-dark' bgcolor='#955F22'";
// else
// $cor = "class='enabled-light' bgcolor='#E3C58C'";
// }
// echo ("$cor>");
// }
/* if disabled or not player's turn, can't click pieces */
if (!$isDisabled && $isPlayersTurn)
{
echo ("<a href='JavaScript:squareClicked($CFG_CONFIRM_MOVE, $i, $j, ");
if ($board[$i][$j] == 0)
echo ("true,\""._("youdontplaywith")."\",\"" . _("confirmmove") . "\")'>");
else
echo ("false,\""._("youdontplaywith")."\",\"" . _("confirmmove") . "\")'>");
}
echo ("<img name='pos$i-$j' src='images/pieces/".$_SESSION['pref_theme']."/");
/* if position is empty... */
if ($board[$i][$j] == 0)
{
/* draw empty square */
$tmpALT="blank";
}
else
{
/* draw correct piece */
if ($board[$i][$j] & BLACK)
$tmpALT = "black_";
else
$tmpALT = "white_";
$tmpALT .= getPieceName($board[$i][$j]);
}
echo($tmpALT.".gif' height='".$_SESSION['pref_boardSize']."' width='".$_SESSION['pref_boardSize']."' border='0' alt='".$tmpALT."'>");
if (!$isDisabled && $isPlayersTurn)
echo ("</a>");
echo ("</td>\n");
}
echo ("</tr>\n");
}
echo ("</table>\n\n");
}
function writeJSboard()
{
global $board, $numMoves;
/* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
if (!minimum_version("4.1.0"))
global $_POST, $_GET, $_SESSION;
/* write out constants */
echo ("var DEBUG = ".DEBUG.";\n");
echo ("var EMPTY = 0;\n");
echo ("var CURRENTTHEME = '".$_SESSION['pref_theme']."';\n");
echo ("var PAWN = ".PAWN.";\n");
echo ("var KNIGHT = ".KNIGHT.";\n");
echo ("var BISHOP = ".BISHOP.";\n");
echo ("var ROOK = ".ROOK.";\n");
echo ("var QUEEN = ".QUEEN.";\n");
echo ("var KING = ".KING.";\n");
echo ("var BLACK = ".BLACK.";\n");
echo ("var WHITE = ".WHITE.";\n");
echo ("var COLOR_MASK = ".COLOR_MASK.";\n");
/* write code for array */
echo ("var board = new Array();\n");
for ($i = 0; $i < 8; $i++)
{
echo ("board[$i] = new Array();\n");
for ($j = 0; $j < 8; $j++)
{
echo ("board[$i][$j] = ".$board[$i][$j].";\n");
}
}
echo("var numMoves = $numMoves;\n");
echo("var errMsg = '';\n"); /* global var used for error messages */
}
/* provide history data to javascript function */
/* NOTE: currently, only pawn validation script uses history */
function writeJSHistory()
{
global $history, $numMoves;
/* write out constants */
echo ("var CURPIECE = 0;\n");
echo ("var CURCOLOR = 1;\n");
echo ("var FROMROW = 2;\n");
echo ("var FROMCOL = 3;\n");
echo ("var TOROW = 4;\n");
echo ("var TOCOL = 5;\n");
/* write code for array */
echo ("var chessHistory = new Array();\n");
for ($i = 0; $i <= $numMoves; $i++)
{
echo ("chessHistory[$i] = new Array();\n");
echo ("chessHistory[$i][CURPIECE] = '".$history[$i]['curPiece']."';\n");
echo ("chessHistory[$i][CURCOLOR] = '".$history[$i]['curColor']."';\n");
echo ("chessHistory[$i][FROMROW] = ".$history[$i]['fromRow'].";\n");
echo ("chessHistory[$i][FROMCOL] = ".$history[$i]['fromCol'].";\n");
echo ("chessHistory[$i][TOROW] = ".$history[$i]['toRow'].";\n");
echo ("chessHistory[$i][TOCOL] = ".$history[$i]['toCol'].";\n");
}
}
function writeVerbousHistory()
{
global $history, $numMoves, $MSG_LANG;
echo ("<table border='1' cellpadding='2' bgcolor='#336699' bordercolordark='#1F5070' bordercolorlight='#1F5070'>\n");
echo ("<tr valign='top' align='center'><td><table border='2' bordercolordark='#6699CC' bordercolorlight='#6699CC'><tr><td>\n");
echo ("<div style='width:320;overflow:auto;height:311'>\n");
echo ("<table border='1' cellspacing='0' cellpadding='4' width=300 bordercolor=#000000 align=center>\n");
echo ("<tr><th bgcolor='#6699CC' colspan='2'>"._("history")."</th></tr>\n");
for ($i = $numMoves; $i >= 0; $i--)
{
if ($i % 2 == 1)
{
echo ("<tr bgcolor='white'>");
echo ("<td width='20'><font color='black'>".($i + 1)."</font></td><td><font color='black'>");
}
else
{
echo ("<tr bgcolor='white'>");
echo ("<td width='20'>".($i + 1)."</td><td><font color='black'>");
}
$tmpReplaced = "";
if (!is_null($history[$i]['replaced']))
$tmpReplaced = $history[$i]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i]['promotedTo']))
$tmpPromotedTo = $history[$i]['promotedTo'];
$tmpCheck = ($history[$i]['isInCheck'] == 1);
echo(moveToVerbousString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck));
echo ("</font></td></tr>\n");
}
echo ("<tr bgcolor='#BBBBBB'><td>0</td><td>"._("newgame")."</td></tr>\n");
echo ("</table></table></div></table>\n");
}
function analyzeHistoryPGN($format = "color", $single = 'none')
{
global $history, $numMoves, $MSG_LANG; $_SESSION;
if ($format == "color"){
echo ("<table border='1' cellpadding='2' bgcolor='#336699' bordercolordark='#1F5070' bordercolorlight='#1F5070'>\n");
echo ("<tr valign='top' align='center'><td><table border='2' bordercolordark='#6699CC' bordercolorlight='#6699CC'><tr><td><div style='width:270;overflow:auto;height:315'><table border='1' width='250' align='center' cellspacing='0' cellpadding='4' bgcolor='6699CC'>\n");
echo ("<tr><th bgcolor='#6699CC' colspan='5'>".strtoupper(_("history"))."</th></tr>\n");
echo ("<tr><td bgcolor='#c0c0c0' width='30'><font color=black><b>Move</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>White</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>Black</b></font></td></tr>\n");
}
for ($i = 0; $i <= $numMoves; $i+=2)
{
if ($format == "color")
$export = false;
else $export = true;
if ($format == "color")
echo ("<tr><td align='center' bgcolor='#BBBBBB'><font color='black'>".(($i/2) + 1)."</font></td><td bgcolor='white' align='center'><font color='black'>");
$tmpReplaced = "";
if (!is_null($history[$i]['replaced']))
$tmpReplaced = $history[$i]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i]['promotedTo']))
$tmpPromotedTo = $history[$i]['promotedTo'];
$tmpCheck = ($history[$i]['isInCheck'] == 1);
if ($format == "plain" && $single != 'single')
{
if (ceil(($i+1)/2) > 1 && $single == 'chess')
{
echo "<br />";
}
echo ceil(($i+1)/2).". ";
}
$last_move=moveToPGNString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck);
$p = mysql_query("UPDATE games SET last_move='".$last_move."' WHERE gameID=".$_SESSION['gameID']."");
echo moveToPGNString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck, $export, $single)." ";
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='images/pieces/".$_SESSION['pref_theme']."/black_".$tmpReplaced.".gif' height='15' align='left'> ";
echo ("</font></td><td bgcolor=white align='center'><font color='black'>");
}
if ($i == $numMoves){
if ($format == "color")
echo (" ");
}
else
{
$tmpReplaced = "";
if (!is_null($history[$i+1]['replaced']))
$tmpReplaced = $history[$i+1]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i+1]['promotedTo']))
$tmpPromotedTo = $history[$i+1]['promotedTo'];
$tmpCheck = ($history[$i+1]['isInCheck'] == 1);
//if ($format == "plain")
// echo ($i+2).". ";
echo moveToPGNString($history[$i+1]['curColor'], $history[$i+1]['curPiece'], $history[$i+1]['fromRow'], $history[$i+1]['fromCol'], $history[$i+1]['toRow'], $history[$i+1]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck,$export,$single)." ";
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='images/pieces/".$_SESSION['pref_theme']."/white_".$tmpReplaced.".gif' height='15' align='left'> ";
}
}
if ($format == "color")
echo ("</font></td></tr>\n");
//else{
// if (floor(($i+1)/8) == ($i)/8 && $i != 0)
// echo "\n";
//}
}
if ($format == "color")
echo ("</table></table></div></table>\n");
}
function writeHistoryPGN($format = "color", $single = 'none')
{
global $history, $numMoves, $MSG_LANG; $_SESSION;
if ($format == "color"){
echo '<table border="0" width="250" class="TABLE" align="center">';
echo "<tr><th class='THTOP'>History</th></tr>";
echo "<tr><td><div style='width:250;overflow:auto;height:147'><table border='1' width='230' align='center' cellspacing='0' cellpadding='3'>";
echo ("<tr><td bgcolor='#c0c0c0' width='30'><font color=black><b>Move</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>White</font></td>");
echo ("<td bgcolor='white' colspan='2' align='center'><font color='black'><b>Black</b></font></td></tr>\n");
}
for ($i = 0; $i <= $numMoves; $i+=2)
{
if ($format == "color")
$export = false;
else $export = true;
if ($format == "color")
echo ("<tr><td align='center' bgcolor='#BBBBBB'><font color='black'>".(($i/2) + 1)."</font></td><td bgcolor='white' align='center'><font color='black'>");
$tmpReplaced = "";
if (!is_null($history[$i]['replaced']))
$tmpReplaced = $history[$i]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i]['promotedTo']))
$tmpPromotedTo = $history[$i]['promotedTo'];
$tmpCheck = ($history[$i]['isInCheck'] == 1);
if ($format == "plain" && $single != 'single')
{
if (ceil(($i+1)/2) > 1 && $single == 'chess')
{
echo "<br />";
}
echo ceil(($i+1)/2).". ";
}
$last_move=moveToPGNString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck);
$p = mysql_query("UPDATE games SET last_move='".$last_move."' WHERE gameID=".$_SESSION['gameID']."");
echo moveToPGNString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck, $export, $single)." ";
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='./images/pieces/".$_SESSION['pref_theme']."/black_".$tmpReplaced.".gif' height='15' align='left'> ";
echo ("</font></td><td bgcolor=white align='center'><font color='black'>");
}
if ($i == $numMoves){
if ($format == "color")
echo (" ");
}
else
{
$tmpReplaced = "";
if (!is_null($history[$i+1]['replaced']))
$tmpReplaced = $history[$i+1]['replaced'];
$tmpPromotedTo = "";
if (!is_null($history[$i+1]['promotedTo']))
$tmpPromotedTo = $history[$i+1]['promotedTo'];
$tmpCheck = ($history[$i+1]['isInCheck'] == 1);
if ($format == "plain")
echo ceil(($i+1)/2).". ";
echo moveToPGNString($history[$i+1]['curColor'], $history[$i+1]['curPiece'], $history[$i+1]['fromRow'], $history[$i+1]['fromCol'], $history[$i+1]['toRow'], $history[$i+1]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck,$export,$single)." ";
if ($format == "color")
{
echo "</td><td align='center' bgcolor='#C6D9EC' height=18>";
if ($tmpReplaced!="")
echo "<img src='./images/pieces/".$_SESSION['pref_theme']."/white_".$tmpReplaced.".gif' height='15' align='left'> ";
}
}
if ($format == "color")
echo ("</font></td></tr>\n");
//else{
// if (floor(($i+1)/8) == ($i)/8 && $i != 0)
// echo "\n";
//}
}
if ($format == "color")
echo ("</table></div></table>\n");
}
function writeHistory()
{
global $MSG_LANG;
/* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
if (!minimum_version("4.1.0"))
global $_POST, $_GET, $_SESSION;
/* based on player's preferences, display the history */
switch($_SESSION['pref_history'])
{
case 'verbous':
writeVerbousHistory();
break;
case 'pgn':
writeHistoryPGN();
break;
case 'grafik':
echo ("<table border='0' width=300 bgcolor=black cellspacing=1 cellpading=1>\n");
echo ("<tr><th bgcolor='beige'>".strtoupper(_("history"))."</th></tr>\n");
echo ("<tr><td bgcolor=white>");
writeHistoryPGN("plain", 'chess');
echo ("</td></tr></table>");
break;
}
}
function writeStatus()
{
global $MSG_LANG, $numMoves, $history, $isCheckMate, $statusMessage, $isPlayersTurn;
?>
<!-- status table -->
<table width='250' align='center' class='STATUSTABLE'>
<tr>
<th class='TD'><font size='2'> <?=($isPlayersTurn)?_("yourturn"):_("opponentturn"); ?></font></th>
</tr>
<?
if (($numMoves == -1) || ($numMoves % 2 == 1)){
$curColor = _("white");
$mycolor = "white";
$oppcolor = "black";
}
else{
$curColor = _("black");
$mycolor = "black";
$oppcolor = "white";
}
if (!$isCheckMate && ($history[$numMoves]['isInCheck'] == 1))
echo("<tr><td align='center' class='TD'>\n<font size=2><b>".$curColor." "._("isincheck")."</b><br />\n".$statusMessage."</td></tr>\n");
else{
echo("<tr><td align='center' class='TD'>".$statusMessage." </td></tr>\n");
echo "<script>
if (isInCheck('$mycolor')){
document.write('<tr><td align=center class=\"TD\"><font size=2><b>$curColor "._("isincheck")."!</td></tr>');
}
</script>\n";
}
if (!isBoardDisabled()){
if (!$isCheckMate){
echo "<script>
curDir=-1;
if (isCheckMate('$mycolor')){
alert('"._("endsincheckmate")."');
window.location='apply.php?playersColor=$oppcolor&action=checkmate';
}
else if (isStaleMate('$mycolor')){
alert('"._("endsinstalemate")."');
window.location='apply.php?playersColor=$oppcolor&action=draw';
}
else if (isThreeFoldRepetition('$mycolor')){
alert('"._("endsinthreefoldrepetition")."');
window.location='apply.php?playersColor=$oppcolor&action=draw';
}
else if (isInsufficientMatingMaterial('$mycolor')){
alert('"._("endsininsufficient")."');
window.location='apply.php?playersColor=$oppcolor&action=draw';
}
</script>\n";
}
echo "<script>
curDir=-1;
if (isDraw('$mycolor')&&!isCheckMate('$mycolor')){
alert('"._("endsindraw")."');
//window.location='apply.php?playersColor=$oppcolor&action=draw';
}
</script>\n";
}
?>
</table>
<?
}
function writePoints()
{
global $MSG_LANG, $opponent, $_SESSION, $oficial, $MyRating, $OpponentRating, $MyPV, $OpponentPV;
if ($oficial == "1"){
$xpw = getXPW($MyRating,$OpponentRating,$OpponentPV);
$xpl = getXPL($OpponentRating,$MyRating,$OpponentPV);
}else{
$xpl=0;
$xpw=0;
}
?>
<?
if ($playersColor == "white")
{
echo (""._("ifwin")." +$xpl,<br /> "._("iflose")." -$xpw");
}
else
{
echo (""._("ifwin")." +$xpw,<br /> "._("iflose")." -$xpl");
}
return;
}
function blitzTime()
{
global $MSG_LANG, $_SESSION, $isPromoting, $otherTurn, $isPlayersTurn, $white, $black;
$p = mysql_query("SELECT * from history where gameID=".$_SESSION['gameID']." ORDER BY timeOfMove DESC limit 1")
OR new cMyErrors(cMyErrors::THROW_MYSQL, 'gui920');
$row = mysql_fetch_array($p);
$cor = $row['curColor'];
$lastmove = $row['timeOfMove'];
//duracao:
$v = explode(" ",$lastmove);
$hora = explode(":",$v[1]);
$data = explode("-",$v[0]);
if ($lastmove == 0)
$inicio = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
else
$inicio = mktime($hora[0],$hora[1],$hora[2],$data[1],$data[2],$data[0]);
$fim = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
//$d = floor(($fim-$inicio)/60/60/24);
//$h = floor(($fim-$inicio)/60/60) - 24*$d;
//$m = floor(($fim-$inicio)/60) - 60*$h - $d*24*60;
//$s = ($fim-$inicio) - $m*60 - $h*60*60 - $d*24*60;
if ($cor == "white"){
if ($isPromoting)
$somawhite = $fim-$inicio;
else
$somablack = $fim-$inicio;
}else{
if ($isPromoting)
$somablack = $fim-$inicio;
else
$somawhite = $fim-$inicio;
}
$p = mysql_query("SELECT * from games where gameID=".$_SESSION['gameID']);
$row = mysql_fetch_array($p);
if ($row[gameMessage] == ""){
$row[timeBlack] += $somablack;
$row[timeWhite] += $somawhite;
}
//$d = floor(($fim-$inicio)/60/60/24);
//$h = floor(($fim-$inicio)/60/60) - 24*$d;
//$m = round(($fim-$inicio)/60) - 60*$h - $d*24*60;
$blackd = floor($row[timeBlack]/60/60/24);
$whited = floor($row[timeWhite]/60/60/24);
$blackh = floor($row[timeBlack]/60/60) - 24*$blackd;
$whiteh = floor($row[timeWhite]/60/60) - 24*$whited;
$blackm = floor($row[timeBlack]/60) - 60*$blackh - $blackd*24*60;
$whitem = floor($row[timeWhite]/60) - 60*$whiteh - $whited*24*60;
$blacks = $row[timeBlack] - 60*$blackm - 60*60*$blackh - $blackd*24*60*60;
$whites = $row[timeWhite] - 60*$whitem - 60*60*$whiteh - $whited*24*60*60;
if ($row['timelimit'] >= 1440)
$timelimit_txt = ($row['timelimit']/1440)." "._("unlimited");
else if ($row['timelimit'] >= 60)
$timelimit_txt = (_("hs")." ".$row['timelimit']/60)." ".'hrs.';
else if ($row['timelimit'] >=30)
$timelimit_txt = (_("min"))." ".$row['timelimit']." ".'min.';
else
$timelimit_txt = (14)." "._("unlimited");
?>
<table border="0" width="250" align="center" cellspacing="0"
cellpadding="0" bgcolor="">
<?
$clocktimewhite=gameeachtime($row['timelimit'] * 60 - $row['timeWhite']);
$clocktimeblack=gameeachtime($row['timelimit'] * 60 - $row['timeBlack']);
$gameeach=gameeachtime(($row["timelimit"]) * 60);
if ($row[gameMessage] != ""){?>
<tr>
<td colspan=2 nowrap align=center>
<table width=172 border=1 bordercolor=000000 bgcolor=FFFFFF
align=center>
<tr>
<td align=center><b><?= _("Game is over")?></b></td>
</tr>
</table>
<br />
</td>
</tr>
<tr>
<td bgcolor=FFFFFF align=center width=125 height=112
background=./images/metal/clock_left.gif> <b><?= _("Game")?></b></td>
<td bgcolor=FFFFFF align=center width=125 height=112
background=./images/metal/clock_right.gif><b><?= _("Over");?></b> </td>
</tr>
<?php } else { ?>
<tr>
<td colspan=2 nowrap align=center>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?if($row['timelimit'] != 0) {echo(_("timeforeach")."<br />".$gameeach['days']." "._("days")." ".$gameeach['hours']." "._("hs")." ".$gameeach['minutes']." "._("min")."");} else {echo(_("timeforeach")."<br />"._("unlimited"));}?></b></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=FFFFFF align=center width=125 height=112
background="./images/metal/<?=($cor == "white")?("clock_left_red.gif"):("clock_left_green.gif")?>"> <b><font
color=#1F5070> <?php
//if($clocktimewhite['days'] != 0) {$showwhite = ("[".$clocktimewhite['days'].":".$clocktimewhite['hours'].":".$clocktimewhite['minutes'].":".$clocktimewhite['seconds']."]");}
if($row['timelimit'] != 0)
{
if($clocktimewhite['days'] != 0)
{
printf("%02d:",$clocktimewhite['days']);
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] != 0)
{
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] != 0)
{
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0&& $clocktimewhite['seconds'] != 0)
{
printf("%02d",$clocktimewhite['seconds']);
}
if($lastmove != 0 && $clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0 && $clocktimewhite['seconds'] == 0)
{
echo("Game Over");
}
} else {
printf("%02d:",$whited);
printf("%02d:",$whiteh);
printf("%02d:",$whitem);
printf("%02d",$whites);
//echo($showwhite);
}
?> </font> </b></td>
<td bgcolor=FFFFFF align=center width=125 height=112
background="./images/metal/<?=($cor == "white")?("clock_right_green.gif"):("clock_right_red.gif")?>"><b>
<font color=#1F5070><?php
if($row['timelimit'] != 0)
{
if($clocktimeblack['days'] != 0)
{
printf("%02d:",$clocktimeblack['days']);
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] != 0)
{
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] != 0)
{
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0&& $clocktimeblack['seconds'] != 0)
{
printf("%02d",$clocktimeblack['seconds']);
}
if($lastmove != 0 && $clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0 && $clocktimeblack['seconds'] == 0)
{
echo("Game Over");
}
} else {
printf("%02d:",$blackd);
printf("%02d:",$blackh);
printf("%02d:",$blackm);
printf("%02d",$blacks);
//echo($showblack);
}
?></b> </td>
</tr>
<?php } ?>
</td>
</tr>
</table>
<?
}
function writeTime()
{
global $MSG_LANG, $_SESSION, $isPromoting, $otherTurn, $isPlayersTurn, $white, $black;
$p = mysql_query("SELECT timeOfMove,gameID,curColor from history where gameID=".$_SESSION['gameID']." ORDER BY timeOfMove DESC limit 1")
OR new cMyErrors(cMyErrors::THROW_MYSQL, 'gui1126');
$row = mysql_fetch_array($p);
$q = mysql_query("SELECT lastMove,gameID from games where gameID=".$_SESSION['gameID']."");
$row2 = mysql_fetch_array($q);
$cor = $row['curColor'];
$lastmove = $row['timeOfMove'];
$lastMove = $row2['lastMove'];
//duracao:
$v = explode(" ",$lastMove);
$hora = explode(":",$v[1]);
$data = explode("-",$v[0]);
//firstmove
$w = explode(" ",$lastMove);
$hora2 = explode(":",$w[1]);
$data2 = explode("-",$w[0]);
if ($lastMove == 0)
{
$inicio = mktime($hora2[0],$hora2[1],$hora2[2],$data2[1],$data2[2],$data2[0]);
//$inicio = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
}
else
{
$inicio = mktime($hora[0],$hora[1],$hora[2],$data[1],$data[2],$data[0]);
}
$fim = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
$agora = mktime(date("H"),date("i"),0,date("m"),date("d"),date("Y"));
$d = floor(($agora-$lastMove)/60/60/24);
$h = floor(($agora-$lastMove)/60/60) - 24*$d;
$m = round(($agora-$lastMove)/60) - 60*$h - $d*24*60;
$s = ($fim-$inicio) - $m*60 - $h*60*60 - $d*24*60;
if ($cor == "white"){
if ($isPromoting)
$somawhite = $fim-$inicio;
else
$somablack = $fim-$inicio;
}else{
if ($isPromoting)
$somablack = $fim-$inicio;
else
$somawhite = $fim-$inicio;
}
$p = mysql_query("SELECT * from games where gameID=".$_SESSION['gameID']);
$row = mysql_fetch_array($p);
if ($row[gameMessage] == ""){
$row[timeBlack] += $somablack;
$row[timeWhite] += $somawhite;
}
//$d = floor(($fim-$inicio)/60/60/24);
//$h = floor(($fim-$inicio)/60/60) - 24*$d;
//$m = round(($fim-$inicio)/60) - 60*$h - $d*24*60;
mysql_query("UPDATE games set currenttimeWhite=$somawhite WHERE gameID=".$_SESSION['gameID']);
mysql_query("UPDATE games set currenttimeBlack=$somablack WHERE gameID=".$_SESSION['gameID']);
mysql_query("UPDATE games set currenttimeWhite=$somawhite WHERE gameID=".$_SESSION['gameID']);
mysql_query("UPDATE games set currenttimeBlack=$somablack WHERE gameID=".$_SESSION['gameID']);
$p2 = mysql_query("SELECT * from games where gameID=".$_SESSION['gameID']);
$row2 = mysql_fetch_array($p2);
if ($row2[gameMessage] == "") {
$row2[timeBlack] += $somablack;
$row2[timeWhite] += $somawhite;
}
$blackd = floor($row2[timelimit]/24/60) - $d;
$whited = floor($row2[timelimit]/24/60) - $d;
$blackh = floor($row2[timeBlack]/60/60) - 24*$d;
$whiteh = floor($row2[timeWhite]/60/60) - 24*$d;
$blackm = floor($row2[timeBlack]/60) - 60*$blackh - $d*24*60;
$whitem = floor($row2[timeWhite]/60) - 60*$whiteh - $d*24*60;
$blacks = $row2[timeBlack] - 60*$blackm - 60*60*$blackh - $d*24*60*60;
$whites = $row2[timeWhite] - 60*$whitem - 60*60*$whiteh - $d*24*60*60;
if ($row2['timelimit'] >= 1440)
$timelimit_txt = ($row2['timelimit']/1440)." "._("unlimited");
else if ($row2['timelimit'] >= 60)
$timelimit_txt = (_("hs")." ".$row2['timelimit']/60)." ".'hrs.';
else if ($row2['timelimit'] >=30)
$timelimit_txt = (_("min"))." ".$row2['timelimit']." ".'min.';
else
$timelimit_txt = (14)." "._("unlimited");
?>
<table border="0" width="250" align="center" cellspacing="0"
cellpadding="0" bgcolor="">
<?
$clocktimewhite=gameeachtime(($row2['timelimit'] * 60) - $row2['currenttimeWhite']);
$clocktimeblack=gameeachtime(($row2['timelimit'] * 60) - $row2['currenttimeBlack']);
$gameeach=gameeachtime(($row2["timelimit"]) * 60);
if ($row2[gameMessage] != ""){
?>
<tr>
<td colspan=2 nowrap align=center>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?if($row['timelimit'] != 0) {echo(_("timeforeach")."<br />".$gameeach['days']." "._("days")." ");} else {echo(_("timeforeach")."<br />"._("unlimited"));}?></b></font></td>
</tr>
</table>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?= _("Time Left") ?>
(D:H:M:S)</b></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=FFFFFF align=center width=125 height=112
background=./images/metal/clock_left.gif> <b><?= _("Game") ?></b></td>
<td bgcolor=FFFFFF align=center width=125 height=112
background=./images/metal/clock_right.gif><b><?= _("Over") ?></b> </td>
</tr>
<?php } else { ?>
<tr>
<td colspan=2 nowrap align=center>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?if($row['timelimit'] != 0) {echo(_("timeforeach")."<br />".$gameeach['days']." "._("days")." ");} else {echo(_("timeforeach")."<br />"._("unlimited"));}?></b></font></td>
</tr>
</table>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?= _("Time Left") ?>
</b></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor=FFFFFF align=center width=125 height=112
background="./images/metal/<?=($cor == "white")?("clock_left_red.gif"):("clock_left_green.gif")?>"> <b>
<font color="#1F5070"> <?php
//if($clocktimewhite['days'] != 0) {$showwhite = ("[".$clocktimewhite['days'].":".$clocktimewhite['hours'].":".$clocktimewhite['minutes'].":".$clocktimewhite['seconds']."]");}
if($row2['timelimit'] != 0)
{
if($clocktimewhite['days'] != 0)
{
printf("%02d:",$clocktimewhite['days']);
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] != 0)
{
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] != 0)
{
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0&& $clocktimewhite['seconds'] != 0)
{
printf("%02d",$clocktimewhite['seconds']);
}
if($lastmove != 0 && $clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0 && $clocktimewhite['seconds'] == 0)
{
_("Game Over");
}
} else {
printf("%02d:",$whited);
printf("%02d:",$whiteh);
printf("%02d:",$whitem);
printf("%02d",$whites);
//echo($showwhite);
}
?> </font></b></td>
<td bgcolor=FFFFFF align=center width=125 height=112
background="./images/metal/<?=($cor == "white")?("clock_right_green.gif"):("clock_right_red.gif")?>"><b><font
color=#1F5070> <?php
if($row2['timelimit'] != 0)
{
if($clocktimeblack['days'] != 0)
{
printf("%02d:",$clocktimeblack['days']);
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] != 0)
{
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] != 0)
{
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0&& $clocktimeblack['seconds'] != 0)
{
printf("%02d",$clocktimeblack['seconds']);
}
if($lastmove != 0 && $clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0 && $clocktimeblack['seconds'] == 0)
{
_("Game Over");
}
} else {
printf("%02d:",$blackd);
printf("%02d:",$blackh);
printf("%02d:",$blackm);
printf("%02d",$blacks);
//echo($showblack);
}
?></font></b> </td>
</tr>
<?php } ?>
</table>
<?
}
function regularTime()
{
global $MSG_LANG, $_SESSION, $isPromoting, $otherTurn, $isPlayersTurn, $white, $black;
$p = mysql_query("SELECT * from history where gameID=".$_SESSION['gameID']." ORDER BY timeOfMove DESC limit 1")
OR new cMyErrors(cMyErrors::THROW_MYSQL, 'gui1361');
$row = mysql_fetch_array($p);
$cor = $row['curColor'];
$lastmove = $row['timeOfMove'];
//duracao:
$v = explode(" ",$lastmove);
$hora = explode(":",$v[1]);
$data = explode("-",$v[0]);
if ($lastmove == 0)
$inicio = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
else
$inicio = mktime($hora[0],$hora[1],$hora[2],$data[1],$data[2],$data[0]);
$fim = mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y"));
//$d = floor(($fim-$inicio)/60/60/24);
//$h = floor(($fim-$inicio)/60/60) - 24*$d;
//$m = floor(($fim-$inicio)/60) - 60*$h - $d*24*60;
//$s = ($fim-$inicio) - $m*60 - $h*60*60 - $d*24*60;
if ($cor == "white"){
if ($isPromoting)
$somawhite = $fim-$inicio;
else
$somablack = $fim-$inicio;
}else{
if ($isPromoting)
$somablack = $fim-$inicio;
else
$somawhite = $fim-$inicio;
}
$p = mysql_query("SELECT * from games where gameID=".$_SESSION['gameID']);
$row = mysql_fetch_array($p);
if ($row[gameMessage] == ""){
$row[timeBlack] += $somablack;
$row[timeWhite] += $somawhite;
}
//$d = floor(($fim-$inicio)/60/60/24);
//$h = floor(($fim-$inicio)/60/60) - 24*$d;
//$m = round(($fim-$inicio)/60) - 60*$h - $d*24*60;
$blackd = floor($row[timeBlack]/60/60/24);
$whited = floor($row[timeWhite]/60/60/24);
$blackh = floor($row[timeBlack]/60/60) - 24*$blackd;
$whiteh = floor($row[timeWhite]/60/60) - 24*$whited;
$blackm = floor($row[timeBlack]/60) - 60*$blackh - $blackd*24*60;
$whitem = floor($row[timeWhite]/60) - 60*$whiteh - $whited*24*60;
$blacks = $row[timeBlack] - 60*$blackm - 60*60*$blackh - $blackd*24*60*60;
$whites = $row[timeWhite] - 60*$whitem - 60*60*$whiteh - $whited*24*60*60;
if ($row['timelimit'] >= 1440)
$timelimit_txt = ($row['timelimit']/1440)." "._("unlimited");
else if ($row['timelimit'] >= 60)
$timelimit_txt = (_("hs")." ".$row['timelimit']/60)." ".'hrs.';
else if ($row['timelimit'] >=30)
$timelimit_txt = (_("min"))." ".$row['timelimit']." ".'min.';
else
$timelimit_txt = (14)." "._("unlimited");
?>
<table border="1" cellpadding="2" bgcolor="#336699"
bordercolordark="#1F5070" bordercolorlight="#1F5070">
<tr valign="top" align="center">
<td>
<table border="2" bordercolordark="#6699CC" bordercolorlight="#6699CC">
<tr>
<td>
<table border="0" width="250" align="center" cellspacing="0"
cellpadding="0" bgcolor="">
<?
$clocktimewhite=gameeachtime($row['timelimit'] * 60 + $row['timeWhite']);
$clocktimeblack=gameeachtime($row['timelimit'] * 60 + $row['timeBlack']);
$gameeach=gameeachtime(($row["timelimit"]) * 60);
if ($row[gameMessage] != ""){?>
<tr>
<td colspan=2 nowrap align=center>
<table width=172 border=1 bordercolor=000000 bgcolor=FFFFFF
align=center>
<tr>
<td align=center><b><?"Game"." "."is over"?></b></td>
</tr>
</table>
<br />
</td>
</tr>
<?
echo("<tr>
<td bgcolor=FFFFFF align=center width=125 height=112 background=./images/metal/clock_left.gif> <b>Game</b></td>
<td bgcolor=FFFFFF align=center width=125 height=112 background=./images/metal/clock_right.gif><b>Over</b> </td></tr>");
} else {?>
<tr>
<td colspan=2 nowrap align=center>
<table width=250 border=2 bordercolor=000000 bgcolor=DBDBDB
align=center>
<tr>
<td align=center bgcolor=000080><font color=FFFFFF><b><?if($row['timelimit'] != 0) {echo(_("timeforeach")."<br />".$gameeach['days']." "._("days")." ");} else {echo(_("timeforeach")."<br />"._("unlimited"));}?></b></font></td>
</tr>
</table>
</td>
</tr>
<?
echo("<tr><td bgcolor=FFFFFF align=center width=125 height=112 background=./images/metal/");
if($cor == "white") {echo("clock_left_red.gif");} else {echo("clock_left_green.gif");}
echo("> <b><font color=#1F5070> ");
//if($clocktimewhite['days'] != 0) {$showwhite = ("[".$clocktimewhite['days'].":".$clocktimewhite['hours'].":".$clocktimewhite['minutes'].":".$clocktimewhite['seconds']."]");}
if($row['timelimit'] != 0)
{
if($clocktimewhite['days'] != 0)
{
printf("%02d:",$clocktimewhite['days']);
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] != 0)
{
printf("%02d:",$clocktimewhite['hours']);
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] != 0)
{
printf("%02d:",$clocktimewhite['minutes']);
printf("%02d",$clocktimewhite['seconds']);
}
if($clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0&& $clocktimewhite['seconds'] != 0)
{
printf("%02d",$clocktimewhite['seconds']);
}
if($lastmove != 0 && $clocktimewhite['days'] == 0 && $clocktimewhite['hours'] == 0 && $clocktimewhite['minutes'] == 0 && $clocktimewhite['seconds'] == 0)
{
echo _("Game Over");
}
} else {
printf("%02d:",$whited);
printf("%02d:",$whiteh);
printf("%02d:",$whitem);
printf("%02d",$whites);
//echo($showwhite);
}
echo("</font></b></td><td bgcolor=FFFFFF align=center width=125 height=112 background=./images/metal/");
if($cor == "white") {echo("clock_right_green.gif");} else {echo("clock_right_red.gif");}
echo("><b><font color=#1F5070>");
if($row['timelimit'] != 0)
{
if($clocktimeblack['days'] != 0)
{
printf("%02d:",$clocktimeblack['days']);
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] != 0)
{
printf("%02d:",$clocktimeblack['hours']);
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] != 0)
{
printf("%02d:",$clocktimeblack['minutes']);
printf("%02d",$clocktimeblack['seconds']);
}
if($clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0&& $clocktimeblack['seconds'] != 0)
{
printf("%02d",$clocktimeblack['seconds']);
}
if($lastmove != 0 && $clocktimeblack['days'] == 0 && $clocktimeblack['hours'] == 0 && $clocktimeblack['minutes'] == 0 && $clocktimeblack['seconds'] == 0)
{
echo _("Game Over");
}
} else {
printf("%02d:",$blackd);
printf("%02d:",$blackh);
printf("%02d:",$blackm);
printf("%02d",$blacks);
//echo($showblack);
}
echo("</b> </td></tr>");}?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?
}
function writePromotion()
{
GLOBAL $MSG_LANG,$_SESSION;
?>
<script>onclick="stopTimer=1";</script>
<table width="435" border="1" bgcolor=red>
<tr>
<td align=center valign=top bgcolor=FFFFFF><?=_("promotepawnto")?>: <br />
<input style="background-color: red" type="radio" name="promotion"
value="<? echo (QUEEN); ?>" checked="checked"><img
alt='<?=_("queen")?>'
src='images/pieces/<?=$_SESSION['pref_theme']?>/black_queen.gif'
height='25' /> <input style="background-color: red" type="radio"
name="promotion" value="<? echo (ROOK); ?>" /><img alt='<?=_("rook")?>'
src='images/pieces/<?=$_SESSION['pref_theme']?>/black_rook.gif'
height='25' /> <input style="background-color: red" type="radio"
name="promotion" value="<? echo (KNIGHT); ?>" /><img
alt='<?=_("knight")?>'
src='images/pieces/<?=$_SESSION['pref_theme']?>/black_knight.gif'
height='25' /> <input style="background-color: red" type="radio"
name="promotion" value="<? echo (BISHOP); ?>" /><img
alt='<?=_("bishop")?>'
src='images/pieces/<?=$_SESSION['pref_theme']?>/black_bishop.gif'
height='25' /> <input type="button" name="btnPromote"
value="<?=_("promote")?>" onclick="promotepawn()" /><br />
</td>
</tr>
</table>
<?
}
function writeWaitPromotion()
{
GLOBAL $MSG_LANG;
?>
<script>onclick="stopTimer=1";</script>
<table width="435" border="1" bgcolor=white>
<tr>
<td align=center><?=_("waitingpromotion")?></td>
</tr>
</table>
<?php
}
function writeUndoRequest()
{
GLOBAL $MSG_LANG;
/* Language selection */
require_once "includes/languageselection.inc.php";
?>
<table width="435" border="1">
<tr>
<td><?=_("requestundo")?> <br />
<input type="radio" name="undoResponse" value="yes"> <?=_("yes")?> <input
type="radio" name="undoResponse" value="no" checked="checked" /> <?=_("no")?>
<input type="hidden" name="isUndoResponseDone" value="no" /> <input
type="button" value="<?=_("Responder") ?>"
onclick="this.form.isUndoResponseDone.value = 'yes'; this.form.submit()" />
</td>
</tr>
</table>
<?php
}
function writeDrawRequest()
{
GLOBAL $MSG_LANG;
?>
<table align='center' width='350' border='0' bgcolor="<?=$bgcolor6 ?>">
<tr>
<td align='center' bgcolor="<?=$bgcolor8?>"><?= _("drawrequest")?> <br />
<input type="radio" name="drawResponse" value="yes" /> <?=_("yes")?> <input
type="radio" name="drawResponse" value="no" checked="checked" /> <?=_("no")?>
<input type="hidden" name="isDrawResponseDone" value="no" /> <input
type="button" value="Submit"
onclick="this.form.isDrawResponseDone.value = 'yes'; this.form.submit()" />
</td>
</tr>
</table>
<?php
}
?>
######################################################################