<?php
session_start();
define("PATH", $_SERVER['DOCUMENT_ROOT']);
include(PATH."/core/func.php");
include(PATH."/core/db.php");
include(PATH."/core/set.php");
include(PATH."/core/define.php");
include(PATH."/core/defineset.php");
db_connect();
$i=0;
$games = explode(',', $_POST['games_list']);
//$games_s = [];
foreach ($games as $game)
{
	$num = 's'.$i;
	$res = db_query("SELECT * FROM `sapper_games` WHERE `id` = '".$game."'");
	if(db_rows($res) == 0)
	{
		$res_active = db_query("SELECT * FROM `sapper_games_active` WHERE `id` = '".$game."'");
		if(db_rows($res_active) != 0)
		{
			$ra = db_assoc($res_active);
			if($_SESSION['login'] != $ra['login2']) { $games_s[$num] = '{"id":"'.$game.'","s":"<center><font class=\"prn_gray\" >Игру начал: '.$ra['login2'].'<\/font></center>"}'; }
		} else {
			$res_end = db_query("SELECT * FROM `sapper_games_end` WHERE `id` = '".$game."'");
			if(db_rows($res_end) != 0)
			{
				$re = db_assoc($res_end);
				if($_SESSION['login'] == $re['login'])
				{
					if($re['winner'] == $_SESSION['login'])
					{
						$games_s[$num] = '{"id":"'.$game.'","s":"<center><font color=\"#0F680B\">Выиграл <br>'.$re['login2'].'<\/font></center>"}';
					}
					else $games_s[$num] = '{"id":"'.$game.'","s":"<center><font color=\"#f00\">Проиграл <br>'.$re['login2'].'<\/font></center>"}';
				}
				else {
					if($_SESSION['login'] != $re['login2']) 
					{
						if($re['winner'] != $re['login']) 
						{
							$games_s[$num] = '{"id":"'.$game.'","s":"<center><font class=\"prn_gray\">Выиграл '.$re['login2'].'<\/font></center>"}';
						}
						else $games_s[$num] = '{"id":"'.$game.'","s":"<center><font class=\"prn_gray\">Проиграл '.$re['login2'].'<\/font></center>"}';
					}
				}
			}
			else $games_s[$num] = '{"id":"'.$game.'","s":"<center><font class=\"prn_gray\">Игра отменена<\/font></center>"}';
		}
	}
	$i++;
	//$games_s['s0'] .= $game.","; 
}
//$statuses['id'] = 14219;
//$statuses['s'] = "<font class=\"prn_gray\" title=\"\u0412\u044b\u0438\u0433\u0440\u0430\u043b FantomaS_1\">\u0412\u044b\u0438\u0433\u0440\u0430\u043b FantomaS_1<\/font>";
//$games['s0'] = '{"id":"14219","s":"<font class=\"prn_gray\" title=\"\u0412\u044b\u0438\u0433\u0440\u0430\u043b FantomaS_1\">\u0412\u044b\u0438\u0433\u0440\u0430\u043b FantomaS_1<\/font>"}';
echo json_encode(array("statuses"=>$games_s));
db_close();
?>