data.func.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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>&nbsp;<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. if(!isset($e['type'])) { $e['type'] = 'text'; }
  108. if(!isset($e['field_type'])) {
  109. $return = '
  110. <div class="form-group mb-2">
  111. <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
  112. <div class="input-group">
  113. <div class="input-group-prepend">
  114. <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).'&nbsp;'.$e['title'].'</span>
  115. </div>
  116. <input type="'.$e['type'].'" class="form-control '.$e['class'].'" data-field="'.$e['field'].'" value="'.$e['value'].'" placeholder="'.($e['placeholder'] ? $e['placeholder']:NULL).'" aria-label="'.($e['aria'] ? $e['aria']:NULL).'" aria-describedby="'.$e['field'].'"/>
  117. </div>
  118. </div>';
  119. } else {
  120. if($e['field_type'] == 'textarea') {
  121. $return = '
  122. <div class="form-group mb-2">
  123. <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
  124. <div class="input-group">
  125. <div class="input-group-prepend">
  126. <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).'&nbsp;'.$e['title'].'</span>
  127. </div>
  128. <textarea class="form-control '.$e['class'].'" data-field="'.$e['field'].'" placeholder="'.($e['placeholder'] ? $e['placeholder']:NULL).'" aria-label="'.($e['aria'] ? $e['aria']:NULL).'" aria-describedby="'.$e['field'].'">'
  129. .$e['value'].
  130. '</textarea>
  131. </div>
  132. <span class="help-block">'.($e['desc'] ? $e['desc']:NULL).'</span>
  133. </div>';
  134. } else if($e['field_type'] == 'select') {
  135. $return = '
  136. <div class="form-group mb-2">
  137. <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
  138. <div class="input-group">
  139. <div class="input-group-prepend">
  140. <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).'&nbsp;'.$e['title'].'</span>
  141. </div>
  142. <select class="custom-select form-control'.$e['class'].'" data-field="'.$e['field'].'">
  143. <option selected="selected" value="'.$e['value'].'">'.$e['value'].'</option>
  144. '.(array_to_options($e['options'], $e['value'])).'
  145. </select>
  146. <span class="help-block">'.($e['desc'] ? $e['desc']:NULL).'</span>
  147. </div>';
  148. } else if($e['field_type'] == 'switch') {
  149. $return = '
  150. <div class="custom-control custom-switch">
  151. <input type="checkbox" class="custom-control-input '.$e['class'].'" '.($e['value'] == 1 ? 'checked="checked"':NULL).' id="ies_'.$e['field'].'" name="ie_'.$e['field'].'_'.$e['id'].'" data-field="'.$e['field'].'">
  152. <label class="custom-control-label '.($e['show-label'] ? NULL:'hidden').'" for="ies_'.$e['field'].'">'.(strlen($e['icon']) > 0 ? '<i class="'.$e['icon'].'"></i> ':NULL).$e['title'].'</label>
  153. </div>'.($e['desc'] ? '<span class="help-block">'.$e['desc'].'</span>':NULL);
  154. }
  155. }
  156. return $return;
  157. }
  158. $exclude_debug_fieldlist = [
  159. 'icon','id','name','item_type','lore','temporary','artifact','notrade','nodestroy','show_name',
  160. 'crafted'
  161. ];
  162. //Convert array to select option values with option to exclude a pre-selected value.
  163. function array_to_options($a, $preselected = NULL, $return = NULL) {
  164. foreach($a as $k => $v) {
  165. if($preselected != $v) {
  166. $return .= '
  167. <option value="'.$v.'">'.$v.'</option>';
  168. }
  169. }
  170. return $return;
  171. }
  172. // Builds list of item skills in option format
  173. function get_skills($skill_ids = [], $return = NULL) {
  174. global $world;
  175. $query = '
  176. SELECT
  177. s.*
  178. FROM skills AS s
  179. WHERE s.`id` IN(1743366740,1756482397,3587918036,3539032716,1386343008,1039865549,4032608519,3330500131,2072844078,1408356869,2650425026,2639209773)';
  180. //The listed ID's appeared in no original items that were listed as skill requirements.
  181. }
  182. // Builds item edit form inputs & form. - Deprecated! Only for debugging.
  183. function get_item_edit_form($item, $return = NULL) {
  184. global $exclude_debug_fieldlist;
  185. $pass = 0;
  186. foreach($item as $k => $v) {
  187. if(!in_array($k,$exclude_debug_fieldlist)) {
  188. $return .= '
  189. <div class="col-'.($k == 'id' ? '2':'4').'">
  190. <div class="form-group">
  191. <label class="form-label hidden" for="basic-addon1">'.$k.'</label>
  192. <div class="input-group">
  193. <div class="input-group-prepend">
  194. <span class="input-group-text strong">'.$k.'</span>
  195. </div>
  196. <input type="text" class="form-control item-edit-input" value="'.$v.'" placeholder="'.$k.'" aria-label="'.$k.'" aria-describedby="'.$k.'">
  197. </div>
  198. <span class="help-block">&nbsp;</span>
  199. </div>
  200. </div>';
  201. }
  202. }
  203. return $return;
  204. }
  205. // Get Item Data
  206. function get_item_data($id, $return = []) {
  207. global $world;
  208. $query = '
  209. SELECT
  210. i.`id`,
  211. i.`name`,
  212. i.`item_type`,
  213. i.`icon`,
  214. i.`count`,
  215. i.`tier`,
  216. i.`skill_id_req`,
  217. i.`skill_id_req2`,
  218. i.`skill_min`,
  219. i.`weight`,
  220. i.`description`,
  221. i.`show_name`,
  222. i.`attuneable`,
  223. i.`artifact`,
  224. i.`lore`,
  225. i.`temporary`,
  226. i.`notrade`,
  227. i.`novalue`,
  228. i.`nozone`,
  229. i.`nodestroy`,
  230. i.`crafted`,
  231. i.`good_only`,
  232. i.`evil_only`,
  233. i.`stacklore`,
  234. i.`lore_equip`,
  235. i.`flags_16384`,
  236. i.`flags_32768`,
  237. i.`ornate`,
  238. i.`heirloom`,
  239. i.`appearance_only`,
  240. i.`unlocked`,
  241. i.`reforged`,
  242. i.`norepair`,
  243. i.`etheral`,
  244. i.`refined`,
  245. i.`flags2_256`,
  246. i.`usable`,
  247. i.`slots`,
  248. i.`set_name`,
  249. i.`sell_price`,
  250. i.`sell_status_amount`,
  251. i.`stack_count`,
  252. i.`collectable`,
  253. i.`adornment_slot1`,
  254. i.`adornment_slot2`,
  255. i.`adornment_slot3`,
  256. i.`adornment_slot4`,
  257. i.`adornment_slot5`,
  258. i.`adornment_slot6`,
  259. i.`adornment_description`,
  260. i.`offers_quest_id`,
  261. i.`soe_autoquest_id`,
  262. i.`part_of_quest_id`,
  263. i.`quest_unknown`,
  264. i.`max_charges`,
  265. i.`display_charges`,
  266. i.`recommended_level`,
  267. i.`adventure_default_level`,
  268. i.`tradeskill_default_level`,
  269. i.`adventure_classes`,
  270. i.`tradeskill_classes`,
  271. i.`soe_item_id`,
  272. i.`soe_item_crc`,
  273. i.`lua_script`,
  274. i.`harvest`
  275. FROM `items` as `i`
  276. WHERE `i`.`id` = '.addslashes($id);
  277. $stmt = $world->prepare($query);
  278. $stmt->execute();
  279. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  280. $return = $row;
  281. return $return;
  282. }
  283. // Quick Item Search
  284. function quick_item_search($s, $limit = 100, $page = 0, $return = []) {
  285. global $world;
  286. $return = [
  287. 'found' => 0,
  288. 'count' => 0,
  289. 'rows' => [],
  290. 'limit' => $limit,
  291. 'page' => $page
  292. ];
  293. $query = '
  294. SELECT
  295. SQL_CALC_FOUND_ROWS
  296. i.`id`,
  297. i.`name`,
  298. i.`item_type`,
  299. i.`icon`
  300. FROM `items` as `i`
  301. WHERE i.`id` = \''.addslashes($s).'\'
  302. OR i.`name` LIKE \'%'.addslashes(str_replace(' ', '%%',$s)).'%\'
  303. OR LOWER(i.`item_type`) = LOWER(\''.addslashes($s).'\')
  304. LIMIT '.$limit;
  305. //error_log($query,1);
  306. $stmt = $world->prepare($query);
  307. $stmt->execute();
  308. $rc = $stmt->rowCount();
  309. if($rc > 0) {
  310. $return['found'] = get_found_count();
  311. $return['count'] = $rc;
  312. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  313. $return['rows'][] = $row;
  314. }
  315. }
  316. return $return;
  317. }
  318. //Returns count of rows found (if LIMIT had not been used).
  319. //Note: Requires SQL_CALC_FOUND_ROWS after SELECT.
  320. function get_found_count() {
  321. global $world;
  322. $query = 'SELECT FOUND_ROWS() as `found`;';
  323. $stmt = $world->prepare($query);
  324. $stmt->execute();
  325. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  326. return $row['found'];
  327. }
  328. //Returns count of characters.
  329. function get_character_count($return = 0) {
  330. global $world;
  331. $query = 'SELECT count(DISTINCT `id`) as `count` FROM `characters`';
  332. $stmt = $world->prepare($query);
  333. $stmt->execute();
  334. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  335. $return = $row['count'];
  336. return $return;
  337. }
  338. //Get World Information.
  339. function get_world_info($world_name = NULL, $return = []) {
  340. global $_db, $login;
  341. $world_name = ($world_name == NULL ? _world:$world_name);
  342. $query = '
  343. SELECT
  344. w.id,
  345. w.name,
  346. w.disabled,
  347. w.account,
  348. w.description,
  349. w.password,
  350. w.serverop,
  351. w.greenname,
  352. w.note,
  353. w.ip_address,
  354. w.login_version,
  355. DATE_FORMAT(FROM_UNIXTIME(w.lastseen), "%m/%d/%y %h:%i %p") AS `lastseen`
  356. FROM login_worldservers AS w
  357. WHERE w.name = \''.$world_name.'\'';
  358. $stmt = $login->prepare($query);
  359. $stmt->execute();
  360. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  361. $return = $row;
  362. return $return;
  363. }
  364. //Pulls variable data from world db.
  365. function get_world_variables($return = []) {
  366. global $world;
  367. $query = '
  368. SELECT
  369. v.variable_name,
  370. v.variable_value,
  371. v.comment
  372. FROM variables as v';
  373. $stmt = $world->prepare($query);
  374. $stmt->execute();
  375. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  376. $return[$row['variable_name']] = [
  377. 'value' => $row['variable_value'],
  378. 'desc' => $row['comment']
  379. ];
  380. }
  381. return $return;
  382. }
  383. /* UTILITY FUNCTIONS */
  384. // Loads HTML output for left navigation menu.
  385. function get_nav_menu($return = NULL) {
  386. global $_modules, $_SESSION;
  387. $active = $_SESSION[_sid]['view'];
  388. foreach($_modules as $k => $m) {
  389. $access = !empty(array_intersect($_SESSION[_sid]['user']['access'], $m['access']));
  390. if($access) {
  391. if($m['type'] == 'module') {
  392. $return .= '
  393. <li class="'.($active == $k ? 'active':NULL).' eq-nav-link" data-module="'.$k.'">
  394. <a class="waves-effect waves-themed" href="#" title="'.$m['desc'].'">
  395. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).'
  396. <span class="nav-link-text" data-il8n="nav.ui_components">'.$m['title'].'</span>
  397. </a>
  398. </li>';
  399. } else if($m['type'] == 'category') {
  400. $return .= '
  401. <li class="nav-title">
  402. '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).' '.$m['title'].'
  403. </li>';
  404. }
  405. }
  406. }
  407. return $return;
  408. }
  409. ?>