d2tools/ajax/uniqueitems.php

198 lines
5.0 KiB
PHP
Raw Normal View History

<?php
include "./config.php";
require_once "../src/D2Functions.php";
require_once '../src/D2ItemData.php';
2021-05-07 09:18:29 +00:00
require_once '../src/D2ItemDesc.php';
$idata = new D2ItemData();
2021-05-07 09:18:29 +00:00
$idesc = new D2ItemDesc();
/*
Copyright (C) 2021 Hash Borgir
This file is part of D2Modder
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
2021-05-03 02:52:31 +00:00
* This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
if (!empty($_GET['cmd']))
$cmd = $_GET['cmd'];
if (!empty($_GET['sort']))
$sort = $_GET['sort'];
if (!empty($_GET['view']))
$view = $_GET['view'];
/*
2021-03-30 19:40:11 +00:00
* @cmd = getUniqueItem
2021-05-03 02:52:31 +00:00
*
*
2021-03-30 19:40:11 +00:00
* */
// first search code in all 3 tables. Grab from where it exists.
if ($cmd == "getUniqueItem") {
echo $idata->uniqueItems($_GET['index']);
}
/*
2021-05-03 02:52:31 +00:00
* @cmd = sortBy
*
*
2021-03-30 19:40:11 +00:00
* */
if ($cmd == "sortBy") {
2021-05-15 07:23:25 +00:00
$sql = "SELECT `index`, `$sort` FROM uniqueitems WHERE enabled='1' ORDER BY ?";
$res = PDO_FetchAll($sql, [$sort]);
2021-05-15 07:23:25 +00:00
//ddump($res);
$html = '';
foreach ($res as $r) {
if ($sort == 'index') {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
} else {
2021-03-30 19:40:11 +00:00
$html .= "<option value=\"{$r['index']}\">$r[$sort] - {$r['index']}</option>";
}
}
echo $html;
}
/*
2021-05-03 02:52:31 +00:00
* @cmd = viewOnly
*
*
2021-03-30 19:40:11 +00:00
* */
if ($cmd == "viewOnly") {
$table = 'misc';
$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, misc.`type`
FROM uniqueitems
LEFT JOIN misc ON uniqueitems.`code` = misc.`code`
WHERE `type` IS NOT NULL AND uniqueitems.`code`='$view'";
if ($view == 'armo') {
$table = 'armor';
$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, $table.`code`
FROM uniqueitems
LEFT JOIN $table ON uniqueitems.`code` = $table.`code`
WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`";
}
if ($view == 'weap') {
$table = 'weapons';
$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, $table.`code`
FROM uniqueitems
LEFT JOIN $table ON uniqueitems.`code` = $table.`code`
WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`";
}
if ($view == "char") {
$sql .= " OR uniqueitems.`code`='cm1' OR uniqueitems.`code`='cm2' OR uniqueitems.`code`='cm3'";
}
$res = PDO_FetchAll($sql);
$html = '';
foreach ($res as $r) {
if ($sort == 'index') {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
} else {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
}
}
echo $html;
}
2021-03-30 19:40:11 +00:00
/*
2021-03-30 19:40:11 +00:00
* @cmd = search
2021-05-03 02:52:31 +00:00
*
*
2021-03-30 19:40:11 +00:00
*
*
*/
if ($cmd == 'search') {
2021-03-30 19:40:11 +00:00
$search = $_GET['search'];
$sql = "SELECT * FROM uniqueitems WHERE `index` LIKE '%$search%' OR code LIKE '%$search%' AND enabled=1 ORDER BY `index`";
$res = PDO_FetchAll($sql);
2021-03-30 19:40:11 +00:00
$html = '';
foreach ($res as $r) {
if ($sort == 'index') {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
} else {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
}
}
echo $html;
}
/*
* @cmd = getString
*
2021-05-07 09:18:29 +00:00
* @arg = property, par, min, max
*
*
*/
if ($cmd == 'getString') {
2021-05-07 09:18:29 +00:00
$prop = $_GET['prop'];
// stat2,stat3,stat4,stat5,stat6,stat7
$sql = "SELECT stat1 FROM properties WHERE code = ?";
$stat = array_filter(PDO_FetchRow($sql, [$prop]));
$s = array_filter($idata->getIscStrings($prop));
2021-05-07 09:18:29 +00:00
// now combine isc strings with par, min, max
$params = array_merge($_GET, $s);
$return = $idesc->getDesc($params);
/*
* This goes into D2ItemDesc->getDesc();
*
$s1 = $params['string1'];
$s2 = $params['string2'];
$prop = $params['prop'];
$par = $params['par'];
$min = (int) $params['min'];
*
* @return string
*/
header('Content-Type: application/json');
2021-05-07 09:18:29 +00:00
echo json_encode($return, JSON_INVALID_UTF8_IGNORE);
}