new_team.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. function action($db = null){
  3. global $AREA_TYPE;
  4. global $DIFFICULTY;
  5. global $SCENARIO;
  6. global $DUNGEON;
  7. global $ELEMENTAL_RIFT_DUNGEON;
  8. global $LABYRINTH_STAGES;
  9. global $UID;
  10. //$player = SQLite3::escapeString($_POST["uid"]);
  11. $player = filter_input(INPUT_POST, 'uid');
  12. $area_type = filter_input(INPUT_POST, 'area_type');
  13. $area = filter_input(INPUT_POST, 'area');
  14. $stage = filter_input(INPUT_POST, 'stage');
  15. $difficulty = filter_input(INPUT_POST, 'difficulty');
  16. $ids = filter_input(INPUT_POST, 'ids');
  17. $name = filter_input(INPUT_POST, 'name');
  18. $description = filter_input(INPUT_POST, 'description');
  19. $id = preg_split("/[\s,]+/", $ids);
  20. $id_count = sizeof($id);
  21. if ($name == null || strlen($name) == 0){
  22. return -1;
  23. }
  24. switch ($area_type){
  25. case $AREA_TYPE["SCENARIO"]:
  26. if ($stage < 0 || $stage > 7){
  27. return -31;
  28. }
  29. if (!($difficulty == 0 || in_array($difficulty, $DIFFICULTY) || $difficulty == $DIFFICULTY["EASY"])){
  30. return -32;
  31. }
  32. if ($id_count < 1 || $id_count > 4){
  33. return -33;
  34. }
  35. if (!in_array($area, $SCENARIO)){
  36. return -34;
  37. }
  38. break;
  39. case $AREA_TYPE["CAIROS_DUNGEON"]:
  40. if ($stage < 0 || $stage > 10){
  41. return -35;
  42. }
  43. $difficulty = null;
  44. if ($id_count < 1 || $id_count > 5){
  45. return -36;
  46. }
  47. if (!in_array($area, $DUNGEON)){
  48. return -37;
  49. }
  50. break;
  51. case $AREA_TYPE["RIFT_DUNGEON"]:
  52. $stage = null;
  53. $difficulty = null;
  54. if ($id_count < 1 || $id_count > 6){
  55. return -39;
  56. }
  57. if (!in_array($area, $ELEMENTAL_RIFT_DUNGEON)){
  58. return -40;
  59. }
  60. break;
  61. case $AREA_TYPE["RIFT_RAID"]:
  62. if ($stage < 0 || $stage > 5){
  63. return -41;
  64. }
  65. $difficulty = null;
  66. if ($id_count < 1 || $id_count > 6){
  67. return -42;
  68. }
  69. $area = null;
  70. break;
  71. case $AREA_TYPE["ARENA"]:
  72. $area = null;
  73. $stage = null;
  74. $difficulty = null;
  75. break;
  76. case $AREA_TYPE["GUILD_WAR"]:
  77. $area = null;
  78. $stage = null;
  79. $difficulty = null;
  80. break;
  81. case $AREA_TYPE["GUILD_SIEGE"]:
  82. $area = null;
  83. $stage = null;
  84. $difficulty = null;
  85. break;
  86. case $AREA_TYPE["TARTARUS_LABYRINTH"]:
  87. $stage = null;
  88. if ($difficulty < 0 || !in_array($difficulty, $DIFFICULTY)){
  89. return -43;
  90. }
  91. if ($id_count < 1 || $id_count > 5){
  92. return -44;
  93. }
  94. if (!in_array($area, $LABYRINTH_STAGES)){
  95. return -45;
  96. }
  97. break;
  98. case $AREA_TYPE["TRIAL_OF_ASCENSION"]:
  99. if ($difficulty != 0 && $difficulty != $DIFFICULTY["NORMAL"] && $difficulty != $DIFFICULTY["HARD"]){
  100. return -46;
  101. }
  102. $stage = null;
  103. if ($id_count < 1 || $id_count > 5){
  104. return -47;
  105. }
  106. $area = null;
  107. break;
  108. case $AREA_TYPE["DIMENSIONAL_HOLE"]:
  109. if ($stage < 0 || $stage > 5){
  110. return -48;
  111. }
  112. $difficulty = null;
  113. if ($id_count < 1 || $id_count > 4){
  114. return -49;
  115. }
  116. if (!in_array($area, $DUNGEON)){
  117. return -50;
  118. }
  119. break;
  120. case $AREA_TYPE["DIMENSIONAL_RIFT"]:
  121. if ($difficulty != 0 && $difficulty != $DIFFICULTY["NORMAL"] && $difficulty != $DIFFICULTY["HARD"]){
  122. return -51;
  123. }
  124. $stage = null;
  125. if ($id_count < 1 || $id_count > 5){
  126. return -52;
  127. }
  128. $area = null;
  129. break;
  130. default:
  131. return -3;
  132. }
  133. $unique_id = array_unique($id);
  134. if ($id_count != sizeof($unique_id)){
  135. return -4;
  136. }
  137. $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
  138. $q = $db->query($s);
  139. $r = $q->fetchArray(SQLITE3_ASSOC);
  140. $team_id = $r["id"];
  141. $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);');
  142. $statement->bindValue(':uid', $player);
  143. $statement->bindValue(':id', $team_id);
  144. $statement->bindValue(':name', $name);
  145. $statement->bindValue(':description', $description);
  146. $statement->bindValue(':area_type', $area_type);
  147. $statement->bindValue(':area', $area);
  148. $statement->bindValue(':stage', $stage);
  149. $statement->bindValue(':difficulty', $difficulty);
  150. $res = $statement->execute();
  151. if (!$res){
  152. return -5;
  153. }
  154. foreach ($id as $i){
  155. $s = "INSERT INTO team_unit VALUES ($team_id, $i);";
  156. $db->query($s);
  157. }
  158. return 0;
  159. }
  160. ?>