d2tools/index.php
2021-03-29 18:47:21 -06:00

131 lines
3.7 KiB
PHP

<?php
session_start();
/*
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.
* 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.
*/
ini_set('display_errors', 1);
error_reporting(1);
ini_set('log_errors', 1);
include "./_pdo.php";
include "./config.php";
if (!isset($_SESSION['modname'])
|| (!file_exists(APP_DB))
|| (!file_exists($_SESSION['modname'] . ".db")))
{
// first load, no active mod, go to switchmods to select mod
header("Location: /switchMods.php");
} else {
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']);
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
$db = new D2Database();
$parser = new D2TxtParser();
$armor = PDO_FetchAll('SELECT * FROM armor WHERE spawnable=1');
$misc = PDO_FetchAll('SELECT * FROM misc 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");
$prop = $parser->filterProps('Properties.txt');
// If there's data, process it and save
if (!empty($_POST)) {
ddump($_POST);
// save db name from post into conf file
require_once './src/D2SaveFile.php';
$saver = new D2SaveFile();
// process post
// combine armor/weapon codes
$post = $_POST;
if (!empty($post['code'])) {
array_filter($post['code']);
if (!empty($post['code'][0])) {
$post['code'] = $post['code'][0];
} else {
$post['code'] = $post['code'][1];
}
}
if ($_POST['formtype'] == "uniqueitems") {
ddump($_POST);
// if ladder or carry1 is 0, set empty field.
if (!$post['ladder']) {
$post['ladder'] = '';
}
if (!$post['carry1']) {
$post['carry1'] = '';
}
$saver->save($u, $post);
$saver->saveTblEnries("UniqueItems.tbl.txt");
}
if ($_POST['formtype'] == "setitems") {
$saver->save($s, $post);
$saver->saveTblEnries("SetItems.tbl.txt");
}
}
// load app
require_once './src/index.php';
}
?>