$url = selfURL();
$url = substr($url, 0, strrpos($url, "/")) . "/";
// The step of the install process
$step = 1;
if (isset($_POST['step'])) {
    $step = $_POST['step'];
}
/*************************************************
 * Validate step data
 *************************************************/
// Step 1 has been processed
if ($step == 2) {
    // Determine if we can really continue to step 2
    // Check to see if the database user and password are correct
    $installAndUpgrade->setDbHost($_POST['dbhost']);
    $installAndUpgrade->setDbUser($_POST['dbuser']);
    $installAndUpgrade->setDbPass($_POST['dbpass']);
    // Store the values into the session so that they can be grabbed on the next page
    $_SESSION['dbhost'] = $_POST['dbhost'];
    $_SESSION['dbuser'] = $_POST['dbuser'];
    $_SESSION['dbpass'] = $_POST['dbpass'];
    // If the test fails, they will told and will have to click the back button to correct it
    $installAndUpgrade->testConnection();
}
// Step 2 has been processed
if ($step == 3) {
    $newOrExisting = $_POST['newOrExisting'];
    // 'New' or 'Existing'
    $installAndUpgrade->setDbHost($_SESSION['dbhost']);
    $installAndUpgrade->setDbUser($_SESSION['dbuser']);
    $installAndUpgrade->setDbPass($_SESSION['dbpass']);
    You should have received a copy of the GNU General Public License
    along with GlobalBan.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * Instead of putting each step on a separate page, each step will post back to this page and be
 * processed in the next step if it passes the previous step.
 */
define("ROOTDIR", dirname(__FILE__));
// Global Constant of root directory
require_once ROOTDIR . "/include/database/class.InstallAndUpgradeQueries.php";
require_once ROOTDIR . "/config/class.Config.php";
$config = new Config();
$installAndUpgrade = new InstallAndUpgradeQueries();
$installAndUpgrade->setDbHost($config->dbHostName);
$installAndUpgrade->setDbUser($config->dbUserName);
$installAndUpgrade->setDbPass($config->dbPassword);
$installAndUpgrade->setDbase($config->dbName);
$complete = false;
if (isset($_POST['submit'])) {
    $installAndUpgrade->createConnection();
    $installAndUpgrade->connectToDatabase();
    $upgradeVersion = $_POST['upgradeVersion'];
    // ---------------------------------------------------------------------------
    // UPGRADE FROM 2.2 TO ANY 3.0+ VERSION
    // ---------------------------------------------------------------------------
    // Upgrade from Version 2.2 to Version 3.0
    if ($upgradeVersion == "22to30") {
        $installAndUpgrade->upgradeTwoPointTwoToThree();
    }
    // Upgrade from Version 2.2 to Version 3.1