Esempio n. 1
0
function saveHistory()
{
    global $CFG_TABLE;
    global $board, $isPromoting, $history, $numMoves, $isInCheck, $CFG_USEEMAILNOTIFICATION;
    /* old PHP versions don't have _POST, _GET and _SESSION as auto_globals */
    if (!minimum_version("4.1.0")) {
        global $_POST, $_GET, $_SESSION;
    }
    /* set destination row for pawn promotion */
    if ($board[$_POST['fromRow']][$_POST['fromCol']] & BLACK) {
        $targetRow = 0;
    } else {
        $targetRow = 7;
    }
    /* determine if move results in pawn promotion */
    if (($board[$_POST['fromRow']][$_POST['fromCol']] & COLOR_MASK) == PAWN && $_POST['toRow'] == $targetRow) {
        $isPromoting = true;
    } else {
        $isPromoting = false;
    }
    /* determine who's playing based on number of moves so far */
    if ($numMoves == -1 || $numMoves % 2 == 1) {
        $curColor = "white";
        $oppColor = "black";
    } else {
        $curColor = "black";
        $oppColor = "white";
    }
    /* add move to history */
    $numMoves++;
    $history[$numMoves]['gamedID'] = $_SESSION['gameID'];
    $history[$numMoves]['curPiece'] = getPieceName($board[$_POST['fromRow']][$_POST['fromCol']]);
    $history[$numMoves]['curColor'] = $curColor;
    $history[$numMoves]['fromRow'] = $_POST['fromRow'];
    $history[$numMoves]['fromCol'] = $_POST['fromCol'];
    $history[$numMoves]['toRow'] = $_POST['toRow'];
    $history[$numMoves]['toCol'] = $_POST['toCol'];
    $history[$numMoves]['promotedTo'] = null;
    if ($isInCheck) {
        $history[$numMoves]['isInCheck'] = 1;
    } else {
        $history[$numMoves]['isInCheck'] = 0;
    }
    if (DEBUG) {
        if ($history[$numMoves]['curPiece'] == '') {
            echo "WARNING!!!  missing piece at " . $_POST['fromRow'] . ", " . $_POST['fromCol'] . ": " . $board[$_POST['fromRow']][$_POST['fromCol']] . "<p>\n";
        }
    }
    if ($board[$_POST['toRow']][$_POST['toCol']] == 0) {
        $tmpQuery = "INSERT INTO " . $CFG_TABLE[history] . " (timeOfMove, gameID, curPiece, curColor, fromRow, fromCol, toRow, toCol, replaced, promotedTo, isInCheck) VALUES (Now(), " . $_SESSION['gameID'] . ", '" . getPieceName($board[$_POST['fromRow']][$_POST['fromCol']]) . "', '{$curColor}', " . $_POST['fromRow'] . ", " . $_POST['fromCol'] . ", " . $_POST['toRow'] . ", " . $_POST['toCol'] . ", null, null, " . $history[$numMoves]['isInCheck'] . ")";
        $history[$numMoves]['replaced'] = null;
        $tmpReplaced = "";
    } else {
        $tmpQuery = "INSERT INTO " . $CFG_TABLE[history] . " (timeOfMove, gameID, curPiece, curColor, fromRow, fromCol, toRow, toCol, replaced, promotedTo, isInCheck) VALUES (Now(), " . $_SESSION['gameID'] . ", '" . getPieceName($board[$_POST['fromRow']][$_POST['fromCol']]) . "', '{$curColor}', " . $_POST['fromRow'] . ", " . $_POST['fromCol'] . ", " . $_POST['toRow'] . ", " . $_POST['toCol'] . ", '" . getPieceName($board[$_POST['toRow']][$_POST['toCol']]) . "', null, " . $history[$numMoves]['isInCheck'] . ")";
        $history[$numMoves]['replaced'] = getPieceName($board[$_POST['toRow']][$_POST['toCol']]);
        $tmpReplaced = $history[$numMoves]['replaced'];
    }
    mysql_query($tmpQuery);
    /* if email notification is activated and move does not result in a pawn's promotion... */
    /* NOTE: moves resulting in pawn promotion are handled by savePromotion() above */
    if ($CFG_USEEMAILNOTIFICATION && !$isPromoting && !$_SESSION['isSharedPC']) {
        /* get opponent's player ID */
        if ($oppColor == 'white') {
            $tmpOpponentID = mysql_query("SELECT whitePlayer FROM " . $CFG_TABLE[games] . " WHERE gameID = " . $_SESSION['gameID']);
        } else {
            $tmpOpponentID = mysql_query("SELECT blackPlayer FROM " . $CFG_TABLE[games] . " WHERE gameID = " . $_SESSION['gameID']);
        }
        $opponentID = mysql_result($tmpOpponentID, 0);
        /* if opponent is using email notification... */
        $tmpOpponentEmail = mysql_query("SELECT value FROM " . $CFG_TABLE[preferences] . " WHERE playerID = " . $opponentID . " AND preference = 'emailNotification'");
        if (mysql_num_rows($tmpOpponentEmail) > 0) {
            $opponentEmail = mysql_result($tmpOpponentEmail, 0);
            if ($opponentEmail != '') {
                /* get opponent's nick */
                $tmpOpponentNick = mysql_query("SELECT nick FROM " . $CFG_TABLE[players] . " WHERE playerID = " . $_SESSION['playerID']);
                $opponentNick = mysql_result($tmpOpponentNick, 0);
                /* get opponent's prefered history type */
                $tmpOpponentHistory = mysql_query("SELECT value FROM " . $CFG_TABLE[preferences] . " WHERE playerID = " . $opponentID . " AND preference = 'history'");
                /* default to PGN */
                if (mysql_num_rows($tmpOpponentHistory) > 0) {
                    $opponentHistory = mysql_result($tmpOpponentHistory, 0);
                } else {
                    $opponentHistory = 'pgn';
                }
                /* notify opponent of move via email */
                if ($opponentHistory == 'pgn') {
                    webchessMail('move', $opponentEmail, moveToPGNString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, '', $isInCheck), $opponentNick, $_SESSION['gameID']);
                } else {
                    webchessMail('move', $opponentEmail, moveToVerbousString($history[$numMoves]['curColor'], $history[$numMoves]['curPiece'], $history[$numMoves]['fromRow'], $history[$numMoves]['fromCol'], $history[$numMoves]['toRow'], $history[$numMoves]['toCol'], $tmpReplaced, '', $isInCheck), $opponentNick, $_SESSION['gameID']);
                }
            }
        }
    }
}
Esempio n. 2
0
function writeHistoryPGN()
{
    global $history, $numMoves;
    for ($i = 0; $i <= $numMoves; $i++) {
        $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;
        $moves[$i / 2][$i & 1] = moveToPGNString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck);
    }
    return $moves;
}
		echo ("<tr><td bgcolor='green' align='center' style='font-weight: normal'><font color='white'><b>Last moves");
	    for ($i = $numMoves-$i+7; $i <= $numMoves; $i+=1)
                {
                        //echo ("<tr><td bgcolor='green' align='center' style='font-weight: normal'><font color='white'><b>Last 2 Moves - ");

                        $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]['check'] == 1);
						echo("-(");
                        echo(moveToPGNString($history[$i]['curColor'], $history[$i]['curPiece'], $history[$i]['fromRow'], $history[$i]['fromCol'], $history[$i]['toRow'], $history[$i]['toCol'], $tmpReplaced, $tmpPromotedTo, $tmpCheck));
                        echo(")");
					   //echo ("</b></td></tr>\n");
                }
        //echo("]");
		echo ("</b></font></td></tr>\n");
		?>
