2021-03-10 13:16:08 +00:00
|
|
|
<?php
|
|
|
|
require_once "../../../bootstrap.php";
|
|
|
|
require_once('../Group/Group.php');
|
|
|
|
require_once('FileHandler.php');
|
2021-04-19 07:15:15 +00:00
|
|
|
|
2021-03-10 13:16:08 +00:00
|
|
|
use Backend\Models\GameData;
|
2021-04-19 07:15:15 +00:00
|
|
|
use Backend\Models\Registration;
|
|
|
|
|
|
|
|
if (isLogin()) {
|
|
|
|
if (isset($_POST['submitUpdate'])) {
|
|
|
|
//Get the game data
|
|
|
|
$gameData = GameData::find($_POST['gameDataId']);
|
|
|
|
if ($gameData === null) {
|
|
|
|
http_response_code(400);
|
|
|
|
echo json_encode(["message" => "game data not found"]);
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
//Get the group
|
|
|
|
$group = groupViaToken($_SESSION['token']);
|
|
|
|
if (!in_array($gameData->id, Registration::where("group_id", $group->id)->pluck("game_data_id")->toArray())) {
|
|
|
|
http_response_code(401);
|
|
|
|
exit();
|
|
|
|
}
|
2021-03-10 13:16:08 +00:00
|
|
|
|
|
|
|
$gameFile = $_FILES['gameFile'];
|
|
|
|
$desc = $_POST['description'];
|
|
|
|
$title = $_POST['gameTitle'];
|
|
|
|
$thumbnail = $_FILES['thumbnailFile'];
|
2021-04-19 07:15:15 +00:00
|
|
|
$isWebBased = isset($_POST['isWebBased']);
|
2021-03-10 13:16:08 +00:00
|
|
|
|
|
|
|
$gameFileName = $_FILES['gameFile']['name'];//Game name
|
|
|
|
$gameFileTmp = $_FILES['gameFile']['tmp_name'];//Tmp location of the file
|
|
|
|
$gameFileError = $_FILES['gameFile']['error'];//File error
|
|
|
|
|
|
|
|
$thumbnailFileName = $_FILES['thumbnailFile']['name'];//Game name
|
|
|
|
$thumbnailFileTmp = $_FILES['thumbnailFile']['tmp_name'];//Tmp location of the file
|
2021-04-19 07:15:15 +00:00
|
|
|
$thumbnailFileError = $_FILES['thumbnailFile']['error'];//File error
|
2021-03-10 13:16:08 +00:00
|
|
|
|
|
|
|
$gameData->game_name = $title;
|
2021-04-19 07:15:15 +00:00
|
|
|
if (isset($gameData) && $gameFileError === 0) {
|
|
|
|
unlink("../../Games/" . $gameData->game_link);
|
|
|
|
$gameData->game_link = ZipFileHandler($gameFileName, $gameFileTmp);
|
2021-03-10 13:16:08 +00:00
|
|
|
}
|
|
|
|
$gameData->description = $desc;
|
2021-04-19 07:15:15 +00:00
|
|
|
if (isset($thumbnail) && $thumbnailFileError === 0) {
|
|
|
|
unlink("../../../Frontend/images/" . $gameData->img);
|
|
|
|
$gameData->img = imagesFileHandler($thumbnailFileName, $thumbnailFileTmp);
|
2021-03-10 13:16:08 +00:00
|
|
|
}
|
|
|
|
$gameData->is_web_Based = $isWebBased;
|
2021-04-19 07:15:15 +00:00
|
|
|
if (!$gameData->save()) {
|
|
|
|
http_response_code(500);
|
|
|
|
} else {
|
|
|
|
http_response_code(201);
|
2021-03-19 12:25:27 +00:00
|
|
|
}
|
|
|
|
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
|
|
|
http_response_code(400);
|
2021-03-10 13:16:08 +00:00
|
|
|
}
|
2021-04-19 07:15:15 +00:00
|
|
|
} else {
|
|
|
|
http_response_code(401);
|
|
|
|
echo json_encode(["message" => "is not login"]);
|
2021-03-10 13:16:08 +00:00
|
|
|
}
|