
<?php
  
ACCESS('users');
  
$game = DB::GET_STRING("SELECT * FROM `GAMES` WHERE `ID` = '".INTVAL(GET('id'))."' LIMIT 1");
$game_user = DB::GET_STRING("SELECT * FROM `GAMES_USERS` WHERE `GAME_ID` = '".$game['ID']."' AND `USER_ID` = '".$user['ID']."' LIMIT 1");

IF (!ISSET($game['ID'])){
  
  ERROR('Неверная директива', 'session');
  REDIRECT('/modules/?path=games');

}

IF (GET('get') == 'delete' && ISSET($game_user['ID'])){

  DB::GET_SET("UPDATE `GAMES` SET `RATING` = `RATING` - '1' WHERE `ID` = '".$game['ID']."' LIMIT 1");
  DB::GET_SET("DELETE FROM `GAMES_USERS` WHERE `GAME_ID` = '".$game['ID']."' AND `USER_ID` = '".$user['ID']."' LIMIT 1");

  SUCCESS('Игра успешно удалена из вашего списка');
  REDIRECT('/modules/?path=games');

}

IF (GET('get') == 'go' && !ISSET($game_user['ID'])){
  
  DB::GET_ADD("INSERT INTO `GAMES_USERS` (`USER_ID`, `GAME_ID`) VALUES ('".$user['ID']."', '".$game['ID']."')");
  DB::GET_SET("UPDATE `GAMES` SET `RATING` = `RATING` + '1' WHERE `ID` = '".$game['ID']."' LIMIT 1");

  REDIRECT('/modules/games/list/'.$game['LINK'].'/');

}

IF (GET('get') == 'go_user' && ISSET($game_user['ID'])){

  REDIRECT('/modules/games/list/'.$game['LINK'].'/');

}

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=games'>".LG('Онлайн игры')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($game['NAME'])."";
ECHO "</div>";

ECHO "<div class='list'>";

ECHO "<table style='width: 100%;'><tr>";

ECHO "<td class='comments-avatar'>";
ECHO "<img class='img' src='/modules/games/list/".$game['LINK']."/img/".$game['IMG']."' style='width: 50px; height: 50px;'>";
ECHO "</td>";
  
ECHO "<td class='comments-info'>";
ECHO "<b>".TEXT_ABSOLUTE($game['NAME'])."</b><br />";

$count = DB::GET_COLUMN("SELECT COUNT(*) FROM `GAMES_USERS` WHERE `GAME_ID` = '".$game['ID']."'");

ECHO "<p>".ICONS('user', 15, 'fa-fw')." ".LG('играют')." ".$count." ".LG('чел.')."</p>";

ECHO "</td>";
  
ECHO "</tr></table>";

ECHO TEXT_ABSOLUTE($game['MESSAGE'])."<br /><br />";

IF (ISSET($game_user['ID'])){
  
  ECHO "<a load='none' href='/modules/?path=games&section=show&id=".$game['ID']."&get=go_user' class='btn'>".ICONS('gamepad', 15, 'fa-fw')." ".LG('Играть')."</a>";
  ECHO "<a href='/modules/?path=games&section=show&id=".$game['ID']."&get=delete' class='btn-o'>".ICONS('trash', 15, 'fa-fw')." ".LG('Удалить из списка')."</a>";
  
}ELSE{
  
  ECHO "<a load='none' href='/modules/?path=games&section=show&id=".$game['ID']."&get=go' class='btn'>".ICONS('plus', 15, 'fa-fw')." ".LG('Вступить в игру')."</a>";
  
}

ECHO "</div>";

//Навигация
ECHO "<div class='navigation'>";
ECHO "<a href='/'>".ICONS('home', 25, 'fa-fw')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "<a href='/modules/?path=games'>".LG('Онлайн игры')."</a>";
ECHO "".ICONS('angle-right', 20, 'fa-fw')."";
ECHO "".TEXT_ABSOLUTE($game['NAME'])."";
ECHO "</div>";
  
?>