</table>
		<? writeStatus(); ?>
		<BR> 
		

				<form method=POST action="chess.php" name=chess> 
    <input type=hidden name="gameID" value="<?=$_SESSION["gameID"]?>"> 
    <table border='0' width=300  bgcolor=black cellspacing=1 cellpading=1> 
    <tr><th bgcolor='beige' colspan='3'>NOTES TO SELF 
Esempio n. 4
0
    function saveHistory($post = "")
    {
        global $db,$db_prefix, $board, $isPromoting, $history, $numMoves, $is_in_check, $CFG_USEEMAILNOTIFICATION;

        if ($post != "")
            $_POST = $post;


        /* set destination row for pawn promotion */
        if ($board[$_POST['from_row']][$_POST['from_col']] & BLACK)
            $targetRow = 0;
        else
            $targetRow = 7;

        /* determine if move results in pawn promotion */
        if ((($board[$_POST['from_row']][$_POST['from_col']] & COLOR_MASK) == PAWN) && ($_POST['to_row'] == $targetRow))
            $isPromoting = true;
        else
            $isPromoting = false;

        /* determine who's playing based on number of moves so far */
        if (($numMoves == -1) || ($numMoves % 2 == 1))
        {
            $cur_color = "white";
            $oppColor = "black";
            $targetRow = 7;
        }
        else
        {
            $cur_color = "black";
            $oppColor = "white";
            $targetRow = 0;
        }

        /* add move to history */
        $numMoves++;
        $history[$numMoves]['game_id'] = $_SESSION['game_id'];
        $history[$numMoves]['cur_piece'] = getPieceName($board[$_POST['from_row']][$_POST['from_col']]);
        $history[$numMoves]['cur_color'] = $cur_color;
        $history[$numMoves]['from_row'] = $_POST['from_row'];
        $history[$numMoves]['from_col'] = $_POST['from_col'];
        $history[$numMoves]['to_row'] = $_POST['to_row'];
        $history[$numMoves]['to_col'] = $_POST['to_col'];
        $history[$numMoves]['promoted_to'] = null;

        if ($is_in_check)
            $history[$numMoves]['is_in_check'] = 1;
        else
            $history[$numMoves]['is_in_check'] = 0;

        /*
        if (DEBUG)
        {
            if ($history[$numMoves]['curPiece'] == '')
                echo ("WARNING!!!  missing piece at ".$_POST['from_row'].", ".$_POST['from_col'].": ".$board[$_POST['from_row']][$_POST['from_col']]."<p>\n");
        }
        */

        if ($board[$_POST['to_row']][$_POST['to_col']] == 0)
        {
            $tmpQuery = "INSERT INTO {$db_prefix}history (time_of_move, game_id, cur_piece, cur_color, from_row, from_col, to_row, to_col, replaced, promoted_to, is_in_check) VALUES (Now(), '$game_id', '".getPieceName($board[$_POST['from_row']][$_POST['from_col']])."', '$cur_color', ".$_POST['from_row'].", ".$_POST['from_col'].", ".$_POST['to_row'].", ".$_POST['to_col'].", null, null, ".$history[$numMoves]['is_in_check'].")";
            $history[$numMoves]['replaced'] = null;
            $tmpReplaced = "";
        }
        else
        {
            $tmpQuery = "INSERT INTO {$db_prefix}history (time_of_move, game_id, cur_piece, cur_color, from_row, from_col, to_row, to_col, replaced, promoted_to, is_in_check) VALUES (Now(), '$game_id', '".getPieceName($board[$_POST['from_row']][$_POST['from_col']])."', '$cur_color', ".$_POST['from_row'].", ".$_POST['from_col'].", ".$_POST['to_row'].", ".$_POST['to_col'].", '".getPieceName($board[$_POST['to_row']][$_POST['to_col']])."', null, ".$history[$numMoves]['is_in_check'].")";

            $history[$numMoves]['replaced'] = getPieceName($board[$_POST['to_row']][$_POST['to_col']]);
            $tmpReplaced = $history[$numMoves]['replaced'];
        }

       $res =  mysql_query($tmpQuery) or die(mysql_error());


        /* if email notification is activated and move does not result in a pawn's promotion... */
        /* NOTE: moves resulting in pawn promotion are handled by savePromotion() above */
        if ($CFG_USEEMAILNOTIFICATION && !$isPromoting)
        {
            /* get opponent's player ID */
            if ($oppColor == 'white')
                $tmpOpponentID = mysql_query("SELECT white_player FROM games WHERE game_id = ".$_SESSION['game_id']);
            else
                $tmpOpponentID = mysql_query("SELECT black_player FROM games WHERE game_id = ".$_SESSION['game_id']);

            $opponentID = mysql_result($tmpOpponentID, 0);

            /* if opponent is using email notification... */
            $tmpOpponentEmail = mysql_query("SELECT value FROM preferences WHERE playerID = ".$opponentID." AND preference = 'emailNotification'");
            if (mysql_num_rows($tmpOpponentEmail) > 0)
            {
                $opponentEmail = mysql_result($tmpOpponentEmail, 0);
                if ($opponentEmail != '')
                {
                    /* get opponent's nick */
                    $tmpOpponentNick = mysql_query("SELECT firstName FROM {$db_prefix}players WHERE playerID = ".$_SESSION['playerID']);
                    $opponentNick = mysql_result($tmpOpponentNick, 0);

                    /* get opponent's prefered history type */
                    $tmpOpponentHistory = mysql_query("SELECT value FROM preferences WHERE playerID = ".$opponentID." AND preference = 'history'");

                    /* default to PGN */
                    if (mysql_num_rows($tmpOpponentHistory) > 0)
                        $opponentHistory = mysql_result($tmpOpponentHistory, 0);
                    else
                        $opponentHistory = 'pgn';

                    /* notify opponent of move via email */
                    if ($opponentHistory == 'pgn')
                        webchessMail('move', $opponentEmail, moveToPGNString($history[$numMoves]['cur_color'], $history[$numMoves]['curPiece'], $history[$numMoves]['from_row'], $history[$numMoves]['from_col'], $history[$numMoves]['to_row'], $history[$numMoves]['to_col'], $tmpReplaced, '', $is_in_check), $opponentNick);
                    else
                        webchessMail('move', $opponentEmail, moveToVerbousString($history[$numMoves]['cur_color'], $history[$numMoves]['curPiece'], $history[$numMoves]['from_row'], $history[$numMoves]['from_col'], $history[$numMoves]['to_row'], $history[$numMoves]['to_col'], $tmpReplaced, '', $is_in_check), $opponentNick);
                }
            }
        }
    }
