295 lines
8.5 KiB
PHP
295 lines
8.5 KiB
PHP
<?php
|
|
/** @var array $CONFIG basic configurations (defined via bootstraping) */
|
|
/** @var array $SECRETS passwords and other stuff worth of protection (defined via bootstraping) */
|
|
require_once "bootstrap.php";
|
|
|
|
require_once "./lib/api.php";
|
|
require_once "./lib/participoLib/participo.php";
|
|
|
|
participo::init($CONFIG["cwsvJudo"], $SECRETS["cwsvJudo"]);
|
|
|
|
$userData = getUserData($_SESSION["user"]["userId"]);
|
|
$usersKids = getUsersKids($_SESSION["user"]["userId"]);
|
|
|
|
abstract class AttendanceType
|
|
{
|
|
const __default = null;
|
|
|
|
const Training = 1;
|
|
const Excused = 2;
|
|
const Ill = 3;
|
|
const SpecialTraining = 4;
|
|
const Competition = 5;
|
|
}
|
|
|
|
abstract class UserAttribute
|
|
{
|
|
const __default = null;
|
|
|
|
const IsAdmin = 1;
|
|
const WantsNewsLetter = 2;
|
|
const Passive = 3;
|
|
const InTraining = 4;
|
|
}
|
|
|
|
/**
|
|
* Datastructure and interface for attendances
|
|
*/
|
|
class Attendance
|
|
{
|
|
private $id = null; //< id in the db
|
|
private $userId = null; //< user of the attendance
|
|
private $date = null; //< date of the attendance
|
|
private $type = null; //< type of attendance
|
|
|
|
private static $Types = [
|
|
AttendanceType::Training => "Training",
|
|
AttendanceType::Excused => "Entschuldigt",
|
|
AttendanceType::Ill => "Krank",
|
|
AttendanceType::SpecialTraining => "SonderTraining",
|
|
AttendanceType::Competition => "Wettkampf",
|
|
];
|
|
private static $NameOfMonth = [
|
|
1 => "Januar",
|
|
2 => "Februar",
|
|
3 => "März",
|
|
4 => "April",
|
|
5 => "Mai",
|
|
6 => "Juni",
|
|
7 => "Juli",
|
|
8 => "August",
|
|
9 => "September",
|
|
10 => "Oktober",
|
|
11 => "November",
|
|
12 => "Dezember",
|
|
];
|
|
|
|
/**
|
|
* constructor
|
|
*
|
|
* @param string/int $id id in the db
|
|
* @param string/int $userId user of the attendance
|
|
* @param string $date date of the attendance
|
|
*/
|
|
public function __construct($id, $userId, $date)
|
|
{
|
|
$this->id = (int) $id;
|
|
$this->userId = (int) $userId;
|
|
$this->date = DateTime::createFromFormat("Y-m-d", $date);
|
|
}
|
|
|
|
/**
|
|
* create an Attendance from an assoziative array
|
|
*
|
|
* @param array $member
|
|
* @return Attendance
|
|
*/
|
|
public static function constructFromArray($member)
|
|
{
|
|
return new Attendance(
|
|
$member["id"],
|
|
$member["userId"],
|
|
$member["date"],
|
|
);
|
|
}
|
|
|
|
/**
|
|
* request a users attendances from the database
|
|
*
|
|
* @param int/string $userId
|
|
* @return array with attendances
|
|
*/
|
|
public static function getUsersAttendance($userId)
|
|
{
|
|
$userId = (int) $userId;
|
|
$query =
|
|
"SELECT `id`, `date` FROM `cwsvjudo_main`.`anwesenheit` WHERE `userId` = :userId";
|
|
$response = dbConnector::query($query, [
|
|
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
|
|
]);
|
|
$attendances = [];
|
|
foreach ($response as $r) {
|
|
$attendances[] = new Attendance($r["id"], $userId, $r["date"]);
|
|
}
|
|
return $attendances;
|
|
}
|
|
|
|
/**
|
|
* html table with users attendances
|
|
*
|
|
* @param int $userId
|
|
* @return string with html code of the attendance table
|
|
*/
|
|
public static function userAttendanceHtmlTable(int $userId): string
|
|
{
|
|
$htmlTableString = "";
|
|
$htmlTableString .= "<ul>";
|
|
$userAttendances = Attendance::groupAttendances(
|
|
Attendance::getUsersAttendance($userId),
|
|
);
|
|
krsort($userAttendances);
|
|
foreach ($userAttendances as $year => $months) {
|
|
$htmlTableString .= "<li>{$year}<dl>";
|
|
// Counting the attendances per half year
|
|
$attendanceCountH1 = 0;
|
|
$attendanceCountH2 = 0;
|
|
foreach ($months as $month => $days) {
|
|
if (1 <= $month and $month <= 6) {
|
|
$attendanceCountH1 += count($days);
|
|
}
|
|
if (7 <= $month and $month <= 12) {
|
|
$attendanceCountH2 += count($days);
|
|
}
|
|
}
|
|
$htmlTableString .= "<dt>Gesamt erstes Halbjahr:</dt><dd> {$attendanceCountH1}</dd>";
|
|
$htmlTableString .= "<dt>Gesamt zweites Halbjahr:</dt><dd>{$attendanceCountH2}</dd>";
|
|
krsort($months);
|
|
foreach ($months as $month => $days) {
|
|
$htmlTableString .=
|
|
"<dt>" . Attendance::$NameOfMonth[$month] . "</dt>";
|
|
$htmlTableString .= "<dd>" . join(", ", $days) . "</dd>";
|
|
}
|
|
$htmlTableString .= "</dl></li>";
|
|
}
|
|
$htmlTableString .= "</ul>";
|
|
|
|
return $htmlTableString;
|
|
}
|
|
|
|
/**
|
|
* group the attendances by year and month.
|
|
*
|
|
* @param array $attendances list of attendances
|
|
* @return array (list of int) array with a list of days for every month in every year
|
|
*/
|
|
public static function groupAttendances(array $attendances): array
|
|
{
|
|
$groupedAttendances = [];
|
|
foreach ($attendances as $a) {
|
|
$year = (int) $a->date->format("Y");
|
|
if (!array_key_exists($year, $groupedAttendances)) {
|
|
$groupedAttendances[$year] = [];
|
|
}
|
|
$month = (int) $a->date->format("m");
|
|
if (!array_key_exists($month, $groupedAttendances[$year])) {
|
|
$groupedAttendances[$year][$month] = [];
|
|
}
|
|
$day = (int) $a->date->format("d");
|
|
$groupedAttendances[$year][$month][] = $day;
|
|
}
|
|
return $groupedAttendances;
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
|
|
<?php readfile("./shared/imports.php"); ?>
|
|
|
|
<!-- inits for the materializeCss -->
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var elems = document.querySelectorAll('.sidenav');
|
|
var instances = M.Sidenav.init(elems, {
|
|
// specify options here
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<title>participo</title>
|
|
<meta name="description" content="Online-Apps der Judoka des Chemnitzer WSV">
|
|
|
|
<link rel="icon" href="/ressourcen/graphiken/icons/cwsv.ico" />
|
|
<link rel="apple-touch-icon" href="/ressourcen/graphiken/logos/favIcons/apple-touch-icon.png">
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<header>
|
|
<nav class="indigo darken-4">
|
|
<a href="/participo" class="breadcrumb">cwsvJudo-Apps</a>
|
|
<a href="/participo/attendance" class="breadcrumb">Anwesenheit</a>
|
|
<a class="right top-nav sidenav-trigger waves-effect waves-light hide-on-large-only" href="#" data-target="nav-mobile"><i class="material-icons">menu</i></a>
|
|
</nav>
|
|
<ul class="sidenav sidenav-fixed sidenav-close" id="nav-mobile">
|
|
<li class="logo">
|
|
<a style="height:auto;" class="brand-logo" id="logo-container" href="/participo/">
|
|
<img alt="cwsvJudoApps" style="max-width:100%;height:12vh;" class="responsive-img" src="/ressourcen/graphiken/logos/cwsvJudoLogoWappen.256w.png" />
|
|
</a>
|
|
</li>
|
|
<?php require_once "sidenav/loginStatus.php"; ?><!-- brings its own li -->
|
|
<li class="bold">
|
|
<a class="waves-effect waves-teal right-align" href="#attendance-<?php echo $userData[
|
|
"id"
|
|
]; ?>">Selber</a>
|
|
</li>
|
|
<?php foreach ($usersKids as $k) {
|
|
if ($userData["id"] == $k["id"]) {
|
|
continue;
|
|
} ?>
|
|
<li class="bold">
|
|
<a class="waves-effect waves-teal right-align" href="#attendance-<?php echo $k[
|
|
"kidId"
|
|
]; ?>"><?php echo $k["vorname"] . " " . $k["name"]; ?></a>
|
|
</li>
|
|
<?php
|
|
} ?>
|
|
</ul>
|
|
</header>
|
|
|
|
<?php if ($_SESSION["login"]) { ?>
|
|
<main>
|
|
<?php // show own ...
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
// show own ...
|
|
|
|
$ownAttendances = Attendance::getUsersAttendance($_SESSION["user"]["userId"]);
|
|
if (!empty($ownAttendances)) {
|
|
echo '<h2 id="attendance-' .
|
|
$userData["id"] .
|
|
'">Eigene Anwesenheiten</h2>' .
|
|
Attendance::userAttendanceHtmlTable($userData["id"]);
|
|
require_once "./lib/participoLib/participo.php";
|
|
} // ... and kids attendances
|
|
if (!empty($usersKids)) {
|
|
echo "<h2>Anwesenheit der Kinder</h2>";
|
|
foreach ($usersKids as $k) {
|
|
if ($userData["id"] == $k["kidId"]) {
|
|
continue;
|
|
}
|
|
echo '<h3 id="attendance-' .
|
|
$k["kidId"] .
|
|
'">' .
|
|
$k["vorname"] .
|
|
" " .
|
|
$k["name"] .
|
|
"</h3>" .
|
|
Attendance::userAttendanceHtmlTable($k["kidId"]);
|
|
}
|
|
}
|
|
?>
|
|
</main>
|
|
<?php } ?>
|
|
</body>
|
|
</html>
|