"; $query = "UPDATE games SET system=0 WHERE system=".$system; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "Files altered successfully! No further action required.
"; } else { echo "Something has gone wrong, please manually alter all files with system '".$system."' to have value 0
"; } } else { echo "System could not be deleted. Try again later.
"; } } // If a source is being removed (can't remove default) elseif ($remove == "source" && $source != "" && $source != "0") { $query = "DELETE FROM source where id=".$system; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "Source deleted successfully! Altering all related files.
"; $query = "UPDATE games SET source=0 WHERE source=".$source; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "Files altered successfully! No further action required.
"; } else { echo "Something has gone wrong, please manually alter all files with source '".$source."' to have value 0
"; } } else { echo "System could not be deleted. Try again later.
"; } } // If a game is being removed elseif ($remove == "game" && $game != "") { $query = "DELETE FROM games JOIN files ON games.id=files.setid JOIN checksums ON files.id=checksums.file WHERE games.id=".$game; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "Game and dependent files deleted successfully!
"; } else { echo "Could not delete game or dependent files. Please try again
";; } } // If a file is being removed elseif ($remove == "file" && $file != "") { $query = "DELETE FROM files JOIN checksums ON files.id=checksums.file WHERE files.id=".$file; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "File deleted successfully!
"; } else { echo "Could not delete file. Please try again
";; } } } // Handle the POST cases. They do not have to be mutually exclusive else { // If a system is being edited or added via POST if ($system != "" && $manufacturer != "" && $systemname != "") { // If the system is new and being added if ($system == "-1") { // Always check if this exact combination is already there. This might have been in error $query = "SELECT * FROM systems WHERE manufacturer='".$manufacturer." AND system='".$systemname."'"; $result = mysqli_query($link, $query); // If we find this system, tell the user and don't move forward if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This system has been found. No further action is required
"; } // If the system is not found, add it else { $query = "INSERT INTO systems (manufacturer, system) VALUES ('".$manufacturer."', '".$systemname."')"; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The system '".$manufacturer." - ".$systemname."' has been added successfully!
"; } else { echo "The system '".$manufacturer." - ".$systemname."' could not be added, try again later
"; } } } // If the system is being edited else { // Check if the system exists first $query = "SELECT * FROM systems WHERE id=".$system; $result = mysqli_query($link, $query); // If we don't find the system, don't add it. This might have been in error if (gettype($result) == "boolean" && !$result) { echo "The system with id '".$system."' could not be found, try again later
"; } // If we find the system, update with the new information, if not a duplicate of another else { $query = "SELECT * FROM systems WHERE manufacturer='".$manufacturer." AND system='".$systemname."'"; $result = mysqli_query($link, $query); // If the system is found or unchanged, don't readd it if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This system has been found. No further action is required
"; } // If the system really has changed or is not a duplicate, add it else { $query = "UPDATE systems SET manufacturer='".$manufacturer."', system='".$systemname."' WHERE id=".$system; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The system '".$manufacturer." - ".$systemname."' has been updated successfully!
"; } else { echo "The system '".$manufacturer." - ".$systemname."' could not be updated, try again later
"; } } } } } // If a source is being edited or added via POST if ($source != "" && $sourcename != "" && $url != "") { // If the source is new and being added if ($source == "-1") { // Always check if this exact combination is already there. This might have been in error $query = "SELECT * FROM sources WHERE name='".$sourcename."'"; $result = mysqli_query($link, $query); // If we find this source, tell the user and don't move forward if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This source has been found. No further action is required
"; } // If the source is not found, add it else { $query = "INSERT INTO sources (name, url) VALUES ('".$sourcename."', '".$url."')"; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The source '".$sourcename."' has been added successfully!
"; } else { echo "The source '".$sourcename."' could not be added, try again later
"; } } } // If the source is being edited else { // Check if the source exists first $query = "SELECT * FROM sources WHERE id=".$system; $result = mysqli_query($link, $query); // If we don't find the source, don't add it. This might have been in error if (gettype($result) == "boolean" && !$result) { echo "The source with id '".$source."' could not be found, try again later
"; } // If we find the source, update with the new information, if not a duplicate of another else { $query = "SELECT * FROM sources WHERE name='".$sourcename."'"; $result = mysqli_query($link, $query); // If the source is found or unchanged, don't readd it if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This source has been found. No further action is required
"; } // If the source really has changed or is not a duplicate, add it else { $query = "UPDATE sources SET name='".$sourcename."', url='".$url."' WHERE id=".$source; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The source '".$sourcename."' has been updated successfully!
"; } else { echo "The source '".$sourcename."' could not be updated, try again later
"; } } } } } // If a game is being edited or added via POST if ($game != "" && $gamename != "" && $system != "" && $source != "") { // If the game is new and being added if ($game == "-1") { // Always check if this exact combination is already there. This might have been in error $query = "SELECT * FROM games WHERE name='".$gamename."' AND system=".$system." AND source=".$source; $result = mysqli_query($link, $query); // If we find this game, tell the user and don't move forward if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This game has been found. No further action is required
"; } // If the game is not found, add it else { $query = "INSERT INTO games (name, system, source) VALUES ('".$gamename."', ".$system.", ".$source.")"; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The game '".$gamename."' has been added successfully!
"; } else { echo "The game '".$gamename."' could not be added, try again later
"; } } } // If the game is being edited else { // Check if the game exists first $query = "SELECT * FROM games WHERE id=".$game; $result = mysqli_query($link, $query); // If we don't find the game, don't add it. This might have been in error if (gettype($result) == "boolean" && !$result) { echo "The game with id '".$game."' could not be found, try again later
"; } // If we find the game, update with the new information, if not a duplicate of another else { $query = "SELECT * FROM games WHERE name='".$gamename."' AND system=".$system." AND source=".$source; $result = mysqli_query($link, $query); // If the game is found elsewhere or unchanged, don't readd it if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This source has been found. No further action is required
"; } // If the game really has changed or is not a duplicate, add it else { $query = "UPDATE game SET name='".$gamename."', system=".$system.", source=".$source." WHERE id=".$game; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The game '".$gamename."' has been updated successfully!
"; } else { echo "The game '".$gamename."' could not be updated, try again later
"; } } } } } // If a file is being edited or added via POST if ($file != "" && $filename != "" && $game != "" && $type != "" && (($type == "rom" && $size != "" && ($crc != "" || $md5 != "" || $sha1 != "")) || ($type == "disk" && ($md5 != "" || $sha1 != "")))) { // If the file is new and being added if ($file == "-1") { // Always check if this exact combination is already there. This might have been in error $query = "SELECT * FROM files JOIN checksums ON files.id=checksums.file WHERE files.name='".$filename. "' AND files.setid=".$game. " AND files.type='".$type. "' AND checksums.size=".$size. "' AND checksums.crc='".$crc. "' AND checksums.md5='".$md5. "' AND checksums.sha1='".$sha1; $result = mysqli_query($link, $query); // If we find this file, tell the user and don't move forward if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This file has been found. No further action is required
"; } // If the file is not found, add it else { $query = "INSERT INTO files (name, game, type) VALUES ('".$filename."', ".$game.", ".$type.")"; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The file '".$filename."' has been added successfully! Adding checksums.
"; $file = mysqli_insert_id($link); $query = "INSERT INTO checksums (game, size, crc, md5, sha1) VALUES (".$game.", ".$size.", '".$crc."', '".$md5."', '".$sha1."')"; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The checksums have been added!
"; } else { echo "The checksums could not be added, please try again later
"; } } else { echo "The file '".$filename."' could not be added, try again later
"; } } } // If the file is being edited else { // Check if the file exists first $query = "SELECT * FROM files WHERE id=".$file; $result = mysqli_query($link, $query); // If we don't find the file, don't add it. This might have been in error if (gettype($result) == "boolean" && !$result) { echo "The game with id '".$file."' could not be found, try again later
"; } // If we find the file, update with the new information, if not a duplicate of another else { $query = "SELECT * FROM files JOIN checksums ON files.id=checksums.file WHERE files.name='".$filename. "' AND files.setid=".$game. " AND files.type='".$type. "' AND checksums.size=".$size. "' AND checksums.crc='".$crc. "' AND checksums.md5='".$md5. "' AND checksums.sha1='".$sha1; $result = mysqli_query($link, $query); // If the file is found elsewhere or unchanged, don't readd it if (gettype($result) != "boolean" && mysqli_num_rows($result) > 0) { echo "This file has been found. No further action is required
"; } // If the source really has changed or is not a duplicate, add it else { $query = "UPDATE file JOIN checksums ON files.id=checksums.file SET files.name='".$filename. "' AND files.setid=".$game. " AND files.type='".$type. "' AND checksums.size=".$size. "' AND checksums.crc='".$crc. "' AND checksums.md5='".$md5. "' AND checksums.sha1='".$sha1; $result = mysqli_query($link, $query); if (gettype($result) == "boolean" && $result) { echo "The file '".$filename."' has been updated successfully!
"; } else { echo "The file '".$filename."' could not be updated, try again later
"; } } } } } } // Assuming there are no relevent params (or processing POST is done), show the basic page if ($system == "" && $source == "" && $game == "" && $file == "") { show_default($link); } // First and foremost, capture file edit mode. It's exclusive above all others. elseif ($file != "") { // Retrieve the file info $query = "SELECT files.id AS file, files.name AS name, files.type AS type, checksums.size AS size, checksums.crc AS crc, checksums.md5 AS md5, checksums.sha1 AS sha1 FROM files JOIN checksums ON files.id=checksums.file WHERE files.id=".$file; $result = mysqli_query($link, $query); $rom = mysqli_fetch_assoc($result); // Now output the editable information echo "
Name
Type
Size
CRC
MD5
SHA-1

