save_run_team.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. function action($db = null){
  3. $player = filter_input(INPUT_POST, 'uid');
  4. $run = filter_input(INPUT_POST, 'run');
  5. $name = filter_input(INPUT_POST, 'name');
  6. $description = filter_input(INPUT_POST, 'description');
  7. if ($name == null || strlen($name) == 0){
  8. return -1;
  9. }
  10. $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
  11. $q = $db->query($s);
  12. $r = $q->fetchArray(SQLITE3_ASSOC);
  13. $team_id = $r["id"];
  14. $s = "SELECT run.area AS area, run.stage AS stage, run.difficulty AS difficulty, k_area.type AS area_type FROM run, k_area WHERE run.uid = '$player' AND run.id = '$run' AND k_area.id = run.area AND run.helper = 0;";
  15. $q = $db->query($s);
  16. $r = $q->fetchArray(SQLITE3_ASSOC);
  17. if (!$r){
  18. return -2;
  19. }
  20. $statement = $db->prepare('INSERT INTO team (uid, id, name, description, area_type, area, stage, difficulty) VALUES (:uid, :id, :name, :description, :area_type, :area, :stage, :difficulty);');
  21. $statement->bindValue(':uid', $player);
  22. $statement->bindValue(':id', $team_id);
  23. $statement->bindValue(':name', $name);
  24. $statement->bindValue(':description', $description);
  25. $statement->bindValue(':area_type', $r["area_type"]);
  26. $statement->bindValue(':area', $r["area"]);
  27. $statement->bindValue(':stage', $r["stage"]);
  28. $statement->bindValue(':difficulty', $r["difficulty"]);
  29. $res = $statement->execute();
  30. if (!$res){
  31. return -3;
  32. }
  33. $s = "SELECT unit FROM run_party WHERE run = $run AND unit IS NOT NULL;";
  34. $q = $db->query($s);
  35. while ($r = $q->fetchArray(SQLITE3_ASSOC)){
  36. $s = "INSERT INTO team_unit VALUES ('$team_id', '" . $r["unit"] . "');";
  37. $db->query($s);
  38. }
  39. return 0;
  40. }
  41. ?>