PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/nacridan/conquest/cqxprewardpanel.inc.php

https://gitlab.com/Goutte/Nacridan
PHP | 251 lines | 225 code | 26 blank | 0 comment | 10 complexity | 01cf9a2b1b006ecce3c407f6cf9a6866 MD5 | raw file
  1. <?php
  2. require_once (HOMEPATH . "/lib/BBCodeParser/BBCodeParser.inc.php");
  3. class CQXPRewardPanel extends HTMLObject
  4. {
  5. public $nacridan;
  6. public $players;
  7. public $curplayer;
  8. public $db;
  9. public $style;
  10. public function CQXPRewardPanel($nacridan, $style, $db)
  11. {
  12. $this->db = $db;
  13. $this->nacridan = $nacridan;
  14. if ($nacridan == null)
  15. $this->players = array();
  16. else
  17. $this->players = $this->nacridan->loadSessPlayers();
  18. $this->curplayer = $this->nacridan->loadCurSessPlayer($db);
  19. $this->style = $style;
  20. }
  21. public function toString()
  22. {
  23. $db = $this->db;
  24. $players = $this->players;
  25. $curplayer = $this->curplayer;
  26. $id = 0;
  27. if (isset($_POST['createconfirm'])) // ------------------- CREATION -----------------
  28. {
  29. if ($_POST['createconfirm'] == 'yes') {
  30. require_once (HOMEPATH . "/class/Mission.inc.php");
  31. require_once (HOMEPATH . "/class/MissionReward.inc.php");
  32. $mission = new Mission();
  33. $mission->set("PlayerList", $_POST["ID_LIST"]);
  34. $mission->set("name", base64_decode($_POST["TITLE"]));
  35. $mission->set("content", base64_decode($_POST["CONTENT"]));
  36. $mission->set("date", gmdate("Y-m-d h:m:s"));
  37. $mission->set("id_BasicMission", 100); // Mission personnalisée avec MJ
  38. $mission->updateDB($db);
  39. $missionReward = new MissionReward();
  40. $missionReward->set("idMission", $mission->get("id"));
  41. $missionReward->set("xpStop", $_POST["XP"]);
  42. $missionReward->updateDB($db);
  43. $str = "<table class='maintable " . $this->style . "'>\n";
  44. $str .= "<tr><td class='mainbgbody'>La récompense a été distribuée. TODO distribuer vraiment</td></tr>";
  45. $str .= "</table>";
  46. } else {
  47. $str = "<table class='maintable " . $this->style . "'>\n";
  48. $str .= "<tr><td class='mainbgbody'>La récompense a été distribuée.</td></tr>";
  49. $str .= "</table>";
  50. }
  51. return $str;
  52. } elseif (isset($_POST['check'])) // --------------VERIFICATION DE L'ANNONCE
  53. {
  54. $str = "<form name='form' method=post target='_self'>\n";
  55. $str .= "<table class='maintable " . $this->style . "'>\n";
  56. $str .= "<tr>\n";
  57. $str .= "<td colspan='2' class='mainbgtitle'><b>" . localize('CRÉATION D\'UNE RÉCOMPENSE') . "</b></td>\n";
  58. $str .= "</tr>\n";
  59. $str .= "<tr><td class='mainbgbody' colspan='3'>Cette récompense convient-elle ?</td></tr>";
  60. $str .= "<tr class='mainbgbody' >";
  61. $str .= "<td width='100px'>" . gmdate("d-m-Y") . "</td>";
  62. $str .= "<td width='250px' >*** <b>" . stripslashes($_POST["title"]) . "</b> ***</td>";
  63. $str .= "</tr>";
  64. $content = stripslashes($_POST["content"]);
  65. $content = nl2br(bbcode($content));
  66. $str .= "<tr class='mainbgbody' >";
  67. $str .= "<td colspan=3>" . $content . "</td>";
  68. $str .= "</tr>";
  69. if(is_numeric($_POST["xp"])){
  70. $str .= "<tr class='mainbgbody' >";
  71. $str .= "<td colspan=3> Quantité totale de PX pour le groupe : <b>" . $_POST["xp"] . "</b></td>";
  72. $str .= "</tr>";
  73. }
  74. $str .= "<tr class='mainbgtitle' ><td colspan=3>Liste des participants</td></tr>";
  75. $idarray = explode(",",$_POST['idlist']);
  76. foreach($idarray as $participant_id){
  77. if (is_numeric($participant_id)) {
  78. $participant = new Player();
  79. $participant->load($participant_id, $db);
  80. $str .= "<tr class='mainbgbody' ><td colspan=3>".$participant->get('name')." (".$participant_id.") niv ".$participant->get('level')."</td></tr>";
  81. }
  82. }
  83. $str .= "<input type='hidden' name='TITLE' value='" . base64_encode($_POST['title']) . "'/>";
  84. $str .= "<input type='hidden' name='CONTENT' value='" . base64_encode($_POST['content']) . "'/>";
  85. $str .= "<input type='hidden' name='ID_LIST' value='" . $_POST['idlist'] . "'/>";
  86. $str .= "<input type='hidden' name='XP' value='" . $_POST['xp'] . "'/>";
  87. $str .= "<input type='hidden' name='createconfirm' value='yes'/>";
  88. $str .= "<td><input type='submit' name='ok' value='Ok'/></td></tr>";
  89. $str .= "</table></form>";
  90. return $str;
  91. } elseif (isset($_POST['create'])) // ------- FORMULAIRE DE CREATION
  92. {
  93. $str = "<table class='maintable " . $this->style . "'>\n";
  94. $str .= "<form name='form' method=post target='_self'>\n";
  95. $str .= "<tr>\n";
  96. $str .= "<td colspan='2' class='mainbgtitle'><b>" . localize('CRÉATION D\'UNE RÉCOMPENSE') . "</b></td>\n";
  97. $str .= "</tr>\n";
  98. $str .= "<tr><td class='mainbgbody' ><label for='title'>Titre : </label><input type='text' maxlength='30' name='title' id='title' /></td></tr>";
  99. $str .= "<tr><td class='mainbgbody' ><label for='px'>Nombre total de PX pour le groupe : </label><input type='text' maxlength='30' name='xp' id='px' /></td></tr>";
  100. $str .= "<tr><td class='mainbgbody' ><label for='idlist'>Liste des participants sous la forme id1,id2, id3 etc. : </label><input type='text' maxlength='200' name='idlist' id='idlist' /></td></tr>";
  101. $str .= "<tr><td class='mainbgbody' align='left'><label for='content'> Description courte de la mission, au minimum mettre le lien vers le récit dans le forum : </label> </td></tr>";
  102. $str .= "";
  103. $str .= "<tr>";
  104. $str .= "<td class='mainbgbody' > <textarea rows=6 cols=60 name='content' id='content' /> </textarea></td>";
  105. $str .= "</tr>";
  106. $str .= "<td><input type='submit' name='check' value='Créer'/></td></tr>";
  107. $str .= "</form>";
  108. $str .= "</table>";
  109. return $str;
  110. } elseif (isset($_POST['deleteconfirm'])) // --------------------- SUPPRESSION
  111. {
  112. $str = "<table class='maintable " . $this->style . "'>\n";
  113. if ($_POST['deleteconfirm'] == 'yes') {
  114. $newslist = unserialize(stripslashes($_POST['newslist']));
  115. foreach ($newslist as $id) {
  116. $dbd = new DBCollection("DELETE FROM News WHERE id=" . $id, $db, 0, 0, false);
  117. }
  118. $str .= "<tr><td>Les annonces sélectionnées ont normalement été supprimées.</td></td>";
  119. } else
  120. $str .= "<td><td>Rien n'a été changé.</td></td>";
  121. $str .= "</table>";
  122. return $str;
  123. } elseif (isset($_POST['delete'])) // --------------- CONFIRMATION DE LA SUPPRESSION
  124. {
  125. $newslist = unserialize(stripslashes($_POST['newslist']));
  126. $str = "<form name='form' method=post target='_self'>\n";
  127. $str .= "<table class='maintable " . $this->style . "'>\n";
  128. $str .= "<tr><td class='mainbgbody'>Êtes-vous sûr de vouloir supprimer ces news ?</td>";
  129. $str .= "<tr><td class='mainbgbody'>" . "<input type='radio' name='deleteconfirm' value='yes' id='yes' />" . "<label for='yes'>Oui, suppression.</label></td></tr>";
  130. $str .= "<tr><td class='mainbgbody'>" . "<input type='radio' name='deleteconfirm' value='no' id='no' />" . "<label for='no'>Non, on garde.</label></td></tr>";
  131. $str .= "</table>";
  132. $newsidlist = array();
  133. $str .= "<table class='maintable " . $this->style . "'>\n";
  134. $str .= "<tr>\n";
  135. $str .= "<td class='mainbglabel' width='80px' align='center'>" . localize('id') . "</td>\n";
  136. $str .= "<td class='mainbglabel' width='100px' align='center'>" . localize('type') . "</td>\n";
  137. $str .= "<td class='mainbglabel' width='200px' align='center'>" . localize('Auteur') . "</td>\n";
  138. $str .= "<td class='mainbglabel' align='center'>" . localize('Date') . "</td>\n";
  139. $str .= "</tr></table>";
  140. $str .= "<table class='maintable " . $this->style . "'>\n";
  141. foreach ($newslist as $arr) {
  142. if (array_key_exists("news" . $arr["id"], $_POST)) {
  143. $str .= "<tr><td class='mainbgbody' width='80px' align='left'> " . $arr["id"] . " </td>\n";
  144. $str .= "<td class='mainbgbody' width='100px' align='left'> " . $arr["type"] . " </td>\n";
  145. $str .= "<td class='mainbgbody' width='200px' align='left'>" . $arr["author"] . " </td>";
  146. $str .= "<td class='mainbgbody' align='left'> " . $arr["date"] . " </td>";
  147. $str .= "</tr>\n";
  148. $newsidlist[] = $arr["id"];
  149. }
  150. }
  151. $str .= "</table>";
  152. $str .= "<input type='hidden' name='newslist' value=" . serialize($newsidlist) . "/>";
  153. $str .= "<input type='submit' name='ok' value='Ok'/>";
  154. $str .= "</form>";
  155. return $str;
  156. } else // ---------------- LISTE des Récompenses -------------
  157. {
  158. $dbm = new DBCollection("SELECT * FROM Mission WHERE id_BasicMission=100", $db);
  159. $data = array();
  160. while (! $dbm->eof()) {
  161. $data[] = array(
  162. 'id' => $dbm->get('id'),
  163. "title" => $dbm->get('name'),
  164. "date" => $dbm->get("date")
  165. );
  166. $dbm->next();
  167. }
  168. $str = "<form name='form' method=post target='_self'>\n";
  169. $str .= "<table class='maintable " . $this->style . "'>\n";
  170. $str .= "<tr>\n";
  171. $str .= "<td colspan='3' class='mainbgtitle'><b>" . localize('LISTES DES ANCIENNES RÉCOMPENSES') . "</b></td>\n";
  172. $str .= "</tr>\n";
  173. $str .= "<tr>\n";
  174. $str .= "<td class='mainbglabel' width='80px' align='center'>" . localize('id') . "</td>\n";
  175. $str .= "<td class='mainbglabel' width='80px' align='center'>" . localize('Title') . "</td>\n";
  176. $str .= "<td class='mainbglabel' align='center'>" . localize('Date') . "</td>\n";
  177. $str .= "</tr></table>";
  178. $str .= "<table class='maintable " . $this->style . "'>";
  179. foreach ($data as $arr) {
  180. $str .= "<tr><td class='mainbgbody' width='27px' align='center'> <input type='checkbox' name='news" . $arr["id"] . "' id='news" . $arr["id"] . "' /> </td>";
  181. $str .= "<td class='mainbgbody' width='80px' align='left'> " . $arr["id"] . " </td>\n";
  182. $str .= "<td class='mainbgbody' width='100px' align='left'> " . $arr["title"] . " </td>\n";
  183. $str .= "<td class='mainbgbody' align='left'> " . $arr["date"] . " </td>";
  184. $str .= "</tr>\n";
  185. }
  186. $str .= "</table>";
  187. $str .= "<table class='maintable " . $this->style . "'>\n";
  188. $str .= "<tr><td><input type='submit' name='delete' value='Supprimer'/></td>";
  189. $str .= "</table>";
  190. $str .= "<input type='hidden' name='newslist' value='" . serialize($data) . "'/>";
  191. $str .= "</form>";
  192. $str .= "<form name='form' method=post target='_self'>\n";
  193. $str .= "<table class='maintable " . $this->style . "'>\n";
  194. $str .= "<tr>\n";
  195. $str .= "<td colspan='2' class='mainbgtitle'><b>" . localize('CRÉATION D\'UNE RÉCOMPENSE') . "</b></td>\n";
  196. $str .= "</tr>\n";
  197. $str .= "<td><input type='submit' name='create' value='Créer'/></td></tr>";
  198. $str .= "</table>";
  199. $str .= "</form>";
  200. return $str;
  201. }
  202. }
  203. }
  204. ?>