"; } // Then capture game edit mode, it also takes precidence over the others. elseif ($game != "") { // Retrieve the system listing $query = "SELECT id, manufacturer, system FROM systems ORDER BY manufacturer ASC, system ASC"; $result = mysqli_query($link, $query); $systems = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($systems, $row); } // Retrieve the sources listing $query = "SELECT id, name FROM sources ORDER BY name ASC"; $result = mysqli_query($link, $query); $sources = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($sources, $row); } // Get the total count in the case that it needs limiting $query = "SELECT COUNT(*) as count FROM systems JOIN games ON systems.id=games.system JOIN sources ON games.source=sources.id JOIN files ON games.id=files.setid JOIN checksums ON files.id=checksums.file WHERE games.id=".$game; $count = mysqli_query($link, $query); $count = mysqli_fetch_assoc($count); $count = $count["count"]; settype($count, "integer"); // Retrieve the game info $query = "SELECT systems.manufacturer AS manufacturer, systems.system AS system, systems.id AS systemid, sources.name AS source, sources.id AS sourceid, games.name AS game, files.id AS file, files.name AS name, files.type AS type, checksums.size AS size, checksums.crc AS crc, checksums.md5 AS md5, checksums.sha1 AS sha1 FROM systems JOIN games ON systems.id=games.system JOIN sources ON games.source=sources.id JOIN files ON games.id=files.setid JOIN checksums ON files.id=checksums.file WHERE games.id=".$game. " LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0"); $result = mysqli_query($link, $query); if (gettype($result) == "boolean" || mysqli_num_rows($result) == 0) { echo "No game info could be retrieved! There might be an error.
"; exit; } $roms = mysqli_fetch_all($result); $game_info = $roms[0]; echo "

