Set active tab to Uniqueitems. header.php, set uniqueitems to first tab active.

ajax/uniqueitems.php, add save/delete functionality
app.js, handle save/delete calls
src/tabs/optionsubmit.php, add delete button
tabs/UniqueItems.php remove form action

Ajax save, and delete working.
This commit is contained in:
Hash Borgir 2023-05-30 13:12:19 -06:00
parent 961a061662
commit 1f7ac14963
5 changed files with 631 additions and 540 deletions

View File

@ -48,49 +48,43 @@ $idesc = new D2ItemDesc();
*/
if (!empty($_GET['cmd']))
$cmd = $_GET['cmd'];
if (!empty($_GET['sort']))
$sort = $_GET['sort'];
if (!empty($_GET['view']))
$view = $_GET['view'];
/*
* @cmd = getUniqueItem
*
*
* */
$cmd = $_GET['cmd'] ?? '';
$sort = $_GET['sort'] ?? '';
$view = $_GET['view'] ?? '';
// first search code in all 3 tables. Grab from where it exists.
if ($cmd == "getUniqueItem") {
echo $idata->uniqueItems($_GET['index']);
if ($_GET['cmd'] === "getUniqueItem") {
$index = $_GET['index'];
echo $idata->uniqueItems($index);
}
/*
* @cmd = sortBy
*
*
* */
if ($cmd == "sortBy") {
$sql = "SELECT `index`, `$sort` FROM uniqueitems WHERE enabled='1' ORDER BY ?";
if ($cmd === "sortBy") {
$sql = "SELECT `index`, `$sort` FROM uniqueitems WHERE enabled='1' ORDER BY ? ASC";
$res = PDO_FetchAll($sql, [$sort]);
//ddump($res);
// Sort the results if the sorting is based on 'index'
if ($sort === 'index') {
sort($res);
}
// Generate HTML options based on the sorted results
$html = '';
foreach ($res as $r) {
if ($sort == 'index') {
if ($sort === 'index') {
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
} else {
$html .= "<option value=\"{$r['index']}\">$r[$sort] - {$r['index']}</option>";
}
}
// Output the generated HTML
echo $html;
}
/*
* @cmd = viewOnly
*
*
* */
//@cmd = viewOnly
if ($cmd == "viewOnly") {
$table = 'misc';
@ -127,13 +121,7 @@ WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code`
echo $html;
}
/*
* @cmd = search
*
*
*
*
*/
// @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`";
@ -151,47 +139,106 @@ if ($cmd == 'search') {
}
/*
* @cmd = getString
*
* @arg = property, par, min, max
*
*
*/
// @cmd = getString
// @arg = property, par, min, max
if ($cmd == 'getString') {
$prop = $_GET['prop'];
// stat2,stat3,stat4,stat5,stat6,stat7
if (!empty($prop)) {
$sql = "SELECT stat1 FROM properties WHERE code = ?";
$stat = array_filter(PDO_FetchRow($sql, [$prop]));
$s = array_filter($idata->getIscStrings($prop));
// now combine isc strings with par, min, max
$params = array_merge($_GET, $s);
$return = $idesc->getDesc($params);
/*
* This goes into D2ItemDesc->getDesc();
*
}
/* This goes into D2ItemDesc->getDesc();
$s1 = $params['string1'];
$s2 = $params['string2'];
$prop = $params['prop'];
$par = $params['par'];
$min = (int) $params['min'];
*
* @return string
@return string
*/
header('Content-Type: application/json');
echo json_encode($return, JSON_INVALID_UTF8_IGNORE);
}
function saveFile() {
$bin = '..\bin\sqlite3.exe ';
$dbfile = '../' . $_SESSION['modname'] . ".db";
$outputFile = TXT_PATH . 'uniqueitems.txt';
// Prepare the command
$command = escapeshellarg($bin) . " " . escapeshellarg($dbfile) . ' ".mode tabs" ".header on" "SELECT * FROM uniqueitems;" > ' . escapeshellarg($outputFile);
$output = exec($command);
var_dump($command);
return $output;
}
if ($cmd == 'delete') {
$sql = "DELETE FROM uniqueitems WHERE `index` = \"{$_GET['index']}\";";
$res = PDO_Execute($sql);
saveFile();
header('Content-Type: application/json');
echo json_encode($res, JSON_INVALID_UTF8_IGNORE);
}
if ($cmd == "save") {
unset($_GET['formtype']);
unset($_GET['submit']);
unset($_GET['item']);
unset($_GET['cmd']);
// if ladder or carry1 is 0, set empty field.
$_GET['ladder'] = $_GET['ladder'] ?? '';
$_GET['carry1'] = $_GET['carry1'] ?? '';
$index = $_GET['index'];
$sql = "SELECT COUNT(*) FROM uniqueitems WHERE `index` = ?";
$indexExists = PDO_FetchOne($sql, [$index]);
$columns = array_keys($_GET);
// Build the INSERT query
$insertQuery = 'INSERT INTO uniqueitems (';
foreach ($_GET as $k => $v) {
$column = str_replace("_", " ", $k);
$insertQuery .= "`$column`, ";
}
$insertQuery = rtrim($insertQuery, ", ");
$insertQuery .= ") VALUES (";
foreach ($_GET as $k => $v) {
$insertQuery .= "\"$v\", ";
}
$insertQuery = rtrim($insertQuery, ", ");
$insertQuery .= ")";
// Build the UPDATE query
$updateQuery = 'UPDATE uniqueitems SET ';
foreach ($_GET as $k => $v) {
$column = str_replace("_", " ", $k);
$updateQuery .= "`$column` = \"$v\", ";
}
$updateQuery = rtrim($updateQuery, ", ");
$updateQuery .= " WHERE `index`=\"$index\"";
if ($indexExists) {
$res = PDO_Execute($updateQuery);
} else {
$res = PDO_Execute($insertQuery);
}
$output = saveFile();
header('Content-Type: application/json');
echo json_encode($output, JSON_INVALID_UTF8_IGNORE);
}

View File

@ -39,7 +39,7 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// highlight json dump for item debugger
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
@ -280,7 +280,8 @@ $(document).ready(function () {
prop = "Prop5";
par = $('.par5').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min5').val();
max = $('.max5').val();
@ -295,7 +296,8 @@ $(document).ready(function () {
prop = "Prop6";
par = $('.par6').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min6').val();
max = $('.max6').val();
@ -311,7 +313,8 @@ $(document).ready(function () {
prop = "Prop7";
par = $('.par7').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min7').val();
max = $('.max7').val();
@ -328,7 +331,8 @@ $(document).ready(function () {
prop = "Prop8";
par = $('.par8').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min8').val();
max = $('.max8').val();
@ -344,7 +348,8 @@ $(document).ready(function () {
prop = "Prop9";
par = $('.par9').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min9').val();
max = $('.max9').val();
@ -360,7 +365,8 @@ $(document).ready(function () {
prop = "Prop10";
par = $('.par10').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min10').val();
max = $('.max10').val();
@ -376,7 +382,8 @@ $(document).ready(function () {
prop = "Prop11";
par = $('.par11').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min11').val();
max = $('.max11').val();
@ -391,7 +398,8 @@ $(document).ready(function () {
prop = "Prop12";
par = $('.par12').val();
if (par == '') par = 0;
if (par == '')
par = 0;
min = $('.min12').val();
max = $('.max12').val();
@ -562,7 +570,34 @@ $(document).ready(function () {
window.open('/genDocs.php?cmd=genDocUniqueItems', '_blank');
});
$('.btn-delete').click(function (event) {
event.preventDefault(); // Prevent default button click behavior
// delete item index
$.get('/ajax/uniqueitems.php?cmd=delete&index=' + $(".uniqueform input[name='index']").val(), function (response) {
// Handle the response from the server
// remove option from list
$('.uniqueitems-select option[value="' + $(".uniqueform input[name='index']").val() + '"]').remove();
console.log(response);
});
});
$('.btn-save').click(function (event) {
event.preventDefault(); // Prevent default button click behavior
// Get form data
var formData = $(".uniqueform").serialize();
// delete item index
$.get('/ajax/uniqueitems.php?cmd=save&' + formData, function (response) {
// Handle the response from the server
console.log(response);
});
});

View File

@ -61,7 +61,7 @@
</div>
<ul class="nav nav-tabs" id="Tabs" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link" id="Unique-tab" data-toggle="tab" href="#Unique" role="tab" aria-controls="Unique" aria-selected="true">Unique Items</a>
<a class="nav-link active" id="Unique-tab" data-toggle="tab" href="#Unique" role="tab" aria-controls="Unique" aria-selected="true">Unique Items</a>
</li>
<!-- <li class="nav-item" role="presentation">
<a class="nav-link" id="Set-tab" data-toggle="tab" href="#Set" role="tab" aria-controls="Set" aria-selected="false">Set Items</a>
@ -77,7 +77,7 @@
</li>
-->
<li class="nav-item" role="presentation">
<a class="nav-link active" id="Chars-tab" data-toggle="tab" href="#Chars" role="tab" aria-controls="Chars" aria-selected="false">Character Editor</a>
<a class="nav-link" id="Chars-tab" data-toggle="tab" href="#Chars" role="tab" aria-controls="Chars" aria-selected="false">Character Editor</a>
</li>
<li class="nav-item" role="presentation">
@ -94,7 +94,7 @@
</div>
</div>
<div class="tab-content" id="TabContent">
<div class="tab-pane fade" id="Unique" role="tabpanel" aria-labelledby="Unique-tab">
<div class="tab-pane fade show active" id="Unique" role="tabpanel" aria-labelledby="Unique-tab">
<?php require_once 'tabs/UniqueItems.php'; ?>
</div>
<div class="tab-pane fade" id="Set" role="tabpanel" aria-labelledby="Set-tab">
@ -113,7 +113,7 @@
<div class="tab-pane fade" id="Doc" role="tabpanel" aria-labelledby="Doc-tab">
<?php require_once 'tabs/Doc.php'; ?>
</div>
<div class="tab-pane fade show active" id="Chars" role="tabpanel" aria-labelledby="Chars-tab">
<div class="tab-pane fade" id="Chars" role="tabpanel" aria-labelledby="Chars-tab">
<?php require_once 'tabs/Chars.php'; ?>
</div>
<div class="tab-pane fade" id="Debug" role="tabpanel" aria-labelledby="Debug-tab">

View File

@ -107,13 +107,13 @@
</select>
</div>
</div>
<form action="/saveD2ModderEditorData.php" method="post">
<form class="uniqueform" action="" method="post">
<div class="form-group row">
<div class="col-2" style="background: #fec;">
<p>Index</p>
<div class="input-group">
<input name="index" type="text" aria-describedby="indexHelpBlock" required="required" class="form-control">
<input name="index" type="text" aria-describedby="indexHelpBlock" required="required" class="form-control input-uindex">
</div><span class="help"><i class="fa fa-question-circle" aria-hidden="true"></i>
</span>
<span class="form-text">Index: the ID pointer that is referenced by the game in TreasureClassEx.txt and CubeMain.txt, this column also contains the string-key used in the TBL files.</span>

View File

@ -1,6 +1,15 @@
<div class="row options" style="background: none;">
<div class="offset-10 col-2" style="background: none;">
<button style="" name="submit" type="submit" class="btn btn-success">SAVE</button>
<button name="submit" type="reset" class="btn btn-danger">CLEAR</button>
<button name="submit" type="submit" class="btn btn-success btn-save">SAVE</button>
<button name="submit" type="reset" class="btn btn-warning btn-clear">CLEAR</button>
<button name="submit" type="submit" class="btn btn-danger btn-delete">DELETE</button>
</div>
</div>
<!--<div class="row options" style="background: none;">
<div class="offset-10 col-2" style="background: none;">
<a href="" name="submit" type="submit" class="btn btn-success btn-save">SAVE</a>
<button name="submit" type="reset" class="btn btn-warning btn-clear">CLEAR</button>
<a href="" name="submit" class="btn btn-danger btn-delete">DELETE</a>
</div>
</div>-->