PageRenderTime 125ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/nacridan/conquest/cqwarehouse.inc.php

https://gitlab.com/nacridan/Nacridan
PHP | 341 lines | 309 code | 13 blank | 19 comment | 16 complexity | b7e6872fde6c4b7265c799ad665feccd MD5 | raw file
  1. <?php
  2. DEFINE("STEP", 8);
  3. require_once (HOMEPATH . "/class/Equipment.inc.php");
  4. require_once (HOMEPATH . "/class/BasicEquipment.inc.php");
  5. class CQWareHouse extends HTMLObject
  6. {
  7. public $db;
  8. public $curplayer;
  9. public $nacridan;
  10. public $err;
  11. public function CQWareHouse($nacridan, $db)
  12. {
  13. $this->db = $db;
  14. $this->nacridan = $nacridan;
  15. $this->curplayer = $this->nacridan->loadCurSessPlayer($db);
  16. $this->err = "";
  17. if (isset($_POST["Take"])) {
  18. if (! $this->nacridan->isRepostForm()) {
  19. require_once (HOMEPATH . "/factory/EquipFactory.inc.php");
  20. if (isset($_POST["IdBasic"]))
  21. EquipFactory::takeWarehouseEquipment($this->curplayer, quote_smart($_POST["IdBasic"]), $this->nacridan->getCity()->get("id"), $this->err, $this->db);
  22. else
  23. $this->err = localize("Vous devez d'abord sélectionner un équipement à prendre.");
  24. } else {
  25. $err = eval(file_get_contents(HOMEPATH . "/include/reposterror.inc.php"));
  26. }
  27. }
  28. if (isset($_POST["Sell"])) {
  29. if (! $this->nacridan->isRepostForm()) {
  30. require_once (HOMEPATH . "/factory/EquipFactory.inc.php");
  31. if (isset($_POST["IdBasic"]) && quote_smart($_POST["PRICE"]) > 0)
  32. EquipFactory::saleWarehouseEquipment($this->curplayer, quote_smart($_POST["IdBasic"]), quote_smart($_POST["PRICE"]), $this->err, $this->db);
  33. else {
  34. if (! isset($_POST["IdBasic"]))
  35. $this->err = localize("Vous devez d'abord sélectionner un équipement à vendre.");
  36. else
  37. $this->err = localize("Vous devez entrer un prix de vente valide.");
  38. }
  39. } else {
  40. $err = eval(file_get_contents(HOMEPATH . "/include/reposterror.inc.php"));
  41. }
  42. }
  43. /*
  44. * if(isset($_POST["RemoveSell"]))
  45. * {
  46. * if(!$this->nacridan->isRepostForm())
  47. * {
  48. * require_once(HOMEPATH."/factory/EquipFactory.inc.php");
  49. * if(isset($_POST["IdBasic"]))
  50. * EquipFactory::removeSaleWarehouseEquipment($this->curplayer,quote_smart($_POST["IdBasic"]), $this->err,$this->db);
  51. *
  52. * if(!isset($_POST["IdBasic"]))
  53. * $this->err=localize("Vous devez d'abord sélectionner un équipement.");
  54. * }
  55. * else
  56. * {
  57. * $err=eval(file_get_contents(HOMEPATH."/include/reposterror.inc.php"));
  58. * }
  59. * }
  60. */
  61. if (isset($_POST["Give"])) {
  62. if (! $this->nacridan->isRepostForm()) {
  63. require_once (HOMEPATH . "/factory/EquipFactory.inc.php");
  64. if (isset($_POST["IdBasic"]))
  65. EquipFactory::giveWarehouseEquipment($this->curplayer, quote_smart($_POST["IdBasic"]), $this->nacridan->getCity()->get("id"), $this->err, $this->db);
  66. else
  67. $this->err = localize("Vous devez d'abord sélectionner un équipement à prendre.");
  68. } else {
  69. $err = eval(file_get_contents(HOMEPATH . "/include/reposterror.inc.php"));
  70. }
  71. }
  72. }
  73. public function toString()
  74. {
  75. $curplayer = $this->curplayer;
  76. $db = $this->db;
  77. $id = $curplayer->get("id");
  78. $err = $this->err;
  79. $str = "";
  80. if (isset($_GET["type"])) {
  81. $type = quote_smart($_GET["type"]);
  82. } else {
  83. $type = 1;
  84. }
  85. if ($err == "" && $str == "") {
  86. switch ($type) {
  87. case 1:
  88. $cond = "Equipment.id_EquipmentType=1 OR Equipment.id_EquipmentType=2";
  89. break;
  90. case 2:
  91. $cond = "Equipment.id_EquipmentType!=1 AND Equipment.id_EquipmentType!=2 AND Equipment.id_EquipmentType!=8 AND Equipment.id_EquipmentType!=9 AND Equipment.id_EquipmentType!=12 AND Equipment.id_EquipmentType <20";
  92. break;
  93. case 3:
  94. $cond = "Equipment.id_EquipmentType=20 OR Equipment.id_EquipmentType=21 OR Equipment.id_EquipmentType=22 OR Equipment.id_EquipmentType=8 OR Equipment.id_EquipmentType=9";
  95. break;
  96. case 4:
  97. $cond = "Equipment.id_EquipmentType=23";
  98. break;
  99. }
  100. /*
  101. * if(isset($_POST["order"]) && $_POST["order"]!="")
  102. * {
  103. * $order=quote_smart($_POST["order"]);
  104. * if(isset($_POST["orderprev"]) && $order==$_POST["orderprev"])
  105. * {
  106. * $order.=" DESC";
  107. * }
  108. * }
  109. * else
  110. * {
  111. * $order="EQ.id_EquipmentType";
  112. * }
  113. *
  114. */
  115. $target = "/conquest/conquest.php?center=warehouse&type=" . $type;
  116. $str = "<form id='formid' name='form' method='POST' action='" . CONFIG_HOST . $target . "' target='_self'>\n";
  117. $str .= "<table class='maintable centerareawidth'>\n";
  118. $str .= "<tr>\n";
  119. $str .= "<td class='mainbgtitle'><b>" . localize('E N T R E P Ô T') . "</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='fightevent'>" . $err . "</span> \n";
  120. $str .= "</td>\n";
  121. $str .= "</tr>\n";
  122. $str .= "<tr>\n";
  123. $str .= "<td class='mainbgtitle'>\n";
  124. $str .= "<a href='../conquest/conquest.php?center=warehouse&type=1' class='tabmenu'>" . localize('Armes') . "</a> |\n";
  125. $str .= "<a href='../conquest/conquest.php?center=warehouse&type=2' class='tabmenu'>" . localize('Armures') . "</a> |\n";
  126. $str .= "<a href='../conquest/conquest.php?center=warehouse&type=4' class='tabmenu'>" . localize('Outils') . "</a> |\n";
  127. $str .= "<a href='../conquest/conquest.php?center=warehouse&type=3' class='tabmenu'>" . localize('Divers') . "</a> |\n";
  128. $str .= "</td>\n";
  129. $str .= "</tr>\n";
  130. $str .= "<tr><td class='mainbgtitle'>\n";
  131. switch ($type) {
  132. case 1:
  133. $str .= localize("Les Armes ");
  134. break;
  135. case 2:
  136. $str .= localize("Les Armures ");
  137. break;
  138. case 3:
  139. $str .= localize("Divers ");
  140. break;
  141. case 4:
  142. $str .= localize("Les ouils ");
  143. break;
  144. }
  145. $eq = new Equipment();
  146. $eqmodifier = new Modifier();
  147. $modifier = new Modifier();
  148. $mission = new Mission();
  149. // profiler_start("SQLQuery");
  150. $dbe = new DBCollection(
  151. "SELECT zone, " . $eq->getASRenamer("Equipment", "EQ") . "," . $eqmodifier->getASRenamer("Modifier_BasicEquipment", "EQM") . "," .
  152. $modifier->getASRenamer("Modifier_BasicTemplate", "MD") . "," . $mission->getASRenamer("Mission", "MISS") .
  153. ",mask,wearable, BasicEquipment.frequency AS frequency, BasicTemplate.frequency AS freq FROM Equipment LEFT JOIN BasicEquipment ON Equipment.id_BasicEquipment=BasicEquipment.id LEFT JOIN BasicTemplate ON Equipment.id_BasicTemplate=BasicTemplate.id LEFT JOIN Modifier_BasicEquipment ON id_Modifier_BasicEquipment=Modifier_BasicEquipment.id LEFT JOIN Modifier_BasicTemplate ON id_Modifier_BasicTemplate=Modifier_BasicTemplate.id LEFT JOIN EquipmentType ON Equipment.id_EquipmentType=EquipmentType.id LEFT JOIN Mission ON Equipment.id_Mission=Mission.id WHERE (" .
  154. $cond . ") AND EquipmentType.small='No' AND id_Warehouse=" . $this->nacridan->getCity()->get("id"), $db);
  155. $array = array();
  156. // profiler_stop("SQLQuery");
  157. while (! $dbe->eof()) {
  158. $eq->DBLoad($dbe, "EQ");
  159. $eqmodifier->DBLoad($dbe, "EQM");
  160. $eqmodifier->updateFromEquipmentLevel($eq->get("level"));
  161. if ($eq->get("id_BasicTemplate") != 0) {
  162. $modifier->DBLoad($dbe, "MD");
  163. $modifier->updateFromTemplateLevel($eq->get("templateLevel"));
  164. $eqmodifier->addModifObj($modifier);
  165. }
  166. $eqmodifier->initCharacStr();
  167. $checkbox = "<input type='radio' name='IdBasic' value='" . $eq->get("id") . "'>";
  168. $name = "<b><span class='" . ($eq->get("maudit") == 1 ? "maudit" : "") . "'>" . localize($eq->get("name")) . "</span></b>";
  169. if ($eq->get("extraname") != "") {
  170. $tlevel = $eq->get("templateLevel");
  171. $name .= " " . "<span class='template'>" . localize($eq->get("extraname")) . "(" . $tlevel . ")</span>";
  172. }
  173. $name .= "<br/>" . localize("Niveau") . " " . $eq->get("level") . " (" . $eq->get("id") . ")<br/>";
  174. if ($eq->get("id_BasicEquipment") != 60 and $eq->get("id_BasicEquipment") != 61 and $eq->get("id_BasicEquipment") != 62 and $eq->get("id_BasicEquipment") != 58 and
  175. $eq->get("id_BasicEquipment") != 57 and $eq->get("id_BasicEquipment") != 56) {
  176. foreach ($eqmodifier->m_characLabel as $key) {
  177. $tmp = $eqmodifier->getModifStr($key);
  178. if ($tmp != "0") {
  179. $name .= " " . localize($key) . ": " . $tmp . " |";
  180. }
  181. }
  182. }
  183. $price = 0;
  184. $sellprice = $eq->get("sell");
  185. if ($sellprice == 0)
  186. $sellprice = "Non";
  187. else
  188. $sellprice .= " PO";
  189. if ($eq->get("extraname") != "")
  190. $price = floor(1000 * (($eq->get("templateLevel")) * ($eq->get("templateLevel"))) / $dbe->get("freq"));
  191. $price += floor(100 * ($eq->get("level") * $eq->get("level") + 1) / $dbe->get("frequency"));
  192. $zone = $dbe->get("zone");
  193. $array[] = array(
  194. "0" => array(
  195. $checkbox,
  196. "class='mainbgbody' align='center'"
  197. ),
  198. "1" => array(
  199. $name,
  200. "class='mainbgbody' align='left'"
  201. ),
  202. "2" => array(
  203. $zone,
  204. "class='mainbgbody' align='center'"
  205. ),
  206. "3" => array(
  207. $sellprice,
  208. "class='mainbgbody' align='center'"
  209. ),
  210. "4" => array(
  211. $price,
  212. "class='mainbgbody' align='center'"
  213. )
  214. );
  215. $dbe->next();
  216. }
  217. $str .= "</table>\n";
  218. $str .= createTable(5, $array, array(),
  219. array(
  220. array(
  221. "",
  222. "class='mainbglabel' width='5%' align='center'"
  223. ),
  224. array(
  225. localize("Nom et caractéristiques"),
  226. "class='mainbglabel' width='55%' align='center'",
  227. "EQ.name",
  228. "mainbglabelhover",
  229. "mainbglabel"
  230. ),
  231. array(
  232. localize("Nombre de Zone(s)"),
  233. "class='mainbglabel' width='10%' align='center'",
  234. "zone",
  235. "mainbglabelhover",
  236. "mainbglabel"
  237. ),
  238. array(
  239. localize("En vente"),
  240. "class='mainbglabel' width='15%' align='center'",
  241. "sellprice",
  242. "mainbglabelhover",
  243. "mainbglabel"
  244. ),
  245. array(
  246. localize("Prix de base"),
  247. "class='mainbglabel' width='15%' align='center'",
  248. "price",
  249. "mainbglabelhover",
  250. "mainbglabel"
  251. )
  252. ),
  253. "class='maintable centerareawidth'", "formid", "order");
  254. $str .= "<table class='maintable'><tr><td class='mainbgtitle' width='615px'>";
  255. $str .= "<input id='Take' type='submit' name='Take' value='" . localize("Prendre cet objet") . "' /></br></table>";
  256. $str .= "<table class='maintable'><tr><td class='mainbgtitle' width='615px'>";
  257. $str .= "<input id='Sell' type='submit' name='Sell' value='" . localize("Mettre en vente cet objet") . "' />";
  258. $str .= " à " . " <input type='text' name='PRICE' value'' maxlength=9 size=10/> " . localize("PO");
  259. $str .= "<br/></table>";
  260. $str .= "<input id='RemoveSell' type='submit' name='RemoveSell' value='" . localize("Supprimer de la vente cet objet") . "' />";
  261. $str .= "<br/></table>";
  262. $str .= "<input name='idform' type='hidden' value='" . getCurrentPageId() . "' />\n";
  263. $str .= "</form>\n";
  264. $str .= "<br>";
  265. // -------- POSER UN OBJET
  266. $str .= "<form name='form' method='POST' target='_self'>";
  267. $str .= "<table class='maintable'><tr><td class='mainbgtitle' width='550px'>";
  268. $str .= localize("Déposer dans l'entrepôt") . " <select id='Object' class='selector cqattackselectorsize' name='IdBasic'>";
  269. $gap = 0;
  270. $dbp = new DBCollection("SELECT * FROM Equipment WHERE weared=\"No\" AND id_Player=" . $id, $db, 0, 0);
  271. $item = array();
  272. $str .= "<option value='0' selected='selected'>" . localize("-- Équipement à déposer ?--") . "</option>";
  273. while (! $dbp->eof()) {
  274. if ($dbp->get("name") != "") {
  275. $item[] = array(
  276. localize($dbp->get("name")) . " " . localize("Niveau") . " " . $dbp->get("level") . " (" . $dbp->get("id") . ")" => $dbp->get("id")
  277. );
  278. }
  279. $dbp->next();
  280. }
  281. foreach ($item as $arr) {
  282. foreach ($arr as $key => $value) {
  283. if ($value == - 1)
  284. $str .= "<optgroup class='group' label='" . $key . "' />";
  285. else
  286. $str .= "<option value='" . $value . "'>" . $key . "</option>";
  287. }
  288. }
  289. $str .= "</select></td><td>";
  290. $str .= "<input id='Give' type='submit' name='Give' value='" . localize("Déposer") . "' />";
  291. $str .= "<input name='idform' type='hidden' value='" . getCurrentPageId() . "' />\n";
  292. $str .= "</td></tr></table>";
  293. $str .= "</form>";
  294. // FIN poser un objet
  295. } else {
  296. if ($str == "") {
  297. $str = "<form method='POST' action='" . CONFIG_HOST . '/conquest/conquest.php?center=warehouse&type=' . $type . "' target='_self'>\n";
  298. $str .= "<table class='maintable' width='620px'>\n";
  299. $str .= "<tr><td class='mainbgtitle' width='620px'>" . $err . "</td></tr></table>";
  300. $str .= "<input type='submit' name='back' value='" . localize("Terminer") . "' />";
  301. $str .= "<input name='idform' type='hidden' value='" . getCurrentPageId() . "' />\n";
  302. $str .= "</form>";
  303. }
  304. }
  305. return $str;
  306. }
  307. }
  308. ?>