removed auth usage, php-cs-fixer
This commit is contained in:
@@ -1,41 +1,42 @@
|
||||
<?php
|
||||
|
||||
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
require_once("config/participo.php");
|
||||
|
||||
require_once("./local/dbConf.php");
|
||||
require_once("./local/cwsvJudo.php");
|
||||
setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
require_once 'config/participo.php';
|
||||
|
||||
require_once("./lib/db.php");
|
||||
require_once("./lib/api.php");
|
||||
require_once("./lib/participoLib/participo.php");
|
||||
require_once './local/dbConf.php';
|
||||
require_once './local/cwsvJudo.php';
|
||||
|
||||
require_once("./auth.php");
|
||||
require_once './lib/db.php';
|
||||
require_once './lib/api.php';
|
||||
require_once './lib/participoLib/participo.php';
|
||||
|
||||
require_once($config['basePath']."/config/cwsvJudo.config.php");
|
||||
require_once($config['basePath']."/config/phpcount.config.php");
|
||||
require_once $config['basePath'] . '/config/cwsvJudo.config.php';
|
||||
require_once $config['basePath'] . '/config/phpcount.config.php';
|
||||
|
||||
dbConnector::connect(
|
||||
$cwsvJudoConfig["db"]["host"],
|
||||
$cwsvJudoConfig["db"]["name"],
|
||||
$cwsvJudoConfig["db"]["user"],
|
||||
$cwsvJudoConfig["db"]["password"]
|
||||
$cwsvJudoConfig['db']['host'],
|
||||
$cwsvJudoConfig['db']['name'],
|
||||
$cwsvJudoConfig['db']['user'],
|
||||
$cwsvJudoConfig['db']['password']
|
||||
);
|
||||
|
||||
participo::authentificate();
|
||||
$userData = getUserData(dbConnector::getDbConnection(), $_SESSION['user']['userId']);
|
||||
$usersKids = getUsersKids(dbConnector::getDbConnection(), $_SESSION['user']['userId']);
|
||||
|
||||
abstract class AttendanceType {
|
||||
abstract class AttendanceType
|
||||
{
|
||||
const __default = null;
|
||||
|
||||
const Training = 1;
|
||||
const Excused = 2;
|
||||
const Ill = 3;
|
||||
|
||||
const Training = 1;
|
||||
const Excused = 2;
|
||||
const Ill = 3;
|
||||
const SpecialTraining = 4;
|
||||
const Competition = 5;
|
||||
const Competition = 5;
|
||||
}
|
||||
|
||||
abstract class UserAttribute {
|
||||
abstract class UserAttribute
|
||||
{
|
||||
const __default = null;
|
||||
|
||||
const IsAdmin = 1;
|
||||
@@ -43,79 +44,86 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
const Passive = 3;
|
||||
const InTraining = 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Datastructure and interface for an user
|
||||
*/
|
||||
class User{
|
||||
class User
|
||||
{
|
||||
private $id = null;
|
||||
private $familyName = null;
|
||||
private $givenName = null;
|
||||
|
||||
private $attributes = null;
|
||||
|
||||
function __construct($id, $familyName, $givenName){
|
||||
public function __construct($id, $familyName, $givenName)
|
||||
{
|
||||
$this->id = (int)$id;
|
||||
$this->familyName = $familyName;
|
||||
$this->givenName = $givenName;
|
||||
}
|
||||
static function fromArray($member){
|
||||
|
||||
public static function fromArray($member)
|
||||
{
|
||||
$id = $member['id'];
|
||||
$familyName = $member['familyName'];
|
||||
$givenName = $member['givenName'];
|
||||
return new User($id, $familyName, $givenName);
|
||||
}
|
||||
static function getUsers($db, $options = []){
|
||||
$attributeId = $options["attributeId"] ?? null;
|
||||
|
||||
public static function getUsers($db, $options = [])
|
||||
{
|
||||
$attributeId = $options['attributeId'] ?? null;
|
||||
$params = [];
|
||||
$query = "SELECT ".
|
||||
"`cwsvjudo`.`wkParticipo_Users`.`id` AS `id`".
|
||||
", `cwsvjudo`.`wkParticipo_Users`.`vorname` AS `givenName`".
|
||||
", `cwsvjudo`.`wkParticipo_Users`.`name` AS `familyName`".
|
||||
", `cwsvjudo`.`wkParticipo_userAttributes`.`name` AS `attributeName`".
|
||||
"FROM `cwsvjudo`.`wkParticipo_Users` ".
|
||||
"JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes` ".
|
||||
"ON `cwsvjudo`.`wkParticipo_Users`.`id` = `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`".
|
||||
"JOIN `cwsvjudo`.`wkParticipo_userAttributes` ".
|
||||
"ON `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` = `cwsvjudo`.`wkParticipo_userAttributes`.`id`";
|
||||
if($attributeId != null){
|
||||
$query .= " WHERE `cwsvjudo`.`wkParticipo_userAttributes`.`id` = :attributeId";
|
||||
$params['attributeId'] = ['value'=>$attributeId, 'data_type'=>PDO::PARAM_INT];
|
||||
$query = 'SELECT ' .
|
||||
'`cwsvjudo`.`wkParticipo_Users`.`id` AS `id`' .
|
||||
', `cwsvjudo`.`wkParticipo_Users`.`vorname` AS `givenName`' .
|
||||
', `cwsvjudo`.`wkParticipo_Users`.`name` AS `familyName`' .
|
||||
', `cwsvjudo`.`wkParticipo_userAttributes`.`name` AS `attributeName`' .
|
||||
'FROM `cwsvjudo`.`wkParticipo_Users` ' .
|
||||
'JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes` ' .
|
||||
'ON `cwsvjudo`.`wkParticipo_Users`.`id` = `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`' .
|
||||
'JOIN `cwsvjudo`.`wkParticipo_userAttributes` ' .
|
||||
'ON `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` = `cwsvjudo`.`wkParticipo_userAttributes`.`id`';
|
||||
if ($attributeId != null) {
|
||||
$query .= ' WHERE `cwsvjudo`.`wkParticipo_userAttributes`.`id` = :attributeId';
|
||||
$params['attributeId'] = ['value' => $attributeId, 'data_type' => PDO::PARAM_INT];
|
||||
}
|
||||
$query .= ";";
|
||||
$query .= ';';
|
||||
$response = dbQuery($db, $query, $params);
|
||||
|
||||
|
||||
$users = [];
|
||||
foreach( $response as $r){
|
||||
foreach ($response as $r) {
|
||||
$users[] = User::fromArray($r);
|
||||
}
|
||||
return $users;
|
||||
}
|
||||
static function htmlTable($users){
|
||||
echo("<table><tr><th>Id<th>Name</th><th>Vorname</th></tr>");
|
||||
foreach( $users as $u){
|
||||
echo("<tr><td>".$u->id."</td><td>".$u->familyName."</td><td>".$u->givenName."</td></tr>");
|
||||
|
||||
public static function htmlTable($users)
|
||||
{
|
||||
echo('<table><tr><th>Id<th>Name</th><th>Vorname</th></tr>');
|
||||
foreach ($users as $u) {
|
||||
echo('<tr><td>' . $u->id . '</td><td>' . $u->familyName . '</td><td>' . $u->givenName . '</td></tr>');
|
||||
}
|
||||
echo("</table>");
|
||||
echo('</table>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Datastructure and interface for attendances
|
||||
*/
|
||||
class Attendance{
|
||||
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
|
||||
|
||||
static private $Types = [
|
||||
AttendanceType::Training => "Training"
|
||||
, AttendanceType::Excused => "Entschuldigt"
|
||||
, AttendanceType::Ill => "Krank"
|
||||
, AttendanceType::SpecialTraining => "SonderTraining"
|
||||
, AttendanceType::Competition => "Wettkampf"
|
||||
private $type = null; //< type of attendance
|
||||
|
||||
private static $Types = [
|
||||
AttendanceType::Training => 'Training', AttendanceType::Excused => 'Entschuldigt', AttendanceType::Ill => 'Krank', AttendanceType::SpecialTraining => 'SonderTraining', AttendanceType::Competition => 'Wettkampf'
|
||||
];
|
||||
static private $NameOfMonth = [1=>"Januar", 2=>"Februar", 3=>"März", 4=>"April", 4=>"Mai", 6=>"Juni", 7=>"Juli", 8=>"August", 9=>"September", 10=>"Oktober", 11=>"November", 12=>"Dezember"];
|
||||
private static $NameOfMonth = [1 => 'Januar', 2 => 'Februar', 3 => 'März', 4 => 'April', 4 => 'Mai', 6 => 'Juni', 7 => 'Juli', 8 => 'August', 9 => 'September', 10 => 'Oktober', 11 => 'November', 12 => 'Dezember'];
|
||||
|
||||
/**
|
||||
* constructor
|
||||
*
|
||||
@@ -123,20 +131,24 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
* @param string/int $userId user of the attendance
|
||||
* @param string $date date of the attendance
|
||||
*/
|
||||
function __construct($id, $userId, $date){
|
||||
public function __construct($id, $userId, $date)
|
||||
{
|
||||
$this->id = (int)$id;
|
||||
$this->userId = (int)$userId;
|
||||
$this->date = DateTime::createFromFormat("Y-m-d", $date);
|
||||
$this->date = DateTime::createFromFormat('Y-m-d', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* create an Attendance from an assoziative array
|
||||
*
|
||||
* @param array $member
|
||||
* @return Attendance
|
||||
*/
|
||||
static function constructFromArray($member){
|
||||
public static function constructFromArray($member)
|
||||
{
|
||||
return new Attendance($member['id'], $member['userId'], $member['date']);
|
||||
}
|
||||
|
||||
/**
|
||||
* request a users attendances from the database
|
||||
*
|
||||
@@ -144,16 +156,18 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
* @param int/string $userId
|
||||
* @return array with attendances
|
||||
*/
|
||||
static function getUsersAttendance($db, $userId){
|
||||
public static function getUsersAttendance($db, $userId)
|
||||
{
|
||||
$userId = (int)$userId;
|
||||
$query = "SELECT `id`, `date` FROM `cwsvjudo`.`anwesenheit` WHERE `userId` = :userId";
|
||||
$response = dbQuery($db, $query, [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]);
|
||||
$query = 'SELECT `id`, `date` FROM `cwsvjudo`.`anwesenheit` WHERE `userId` = :userId';
|
||||
$response = dbQuery($db, $query, [':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]]);
|
||||
$attendances = [];
|
||||
foreach($response as $r){
|
||||
foreach ($response as $r) {
|
||||
$attendances[] = new Attendance($r['id'], $userId, $r['date']);
|
||||
}
|
||||
return $attendances;
|
||||
}
|
||||
|
||||
/**
|
||||
* html table with users attendances
|
||||
*
|
||||
@@ -161,56 +175,61 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
* @param string/int $userId
|
||||
* @return string with html code of the attendance table
|
||||
*/
|
||||
static function userAttendanceHtmlTable($db, $userId){
|
||||
$htmlTableString = "";
|
||||
$htmlTableString .= "<ul>";
|
||||
$userAttendances = Attendance::groupAttendances(
|
||||
Attendance::getUsersAttendance($db, $userId)
|
||||
public static function userAttendanceHtmlTable($db, $userId)
|
||||
{
|
||||
$htmlTableString = '';
|
||||
$htmlTableString .= '<ul>';
|
||||
$userAttendances = Attendance::groupAttendances(
|
||||
Attendance::getUsersAttendance($db, $userId)
|
||||
);
|
||||
krsort($userAttendances);
|
||||
foreach( $userAttendances as $year=>$months ){
|
||||
$htmlTableString .= "<li>".$year."<dl>";
|
||||
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){
|
||||
foreach ($months as $month => $days) {
|
||||
if (1 <= $month and $month <= 6) {
|
||||
$attendanceCountH1 += count($days);
|
||||
}
|
||||
if(7<=$month and $month <= 12){
|
||||
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>";
|
||||
$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>";
|
||||
foreach ($months as $month => $days) {
|
||||
$htmlTableString .= '<dt>' . Attendance::$NameOfMonth[$month] . '</dt>';
|
||||
$htmlTableString .= '<dd>' . join(', ', $days) . '</dd>';
|
||||
}
|
||||
$htmlTableString .= "</dl></li>";
|
||||
$htmlTableString .= '</dl></li>';
|
||||
}
|
||||
$htmlTableString .= "</ul>";
|
||||
$htmlTableString .= '</ul>';
|
||||
|
||||
return $htmlTableString;
|
||||
}
|
||||
|
||||
/**
|
||||
* group the attendances by year and month.
|
||||
*
|
||||
* @param list $attendances list of attendances
|
||||
* @return array[int][int](list of int) array with a list of days for every month in every year
|
||||
*/
|
||||
static function groupAttendances($attendances){
|
||||
* @return array[int][int](list of int) array with a list of days for every month in every year
|
||||
*/
|
||||
public static function groupAttendances($attendances)
|
||||
{
|
||||
$groupedAttendances = [];
|
||||
foreach($attendances as $a){
|
||||
$year =(int) $a->date->format("Y");
|
||||
if(!array_key_exists($year, $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]))
|
||||
}
|
||||
$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;
|
||||
}
|
||||
$day = (int) $a->date->format('d');
|
||||
$groupedAttendances[$year][$month][] = $day;
|
||||
}
|
||||
return $groupedAttendances;
|
||||
}
|
||||
@@ -223,7 +242,7 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<?php readfile("./shared/imports.php");?>
|
||||
<?php readfile('./shared/imports.php'); ?>
|
||||
|
||||
<!-- inits for the materializeCss -->
|
||||
<script>
|
||||
@@ -254,50 +273,53 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
|
||||
<img alt="cwsvJudoApps" style="max-width:100%;height:12vh;" class="responsive-img" src="http://cwsvjudo.bplaced.net/ressourcen/graphiken/logos/cwsvJudoLogoWappen.x256.png" />
|
||||
</a>
|
||||
</li>
|
||||
<?php require_once("sidenav/loginStatus.php");?><!-- brings its own 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>
|
||||
<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;
|
||||
?>
|
||||
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>
|
||||
<a class="waves-effect waves-teal right-align" href="#attendance-<?php echo($k['kidId']); ?>"><?php echo($k['vorname'] . ' ' . $k['name']); ?></a>
|
||||
</li>
|
||||
<?php }?>
|
||||
<?php
|
||||
}?>
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<?php
|
||||
if($_SESSION['login']){
|
||||
?>
|
||||
if ($_SESSION['login']) {
|
||||
?>
|
||||
<main>
|
||||
<?php //User::htmlTable( User::getUsers(dbConnector::getDbConnection(), ['attributeId' => UserAttribute::InTraining]));?>
|
||||
<?php // show own ...
|
||||
$ownAttendances = Attendance::getUsersAttendance(dbConnector::getDbConnection(), $_SESSION['user']['userId']);
|
||||
if (!empty($ownAttendances)){
|
||||
echo(
|
||||
"<h2 id=\"attendance-".$userData['id']."\">Eigene Anwesenheiten</h2>".
|
||||
if (!empty($ownAttendances)) {
|
||||
echo(
|
||||
'<h2 id="attendance-' . $userData['id'] . '">Eigene Anwesenheiten</h2>' .
|
||||
Attendance::userAttendanceHtmlTable(dbConnector::getDbConnection(), $userData['id'])
|
||||
); require_once("./lib/participoLib/participo.php");
|
||||
|
||||
);
|
||||
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;
|
||||
}
|
||||
// ... 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>".
|
||||
echo(
|
||||
'<h3 id="attendance-' . $k['kidId'] . '">' . $k['vorname'] . ' ' . $k['name'] . '</h3>' .
|
||||
Attendance::userAttendanceHtmlTable(dbConnector::getDbConnection(), $k['kidId'])
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
||||
} ?>
|
||||
</main>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user