1e versie

This commit is contained in:
2025-11-12 10:17:30 +01:00
commit 6b5f9abec7
10 changed files with 255 additions and 0 deletions

14
includes/db.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
$config = require __DIR__ . '/../config/config.php';
try {
$pdo = new PDO(
"mysql:host={$config['db']['host']};dbname={$config['db']['name']};charset=utf8mb4",
$config['db']['user'],
$config['db']['pass'],
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
} catch (PDOException $e) {
die("Databaseverbinding mislukt: " . $e->getMessage());
}

44
includes/functions.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
function startNieuweRonde($pdo)
{
$config = require __DIR__ . '/../config/config.php';
$deelnemers = $config['deelnemers'];
$getrokken = [];
$targets = $deelnemers;
shuffle($targets);
// Zorg dat niemand zichzelf krijgt
do {
shuffle($targets);
} while (array_intersect_assoc($deelnemers, $targets));
foreach ($deelnemers as $i => $trekker) {
$getrokken[$trekker] = $targets[$i];
}
// Oude ronde archiveren
$archiefBestand = __DIR__ . '/../data/archief/' . date('Ymd_His') . '_lootjes.json';
if (file_exists(__DIR__ . '/../data/lootjes.json')) {
rename(__DIR__ . '/../data/lootjes.json', $archiefBestand);
}
file_put_contents(__DIR__ . '/../data/lootjes.json', json_encode($getrokken, JSON_PRETTY_PRINT));
return $getrokken;
}
function getLootjeVoor($gebruiker)
{
$path = __DIR__ . '/../data/lootjes.json';
if (!file_exists($path)) return null;
$lootjes = json_decode(file_get_contents($path), true);
return $lootjes[$gebruiker] ?? null;
}
function isAdmin($username)
{
$config = require __DIR__ . '/../config/config.php';
return in_array($username, $config['admin_users']);
}

23
includes/ldap.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
function ldap_authenticate($username, $password)
{
$config = require __DIR__ . '/../config/config.php';
$ldapconn = ldap_connect($config['ldap']['server']);
if (!$ldapconn) {
return false;
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
$bind_dn = "uid={$username},{$config['ldap']['user_dn']}";
if (@ldap_bind($ldapconn, $bind_dn, $password)) {
ldap_unbind($ldapconn);
return true;
}
return false;
}