new_team.php 6.6 KB

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