Edit the Game Information Below

System
Source
Name

"; foreach ($roms as $rom) { echo ""; for ($i = 7; $i < 13; $i++) { echo ""; } echo "\n"; } echo "
NameTypeSizeCRCMD5SHA-1
".$rom[$i]."
". "\n

"; echo "
"; if ($offset != "" && $offset > 0) { echo "Last 50 "; } if ($count > (mysqli_num_rows($result) + ($offset == "" ? 0 : $offset*50))) { echo "Next 50"; } echo "
"; echo "Back to previous page
\n"; } else { // Retrieve source info only so it's not duplicated if ($source_set) { $query = "SELECT name, url FROM sources WHERE id='".$source."'"; $source_result = mysqli_query($link, $query); $source_info = mysqli_fetch_assoc($source_result); } // Retrieve system info only so it's not duplicated if ($system_set) { $query = "SELECT manufacturer, system FROM systems WHERE id='".$system."'"; $system_result = mysqli_query($link, $query); $system_info = mysqli_fetch_assoc($system_result); } // Get the total count in the case that it needs limiting $query = "SELECT COUNT(*) as count FROM systems JOIN games ON systems.id=games.system JOIN sources ON games.source=sources.id WHERE ". ($source_set ? "sources.id=".$source : ""). ($source_set && $system_set ? " AND " : ""). ($system_set ? "systems.id=".$system : ""); $count = mysqli_query($link, $query); $count = mysqli_fetch_assoc($count); $count = $count["count"]; settype($count, "integer"); // Then get all games assocated $query = "SELECT games.name AS name, games.id AS id, systems.manufacturer AS manufacturer, systems.system AS system, sources.name AS source FROM systems JOIN games ON systems.id=games.system JOIN sources ON games.source=sources.id WHERE ". ($source_set ? "sources.id=".$source : ""). ($source_set && $system_set ? " AND " : ""). ($system_set ? "systems.id=".$system : ""). " ORDER BY games.name ASC LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0"); $games_result = mysqli_query($link, $query); echo "
\n"; if ($source_set) { echo "\n". "Source: \n". "URL(s):
\n"; } if ($system_set) { echo "\n". "Manufacturer: \n". "Name:
\n"; } echo "\n

\n"; echo "

Games With This ". ($source_set ? "Source" : ""). ($source_set && $system_set ? " And " : ""). ($system_set ? "System" : "")."

\n"; if (gettype($games_result) != "boolean") { while ($game = mysqli_fetch_assoc($games_result)) { echo "".$game["name"]; if ($source_set && !$system_set) { echo " (".$game["manufacturer"]." - ".$game["system"].")"; } if (!$source_set && $system_set) { echo " (".$game["source"].")"; } echo "
\n"; } echo "
"; if ($offset != "" && $offset > 0) { echo "Last 50 "; } if ($count > (mysqli_num_rows($games_result) + ($offset == "" ? 0 : $offset*50))) { echo "Next 50"; } echo "
"; } else { echo "No games could be found!"; } echo "
"; } // Requires the mysqli link function show_default($link) { // Retrieve the system listing $query = "SELECT id, manufacturer, system FROM systems ORDER BY manufacturer ASC, system ASC"; $result = mysqli_query($link, $query); $systems = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($systems, $row); } // Retrieve the sources listing $query = "SELECT id, name FROM sources ORDER BY name ASC"; $result = mysqli_query($link, $query); $sources = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($sources, $row); } // Output the input selection form echo <<

Select a System or Source


Or Add a New One

Source Add

Name: URL(s):

System Add

Manufacturer: Name:

\n


\n"; } ?>