data.func.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. include('inc/forms/form.edit.item.php');
  16. echo '
  17. <div class="row"><div class="col-lg-12"><h1><hr></hr></h1></div></div>
  18. <div class="row">
  19. '.get_item_edit_form($item).'
  20. </div>
  21. <p class="display-4 animated flipInX" style="font-size:22pt!important;"><i class="fad fa-debug text-danger"></i> Debug Output</p>
  22. <pre class="text-left panel-tag">'.print_r($item,1).'</pre>
  23. <script>
  24. $(\'#item-editor-header-label\').empty().append(\'<span class="inline animated bounceIn"><i class="fad fa-caret-right"></i> '.$item['name'].'</span>\');
  25. $(\'#item-editor-header-label\').switchClass("btn-info","btn-primary");
  26. </script>';
  27. }
  28. // Get item icons by selected category.
  29. if(isset($_POST['get-item-icons'])) {
  30. require('inc/json.item.icons.php');
  31. echo get_icon_picker($itemIcons, 'icons', $_POST['get-item-icons'], (isset($_POST['page']) ? $_POST['page']:1));
  32. }
  33. /* GET FUNCTIONS */
  34. function get_icon_picker($icons, $type = 'icons', $category = 'Adornment', $page = 1, $limit = 133, $return = NULL) {
  35. $pass = 0;
  36. if($type == 'categories') {
  37. $return .= '
  38. <button class="icopicker-category btn btn-sm btn-block btn-default" data-category="all">All</button>';
  39. foreach($icons as $c => $i) {
  40. $return .= '
  41. <button class="icopicker-category btn btn-sm btn-block btn-default" data-category="'.$c.'">
  42. '.$c.'
  43. </button>';
  44. $pass++;
  45. }
  46. $return .= '<script>setTimeout(function() { $(\'.icopicker-category[data-category="Adornment"]\').trigger(\'click\'); },500); </script>';
  47. } else {
  48. $from = ($limit*$page)-$limit;
  49. $to = ($limit*$page);
  50. $pass++;
  51. if($category == 'all') {
  52. $ico = [];
  53. foreach($icons as $c => $v) {
  54. foreach($v['icons'] as $i) {
  55. if(!in_array($i, $ico)) {
  56. $ico[] = $i;
  57. }
  58. }
  59. }
  60. } else {
  61. $ico = $icons[$category]['icons'];
  62. }
  63. $pass = 0;
  64. foreach($ico as $k => $i) {
  65. if(($pass >= $from) && ($pass+1 <= $to)) {
  66. $return .= '<div class="ico-picker-i ico-unloaded" data-icon-id="'.$i.'"><span class="ico-picker-loader"><i class="fad fa-circle-notch fa-spin fast-spin"></i></div>';
  67. }
  68. $pass++;
  69. }
  70. }
  71. $pagination = ($type == 'icons' ? '<div class="ico-picker-pagination">'.ico_pagination($category, $page, $limit, count($ico)).'</div>':NULL);
  72. return $pagination.$return;
  73. }
  74. //Generates pagination for icons.
  75. function ico_pagination($category, $p, $limit, $count, $return = NULL) {
  76. $return .= '<button class="btn btn-xs btn-default '.($p == 1 ? 'hidden':NULL).'" data-category="'.$category.'"><i class="fad fa-arrow-from-right"></i></button>';
  77. $page_count = ceil($count/$limit);
  78. if($page_count > 1) {
  79. if(($p-5) > 1) {
  80. $return .= '<span class="ico-picker-ellipsis"><i class="fas fa-ellipsis-h-alt"></i></span>';
  81. }
  82. for ($k = 1 ; $k <= $page_count; $k++){
  83. if(($k >= ($p-5)) && ($k <= ($p+5))) {
  84. $return .= '
  85. <button class="btn btn-xs ico-picker-page '.($p == $k ? 'btn-success':'btn-default').'" '.($p == $k ? 'disabled="disabled"':NULL).' data-page="'.$k.'" data-category="'.$category.'">
  86. '.$k.'
  87. </button>';
  88. }
  89. }
  90. if(($p+5) < $page_count) {
  91. $return .= '<span class="ico-picker-ellipsis"><i class="fas fa-ellipsis-h-alt"></i></span>';
  92. }
  93. } else {
  94. $return .= '
  95. <button class="btn btn-xs ico-picker-page btn-success" data-page="'.$p.'" data-category="'.$category.'" disabled="disabled">
  96. '.$p.'
  97. </button>';
  98. }
  99. $return .= '
  100. <button class="btn btn-xs btn-default ico-picker-page" data-category="'.$category.'" '.($p == $page_count ? 'disabled="disabled"':NULL).'>
  101. <i class="fad fa-arrow-from-left"></i>
  102. </button>';
  103. return $return;
  104. }
  105. //Global function to build editable inputs. (WIP)
  106. function build_edit_input($e, $return = NULL) {
  107. $return = '
  108. <div class="form-group">
  109. <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
  110. <div class="input-group">
  111. <div class="input-group-prepend">
  112. <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).'&nbsp;'.$e['title'].'</span>
  113. </div>
  114. <input
  115. type="text"
  116. class="form-control '.$e['class'].'"
  117. data-field="'.$e['field'].'"
  118. value="'.$e['value'].'"
  119. placeholder="'.($e['placeholder'] ? $e['placeholder']:NULL).'"
  120. aria-label="'.($e['aria'] ? $e['aria']:NULL).'"
  121. aria-describedby="'.$e['field'].'"
  122. />
  123. </div>
  124. <span class="help-block">'.($e['desc'] ? $e['desc']:'&nbsp;').'</span>
  125. </div>';
  126. return $return;
  127. }
  128. // Builds item edit form inputs & form.
  129. function get_item_edit_form($item, $return = NULL) {
  130. $pass = 0;
  131. $return .= '
  132. <div class="col-2 text-center">
  133. <img class="edit-item-ico vm" src="img/eq2/items/'.$item['icon'].'.png"/>
  134. </div>';
  135. foreach($item as $k => $v) {
  136. $return .= '
  137. <div class="col-'.($k == 'id' ? '2':'4').'">
  138. <div class="form-group">
  139. <label class="form-label hidden" for="basic-addon1">'.$k.'</label>
  140. <div class="input-group">
  141. <div class="input-group-prepend">
  142. <span class="input-group-text strong">'.$k.'</span>
  143. </div>
  144. <input type="text" class="form-control item-edit-input" value="'.$v.'" placeholder="'.$k.'" aria-label="'.$k.'" aria-describedby="'.$k.'">
  145. </div>
  146. <span class="help-block">&nbsp;</span>
  147. </div>
  148. </div>';
  149. }
  150. return $return;
  151. }
  152. // Get Item Data
  153. function get_item_data($id, $return = []) {
  154. global $world;
  155. $query = '
  156. SELECT
  157. i.`id`,
  158. i.`name`,
  159. i.`item_type`,
  160. i.`icon`,
  161. i.`count`,
  162. i.`tier`,
  163. i.`skill_id_req`,
  164. i.`skill_id_req2`,
  165. i.`skill_min`,
  166. i.`weight`,
  167. i.`description`,
  168. i.`show_name`,
  169. i.`attuneable`,
  170. i.`artifact`,
  171. i.`lore`,
  172. i.`temporary`,
  173. i.`notrade`,
  174. i.`novalue`,
  175. i.`nozone`,
  176. i.`nodestroy`,
  177. i.`crafted`,
  178. i.`good_only`,
  179. i.`evil_only`,
  180. i.`stacklore`,
  181. i.`lore_equip`,
  182. i.`flags_16384`,
  183. i.`flags_32768`,
  184. i.`ornate`,
  185. i.`heirloom`,
  186. i.`appearance_only`,
  187. i.`unlocked`,
  188. i.`reforged`,
  189. i.`norepair`,
  190. i.`etheral`,
  191. i.`refined`,
  192. i.`flags2_256`,
  193. i.`usable`,
  194. i.`slots`,
  195. i.`set_name`,
  196. i.`sell_price`,
  197. i.`sell_status_amount`,
  198. i.`stack_count`,
  199. i.`collectable`,
  200. i.`adornment_slot1`,
  201. i.`adornment_slot2`,
  202. i.`adornment_slot3`,
  203. i.`adornment_slot4`,
  204. i.`adornment_slot5`,
  205. i.`adornment_slot6`,
  206. i.`adornment_description`,
  207. i.`offers_quest_id`,
  208. i.`soe_autoquest_id`,
  209. i.`part_of_quest_id`,
  210. i.`quest_unknown`,
  211. i.`max_charges`,
  212. i.`display_charges`,
  213. i.`recommended_level`,
  214. i.`adventure_default_level`,
  215. i.`tradeskill_default_level`,
  216. i.`adventure_classes`,
  217. i.`tradeskill_classes`,
  218. i.`soe_item_id`,
  219. i.`soe_item_crc`,
  220. i.`lua_script`,
  221. i.`harvest`
  222. FROM `items` as `i`
  223. WHERE `i`.`id` = '.addslashes($id);
  224. $stmt = $world->prepare($query);
  225. $stmt->execute();
  226. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  227. $return = $row;
  228. return $return;
  229. }
  230. // Quick Item Search
  231. function quick_item_search($s, $limit = 100, $page = 0, $return = []) {
  232. global $world;
  233. $return = [
  234. 'found' => 0,
  235. 'count' => 0,
  236. 'rows' => [],
  237. 'limit' => $limit,
  238. 'page' => $page
  239. ];
  240. $query = '
  241. SELECT
  242. SQL_CALC_FOUND_ROWS
  243. i.`id`,
  244. i.`name`,
  245. i.`item_type`,
  246. i.`icon`
  247. FROM `items` as `i`
  248. WHERE i.`id` = \''.addslashes($s).'\'
  249. OR i.`name` LIKE \'%'.addslashes(str_replace(' ', '%%',$s)).'%\'
  250. OR LOWER(i.`item_type`) = LOWER(\''.addslashes($s).'\')
  251. LIMIT '.$limit;
  252. //error_log($query,1);
  253. $stmt = $world->prepare($query);
  254. $stmt->execute();
  255. $rc = $stmt->rowCount();
  256. if($rc > 0) {
  257. $return['found'] = get_found_count();
  258. $return['count'] = $rc;
  259. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  260. $return['rows'][] = $row;
  261. }
  262. }
  263. return $return;
  264. }
  265. //Returns count of rows found (if LIMIT had not been used).
  266. //Note: Requires SQL_CALC_FOUND_ROWS after SELECT.
  267. function get_found_count() {
  268. global $world;
  269. $query = 'SELECT FOUND_ROWS() as `found`;';
  270. $stmt = $world->prepare($query);
  271. $stmt->execute();
  272. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  273. return $row['found'];
  274. }
  275. //Returns count of characters.
  276. function get_character_count($return = 0) {
  277. global $world;
  278. $query = 'SELECT count(DISTINCT `id`) as `count` FROM `characters`';
  279. $stmt = $world->prepare($query);
  280. $stmt->execute();
  281. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  282. $return = $row['count'];
  283. return $return;
  284. }
  285. //Get World Information.
  286. function get_world_info($world_name = NULL, $return = []) {
  287. global $_db, $login;
  288. $world_name = ($world_name == NULL ? _world:$world_name);
  289. $query = '
  290. SELECT
  291. w.id,
  292. w.name,
  293. w.disabled,
  294. w.account,
  295. w.description,
  296. w.password,
  297. w.serverop,
  298. w.greenname,
  299. w.note,
  300. w.ip_address,
  301. w.login_version,
  302. DATE_FORMAT(FROM_UNIXTIME(w.lastseen), "%m/%d/%y %h:%i %p") AS `lastseen`
  303. FROM login_worldservers AS w
  304. WHERE w.name = \''.$world_name.'\'';
  305. $stmt = $login->prepare($query);
  306. $stmt->execute();
  307. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  308. $return = $row;
  309. return $return;
  310. }
  311. //Pulls variable data from world db.
  312. function get_world_variables($return = []) {
  313. global $world;
  314. $query = '
  315. SELECT
  316. v.variable_name,
  317. v.variable_value,
  318. v.comment
  319. FROM variables as v';
  320. $stmt = $world->prepare($query);
  321. $stmt->execute();
  322. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  323. $return[$row['variable_name']] = [
  324. 'value' => $row['variable_value'],
  325. 'desc' => $row['comment']
  326. ];
  327. }
  328. return $return;
  329. }
  330. /* UTILITY FUNCTIONS */
  331. // Loads HTML output for left navigation menu.
  332. function get_nav_menu($return = NULL) {
  333. global $_modules, $_SESSION;
  334. $active = $_SESSION[_sid]['view'];
  335. foreach($_modules as $k => $m) {
  336. $access = !empty(array_intersect($_SESSION[_sid]['user']['access'], $m['access']));
  337. if($access) {
  338. if($m['type'] == 'module') {
  339. $return .= '
  340. <li class="'.($active == $k ? 'active':NULL).' eq-nav-link" data-module="'.$k.'">
  341. <a class="waves-effect waves-themed" href="#" title="'.$m['desc'].'">
  342. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).'
  343. <span class="nav-link-text" data-il8n="nav.ui_components">'.$m['title'].'</span>
  344. </a>
  345. </li>';
  346. } else if($m['type'] == 'category') {
  347. $return .= '
  348. <li class="nav-title">
  349. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).' '.$m['title'].'
  350. </li>';
  351. }
  352. }
  353. }
  354. return $return;
  355. }
  356. ?>