From 359500db9bf89415e643dcd2b97cf7e404044574 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 23 Feb 2016 00:28:25 -0800 Subject: [PATCH] Create view from edit; cleanup edit --- wizzardRedux/admin/edit.php | 4 +- wizzardRedux/pages/view.php | 270 +++++++++++++++++++++++++++++++++++- 2 files changed, 268 insertions(+), 6 deletions(-) diff --git a/wizzardRedux/admin/edit.php b/wizzardRedux/admin/edit.php index 2ee0117..560cf97 100644 --- a/wizzardRedux/admin/edit.php +++ b/wizzardRedux/admin/edit.php @@ -2,6 +2,8 @@ /* ------------------------------------------------------------------------------------ Add, edit, and remove data from the database manually. + +TODO: Add search functionality ------------------------------------------------------------------------------------ */ // All possible $_GET variables that we can use (propogate this to other files?) @@ -513,7 +515,7 @@ elseif ($file != "") $result = mysqli_query($link, $query); $rom = mysqli_fetch_assoc($result); - // Now output the editable information (add form around this) + // Now output the editable information echo "
diff --git a/wizzardRedux/pages/view.php b/wizzardRedux/pages/view.php index c67d23d..e47bde1 100644 --- a/wizzardRedux/pages/view.php +++ b/wizzardRedux/pages/view.php @@ -1,10 +1,270 @@ "; + exit; + } + $roms = mysqli_fetch_all($result); + $game_info = $roms[1]; + + echo "

View the Game Information Below

+ +
+ + + + + + + + + + + + +
System".$game_info[0]." - ".$game_info[1]."
Source".$game_info[3]."
Name'".$game_info[5]."

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

"; + + 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 != "") + { + $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 != "") + { + $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 != "" ? "sources.id=".$source : ""). + ($source != "" && $system != "" ? " AND " : ""). + ($system != "" ? "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 != "" ? "sources.id=".$source : ""). + ($source != "" && $system != "" ? " AND " : ""). + ($system != "" ? "systems.id=".$system : ""). + " ORDER BY games.name ASC + LIMIT 50 OFFSET ".($offset == "" ? "0" : ($offset*5)."0"); + $games_result = mysqli_query($link, $query); + + echo "

Games With This ". + ($source != "" ? "Source" : ""). + ($source != "" && $system != "" ? " And " : ""). + ($system != "" ? "System" : "")."

\n"; + if (gettype($games_result) != "boolean") + { + while ($game = mysqli_fetch_assoc($games_result)) + { + echo "".$game["name"]; + if ($source != "" && !$system != "") + { + echo " (".$game["manufacturer"]." - ".$game["system"].")"; + } + if (!$source != "" && $system != "") + { + 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

+ +
+ +

\n"; +} ?> \ No newline at end of file