data.func.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /* REQUEST HANDLING */
  3. // Handle navigation request & update session.
  4. if(isset($_POST['set-navigation'])) {
  5. $_SESSION[_sid]['view'] = $_POST['set-navigation'];
  6. echo $_SESSION[_sid]['view'];
  7. }
  8. // Get item data with quick search.
  9. if(isset($_POST['quick-item-search'])) {
  10. echo json_encode(quick_item_search($_POST['quick-item-search']));
  11. }
  12. // Get item to be edited.
  13. if(isset($_POST['get-edit-item'])) {
  14. $item = get_item_data($_POST['get-edit-item']);
  15. echo '
  16. <div class="row">
  17. '.get_item_edit_form($item).'
  18. </div>
  19. <p class="display-4 animated flipInX" style="font-size:22pt!important;"><i class="fad fa-debug text-danger"></i> Debug Output</p>
  20. <pre class="text-left panel-tag">'.print_r($item,1).'</pre>
  21. <script>
  22. $(\'#item-editor-header-label\').empty().append(\'<span class="inline animated bounceIn"><i class="fad fa-caret-right"></i> '.$item['name'].'</span>\');
  23. $(\'#item-editor-header-label\').switchClass("btn-info","btn-primary");
  24. </script>';
  25. }
  26. /* GET FUNCTIONS */
  27. // Builds item edit form inputs & form.
  28. function get_item_edit_form($item, $return = NULL) {
  29. $pass = 0;
  30. $return .= '
  31. <div class="col-2 text-center">
  32. <img class="edit-item-ico vm" src="img/eq2/items/'.$item['icon'].'.png"/>
  33. </div>';
  34. foreach($item as $k => $v) {
  35. $return .= '
  36. <div class="col-'.($k == 'id' ? '2':'4').'">
  37. <div class="form-group">
  38. <label class="form-label hidden" for="basic-addon1">'.$k.'</label>
  39. <div class="input-group">
  40. <div class="input-group-prepend">
  41. <span class="input-group-text strong">'.$k.'</span>
  42. </div>
  43. <input type="text" class="form-control item-edit-input" value="'.$v.'" placeholder="'.$k.'" aria-label="'.$k.'" aria-describedby="'.$k.'">
  44. </div>
  45. <span class="help-block">&nbsp;</span>
  46. </div>
  47. </div>';
  48. }
  49. return $return;
  50. }
  51. // Get Item Data
  52. function get_item_data($id, $return = []) {
  53. global $world;
  54. $query = '
  55. SELECT
  56. i.`id`,
  57. i.`name`,
  58. i.`item_type`,
  59. i.`icon`,
  60. i.`count`,
  61. i.`tier`,
  62. i.`skill_id_req`,
  63. i.`skill_id_req2`,
  64. i.`skill_min`,
  65. i.`weight`,
  66. i.`description`,
  67. i.`show_name`,
  68. i.`attuneable`,
  69. i.`artifact`,
  70. i.`lore`,
  71. i.`temporary`,
  72. i.`notrade`,
  73. i.`novalue`,
  74. i.`nozone`,
  75. i.`nodestroy`,
  76. i.`crafted`,
  77. i.`good_only`,
  78. i.`evil_only`,
  79. i.`stacklore`,
  80. i.`lore_equip`,
  81. i.`flags_16384`,
  82. i.`flags_32768`,
  83. i.`ornate`,
  84. i.`heirloom`,
  85. i.`appearance_only`,
  86. i.`unlocked`,
  87. i.`reforged`,
  88. i.`norepair`,
  89. i.`etheral`,
  90. i.`refined`,
  91. i.`flags2_256`,
  92. i.`usable`,
  93. i.`slots`,
  94. i.`set_name`,
  95. i.`sell_price`,
  96. i.`sell_status_amount`,
  97. i.`stack_count`,
  98. i.`collectable`,
  99. i.`adornment_slot1`,
  100. i.`adornment_slot2`,
  101. i.`adornment_slot3`,
  102. i.`adornment_slot4`,
  103. i.`adornment_slot5`,
  104. i.`adornment_slot6`,
  105. i.`adornment_description`,
  106. i.`offers_quest_id`,
  107. i.`soe_autoquest_id`,
  108. i.`part_of_quest_id`,
  109. i.`quest_unknown`,
  110. i.`max_charges`,
  111. i.`display_charges`,
  112. i.`recommended_level`,
  113. i.`adventure_default_level`,
  114. i.`tradeskill_default_level`,
  115. i.`adventure_classes`,
  116. i.`tradeskill_classes`,
  117. i.`soe_item_id`,
  118. i.`soe_item_crc`,
  119. i.`lua_script`,
  120. i.`harvest`
  121. FROM `items` as `i`
  122. WHERE `i`.`id` = '.addslashes($id);
  123. $stmt = $world->prepare($query);
  124. $stmt->execute();
  125. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  126. $return = $row;
  127. return $return;
  128. }
  129. // Quick Item Search
  130. function quick_item_search($s, $limit = 100, $page = 0, $return = []) {
  131. global $world;
  132. $return = [
  133. 'found' => 0,
  134. 'count' => 0,
  135. 'rows' => [],
  136. 'limit' => $limit,
  137. 'page' => $page
  138. ];
  139. $query = '
  140. SELECT
  141. SQL_CALC_FOUND_ROWS
  142. i.`id`,
  143. i.`name`,
  144. i.`item_type`,
  145. i.`icon`
  146. FROM `items` as `i`
  147. WHERE i.`id` = \''.addslashes($s).'\'
  148. OR i.`name` LIKE \'%'.addslashes(str_replace(' ', '%%',$s)).'%\'
  149. OR LOWER(i.`item_type`) = LOWER(\''.addslashes($s).'\')
  150. LIMIT '.$limit;
  151. //error_log($query,1);
  152. $stmt = $world->prepare($query);
  153. $stmt->execute();
  154. $rc = $stmt->rowCount();
  155. if($rc > 0) {
  156. $return['found'] = get_found_count();
  157. $return['count'] = $rc;
  158. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  159. $return['rows'][] = $row;
  160. }
  161. }
  162. return $return;
  163. }
  164. //Returns count of rows found (if LIMIT had not been used).
  165. //Note: Requires SQL_CALC_FOUND_ROWS after SELECT.
  166. function get_found_count() {
  167. global $world;
  168. $query = 'SELECT FOUND_ROWS() as `found`;';
  169. $stmt = $world->prepare($query);
  170. $stmt->execute();
  171. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  172. return $row['found'];
  173. }
  174. //Returns count of characters.
  175. function get_character_count($return = 0) {
  176. global $world;
  177. $query = 'SELECT count(DISTINCT `id`) as `count` FROM `characters`';
  178. $stmt = $world->prepare($query);
  179. $stmt->execute();
  180. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  181. $return = $row['count'];
  182. return $return;
  183. }
  184. //Get World Information.
  185. function get_world_info($world_name = NULL, $return = []) {
  186. global $_db, $login;
  187. $world_name = ($world_name == NULL ? _world:$world_name);
  188. $query = '
  189. SELECT
  190. w.id,
  191. w.name,
  192. w.disabled,
  193. w.account,
  194. w.description,
  195. w.password,
  196. w.serverop,
  197. w.greenname,
  198. w.note,
  199. w.ip_address,
  200. w.login_version,
  201. DATE_FORMAT(FROM_UNIXTIME(w.lastseen), "%m/%d/%y %h:%i %p") AS `lastseen`
  202. FROM login_worldservers AS w
  203. WHERE w.name = \''.$world_name.'\'';
  204. $stmt = $login->prepare($query);
  205. $stmt->execute();
  206. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  207. $return = $row;
  208. return $return;
  209. }
  210. //Pulls variable data from world db.
  211. function get_world_variables($return = []) {
  212. global $world;
  213. $query = '
  214. SELECT
  215. v.variable_name,
  216. v.variable_value,
  217. v.comment
  218. FROM variables as v';
  219. $stmt = $world->prepare($query);
  220. $stmt->execute();
  221. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  222. $return[$row['variable_name']] = [
  223. 'value' => $row['variable_value'],
  224. 'desc' => $row['comment']
  225. ];
  226. }
  227. return $return;
  228. }
  229. /* UTILITY FUNCTIONS */
  230. // Loads HTML output for left navigation menu.
  231. function get_nav_menu($return = NULL) {
  232. global $_modules, $_SESSION;
  233. $active = $_SESSION[_sid]['view'];
  234. foreach($_modules as $k => $m) {
  235. $access = !empty(array_intersect($_SESSION[_sid]['user']['access'], $m['access']));
  236. if($access) {
  237. if($m['type'] == 'module') {
  238. $return .= '
  239. <li class="'.($active == $k ? 'active':NULL).' eq-nav-link" data-module="'.$k.'">
  240. <a class="waves-effect waves-themed" href="#" title="'.$m['desc'].'">
  241. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).'
  242. <span class="nav-link-text" data-il8n="nav.ui_components">'.$m['title'].'</span>
  243. </a>
  244. </li>';
  245. } else if($m['type'] == 'category') {
  246. $return .= '
  247. <li class="nav-title">
  248. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).' '.$m['title'].'
  249. </li>';
  250. }
  251. }
  252. }
  253. return $return;
  254. }
  255. ?>