Did work on various big things. See CHANGELOG for more details.
This commit is contained in:
parent
be5ae0d004
commit
b6582662f0
1
.gitignore
vendored
Executable file
1
.gitignore
vendored
Executable file
@ -0,0 +1 @@
|
||||
php/conn.php
|
5
CHANGELOG
Executable file
5
CHANGELOG
Executable file
@ -0,0 +1,5 @@
|
||||
9 maart 2020: Verbinding met database gelegd.
|
||||
Basis login systeem gemaakt.
|
||||
README.md geüpdatet.
|
||||
Routes gefixed.
|
||||
Tabel gemaakt op de homepage voor het ophalen van de data in de rooster tabel.
|
20
README.md
Normal file → Executable file
20
README.md
Normal file → Executable file
@ -1,2 +1,20 @@
|
||||
## Gymrooster PHP
|
||||
## Gymrooster PHP edition 9000
|
||||
Rooster voor Het Heerenlanden waar leraren leerlingen kunnen laten weten waar de gymles wordt gegeven.
|
||||
|
||||
Om het zelf te testen, gebruik de volgende commando's:
|
||||
```bash
|
||||
git clone https://gitea.arnweb.nl/Hecc-inc./gymrooster_php.git
|
||||
cd gymrooster_php
|
||||
```
|
||||
|
||||
Je hebt een apache2 web server nodig met php >= 7.3. Verder heb je ook een mariadb server nodig en php_mysqli. **Vul de details in in het bestand `php/conn.php` volgens https://www.w3schools.com/php/php_mysql_connect.asp.**
|
||||
|
||||
In de mariadb database moet er een database zijn met twee tabellen 'rooster' en 'docenten'. De code voor een voorbeeld is:
|
||||
```sql
|
||||
CREATE DATABASE gymrooster;
|
||||
USE gymrooster;
|
||||
CREATE TABLE docenten (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, username TEXT NOT NULL, password TEXT NOT NULL, naam TEXT NOT NULL);
|
||||
CREATE TABLE rooster (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, dag DATE NOT NULL, docent INT NOT NULL, opmerking TEXT NOT NULL, locatie INT NOT NULL);
|
||||
INSERT INTO docenten (username, password, naam) VALUES ('test', 'test', 'test user');
|
||||
INSERT INTO rooster (dag, docent, opmerking, locatie) VALUES (DATE('2020-03-09'), 1, 'Dit is een opmerking', 2);
|
||||
```
|
0
html/.htaccess
Normal file → Executable file
0
html/.htaccess
Normal file → Executable file
0
html/css/index.css
Normal file → Executable file
0
html/css/index.css
Normal file → Executable file
0
html/css/index.css.map
Normal file → Executable file
0
html/css/index.css.map
Normal file → Executable file
0
html/css/index.scss
Normal file → Executable file
0
html/css/index.scss
Normal file → Executable file
19
html/index.php
Normal file → Executable file
19
html/index.php
Normal file → Executable file
@ -1,10 +1,21 @@
|
||||
<?php
|
||||
ob_start();
|
||||
|
||||
echo $_SERVER['REQUEST_URI'];
|
||||
include __DIR__ . '/../php/auth.php';
|
||||
|
||||
ob_start();
|
||||
|
||||
$url = $_SERVER['REQUEST_URI'];
|
||||
|
||||
if ($url === '/') {
|
||||
include __DIR__ . '/../templates/index.html.php';
|
||||
} elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "GET") {
|
||||
include __DIR__ . '/../templates/login.html.php';
|
||||
} elseif ($url === '/login' && $_SERVER['REQUEST_METHOD'] === "POST") {
|
||||
include __DIR__ . '/../php/login.php';
|
||||
} elseif ($url === '/dashboard' && isAuthorized()) {
|
||||
include __DIR__ . '/../templates/dashboard.html.php';
|
||||
}
|
||||
|
||||
$output = ob_get_clean();
|
||||
$output = ob_get_clean();
|
||||
|
||||
include __DIR__ . '/../templates/layout.html.php';
|
||||
include __DIR__ . '/../templates/layout.html.php';
|
||||
|
16
php/auth.php
Normal file
16
php/auth.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
function isAuthorized() {
|
||||
|
||||
require 'conn.php';
|
||||
|
||||
$result = $conn->query("SELECT * FROM docenten WHERE username = '" . $_SESSION["username"] . "' AND password = '" . $_SESSION["password"] . "'");
|
||||
|
||||
if ($result->num_rows === 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
9
php/dashboard.php
Executable file
9
php/dashboard.php
Executable file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
require 'conn.php';
|
||||
|
||||
$result = $conn->query("SELECT * FROM docenten WHERE username = '" . $_SESSION['username'] . "';");
|
||||
|
||||
$docent = $result->fetch_assoc();
|
13
php/index.php
Executable file
13
php/index.php
Executable file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
require "conn.php";
|
||||
|
||||
$today = date("Y-m-d"); // Create date in mysql DATE format.
|
||||
|
||||
$result = $conn->query("SELECT * FROM rooster INNER JOIN docenten ON rooster.docent = docenten.id WHERE dag = DATE('" . $today . "');");
|
||||
|
||||
if ($result->num_rows === 1) {
|
||||
$rooster = [$result->fetch_assoc()];
|
||||
} else {
|
||||
$rooster = $result;
|
||||
}
|
18
php/login.php
Normal file
18
php/login.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
require 'conn.php';
|
||||
|
||||
$result = $conn->query("SELECT * FROM docenten WHERE username = '" . $_POST["username"] . "' AND password = '" . $_POST["password"] . "'");
|
||||
|
||||
if ($result->num_rows === 1) {
|
||||
session_start();
|
||||
|
||||
$_SESSION["username"] = $_POST["username"];
|
||||
$_SESSION["password"] = $_POST["password"];
|
||||
|
||||
header('Location: /dashboard');
|
||||
} else {
|
||||
echo 'Wrong password or username';
|
||||
}
|
||||
|
||||
|
2
templates/dashboard.html.php
Normal file
2
templates/dashboard.html.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php require __DIR__ . '/../php/dashboard.php' ?>
|
||||
Welkom <?=$docent['naam']?>
|
50
templates/index.html.php
Normal file → Executable file
50
templates/index.html.php
Normal file → Executable file
@ -1,13 +1,39 @@
|
||||
<?php include "../php/index.php" ?>
|
||||
|
||||
<!-- Layout like:
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Docent</th>
|
||||
<th>Locatie</th>
|
||||
<th>Opmerkingen</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Kruiswijk</td>
|
||||
<td>Buiten</td>
|
||||
<td>Neem sportkleding mee!</td>
|
||||
</tr>
|
||||
</table>
|
||||
<table>
|
||||
<tr>
|
||||
<th>Docent</th>
|
||||
<th>Locatie</th>
|
||||
<th>Opmerkingen</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Kruiswijk</td>
|
||||
<td>Buiten</td>
|
||||
<td>Neem sportkleding mee!</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div> -->
|
||||
|
||||
<div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Docent</th>
|
||||
<th>Locatie</th>
|
||||
<th>Opmerkingen</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($rooster as $record) { ?>
|
||||
<tr>
|
||||
<td><?=$record["naam"]?></td>
|
||||
<td><?=$record["locatie"] === 1 ? 'Binnen' : 'Buiten'?></td>
|
||||
<td><?=$record["opmerking"]?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
2
templates/layout.html.php
Normal file → Executable file
2
templates/layout.html.php
Normal file → Executable file
@ -9,7 +9,7 @@
|
||||
<body>
|
||||
<nav>
|
||||
<!-- Topnav -->
|
||||
<a href="/"><img src="res/HLC.svg"></a>
|
||||
<a href="/"><img src="/res/HLC.svg"></a>
|
||||
<a href="/login">Login</a>
|
||||
</nav>
|
||||
|
||||
|
4
templates/login.html.php
Normal file → Executable file
4
templates/login.html.php
Normal file → Executable file
@ -1,11 +1,11 @@
|
||||
<!-- Login screen -->
|
||||
<div class="loginContainer">
|
||||
<form action="/">
|
||||
<form action="/login" method="post">
|
||||
<h1>Login</h1>
|
||||
<label for="username">Gebruikersnaam:</label><br>
|
||||
<input type="text" name="username" placeholder="Gebruikersnaam"><br>
|
||||
<label for="password">Wachtwoord:</label><br>
|
||||
<input type="password" name="password" placeholder="Wachtwoord">
|
||||
<input type="password" name="password" placeholder="Wachtwoord"><br>
|
||||
|
||||
<button type="submit">Login</button>
|
||||
</form>
|
||||
|
Loading…
Reference in New Issue
Block a user