mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-10-13 08:24:24 -05:00
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:
@@ -48,150 +48,197 @@ $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 ?";
|
||||
$res = PDO_FetchAll($sql, [$sort]);
|
||||
|
||||
//ddump($res);
|
||||
|
||||
$html = '';
|
||||
foreach ($res as $r) {
|
||||
if ($sort == 'index') {
|
||||
$html .= "<option value=\"{$r['index']}\">{$r['index']}</option>";
|
||||
} else {
|
||||
$html .= "<option value=\"{$r['index']}\">$r[$sort] - {$r['index']}</option>";
|
||||
}
|
||||
}
|
||||
echo $html;
|
||||
if ($cmd === "sortBy") {
|
||||
$sql = "SELECT `index`, `$sort` FROM uniqueitems WHERE enabled='1' ORDER BY ? ASC";
|
||||
$res = PDO_FetchAll($sql, [$sort]);
|
||||
|
||||
// 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') {
|
||||
$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';
|
||||
$sql = "SELECT uniqueitems.`index`, uniqueitems.`code`, misc.`type`
|
||||
$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`
|
||||
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`
|
||||
}
|
||||
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") { // charm
|
||||
$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;
|
||||
}
|
||||
if ($view == "char") { // charm
|
||||
$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;
|
||||
}
|
||||
|
||||
/*
|
||||
* @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`";
|
||||
$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;
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @cmd = getString
|
||||
*
|
||||
* @arg = property, par, min, max
|
||||
*
|
||||
*
|
||||
*/
|
||||
// @cmd = getString
|
||||
// @arg = property, par, min, max
|
||||
if ($cmd == 'getString') {
|
||||
|
||||
|
||||
$prop = $_GET['prop'];
|
||||
$prop = $_GET['prop'];
|
||||
|
||||
// stat2,stat3,stat4,stat5,stat6,stat7
|
||||
|
||||
$sql = "SELECT stat1 FROM properties WHERE code = ?";
|
||||
$stat = array_filter(PDO_FetchRow($sql, [$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));
|
||||
|
||||
$s = array_filter($idata->getIscStrings($prop));
|
||||
|
||||
// now combine isc strings with par, min, max
|
||||
|
||||
$params = array_merge($_GET, $s);
|
||||
// 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
|
||||
*/
|
||||
|
||||
|
||||
$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');
|
||||
echo json_encode($return, JSON_INVALID_UTF8_IGNORE);
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user