commit e18598d100b0bf90204b60f5dca077ae9da375be
parent a1caada19a1f4f58b9f0de43a41503c886ee106b
Author: LennartSchroot <lennartschroot@gmail.com>
Date: Sun, 16 Apr 2023 17:43:23 +0200
updateje
joejoe
Diffstat:
6 files changed, 148 insertions(+), 26 deletions(-)
diff --git a/addContract.php b/addContract.php
@@ -0,0 +1,124 @@
+<!DOCTYPE html>
+<html lang="nl">
+<head>
+ <title>Add contract</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
+</head>
+<?php
+include "navbar.php";
+include "Connect.php";
+if(!in_array(1, $_SESSION['permissions'])){
+ header('Location: dashboard.php');
+ exit;
+}
+?>
+<body>
+<div class="container">
+ <h1>Add contract</h1>
+
+ <form action="addContract.php" method="post">
+ <div class="mb-3">
+ <label for="subscription">Choose subscription:</label>
+ <select name="subscription" id="subscription">
+ <option value="realtime">Realtime</option>
+ <option value="weekly">Weekly</option>
+ <option value="fortnightly">Fortnightly</option>
+ </select>
+ </div>
+ <div class="mb-3">
+ <label for="customer" class="form-label"><b>Customer ID:</b></label>
+ <input type="text" class="form-control" name="customer" id="customer" placeholder="Customer ID">
+ </div>
+ <div class="mb-3">
+ <label for="start-date" class="form-label"><b>Start Date:</b></label>
+ <input class="form-control me-2" type="text" name="start-date" placeholder="Start date (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}">
+ </div>
+ <div class="mb-3">
+ <label for="start-date" class="form-label"><b>End Date:</b></label>
+ <input class="form-control me-2" type="text" name="end-date" placeholder="End date (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}">
+ </div>
+ <label for="token" class="form-label"><b>*token*:</b></label>
+ <div class="form-group">
+ <label for="tariff">Tariff:</label>
+ <a>€</a><input type="number" class="form-control" name="tariff" id="tariff" placeholder="Tariff" style="display: inline-block; width: auto;">
+ </div>
+ <div class="mb-3">
+ <label for="addition" class="form-label"><b>Additional information:</b></label>
+ <input type="text" class="form-control" name="addition" id="addition" placeholder="Additional information" style="height: 200px;">
+ </div>
+ <button type="submit" class="btn btn-primary" name="submit">Voeg toe</button>
+ </form>
+</div>
+<?php
+$connect = new Connect;
+$conn = $connect->getConn();
+
+if ($_SERVER["REQUEST_METHOD"] == "POST") {
+ $errors = array(); // initialize an empty array to store errors
+
+ // Check if voornaam is set and not empty
+ if (isset($_POST['voornaam']) && !empty($_POST['voornaam'])) {
+ $fname = $_POST['voornaam'];
+ } else {
+ $errors[] = "Voornaam is required";
+ }
+
+ // Check if achternaam is set and not empty
+ if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
+ $lname = $_POST['achternaam'];
+ } else {
+ $errors[] = "Achternaam is required";
+ }
+
+ // Check if email is set and not empty
+ if (isset($_POST['email']) && !empty($_POST['email'])) {
+ $email = $_POST['email'];
+ } else {
+ $errors[] = "E-mail is required";
+ }
+
+ // Check if password is set and not empty
+ if (isset($_POST['password']) && !empty($_POST['password'])) {
+ $password = $_POST['password'];
+ } else {
+ $errors[] = "Wachtwoord is required";
+ }
+
+ // Check if permissions is set
+ if (isset($_POST['permissions'])) {
+ $permissions = $_POST['permissions'];
+ } else {
+ $errors[] = "Permissies zijn vereist";
+ }
+
+ // Check if there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ echo $error . "<br>";
+ }
+ } else {
+ // Pass the password through a hashing function
+ $hash = password_hash($password, PASSWORD_DEFAULT);
+
+ // Making a sql statement to add user to the database, preparing it and excuting
+ $sql = "INSERT INTO medewerkers (email, voornaam, achternaam, wachtwoord) VALUES(?, ?, ?, ?)";
+ $stmt= $conn->prepare($sql);
+ $stmt->bind_param("ssss", $email, $fname, $lname, $hash);
+ $stmt->execute();
+
+ //Excecuting a sql statement for all the user permissions
+ foreach($permissions as $perm){
+ $sql = "INSERT INTO medewerkers_permissie (email, permissie_id) VALUES (?, ?);";
+ $stmt= $conn->prepare($sql);
+ $stmt->bind_param("si", $email, $perm);
+ $stmt->execute();
+ }
+ }
+}
+// closing the connection
+mysqli_close($conn);
+?>
+</body>
+</html>
diff --git a/alteruser.php b/alteruser.php
@@ -2,7 +2,7 @@
<html lang="nl">
<head>
- <title>User aanpassen</title>
+ <title>Edit user</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
</head>
@@ -16,23 +16,23 @@ if (!in_array(1, $_SESSION['permissions'])) {
<body>
<div class="container">
- <h1>User aanpassen</h1>
+ <h1>Edit user</h1>
<form action="crud_user.php" method="post">
<div class="mb-3">
- <label for="voornaam" class="form-label"><b>Voornaam:</b></label>
- <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="Voornaam">
+ <label for="voornaam" class="form-label"><b>First Name:</b></label>
+ <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="First Name">
</div>
<div class="mb-3">
- <label for="achternaam" class="form-label"><b>Achternaam:</b></label>
- <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam">
+ <label for="achternaam" class="form-label"><b>Last Name:</b></label>
+ <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Last Name">
</div>
<div class="mb-3">
<label for="email" class="form-label"><b>Email:</b></label>
<input type="text" class="form-control" name="email" id="email" placeholder="Email">
</div>
<div class="mb-3">
- <label for="password" class="form-label"><b>Wachtwoord:</b></label>
+ <label for="password" class="form-label"><b>Password:</b></label>
<input type="password" class="form-control" name="password" id="password" placeholder="******">
</div>
<p>Please select the user permissions:</p>
@@ -50,7 +50,7 @@ if (!in_array(1, $_SESSION['permissions'])) {
value="3">
<label class="form-check-label" for="Wetenschappelijk medewerker">Wetenschappelijk medewerker</label>
</div>
- <button type="submit" class="btn btn-primary" name="submit">Voeg toe</button>
+ <button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
</div>
<?php
diff --git a/crud_user.php b/crud_user.php
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="nl">
<head>
- <title>User toevoegen</title>
+ <title>Add user</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
</head>
@@ -15,23 +15,23 @@
?>
<body>
<div class="container">
- <h1>User toevoegen</h1>
+ <h1>Add user</h1>
<form action="crud_user.php" method="post">
<div class="mb-3">
- <label for="voornaam" class="form-label"><b>Voornaam:</b></label>
- <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="Voornaam">
+ <label for="voornaam" class="form-label"><b>First Name:</b></label>
+ <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="First Name">
</div>
<div class="mb-3">
- <label for="achternaam" class="form-label"><b>Achternaam:</b></label>
- <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Achternaam">
+ <label for="achternaam" class="form-label"><b>Last Name:</b></label>
+ <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Last Name">
</div>
<div class="mb-3">
<label for="email" class="form-label"><b>Email:</b></label>
<input type="text" class="form-control" name="email" id="email" placeholder="Email">
</div>
<div class="mb-3">
- <label for="password" class="form-label"><b>Wachtwoord:</b></label>
+ <label for="password" class="form-label"><b>Password:</b></label>
<input type="password" class="form-control" name="password" id="password" placeholder="******">
</div>
<p>Please select the user permissions:</p>
@@ -47,7 +47,7 @@
<input type="checkbox" class="form-check-input" id="Wetenschappelijk medewerker" name="permissions[]" value="3">
<label class="form-check-label" for="Wetenschappelijk medewerker">Wetenschappelijk medewerker</label>
</div>
- <button type="submit" class="btn btn-primary" name="submit">Voeg toe</button>
+ <button type="submit" class="btn btn-primary" name="submit">Add</button>
</form>
</div>
<?php
diff --git a/index.php b/index.php
@@ -19,12 +19,10 @@ $router->get('/', function () {
include 'templates/homepage.php';
});
-$router->get('/uitloggen', function () {
- session_destroy();
- include 'templates/login.html';
+$router->get('/addcontract', function () {
+ include 'addContract.php';
});
-
$router->get('/login', function () {
include 'templates/login.html';
});
diff --git a/navbar.php b/navbar.php
@@ -70,9 +70,13 @@
</ul>
</li>
<?php } ?>
+ <li class="nav-item">
+ <a class="nav-link" href="/addContract.php">Add Subscription</a>
+ </li>
</ul>
</div>
</nav>
+
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js"></script>
\ No newline at end of file
diff --git a/searchdata.php b/searchdata.php
@@ -32,12 +32,8 @@ error_reporting(0);
$sql .= " WHERE station_name = ?";
}
- $dateEnd = $_GET['date-end'] . "%";
- $dateBegin = $_GET['date-begin'] . "%";
-
- echo $sql;
-// echo $dateBegin;
-// echo $dateEnd;
+ $dateEnd = ($_GET['date-end']);
+ $dateBegin = ($_GET['date-begin']);
$stmt = $conn->prepare($sql);
if (isset($_GET['date-begin']))