if (!isset($_GET["cmd"])) { echo "Please specify command!"; return; } $cmd = $_GET["cmd"]; if ($cmd == "generate") { generateGraph(); } else { if ($cmd == "solve") { solveGraph(); } else { if ($cmd == "submit") { submitGraph(); } else { if ($cmd == "highscore") { getHighscore(); } else { echo "Sorry, command is not supported!"; return; } } } } function generateGraph() { if ((!isset($_GET["N"]) || !isset($_GET["M"])) && !isset($_GET["graph_id"])) { echo "Set N(left) and M(right) please. Or specify a graph_id."; return; } if (isset($_GET["graph_id"])) { $graphId = $_GET["graph_id"];
case 'add': if (isset($_POST['name']) || isset($_POST['score']) || isset($_POST['level'])) { echo addHighscore($_POST['name'], $_POST['score'], $_POST['level']); } break; case 'reset': echo resetHighscore(); break; } } else { if (isset($_GET['action'])) { if ($_GET['action'] == 'get') { if (isset($_GET['page'])) { echo getHighscore($_GET['page']); } else { echo getHighscore(); } } } else { echo "define action to call"; } } function getHighscore($page = 1) { $db = new SQLite3('pacman.db'); createDataBase($db); $results = $db->query('SELECT name, score FROM highscore WHERE cheater = 0 AND name != "" ORDER BY score DESC LIMIT 10 OFFSET ' . ($page - 1) * 10); while ($row = $results->fetchArray()) { $tmp["name"] = htmlspecialchars($row['name']); $tmp["score"] = strval($row['score']); $response[] = $tmp;