<?php

require_once "../../include/config.php";
require "../database/Database.php";
require "Customer.php";
$db = new Database();
$db->connectDatabase();
//Check if the POST variable 'redirectType' is not null and if it isnt equals to logout
if (isset($_POST['redirectType']) && strtolower($_POST['redirectType']) != "logout") {
    //Check if the user hasn't been logged in already.
    if (!isset($_SESSION['customer'])) {
        //Get the user details from the database. This can return null or it can return details.
        $user = $db->getCustomer($_POST['username'], $_POST['password']);
        //Switch through the post of redirectType
        switch (strtolower($_POST['redirectType'])) {
            //If the redirectType is login.
            case "login":
                if (!empty($user)) {
                    new Customer($user);
                    header("Location: http://" . $_SERVER['SERVER_NAME'] . "/faseovergang/index.php");
                } else {
                    echo "Invalid credentials";
                }
                break;
                //If the redirectType is register.
            //If the redirectType is register.
            case "register":
                if (empty($user)) {
                    $db->addCustomer($_POST['username'], $_POST['password']);
                    header("Location: http://" . $_SERVER['SERVER_NAME'] . "/faseovergang/index.php?page=login");
                } else {