commit b0d458da15e5e46b8f826210603b6308dd6d62f2
parent f069f7b5121c7826914df048e62beee6a239bc31
Author: MoiBaguette <[email protected]>
Date: Tue, 18 Apr 2023 16:42:14 +0200
added routing
Diffstat:
38 files changed, 1627 insertions(+), 1531 deletions(-)
diff --git a/add_contract.php b/add_contract.php
@@ -1,139 +0,0 @@
-<!DOCTYPE html>
-<html lang="nl">
-<head>
- <title>Add contract</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/general.css">
-</head>
-<?php
-include "navbar.php";
-include "utils/autoloader.php";
-if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: dashboard.php');
- exit;
-}
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
-$customer_id = null;
-if($_SERVER['REQUEST_METHOD'] == "GET"){
- if(isset($_GET['email'])){
- $email = $_GET['email'];
- $c = $db->get(Customer::class);
- $c->where('email', $email);
- $customer_id = $c->customer_id;
- }
-}
-$available_subsciptions = [];
-$all_p = $db->all(Subscription::class);
-foreach($all_p as $tmp){
- $available_permissions[$tmp->sub_id] = $tmp->sub_name;
-}
-
-$msg = "";
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $errors = array(); // initialize an empty array to store errors
-
- // Check if subscription type is set and not empty
- if (isset($_POST['subscription']) && !empty($_POST['subscription'])) {
- $sub_type = $_POST['subscription'];
- } else {
- $errors[] = "subscription type is required";
- }
-
- // Check if customer_id is set and not empty
- if (isset($_POST['customer_id']) && !empty($_POST['customer_id'])) {
- $customer_id = $_POST['customer_id'];
- } else {
- $errors[] = "customer_id is required";
- }
-
- // Check if start-date is set and not empty
- if (isset($_POST['start-date']) && !empty($_POST['start-date'])) {
- $start_date = $_POST['start-date'];
- } else {
- $errors[] = "start date is required";
- }
-
- // Check if end-date is set and not empty
- if (isset($_POST['end-date']) && !empty($_POST['end-date'])) {
- $end_date = $_POST['end-date'];
- } else {
- $errors[] = "end date is required";
- }
-
- // Check if permissions is set
- if (isset($_POST['tariff']) && !empty($_POST['tariff'])) {
- $tariff = $_POST['tariff'];
- } else {
- $errors[] = "tarif is required";
- }
- //
- if (isset($_POST['addition']) && !empty($_POST['addition'])) {
- $addition = $_POST['addition'];
- } else {
- $errors[] = "additional information is required";
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- $msg.= $error . "<br>";
- }
- } else {
- $c = $db->get(Contract::class);
- $c->sub_id = (int) $sub_type;
- $c->customer_id = (int) $customer_id;
- $c->start_date = $start_date;
- $c->end_date = $end_date;
- $token = bin2hex(random_bytes(32));
- $c->token = $token;
- $c->tariff = (double) $tariff;
- $c->standards = $addition;
-
- if($c->add())
- $msg = "succes!!!";
- }
- }
-?>
-<body>
-<div class="container">
- <h1>Add contract</h1>
- <form action="add_contract.php" method="post">
- <div class="mb-3">
- <label for="subscription">Choose subscription:</label>
- <select name="subscription" id="subscription">
- <?php
- foreach($available_permissions as $key => $value){
- echo "<option value=\"{$key}\">{$value}</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" id="customer_id" placeholder="Customer ID" value="<?php echo $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="end-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>
- <?php echo $msg;?>
-</div>
-</body>
-</html>
diff --git a/add_customer.php b/add_customer.php
@@ -1,88 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
- <head>
- <title>Add user</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- </head>
- <?php
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- $msg = "";
- 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 there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- $msg .= $error . "<br>";
- }
- } else {
- //create a database object with table customer
- $c = $db->get(Customer::class);
- //check if customer already exists
- if($c->where("email", $email)){
- $msg = "this user already exists: " . $c->email . " " . $c->first_name . " " . $c->last_name;
- }else{
- $c = $db->get(Customer::class);
- //set new user data
- $c->first_name = $fname;
- $c->last_name = $lname;
- $c->email = $email;
- //add user with the add function
- if($c->add()){
- $msg = "added to the db this info:<br> email: {$c->email}<br> firstname: {$c->first_name}<br> lastname: {$c->last_name}";
- };
- }
- }
- }
- ?>
- <body>
- <div class="container">
- <h1>Add customer</h1>
-
- <form action="add_customer.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">
- </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">
- </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>
- <button type="submit" class="btn btn-primary" name="submit">Add customer</button>
- </form>
- <?php echo $msg;?>
- </div>
- </body>
-</html>
diff --git a/add_user.php b/add_user.php
@@ -1,145 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
- <head>
- <title>Add user</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- </head>
- <?php
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- //select the available permissions from the database
- $all_p = $db->all(Permissions::class);
- $available_permissions = [];
- foreach($all_p as $tmp){
- $available_permissions[] = ['id' => $tmp->permission_id, 'name' => $tmp->permission_name];
- }
- $msg = "";
- 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[] = "Permissions are required";
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- $msg .= $error . "<br>";
- }
- } else {
- // Pass the password through a hashing function
- $hashed_pwd = password_hash($password, PASSWORD_DEFAULT);
-
- //create a database object with table user
- $u = $db->get(User::class);
- //check if email already exists
- if($u->where("email", $email)){
- $msg = "this email address is taken: " . $email;
- }else{
- $u = $db->get(User::class);
- $succes = false;
- //set new user data
- $u->email = $email;
- $u->first_name = $fname;
- $u->last_name = $lname;
- $u->password = $hashed_pwd;
-
- //add user with the add function
- if($u->add()){
- $succes = true;
- };
- $u = $db->get(User::class);
- $u->where("email", $email);
- //create a database object with table permission for each permission
- //set the data and execute the add function
- foreach($permissions as $permission){
- $p = $db->get(Permission_user::class);
- $p->user_id = $u->user_id;
- $p->permission_id = (int) $permission;
- if($p->add())
- {
- $succes = true;
- }
- }
- if($succes){
- $msg = "succes! user with email: {$email} was added to the db";
- }
- }
- }
- }
- ?>
- <body>
- <div class="container">
- <h1>Add user</h1>
-
- <form action="add_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">
- </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">
- </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>
- <input type="password" class="form-control" name="password" id="password" placeholder="******">
- </div>
- <p>Please select the user permissions:</p>
- <?php
- foreach($available_permissions as $db_permission){
- echo "<div class=\"mb-3 form-check\">
- <input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission['id'] . "\">
- <label class=\"form-check-label\" for=" . $db_permission['name'] . ">" . $db_permission['name'] . "</label>
- </div>";
- }
- ?>
- <button type="submit" class="btn btn-primary" name="submit">Add user</button>
- </form>
- <?php echo $msg;?>
- </div>
- </body>
-</html>
diff --git a/alter_contract.php b/alter_contract.php
@@ -1,167 +0,0 @@
-<!DOCTYPE html>
-<html lang="nl">
-<head>
- <title>Add contract</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
-</head>
-<?php
-include "navbar.php";
-include "utils/autoloader.php";
-if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: dashboard.php');
- exit;
-}
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
-$customer_id = null;
-if($_SERVER['REQUEST_METHOD'] == "GET"){
- if(isset($_GET['contract_id'])){
- $c = $db->get(Contract::class);
- $c->where('contract_id', $_GET['contract_id']);
- $customer_id = $c->customer_id;
- $contract_id = $c->contract_id;
- $sub_type = $c->sub_id;
- $start_date = $c->start_date;
- $end_date = $c->end_date;
- $tariff = $c->tariff;
- $addition = $c->standards;
- }else{
- $customer_id = "";
- $selected = "";
- $start_date = "";
- $end_date = "";
- $tariff = "";
- $addition = "";
- }
-}
-$msg = "";
-$available_subsciptions = [];
-$all_p = $db->all(Subscription::class);
-foreach($all_p as $tmp){
- $available_permissions[$tmp->sub_id] = $tmp->sub_name;
-}
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $errors = array(); // initialize an empty array to store errors
-
- // Check if subscription type is set and not empty
- if (isset($_POST['subscription']) && !empty($_POST['subscription'])) {
- $sub_type = $_POST['subscription'];
- } else {
- $errors[] = "subscription type is required";
- }
-
- // Check if customer_id is set and not empty
- if (isset($_POST['customer_id']) && !empty($_POST['customer_id'])) {
- $customer_id = $_POST['customer_id'];
- } else {
- $errors[] = "customer_id is required";
- }
- // Check if contract_id is set and not empty
- if (isset($_POST['contract_id']) && !empty($_POST['contract_id'])) {
- $contract_id = $_POST['contract_id'];
- } else {
- $errors[] = "contract_id is required";
- }
-
- // Check if start-date is set and not empty
- if (isset($_POST['start-date']) && !empty($_POST['start-date'])) {
- $start_date = $_POST['start-date'];
- } else {
- $errors[] = "start date is required";
- }
-
- // Check if end-date is set and not empty
- if (isset($_POST['end-date']) && !empty($_POST['end-date'])) {
- $end_date = $_POST['end-date'];
- } else {
- $errors[] = "end date is required";
- }
-
- // Check if permissions is set
- if (isset($_POST['tariff']) && !empty($_POST['tariff'])) {
- $tariff = $_POST['tariff'];
- } else {
- $errors[] = "tarif is required";
- }
- //
- if (isset($_POST['addition']) && !empty($_POST['addition'])) {
- $addition = $_POST['addition'];
- } else {
- $errors[] = "additional information is required";
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- echo $error . "<br>";
- }
- } else {
- $c = $db->get(Contract::class);
- if(!$c->where('contract_id', (int) $contract_id)){
- $msg = "this contract does not exist";
- }else{
- $c->sub_id = (int) $sub_type;
- $c->customer_id = (int) $customer_id;
- $c->start_date = $start_date;
- $c->end_date = $end_date;
- $token = bin2hex(random_bytes(32));
- $c->token = $token;
- $c->tariff = (double) $tariff;
- $c->standards = $addition;
-
- if($c->save()){
- $msg = "update to the db this info:<br> contract id: {$c->customer_id}<br> start date: {$c->start_date}<br> end date: {$c->end_date} addition: {$c->standards}";
- }
- }
- }
-}
-?>
-<body>
-<div class="container">
- <h1>Add contract</h1>
- <form action="alter_contract.php" method="post">
- <div class="mb-3">
- <label for="subscription">Choose subscription:</label>
- <select name="subscription" id="subscription">
- <?php
- $tmp = "";
- foreach($available_permissions as $key => $value){
- if($sub_type == $value)
- $tmp = "selected";
- else
- $tmp = "selected";
- echo "<option value=\"{$key} {$tmp}\">{$value}</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" id="customer_id" placeholder="Customer ID" value="<?php echo $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}" value=<?php echo$start_date;?>>
- </div>
- <div class="mb-3">
- <label for="end-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}" value=<?php echo$end_date;?>>
- </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;" value=<?php echo$tariff;?>>
- </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;" value=<?php echo$addition;?>>
- </div>
- <input type="hidden" name="contract_id" value=<?php echo$contract_id;?>>
- <button type="submit" class="btn btn-primary" name="submit">Alter contract</button>
- </form>
- <?php echo $msg;?>
-</div>
-</body>
-</html>
diff --git a/alter_customer.php b/alter_customer.php
@@ -1,109 +0,0 @@
-<!DOCTYPE html>
-<!--Deltron 3030 - The mastermind -->
-<html lang="eng">
- <head>
- <title>Add user</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- </head>
-<?php
-include "navbar.php";
-include "utils/autoloader.php";
-if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
-}
-$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- //if not found set to empty if not GET
-$fname = "";
-$lname = "";
-$email = "";
-$msg = "";
-if($_SERVER["REQUEST_METHOD"] == "GET"){
- //if the get var isset and user is found in the database load data into forms
- if(!isset($_GET['email'])){
- echo"";
- }else{
- $get_email = $_GET['email'];
- $c = $db->get(Customer::class);
- if($c->where("email", $get_email)){
- $fname = $c->first_name;
- $lname = $c->last_name;
- $email = $c->email;
- $customer_id = $c->customer_id;
- }
- }
-}
-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 there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- $msg .= $error . "<br>";
- }
- } else {
- //create a database object with table customer
- $c = $db->get(Customer::class);
- //check if customer already exists
- if(!$c->where("email", $email)){
- $msg = "this user does not exist: " . $email . " " . $fname . " " . $lname;
- }else{
- $c = $db->get(Customer::class);
- $c->where('email', $email);
- //set new user data
- $c->first_name = $fname;
- $c->last_name = $lname;
- $c->email = $email;
- //add user with the add function
- if($c->save()){
- $msg = "update to the db this info:<br> email: {$c->email}<br> firstname: {$c->first_name}<br> lastname: {$c->last_name}";
- };
- }
- }
-}
-?>
- <body>
- <div class="container">
- <h1>Alter customer</h1>
-
- <form action="alter_customer.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" value=<?php echo$fname?>>
- </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" value=<?php echo$lname?>>
- </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" value=<?php echo$email?>>
- </div>
- <button type="submit" class="btn btn-primary" name="submit">Alter customer</button>
- </form>
- <?php echo $msg;?>
- </div>
- </body>
-</html>
diff --git a/alter_user.php b/alter_user.php
@@ -1,181 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
-
-<head>
- <title>User toevoegen</title>
- <!-- Bootstrap CSS -->
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
-</head>
-<?php
-use Lollipop\DatabaseObject;
-use Lollipop\SQLDatabase;
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- $msg = "";
- //select the available permissions from the database
- $all_p = $db->all(Permissions::class);
- $available_permissions = [];
- foreach($all_p as $tmp){
- $available_permissions[] = ['id' => $tmp->permission_id, 'name' => $tmp->permission_name];
- }
- //if not found set to empty if not GET
- $fname = "";
- $lname = "";
- $email = "";
- $user_permissions = [];
-
- if($_SERVER["REQUEST_METHOD"] == "GET"){
- //if the get var isset and user is found in the database load data into forms
- if(!isset($_GET['email'])){
- echo"";
- }else{
- $get_email = $_GET['email'];
- $u = $db->get(User::class);
- $u->where("email", $get_email);
- if($u->email != null){
- $fname = $u->first_name;
- $lname = $u->last_name;
- $email = $u->email;
- $p = $db->all_where(Permission_user::class, array('user_id' => $u->user_id));
- foreach($p as $permission){
- $user_permissions[] = $permission->permission_id;
- }
- }
- }
- }
- 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[] = "First name is required";
- }
-
- // Check if achternaam is set and not empty
- if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
- $lname = $_POST['achternaam'];
- } else {
- $errors[] = "Last name 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 permissions is set
- if (isset($_POST['permissions'])) {
- $permissions = $_POST['permissions'];
- }
-
- // Check if there are any errors
- if (count($errors) > 0) {
- // Print out the errors
- foreach ($errors as $error) {
- $msg .= $error . "<br>";
- }
- } else {
- //create a database object with table user
- $u = $db->get(User::class);
- $u->where("email", $email);
- $user_id = $u->user_id;
- //check if email already exists
- if($u->email == null){
- $msg = "this user does not exist " . $email;
- }else{
- $succes = false;
- //set new user data
- $u->email = $email;
- $u->user_id = $user_id;
- $u->first_name = $fname;
- $u->last_name = $lname;
- //add user with the add function
- if( $u->save()){
- $succes = true;
- };
-
- $p = $db->get(Permission_user::class);
- //delete all permissions
- foreach($available_permissions as $available){
- $p->user_id = $user_id;
- $p->permission_id = $available['id'];
- $p->delete();
- }
-
- //add permissions
- if(isset($permissions)){
- foreach($permissions as $keep){
- $p->user_id = $user_id;
- $p->permission_id = (int)$keep;
- $p->add();
- }
- }
- if($succes){
- $msg = "succes! changes saved to the database";
- }
- }
- }
- //if the get var isset and user is found in the database load data into forms
- if(!isset($_GET['email'])){
- echo"";
- }else{
- $get_email = $_GET['email'];
- $u = $db->get(User::class);
- $u->where("email", $email);
- if($u->email != null){
- $fname = $u->first_name;
- $lname = $u->last_name;
- $email = $u->email;
- $p = $db->all_where(Permission_user::class, array('user_id' => $u->user_id));
- foreach($p as $permission){
- $user_permissions[] = $permission->permission_id;
- }
- }
- }
- }
-?>
-
-<body>
- <div class="container">
- <h1>Alter user</h1>
- <form action="alter_user.php?email=<?php echo $email;?>" method="post">
- <div class="mb-3">
- <label for="voornaam" class="form-label"><b>First name:</b></label>
- <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="First name" value=<?php echo$fname?>>
- </div>
- <div class="mb-3">
- <label for="achternaam" class="form-label"><b>Last name:</b></label>
- <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Last name" value=<?php echo$lname?>>
- </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" value=<?php echo$email?>>
- </div>
- <p>Please select the user permissions:</p>
- <?php
- foreach($available_permissions as $db_permission){
- echo "<div class=\"mb-3 form-check\">" .
- "<input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission['id'] . "\"";
- if ($user_permissions != null && in_array($db_permission['id'], $user_permissions)) {
- echo " checked";
- }
- echo "><label class=\"form-check-label\" for=" . $db_permission['name'] . ">" . $db_permission['name'] . "</label>" .
- "</div>";
- }
- ?>
- <button type="submit" class="btn btn-primary" name="submit">Alter user</button>
- </form>
- <?php echo $msg;?>
- </div>
-</body>
-</html>
-\ No newline at end of file
diff --git a/dashboard.php b/dashboard.php
@@ -1,20 +0,0 @@
-<html>
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- </head>
- <?php
- include "navbar.php";
- echo "voornaam = ";
- echo $_SESSION['first_name'];
- echo "<br>";
- echo "achternaam = ";
- echo $_SESSION['last_name'];
- echo "<br>";
- echo "email = ";
- echo $_SESSION['email'];
- echo "<br>";
- foreach($_SESSION['user_permissions'] as $tmp){
- echo $tmp;
- }
- ?>
-</html>
diff --git a/datainserter.php b/datainserter.php
@@ -1,133 +0,0 @@
-<?php
-// Server connection details
-$servername = "86.92.67.21";
-$username = "friedel";
-$password = "hailiwa";
-$dbname = "wap2";
-
-$redis = new Redis();
-$redis->connect('127.0.0.1', 6379);
-
-// Create connection
-$db_connection = mysqli_connect($servername, $username, $password, $dbname);
-
-// Check connection
-if (!$db_connection) {
- die("Connection failed: " . mysqli_connect_error());
-}
-
-// Check if request method is POST
-if ($_SERVER['REQUEST_METHOD'] == 'POST') {
-
- // Include data validator function
- include 'datavalidator.php';
-
- // Retrieve the raw request body data
- $request_body = file_get_contents('php://input');
-
- // Decode the JSON data into a PHP associative array
- $data = json_decode($request_body, true);
-
- // Access the "WEATHERDATA" array from the decoded data
- $weather_data = $data['WEATHERDATA'];
-
- // Loop through each weather data object and insert it into the database
- foreach ($weather_data as $weather_obj) {
- $stn = $weather_obj['STN'];
- $date = $weather_obj['DATE'];
- $time = $weather_obj['TIME'];
- $temp = $weather_obj['TEMP'];
- $dewp = $weather_obj['DEWP'];
- $stp = $weather_obj['STP'];
- $slp = $weather_obj['SLP'];
- $visib = $weather_obj['VISIB'];
- $wdsp = $weather_obj['WDSP'];
- $prcp = $weather_obj['PRCP'];
- $sndp = $weather_obj['SNDP'];
- $frshtt = $weather_obj['FRSHTT'];
- $cldc = $weather_obj['CLDC'];
- $wnddir = $weather_obj['WNDDIR'];
-
-// $stn = 637200;
-// $date = "2022-02-09";
-// $time = "00:00:58";
-// $temp = 10.1;
-// $dewp = 1.5;
-// $stp = 984.1;
-// $slp = 1012.6;
-// $visib = 23.4;
-// $wdsp = 13.8;
-// $prcp = 0.00;
-// $sndp = 0.0;
-// $frshtt = "000000";
-// $cldc = 96.8;
-// $wnddir = 228;
-
- // Validate temperature
- $valid = validate_temperature($stn, $temp, $redis);
-
- // Prepare SQL INSERT-statement
- $sql = "INSERT INTO weather_data (station_name,date_time,validated,temperature,dew_point,pressure_sea,pressure_station,visibility,
- wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
-
- // Create prepared statement with the SQL statement
- $stmt = mysqli_prepare($db_connection, $sql);
-
- // Concatenate date and time
- $datetime = $date . " " . $time;
-
- // Extract the boolean values from $frshtt
- $frost = (int)substr($frshtt, 0, 1);
- $rain = (int)substr($frshtt, 1, 1);
- $snow = (int)substr($frshtt, 2, 1);
- $hail = (int)substr($frshtt, 3, 1);
- $thunder = (int)substr($frshtt, 4, 1);
- $tornado = (int)substr($frshtt, 5, 1);
-
- // Bind parameters to prepared statement
- mysqli_stmt_bind_param($stmt, "isiddddddddsiiiiiidi", $stn, $datetime, $valid, $temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
-
- // Execute prepared statement, only if the data is not within the first 30 entries
- $result = mysqli_stmt_execute($stmt);
-
-
- // wanneer $valid -1 is zal deze tot de eerste 30 waarden van een station behoren, en dus niet in de database worden gemikt
-// if ($valid == -1) {
-// echo "entry geskipt";
-// $result = false;
-// }
-
- // Second Insert for shadow table
- if ($valid == -1) {
- $sql2 = "SELECT data_id from weather_data where station_name = ? and date_time = ?";
- $stmt2 = mysqli_prepare($db_connection, $sql2);
- mysqli_stmt_bind_param($stmt2, "is", $stn, $datetime);
- $stmt2->execute();
- $result = $stmt2->get_result();
- $row = $result->fetch_assoc();
- $data_id = $row['data_id'];
-
- $sql3 = "INSERT INTO weather_data_corrected (station_name, origin_data_id, date_time,temperature,dew_point,pressure_sea,pressure_station,visibility,
- wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- $stmt3 = mysqli_prepare($db_connection, $sql3);
- $new_temp = round($redis->lIndex('average'.$stn, 0), 1);
- mysqli_stmt_bind_param($stmt3, "iisddddddddsiiiiiidi", $stn, $data_id, $datetime, $new_temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
- $result = mysqli_stmt_execute($stmt3);
- }
-
-
- // Check if the insertion was successful
- if ($result) {
- echo "Data inserted successfully";
- }
- else {
- echo "Error inserting data: " . mysqli_error($db_connection);
- }
- }
-}
-
-// Close the database connection
-mysqli_close($db_connection);
-?>
diff --git a/datavalidator.php b/datavalidator.php
@@ -1,48 +0,0 @@
-<?php
-
-
-/**
- * Validates the temperature against the average of the last 30 rows for the given station name.
- *
- * @param string $station The station name to validate against.
- * @param float $temperature The temperature value to validate.
- * @param Redis $redis The Redis connection object.
- * @return float Returns the correct temperature.
- */
-function validate_temperature($station, $temperature, $redis) {
- // Return the correct temperature validated with last 30 values.
-
- //Deze checkt of het de eerste value is en maakt 2 queues aan en knalt de waardes erin.
- if(!$redis->exists('values'.$station)) {
- $redis->lpush('values'.$station, $temperature);
- $redis->lpush('average'.$station, $temperature);
- return 0;
- }
- //Als het aantal values de 30 nog niet bereikt heeft, berekend hij gewoon het gemiddelde en voegt de value toe aan de queue
- else {
- if($redis->llen('values'.$station) < 3) {
- $avg = ($redis->rpop('average'.$station) * $redis->llen('values'.$station) + $temperature) / ($redis->llen('values'.$station) + 1);
- $redis->lpush('average'.$station, $avg);
- $redis->lpush('values'.$station, $temperature);
- return 0;
- }
- //Bij 30 values zal de volgende value eerst gecheckt worden met het bekende gemiddelde en eventueel aangepast worden.
- //Daarna zal deze toegevoegd worden aan de value en average queue. De laatste waarde zal eruit gehaald worden.
- else {
- $current_avg = $redis->lIndex('average'.$station, 0) ?: 0.000000000000001;
- if(abs(($temperature - $current_avg) / $current_avg) > 0.2) {
- $temperature = $current_avg;
- $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
- $redis->lpush('average'.$station, $new_avg);
- $redis->lpush('values'.$station, $temperature);
- return -1;
- }
- else {
- $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
- $redis->lpush('average'.$station, $new_avg);
- $redis->lpush('values'.$station, $temperature);
- return 1;
- }
- }
- }
-}
-\ No newline at end of file
diff --git a/index.php b/index.php
@@ -1,48 +1,137 @@
<?php
-include "Router/Router.php";
+include "utils/Router.php";
$router = new Router\Router();
$router->get('/', function () {
- include 'templates/homepage.php';
+ include 'views/homepage.php';
});
-$router->get('/addcontract', function () {
- include 'addContract.php';
-});
+//views
-$router->get('/login_handler', function () {
- include '../login_handler.php';
+//add contract
+$router->get('/add_contract', function () {
+ include 'views/add_contract.php';
+});
+$router->post('/add_contract', function () {
+ include 'views/add_contract.php';
});
-$router->get('/login', function () {
- include 'templates/login.html';
+//add customer
+$router->get('/add_customer', function () {
+ include 'views/add_customer.php';
+});
+$router->post('/add_customer', function () {
+ include 'views/add_customer.php';
});
+//add user
$router->get('/add_user', function () {
- include 'add_user.php';
+ include 'views/add_user.php';
+});
+$router->post('/add_user', function () {
+ include 'views/add_user.php';
});
-$router->get('/search_user', function () {
- include 'search_user.php';
+//alter_contract
+$router->get('/alter_contract ', function () {
+ include 'views/alter_contract .php';
+});
+$router->post('/alter_contract ', function () {
+ include 'views/alter_contract .php';
+});
+
+//alter_customer
+$router->get('/alter_customer ', function () {
+ include 'views/alter_customer .php';
+});
+$router->post('/alter_customer ', function () {
+ include 'views/alter_customer .php';
});
+//alter_user
$router->get('/alter_user', function () {
- include 'search_user.php';
+ include 'views/alter_user.php';
+});
+$router->post('/alter_user', function () {
+ include 'views/alter_user.php';
});
+//dashboard
$router->get('/dashboard', function () {
- include 'search_data.php';
+ include 'views/dashboard.php';
+});
+
+//homepage
+$router->get('/homepage', function () {
+ include 'views/homepage.php';
+});
+
+//navbar
+$router->get('/navbar', function () {
+ include 'views/navbar.php';
+});
+
+//search_contract
+$router->get('/search_contract', function () {
+ include 'views/search_contract.php';
+});
+$router->post('/search_contract', function () {
+ include 'views/search_contract.php';
+});
+
+//search_customer
+$router->get('/search_customer', function () {
+ include 'views/search_customer.php';
+});
+$router->post('/search_customer', function () {
+ include 'views/search_customer.php';
+});
+
+//search_data
+$router->get('/search_data', function () {
+ include 'views/search_data.php';
+});
+$router->post('/search_data', function () {
+ include 'views/search_data.php';
+});
+
+//search_user
+$router->get('/search_user', function () {
+ include 'views/search_user.php';
+});
+$router->post('/search_user', function () {
+ include 'views/search_user.php';
+});
+
+
+//logic
+
+//login_handler
+$router->get('/login_handler', function () {
+ include 'logic/login_handler.php';
+});
+$router->post('/login_handler', function () {
+ include 'logic/login_handler.php';
+});
+
+//data inserter
+$router->post('/datainserter', function () {
+ include 'logic/datainserter.php';
});
+//log-out
$router->post('/logout', function () {
- include 'logout.php';
+ include 'logic/logout.php';
});
-$router->post('/login', function ($params) {
+//post weather data
+$router->post('/weather_data', function () {
+ include 'logic/postWeatherData.php';
});
+//404
$router->addNotFoundHandler(function (){
- include 'templates/404.html';
+ include 'views/404.html';
});
$router->run();
diff --git a/logic/datainserter.php b/logic/datainserter.php
@@ -0,0 +1,132 @@
+<?php
+// Server connection details
+$servername = "86.92.67.21";
+$username = "friedel";
+$password = "hailiwa";
+$dbname = "wap2";
+
+$redis = new Redis();
+$redis->connect('127.0.0.1', 6379);
+
+// Include data validator function
+ include 'datavalidator.php';
+// Create connection
+$db_connection = mysqli_connect($servername, $username, $password, $dbname);
+
+// Check connection
+if (!$db_connection) {
+ die("Connection failed: " . mysqli_connect_error());
+}
+
+// Check if request method is POST
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+
+ // Retrieve the raw request body data
+ $request_body = file_get_contents('php://input');
+
+ // Decode the JSON data into a PHP associative array
+ $data = json_decode($request_body, true);
+
+ // Access the "WEATHERDATA" array from the decoded data
+ $weather_data = $data['WEATHERDATA'];
+
+ // Loop through each weather data object and insert it into the database
+ foreach ($weather_data as $weather_obj) {
+ $stn = $weather_obj['STN'];
+ $date = $weather_obj['DATE'];
+ $time = $weather_obj['TIME'];
+ $temp = $weather_obj['TEMP'];
+ $dewp = $weather_obj['DEWP'];
+ $stp = $weather_obj['STP'];
+ $slp = $weather_obj['SLP'];
+ $visib = $weather_obj['VISIB'];
+ $wdsp = $weather_obj['WDSP'];
+ $prcp = $weather_obj['PRCP'];
+ $sndp = $weather_obj['SNDP'];
+ $frshtt = $weather_obj['FRSHTT'];
+ $cldc = $weather_obj['CLDC'];
+ $wnddir = $weather_obj['WNDDIR'];
+
+// $stn = 637200;
+// $date = "2022-02-09";
+// $time = "00:00:58";
+// $temp = 10.1;
+// $dewp = 1.5;
+// $stp = 984.1;
+// $slp = 1012.6;
+// $visib = 23.4;
+// $wdsp = 13.8;
+// $prcp = 0.00;
+// $sndp = 0.0;
+// $frshtt = "000000";
+// $cldc = 96.8;
+// $wnddir = 228;
+
+ // Validate temperature
+ $valid = validate_temperature($stn, $temp, $redis);
+
+ // Prepare SQL INSERT-statement
+ $sql = "INSERT INTO weather_data (station_name,date_time,validated,temperature,dew_point,pressure_sea,pressure_station,visibility,
+ wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ // Create prepared statement with the SQL statement
+ $stmt = mysqli_prepare($db_connection, $sql);
+
+ // Concatenate date and time
+ $datetime = $date . " " . $time;
+
+ // Extract the boolean values from $frshtt
+ $frost = (int)substr($frshtt, 0, 1);
+ $rain = (int)substr($frshtt, 1, 1);
+ $snow = (int)substr($frshtt, 2, 1);
+ $hail = (int)substr($frshtt, 3, 1);
+ $thunder = (int)substr($frshtt, 4, 1);
+ $tornado = (int)substr($frshtt, 5, 1);
+
+ // Bind parameters to prepared statement
+ mysqli_stmt_bind_param($stmt, "isiddddddddsiiiiiidi", $stn, $datetime, $valid, $temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
+
+ // Execute prepared statement, only if the data is not within the first 30 entries
+ $result = mysqli_stmt_execute($stmt);
+
+
+ // wanneer $valid -1 is zal deze tot de eerste 30 waarden van een station behoren, en dus niet in de database worden gemikt
+// if ($valid == -1) {
+// echo "entry geskipt";
+// $result = false;
+// }
+
+ // Second Insert for shadow table
+ if ($valid == -1) {
+ $sql2 = "SELECT data_id from weather_data where station_name = ? and date_time = ?";
+ $stmt2 = mysqli_prepare($db_connection, $sql2);
+ mysqli_stmt_bind_param($stmt2, "is", $stn, $datetime);
+ $stmt2->execute();
+ $result = $stmt2->get_result();
+ $row = $result->fetch_assoc();
+ $data_id = $row['data_id'];
+
+ $sql3 = "INSERT INTO weather_data_corrected (station_name, origin_data_id, date_time,temperature,dew_point,pressure_sea,pressure_station,visibility,
+ wind_speed,precipitation,snow_depth,events,frost_boolean,rain_boolean,snow_boolean,hail_boolean,thunder_boolean,tornado_boolean,cloud_count,wind_direction)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ $stmt3 = mysqli_prepare($db_connection, $sql3);
+ $new_temp = round($redis->lIndex('average'.$stn, 0), 1);
+ mysqli_stmt_bind_param($stmt3, "iisddddddddsiiiiiidi", $stn, $data_id, $datetime, $new_temp, $dewp, $stp, $slp, $visib, $wdsp, $prcp, $sndp, $frshtt, $frost, $rain, $snow, $hail, $thunder, $tornado, $cldc, $wnddir);
+ $result = mysqli_stmt_execute($stmt3);
+ }
+
+
+ // Check if the insertion was successful
+ if ($result) {
+ echo "Data inserted successfully";
+ }
+ else {
+ echo "Error inserting data: " . mysqli_error($db_connection);
+ }
+ }
+}
+
+// Close the database connection
+mysqli_close($db_connection);
+?>
diff --git a/logic/datavalidator.php b/logic/datavalidator.php
@@ -0,0 +1,46 @@
+<?php
+/**
+ * Validates the temperature against the average of the last 30 rows for the given station name.
+ *
+ * @param string $station The station name to validate against.
+ * @param float $temperature The temperature value to validate.
+ * @param Redis $redis The Redis connection object.
+ * @return float Returns the correct temperature.
+ */
+function validate_temperature($station, $temperature, $redis) {
+ // Return the correct temperature validated with last 30 values.
+
+ //Deze checkt of het de eerste value is en maakt 2 queues aan en knalt de waardes erin.
+ if(!$redis->exists('values'.$station)) {
+ $redis->lpush('values'.$station, $temperature);
+ $redis->lpush('average'.$station, $temperature);
+ return 0;
+ }
+ //Als het aantal values de 30 nog niet bereikt heeft, berekend hij gewoon het gemiddelde en voegt de value toe aan de queue
+ else {
+ if($redis->llen('values'.$station) < 3) {
+ $avg = ($redis->rpop('average'.$station) * $redis->llen('values'.$station) + $temperature) / ($redis->llen('values'.$station) + 1);
+ $redis->lpush('average'.$station, $avg);
+ $redis->lpush('values'.$station, $temperature);
+ return 0;
+ }
+ //Bij 30 values zal de volgende value eerst gecheckt worden met het bekende gemiddelde en eventueel aangepast worden.
+ //Daarna zal deze toegevoegd worden aan de value en average queue. De laatste waarde zal eruit gehaald worden.
+ else {
+ $current_avg = $redis->lIndex('average'.$station, 0) ?: 0.000000000000001;
+ if(abs(($temperature - $current_avg) / $current_avg) > 0.2) {
+ $temperature = $current_avg;
+ $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
+ $redis->lpush('average'.$station, $new_avg);
+ $redis->lpush('values'.$station, $temperature);
+ return -1;
+ }
+ else {
+ $new_avg = (($redis->rpop('average'.$station) * 3) - $redis->rpop('values'.$station) + $temperature) / 3;
+ $redis->lpush('average'.$station, $new_avg);
+ $redis->lpush('values'.$station, $temperature);
+ return 1;
+ }
+ }
+ }
+}
+\ No newline at end of file
diff --git a/login_handler.php b/logic/login_handler.php
diff --git a/logout.php b/logic/logout.php
diff --git a/postWeatherData.php b/logic/postWeatherData.php
diff --git a/redisconnection.php b/logic/redisconnection.php
diff --git a/navbar.php b/navbar.php
@@ -1,84 +0,0 @@
-<?php
- session_start();
- if(!isset($_SESSION['email'])){
- header('Location: /');
- exit;
- }
- // Get the permission level of the user
- $permission_levels= $_SESSION['user_permissions'];
-
- // Assume $permission_levels is an array containing the user's permission levels
-
- $links = array();
-
- // Define the links for each type of employee
- // Define the links for each type of employee
- if (in_array(1, $permission_levels)) {
- // Admin links
- $admin_links = array(
- array('url' => '/add_user.php', 'title' => 'Add User'),
- array('url' => '/search_user.php', 'title' => 'Search for user'),
- );
- $links[] = array('name' => 'Admin', 'links' => $admin_links);
- }
-
- if (in_array(2, $permission_levels)) {
- // Administrative employee links
- $admin_employee_links = array(
- array('url' => '/add_customer.php', 'title' => 'Add customer'),
- array('url' => '/search_customer.php', 'title' => 'Search customer'),
- array('url' => '/add_contract.php', 'title' => 'Add contract'),
- array('url' => '/search_contract.php', 'title' => 'Search contract'),
- );
- $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links);
- }
-
- if (in_array(3, $permission_levels)) {
- // Scientific employee links
- $scientific_employee_links = array(
- array('url' => 'search_data.php', 'title' => 'Search data'),
- array('url' => 'scientific_employee_page_2.php', 'title' => 'Scientific Employee Page 2'),
- array('url' => 'scientific_employee_page_3.php', 'title' => 'Scientific Employee Page 3')
- );
- $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links);
- }
-
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- if(isset($_POST['logout'])){
- session_unset();
- session_destroy();
- header('Location: login.php');
- exit;
- }
- }
-?>
-
-<nav class="navbar navbar-expand-lg navbar-light bg-light">
- <a class="navbar-brand" href="/dashboard">Dashboard</a>
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarNavDropdown">
- <ul class="navbar-nav">
- <?php foreach($links as $employee_links) { ?>
- <li class="nav-item dropdown">
- <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
- <?php echo $employee_links['name']; ?>
- </a>
- <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>">
- <?php foreach ($employee_links['links'] as $link) { ?>
- <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li>
- <?php } ?>
- </ul>
- </li>
- <?php } ?>
- </ul>
- <form method="post" action="/logout">
- <button type="submit" id='logout' class="btn btn-primary">Log out</button>
- </form>
- </div>
-</nav>
-
-<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
-<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
-<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
diff --git a/search_contract.php b/search_contract.php
@@ -1,88 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- <?php
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- ?>
- </head>
-<body>
- <form class="d-flex" action="search_contract.php" method="post">
- <input class="form-control me-2" type="search" name="search_id" placeholder="ID" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
-</form>
- <?php
-
- $query = [];
- if(isset($_POST['search_id'])) {
- $query["customer_id"] = "{$_POST['search_id']}";
- }
- if(isset($_POST['delete'])){
- $c = $db->get(Contract::class);
- $c->where("customer_id", $_POST['delete']);
- $c->delete();
- }
- if($query == null){
- $query['customer_id'] = "%";
- }
- display_results($db, $query);
- function display_results($db, $query){
- //create a User orm class and load all the records where user like query
- $results = $db->all_where(Contract::class, $query);
-
- // display results
- if($results != null){
- echo "<table class=\"table table-striped\">
- <thead>
- <tr>
- <th>Contract id</th>
- <th>Customer id </th>
- <th>Sub id </th>
- <th>Tariff</th>
- <th>Start date</th>
- <th>End date</th>
- <th>Standards</th>
- <th>Token</th>
- <th>Alter contract data</th>
- <th>Delete</th>
- </tr>
- </thead>
- <tbody>";
- foreach($results as $data) {
- $link_alter = "/alter_contract.php?contract_id=" . $data->contract_id;
- echo "<tr>";
- echo "<td>" . $data->contract_id . "</td>";
- echo "<td>" . $data->customer_id . "</td>";
- echo "<td>" . $data->sub_id . "</td>";
- echo "<td>" . $data->tariff . "</td>";
- echo "<td>" . $data->start_date . "</td>";
- echo "<td>" . $data->end_date . "</td>";
- echo "<td>" . $data->standards . "</td>";
- echo "<td>" . $data->token . "</td>";
- echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
- echo "
- <td>
- <form method=\"post\" action=\"search_contract.php\">
- <button type=\"submit\" name='delete' value=" . $data->customer_id ." ' class=\"btn btn-primary\">Delete</button>
- </form>
- </td>";
- echo "</tr>";
- }
- echo"
- </tbody>
- </table>";
- }else{
- echo "No contracts were found.";
- }
- }
- ?>
- </body>
-</html>
-
diff --git a/search_customer.php b/search_customer.php
@@ -1,90 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- <?php
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- ?>
- </head>
-<body>
- <form class="d-flex" action="search_customer.php" method="post">
- <input class="form-control me-2" type="search" name="search_email" placeholder="Email" aria-label="Search">
- <input class="form-control me-2" type="search" name="search_first_name" placeholder="First name" aria-label="Search">
- <input class="form-control me-2" type="search" name="search_last_name" placeholder="Last name" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
-</form>
- <?php
- $query = [];
- if(isset($_POST['search_email'])) {
- $query["email"] = "%{$_POST['search_email']}%";
- }
- if(isset($_POST['search_last_name'])) {
- $query["first_name"] = "%{$_POST['search_first_name']}%";
- }
- if(isset($_POST['search_first_name'])) {
- $query["last_name"] = "%{$_POST['search_last_name']}%";
- }
- if(isset($_POST['delete'])){
- $c = $db->get(Customer::class);
- $c->where("email", $_POST['delete']);
- $c->delete();
- }
- if($query == []){
- $query['email'] = "%";
- }
- display_results($db, $query);
- function display_results($db, $query){
- //create a User orm class and load all the records where user like query
- $results = $db->all_where(Customer::class, $query);
-
- // display results
- if($results != null){
- echo "<table class=\"table table-striped\">
- <thead>
- <tr>
- <th>Id</th>
- <th>E-mail</th>
- <th>First name</th>
- <th>Last name</th>
- <th>Alter customer data</th>
- <th>Add conctract</th>
- <th>Delete</th>
- </tr>
- </thead>
- <tbody>";
- foreach($results as $data) {
- $link_alter = "/alter_customer.php?email=" . $data->email;
- $link_add_contract = "/add_contract.php?email=" . $data->email;
- echo "<tr>";
- echo "<td>" . $data->customer_id . "</td>";
- echo "<td>" . $data->email . "</td>";
- echo "<td>" . $data->first_name . "</td>";
- echo "<td>" . $data->last_name . "</td>";
- echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
- echo "<td><a href='" . $link_add_contract . "'>Add Contract</a></td>";
- echo "
- <td>
- <form method=\"post\" action=\"search_customer.php\">
- <button type=\"submit\" name='delete' value=" . $data->email ." ' class=\"btn btn-primary\">delete</button>
- </form>
- </td>";
- echo "</tr>";
- }
- echo"
- </tbody>
- </table>";
- }else{
- echo "No customers were found.";
- }
- }
- ?>
- </body>
-</html>
-
diff --git a/search_data.php b/search_data.php
@@ -1,104 +0,0 @@
-<?php
- include "navbar.php";
- include "utils/autoloader.php";
-
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
-
- $weather = $db->get(Weather_data::class);
-
- //$date_begin = '2023-04-04';
- //$date_end = '2023-04-05';
-
- $date_begin = "";
- $date_end = "";
- $station = "";
-
- $query = array();
- if($_SERVER['REQUEST_METHOD'] == 'GET'){
- if(isset($_GET['date_begin']) && !empty($_GET['date_begin'])){
- $date_begin = ($_GET['date_begin'] . "%");
- $query["date_time"][">="] = $date_begin;
- }
- if(isset($_GET['date_end'])&& !empty($_GET['date_end'])){
- $date_end = ($_GET['date_end'] . "%");
- $query["date_time"]["<="] = $date_end;
- }
- if(isset($_GET['station']) && !empty($_GET['station'])){
- $station = ($_GET['station'] . "%");
- $query["station_name"]["="] = $station;
- }
-
- if($query == null){
- $query["station_name"]["LIKE"] = "%";
- }
- $weather_data = $db->getDateRange(Weather_data::class, $query, "DESC");
- //var_dump($weather_data);
- }
-?>
-<html>
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- </head>
- <body>
- <form class="d-flex" action="search_data.php" method="get">
- <input class="form-control me-2" type="text" name="date_begin" placeholder="Date begin (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
- <input class="form-control me-2" type="text" name="date_end" placeholder="Date end (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
- <input class="form-control me-2" type="text" name="station" placeholder="Search" aria-label="Search" value=<?php ?>>
- <button class="btn btn-outline-success" type="submit">Search</button>
- </form>
-
- <?php
- // verification logic and $_SESSION start
- if ($weather_data != null) {?>
- <table class="table table-striped">
- <thead>
- <tr>
- <th> Station name </th>
- <th> Date & Time </th>
- <th> Validated </th>
- <th> Temperature </th>
- <th> Dewpoint </th>
- <th> Sea pressure </th>
- <th> Station pressure </th>
- <th> Visibility </th>
- <th> Wind speed </th>
- <th> Precipitation </th>
- <th> Snow depth </th>
- <th> Events </th>
- <th> Cloud count </th>
- <th> Wind direction </th>
- </tr>
- </thead>
- <tbody>
-
- </tbody>
- <?php
- foreach($weather_data as $data) {
- $link = "/search_data.php?station=" . $data->station_name;
- echo "<tr>";
- echo "<td><a href='" . $link . "'>" . $data->station_name . "</a></td>";
- echo "<td>" . $data->date_time . "</td>";
- echo "<td>" . $data->validated . "</td>";
- echo "<td>" . $data->temperature . "</td>";
- echo "<td>" . $data->dew_point . "</td>";
- echo "<td>" . $data->pressure_sea . "</td>";
- echo "<td>" . $data->pressure_station . "</td>";
- echo "<td>" . $data->visibility . "</td>";
- echo "<td>" . $data->wind_speed . "</td>";
- echo "<td>" . $data->precipitation . "</td>";
- echo "<td>" . $data->snow_depth . "</td>";
- echo "<td>" . $data->events . "</td>";
- echo "<td>" . $data->cloud_count . "</td>";
- echo "<td>" . $data->wind_direction . "</td>";
- echo "</tr>";
- }
- ?>
- </tbody>
- </table>
- <?php
- } else {
- echo "No data found.";
- }
- ?>
- </body>
-</html>
-\ No newline at end of file
diff --git a/search_user.php b/search_user.php
@@ -1,78 +0,0 @@
-<!DOCTYPE html>
-<html lang="eng">
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
- <?php
- include "navbar.php";
- include "utils/autoloader.php";
- if(!in_array(1, $_SESSION['user_permissions'])){
- header('Location: /dashboard');
- exit;
- }
- $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
- ?>
- </head>
-<body>
- <form class="d-flex" action="search_user.php" method="post">
- <input class="form-control me-2" type="search" name="search" placeholder="Email" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
-</form>
- <?php
- if(isset($_POST['search'])) {
- //set $query
- $query = "%" . $_POST['search'] . "%";
- display_results($db, $query);
- }elseif(isset($_POST['delete'])){
- $u = $db->get(User::class);
- $u->where("email", $_POST['delete']);
- $u->delete();
- display_results($db, $_POST['query']);
- }
- else{
- display_results($db, '%');
- }
- function display_results($db, $query){
- //create a User orm class and load all the records where user like query
- $results = $db->all_where(User::class, array('email' => $query));
-
- // display results
- if($results != null){
- echo "<table class=\"table table-striped\">
- <thead>
- <tr>
- <th>E-mail</th>
- <th>First name</th>
- <th>Last name</th>
- <th>Alter</th>
- <th>Delete</th>
- </tr>
- </thead>
- <tbody>";
- foreach($results as $data) {
- $link = "/alter_user.php?email=" . $data->email;
- echo "<tr>";
- echo "<td>" . $data->email . "</td>";
- echo "<td>" . $data->first_name . "</td>";
- echo "<td>" . $data->last_name . "</td>";
- echo "<td><a href='" . $link . "'>Edit</a></td>";
- echo "
- <td>
- <form method=\"post\" action=\"search_user.php\">
- <input type=\"hidden\" name=\"query\" value=" . $query. ">
- <button type=\"submit\" name='delete' value=" . $data->email ." ' class=\"btn btn-primary\">delete</button>
- </form>
- </td>";
- echo "</tr>";
- }
- echo"
- </tbody>
- </table>";
- }else{
- echo "No users with this email address were found.";
- }
- }
- ?>
- </body>
-</html>
-
diff --git a/templates/homepage.php b/templates/homepage.php
@@ -1,37 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>IWA - Weather Stations</title>
- <link rel="stylesheet" type="text/css" href="/css/homepage.css">
-</head>
-<body>
-<div class="header">
- <h1>IWA - Weather Stations</h1>
- <form class="search-form" action="/dashboard">
- <button type="submit">Search for weather stations</button>
- </form>
-</div>
-
-<div class="main">
- <div class="dashboard-section">
- <h2>Dashboard</h2>
- <p>Welcome to your weather station dashboard. Here, you can view real-time weather data from your weather stations, set alerts, and more.</p>
- <a href="/dashboard" class="button">Go to Dashboard</a>
- </div>
- <div class="login-section">
- <h2>Login</h2>
- <form class="login-form" action="../login_handler.php" method="post">
- <label for="email">Email:</label>
- <input type="text" name="email" required>
- <label for="password">Password:</label>
- <input type="password" name="password" required>
- <button type="submit" name='login_btn'>Login</button>
- </form>
- </div>
-</div>
-
-<div class="footer">
- <p>© 2023 IWA. All rights reserved.</p>
-</div>
-</body>
-</html>
diff --git a/Router/Router.php b/utils/Router.php
diff --git a/templates/404.html b/views/404.html
diff --git a/views/add_contract.php b/views/add_contract.php
@@ -0,0 +1,139 @@
+<!DOCTYPE html>
+<html lang="nl">
+<head>
+ <title>Add contract</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/general.css">
+</head>
+<?php
+include "views/navbar.php";
+include "utils/autoloader.php";
+if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: dashboard');
+ exit;
+}
+$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+$customer_id = null;
+if($_SERVER['REQUEST_METHOD'] == "GET"){
+ if(isset($_GET['email'])){
+ $email = $_GET['email'];
+ $c = $db->get(Customer::class);
+ $c->where('email', $email);
+ $customer_id = $c->customer_id;
+ }
+}
+$available_subsciptions = [];
+$all_p = $db->all(Subscription::class);
+foreach($all_p as $tmp){
+ $available_permissions[$tmp->sub_id] = $tmp->sub_name;
+}
+
+$msg = "";
+if ($_SERVER["REQUEST_METHOD"] == "POST") {
+ $errors = array(); // initialize an empty array to store errors
+
+ // Check if subscription type is set and not empty
+ if (isset($_POST['subscription']) && !empty($_POST['subscription'])) {
+ $sub_type = $_POST['subscription'];
+ } else {
+ $errors[] = "subscription type is required";
+ }
+
+ // Check if customer_id is set and not empty
+ if (isset($_POST['customer_id']) && !empty($_POST['customer_id'])) {
+ $customer_id = $_POST['customer_id'];
+ } else {
+ $errors[] = "customer_id is required";
+ }
+
+ // Check if start-date is set and not empty
+ if (isset($_POST['start-date']) && !empty($_POST['start-date'])) {
+ $start_date = $_POST['start-date'];
+ } else {
+ $errors[] = "start date is required";
+ }
+
+ // Check if end-date is set and not empty
+ if (isset($_POST['end-date']) && !empty($_POST['end-date'])) {
+ $end_date = $_POST['end-date'];
+ } else {
+ $errors[] = "end date is required";
+ }
+
+ // Check if permissions is set
+ if (isset($_POST['tariff']) && !empty($_POST['tariff'])) {
+ $tariff = $_POST['tariff'];
+ } else {
+ $errors[] = "tarif is required";
+ }
+ //
+ if (isset($_POST['addition']) && !empty($_POST['addition'])) {
+ $addition = $_POST['addition'];
+ } else {
+ $errors[] = "additional information is required";
+ }
+
+ // Check if there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ $msg.= $error . "<br>";
+ }
+ } else {
+ $c = $db->get(Contract::class);
+ $c->sub_id = (int) $sub_type;
+ $c->customer_id = (int) $customer_id;
+ $c->start_date = $start_date;
+ $c->end_date = $end_date;
+ $token = bin2hex(random_bytes(32));
+ $c->token = $token;
+ $c->tariff = (double) $tariff;
+ $c->standards = $addition;
+
+ if($c->add())
+ $msg = "succes!!!";
+ }
+ }
+?>
+<body>
+<div class="container">
+ <h1>Add contract</h1>
+ <form action="add_contract" method="post">
+ <div class="mb-3">
+ <label for="subscription">Choose subscription:</label>
+ <select name="subscription" id="subscription">
+ <?php
+ foreach($available_permissions as $key => $value){
+ echo "<option value=\"{$key}\">{$value}</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" id="customer_id" placeholder="Customer ID" value="<?php echo $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="end-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>
+ <?php echo $msg;?>
+</div>
+</body>
+</html>
diff --git a/views/add_customer.php b/views/add_customer.php
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <head>
+ <title>Add user</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ </head>
+ <?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ $msg = "";
+ 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 there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ $msg .= $error . "<br>";
+ }
+ } else {
+ //create a database object with table customer
+ $c = $db->get(Customer::class);
+ //check if customer already exists
+ if($c->where("email", $email)){
+ $msg = "this user already exists: " . $c->email . " " . $c->first_name . " " . $c->last_name;
+ }else{
+ $c = $db->get(Customer::class);
+ //set new user data
+ $c->first_name = $fname;
+ $c->last_name = $lname;
+ $c->email = $email;
+ //add user with the add function
+ if($c->add()){
+ $msg = "added to the db this info:<br> email: {$c->email}<br> firstname: {$c->first_name}<br> lastname: {$c->last_name}";
+ };
+ }
+ }
+ }
+ ?>
+ <body>
+ <div class="container">
+ <h1>Add customer</h1>
+
+ <form action="add_customer" 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">
+ </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">
+ </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>
+ <button type="submit" class="btn btn-primary" name="submit">Add customer</button>
+ </form>
+ <?php echo $msg;?>
+ </div>
+ </body>
+</html>
diff --git a/views/add_user.php b/views/add_user.php
@@ -0,0 +1,145 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <head>
+ <title>Add user</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ </head>
+ <?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ //select the available permissions from the database
+ $all_p = $db->all(Permissions::class);
+ $available_permissions = [];
+ foreach($all_p as $tmp){
+ $available_permissions[] = ['id' => $tmp->permission_id, 'name' => $tmp->permission_name];
+ }
+ $msg = "";
+ 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[] = "Permissions are required";
+ }
+
+ // Check if there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ $msg .= $error . "<br>";
+ }
+ } else {
+ // Pass the password through a hashing function
+ $hashed_pwd = password_hash($password, PASSWORD_DEFAULT);
+
+ //create a database object with table user
+ $u = $db->get(User::class);
+ //check if email already exists
+ if($u->where("email", $email)){
+ $msg = "this email address is taken: " . $email;
+ }else{
+ $u = $db->get(User::class);
+ $succes = false;
+ //set new user data
+ $u->email = $email;
+ $u->first_name = $fname;
+ $u->last_name = $lname;
+ $u->password = $hashed_pwd;
+
+ //add user with the add function
+ if($u->add()){
+ $succes = true;
+ };
+ $u = $db->get(User::class);
+ $u->where("email", $email);
+ //create a database object with table permission for each permission
+ //set the data and execute the add function
+ foreach($permissions as $permission){
+ $p = $db->get(Permission_user::class);
+ $p->user_id = $u->user_id;
+ $p->permission_id = (int) $permission;
+ if($p->add())
+ {
+ $succes = true;
+ }
+ }
+ if($succes){
+ $msg = "succes! user with email: {$email} was added to the db";
+ }
+ }
+ }
+ }
+ ?>
+ <body>
+ <div class="container">
+ <h1>Add user</h1>
+
+ <form action="add_user" 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">
+ </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">
+ </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>
+ <input type="password" class="form-control" name="password" id="password" placeholder="******">
+ </div>
+ <p>Please select the user permissions:</p>
+ <?php
+ foreach($available_permissions as $db_permission){
+ echo "<div class=\"mb-3 form-check\">
+ <input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission['id'] . "\">
+ <label class=\"form-check-label\" for=" . $db_permission['name'] . ">" . $db_permission['name'] . "</label>
+ </div>";
+ }
+ ?>
+ <button type="submit" class="btn btn-primary" name="submit">Add user</button>
+ </form>
+ <?php echo $msg;?>
+ </div>
+ </body>
+</html>
diff --git a/views/alter_contract.php b/views/alter_contract.php
@@ -0,0 +1,167 @@
+<!DOCTYPE html>
+<html lang="nl">
+<head>
+ <title>Add contract</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+</head>
+<?php
+include "views/navbar.php";
+include "utils/autoloader.php";
+if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: dashboard');
+ exit;
+}
+$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+$customer_id = null;
+if($_SERVER['REQUEST_METHOD'] == "GET"){
+ if(isset($_GET['contract_id'])){
+ $c = $db->get(Contract::class);
+ $c->where('contract_id', $_GET['contract_id']);
+ $customer_id = $c->customer_id;
+ $contract_id = $c->contract_id;
+ $sub_type = $c->sub_id;
+ $start_date = $c->start_date;
+ $end_date = $c->end_date;
+ $tariff = $c->tariff;
+ $addition = $c->standards;
+ }else{
+ $customer_id = "";
+ $selected = "";
+ $start_date = "";
+ $end_date = "";
+ $tariff = "";
+ $addition = "";
+ }
+}
+$msg = "";
+$available_subsciptions = [];
+$all_p = $db->all(Subscription::class);
+foreach($all_p as $tmp){
+ $available_permissions[$tmp->sub_id] = $tmp->sub_name;
+}
+if ($_SERVER["REQUEST_METHOD"] == "POST") {
+ $errors = array(); // initialize an empty array to store errors
+
+ // Check if subscription type is set and not empty
+ if (isset($_POST['subscription']) && !empty($_POST['subscription'])) {
+ $sub_type = $_POST['subscription'];
+ } else {
+ $errors[] = "subscription type is required";
+ }
+
+ // Check if customer_id is set and not empty
+ if (isset($_POST['customer_id']) && !empty($_POST['customer_id'])) {
+ $customer_id = $_POST['customer_id'];
+ } else {
+ $errors[] = "customer_id is required";
+ }
+ // Check if contract_id is set and not empty
+ if (isset($_POST['contract_id']) && !empty($_POST['contract_id'])) {
+ $contract_id = $_POST['contract_id'];
+ } else {
+ $errors[] = "contract_id is required";
+ }
+
+ // Check if start-date is set and not empty
+ if (isset($_POST['start-date']) && !empty($_POST['start-date'])) {
+ $start_date = $_POST['start-date'];
+ } else {
+ $errors[] = "start date is required";
+ }
+
+ // Check if end-date is set and not empty
+ if (isset($_POST['end-date']) && !empty($_POST['end-date'])) {
+ $end_date = $_POST['end-date'];
+ } else {
+ $errors[] = "end date is required";
+ }
+
+ // Check if permissions is set
+ if (isset($_POST['tariff']) && !empty($_POST['tariff'])) {
+ $tariff = $_POST['tariff'];
+ } else {
+ $errors[] = "tarif is required";
+ }
+ //
+ if (isset($_POST['addition']) && !empty($_POST['addition'])) {
+ $addition = $_POST['addition'];
+ } else {
+ $errors[] = "additional information is required";
+ }
+
+ // Check if there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ echo $error . "<br>";
+ }
+ } else {
+ $c = $db->get(Contract::class);
+ if(!$c->where('contract_id', (int) $contract_id)){
+ $msg = "this contract does not exist";
+ }else{
+ $c->sub_id = (int) $sub_type;
+ $c->customer_id = (int) $customer_id;
+ $c->start_date = $start_date;
+ $c->end_date = $end_date;
+ $token = bin2hex(random_bytes(32));
+ $c->token = $token;
+ $c->tariff = (double) $tariff;
+ $c->standards = $addition;
+
+ if($c->save()){
+ $msg = "update to the db this info:<br> contract id: {$c->customer_id}<br> start date: {$c->start_date}<br> end date: {$c->end_date} addition: {$c->standards}";
+ }
+ }
+ }
+}
+?>
+<body>
+<div class="container">
+ <h1>Add contract</h1>
+ <form action="alter_contract" method="post">
+ <div class="mb-3">
+ <label for="subscription">Choose subscription:</label>
+ <select name="subscription" id="subscription">
+ <?php
+ $tmp = "";
+ foreach($available_permissions as $key => $value){
+ if($sub_type == $value)
+ $tmp = "selected";
+ else
+ $tmp = "selected";
+ echo "<option value=\"{$key} {$tmp}\">{$value}</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" id="customer_id" placeholder="Customer ID" value="<?php echo $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}" value=<?php echo$start_date;?>>
+ </div>
+ <div class="mb-3">
+ <label for="end-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}" value=<?php echo$end_date;?>>
+ </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;" value=<?php echo$tariff;?>>
+ </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;" value=<?php echo$addition;?>>
+ </div>
+ <input type="hidden" name="contract_id" value=<?php echo$contract_id;?>>
+ <button type="submit" class="btn btn-primary" name="submit">Alter contract</button>
+ </form>
+ <?php echo $msg;?>
+</div>
+</body>
+</html>
diff --git a/views/alter_customer.php b/views/alter_customer.php
@@ -0,0 +1,109 @@
+<!DOCTYPE html>
+<!--Deltron 3030 - The mastermind -->
+<html lang="eng">
+ <head>
+ <title>Add user</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ </head>
+<?php
+include "views/navbar.php";
+include "utils/autoloader.php";
+if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+}
+$db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ //if not found set to empty if not GET
+$fname = "";
+$lname = "";
+$email = "";
+$msg = "";
+if($_SERVER["REQUEST_METHOD"] == "GET"){
+ //if the get var isset and user is found in the database load data into forms
+ if(!isset($_GET['email'])){
+ echo"";
+ }else{
+ $get_email = $_GET['email'];
+ $c = $db->get(Customer::class);
+ if($c->where("email", $get_email)){
+ $fname = $c->first_name;
+ $lname = $c->last_name;
+ $email = $c->email;
+ $customer_id = $c->customer_id;
+ }
+ }
+}
+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 there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ $msg .= $error . "<br>";
+ }
+ } else {
+ //create a database object with table customer
+ $c = $db->get(Customer::class);
+ //check if customer already exists
+ if(!$c->where("email", $email)){
+ $msg = "this user does not exist: " . $email . " " . $fname . " " . $lname;
+ }else{
+ $c = $db->get(Customer::class);
+ $c->where('email', $email);
+ //set new user data
+ $c->first_name = $fname;
+ $c->last_name = $lname;
+ $c->email = $email;
+ //add user with the add function
+ if($c->save()){
+ $msg = "update to the db this info:<br> email: {$c->email}<br> firstname: {$c->first_name}<br> lastname: {$c->last_name}";
+ };
+ }
+ }
+}
+?>
+ <body>
+ <div class="container">
+ <h1>Alter customer</h1>
+
+ <form action="alter_customer" 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" value=<?php echo$fname?>>
+ </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" value=<?php echo$lname?>>
+ </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" value=<?php echo$email?>>
+ </div>
+ <button type="submit" class="btn btn-primary" name="submit">Alter customer</button>
+ </form>
+ <?php echo $msg;?>
+ </div>
+ </body>
+</html>
diff --git a/views/alter_user.php b/views/alter_user.php
@@ -0,0 +1,181 @@
+<!DOCTYPE html>
+<html lang="eng">
+
+<head>
+ <title>User toevoegen</title>
+ <!-- Bootstrap CSS -->
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+</head>
+<?php
+use Lollipop\DatabaseObject;
+use Lollipop\SQLDatabase;
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ $msg = "";
+ //select the available permissions from the database
+ $all_p = $db->all(Permissions::class);
+ $available_permissions = [];
+ foreach($all_p as $tmp){
+ $available_permissions[] = ['id' => $tmp->permission_id, 'name' => $tmp->permission_name];
+ }
+ //if not found set to empty if not GET
+ $fname = "";
+ $lname = "";
+ $email = "";
+ $user_permissions = [];
+
+ if($_SERVER["REQUEST_METHOD"] == "GET"){
+ //if the get var isset and user is found in the database load data into forms
+ if(!isset($_GET['email'])){
+ echo"";
+ }else{
+ $get_email = $_GET['email'];
+ $u = $db->get(User::class);
+ $u->where("email", $get_email);
+ if($u->email != null){
+ $fname = $u->first_name;
+ $lname = $u->last_name;
+ $email = $u->email;
+ $p = $db->all_where(Permission_user::class, array('user_id' => $u->user_id));
+ foreach($p as $permission){
+ $user_permissions[] = $permission->permission_id;
+ }
+ }
+ }
+ }
+ 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[] = "First name is required";
+ }
+
+ // Check if achternaam is set and not empty
+ if (isset($_POST['achternaam']) && !empty($_POST['achternaam'])) {
+ $lname = $_POST['achternaam'];
+ } else {
+ $errors[] = "Last name 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 permissions is set
+ if (isset($_POST['permissions'])) {
+ $permissions = $_POST['permissions'];
+ }
+
+ // Check if there are any errors
+ if (count($errors) > 0) {
+ // Print out the errors
+ foreach ($errors as $error) {
+ $msg .= $error . "<br>";
+ }
+ } else {
+ //create a database object with table user
+ $u = $db->get(User::class);
+ $u->where("email", $email);
+ $user_id = $u->user_id;
+ //check if email already exists
+ if($u->email == null){
+ $msg = "this user does not exist " . $email;
+ }else{
+ $succes = false;
+ //set new user data
+ $u->email = $email;
+ $u->user_id = $user_id;
+ $u->first_name = $fname;
+ $u->last_name = $lname;
+ //add user with the add function
+ if( $u->save()){
+ $succes = true;
+ };
+
+ $p = $db->get(Permission_user::class);
+ //delete all permissions
+ foreach($available_permissions as $available){
+ $p->user_id = $user_id;
+ $p->permission_id = $available['id'];
+ $p->delete();
+ }
+
+ //add permissions
+ if(isset($permissions)){
+ foreach($permissions as $keep){
+ $p->user_id = $user_id;
+ $p->permission_id = (int)$keep;
+ $p->add();
+ }
+ }
+ if($succes){
+ $msg = "succes! changes saved to the database";
+ }
+ }
+ }
+ //if the get var isset and user is found in the database load data into forms
+ if(!isset($_GET['email'])){
+ echo"";
+ }else{
+ $get_email = $_GET['email'];
+ $u = $db->get(User::class);
+ $u->where("email", $email);
+ if($u->email != null){
+ $fname = $u->first_name;
+ $lname = $u->last_name;
+ $email = $u->email;
+ $p = $db->all_where(Permission_user::class, array('user_id' => $u->user_id));
+ foreach($p as $permission){
+ $user_permissions[] = $permission->permission_id;
+ }
+ }
+ }
+ }
+?>
+
+<body>
+ <div class="container">
+ <h1>Alter user</h1>
+ <form action="alter_user?email=<?php echo $email;?>" method="post">
+ <div class="mb-3">
+ <label for="voornaam" class="form-label"><b>First name:</b></label>
+ <input type="text" class="form-control" name="voornaam" id="voornaam" placeholder="First name" value=<?php echo$fname?>>
+ </div>
+ <div class="mb-3">
+ <label for="achternaam" class="form-label"><b>Last name:</b></label>
+ <input type="text" class="form-control" name="achternaam" id="achternaam" placeholder="Last name" value=<?php echo$lname?>>
+ </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" value=<?php echo$email?>>
+ </div>
+ <p>Please select the user permissions:</p>
+ <?php
+ foreach($available_permissions as $db_permission){
+ echo "<div class=\"mb-3 form-check\">" .
+ "<input type=\"checkbox\" class=\"form-check-input\" name=\"permissions[]\" value=" . $db_permission['id'] . "\"";
+ if ($user_permissions != null && in_array($db_permission['id'], $user_permissions)) {
+ echo " checked";
+ }
+ echo "><label class=\"form-check-label\" for=" . $db_permission['name'] . ">" . $db_permission['name'] . "</label>" .
+ "</div>";
+ }
+ ?>
+ <button type="submit" class="btn btn-primary" name="submit">Alter user</button>
+ </form>
+ <?php echo $msg;?>
+ </div>
+</body>
+</html>
+\ No newline at end of file
diff --git a/views/dashboard.php b/views/dashboard.php
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ </head>
+ <?php
+ include "views/navbar.php";
+ echo "voornaam = ";
+ echo $_SESSION['first_name'];
+ echo "<br>";
+ echo "achternaam = ";
+ echo $_SESSION['last_name'];
+ echo "<br>";
+ echo "email = ";
+ echo $_SESSION['email'];
+ echo "<br>";
+ foreach($_SESSION['user_permissions'] as $tmp){
+ echo $tmp;
+ }
+ ?>
+</html>
diff --git a/views/homepage.php b/views/homepage.php
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>IWA - Weather Stations</title>
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+</head>
+<body>
+<div class="header">
+ <h1>IWA - Weather Stations</h1>
+ <form class="search-form" action="/dashboard">
+ <button type="submit">Search for weather stations</button>
+ </form>
+</div>
+
+<div class="main">
+ <div class="dashboard-section">
+ <h2>Dashboard</h2>
+ <p>Welcome to your weather station dashboard. Here, you can view real-time weather data from your weather stations, set alerts, and more.</p>
+ <a href="/dashboard" class="button">Go to Dashboard</a>
+ </div>
+ <div class="login-section">
+ <h2>Login</h2>
+ <form class="login-form" action="login_handler" method="post">
+ <label for="email">Email:</label>
+ <input type="text" name="email" required>
+ <label for="password">Password:</label>
+ <input type="password" name="password" required>
+ <button type="submit" name='login_btn'>Login</button>
+ </form>
+ </div>
+</div>
+
+<div class="footer">
+ <p>© 2023 IWA. All rights reserved.</p>
+</div>
+</body>
+</html>
diff --git a/views/navbar.php b/views/navbar.php
@@ -0,0 +1,84 @@
+<?php
+ session_start();
+ if(!isset($_SESSION['email'])){
+ header('Location: /');
+ exit;
+ }
+ // Get the permission level of the user
+ $permission_levels= $_SESSION['user_permissions'];
+
+ // Assume $permission_levels is an array containing the user's permission levels
+
+ $links = array();
+
+ // Define the links for each type of employee
+ // Define the links for each type of employee
+ if (in_array(1, $permission_levels)) {
+ // Admin links
+ $admin_links = array(
+ array('url' => '/add_user', 'title' => 'Add User'),
+ array('url' => '/search_user', 'title' => 'Search for user'),
+ );
+ $links[] = array('name' => 'Admin', 'links' => $admin_links);
+ }
+
+ if (in_array(2, $permission_levels)) {
+ // Administrative employee links
+ $admin_employee_links = array(
+ array('url' => '/add_customer', 'title' => 'Add customer'),
+ array('url' => '/search_customer', 'title' => 'Search customer'),
+ array('url' => '/add_contract', 'title' => 'Add contract'),
+ array('url' => '/search_contract', 'title' => 'Search contract'),
+ );
+ $links[] = array('name' => 'Administrative Employee', 'links' => $admin_employee_links);
+ }
+
+ if (in_array(3, $permission_levels)) {
+ // Scientific employee links
+ $scientific_employee_links = array(
+ array('url' => 'search_data', 'title' => 'Search data'),
+ array('url' => 'scientific_employee_page_2', 'title' => 'Scientific Employee Page 2'),
+ array('url' => 'scientific_employee_page_3', 'title' => 'Scientific Employee Page 3')
+ );
+ $links[] = array('name' => 'Scientific Employee', 'links' => $scientific_employee_links);
+ }
+
+ if($_SERVER["REQUEST_METHOD"] == "POST"){
+ if(isset($_POST['logout'])){
+ session_unset();
+ session_destroy();
+ header('Location: login');
+ exit;
+ }
+ }
+?>
+
+<nav class="navbar navbar-expand-lg navbar-light bg-light">
+ <a class="navbar-brand" href="/dashboard">Dashboard</a>
+ <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
+ <span class="navbar-toggler-icon"></span>
+ </button>
+ <div class="collapse navbar-collapse" id="navbarNavDropdown">
+ <ul class="navbar-nav">
+ <?php foreach($links as $employee_links) { ?>
+ <li class="nav-item dropdown">
+ <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+ <?php echo $employee_links['name']; ?>
+ </a>
+ <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink<?php echo $employee_links['name']; ?>">
+ <?php foreach ($employee_links['links'] as $link) { ?>
+ <li><a class="dropdown-item" href="<?php echo $link['url']; ?>"><?php echo $link['title']; ?></a></li>
+ <?php } ?>
+ </ul>
+ </li>
+ <?php } ?>
+ </ul>
+ <form method="post" action="/logout">
+ <button type="submit" id='logout' class="btn btn-primary">Log out</button>
+ </form>
+ </div>
+</nav>
+
+<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
+<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
diff --git a/views/search_contract.php b/views/search_contract.php
@@ -0,0 +1,88 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ <?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ ?>
+ </head>
+<body>
+ <form class="d-flex" action="search_contract" method="post">
+ <input class="form-control me-2" type="search" name="search_id" placeholder="ID" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+</form>
+ <?php
+
+ $query = [];
+ if(isset($_POST['search_id'])) {
+ $query["customer_id"] = "{$_POST['search_id']}";
+ }
+ if(isset($_POST['delete'])){
+ $c = $db->get(Contract::class);
+ $c->where("customer_id", $_POST['delete']);
+ $c->delete();
+ }
+ if($query == null){
+ $query['customer_id'] = "%";
+ }
+ display_results($db, $query);
+ function display_results($db, $query){
+ //create a User orm class and load all the records where user like query
+ $results = $db->all_where(Contract::class, $query);
+
+ // display results
+ if($results != null){
+ echo "<table class=\"table table-striped\">
+ <thead>
+ <tr>
+ <th>Contract id</th>
+ <th>Customer id </th>
+ <th>Sub id </th>
+ <th>Tariff</th>
+ <th>Start date</th>
+ <th>End date</th>
+ <th>Standards</th>
+ <th>Token</th>
+ <th>Alter contract data</th>
+ <th>Delete</th>
+ </tr>
+ </thead>
+ <tbody>";
+ foreach($results as $data) {
+ $link_alter = "/alter_contract?contract_id=" . $data->contract_id;
+ echo "<tr>";
+ echo "<td>" . $data->contract_id . "</td>";
+ echo "<td>" . $data->customer_id . "</td>";
+ echo "<td>" . $data->sub_id . "</td>";
+ echo "<td>" . $data->tariff . "</td>";
+ echo "<td>" . $data->start_date . "</td>";
+ echo "<td>" . $data->end_date . "</td>";
+ echo "<td>" . $data->standards . "</td>";
+ echo "<td>" . $data->token . "</td>";
+ echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
+ echo "
+ <td>
+ <form method=\"post\" action=\"search_contract\">
+ <button type=\"submit\" name='delete' value=" . $data->customer_id ." ' class=\"btn btn-primary\">Delete</button>
+ </form>
+ </td>";
+ echo "</tr>";
+ }
+ echo"
+ </tbody>
+ </table>";
+ }else{
+ echo "No contracts were found.";
+ }
+ }
+ ?>
+ </body>
+</html>
+
diff --git a/views/search_customer.php b/views/search_customer.php
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ <?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ ?>
+ </head>
+<body>
+ <form class="d-flex" action="search_customer" method="post">
+ <input class="form-control me-2" type="search" name="search_email" placeholder="Email" aria-label="Search">
+ <input class="form-control me-2" type="search" name="search_first_name" placeholder="First name" aria-label="Search">
+ <input class="form-control me-2" type="search" name="search_last_name" placeholder="Last name" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+</form>
+ <?php
+ $query = [];
+ if(isset($_POST['search_email'])) {
+ $query["email"] = "%{$_POST['search_email']}%";
+ }
+ if(isset($_POST['search_last_name'])) {
+ $query["first_name"] = "%{$_POST['search_first_name']}%";
+ }
+ if(isset($_POST['search_first_name'])) {
+ $query["last_name"] = "%{$_POST['search_last_name']}%";
+ }
+ if(isset($_POST['delete'])){
+ $c = $db->get(Customer::class);
+ $c->where("email", $_POST['delete']);
+ $c->delete();
+ }
+ if($query == []){
+ $query['email'] = "%";
+ }
+ display_results($db, $query);
+ function display_results($db, $query){
+ //create a User orm class and load all the records where user like query
+ $results = $db->all_where(Customer::class, $query);
+
+ // display results
+ if($results != null){
+ echo "<table class=\"table table-striped\">
+ <thead>
+ <tr>
+ <th>Id</th>
+ <th>E-mail</th>
+ <th>First name</th>
+ <th>Last name</th>
+ <th>Alter customer data</th>
+ <th>Add conctract</th>
+ <th>Delete</th>
+ </tr>
+ </thead>
+ <tbody>";
+ foreach($results as $data) {
+ $link_alter = "/alter_customer?email=" . $data->email;
+ $link_add_contract = "/add_contract?email=" . $data->email;
+ echo "<tr>";
+ echo "<td>" . $data->customer_id . "</td>";
+ echo "<td>" . $data->email . "</td>";
+ echo "<td>" . $data->first_name . "</td>";
+ echo "<td>" . $data->last_name . "</td>";
+ echo "<td><a href='" . $link_alter . "'>Alter</a></td>";
+ echo "<td><a href='" . $link_add_contract . "'>Add Contract</a></td>";
+ echo "
+ <td>
+ <form method=\"post\" action=\"search_customer\">
+ <button type=\"submit\" name='delete' value=" . $data->email ." ' class=\"btn btn-primary\">delete</button>
+ </form>
+ </td>";
+ echo "</tr>";
+ }
+ echo"
+ </tbody>
+ </table>";
+ }else{
+ echo "No customers were found.";
+ }
+ }
+ ?>
+ </body>
+</html>
+
diff --git a/views/search_data.php b/views/search_data.php
@@ -0,0 +1,104 @@
+<?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+
+ $weather = $db->get(Weather_data::class);
+
+ //$date_begin = '2023-04-04';
+ //$date_end = '2023-04-05';
+
+ $date_begin = "";
+ $date_end = "";
+ $station = "";
+
+ $query = array();
+ if($_SERVER['REQUEST_METHOD'] == 'GET'){
+ if(isset($_GET['date_begin']) && !empty($_GET['date_begin'])){
+ $date_begin = ($_GET['date_begin'] . "%");
+ $query["date_time"][">="] = $date_begin;
+ }
+ if(isset($_GET['date_end'])&& !empty($_GET['date_end'])){
+ $date_end = ($_GET['date_end'] . "%");
+ $query["date_time"]["<="] = $date_end;
+ }
+ if(isset($_GET['station']) && !empty($_GET['station'])){
+ $station = ($_GET['station'] . "%");
+ $query["station_name"]["="] = $station;
+ }
+
+ if($query == null){
+ $query["station_name"]["LIKE"] = "%";
+ }
+ $weather_data = $db->getDateRange(Weather_data::class, $query, "DESC");
+ //var_dump($weather_data);
+ }
+?>
+<html>
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ </head>
+ <body>
+ <form class="d-flex" action="search_data" method="get">
+ <input class="form-control me-2" type="text" name="date_begin" placeholder="Date begin (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
+ <input class="form-control me-2" type="text" name="date_end" placeholder="Date end (YYYY-MM-DD)" pattern="\d{4}-\d{2}-\d{2}" value=<?php ?>>
+ <input class="form-control me-2" type="text" name="station" placeholder="Search" aria-label="Search" value=<?php ?>>
+ <button class="btn btn-outline-success" type="submit">Search</button>
+ </form>
+
+ <?php
+ // verification logic and $_SESSION start
+ if ($weather_data != null) {?>
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th> Station name </th>
+ <th> Date & Time </th>
+ <th> Validated </th>
+ <th> Temperature </th>
+ <th> Dewpoint </th>
+ <th> Sea pressure </th>
+ <th> Station pressure </th>
+ <th> Visibility </th>
+ <th> Wind speed </th>
+ <th> Precipitation </th>
+ <th> Snow depth </th>
+ <th> Events </th>
+ <th> Cloud count </th>
+ <th> Wind direction </th>
+ </tr>
+ </thead>
+ <tbody>
+
+ </tbody>
+ <?php
+ foreach($weather_data as $data) {
+ $link = "/search_data?station=" . $data->station_name;
+ echo "<tr>";
+ echo "<td><a href='" . $link . "'>" . $data->station_name . "</a></td>";
+ echo "<td>" . $data->date_time . "</td>";
+ echo "<td>" . $data->validated . "</td>";
+ echo "<td>" . $data->temperature . "</td>";
+ echo "<td>" . $data->dew_point . "</td>";
+ echo "<td>" . $data->pressure_sea . "</td>";
+ echo "<td>" . $data->pressure_station . "</td>";
+ echo "<td>" . $data->visibility . "</td>";
+ echo "<td>" . $data->wind_speed . "</td>";
+ echo "<td>" . $data->precipitation . "</td>";
+ echo "<td>" . $data->snow_depth . "</td>";
+ echo "<td>" . $data->events . "</td>";
+ echo "<td>" . $data->cloud_count . "</td>";
+ echo "<td>" . $data->wind_direction . "</td>";
+ echo "</tr>";
+ }
+ ?>
+ </tbody>
+ </table>
+ <?php
+ } else {
+ echo "No data found.";
+ }
+ ?>
+ </body>
+</html>
+\ No newline at end of file
diff --git a/views/search_user.php b/views/search_user.php
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html lang="eng">
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ <link rel="stylesheet" type="text/css" href="/css/homepage.css">
+ <?php
+ include "views/navbar.php";
+ include "utils/autoloader.php";
+ if(!in_array(1, $_SESSION['user_permissions'])){
+ header('Location: /dashboard');
+ exit;
+ }
+ $db = new Lollipop\SQLDatabase("86.92.67.21", "friedel", "hailiwa", "wap2");
+ ?>
+ </head>
+<body>
+ <form class="d-flex" action="search_user" method="post">
+ <input class="form-control me-2" type="search" name="search" placeholder="Email" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+</form>
+ <?php
+ if(isset($_POST['search'])) {
+ //set $query
+ $query = "%" . $_POST['search'] . "%";
+ display_results($db, $query);
+ }elseif(isset($_POST['delete'])){
+ $u = $db->get(User::class);
+ $u->where("email", $_POST['delete']);
+ $u->delete();
+ display_results($db, $_POST['query']);
+ }
+ else{
+ display_results($db, '%');
+ }
+ function display_results($db, $query){
+ //create a User orm class and load all the records where user like query
+ $results = $db->all_where(User::class, array('email' => $query));
+
+ // display results
+ if($results != null){
+ echo "<table class=\"table table-striped\">
+ <thead>
+ <tr>
+ <th>E-mail</th>
+ <th>First name</th>
+ <th>Last name</th>
+ <th>Alter</th>
+ <th>Delete</th>
+ </tr>
+ </thead>
+ <tbody>";
+ foreach($results as $data) {
+ $link = "/alter_user?email=" . $data->email;
+ echo "<tr>";
+ echo "<td>" . $data->email . "</td>";
+ echo "<td>" . $data->first_name . "</td>";
+ echo "<td>" . $data->last_name . "</td>";
+ echo "<td><a href='" . $link . "'>Edit</a></td>";
+ echo "
+ <td>
+ <form method=\"post\" action=\"search_user\">
+ <input type=\"hidden\" name=\"query\" value=" . $query. ">
+ <button type=\"submit\" name='delete' value=" . $data->email ." ' class=\"btn btn-primary\">delete</button>
+ </form>
+ </td>";
+ echo "</tr>";
+ }
+ echo"
+ </tbody>
+ </table>";
+ }else{
+ echo "No users with this email address were found.";
+ }
+ }
+ ?>
+ </body>
+</html>
+
diff --git a/weather_data.txt b/weather_data.txt
@@ -0,0 +1,10 @@
+75630,2023-04-18,14:40:58,7.6,2,993.1,998.9,27.9,17.8,0,0,000000,5.2,37
+135780,2023-04-18,14:40:58,6.1,2.5,999.4,1002.2,12.1,8.6,0.03,0,010000,59.8,232
+170980,2023-04-18,14:40:58,8.6,2.4,815.6,813.1,10.3,13.3,0.22,0.2,011000,53.4,242
+324080,2023-04-18,14:40:58,-4.4,-8.9,1006.5,1008.3,29,15.3,0.04,19.5,111000,50,274
+725200,2023-04-18,14:40:58,4,-5.1,975.3,1016,17.6,15.9,0.07,0,010000,96.7,235
+725214,2023-04-18,14:40:58,5.8,-2.6,1010,1018.7,14.9,15.5,0,0,000000,98.3,220
+478580,2023-04-18,14:40:58,11.9,3.5,1002.9,996.8,9.7,15.8,0,0,000000,51.3,310
+324090,2023-04-18,14:40:58,-1.4,-5.4,1014,1001.3,40.4,14.3,0,0,100000,69.5,313
+725210,2023-04-18,14:40:58,2.5,-4.2,977.1,1017,15.3,15.1,0.09,0,010000,50,264
+725208,2023-04-18,14:40:58,3.8,-3.9,1018.6,1017.8,15.3,14.8,0.01,0,010000,80,231