new_team.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * File for the team creation action.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @category Action
  8. */
  9. /**
  10. * Logs the user out and redirects to the login page.
  11. *
  12. * Reads the POST parameters looking for the following KEYS:
  13. * uid
  14. * area_type
  15. * area
  16. * stage
  17. * difficulty
  18. * ids
  19. * name
  20. * description
  21. * Validates the data and creates the team in the database.
  22. *
  23. * @param resource $db Database connection.
  24. * @return int 0 on success, negative values on error.
  25. * @category Action
  26. * @global int[] Area types.
  27. * @global int[] Difficulty levels.
  28. * @global int[] Scenario areas.
  29. * @global int[] Dungeon sections.
  30. * @global int[] Elemental rift dungeons.
  31. * @global int[] Labyrinth stage types.
  32. */
  33. function action($db = null){
  34. $player = filter_input(INPUT_POST, 'uid');
  35. $area_type = filter_input(INPUT_POST, 'area_type');
  36. $area = filter_input(INPUT_POST, 'area');
  37. $stage = filter_input(INPUT_POST, 'stage');
  38. $difficulty = filter_input(INPUT_POST, 'difficulty');
  39. $ids = filter_input(INPUT_POST, 'ids');
  40. $name = filter_input(INPUT_POST, 'name');
  41. $description = filter_input(INPUT_POST, 'description');
  42. $id = preg_split("/[\s,]+/", $ids);
  43. $id_count = sizeof($id);
  44. if ($name == null || strlen($name) == 0){
  45. return -1;
  46. }
  47. switch ($area_type){
  48. case AREA_TYPE::SCENARIO:
  49. if ($stage < 0 || $stage > 7){
  50. return -31;
  51. }
  52. if (!($difficulty == 0 || property_exists(DIFFICULTY_ID, $difficulty) || $difficulty == DIFFICULTY::EASY)){
  53. return -32;
  54. }
  55. if ($id_count < 1 || $id_count > 4){
  56. return -33;
  57. }
  58. if (!property_exists(SCENARIO_ID, $area)){
  59. return -34;
  60. }
  61. break;
  62. case AREA_TYPE::CAIROS_DUNGEON:
  63. if ($stage < 0 || $stage > 10){
  64. return -35;
  65. }
  66. $difficulty = null;
  67. if ($id_count < 1 || $id_count > 5){
  68. return -36;
  69. }
  70. if (!property_exists(DUNGEON_ID, $area)){
  71. return -37;
  72. }
  73. break;
  74. case AREA_TYPE::RIFT_DUNGEON:
  75. $stage = null;
  76. $difficulty = null;
  77. if ($id_count < 1 || $id_count > 6){
  78. return -39;
  79. }
  80. if (!property_exists(ELEMENTAL_RIFT_DUNGEON_ID, $area)){
  81. return -40;
  82. }
  83. break;
  84. case AREA_TYPE::RIFT_RAID:
  85. if ($stage < 0 || $stage > 5){
  86. return -41;
  87. }
  88. $difficulty = null;
  89. if ($id_count < 1 || $id_count > 6){
  90. return -42;
  91. }
  92. $area = null;
  93. break;
  94. case AREA_TYPE::ARENA:
  95. $area = null;
  96. $stage = null;
  97. $difficulty = null;
  98. break;
  99. case AREA_TYPE::GUILD_WAR:
  100. $area = null;
  101. $stage = null;
  102. $difficulty = null;
  103. break;
  104. case AREA_TYPE::GUILD_SIEGE:
  105. $area = null;
  106. $stage = null;
  107. $difficulty = null;
  108. break;
  109. case AREA_TYPE::TARTARUS_LABYRINTH:
  110. $stage = null;
  111. if ($difficulty < 0 || !property_exists(DIFFICULTY_ID, $difficulty)){
  112. return -43;
  113. }
  114. if ($id_count < 1 || $id_count > 5){
  115. return -44;
  116. }
  117. if (!property_exists(LABYRINTH_STAGES_ID, $area)){
  118. return -45;
  119. }
  120. break;
  121. case AREA_TYPE::TRIAL_OF_ASCENSION:
  122. if ($difficulty != 0 && $difficulty != DIFFICULTY::NORMAL && $difficulty != DIFFICULTY::HARD){
  123. return -46;
  124. }
  125. $stage = null;
  126. if ($id_count < 1 || $id_count > 5){
  127. return -47;
  128. }
  129. $area = null;
  130. break;
  131. case AREA_TYPE::DIMENSIONAL_HOLE:
  132. if ($stage < 0 || $stage > 5){
  133. return -48;
  134. }
  135. $difficulty = null;
  136. if ($id_count < 1 || $id_count > 4){
  137. return -49;
  138. }
  139. if (!property_exists(DUNGEON_ID, $area)){
  140. return -50;
  141. }
  142. break;
  143. case AREA_TYPE::DIMENSIONAL_RIFT:
  144. if ($difficulty != 0 && $difficulty != DIFFICULTY::NORMAL && $difficulty != DIFFICULTY::HARD){
  145. return -51;
  146. }
  147. $stage = null;
  148. if ($id_count < 1 || $id_count > 5){
  149. return -52;
  150. }
  151. $area = null;
  152. break;
  153. default:
  154. return -3;
  155. }
  156. $unique_id = array_unique($id);
  157. if ($id_count != sizeof($unique_id)){
  158. return -4;
  159. }
  160. $s = "SELECT CASE WHEN MAX(id) IS NULL THEN 1 ELSE MAX(id) + 1 END AS id FROM team;";
  161. $q = $db->query($s);
  162. $r = $q->fetchArray(SQLITE3_ASSOC);
  163. $team_id = $r["id"];
  164. $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);');
  165. $statement->bindValue(':uid', $player);
  166. $statement->bindValue(':id', $team_id);
  167. $statement->bindValue(':name', $name);
  168. $statement->bindValue(':description', $description);
  169. $statement->bindValue(':area_type', $area_type);
  170. $statement->bindValue(':area', $area);
  171. $statement->bindValue(':stage', $stage);
  172. $statement->bindValue(':difficulty', $difficulty);
  173. $res = $statement->execute();
  174. if (!$res){
  175. return -5;
  176. }
  177. foreach ($id as $i){
  178. $s = "INSERT INTO team_unit VALUES ($team_id, $i);";
  179. $db->query($s);
  180. }
  181. return 0;
  182. }
  183. ?>