Esempio n. 5
0
                    $tmpReplaced = $history[$i]['replaced'];
          }

          $tmpPromotedTo = "";
          if (!is_null($history[$i]['promoted_to']))
          {
                    $tmpPromotedTo = $history[$i]['promoted_to'];
          }
          $tmpCheck = 0;
          if ($history[$i]['is_in_check'] == 1)
          {

               $tmpCheck = 1;
          }
          echo("-(");
          echo(moveToPGNString($history[$i]['cur_color'], $history[$i]['cur_piece'], $history[$i]['from_row'], $history[$i]['from_col'], $history[$i]['to_row'], $history[$i]['to_col'], $tmpReplaced, $tmpPromotedTo, $tmpCheck));
          echo(")");
          //echo ("</b></td></tr>\n");
     }
        //echo("]");
        echo ("</b></font></td></tr>\n");
        ?>
</table>
        <? writeStatus(); ?>
        <BR>


                <form method=POST action="chess.php" name=chess>
    <input type=hidden name="game_id" value="<?php 
echo $_SESSION["game_id"];
?>
Esempio n. 6
0
    function writeHistoryPGN($format = "color", $single = 'none')
    {
        global $history, $numMoves, $MSG_LANG; $_SESSION;

        if ($format == "color"){
              echo ("<table border='0' width=100%  bgcolor=black cellspacing=1 cellpading=1>\n");
          echo ("<tr><th bgcolor='beige' colspan='5'>".strtoupper($MSG_LANG["history"])."</th></tr>\n");
          echo ("<tr><th bgcolor='#BBBBBB' width='50'>".$MSG_LANG["movement"]."</th>");
          echo ("<th bgcolor='white' colspan='2' align='center'><font color='black'>".$MSG_LANG["white"]."</font></th>");
          echo ("<th bgcolor='silver' colspan='2' align='center'><font color='black'>".$MSG_LANG["black"]."</font></th></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'>".(($i/2) + 1)."</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]['promoted_to']))
                $tmpPromotedTo = $history[$i]['promoted_to'];

            $tmpCheck = ($history[$i]['is_in_check'] == 1);

            if ($format == "plain" && $single != 'single')
                         {
                              if (ceil(($i+1)/2) > 1 && $single == 'chess')
                              {
                                echo "<br>";
                              }

                              echo ceil(($i+1)/2).". ";
                         }


                echo moveToPGNString($history[$i]['cur_color'], $history[$i]['cur_piece'], $history[$i]['from_row'], $history[$i]['from_col'], $history[$i]['to_row'], $history[$i]['to_col'], $tmpReplaced, $tmpPromotedTo, $tmpCheck, $export, $single)." ";

                         if ($format == "color")
            {
                echo "</td><td align='center' bgcolor=white height=18>";
                if ($tmpReplaced!="")
                    echo "<img src='images/pieces/".$_SESSION['theme_set']."/black_".$tmpReplaced.".gif' height='15' align='left'> ";
                echo ("</font></td><td bgcolor='silver' align='center'><font color='black'>");
            }

            if ($i == $numMoves){
                if ($format == "color")
                    echo ("&nbsp;");
            }
            else
            {
                $tmpReplaced = "";
                if (!is_null($history[$i+1]['replaced']))
                    $tmpReplaced = $history[$i+1]['replaced'];

                $tmpPromotedTo = "";
                if (!is_null($history[$i+1]['promoted_to']))
                    $tmpPromotedTo = $history[$i+1]['promoted_to'];

                $tmpCheck = ($history[$i+1]['is_in_check'] == 1);

                //if ($format == "plain")
                //      echo ($i+2).". ";

                echo moveToPGNString($history[$i+1]['cur_color'], $history[$i+1]['cur_piece'], $history[$i+1]['from_row'], $history[$i+1]['from_col'], $history[$i+1]['to_row'], $history[$i+1]['to_col'], $tmpReplaced, $tmpPromotedTo, $tmpCheck,$export,$single)." ";
            if ($format == "color")
                {
                    echo "</td><td align='center' bgcolor='silver' height=18>";
                    if ($tmpReplaced!="")
                        echo "<img src='images/pieces/".$_SESSION['theme_set']."/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>\n");

    }