Location: PHPKode > scripts > Some Chess > some-chess/board.php
<?php 
//		Some Chess, a PHP multi-player chess server.
//		Copyright (C) 2006 Jon Link
session_start(); 
require_once('loginon.php');
require_once('config.php');
include_once('languages/'.$lang.'_chess.php');
include_once('standard.php');
include_once('constants.php');
$id					 	= validate($_SESSION['id']);
$do						= $_POST['do'];
if(!$do) $do			= $_GET['do'];
$gameID				 	= $_POST['gameID'];
if(!$gameID) $gameID	= $_GET['gameID'];
$gameID					= validate($gameID);
$vsName				 	= str_replace('_',' ',$_GET['vs']);
if(!$vsName)$vsName		= $_SESSION['vs'.$gameID];
$query				 = 'SELECT * FROM games WHERE gameID="'.$gameID.'" LIMIT 1';
$result				 = mysql_query($query)or die('<div class="error">'.errorDBStr.'game</div>');	
$locations			 = unserialize(mysql_result($result,0,'setup'));
$bID				 = mysql_result($result,0,'blackPlayerID');
$wID				 = mysql_result($result,0,'whitePlayerID');
if($id == $bID){$playerColor = 'black';}elseif($id == $wID){$playerColor = 'white';}
if($do == 'move'){
	$clickedSQ			 	 			= validate($_GET['sq']);
	if($_SESSION['oldSpot'.$gameID]){
		$oldSpot 			 			= validate($_SESSION['oldSpot'.$gameID]);
		$newSpot 			 			= $clickedSQ;
		if(!$newSpot)$newSpot 			= validate($_POST['newSpot']);
		unset($_SESSION['oldSpot'.$gameID]);
	}elseif($clickedSQ){
		$_SESSION['oldSpot'.$gameID] 	= validate($clickedSQ);
		$do					 			= 'display';
	}
}
if($do == 'move'){
	include_once('move.php');
	$promote			= $_POST['promote'];
	$canCastle			= ($id == $bID)? unserialize(mysql_result($result,0,'bCastle')):unserialize(mysql_result($result,0,'wCastle'));
	$nextMoveNum		= mysql_result($result,0,'nextMoveNum');
	$lastMove			= unserialize(mysql_result($result,0,'lastMove'));
	$nTC				= mysql_result($result,0,'nextTurnColor');
	$locations 			= moveIt($locations,$oldSpot,$newSpot,$nextMoveNum,$gameID,$canCastle,$playerColor,$nTC,$lastMove,$promote,$lang);
	$do 				= 'display';
}
if($do == 'display'){
	include_once('display.php');
	$query				= 'SELECT nextTurnColor,gameDate,lastMove,reqDraw,reqUndo FROM games WHERE gameID="'.$gameID.'" LIMIT 1';
	$result				= mysql_query($query) or die('<div class="error">'.errorDBStr.'games</div>');	
	$reqDraw			= mysql_result($result,0,'reqDraw');
	$reqUndo			= mysql_result($result,0,'reqUndo');
	$lastMove			= unserialize(mysql_result($result,0,'lastMove'));
	if($reqUndo == $_SESSION['id']){
		$message = '<p>'.$infoBoxStr[10].'</p>';
		$undoB = 0;
	}elseif($reqUndo){
		$message = '<p>'.$infoBoxStr[9].'</p>';
		$undoB = 2;
	}
	if($reqDraw == $_SESSION['id']){
		$message .= '<p>'.$infoBoxStr[8].'</p>';
		$undoD = 0;
	}elseif($reqDraw){
		$message .= '<p>'.$infoBoxStr[7].'</p>';
		$undoD = 2;
	}
	if($_SESSION['oldSpot'.$gameID]) $message = '<p>'.$infoBoxStr[15].$_SESSION['oldSpot'.$gameID].$infoBoxStr[16].'</p>';
	if(mysql_result($result,0,'nextTurnColor') == $playerColor){
		$turn = $boardStr[0];
		if(strpos($lastMove['move'],'+') !== false) $message 	.= '<p>'.$infoBoxStr[6].'</p>';
		if(strpos($lastMove['move'],'#') !== false) $message 	= '<p>'.$gameOverStr[0].'</p>';
	}else{
		if($undoB === 0){$undoB = null;}else{$undoB = 1;}
		$turn = $boardStr[1].$vsName.$boardStr[2];
		if(strpos($lastMove['move'],'#') !== false) $message 	.= $gameOverStr[1];
		if($boardRefresh && strpos($lastMove['move'],'#') === false) header('refresh: '.$boardRefresh.'; url=board.php?do=display&gameID='.$gameID);
	}
	echo'<link rel="stylesheet" type="text/css" href="board.css">';
	displayBoard($locations,$playerColor,$gameID);
	if(mysql_result($result,0,'gameDate' && $endDays)<date(YmdHis, mktime(0, 0, 0, date(m), date(d)-$endDays, date(Y)))) $endB = true;
	include_once('info.php');
}
$_SESSION['vs'.$gameID] = $vsName;
unset($undoB);
?>
Return current item: Some Chess