diff --git a/include/TGDB.API.php b/include/TGDB.API.php index b505106..8f2c34c 100644 --- a/include/TGDB.API.php +++ b/include/TGDB.API.php @@ -25,7 +25,7 @@ public static function getInstance() function GetGameListByPlatform($IDs = 0, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -107,7 +107,7 @@ function GetGameByID($IDs, $offset = 0, $limit = 20, $fields = array()) return array(); } - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -141,7 +141,7 @@ function SearchGamesByName($searchTerm, $offset = 0, $limit = 20, $fields = arra { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -190,7 +190,7 @@ function SearchGamesByNameByPlatformID($searchTerm, $IDs, $offset = 0, $limit = { $dbh = $this->database->dbh; - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -265,7 +265,7 @@ function GetGamesByDate($date, $offset = 0, $limit = 20, $fields = array(), $Ord function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -334,7 +334,7 @@ function GetGamesByDateByPlatform($IDs, $date, $offset = 0, $limit = 20, $fields function GetAllGames($offset = 0, $limit = 20, $fields = array(), $OrderBy = '', $ASCDESC = 'ASC') { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -375,7 +375,7 @@ function GetAllGames($offset = 0, $limit = 20, $fields = array(), $OrderBy = '', function GetGamesByLatestUpdatedDate($minutes, $offset = 0, $limit = 20, $fields = array()) { - $qry = "Select id, GameTitle, Developer, ReleaseDate, Platform "; + $qry = "Select id, GameTitle, Developer, ReleaseDate, ReleaseDateRevised, Platform "; if(!empty($fields)) { @@ -754,7 +754,193 @@ function is_valid_games_col($name) } return isset($this->GamesTblCols[$name]); } -} + /* Everything belowis not planned to be exposed through external API */ + function InsertUserEdits($user_id, $game_id, $type, $diff, $subtype = '') + { + $dbh = $this->database->dbh; + $sth = $dbh->prepare("INSERT INTO user_edits (users_id, games_id, type, diff) VALUES (:users_id, :games_id, :type, :diff);"); + $sth->bindValue(':users_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':games_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':type', $type, PDO::PARAM_INT); + $sth->bindValue(':diff', $diff, PDO::PARAM_STR); + return $sth->execute(); + } + + function UpdateGame($user_id, $game_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + { + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("Select * FROM games WHERE id = :game_id"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + + if($sth->execute()) + { + $Game = $sth->fetch(PDO::FETCH_ASSOC); + } + if(!isset($Game) || empty($Game)) + { + return false; + } + } + + { + $dbh->beginTransaction(); + + $sth = $dbh->prepare("UPDATE games SET GameTitle=:GameTitle, Overview=:Overview, ReleaseDateRevised=:ReleaseDateRevised, ReleaseDate=:ReleaseDate, Players=:Players, coop=:coop, + Developer=:Developer, Publisher=:Publisher, Youtube=:YouTube WHERE id=:game_id"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $sth->bindValue(':GameTitle', htmlspecialchars($GameTitle), PDO::PARAM_STR); + $sth->bindValue(':Overview', htmlspecialchars($Overview), PDO::PARAM_STR); + $sth->bindValue(':ReleaseDateRevised', $ReleaseDateRevised, PDO::PARAM_STR); + $date = explode('-', $ReleaseDateRevised); + $sth->bindValue(':ReleaseDate', "$date[1]/$date[2]/$date[0]", PDO::PARAM_STR); + $sth->bindValue(':Players', $Players, PDO::PARAM_INT); + $sth->bindValue(':YouTube', htmlspecialchars($Youtube), PDO::PARAM_STR); + $sth->bindValue(':coop', $coop, PDO::PARAM_INT); + + // NOTE: these will be moved to own table, as a single game can have multiple devs/publishers + // it will also mean, we will be able to standardise devs/publishers names + // this will allow their selection from a menu as oppose to being provided by the user + $sth->bindValue(':Developer', htmlspecialchars($Developer), PDO::PARAM_STR); + $sth->bindValue(':Publisher', htmlspecialchars($Publisher), PDO::PARAM_STR); + + $sth->execute(); + { + foreach($Game as $key => $value) + { + if(isset($$key) && htmlspecialchars($$key) != $value) + { + if($key == 'Overview') + { + $diff = xdiff_string_diff($Game['Overview'], htmlspecialchars($Overview), 1); + if(empty($diff)) + { + continue; + } + } + else + { + $diff = htmlspecialchars($$key); + } + $this->InsertUserEdits($user_id, $game_id, $key, $diff); + } + } + } + return $dbh->commit(); + } + } + + function DeleteGameImages($user_id, $game_id, $id, $type) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM banners WHERE id=:id;"); + $sth->bindValue(':id', $id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, $type, "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function DeleteAllGameImages($user_id, $game_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM banners WHERE keyvalue=:game_id;"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, "all_images", "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function DeleteAndInsertGameImages($user_id, $id, $game_id, $type, $filename, $side = NULL) + { + $dbh = $this->database->dbh; + $dbh->beginTransaction(); + $this->DeleteGameImages($user_id, $game_id, $id, $type); + $this->InsertGameImages($user_id, $game_id, $type, $filename, $side); + return $dbh->commit(); + + } + + function InsertGameImages($user_id, $game_id, $type, $filename, $side = NULL) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("INSERT INTO banners (keyvalue, keytype, side, filename, userid) VALUES (:keyvalue, :keytype, :side, :filename, :user_id); "); + $sth->bindValue(':user_id', $user_id, PDO::PARAM_INT); + $sth->bindValue(':keyvalue', $game_id, PDO::PARAM_INT); + $sth->bindValue(':keytype', $type, PDO::PARAM_STR); + $sth->bindValue(':side', $side, PDO::PARAM_STR); + $sth->bindValue(':filename', $filename, PDO::PARAM_STR); + $res = $sth->execute(); + + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, $type, $filename); + } + return ($dbh->inTransaction() || $res); + } + function DeleteGame($user_id, $game_id) + { + $dbh = $this->database->dbh; + + $sth = $dbh->prepare("DELETE FROM games WHERE id=:game_id;"); + $sth->bindValue(':game_id', $game_id, PDO::PARAM_INT); + $res = $sth->execute(); + if($dbh->inTransaction() || $res) + { + $this->InsertUserEdits($user_id, $game_id, "game", "[REMOVED]"); + } + return ($dbh->inTransaction() || $res); + } + + function InsertGame($user_id, $GameTitle, $Overview, $Youtube, $ReleaseDateRevised, $Players, $coop, $Developer, $Publisher) + { + $game_id = 0; + $dbh = $this->database->dbh; + { + $sth = $dbh->prepare("INSERT INTO games(GameTitle, Overview, ReleaseDateRevised, ReleaseDate, Players, coop, Developer, Publisher, Youtube, Alternates) + values (:GameTitle, :Overview, :ReleaseDateRevised, :ReleaseDate, :Players, :coop, :Developer, :Publisher, :YouTube, :Alternates)"); + $sth->bindValue(':GameTitle', htmlspecialchars($GameTitle), PDO::PARAM_STR); + $sth->bindValue(':Overview', htmlspecialchars($Overview), PDO::PARAM_STR); + $sth->bindValue(':ReleaseDateRevised', $ReleaseDateRevised, PDO::PARAM_STR); + $date = explode('-', $ReleaseDateRevised); + $sth->bindValue(':ReleaseDate', "$date[1]/$date[2]/$date[0]", PDO::PARAM_STR); + $sth->bindValue(':Players', $Players, PDO::PARAM_INT); + $sth->bindValue(':YouTube', htmlspecialchars($Youtube), PDO::PARAM_STR); + $sth->bindValue(':coop', $coop, PDO::PARAM_INT); + $sth->bindValue(':Alternates', "", PDO::PARAM_STR); + + // NOTE: these will be moved to own table, as a single game can have multiple devs/publishers + // it will also mean, we will be able to standardise devs/publishers names + // this will allow their selection from a menu as oppose to being provided by the user + $sth->bindValue(':Developer', htmlspecialchars($Developer), PDO::PARAM_STR); + $sth->bindValue(':Publisher', htmlspecialchars($Publisher), PDO::PARAM_STR); + + if($sth->execute()) + { + $game_id = $dbh->lastInsertId(); + $dbh->beginTransaction(); + $this->InsertUserEdits($user_id, $game_id, 'game', '[NEW]'); + + $GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; + foreach($GameArrayFields as $key) + { + $diff = htmlspecialchars($$key); + $this->InsertUserEdits($user_id, $game_id, $key, $diff); + } + $dbh->commit(); + } + } + return $game_id; + } +} ?> diff --git a/website/actions/add_game.php b/website/actions/add_game.php new file mode 100644 index 0000000..16769f3 --- /dev/null +++ b/website/actions/add_game.php @@ -0,0 +1,64 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + + +$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +foreach($GameArrayFields as $field) +{ + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + if(empty($_REQUEST[$field]) && ($field != 'Youtube' && $field != 'Overview' && $field != 'Publisher')) + { + returnJSONAndDie(-1, "field is empty: ($field)."); + } +} + +$date = explode('-', $_REQUEST['ReleaseDateRevised']); +if(!checkdate($date[1], $date[2], $date[0])) +{ + returnJSONAndDie(-1, "Invalid Date Format"); +} + + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->InsertGame($_user->GetUserID(), $_REQUEST['GameTitle'], $_REQUEST['Overview'], $_REQUEST['Youtube'], $_REQUEST['ReleaseDateRevised'], + $_REQUEST['Players'], $_REQUEST['coop'], $_REQUEST['Developer'], $_REQUEST['Publisher']); + + if($res) + { + returnJSONAndDie(1, $res); + } + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/delete_game.php b/website/actions/delete_game.php new file mode 100644 index 0000000..3f06f87 --- /dev/null +++ b/website/actions/delete_game.php @@ -0,0 +1,69 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('m_delete_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + +if(!isset($_REQUEST['game_id']) || !is_numeric($_REQUEST['game_id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + if(empty($API->GetGameByID($_REQUEST['game_id'], 0, 1))) + { + returnJSONAndDie(0, "No game in record to delete."); + } + + $covers = $API->GetGameBoxartByID($_REQUEST['game_id'], 0, 99, 'ALL'); + + if(!empty($covers) && ($covers = $covers[$_REQUEST['game_id']])) + { + $sizes = ["original", "small", "thumb", "cropped_center_thumb", "medium", "large"]; + foreach($covers as $cover) + { + foreach($sizes as $size) + { + $image_to_delete = __DIR__ . "/../../cdn/images/$size/" . $cover->filename; + if(file_exists($image_to_delete)) + { + unlink($image_to_delete); + } + } + } + } + + $API->DeleteAllGameImages($_user->GetUserID(), $_REQUEST['game_id']); + $res = $API->DeleteGame($_user->GetUserID(), $_REQUEST['game_id']); + + returnJSONAndDie(1, "success!!"); + + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/edit_game.php b/website/actions/edit_game.php new file mode 100644 index 0000000..7c052d0 --- /dev/null +++ b/website/actions/edit_game.php @@ -0,0 +1,66 @@ + $code, "msg" => $msg)); + die(); +} + +$_user = phpBBuser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(-1, ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} + + +$GameArrayFields = ['GameTitle', 'Overview', 'ReleaseDateRevised', 'Players', 'coop', 'Developer', 'Publisher', 'Youtube']; +if(!isset($_REQUEST['game_id']) || !is_numeric($_REQUEST['game_id'])) +{ + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR); +} +else +{ + foreach($GameArrayFields as $field) + { + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(-1, ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + } + + $date = explode('-', $_REQUEST['ReleaseDateRevised']); + if(!checkdate($date[1], $date[2], $date[0])) + { + returnJSONAndDie(-1, "Invalid Date Format"); + } +} + +require_once __DIR__ . "/../../include/TGDB.API.php"; + +try +{ + + $API = TGDB::getInstance(); + $res = $API->UpdateGame( $_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['GameTitle'], $_REQUEST['Overview'], $_REQUEST['Youtube'], $_REQUEST['ReleaseDateRevised'], + $_REQUEST['Players'], $_REQUEST['coop'], $_REQUEST['Developer'], $_REQUEST['Publisher']); + + if($res) + { + returnJSONAndDie(1, "success!!"); + } + +} +catch (Exception $e) +{ + error_log($e); +} +returnJSONAndDie(-1, "Unexpected Error has occured, Please try again!!"); diff --git a/website/actions/uploads.php b/website/actions/uploads.php new file mode 100644 index 0000000..be6228f --- /dev/null +++ b/website/actions/uploads.php @@ -0,0 +1,248 @@ +fromFile($original_image); + $type = ($type == 'jpg') ? 'jpeg' : $type; + $image->toFile($dest_image, "image/$type", 100); + return true; + } + catch(Exception $err) + { + error_log($err); + return false; + } + } +} + +function returnJSONAndDie($msg) +{ + global $tmp_image_out_path, $image_out_path; + if(isset($tmp_image_out_path) && file_exists($tmp_image_out_path)) + { + unlink($tmp_image_out_path); + } + if(isset($image_out_path) && file_exists($image_out_path)) + { + unlink($image_out_path); + } + echo json_encode(array("error" => $msg)); + die(); +} + +$_user = phpBBUser::getInstance(); +if(!$_user->isLoggedIn()) +{ + returnJSONAndDie(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + returnJSONAndDie(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + } +} +$Fields = ['game_id', 'type', 'subtype']; +{ + foreach($Fields as $field) + { + if(!isset($_REQUEST[$field])) + { + returnJSONAndDie(ErrorPage::$MSG_MISSING_PARAM_ERROR . ": ($field)."); + } + } + // TODO: move these hardcoded values to a table, but this will do for now + switch($_REQUEST['type']) + { + case 'boxart': + if($_REQUEST['subtype'] == 'front' || $_REQUEST['subtype'] == 'back') + { + break; + } + returnJSONAndDie("Invalid subtype selection: " . $_REQUEST['subtype']); + case 'fanart': + case 'series': + case 'screenshot': + case 'platform-banner': + case 'platform-fanart': + case 'platform-boxart': + case 'clearlogo': + if(empty($_REQUEST['subtype'])) + { + break; + } + returnJSONAndDie("Invalid subtype selection: " . $_REQUEST['subtype']); + default: + returnJSONAndDie("Invalid type selection: " . $_REQUEST['type']); + } +} + + +$uploader = new UploadHandler(); + +$uploader->allowedExtensions = array('jpe', 'jpg', 'jpeg', 'gif', 'png', 'bmp'); +$uploader->sizeLimit = 5 * 1024 *1024; + +$uploader->inputName = "qqfile"; + +function get_request_method() +{ + global $HTTP_RAW_POST_DATA; + + if(isset($HTTP_RAW_POST_DATA)) + { + parse_str($HTTP_RAW_POST_DATA, $_POST); + } + + if (isset($_POST["_method"]) && $_POST["_method"] != null) + { + return $_POST["_method"]; + } + + return $_SERVER["REQUEST_METHOD"]; +} + +if (get_request_method() == "POST") +{ + header("Content-Type: text/plain"); + + $tmp_path = __DIR__ . "/../../cdn/images/tmp/original/" . $_REQUEST['type']; + $path = __DIR__ . "/../../cdn/images/original/" . $_REQUEST['type']; + if(!empty($_REQUEST['subtype'])) + { + $tmp_path .= "/" . $_REQUEST['subtype']; + $path .= "/" . $_REQUEST['subtype']; + } + + $API = TGDB::getInstance(); + $covers = $API->GetGameBoxartByID($_REQUEST['game_id'], 0, 30, $_REQUEST['type']); + if(!empty($covers) && ($covers = $covers[$_REQUEST['game_id']]) && count($covers) > 5) + { + returnJSONAndDie("Max (5) allowed uploaded images has been reached."); + } + + if($_REQUEST['type'] == 'clearlogo') + { + $type = "png"; + } + else + { + $type = "jpg"; + if($_REQUEST['type'] == 'boxart') + { + // by forcing the name to "-1.$type", we'll always replace the cover with new upload + $image_name = $_REQUEST['game_id'] . "-1.$type"; + } + } + if(!isset($image_name)) + { + for($i = 1; $i < 6; ++$i) + { + $tmp_name = $_REQUEST['game_id'] . "-$i.$type"; + if(!file_exists($path . "/" . $tmp_name)) + { + $image_name = $tmp_name; + break; + } + } + if(!isset($image_name)) + { + die("Failed to find an image_name"); + } + } + + if(!file_exists($tmp_path)) + { + mkdir($tmp_path, 0755, true); + } + $result = $uploader->handleUpload($tmp_path, $image_name); + $result["uploadName"] = $uploader->getUploadName(); + + if(isset($result['success'])) + { + $tmp_image_out_path = $tmp_path . "/" . $image_name; + $image_out_path = $path . "/" . $image_name; + $result['final_out'] = $image_out_path; + if(save_image($tmp_image_out_path, $image_out_path, $type)) + { + if($_REQUEST['type'] == 'boxart') + { + if(!empty($covers)) + { + foreach($covers as $cover) + { + if($_REQUEST['subtype'] == $cover->side) + { + $sql_image_path = $cover->filename; + break; + } + } + if(isset($sql_image_path)) + { + $sizes = ["small", "thumb", "cropped_center_thumb", "medium", "large"]; + if(basename($sql_image_path) != $image_name) + { + array_push($sizes, 'original'); + } + foreach($sizes as $size) + { + $image_to_delete = __DIR__ . "/../../cdn/images/$size/" . $sql_image_path; + if(file_exists($image_to_delete)) + { + unlink($image_to_delete); + } + } + } + foreach($covers as $cover) + { + if($_REQUEST['subtype'] == $cover->side) + { + $res = $API->DeleteAndInsertGameImages($_user->GetUserID(), $cover->id, $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); + break; + } + } + } + else + { + $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $_REQUEST['subtype'] . "/" . $image_name, $_REQUEST['subtype']); + } + } + else + { + $res = $API->InsertGameImages($_user->GetUserID(), $_REQUEST['game_id'], $_REQUEST['type'], + $_REQUEST['type'] . "/" . $image_name); + } + + if(!isset($res) || !$res) + { + returnJSONAndDie("Failed to update database."); + } + } + else + { + returnJSONAndDie("Failed save image." . $image_out_path); + } + } + + echo json_encode($result); +} +else +{ + header("HTTP/1.0 405 Method Not Allowed"); +} \ No newline at end of file diff --git a/website/add_game.php b/website/add_game.php new file mode 100644 index 0000000..f4150b3 --- /dev/null +++ b/website/add_game.php @@ -0,0 +1,245 @@ +isLoggedIn()) +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); + $errorPage->print_die(); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + $errorPage->print_die(); + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + + +$API = TGDB::getInstance(); +$PlatformList = $API->GetPlatformsList(); + +$Header = new HEADER(); +$Header->setTitle("TGDB - Add Game"); +$Header->appendRawHeader(function() { ?> + + + + + + + + + + + + + + += $Header->print(); ?> + +
+ + diff --git a/website/edit_game.php b/website/edit_game.php new file mode 100644 index 0000000..d55c9c2 --- /dev/null +++ b/website/edit_game.php @@ -0,0 +1,599 @@ +SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_MISSING_PARAM_ERROR); + $errorPage->print_die(); +} +require_once __DIR__ . "/include/login.phpbb.class.php"; +$_user = phpBBUser::getInstance(); +if(!$_user->isLoggedIn()) +{ + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NOT_LOGGED_IN_EDIT_ERROR); + $errorPage->print_die(); +} +else +{ + if(!$_user->hasPermission('u_edit_games')) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_NO_PERMISSION_TO_EDIT_ERROR); + $errorPage->print_die(); + } +} + +require_once __DIR__ . "/include/header.footer.class.php"; +require_once __DIR__ . "/include/TGDBUtils.class.php"; +require_once __DIR__ . "/../include/TGDB.API.php"; +require_once __DIR__ . "/../include/CommonUtils.class.php"; + + +if(isset($_REQUEST['id']) && !empty($_REQUEST['id']) && is_numeric($_REQUEST['id'])) +{ + $options = array("ReleaseDateRevised" => true, "Overview" => true, "Players" => true, "Rating" => true, "ESRB" => true, "boxart" => true, "coop" => true, + "Genre" => true, "Publisher" => true, "Platform" => true, "Youtube" => true); + $API = TGDB::getInstance(); + $list = $API->GetGameByID($_REQUEST['id'], 0, 1, $options); + if(empty($list)) + { + $errorPage = new ErrorPage(); + $errorPage->SetHeader(ErrorPage::$HEADER_OOPS_ERROR); + $errorPage->SetMSG(ErrorPage::$MSG_REMOVED_GAME_INVALID_PARAM_ERROR); + $errorPage->print_die(); + } + else + { + $Game = array_shift($list); + $covers = $API->GetGameBoxartByID($_REQUEST['id'], 0, 9999, 'ALL'); + if(!empty($covers)) + { + $Game->boxart = $covers[$_REQUEST['id']]; + } + } + $Platform = $API->GetPlatforms($Game->Platform, array("icon" => true, "overview" => true, "developer" => true)); + if(isset($Platform[$Game->Platform])) + { + $Platform = $Platform[$Game->Platform]; + } +} + + +$fanarts = TGDBUtils::GetAllCovers($Game, 'fanart', ''); +$screenshots = TGDBUtils::GetAllCovers($Game, 'screenshot', ''); +$banners = TGDBUtils::GetAllCovers($Game, 'series', ''); +$is_graphics_empty = empty($fanarts) && empty($screenshots) && empty($banners); + +$box_cover = new \stdClass(); +$box_cover->front = TGDBUtils::GetAllCovers($Game, 'boxart', 'front'); +if(!empty($box_cover->front)) +{ + $box_cover->front = $box_cover->front[0]; +} +$box_cover->back = TGDBUtils::GetAllCovers($Game, 'boxart', 'back'); +if(!empty($box_cover->back)) +{ + $box_cover->back = $box_cover->back[0]; +} + +$Header = new HEADER(); +$Header->setTitle("TGDB - Browse - Game - $Game->GameTitle"); +$Header->appendRawHeader(function() { global $Game, $_user; ?> + + + + " /> + + + + + + + + + + + + + + + + + + + + + + + + + += $Header->print(); ?> + + + + diff --git a/website/game.php b/website/game.php index 1e49091..e5f8007 100755 --- a/website/game.php +++ b/website/game.php @@ -154,36 +154,35 @@ - back)): ?> + back)): ?> - + back)): ?> - + - -Platform: = $Platform->name; ?>
- +Developer: = $Game->Developer; ?>
Publisher)) : ?>Publisher: = $Game->Publisher; ?>
- ReleaseDate)) : ?> -ReleaseDate: = $Game->ReleaseDate ;?>
+ ReleaseDateRevised)) : ?> +ReleaseDateRevised: = $Game->ReleaseDateRevised ;?>
PlatformDetails)) : ?>Platform: = $Game->PlatformDetails->name; ?>
Players)) : ?> @@ -250,21 +249,6 @@getJSON()); ?>-
= $msg ?>
+ += $msg ?>
+ +