<?php

function __autoload($filename)
{
    include "classes/" . $filename . ".php";
}
$dataBase = new dataBase();
var_dump($dataBase->getRow("*", "artikels"));
if (isset($_POST["artikelToevoegen"])) {
    $titel = $_POST["titel"];
    $kernWoorden = $_POST["kernwoorden"];
    $artikel = $_POST["artikel"];
    $datum = $_POST["datum"];
    var_dump($dataBase->insert("artikels", "titel, kernwoorden, artikel, auteur, datum", "'" . $titel . "','" . $kernWoorden . "','" . $artikel . "','" . "*****@*****.**" . "','" . $datum . "'"));
}
?>

<!doctype html>

<html>

	<head>

		<title>Classe database test</title>

		<link rel="stylesheet" type="text/css" href="css/style.css">
	</head>

	<body>

			<h1>FrameWork test</h1>
<?php

include "artikels-logic.php";
function __autoload($filename)
{
    include "classes/" . $filename . ".php";
}
$dataBase = new dataBase();
$picture = $dataBase->getRow("profile_picture", "users", true, "'" . $email . "'", "email");
$id = $dataBase->getRow("id", "users", true, "'" . $email . "'", "email");
$actualId = $id[0]["id"];
if (empty($picture[0]["profile_picture"])) {
    $imgstring = "img/default.png";
} else {
    $actualPicture = $picture[0]["profile_picture"];
    $imgstring = "img/" . $actualPicture;
}
if (isset($_SESSION["notifications"])) {
    echo "Type :" . $_SESSION["notifications"]["type"];
    echo " message : " . $_SESSION["notifications"]["message"];
    unset($_SESSION["notifications"]);
}
?>




<!doctype html>

<html>
    include "classes/" . $filename . ".php";
}
$dataBase = new dataBase();
if (isset($_POST["changeInfo"])) {
    $newEmail = $_POST["email"];
    $id = $_POST["id"];
    if ($_POST["email"] != "" && $_FILES["profilePicture"]["name"] != "") {
        if ($_FILES["profilePicture"]["type"] == "image/png" || $_FILES["profilePicture"]["type"] == "image/jpeg" || $_FILES["profilePicture"]["type"] == "image/gif") {
            if ($_FILES["profilePicture"]["size"] <= 2000000) {
                $newPictureName = newName($_FILES["profilePicture"]["name"]);
                while (file_exists("img\\" . $newPictureName)) {
                    $newPictureName = newName($_FILES["profilePicture"]["name"]);
                }
                move_uploaded_file($_FILES['profilePicture']['tmp_name'], "img\\" . $newPictureName);
                $test = $dataBase->update("users", "email", "'" . $newEmail . "'", "profile_picture", "'" . $newPictureName . "'", "id", "'" . $id . "'");
                $salt = $dataBase->getRow("salt", "users", true, "'" . $id . "'", "id");
                $actualSalt = $salt[0]["salt"];
                $hash = openssl_digest($newEmail . $actualSalt, 'sha512');
                var_dump($test);
                setcookie("login", $newEmail . "," . $hash, time() + 2592000);
                header("location: gegevens-wijzigen-form.php");
            } else {
                $_SESSION["notifications"]["type"] = "error";
                $_SESSION["notifications"]["message"] = "File is too big";
                header("location: gegevens-wijzigen-form.php");
            }
        } else {
            $_SESSION["notifications"]["type"] = "error";
            $_SESSION["notifications"]["message"] = "File is wrong type";
            header("location: gegevens-wijzigen-form.php");
        }