change_game_mode.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * File for the team score modification.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @category Action
  8. */
  9. /**
  10. * Sets the score for a team.
  11. *
  12. * Reads the POST parameters looking for the following KEYS:
  13. * uid
  14. * team
  15. * score
  16. * Validates the data and sets the score.
  17. *
  18. * @return int 0 on success, negative values on error.
  19. * @category Action
  20. * @global resource Database connection.
  21. */
  22. function action(){
  23. global $db;
  24. $player = filter_input(INPUT_GET, "uid");
  25. $mode = filter_input(INPUT_GET, "mode");
  26. if (mode != GAME_MODE_ID::NORMAL && mode != GAME_MODE_ID::RTA){
  27. return 400;
  28. }
  29. $statement = $db->prepare("
  30. UPDATE player
  31. SET mode = :mode
  32. WHERE uid = :uid;
  33. ");
  34. $statement->bindValue(":mode", $mode, SQLITE3_TEXT);
  35. $statement->bindValue(":uid", $player, SQLITE3_TEXT);
  36. $statement->execute();
  37. header("HTTP/1.1 201 OK");
  38. die();
  39. return 201;
  40. }
  41. ?>