item search working

This commit is contained in:
color.diff=auto 2021-03-30 13:40:11 -06:00
parent 3eadaac01e
commit 02527a0d65
8 changed files with 181 additions and 89 deletions

View File

@ -49,14 +49,22 @@ if (!empty($_GET['sort']))
$sort = $_GET['sort']; $sort = $_GET['sort'];
if (!empty($_GET['view'])) if (!empty($_GET['view']))
$view = $_GET['view']; $view = $_GET['view'];
/*
* @cmd = getUniqueItem
*
*
* */
if ($cmd == "getUniqueItem") { if ($cmd == "getUniqueItem") {
$sql = "SELECT * FROM `uniqueitems` WHERE `enabled`='1' AND `index`=\"{$_GET['index']}\""; $sql = "SELECT * FROM `uniqueitems` WHERE `enabled`='1' AND `index`=\"{$_GET['index']}\"";
$res = PDO_FetchRow($sql); $res = PDO_FetchRow($sql);
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode($res, JSON_INVALID_UTF8_IGNORE); echo json_encode($res, JSON_INVALID_UTF8_IGNORE);
} }
/*
* @cmd = sortBy
*
*
* */
if ($cmd == "sortBy") { if ($cmd == "sortBy") {
$sql = "SELECT `index`,`$sort` FROM `uniqueitems` WHERE `enabled`='1' ORDER BY `$sort`"; $sql = "SELECT `index`,`$sort` FROM `uniqueitems` WHERE `enabled`='1' ORDER BY `$sort`";
$res = PDO_FetchAll($sql); $res = PDO_FetchAll($sql);
@ -66,12 +74,16 @@ if ($cmd == "sortBy") {
if ($sort == 'index') { if ($sort == 'index') {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>"; $html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
} else { } else {
$html .= "<option value=\"{$r['index']}\">{$r['index']} ($r[$sort])</option>"; $html .= "<option value=\"{$r['index']}\">$r[$sort] - {$r['index']}</option>";
} }
} }
echo $html; echo $html;
} }
/*
* @cmd = viewOnly
*
*
* */
if ($cmd == "viewOnly") { if ($cmd == "viewOnly") {
$table = 'misc'; $table = 'misc';
@ -93,14 +105,10 @@ FROM uniqueitems
LEFT JOIN $table ON uniqueitems.`code` = $table.`code` LEFT JOIN $table ON uniqueitems.`code` = $table.`code`
WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`"; WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code` != '' ORDER BY `index`";
} }
if ($view == "char") { if ($view == "char") {
$sql .= " OR uniqueitems.`code`='cm1' OR uniqueitems.`code`='cm2' OR uniqueitems.`code`='cm3'"; $sql .= " OR uniqueitems.`code`='cm1' OR uniqueitems.`code`='cm2' OR uniqueitems.`code`='cm3'";
} }
$res = PDO_FetchAll($sql); $res = PDO_FetchAll($sql);
$html = ''; $html = '';
foreach ($res as $r) { foreach ($res as $r) {
if ($sort == 'index') { if ($sort == 'index') {
@ -111,3 +119,28 @@ WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code`
} }
echo $html; echo $html;
} }
/*
* @cmd = search
*
*
*
*
*/
if ($cmd == 'search'){
$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);
$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;
}

View File

@ -45,3 +45,4 @@ $author = "HashCasper";
$version = '<span style="color: #aaa">4.0'; $version = '<span style="color: #aaa">4.0';
define('APP_DB', "D2Modder.db"); define('APP_DB', "D2Modder.db");

View File

@ -1,44 +1,45 @@
<?php <?php
session_start(); session_start();
/* /*
Copyright (C) 2021 Hash Borgir Copyright (C) 2021 Hash Borgir
This file is part of D2Modder This file is part of D2Modder
Redistribution and use in source and binary forms, with Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above * Redistributions of source code must retain the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer. following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other following disclaimer in the documentation and/or other
materials provided with the distribution. materials provided with the distribution.
* This software must not be used for commercial purposes * This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited * without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent. * without my express knowledge and consent.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY! but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
@ -50,13 +51,23 @@ include "./_pdo.php";
include "./config.php"; include "./config.php";
if (!isset($_SESSION['modname']) if (empty($_SESSION['modname'])) {
|| (!file_exists(APP_DB))
|| (!file_exists($_SESSION['modname'] . ".db"))) }
{
if (!isset($_SESSION['modname']) || (!file_exists(APP_DB)) || (!file_exists($_SESSION['modname'] . ".db"))) {
// first load, no active mod, go to switchmods to select mod // first load, no active mod, go to switchmods to select mod
header("Location: /switchMods.php"); header("Location: /switchMods.php");
} else { } else {
PDO_Connect("sqlite:" . APP_DB);
$sql = "SELECT * FROM D2Modder ORDER BY lastused LIMIT 1";
$lastUsedMod = PDO_FetchRow($sql);
$_SESSION['modname'] = $lastUsedMod['modname'];
$_SESSION['path'] = $lastUsedMod['path'];
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt'); define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'] . ".db"); define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']); define('TXT_PATH', $_SESSION['path']);
@ -74,17 +85,13 @@ if (!isset($_SESSION['modname'])
$weapon = PDO_FetchAll('SELECT * FROM weapons WHERE spawnable=1'); $weapon = PDO_FetchAll('SELECT * FROM weapons WHERE spawnable=1');
$uniqueitems = PDO_FetchAll("SELECT `index`,`code` FROM uniqueitems WHERE `enabled`='1' ORDER BY `index` ASC"); $uniqueitems = PDO_FetchAll("SELECT `index`,`code` FROM uniqueitems WHERE `enabled`='1' ORDER BY `index` ASC");
$prop = $parser->filterProps('Properties.txt'); $prop = $parser->filterProps('Properties.txt');
// If there's data, process it and save // If there's data, process it and save
if (!empty($_POST)) { if (!empty($_POST)) {
ddump($_POST); ddump($_POST);
// save db name from post into conf file // save db name from post into conf file
require_once './src/D2SaveFile.php'; require_once './src/D2SaveFile.php';

View File

@ -39,6 +39,14 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
function search() {
$.get("/ajax/uniqueitems.php?cmd=search&search=" + searchbox.value, function (data) {
$('.uniqueitems-select').html(data)
});
}
$(document).ready(function () { $(document).ready(function () {
$('.form-text').hide(); $('.form-text').hide();
$('.help').click(function () { $('.help').click(function () {
@ -157,5 +165,11 @@ $(document).ready(function () {
}); });
}); });
searchbox = document.getElementById('search');
searchbox.addEventListener('input', search);
}); });

View File

@ -132,4 +132,35 @@ h1,h2,h3,h4,h5,h6, div > p {
top:0px; top:0px;
right: 0px; right: 0px;
color: #ccc; color: #ccc;
}
select {
font-size: 18px;
border: 1px solid #CCC;
height: 34px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: url(https://stackoverflow.com/favicon.ico) 96% / 15% no-repeat #EEE;
}
/* CAUTION: Internet Explorer hackery ahead */
select::-ms-expand {
display: none; /* Remove default arrow in Internet Explorer 10 and 11 */
}
/* Target Internet Explorer 9 to undo the custom arrow */
@media screen and (min-width:0\0) {
select {
background: none\9;
padding: 5px\9;
}
}
option {
-webkit-appearance: none;
-moz-appearance: none;
} }

View File

@ -1,43 +1,43 @@
<?php <?php
/* /*
Copyright (C) 2021 Hash Borgir Copyright (C) 2021 Hash Borgir
This file is part of D2Modder This file is part of D2Modder
Redistribution and use in source and binary forms, with Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the or without modification, are permitted provided that the
following conditions are met: following conditions are met:
* Redistributions of source code must retain the above * Redistributions of source code must retain the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer. following disclaimer.
* Redistributions in binary form must reproduce the above * Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other following disclaimer in the documentation and/or other
materials provided with the distribution. materials provided with the distribution.
* This software must not be used for commercial purposes * This software must not be used for commercial purposes
* without my consent. Any sales or commercial use are prohibited * without my consent. Any sales or commercial use are prohibited
* without my express knowledge and consent. * without my express knowledge and consent.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY! but WITHOUT ANY WARRANTY!
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
?> ?>
@ -57,11 +57,10 @@
</style> </style>
<script <script
src="/res/jquery-3.6.0.min.js"></script> src="/res/jquery-3.6.0.min.js"></script>
<script src="/res/bootstrap.bundle.min.js"></script> <script src="/res/bootstrap.bundle.min.js"></script>
<script src="/res/app.js"></script> <script src="/res/app.js"></script>
</script> </script>
<title>D2Modder</title> <title>D2Modder</title>
</head> </head>

View File

@ -1,7 +1,13 @@
<div style="height: 40px; margin: 40px 10px;"><h2>Unique Item Maker</h2></div> <div style="height: 40px; margin: 40px 10px;"><h2>Unique Item Maker</h2></div>
<div class="row" style="">
<div class="col-3">
<div class="row" style="margin:40px;">
<div class="col" style="text-align: center;">
<p>Search for Item</p>
<input style="border: 1px solid #999; padding: 10px;width: 420px;" id="search" type="text custom-control-inline" placeholder="Search item" name="search">
</div>
</div>
<div class="row" style="">
<div class="col-4">
<select name="uniqueitems" class="custom-select uniqueitems-select"> <select name="uniqueitems" class="custom-select uniqueitems-select">
<option value=""></option> <option value=""></option>
<?php foreach ($uniqueitems as $u) { ?> <?php foreach ($uniqueitems as $u) { ?>
@ -9,7 +15,7 @@
<?php } ?> <?php } ?>
</select> </select>
</div> </div>
<div class="col"> <div class="col-8">
<span style="font-family:Exocet;">Sort By: </span> <span style="font-family:Exocet;">Sort By: </span>
<div class="custom-control custom-radio custom-control-inline"> <div class="custom-control custom-radio custom-control-inline">
<input name="sort" id="sort_0" type="radio" class="custom-control-input" value="lvl"> <input name="sort" id="sort_0" type="radio" class="custom-control-input" value="lvl">
@ -28,9 +34,8 @@
<label for="sort_3" class="custom-control-label">Item Code</label> <label for="sort_3" class="custom-control-label">Item Code</label>
</div> </div>
</div> </div>
</div>
<div class="row" style="margin-bottom: 40px;"> <div class="offset-4 col-8">
<div class="offset-3 col">
<span style="font-family:Exocet;">View Only: </span> <span style="font-family:Exocet;">View Only: </span>
<div class="custom-control custom-radio custom-control-inline"> <div class="custom-control custom-radio custom-control-inline">
<input name="view" id="view_0" type="radio" class="custom-control-input" value="rin"> <input name="view" id="view_0" type="radio" class="custom-control-input" value="rin">

View File

@ -64,7 +64,9 @@ if (file_exists(APP_DB)) {
unlink($_POST['modname'] . ".db"); unlink($_POST['modname'] . ".db");
header("Refresh:0"); header("Refresh:0");
} else { } else {
$time = time();
$sql = "UPDATE `D2Modder` SET `lastused`=$time WHERE modname='{$_POST['modname']}'";
PDO_Execute($sql);
$_SESSION['modname'] = $mod['modname']; $_SESSION['modname'] = $mod['modname'];
$_SESSION['path'] = $mod['path']; $_SESSION['path'] = $mod['path'];
header("Location: /"); header("Location: /");