1e versie
This commit is contained in:
44
includes/functions.php
Normal file
44
includes/functions.php
Normal 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']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user