if (!defined('isIncluded') || $_SESSION['GroepID'] != 4) {
    header('location: index.php');
}
if (isset($_POST['submit'])) {
    if (!empty($_POST['iptGebEmail']) && !empty($_POST['iptGebStraat']) && !empty($_POST['iptGebHuisnummer']) && !empty($_POST['iptGebPostcode']) && !empty($_POST['iptGebWoonplaats']) && !empty($_POST['iptGebTelefoon']) && !empty($_POST['iptBedBedrijfsnaam']) && !empty($_POST['iptBedStraat']) && !empty($_POST['iptBedHuisnummer']) && !empty($_POST['iptBedPostcode']) && !empty($_POST['iptBedVestigingsplaats']) && !Gebruiker::emailAlreadyExists($_POST['iptGebEmail'])) {
        $properties_values = array('Bedrijfsnaam' => $_POST['iptBedBedrijfsnaam'], 'Straat' => $_POST['iptBedStraat'], 'Huisnummer' => $_POST['iptBedHuisnummer'], 'HuisnummerToevoeging' => $_POST['iptBedHuisnummerToevoeging'], 'Postcode' => $_POST['iptBedPostcode'], 'Vestigingsplaats' => $_POST['iptBedVestigingsplaats'], 'Email' => $_POST['iptBedEmail']);
        Bedrijf::create($properties_values);
        global $db;
        $stmt = $db->query("SELECT MAX(BedrijfID) FROM bedrijf");
        $stmt->execute();
        $res = $stmt->fetch(PDO::FETCH_ASSOC);
        $bedrijfId = $res['MAX(BedrijfID)'];
        $randPass = getUniqueCode(15);
        mailPassword($_POST['iptGebEmail'], $randPass);
        $properties_values = array('Email' => $_POST['iptGebEmail'], 'Wachtwoord' => encrypt($randPass), 'GroepID' => 3, 'BedrijfID' => $bedrijfId, 'Voornaam' => $_POST['iptGebVoornaam'], 'Tussenvoegsel' => $_POST['iptGebTussenvoegsel'], 'Achternaam' => $_POST['iptGebAchternaam'], 'Straat' => $_POST['iptGebStraat'], 'Huisnummer' => $_POST['iptGebHuisnummer'], 'HuisnummerToevoeging' => $_POST['iptGebHuisnummerToevoeging'], 'Postcode' => $_POST['iptGebPostcode'], 'Woonplaats' => $_POST['iptGebWoonplaats'], 'Telefoon' => $_POST['iptGebTelefoon'], 'Aanmaker' => $_SESSION['GebruikerID']);
        Gebruiker::create($properties_values);
        echo '<br /><div class="notification_ok">De groothandel is succesvol aangemaakt.</div>';
    } else {
        if (Gebruiker::emailAlreadyExists($_POST['iptGebEmail'])) {
            echo '<br /><div class="notification_error">Dit e-mailadres is al in gebruik.</div>';
        } else {
            echo '<br /><div class="notification_error">De groothandel kon niet worden aangemaakt.</div>';
        }
    }
} else {
    ?>
	<div id="form">
		<form name="groothandelAdd" method="post">
			<fieldset class="info_fieldset">
				<div id="fields">
					<label style="font-weight: bold; width: 415px;">Gebruiker informatie</label>