teams.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. <?php
  2. /**
  3. * Teams view.
  4. *
  5. * Contains the view layout and ome code to present the data.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. * @category View
  11. * @property Teams_Page $page The page model.
  12. * @var Teams_Page $page The page model.
  13. */
  14. ?>
  15. <!DOCTYPE html>
  16. <html lang='en'>
  17. <head>
  18. <?=$page->generate_head()?>
  19. <script>
  20. units = [];
  21. max_units = 0;
  22. selected_units = 0;
  23. selected_ids = [];
  24. current_slot_id = "";
  25. leader_id = "";
  26. <?php
  27. foreach ($page->get_units() as $unit){
  28. ?>
  29. units.push(
  30. {
  31. id: <?=$unit->get_id()?>,
  32. name: "<?=$unit->get_title()?>",
  33. stars: <?=$unit->get_stars()?>,
  34. level: <?=$unit->get_level()?>,
  35. image: '<?=$unit->get_monster()->get_image()?>',
  36. awakens_from: '<?=$unit->get_monster()->get_awakens_from()?>',
  37. awakens_to: '<?=$unit->get_monster()->get_awakens_to()?>',
  38. element: '<?=$unit->get_monster()->get_element_name()?>'
  39. }
  40. );
  41. <?php
  42. }
  43. ?>
  44. /**
  45. * Changes the score of a team.
  46. *
  47. * @param team ID of the team to change.
  48. * @param score New score.
  49. * @return true on success, false on error.
  50. */
  51. function rateTeam(team, score){
  52. params = '?player=<?=get_context()->get_player()->get_id()?>&team=' + team + '&score=' + score;
  53. console.log(params);
  54. var xhttp = new XMLHttpRequest();
  55. xhttp.onreadystatechange = function() {
  56. //if (this.readyState == 4){
  57. // alert("STATUS: " + this.status);
  58. //}
  59. };
  60. xhttp.open('GET', '/action/rate_team/' + params, true);
  61. xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  62. xhttp.send();
  63. return true;
  64. }
  65. /**
  66. * Shows or hiddes the new team panel.
  67. *
  68. * @param show True to show, false to hide.
  69. */
  70. function showNewTeam(show){
  71. if (show === true){
  72. document.getElementById('new_team').style.display = 'block';
  73. }
  74. else{
  75. document.getElementById('new_team').style.display = 'none';
  76. }
  77. }
  78. /**
  79. * Parses the form data and generates the request to save a team.
  80. */
  81. function saveTeam(){
  82. if (selected_units > max_units){
  83. alert('Too many units selected.');
  84. return;
  85. }
  86. var name = document.getElementById('new_team_name').value;
  87. var description = document.getElementById('new_team_description').value;
  88. var area_type = document.getElementById('new_area_type').options[document.getElementById('new_area_type').selectedIndex].value;
  89. var area = null;
  90. var difficulty = null;
  91. var stage = null;
  92. switch (area_type){
  93. case '<?=AREA_TYPE_ID::SCENARIO?>':
  94. area = document.getElementById('new_area_scenario').options[document.getElementById('new_area_scenario').selectedIndex].value;
  95. difficulty = document.getElementById('new_area_difficulty').options[document.getElementById('new_area_difficulty').selectedIndex].value;
  96. stage = document.getElementById('new_area_stage').options[document.getElementById('new_area_stage').selectedIndex].value;
  97. break;
  98. case '<?=AREA_TYPE_ID::CAIROS_DUNGEON?>':
  99. area = document.getElementById('new_area_cairos_dungeon').options[document.getElementById('new_area_cairos_dungeon').selectedIndex].value;
  100. stage = document.getElementById('new_area_stage').options[document.getElementById('new_area_stage').selectedIndex].value;
  101. break;
  102. case '<?=AREA_TYPE_ID::RIFT_DUNGEON?>':
  103. area = document.getElementById('new_area_rift_dungeon').options[document.getElementById('new_area_rift_dungeon').selectedIndex].value;
  104. break;
  105. case '<?=AREA_TYPE_ID::RIFT_RAID?>':
  106. //area = document.getElementById('new_area_rift_raid').options[document.getElementById('new_area_rift_raid').selectedIndex].value;
  107. stage = document.getElementById('new_area_stage').options[document.getElementById('new_area_stage').selectedIndex].value;
  108. area = stage;
  109. break;
  110. case '<?=AREA_TYPE_ID::ARENA?>':
  111. break;
  112. case '<?=AREA_TYPE_ID::GUILD_WAR?>':
  113. break;
  114. case '<?=AREA_TYPE_ID::GUILD_SIEGE?>':
  115. break;
  116. case '<?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>':
  117. area = <?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>;
  118. difficulty = document.getElementById('new_area_difficulty').options[document.getElementById('new_area_difficulty').selectedIndex].value;
  119. stage = document.getElementById('new_area_tartarus_labyrinth').options[document.getElementById('new_area_tartarus_labyrinth').selectedIndex].value;
  120. break;
  121. case '<?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>':
  122. area = <?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>;
  123. difficulty = document.getElementById('new_area_difficulty').options[document.getElementById('new_area_difficulty').selectedIndex].value;
  124. break;
  125. case '<?=AREA_TYPE_ID::DIMENSIONAL_HOLE?>':
  126. area = document.getElementById('new_area_dimensional_hole').options[document.getElementById('new_area_dimensional_hole').selectedIndex].value;
  127. stage = document.getElementById('new_area_stage').options[document.getElementById('new_area_stage').selectedIndex].value;
  128. break;
  129. case '<?=AREA_TYPE_ID::DIMENSIONAL_RIFT?>':
  130. difficulty = document.getElementById('new_area_difficulty').options[document.getElementById('new_area_difficulty').selectedIndex].value;
  131. break;
  132. default:
  133. alert('Unknown Area');
  134. return;
  135. }
  136. if (!Number.isInteger(parseInt(area))){
  137. area = 0;
  138. }
  139. if (!Number.isInteger(parseInt(stage))){
  140. stage = 0;
  141. }
  142. if (!Number.isInteger(parseInt(difficulty))){
  143. difficulty = 0;
  144. }
  145. var request =
  146. 'player=<?=get_context()->get_player()->get_id()?>' +
  147. '&area_type=' + area_type +
  148. '&area=' + area +
  149. '&difficulty=' + difficulty +
  150. '&stage=' + stage +
  151. '&name=' + encodeURI(name) +
  152. '&description=' + encodeURI(description) +
  153. '&leader=' + leader_id;
  154. var id = [];
  155. var front = 0;
  156. var slots = document.getElementsByClassName('new_unit_slot');
  157. for (var i = 0; i < slots.length; i ++) {
  158. slots[i].classList.remove('leader');
  159. var id_value = slots[i].getElementsByClassName('unit_id')[0].value;
  160. if (String(id_value).length > 0){
  161. id.push(id_value);
  162. if (
  163. (
  164. area_type == '<?=AREA_TYPE_ID::RIFT_DUNGEON?>' ||
  165. area_type == '<?=AREA_TYPE_ID::RIFT_RAID?>'
  166. ) &&
  167. i <= 3
  168. ){
  169. front = front + 1;
  170. }
  171. }
  172. }
  173. var ids = id.join(',');
  174. request =
  175. request +
  176. '&ids=' + ids +
  177. '&front=' + front;
  178. var xhttp = new XMLHttpRequest();
  179. xhttp.onreadystatechange = function() {
  180. if (this.readyState == 4){
  181. if (this.status == 200){
  182. location.reload();
  183. }
  184. else{
  185. showError('Error saving team. HTTP status ' + this.status)
  186. }
  187. }
  188. };
  189. xhttp.open("POST", "/action/add_team/", true);
  190. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  191. xhttp.send(request);
  192. }
  193. /**
  194. * Generates the request to delete a team.
  195. *
  196. * @param id Team id.
  197. */
  198. function deleteTeam(id){
  199. if (!confirm("Permanently delete team?")){
  200. return
  201. }
  202. var request = 'player=<?=get_context()->get_player()->get_id()?>&id=' + id;
  203. var xhttp = new XMLHttpRequest();
  204. xhttp.onreadystatechange = function() {
  205. if (this.readyState == 4){
  206. if (this.status == 200){
  207. location.reload();
  208. }
  209. else{
  210. showError('Error deleting team. HTTP status ' + this.status)
  211. }
  212. }
  213. };
  214. xhttp.open("POST", "/action/delete_team/", true);
  215. xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  216. xhttp.send(request);
  217. }
  218. /**
  219. * GOpens the team edit for with the selected team.
  220. *
  221. * @param id Team id.
  222. */
  223. function editTeam(id){
  224. // TODO
  225. alert("Function not implemented yet. Please delete the team and recreate it.");
  226. }
  227. /**
  228. * Searches a unit with the pattern entered in the 'new_unit_id'
  229. * field. Shows a clickable list of matching units.
  230. */
  231. function searchUnit(panel){
  232. key = document.getElementById('new_unit_id').value;
  233. var autocomplete = document.getElementById('new_unit_autocomplete');
  234. while (autocomplete.firstChild) {
  235. autocomplete.removeChild(autocomplete.firstChild);
  236. }
  237. if (key.length == 0){
  238. autocomplete.style.display = 'block';
  239. }
  240. for (var i = 0; i < units.length; i++) {
  241. if (units[i].name.toUpperCase().includes(key.toUpperCase())){
  242. autocomplete.style.display = 'block';
  243. var line = document.createElement('div');
  244. var img = document.createElement('img');
  245. img.setAttribute('src', units[i].image);
  246. var nam = document.createElement('span');
  247. var tex = document.createTextNode(units[i].name + '(' + units[i].stars + '*, Lv. ' + units[i].level + ')');
  248. nam.appendChild(tex);
  249. line.appendChild(img);
  250. line.appendChild(nam);
  251. sid = units[i].id;
  252. line.setAttribute('onclick', 'selectUnit(' + sid + ');');
  253. autocomplete.appendChild(line);
  254. }
  255. }
  256. }
  257. /**
  258. * Shows the search bar to searcha unit below a slot.
  259. */
  260. function showSearchUnit(slot){
  261. if (selected_units >= max_units){
  262. return;
  263. }
  264. var key = document.getElementById('new_unit_id');
  265. key.style.left = (slot.offsetLeft + 5) + 'px';
  266. key.style.top = (slot.offsetTop + 50) + 'px';
  267. key.style.display = 'block';
  268. key.focus();
  269. var autocomplete = document.getElementById('new_unit_autocomplete');
  270. autocomplete.style.left = key.left;
  271. autocomplete.style.top = (key.offsetTop + 15) + 'px';
  272. current_slot_id = slot.id;
  273. }
  274. /**
  275. * Selects a leader unit.
  276. */
  277. function selectLeader(slot){
  278. leader_id = slot.getElementsByClassName('unit_id')[0].value;
  279. var slots = document.getElementsByClassName('new_unit_slot');
  280. for (var i = 0; i < slots.length; i ++) {
  281. slots[i].classList.remove('leader');
  282. }
  283. slot.classList.add('leader');
  284. }
  285. /**
  286. * Selects a unit from the list and adds it to the new team.
  287. * The search list is hidden afterwards.
  288. *
  289. * @param id Unit id.
  290. */
  291. function selectUnit(id){
  292. var name = null;
  293. var stars = null;
  294. var level = null;
  295. var image = null;
  296. var element = null;
  297. var awakens_from = null;
  298. var awakens_to = null;
  299. for (var i = 0; i < units.length; i ++) {
  300. if (units[i].id == id){
  301. name = units[i].name;
  302. stars = units[i].stars;
  303. level = units[i].level;
  304. image = units[i].image;
  305. element = units[i].element;
  306. break;
  307. }
  308. }
  309. if (name != null){
  310. // Build monster panel
  311. var monsterPanel = document.createElement('div');
  312. monsterPanel.setAttribute('class', 'monster_panel');
  313. monsterPanel.setAttribute('id', 'monster_panel_' + id);
  314. var monsterStars = document.createElement('span');
  315. monsterStars.setAttribute('class', 'stars');
  316. for (var i = 0; i < stars; i ++){
  317. var star = document.createElement('img');
  318. // TODO: Handle star color.
  319. star.setAttribute('class', 'star star_purple');
  320. star.setAttribute('src', '<?=URL::IMG["ICON"]?>star.png');
  321. monsterStars.appendChild(star);
  322. }
  323. var monsterImage = document.createElement('img');
  324. monsterImage.setAttribute('class', 'monster border_' + element);
  325. monsterImage.setAttribute('src', image);
  326. var monsterLevel = document.createElement('span');
  327. monsterLevel.setAttribute('class', 'level');
  328. monsterLevel.appendChild(document.createTextNode(level));
  329. monsterPanel.appendChild(monsterStars);
  330. monsterPanel.appendChild(monsterImage);
  331. monsterPanel.appendChild(monsterLevel);
  332. // Attach monster panel
  333. var slot = document.getElementById(current_slot_id);
  334. slot.appendChild(monsterPanel);
  335. slot.setAttribute('onclick', 'selectLeader(this);');
  336. // X to remove
  337. var x = document.createElement('input');
  338. x.setAttribute('type', 'button');
  339. x.setAttribute('value', 'x');
  340. x.setAttribute('class', 'delete_unit');
  341. x.setAttribute('onClick', 'deleteUnit(this.parentElement.parentElement);');
  342. monsterPanel.appendChild(x);
  343. // Set ID
  344. var input_id = slot.getElementsByClassName('unit_id')[0];
  345. input_id.value = id;
  346. // Hide the selector
  347. var autocomplete = document.getElementById('new_unit_autocomplete');
  348. while (autocomplete.firstChild) {
  349. autocomplete.removeChild(autocomplete.firstChild);
  350. }
  351. autocomplete.style.display = 'none';
  352. document.getElementById('new_unit_id').value = '';
  353. document.getElementById('new_unit_id').style.display = 'none';
  354. selected_units ++;
  355. }
  356. }
  357. /**
  358. * Deletes a unit from the new team form.
  359. */
  360. function deleteUnit(slot){
  361. console.log(slot.nodename)
  362. var panel = slot.getElementsByClassName('monster_panel')[0];
  363. slot.removeChild(panel);
  364. var id = slot.getElementsByClassName('unit_id')[0];
  365. id.value = '';
  366. selected_units --;
  367. // Remove leader symbol
  368. if (slot.classList.contains('leader')){
  369. slot.classList.remove('leader');
  370. leader_id = '';
  371. }
  372. slot.setAttribute('onClick', 'showSearchUnit(this);');
  373. }
  374. /**
  375. * Shows the stage selector in the new team panel.
  376. *
  377. * @param total The number of stages to show.
  378. */
  379. function populateStage(total){
  380. var sel = document.getElementById('new_area_stage');
  381. while (sel.firstChild) {
  382. sel.removeChild(sel.firstChild);
  383. }
  384. var opt;
  385. var att;
  386. // Empty
  387. opt = document.createElement('option');
  388. tex = document.createTextNode('');
  389. opt.appendChild(tex);
  390. sel.appendChild(opt);
  391. for (var i = 1; i <= total; i ++){
  392. opt = document.createElement('option');
  393. tex = document.createTextNode('Stage ' + i);
  394. att = document.createAttribute('value');
  395. att.value = i;
  396. opt.setAttributeNode(att);
  397. opt.appendChild(tex);
  398. sel.appendChild(opt);
  399. }
  400. }
  401. /**
  402. * Shows the difficulty selector in the new team panel.
  403. *
  404. * @param labyrinth Indicates if the area type is the Tartarus
  405. * labyrinth. If so, it includes 'Easy'.
  406. * @param toa Indicates if the area type is the Tower of
  407. * Ascension. If so, it excludes 'Hell'.
  408. */
  409. function populateDifficulty(labyrinth = false, toa = false){
  410. var sel = document.getElementById('new_area_difficulty');
  411. while (sel.firstChild) {
  412. sel.removeChild(sel.firstChild);
  413. }
  414. var opt;
  415. var att;
  416. var tex;
  417. // Empty
  418. opt = document.createElement('option');
  419. tex = document.createTextNode('');
  420. opt.appendChild(tex);
  421. sel.appendChild(opt);
  422. // Easy (Labyrinth only)
  423. if (labyrinth){
  424. opt = document.createElement('option');
  425. tex = document.createTextNode('Easy difficulty');
  426. att = document.createAttribute('value');
  427. att.value = '<?=DIFFICULTY_ID::EASY?>';
  428. opt.setAttributeNode(att);
  429. opt.appendChild(tex);
  430. sel.appendChild(opt);
  431. }
  432. // Normal
  433. opt = document.createElement('option');
  434. tex = document.createTextNode('Normal difficulty');
  435. att = document.createAttribute('value');
  436. att.value = '<?=DIFFICULTY_ID::NORMAL?>';
  437. opt.setAttributeNode(att);
  438. opt.appendChild(tex);
  439. sel.appendChild(opt);
  440. // Hard
  441. opt = document.createElement('option');
  442. tex = document.createTextNode('Hard difficulty');
  443. att = document.createAttribute('value');
  444. att.value = '<?=DIFFICULTY_ID::HARD?>';
  445. opt.setAttributeNode(att);
  446. opt.appendChild(tex);
  447. sel.appendChild(opt);
  448. // Hell
  449. if (!toa){
  450. opt = document.createElement('option');
  451. tex = document.createTextNode('Hell difficulty');
  452. att = document.createAttribute('value');
  453. att.value = '<?=DIFFICULTY_ID::HELL?>';
  454. opt.setAttributeNode(att);
  455. opt.appendChild(tex);
  456. sel.appendChild(opt);
  457. }
  458. }
  459. /**
  460. * Shows the appropiate area selector when the area type is
  461. * selected in the new team panel.
  462. */
  463. function selectNewAreaType(){
  464. max_units = 0;
  465. //selected_units = 0;
  466. //selected_ids = [];
  467. current_slot_id = "";
  468. leader_id = "";
  469. var type = document.getElementById('new_area_type').options[document.getElementById('new_area_type').selectedIndex].value;
  470. document.getElementById('new_area_scenario').style.display = 'none';
  471. document.getElementById('new_area_scenario').selectedIndex = 0;
  472. document.getElementById('new_area_cairos_dungeon').style.display = 'none';
  473. document.getElementById('new_area_cairos_dungeon').selectedIndex = 0;
  474. document.getElementById('new_area_rift_dungeon').style.display = 'none';
  475. document.getElementById('new_area_rift_dungeon').selectedIndex = 0;
  476. document.getElementById('new_area_tartarus_labyrinth').style.display = 'none';
  477. document.getElementById('new_area_tartarus_labyrinth').selectedIndex = 0;
  478. document.getElementById('new_area_dimensional_hole').style.display = 'none';
  479. document.getElementById('new_area_dimensional_hole').selectedIndex = 0;
  480. document.getElementById('new_area_difficulty').style.display = 'none';
  481. document.getElementById('new_area_difficulty').selectedIndex = 0;
  482. document.getElementById('new_area_stage').style.display = 'none';
  483. document.getElementById('new_area_stage').selectedIndex = 0;
  484. switch (type){
  485. case '<?=AREA_TYPE_ID::SCENARIO?>':
  486. document.getElementById('new_area_scenario').style.display = 'inline';
  487. max_units = 4;
  488. break;
  489. case '<?=AREA_TYPE_ID::CAIROS_DUNGEON?>':
  490. document.getElementById('new_area_cairos_dungeon').style.display = 'inline';
  491. max_units = 5;
  492. break;
  493. case '<?=AREA_TYPE_ID::RIFT_DUNGEON?>':
  494. document.getElementById('new_area_rift_dungeon').style.display = 'inline';
  495. max_units = 6;
  496. break;
  497. case '<?=AREA_TYPE_ID::RIFT_RAID?>':
  498. //document.getElementById('new_area_rift_raid').style.display = 'inline';
  499. populateStage(5);
  500. document.getElementById('new_area_stage').style.display = 'inline';
  501. max_units = 6
  502. break;
  503. case '<?=AREA_TYPE_ID::ARENA?>':
  504. max_units = 4;
  505. //document.getElementById('new_area_arena').style.display = 'inline';
  506. break;
  507. case '<?=AREA_TYPE_ID::GUILD_WAR?>':
  508. max_units = 3;
  509. document.getElementById('new_area_guild_war').style.display = 'inline';
  510. break;
  511. case '<?=AREA_TYPE_ID::GUILD_SIEGE?>':
  512. max_units = 3;
  513. document.getElementById('new_area_guild_siege').style.display = 'inline';
  514. break;
  515. case '<?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>':
  516. max_units = 5;
  517. document.getElementById('new_area_tartarus_labyrinth').style.display = 'inline';
  518. break;
  519. case '<?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>':
  520. max_units = 5;
  521. document.getElementById('new_area_difficulty').style.display = 'inline';
  522. populateDifficulty(false, true);
  523. break;
  524. case '<?=AREA_TYPE_ID::WORLD_BOSS?>':
  525. //max_units = 5;
  526. //document.getElementById('new_area_world_boss').style.display = 'inline';
  527. break;
  528. case '<?=AREA_TYPE_ID::DIMENSIONAL_HOLE?>':
  529. max_units = 4;
  530. document.getElementById('new_area_dimensional_hole').style.display = 'inline';
  531. break;
  532. case '<?=AREA_TYPE_ID::DIMENSIONAL_RIFT?>':
  533. max_units = 5;
  534. //document.getElementById('new_area_dimensional_rift').style.display = 'inline';
  535. break;
  536. }
  537. var container = document.getElementById('new_team_units');
  538. while (container.firstChild) {
  539. container.removeChild(container.firstChild);
  540. }
  541. var panel;
  542. var hr;
  543. var id;
  544. var max_slots = max_units;
  545. for (var i = 0; i < max_slots; i ++){
  546. panel = document.createElement('div');
  547. panel.setAttribute('id', 'new_unit_slot_' + i);
  548. panel.setAttribute('class', 'new_unit_slot');
  549. panel.setAttribute('onClick', 'showSearchUnit(this);');
  550. id = document.createElement('input');
  551. id.setAttribute('type', 'hidden');
  552. id.setAttribute('class', 'unit_id');
  553. panel.appendChild(id);
  554. container.appendChild(panel);
  555. if (
  556. (
  557. type == '<?=AREA_TYPE_ID::RIFT_DUNGEON?>' ||
  558. type == '<?=AREA_TYPE_ID::RIFT_RAID?>'
  559. ) &&
  560. i == 3
  561. ){
  562. max_slots = 8;
  563. hr = document.createElement('hr');
  564. container.appendChild(hr);
  565. }
  566. }
  567. }
  568. /**
  569. * Populates the difficulty and stage selectors when an area is
  570. * selected in the new team panel.
  571. */
  572. function selectNewArea(){
  573. var type = document.getElementById('new_area_type').options[document.getElementById('new_area_type').selectedIndex].value;
  574. document.getElementById('new_area_stage').selectedIndex = 0;
  575. document.getElementById('new_area_difficulty').selectedIndex = 0;
  576. document.getElementById('new_area_stage').style.display = 'none';
  577. document.getElementById('new_area_difficulty').style.display = 'none';
  578. switch (type){
  579. case '<?=AREA_TYPE_ID::SCENARIO?>':
  580. document.getElementById('new_area_stage').style.display = 'inline';
  581. document.getElementById('new_area_difficulty').style.display = 'inline';
  582. populateStage(7);
  583. populateDifficulty();
  584. break;
  585. case '<?=AREA_TYPE_ID::CAIROS_DUNGEON?>':
  586. document.getElementById('new_area_stage').style.display = 'inline';
  587. var area = document.getElementById('new_area_cairos_dungeon').options[document.getElementById('new_area_cairos_dungeon').selectedIndex].value;
  588. if (area == <?=DUNGEON_ID::GIANTS_KEEP?> || area == <?=DUNGEON_ID::DRAGONS_LAIR?> || area == <?=DUNGEON_ID::NECROPOLIS?>){
  589. populateStage(12);
  590. }
  591. else{
  592. populateStage(10);
  593. }
  594. populateDifficulty();
  595. break;
  596. case '<?=AREA_TYPE_ID::RIFT_DUNGEON?>':
  597. break;
  598. case '<?=AREA_TYPE_ID::RIFT_RAID?>':
  599. document.getElementById('new_area_stage').style.display = 'inline';
  600. populateStage(5);
  601. break;
  602. case '<?=AREA_TYPE_ID::ARENA?>':
  603. break;
  604. case '<?=AREA_TYPE_ID::GUILD_WAR?>':
  605. break;
  606. case '<?=AREA_TYPE_ID::GUILD_SIEGE?>':
  607. break;
  608. case '<?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>':
  609. document.getElementById('new_area_difficulty').style.display = 'inline';
  610. populateDifficulty(true, false);
  611. break;
  612. case '<?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>':
  613. document.getElementById('new_area_difficulty').style.display = 'inline';
  614. populateDifficulty(false, true);
  615. break;
  616. case '<?=AREA_TYPE_ID::WORLD_BOSS?>':
  617. break;
  618. case '<?=AREA_TYPE_ID::DIMENSIONAL_HOLE?>':
  619. document.getElementById('new_area_stage').style.display = 'inline';
  620. populateStage(5);
  621. break;
  622. case '<?=AREA_TYPE_ID::DIMENSIONAL_RIFT?>':
  623. break;
  624. }
  625. }
  626. /**
  627. * Closes the error dialog.
  628. */
  629. function closeError(){
  630. document.getElementById('error').style.display = 'none';
  631. }
  632. /**
  633. * Opens the error dialog with theselected text.
  634. */
  635. function showError(text){
  636. document.getElementById('error_msg').innerHTML = text;
  637. document.getElementById('error').style.display = 'block';
  638. }
  639. </script>
  640. </head>
  641. <body>
  642. <header>
  643. <?php
  644. include __DIR__ . "/inc/header_app.php";
  645. include __DIR__ . "/inc/header_player.php";
  646. ?>
  647. </header>
  648. <aside>
  649. <h2>
  650. Teams
  651. </h2>
  652. <p>
  653. View and manage teams
  654. </p>
  655. <form action='/player/<?=get_context()->get_player()->get_id()?>/teams/' method='get' id='filter_monsters' class='filter'>
  656. <table>
  657. <tr>
  658. <td class='label'>
  659. Name:
  660. </td>
  661. <td>
  662. <input type='text' name='name' id='filter_name' value='<?=$page->get_filter("NAME")?>'/>
  663. </td>
  664. </tr>
  665. <tr>
  666. <td class='label'>
  667. Area:
  668. </td>
  669. <td>
  670. <select name='area'>
  671. <option value=''> </option>
  672. <option value='<?=AREA_TYPE_ID::SCENARIO?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::SCENARIO ? "selected='selected'" : "")?>>
  673. Scenario
  674. </option>
  675. <option value='<?=AREA_TYPE_ID::CAIROS_DUNGEON?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::CAIROS_DUNGEON ? "selected='selected'" : "")?>>
  676. Cairos Dungeon
  677. </option>
  678. <option value='<?=AREA_TYPE_ID::RIFT_DUNGEON?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::RIFT_DUNGEON ? "selected='selected'" : "")?>>
  679. Rift Dungeon
  680. </option>
  681. <option value='<?=AREA_TYPE_ID::RIFT_RAID?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::RIFT_RAID ? "selected='selected'" : "")?>>
  682. Rift Raid
  683. </option>
  684. <option value='<?=AREA_TYPE_ID::DIMENSIONAL_HOLE?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::DIMENSIONAL_HOLE ? "selected='selected'" : "")?>>
  685. Dimensional Hole>
  686. </option>
  687. <option value='<?=AREA_TYPE_ID::ARENA?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::ARENA ? "selected='selected'" : "")?>>
  688. Arena
  689. </option>
  690. <option value='<?=AREA_TYPE_ID::GUILD_WAR?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::GUILD_WAR ? "selected='selected'" : "")?>>
  691. Guild War
  692. </option>
  693. <option value='<?=AREA_TYPE_ID::GUILD_SIEGE?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::GUILD_SIEGE ? "selected='selected'" : "")?>>
  694. Guild Siege
  695. </option>
  696. <option value='<?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::TARTARUS_LABYRINTH ? "selected='selected'" : "")?>>
  697. Tartarus Labyrinth
  698. </option>
  699. <option value='<?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::TRIAL_OF_ASCENSION ? "selected='selected'" : "")?>>
  700. Trial of Ascension
  701. </option>
  702. <option value='<?=AREA_TYPE_ID::WORLD_BOSS?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::WORLD_BOSS ? "selected='selected'" : "")?>>
  703. World Boss
  704. </option>
  705. <option value='<?=AREA_TYPE_ID::DIMENSIONAL_RIFT?>' <?=($page->get_filter("AREA") == AREA_TYPE_ID::DIMENSIONAL_RIFT ? "selected='selected'" : "")?>>
  706. Dimensinal Rift
  707. </option>
  708. </select>
  709. </td>
  710. </tr>
  711. </table>
  712. <input type='submit' value='Apply'/>
  713. </form>
  714. </aside>
  715. <main>
  716. <section class='content'>
  717. <h2>
  718. Teams
  719. </h2>
  720. <article>
  721. <table id='teams'>
  722. <tr>
  723. <th>
  724. Team
  725. </th>
  726. <th>
  727. Description
  728. </th>
  729. <th>
  730. Units
  731. </th>
  732. <th>
  733. Score
  734. </th>
  735. <th>
  736. Actions
  737. </th>
  738. </tr>
  739. <?php
  740. $odd = "odd";
  741. foreach ($page->get_teams() as $team){
  742. ?>
  743. <tr>
  744. <td class='team <?=$odd?>'>
  745. <h4>
  746. <img title='<?=$team->get_area()->get_name()?>' class='area' src='<?=$team->get_area()->get_image($team->get_stage())?>'/>
  747. <?php
  748. if ($team->get_stage() > 0 && $team->get_area()->get_type() != AREA_TYPE_ID::TARTARUS_LABYRINTH){
  749. ?>
  750. <span class='stage'><?=$team->get_stage()?></span>
  751. <?php
  752. }
  753. ?>
  754. <span class='team_name'><?=$team->get_name()?></span>
  755. </h4>
  756. </td>
  757. <td class='description <?=$odd?>'>
  758. <?=$team->get_description()?>
  759. </td>
  760. <td class='units <?=$odd?>'>
  761. <?php
  762. $prev_front = false;
  763. $front = "undefined";
  764. foreach ($team->get_units() as $unit){
  765. $front = in_array($unit->get_id(), $team->get_frontline());
  766. if ($front != "undefined" && $prev_front != $front){
  767. ?>
  768. <hr class='frontline'/>
  769. <?php
  770. }
  771. ?>
  772. <a href='/<?=get_context()->get_player()->get_id()?>/units/<?=$unit->get_id()?>'>
  773. <div class='monster_panel'>
  774. <?=HTML::unit_panel($unit)?>
  775. <?php
  776. if ($unit->get_id() == $team->get_leader()){
  777. ?>
  778. <img alt='Leader' class='leader' src='<?=URL::IMG["ICON"]?>leader.png'/>
  779. <?php
  780. }
  781. ?>
  782. </div>
  783. </a>
  784. <?php
  785. $prev_front = $front;
  786. }
  787. ?>
  788. </td>
  789. <td class='score <?=$odd?>'>
  790. <input type='number' min='0' max='20' value='<?=$team->get_score()?>' onChange='rateTeam(<?=$team->get_id()?>, this.value);'/>
  791. </td>
  792. <td class='action <?=$odd?>'>
  793. <a title='Edit team' class='a_button' onclick='editTeam(<?=$team->get_id()?>)'>
  794. <img alt='Edit team' src='<?=URL::IMG["ICON"]?>edit.png'/>
  795. </a>
  796. <a title='Remove team' class='a_button' onclick='deleteTeam(<?=$team->get_id()?>)'>
  797. <img alt='Remove team' src='<?=URL::IMG["ICON"]?>nok.png'/>
  798. </a>
  799. </td>
  800. </tr>
  801. <?php
  802. if ($odd == ""){
  803. $odd = "odd";
  804. }
  805. else{
  806. $odd = "";
  807. }
  808. }
  809. ?>
  810. </table>
  811. <input type='button' onClick='showNewTeam(true);' value='New Team'/>
  812. </article>
  813. </section> <!-- .list -->
  814. </main>
  815. <?php
  816. include __DIR__ . "/inc/footer.php";
  817. ?>
  818. <section id='new_team' class='content'>
  819. <h2>
  820. New team
  821. </h2>
  822. <article>
  823. <table>
  824. <tr>
  825. <td class='new_title'>
  826. Area
  827. </td>
  828. <td class='new_values' id='new_values_area'>
  829. <select id='new_area_type' name='new_area_type' onChange='selectNewAreaType();'>
  830. <option value=''> </option>
  831. <option value='<?=AREA_TYPE_ID::SCENARIO?>'>Scenario</option>
  832. <option value='<?=AREA_TYPE_ID::CAIROS_DUNGEON?>'>Cairos Dungeon</option>
  833. <option value='<?=AREA_TYPE_ID::RIFT_DUNGEON?>'>Rift Dungeon</option>
  834. <option value='<?=AREA_TYPE_ID::RIFT_RAID?>'>Rift Raid</option>
  835. <option value='<?=AREA_TYPE_ID::DIMENSIONAL_HOLE?>'>Dimensional Hole</option>
  836. <option value='<?=AREA_TYPE_ID::ARENA?>'>Arena</option>
  837. <option value='<?=AREA_TYPE_ID::GUILD_WAR?>'>Guild War</option>
  838. <option value='<?=AREA_TYPE_ID::GUILD_SIEGE?>'>Guild Siege</option>
  839. <option value='<?=AREA_TYPE_ID::TARTARUS_LABYRINTH?>'>Tartarus Labyrinth</option>
  840. <option value='<?=AREA_TYPE_ID::TRIAL_OF_ASCENSION?>'>Trial of Ascension</option>
  841. <!--<option value='<?=AREA_TYPE_ID::WORLD_BOSS?>'>World Boss</option>-->
  842. <option value='<?=AREA_TYPE_ID::DIMENSIONAL_RIFT?>'>Dimensinal Rift</option>
  843. </select>
  844. <select id='new_area_scenario' class='new_area' onChange='selectNewArea();'>
  845. <option value=''> </option>
  846. <option value='<?=SCENARIO_ID::GAREN_FOREST?>'>Garen Forest</option>
  847. <option value='<?=SCENARIO_ID::MT_SIZ?>'>Mt. Siz</option>
  848. <option value='<?=SCENARIO_ID::KABIR_RUINS?>'>Kabir Ruins</option>
  849. <option value='<?=SCENARIO_ID::MT_WHITE_RAGON?>'>Mt. White Ragon</option>
  850. <option value='<?=SCENARIO_ID::TELAIN_FOREST?>'>Telain Forest</option>
  851. <option value='<?=SCENARIO_ID::HYDENI_RUINS?>'>Hydeni Ruins</option>
  852. <option value='<?=SCENARIO_ID::TAMOR_DESERT?>'>Tamor Desert</option>
  853. <option value='<?=SCENARIO_ID::VROFAGUS_RUINS?>'>Vrofagus Ruins</option>
  854. <option value='<?=SCENARIO_ID::FAIMON_VOLCANO?>'>Faimon Volcano</option>
  855. <option value='<?=SCENARIO_ID::AIDEN_FOREST?>'>Aiden Forest</option>
  856. <option value='<?=SCENARIO_ID::FERUN_CASTLE?>'>Ferun Castle</option>
  857. <option value='<?=SCENARIO_ID::MT_RUNAR?>'>Mt. Runar</option>
  858. <option value='<?=SCENARIO_ID::CHIRUKA_REMAINS?>'>Charuca Remains</option>
  859. </select>
  860. <select id='new_area_cairos_dungeon' class='new_area' onChange='selectNewArea();'>
  861. <option value=''> </option>
  862. <option value='<?=DUNGEON_ID::GIANTS_KEEP?>'>Giant&#39;s Keep</option>
  863. <option value='<?=DUNGEON_ID::DRAGONS_LAIR?>'>Dragon&#39;s Lair</option>
  864. <option value='<?=DUNGEON_ID::NECROPOLIS?>'>Necropolis</option>
  865. <option value='<?=DUNGEON_ID::STEEL_FORTRESS?>'>Steel Fortress</option>
  866. <option value='<?=DUNGEON_ID::PUNISHERS_CRYPT?>'>Punisher&#39;s Crypt</option>
  867. <option value='<?=DUNGEON_ID::HALL_OF_MAGIC?>'>Hall of Magic</option>
  868. <option value='<?=DUNGEON_ID::HALL_OF_FIRE?>'>Hall of Fire</option>
  869. <option value='<?=DUNGEON_ID::HALL_OF_WATER?>'>Hall of Water</option>
  870. <option value='<?=DUNGEON_ID::HALL_OF_WIND?>'>Hall of Wind</option>
  871. <option value='<?=DUNGEON_ID::HALL_OF_LIGHT?>'>Hall of Light</option>
  872. <option value='<?=DUNGEON_ID::HALL_OF_DARK?>'>Hall of Dark</option>
  873. </select>
  874. <select id='new_area_rift_dungeon' class='new_area' onChange='selectNewArea();'>
  875. <option value=''> </option>
  876. <option value='<?=ELEMENTAL_RIFT_DUNGEON_ID::FIRE_BEAST?>'>Fire Beast</option>
  877. <option value='<?=ELEMENTAL_RIFT_DUNGEON_ID::ICE_BEAST?>'>Ice Beast</option>
  878. <option value='<?=ELEMENTAL_RIFT_DUNGEON_ID::WIND_BEAST?>'>Wind Beast</option>
  879. <option value='<?=ELEMENTAL_RIFT_DUNGEON_ID::LIGHT_BEAST?>'>Light Beast</option>
  880. <option value='<?=ELEMENTAL_RIFT_DUNGEON_ID::DARK_BEAST?>'>Dark Beast</option>
  881. </select>
  882. <select id='new_area_dimensional_hole' class='new_area' onChange='selectNewArea();'>
  883. <option value=''> </option>
  884. <option value='<?=DUNGEON_ID::FOREST_OF_ROARING_BEASTS?>'>Forest or Roaring Beasts</option>
  885. <option value='<?=DUNGEON_ID::KARZHAN_REMAINS_WARBEAR?>'>Karzhan Remains (Warbear)</option>
  886. <option value='<?=DUNGEON_ID::KARZHAN_REMAINS_INUGAMI?>'>Karzhan Remains (Inugami)</option>
  887. <option value='<?=DUNGEON_ID::SANCTUARY_OF_DREAMING_FAIRIES?>'>Sanctuary of Dreaming Fairies</option>
  888. <option value='<?=DUNGEON_ID::ELLUNIA_REMAINS_FAIRY?>'>Ellunia Remains (Fairy)</option>
  889. <option value='<?=DUNGEON_ID::ELLUNIA_REMAINS_PIXIE?>'>Ellunia Remains (Pixie)</option>
  890. <option value='<?=DUNGEON_ID::CLIFF_OF_TOUGH_BEASTS_MEN?>'>cliff of Tough Beasts Men</option>
  891. <option value='<?=DUNGEON_ID::LUMEL_REMAINS_WEREWOLF?>'>Lumel Remains (Werewolf)</option>
  892. <option value='<?=DUNGEON_ID::LUMEL_REMAINS_MARTIAL_CAT?>'>Lumel Remains (Martial Cat)</option>
  893. </select>
  894. <select id='new_area_tartarus_labyrinth' class='new_area' onChange='selectNewArea();'>
  895. <option value=''> </option>
  896. <option value='<?=LABYRINTH_STAGES_ID::TARTARUS?>'>Tartarus</option>
  897. <option value='<?=LABYRINTH_STAGES_ID::KOTTOS?>'>Kottos</option>
  898. <option value='<?=LABYRINTH_STAGES_ID::LEOS?>'>Leos</option>
  899. <option value='<?=LABYRINTH_STAGES_ID::AQUILES?>'>Aquiles</option>
  900. <option value='<?=LABYRINTH_STAGES_ID::NORMAL?>'>Normal Stage</option>
  901. <option value='<?=LABYRINTH_STAGES_ID::RESCUE?>'>Rescue Stage</option>
  902. <option value='<?=LABYRINTH_STAGES_ID::EXPLODE?>'>Explode Stage</option>
  903. <option value='<?=LABYRINTH_STAGES_ID::COOL_TIME?>'>Cool Time Stage</option>
  904. <option value='<?=LABYRINTH_STAGES_ID::SPEED_LIMIT?>'>Speed Limit Stage</option>
  905. <option value='<?=LABYRINTH_STAGES_ID::TIME_LIMIT?>'>Time Limit Stage</option>
  906. </select>
  907. <select id='new_area_difficulty'>
  908. </select>
  909. <select id='new_area_stage'>
  910. </select>
  911. </td>
  912. </tr>
  913. <tr>
  914. <td class='new_title'>
  915. Name
  916. </td>
  917. <td class='new_values'>
  918. <input type='text' id='new_team_name' name='name'/>
  919. </td>
  920. </tr>
  921. <tr>
  922. <td class='new_title'>
  923. Description
  924. </td>
  925. <td class='new_values'>
  926. <textarea id='new_team_description' name='description'></textarea>
  927. </td>
  928. </tr>
  929. <tr>
  930. <td class='new_title'>
  931. Units:
  932. <!--<div class='new_unit' id='new_unit'>
  933. </div>-->
  934. </td>
  935. <td id='new_units' class='new_values'>
  936. <div id='new_team_units'>
  937. </div>
  938. <input id='new_unit_id' class='no_remove' onInput='searchUnit();'/>
  939. <div id='new_unit_autocomplete' class='no_remove new_unit_autocomplete'>
  940. </div>
  941. </td>
  942. </tr>
  943. <tr>
  944. <td colspan='2'>
  945. <input type='button' value='Save' onClick='saveTeam();'/>
  946. <input type='button' value='Close' onClick='showNewTeam(false);'/>
  947. </td>
  948. </tr>
  949. </table>
  950. </article>
  951. </section>
  952. <section id='error'>
  953. <h2>
  954. Teams
  955. </h2>
  956. <article>
  957. <p id='error_msg'>
  958. </p>
  959. <input type='button' onclick='closeError();'>
  960. </article>
  961. </section>
  962. </body>
  963. </html>