123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- <?php
- /* REQUEST HANDLING */
-
- // Handle navigation request & update session.
- if(isset($_POST['set-navigation'])) {
- $_SESSION[_sid]['view'] = $_POST['set-navigation'];
- echo $_SESSION[_sid]['view'];
- }
- // Get item data with quick search.
- if(isset($_POST['quick-item-search'])) {
- echo json_encode(quick_item_search($_POST['quick-item-search']));
- }
- // Get item data with quick search.
- if(isset($_POST['edit-item'])) {
- echo json_encode(edit_item($_POST['data']));
- }
-
- // Get item to be edited.
- if(isset($_POST['get-edit-item'])) {
- $item = get_item_data($_POST['get-edit-item']);
- include('inc/forms/form.edit.item.php');
- echo '
- <div class="row"><div class="col-lg-12"><h1> <hr></hr></h1></div></div>
- <div class="row">
- '.get_item_edit_form($item).'
- </div>
-
-
-
-
- <p class="display-4 animated flipInX" style="font-size:22pt!important;"><i class="fad fa-debug text-danger"></i> Debug Output</p>
- <pre class="text-left panel-tag">'.print_r($item,1).'</pre>
- <script>
- $(\'#item-editor-header-label\').empty().append(\'<span class="inline animated bounceIn"><i class="fad fa-caret-right"></i> '.$item['name'].'</span>\');
- $(\'#item-editor-header-label\').switchClass("btn-info","btn-primary");
- </script>';
- }
-
-
- // Get item icons by selected category.
- if(isset($_POST['get-item-icons'])) {
- require('inc/data.item.icons.php');
- echo get_icon_picker($itemIcons, 'icons', $_POST['get-item-icons'], (isset($_POST['page']) ? $_POST['page']:1));
- }
-
- /* GET FUNCTIONS */
-
- /* Edit Item Function */
- function edit_item($data, $return = ['status'=>true, 'msg'=>'', 'rows'=>0]) {
- global $world;
-
- foreach($data as $table => $o) {
- $query = '
- UPDATE `'.addslashes($table).'`
- SET';
- $pass = 0;
- foreach($o['fields'] as $field => $value) {
- $query .= ($pass > 0 ? ',':NULL).'
- `'.addslashes($field).'` = "'.addslashes($value).'"';
- $pass++;
- }
- $query .= '
- WHERE `'.addslashes($o['key']).'` = '.addslashes($o['id']);
- $return['query'] = $query;
- try {
- $stmt = $world->prepare($query);
- $stmt->execute();
- $return['rows'] = $stmt->rowCount();
- $return['status'] = true;
- } catch(PDOException $e) {
- $return['status'] = false;
- $return['msg'] = $e->getMessage();
- }
- }
- return $return;
- }
-
-
-
-
- function get_icon_picker($icons, $type = 'icons', $category = 'Adornment', $page = 1, $limit = 133, $return = NULL) {
- $pass = 0;
- if($type == 'categories') {
- $return .= '
- <button class="icopicker-category btn btn-sm btn-block btn-default" data-category="all">All</button>';
- foreach($icons as $c => $i) {
- $return .= '
- <button class="icopicker-category btn btn-sm btn-block btn-default" data-category="'.$c.'">
- '.$c.'
- </button>';
- $pass++;
- }
- $return .= '<script>setTimeout(function() { $(\'.icopicker-category[data-category="Adornment"]\').trigger(\'click\'); },500); </script>';
- } else {
- $from = ($limit*$page)-$limit;
- $to = ($limit*$page);
- $pass++;
-
- if($category == 'all') {
- $ico = [];
- foreach($icons as $c => $v) {
- foreach($v['icons'] as $i) {
- if(!in_array($i, $ico)) {
- $ico[] = $i;
- }
- }
- }
- } else {
- $ico = $icons[$category]['icons'];
- }
- $pass = 0;
- foreach($ico as $k => $i) {
- if(($pass >= $from) && ($pass+1 <= $to)) {
- $return .= '<div class="ico-picker-i ico-unloaded" data-icon-id="'.$i.'"><span class="ico-picker-loader"><i class="fal fa-circle-notch color-info-400 fa-spin fast-spin opacity-50"></i></div>';
- }
- $pass++;
- }
- }
- $pagination = ($type == 'icons' ? '<div class="ico-picker-pagination">'.ico_pagination($category, $page, $limit, count($ico)).'</div>':NULL);
- return $pagination.$return;
- }
-
- //Generates pagination for icons.
- function ico_pagination($category, $p, $limit, $count, $return = NULL) {
- $return .= '<button class="btn btn-xs btn-default '.($p == 1 ? 'hidden':NULL).'" data-category="'.$category.'"><strong class="color-info-400">1</strong> <i class="fad fa-arrow-from-right"></i></button>';
- $page_count = ceil($count/$limit);
- $showEndButton = false;
- if($page_count > 1) {
- if(($p-5) > 1) {
- $return .= '<span class="ico-picker-ellipsis"><i class="fas fa-ellipsis-h-alt"></i></span>';
- }
- for ($k = 1 ; $k <= $page_count; $k++){
- if(($k >= ($p-5)) && ($k <= ($p+5))) {
- $return .= '
- <button class="btn btn-xs ico-picker-page '.($p == $k ? 'btn-success animated jello':'btn-default').'" '.($p == $k ? 'disabled="disabled"':NULL).' data-page="'.$k.'" data-category="'.$category.'">
- '.$k.'
- </button>';
- }
- }
- if(($p+5) < $page_count) {
- $return .= '<span class="ico-picker-ellipsis"><i class="fas fa-ellipsis-h-alt"></i></span>';
- $showEndButton = true;
- } else { $showEndButton = false; }
- } else {
- $return .= '
- <button class="btn btn-xs ico-picker-page btn-success" data-page="'.$p.'" data-category="'.$category.'" disabled="disabled">
- '.$p.'
- </button>';
- }
- if($showEndButton && $p != $page_count) {
- $return .= '
- <button class="btn btn-xs btn-default ico-picker-page" data-page="'.$page_count.'" data-category="'.$category.'">
- <i class="fad fa-arrow-from-left"></i> <strong class="color-info-400">'.$page_count.'</strong>
- </button>';
- }
- return $return;
- }
-
-
- //Global function to build editable inputs. (WIP)
- function build_edit_input($e, $return = NULL) {
- if(!isset($e['type'])) { $e['type'] = 'text'; }
- if(!isset($e['table'])) { $table = 'data-table=""'; } else { $table = 'data-table="'.$e['table'].'"'; }
- if(!isset($e['field_type'])) {
- $return = '
- <div class="form-group mb-2">
- <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).' '.$e['title'].'</span>
- </div>
- <input type="'.$e['type'].'" class="form-control '.$e['class'].'" '.$table.' data-key="'.$e['key'].'" data-id="'.$e['id'].'" data-field="'.$e['field'].'" value="'.$e['value'].'" placeholder="'.($e['placeholder'] ? $e['placeholder']:NULL).'" aria-label="'.($e['aria'] ? $e['aria']:NULL).'" aria-describedby="'.$e['field'].'"/>
- </div>'.($e['desc'] ? '<span class="help-block">'.$e['desc'].'</span>':NULL).'
- </div>';
- } else {
- if($e['field_type'] == 'textarea') {
- $return = '
- <div class="form-group mb-2">
- <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).' '.$e['title'].'</span>
- </div>
- <textarea class="form-control '.$e['class'].'" '.$table.' data-key="'.$e['key'].'" data-id="'.$e['id'].'" data-field="'.$e['field'].'" placeholder="'.($e['placeholder'] ? $e['placeholder']:NULL).'" aria-label="'.($e['aria'] ? $e['aria']:NULL).'" aria-describedby="'.$e['field'].'">'
- .$e['value'].
- '</textarea>
- </div>'.($e['desc'] ? '<span class="help-block">'.$e['desc'].'</span>':NULL).'
- </div>';
- } else if($e['field_type'] == 'select') {
- $return = '
- <div class="form-group mb-2">
- <label class="form-label '.($e['show-label'] ? NULL:'hidden').'" for="basic-addon1">'.$e['title'].'</label>
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text strong">'.($e['icon'] ? '<i class="'.$e['icon'].'"></i>':NULL).' '.$e['title'].'</span>
- </div>
- <select class="custom-select form-control '.$e['class'].'" '.$table.' data-key="'.$e['key'].'" data-id="'.$e['id'].'" data-field="'.$e['field'].'">
- '.(array_to_options($e['options'], $e['value'])).'
- </select>
- </div>'.($e['desc'] ? '<span class="help-block">'.$e['desc'].'</span>':NULL).'
- </div>';
- } else if($e['field_type'] == 'switch') {
- $return = '
- <div class="custom-control custom-switch">
- <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'].'" '.$table.' data-key="'.$e['key'].'" data-id="'.$e['id'].'" data-field="'.$e['field'].'">
- <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>
- </div>'.($e['desc'] ? '<span class="help-block">'.$e['desc'].'</span>':NULL);
- }
- }
- return $return;
- }
-
- $exclude_debug_fieldlist = [
- 'icon','id','name','item_type','lore','temporary','artifact','notrade','nodestroy','show_name',
- 'crafted'
- ];
-
-
-
- //Convert array to select option values with option to exclude a pre-selected value.
- function array_to_options($a, $preselected = NULL, $return = NULL) {
- foreach($a as $k => $v) {
- if(isset($v['id'])) {
- //Template Array: ['id'=>$row['id'], 'short'=>$row['short_name'], 'name'=>$row['name'], 'desc'=>$row['description']];
- $return .= '
- <option value="'.$v['id'].'" data-desc="'.$v['desc'].'" '.($preselected == $v['id'] ? 'selected="selected"':NULL).'>'.$v['name'].' ('.$v['id'].')</option>';
-
- } else { //For 2d arrays
- $return .= '
- <option value="'.$v.'" '.($preselected == $v ? 'selected="selected"':NULL).'>'.$v.'</option>';
- }
- }
- return $return;
- }
-
-
- // Builds list of item skills in option format
- function get_skills($skill_ids = [], $get_array = false, $return = NULL) {
- global $world;
- $query = '
- SELECT
- s.`id`,
- s.`short_name`,
- s.`name`,
- s.`description`,
- s.`skill_type`,
- s.`display`
- FROM skills AS s
- '.(count($skill_ids) > 0 ? 'WHERE s.`id` IN('.implode(', ',$skill_ids).')':NULL).'
- ORDER BY s.`skill_type`, s.`name`';
- //The listed ID's appeared in no original items that were listed as skill requirements.
- $stmt = $world->prepare($query);
- $stmt->execute();
-
- if($get_array) {
- $return = [['id'=>0, 'short'=>'none', 'name'=>'None', 'desc'=>NULL]];
- } else {
- $return .= '<option value="0" data-shortname="none" data-desc="">None</option>';
- }
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- if($get_array) {
- $return[] = ['id'=>$row['id'], 'short'=>$row['short_name'], 'name'=>$row['name'], 'desc'=>$row['description']];
- } else {
- $return .= '<option value="'.$row['id'].'" data-shortname="'.$row['short_name'].'" data-desc="'.$row['description'].'">'.$row['name'].'('.$row['id'].')</option>';
- }
- }
- return $return;
- }
-
- // Builds item edit form inputs & form. - Deprecated! Only for debugging.
- function get_item_edit_form($item, $return = NULL) {
- global $exclude_debug_fieldlist;
- $pass = 0;
- foreach($item as $k => $v) {
- if(!in_array($k,$exclude_debug_fieldlist)) {
- $return .= '
- <div class="col-'.($k == 'id' ? '2':'4').'">
- <div class="form-group">
- <label class="form-label hidden" for="basic-addon1">'.$k.'</label>
- <div class="input-group">
- <div class="input-group-prepend">
- <span class="input-group-text strong">'.$k.'</span>
- </div>
- <input type="text" class="form-control item-edit-input" value="'.$v.'" placeholder="'.$k.'" aria-label="'.$k.'" aria-describedby="'.$k.'">
- </div>
- <span class="help-block"> </span>
- </div>
- </div>';
- }
- }
- return $return;
- }
-
- // Get Item Data
- function get_item_data($id, $return = []) {
- global $world;
- $query = '
- SELECT
- i.`id`,
- i.`name`,
- i.`item_type`,
- i.`icon`,
- i.`count`,
- i.`tier`,
- i.`skill_id_req`,
- i.`skill_id_req2`,
- i.`skill_min`,
- i.`weight`,
- i.`description`,
- i.`show_name`,
- i.`attuneable`,
- i.`artifact`,
- i.`lore`,
- i.`temporary`,
- i.`notrade`,
- i.`novalue`,
- i.`nozone`,
- i.`nodestroy`,
- i.`crafted`,
- i.`good_only`,
- i.`evil_only`,
- i.`stacklore`,
- i.`lore_equip`,
- i.`flags_16384`,
- i.`flags_32768`,
- i.`ornate`,
- i.`heirloom`,
- i.`appearance_only`,
- i.`unlocked`,
- i.`reforged`,
- i.`norepair`,
- i.`etheral`,
- i.`refined`,
- i.`flags2_256`,
- i.`usable`,
- i.`slots`,
- i.`set_name`,
- i.`sell_price`,
- i.`sell_status_amount`,
- i.`stack_count`,
- i.`collectable`,
- i.`adornment_slot1`,
- i.`adornment_slot2`,
- i.`adornment_slot3`,
- i.`adornment_slot4`,
- i.`adornment_slot5`,
- i.`adornment_slot6`,
- i.`adornment_description`,
- i.`offers_quest_id`,
- i.`soe_autoquest_id`,
- i.`part_of_quest_id`,
- i.`quest_unknown`,
- i.`max_charges`,
- i.`display_charges`,
- i.`recommended_level`,
- i.`adventure_default_level`,
- i.`tradeskill_default_level`,
- i.`adventure_classes`,
- i.`tradeskill_classes`,
- i.`soe_item_id`,
- i.`soe_item_crc`,
- i.`lua_script`,
- i.`harvest`
- FROM `items` as `i`
- WHERE `i`.`id` = '.addslashes($id);
- $stmt = $world->prepare($query);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $return = $row;
- return $return;
- }
-
- // Quick Item Search
- function quick_item_search($s, $limit = 100, $page = 0, $return = []) {
- global $world;
- $return = [
- 'found' => 0,
- 'count' => 0,
- 'rows' => [],
- 'limit' => $limit,
- 'page' => $page
- ];
- $query = '
- SELECT
- SQL_CALC_FOUND_ROWS
- i.`id`,
- i.`name`,
- i.`item_type`,
- i.`icon`
- FROM `items` as `i`
- WHERE i.`id` = \''.addslashes($s).'\'
- OR i.`name` LIKE \'%'.addslashes(str_replace(' ', '%%',$s)).'%\'
- OR LOWER(i.`item_type`) = LOWER(\''.addslashes($s).'\')
- LIMIT '.$limit;
- //error_log($query,1);
- $stmt = $world->prepare($query);
- $stmt->execute();
- $rc = $stmt->rowCount();
- if($rc > 0) {
- $return['found'] = get_found_count();
- $return['count'] = $rc;
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- $return['rows'][] = $row;
- }
- }
- return $return;
- }
-
- //Returns count of rows found (if LIMIT had not been used).
- //Note: Requires SQL_CALC_FOUND_ROWS after SELECT.
- function get_found_count() {
- global $world;
- $query = 'SELECT FOUND_ROWS() as `found`;';
- $stmt = $world->prepare($query);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- return $row['found'];
- }
-
- //Returns count of characters.
- function get_character_count($return = 0) {
- global $world;
- $query = 'SELECT count(DISTINCT `id`) as `count` FROM `characters`';
- $stmt = $world->prepare($query);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $return = $row['count'];
- return $return;
- }
- //Get World Information.
- function get_world_info($world_name = NULL, $return = []) {
- global $_db, $login;
- $world_name = ($world_name == NULL ? _world:$world_name);
- $query = '
- SELECT
- w.id,
- w.name,
- w.disabled,
- w.account,
- w.description,
- w.password,
- w.serverop,
- w.greenname,
- w.note,
- w.ip_address,
- w.login_version,
- DATE_FORMAT(FROM_UNIXTIME(w.lastseen), "%m/%d/%y %h:%i %p") AS `lastseen`
- FROM login_worldservers AS w
- WHERE w.name = \''.$world_name.'\'';
- $stmt = $login->prepare($query);
- $stmt->execute();
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- $return = $row;
- return $return;
- }
- //Pulls variable data from world db.
- function get_world_variables($return = []) {
- global $world;
-
- $query = '
- SELECT
- v.variable_name,
- v.variable_value,
- v.comment
- FROM variables as v';
- $stmt = $world->prepare($query);
- $stmt->execute();
-
- while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- $return[$row['variable_name']] = [
- 'value' => $row['variable_value'],
- 'desc' => $row['comment']
- ];
- }
- return $return;
- }
- /* UTILITY FUNCTIONS */
- // Loads HTML output for left navigation menu.
- function get_nav_menu($return = NULL) {
- global $_modules, $_SESSION;
-
- $active = $_SESSION[_sid]['view'];
- foreach($_modules as $k => $m) {
- $access = !empty(array_intersect($_SESSION[_sid]['user']['access'], $m['access']));
- if($access) {
- if($m['type'] == 'module') {
- $return .= '
- <li class="'.($active == $k ? 'active':NULL).' eq-nav-link" data-module="'.$k.'">
- <a class="waves-effect waves-themed" href="#" title="'.$m['desc'].'">
- '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).'
- <span class="nav-link-text" data-il8n="nav.ui_components">'.$m['title'].'</span>
- </a>
- </li>';
- } else if($m['type'] == 'category') {
- $return .= '
- <li class="nav-title">
- '.($m['icon'] ? '<i class="'.$m['icon'].'"></i>':NULL).' '.$m['title'].'
- </li>';
- }
- }
- }
- return $return;
- }
- ?>
|