|
|
|
|
@@ -1,11 +1,11 @@
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
require_once 'participoLib/dbConnector.php';
|
|
|
|
|
require_once 'participoLib/user.php';
|
|
|
|
|
require_once 'participoLib/event.php';
|
|
|
|
|
require_once 'participoLib/eventPage.php';
|
|
|
|
|
require_once 'participoLib/starter.php';
|
|
|
|
|
require_once 'participoLib/planer.php';
|
|
|
|
|
require_once "participoLib/dbConnector.php";
|
|
|
|
|
require_once "participoLib/user.php";
|
|
|
|
|
require_once "participoLib/event.php";
|
|
|
|
|
require_once "participoLib/eventPage.php";
|
|
|
|
|
require_once "participoLib/starter.php";
|
|
|
|
|
require_once "participoLib/planer.php";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FrameWork for the participoApp
|
|
|
|
|
@@ -26,7 +26,11 @@ class participo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static $db = null;
|
|
|
|
|
private static $message = ['error' => null, 'success' => null, 'notice' => null];
|
|
|
|
|
private static $message = [
|
|
|
|
|
"error" => null,
|
|
|
|
|
"success" => null,
|
|
|
|
|
"notice" => null,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/** id of session user
|
|
|
|
|
*
|
|
|
|
|
@@ -46,7 +50,7 @@ class participo
|
|
|
|
|
public static function getSessionUserId()
|
|
|
|
|
{
|
|
|
|
|
if (!isset(self::$userId)) {
|
|
|
|
|
self::$userId = $_SESSION['user']['userId'] ?? null;
|
|
|
|
|
self::$userId = $_SESSION["user"]["userId"] ?? null;
|
|
|
|
|
}
|
|
|
|
|
self::$userId = filterId(self::$userId);
|
|
|
|
|
return self::$userId;
|
|
|
|
|
@@ -69,7 +73,9 @@ class participo
|
|
|
|
|
*/
|
|
|
|
|
public static function isLoginValid()
|
|
|
|
|
{
|
|
|
|
|
return (isset($_SESSION) && array_key_exists('login', $_SESSION) && $_SESSION['login'] == true);
|
|
|
|
|
return isset($_SESSION) &&
|
|
|
|
|
array_key_exists("login", $_SESSION) &&
|
|
|
|
|
$_SESSION["login"] == true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Remove all login data from the session data
|
|
|
|
|
@@ -78,7 +84,7 @@ class participo
|
|
|
|
|
*/
|
|
|
|
|
public static function logout()
|
|
|
|
|
{
|
|
|
|
|
foreach (['login', 'user'] as $key) {
|
|
|
|
|
foreach (["login", "user"] as $key) {
|
|
|
|
|
unset($_SESSION[$key]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -89,12 +95,15 @@ class participo
|
|
|
|
|
*/
|
|
|
|
|
public static function htmlLoginStatus()
|
|
|
|
|
{
|
|
|
|
|
return
|
|
|
|
|
'<div style="border: 1px solid black">' .
|
|
|
|
|
'Datum: ' . date('Y-m-d') . '<br />' .
|
|
|
|
|
'Eingeloggt als <strong>' . htmlspecialchars($_SESSION['user']['username']) . '</strong>.<br />' .
|
|
|
|
|
return '<div style="border: 1px solid black">' .
|
|
|
|
|
"Datum: " .
|
|
|
|
|
date("Y-m-d") .
|
|
|
|
|
"<br />" .
|
|
|
|
|
"Eingeloggt als <strong>" .
|
|
|
|
|
htmlspecialchars($_SESSION["user"]["username"]) .
|
|
|
|
|
"</strong>.<br />" .
|
|
|
|
|
'<a href="logout.php">Sitzung beenden</a>' .
|
|
|
|
|
'</div>';
|
|
|
|
|
"</div>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Checking if an action is allowed. A present apiKey overrides (and deletes) a present login.
|
|
|
|
|
@@ -114,36 +123,43 @@ class participo
|
|
|
|
|
*
|
|
|
|
|
* @retval void
|
|
|
|
|
*/
|
|
|
|
|
public static function authentificate($action = 'login')
|
|
|
|
|
public static function authentificate($action = "login")
|
|
|
|
|
{
|
|
|
|
|
// Ensure a session is started
|
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
|
|
// check if an apiKey was received
|
|
|
|
|
if (array_key_exists('apiKey', $_GET)) {
|
|
|
|
|
if (array_key_exists("apiKey", $_GET)) {
|
|
|
|
|
self::logout();
|
|
|
|
|
$key = ApiKey::loadFromDb($_GET['apiKey']);
|
|
|
|
|
$key = ApiKey::loadFromDb($_GET["apiKey"]);
|
|
|
|
|
if (isset($key) && $key->isValidFor($action)) {
|
|
|
|
|
$user = User::loadFromDb($key->getUserId());
|
|
|
|
|
// case valid login: Set the session data
|
|
|
|
|
$_SESSION = [
|
|
|
|
|
'login' => true, //false,
|
|
|
|
|
'apiKey' => $key->getKey(),
|
|
|
|
|
'user' => [
|
|
|
|
|
'username' => $user->getLoginName(),
|
|
|
|
|
'userId' => $user->getId(),
|
|
|
|
|
'userConfig' => $user->getConfig(),
|
|
|
|
|
]
|
|
|
|
|
"login" => true, //false,
|
|
|
|
|
"apiKey" => $key->getKey(),
|
|
|
|
|
"user" => [
|
|
|
|
|
"username" => $user->getLoginName(),
|
|
|
|
|
"userId" => $user->getId(),
|
|
|
|
|
"userConfig" => $user->getConfig(),
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
logLoginsToJsonFile($user->getLoginName());
|
|
|
|
|
// we're not logged in, but authorized for the stuff we want to do. So don't redirect
|
|
|
|
|
return;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if not returned yet: no login, no valid apiKey -> redirect to login page
|
|
|
|
|
if (!self::isLoginValid()) {
|
|
|
|
|
header('Location: login?returnToUrl=' . urlencode($_SERVER['REQUEST_URI'] . ($_POST['fragment'] ?? '')), true, 301);
|
|
|
|
|
header(
|
|
|
|
|
"Location: login?returnToUrl=" .
|
|
|
|
|
urlencode(
|
|
|
|
|
$_SERVER["REQUEST_URI"] . ($_POST["fragment"] ?? "")
|
|
|
|
|
),
|
|
|
|
|
true,
|
|
|
|
|
301
|
|
|
|
|
);
|
|
|
|
|
exit(); // shouldn't matter
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -160,10 +176,10 @@ class participo
|
|
|
|
|
{
|
|
|
|
|
self::authentificate();
|
|
|
|
|
self::initDb(
|
|
|
|
|
$config['db']['host'],
|
|
|
|
|
$config['db']['name'],
|
|
|
|
|
$config['db']['user'],
|
|
|
|
|
$config['db']['password']
|
|
|
|
|
$config["db"]["host"],
|
|
|
|
|
$config["db"]["name"],
|
|
|
|
|
$config["db"]["user"],
|
|
|
|
|
$config["db"]["password"]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -182,8 +198,8 @@ class participo
|
|
|
|
|
*/
|
|
|
|
|
public static function parseParams($params)
|
|
|
|
|
{
|
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
|
|
|
$request = explode('/', substr(@$_SERVER['PATH_INFO'], 1));
|
|
|
|
|
$method = $_SERVER["REQUEST_METHOD"];
|
|
|
|
|
$request = explode("/", substr(@$_SERVER["PATH_INFO"], 1));
|
|
|
|
|
|
|
|
|
|
$parsedParams = [];
|
|
|
|
|
foreach ($params as $paramName => $parseFunction) {
|
|
|
|
|
@@ -192,11 +208,15 @@ class participo
|
|
|
|
|
// case 'PUT':
|
|
|
|
|
// do_something_with_put($request);
|
|
|
|
|
// break;
|
|
|
|
|
case 'POST':
|
|
|
|
|
$parsedParams[$paramName] = $parseFunction($_POST[$paramName]);
|
|
|
|
|
case "POST":
|
|
|
|
|
$parsedParams[$paramName] = $parseFunction(
|
|
|
|
|
$_POST[$paramName]
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'GET':
|
|
|
|
|
$parsedParams[$paramName] = $parseFunction($_GET[$paramName]);
|
|
|
|
|
case "GET":
|
|
|
|
|
$parsedParams[$paramName] = $parseFunction(
|
|
|
|
|
$_GET[$paramName]
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// handle_error($request);
|
|
|
|
|
@@ -213,7 +233,7 @@ class participo
|
|
|
|
|
|
|
|
|
|
public static function addMessage($type, $message)
|
|
|
|
|
{
|
|
|
|
|
self::$message[$type] = (self::$message[$type] ?? '') . $message;
|
|
|
|
|
self::$message[$type] = (self::$message[$type] ?? "") . $message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** check password for user
|
|
|
|
|
@@ -230,7 +250,7 @@ class participo
|
|
|
|
|
|
|
|
|
|
// Check for dbConnection
|
|
|
|
|
if (!dbConnector::getDbConnection()) {
|
|
|
|
|
self::addMessage('error', '<div>No DbConnection available</div>');
|
|
|
|
|
self::addMessage("error", "<div>No DbConnection available</div>");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -239,25 +259,28 @@ class participo
|
|
|
|
|
// If there is no such user OR the password isn't valid the login fails
|
|
|
|
|
if ($user == null || !$user->verifyPassword($password)) {
|
|
|
|
|
sleep(5); // discourage brute force attacks
|
|
|
|
|
self::addMessage('error', '<div>Falsches Passwort oder LoginName</div>');
|
|
|
|
|
self::addMessage(
|
|
|
|
|
"error",
|
|
|
|
|
"<div>Falsches Passwort oder LoginName</div>"
|
|
|
|
|
);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
session_start();
|
|
|
|
|
// case valid login: Set the session data
|
|
|
|
|
$_SESSION = [
|
|
|
|
|
'login' => true,
|
|
|
|
|
'user' => [
|
|
|
|
|
'username' => $user->getLoginName(),
|
|
|
|
|
'userId' => $user->getId(),
|
|
|
|
|
'userConfig' => $user->getConfig()
|
|
|
|
|
]
|
|
|
|
|
"login" => true,
|
|
|
|
|
"user" => [
|
|
|
|
|
"username" => $user->getLoginName(),
|
|
|
|
|
"userId" => $user->getId(),
|
|
|
|
|
"userConfig" => $user->getConfig(),
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// Logging Logins
|
|
|
|
|
logLoginsToJsonFile($_SESSION['user']['username']);
|
|
|
|
|
logLoginsToJsonFile($_SESSION["user"]["username"]);
|
|
|
|
|
|
|
|
|
|
self::addMessage('success', '<div>Anmeldung erfolgreich</div>');
|
|
|
|
|
self::addMessage("success", "<div>Anmeldung erfolgreich</div>");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -269,8 +292,8 @@ class participo
|
|
|
|
|
*/
|
|
|
|
|
public static function isUserAdmin($userId = null)
|
|
|
|
|
{
|
|
|
|
|
$userId = $userId ?? $_SESSION['user']['userId'];
|
|
|
|
|
return self::hasUserAttribute($userId, 'isAdmin');
|
|
|
|
|
$userId = $userId ?? $_SESSION["user"]["userId"];
|
|
|
|
|
return self::hasUserAttribute($userId, "isAdmin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getUserId()
|
|
|
|
|
@@ -280,24 +303,26 @@ class participo
|
|
|
|
|
/** get current logged in users kids */
|
|
|
|
|
public static function getKids($userId = null)
|
|
|
|
|
{
|
|
|
|
|
$userId = $userId ?? $_SESSION['user']['userId'] ?? null;
|
|
|
|
|
$userId = $userId ?? ($_SESSION["user"]["userId"] ?? null);
|
|
|
|
|
|
|
|
|
|
$query =
|
|
|
|
|
'SELECT * FROM `wkParticipo_Users` '
|
|
|
|
|
. 'INNER JOIN `vormundschaft` '
|
|
|
|
|
. 'ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` '
|
|
|
|
|
. 'INNER JOIN `wkParticipo_user<=>userAttributes` '
|
|
|
|
|
. 'ON `wkParticipo_Users`.`id` = `wkParticipo_user<=>userAttributes`.`userId`'
|
|
|
|
|
. 'WHERE `vormundschaft`.`userId` = :userId '
|
|
|
|
|
. 'AND `vormundschaft`.`userId` = :userId '
|
|
|
|
|
. 'AND `wkParticipo_user<=>userAttributes`.`attributeId` = 4;';
|
|
|
|
|
$params = [':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]];
|
|
|
|
|
"SELECT * FROM `wkParticipo_Users` " .
|
|
|
|
|
"INNER JOIN `vormundschaft` " .
|
|
|
|
|
"ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId` " .
|
|
|
|
|
"INNER JOIN `wkParticipo_user<=>userAttributes` " .
|
|
|
|
|
"ON `wkParticipo_Users`.`id` = `wkParticipo_user<=>userAttributes`.`userId`" .
|
|
|
|
|
"WHERE `vormundschaft`.`userId` = :userId " .
|
|
|
|
|
"AND `vormundschaft`.`userId` = :userId " .
|
|
|
|
|
"AND `wkParticipo_user<=>userAttributes`.`attributeId` = 4;";
|
|
|
|
|
$params = [
|
|
|
|
|
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = dbConnector::query($query, $params);
|
|
|
|
|
|
|
|
|
|
$kids = [];
|
|
|
|
|
foreach ($response as $r) {
|
|
|
|
|
$kids[] = User::fromDbArray($r, ['id' => 'kidId']);
|
|
|
|
|
$kids[] = User::fromDbArray($r, ["id" => "kidId"]);
|
|
|
|
|
}
|
|
|
|
|
return $kids;
|
|
|
|
|
}
|
|
|
|
|
@@ -311,17 +336,18 @@ class participo
|
|
|
|
|
public static function isWardOf(int $kidId, int $userId = null)
|
|
|
|
|
{
|
|
|
|
|
// Try to get the Guard from the session data.
|
|
|
|
|
$userId = $userId ?? $_SESSION['user']['userId'] ?? null;
|
|
|
|
|
$userId = $userId ?? ($_SESSION["user"]["userId"] ?? null);
|
|
|
|
|
|
|
|
|
|
$query = 'SELECT `kidId` FROM `vormundschaft` WHERE `userId` = :userId AND `kidId` = :kidId;';
|
|
|
|
|
$query =
|
|
|
|
|
"SELECT `kidId` FROM `vormundschaft` WHERE `userId` = :userId AND `kidId` = :kidId;";
|
|
|
|
|
$params = [
|
|
|
|
|
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT],
|
|
|
|
|
':kidId' => ['value' => $kidId, 'data_type' => PDO::PARAM_INT]
|
|
|
|
|
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
|
|
|
|
|
":kidId" => ["value" => $kidId, "data_type" => PDO::PARAM_INT],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$response = dbConnector::query($query, $params);
|
|
|
|
|
|
|
|
|
|
return (count($response) >= 1);
|
|
|
|
|
return count($response) >= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Checks, if a user as a certain attribute
|
|
|
|
|
@@ -340,13 +366,16 @@ ON `wkParticipo_user<=>userAttributes`.`attributeId` = `wkParticipo_userAttribut
|
|
|
|
|
WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId;
|
|
|
|
|
SQL;
|
|
|
|
|
$params = [
|
|
|
|
|
':userId' => ['value' => $userId, 'data_type' => PDO::PARAM_INT],
|
|
|
|
|
':attributeName' => ['value' => $attributeName, 'data_type' => PDO::PARAM_STR]
|
|
|
|
|
":userId" => ["value" => $userId, "data_type" => PDO::PARAM_INT],
|
|
|
|
|
":attributeName" => [
|
|
|
|
|
"value" => $attributeName,
|
|
|
|
|
"data_type" => PDO::PARAM_STR,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$attributedUsers = dbConnector::query($query, $params);
|
|
|
|
|
// Since the id should be unique, there should only be one result this is just for dealing with empty arrays
|
|
|
|
|
foreach ($attributedUsers as $u) {
|
|
|
|
|
if ($u['userId'] == $userId) {
|
|
|
|
|
if ($u["userId"] == $userId) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -355,9 +384,9 @@ SQL;
|
|
|
|
|
|
|
|
|
|
public static function getEventStarter($sinceDate = null)
|
|
|
|
|
{
|
|
|
|
|
$userId = $_SESSION['user']['userId'];
|
|
|
|
|
$userId = $_SESSION["user"]["userId"];
|
|
|
|
|
if (!$sinceDate) {
|
|
|
|
|
$sinceDate = 'CURDATE()';
|
|
|
|
|
$sinceDate = "CURDATE()";
|
|
|
|
|
} else {
|
|
|
|
|
$sinceDate = 'DATE("' . $sinceDate . '")';
|
|
|
|
|
}
|
|
|
|
|
@@ -387,14 +416,14 @@ SQL;
|
|
|
|
|
class AppCardAction
|
|
|
|
|
{
|
|
|
|
|
private $caption = null; //< Caption for the action
|
|
|
|
|
private $link = '.'; //< link for the action
|
|
|
|
|
private $link = "."; //< link for the action
|
|
|
|
|
|
|
|
|
|
/** Constructor for the AppAction
|
|
|
|
|
*
|
|
|
|
|
* @param string $caption caption for the action
|
|
|
|
|
* @param string $link link to the action
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($caption, $link = '.')
|
|
|
|
|
public function __construct($caption, $link = ".")
|
|
|
|
|
{
|
|
|
|
|
//! @todo input sanitation
|
|
|
|
|
$this->link = $link;
|
|
|
|
|
@@ -407,7 +436,7 @@ class AppCardAction
|
|
|
|
|
*/
|
|
|
|
|
public function htmlCode()
|
|
|
|
|
{
|
|
|
|
|
return '<a href="' . $this->link . '">' . $this->caption . '</a>';
|
|
|
|
|
return '<a href="' . $this->link . '">' . $this->caption . "</a>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Create AppCardAction from assoziative array
|
|
|
|
|
@@ -417,8 +446,8 @@ class AppCardAction
|
|
|
|
|
*/
|
|
|
|
|
public static function fromArray($member)
|
|
|
|
|
{
|
|
|
|
|
$caption = $member['caption'] ?? null;
|
|
|
|
|
$link = $member['link'] ?? '.';
|
|
|
|
|
$caption = $member["caption"] ?? null;
|
|
|
|
|
$link = $member["link"] ?? ".";
|
|
|
|
|
return new AppCardAction($caption, $link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -427,8 +456,8 @@ class AppCardAction
|
|
|
|
|
*/
|
|
|
|
|
class AppCard
|
|
|
|
|
{
|
|
|
|
|
private $title = ''; //< title of the card
|
|
|
|
|
private $description = ''; //< description of the App
|
|
|
|
|
private $title = ""; //< title of the card
|
|
|
|
|
private $description = ""; //< description of the App
|
|
|
|
|
private $link = null; //< link for the card-content
|
|
|
|
|
private $imgUrl = null; //< url for an image right under the title
|
|
|
|
|
private $actionList = []; //< list of actions for the bottom of the card
|
|
|
|
|
@@ -442,8 +471,13 @@ class AppCard
|
|
|
|
|
* @param string $imgUrl url for an image right under the title
|
|
|
|
|
* @param array $actionList list of actions at the bottom of the card
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($title, $description, $link = null, $imgUrl = null, $actionList = [])
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
$title,
|
|
|
|
|
$description,
|
|
|
|
|
$link = null,
|
|
|
|
|
$imgUrl = null,
|
|
|
|
|
$actionList = []
|
|
|
|
|
) {
|
|
|
|
|
//! @todo input sanitation
|
|
|
|
|
$this->title = $title;
|
|
|
|
|
$this->description = $description;
|
|
|
|
|
@@ -459,22 +493,37 @@ class AppCard
|
|
|
|
|
*/
|
|
|
|
|
public function htmlCode($options = [])
|
|
|
|
|
{
|
|
|
|
|
$extraClass = $options['extraClass'] ?? '';
|
|
|
|
|
$actionListCode = '';
|
|
|
|
|
$extraClass = $options["extraClass"] ?? "";
|
|
|
|
|
$actionListCode = "";
|
|
|
|
|
foreach ($this->actionList as $a) {
|
|
|
|
|
$actionListCode .= $a->htmlCode();
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
'<div style="padding:1%;" class="col s12 m6 ' . $extraClass . '">' .
|
|
|
|
|
return '<div style="padding:1%;" class="col s12 m6 ' .
|
|
|
|
|
$extraClass .
|
|
|
|
|
'">' .
|
|
|
|
|
'<div style="margin:1%;" class="card blue-grey darken-1">' .
|
|
|
|
|
'<div class="card-content white-text">' .
|
|
|
|
|
(($this->link != null) ? ('<a href="' . $this->link . '">') : ('')) . '<span class="card-title">' . $this->title . '</span>' . (($this->link != null) ? ('</a>') : ('')) .
|
|
|
|
|
(($this->imgUrl != null) ? ('<img alt="' . $this->title . '" style="display:block;margin-left:auto;margin-right:auto;max-height:10vh;" class="responsive-img" src="' . $this->imgUrl . '" />') : ('')) .
|
|
|
|
|
'<p>' . $this->description . '</p>' .
|
|
|
|
|
'</div>' .
|
|
|
|
|
'<div class="card-action">' . $actionListCode . '</div>' .
|
|
|
|
|
'</div>' .
|
|
|
|
|
'</div>';
|
|
|
|
|
($this->link != null ? '<a href="' . $this->link . '">' : "") .
|
|
|
|
|
'<span class="card-title">' .
|
|
|
|
|
$this->title .
|
|
|
|
|
"</span>" .
|
|
|
|
|
($this->link != null ? "</a>" : "") .
|
|
|
|
|
($this->imgUrl != null
|
|
|
|
|
? '<img alt="' .
|
|
|
|
|
$this->title .
|
|
|
|
|
'" style="display:block;margin-left:auto;margin-right:auto;max-height:10vh;" class="responsive-img" src="' .
|
|
|
|
|
$this->imgUrl .
|
|
|
|
|
'" />'
|
|
|
|
|
: "") .
|
|
|
|
|
"<p>" .
|
|
|
|
|
$this->description .
|
|
|
|
|
"</p>" .
|
|
|
|
|
"</div>" .
|
|
|
|
|
'<div class="card-action">' .
|
|
|
|
|
$actionListCode .
|
|
|
|
|
"</div>" .
|
|
|
|
|
"</div>" .
|
|
|
|
|
"</div>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -485,11 +534,11 @@ class AppCard
|
|
|
|
|
*/
|
|
|
|
|
public static function fromArray($member)
|
|
|
|
|
{
|
|
|
|
|
$title = $member['title'] ?? '';
|
|
|
|
|
$description = $member['description'] ?? '';
|
|
|
|
|
$link = $member['link'] ?? null;
|
|
|
|
|
$imgUrl = $member['imgUrl'] ?? null;
|
|
|
|
|
$actionList = $member['actions'] ?? [];
|
|
|
|
|
$title = $member["title"] ?? "";
|
|
|
|
|
$description = $member["description"] ?? "";
|
|
|
|
|
$link = $member["link"] ?? null;
|
|
|
|
|
$imgUrl = $member["imgUrl"] ?? null;
|
|
|
|
|
$actionList = $member["actions"] ?? [];
|
|
|
|
|
|
|
|
|
|
return new AppCard($title, $description, $link, $imgUrl, $actionList);
|
|
|
|
|
}
|
|
|
|
|
@@ -500,7 +549,7 @@ class AppCard
|
|
|
|
|
* @param string $jsonFileName path to the json file with the logged logins
|
|
|
|
|
* @return string Html table of users last logins
|
|
|
|
|
*/
|
|
|
|
|
function lastLoginTable($jsonFileName = 'lastLogins.json')
|
|
|
|
|
function lastLoginTable($jsonFileName = "lastLogins.json")
|
|
|
|
|
{
|
|
|
|
|
// load the jsonfile into an associative array
|
|
|
|
|
$lastLogins = json_decode(file_get_contents($jsonFileName), true);
|
|
|
|
|
@@ -508,57 +557,55 @@ function lastLoginTable($jsonFileName = 'lastLogins.json')
|
|
|
|
|
// collecting the last login of the users ...
|
|
|
|
|
$lastLoginRows = [];
|
|
|
|
|
foreach ($lastLogins as $userName => $lastLogins) {
|
|
|
|
|
$lastLoginRows[$userName] = $lastLogins['lastLogins'][0];
|
|
|
|
|
$lastLoginRows[$userName] = $lastLogins["lastLogins"][0];
|
|
|
|
|
}
|
|
|
|
|
// and sort it so the last login is first in line
|
|
|
|
|
arsort($lastLoginRows);
|
|
|
|
|
|
|
|
|
|
// build the table
|
|
|
|
|
$lastLoginsTable =
|
|
|
|
|
'<table>' .
|
|
|
|
|
'<thead><tr><th>userName</th><th>lastLogin</th></tr></thead>' .
|
|
|
|
|
'<tbody>';
|
|
|
|
|
"<table>" .
|
|
|
|
|
"<thead><tr><th>userName</th><th>lastLogin</th></tr></thead>" .
|
|
|
|
|
"<tbody>";
|
|
|
|
|
foreach ($lastLoginRows as $userName => $lastLogin) {
|
|
|
|
|
$lastLoginsTable .=
|
|
|
|
|
'<tr><td>' . $userName . '</td><td>' . $lastLogin . '</td></tr>';
|
|
|
|
|
"<tr><td>" . $userName . "</td><td>" . $lastLogin . "</td></tr>";
|
|
|
|
|
}
|
|
|
|
|
$lastLoginsTable .=
|
|
|
|
|
'</tbody>' .
|
|
|
|
|
'</table>';
|
|
|
|
|
$lastLoginsTable .= "</tbody>" . "</table>";
|
|
|
|
|
return $lastLoginsTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
|
|
|
|
|
function htmlRetMessage($anRetMessage)
|
|
|
|
|
{
|
|
|
|
|
$retHtmlString = '';
|
|
|
|
|
$retHtmlString = "";
|
|
|
|
|
if (!empty($anRetMessage)) {
|
|
|
|
|
$retHtmlString .= '<div style="border: 1px solid;">';
|
|
|
|
|
if (!empty($anRetMessage['error'])) {
|
|
|
|
|
if (!empty($anRetMessage["error"])) {
|
|
|
|
|
$retHtmlString .= '<div style="border: 1px solid;">';
|
|
|
|
|
$retHtmlString .= 'ERROR:<br />';
|
|
|
|
|
$retHtmlString .= $anRetMessage['error'];
|
|
|
|
|
$retHtmlString .= '</div>';
|
|
|
|
|
$retHtmlString .= "ERROR:<br />";
|
|
|
|
|
$retHtmlString .= $anRetMessage["error"];
|
|
|
|
|
$retHtmlString .= "</div>";
|
|
|
|
|
}
|
|
|
|
|
if (!empty($anRetMessage['warning'])) {
|
|
|
|
|
if (!empty($anRetMessage["warning"])) {
|
|
|
|
|
$retHtmlString .= '<div style="border: 1px solid;">';
|
|
|
|
|
$retHtmlString .= 'WARNING:<br />';
|
|
|
|
|
$retHtmlString .= $anRetMessage['warning'];
|
|
|
|
|
$retHtmlString .= '</div>';
|
|
|
|
|
$retHtmlString .= "WARNING:<br />";
|
|
|
|
|
$retHtmlString .= $anRetMessage["warning"];
|
|
|
|
|
$retHtmlString .= "</div>";
|
|
|
|
|
}
|
|
|
|
|
if (!empty($anRetMessage['notice'])) {
|
|
|
|
|
if (!empty($anRetMessage["notice"])) {
|
|
|
|
|
$retHtmlString .= '<div style="border: 1px solid;">';
|
|
|
|
|
$retHtmlString .= 'Info:<br />';
|
|
|
|
|
$retHtmlString .= $anRetMessage['notice'];
|
|
|
|
|
$retHtmlString .= '</div>';
|
|
|
|
|
$retHtmlString .= "Info:<br />";
|
|
|
|
|
$retHtmlString .= $anRetMessage["notice"];
|
|
|
|
|
$retHtmlString .= "</div>";
|
|
|
|
|
}
|
|
|
|
|
if (!empty($anRetMessage['success'])) {
|
|
|
|
|
if (!empty($anRetMessage["success"])) {
|
|
|
|
|
$retHtmlString .= '<div style="border: 1px solid;">';
|
|
|
|
|
$retHtmlString .= 'SUCCESS:<br />';
|
|
|
|
|
$retHtmlString .= $anRetMessage['success'];
|
|
|
|
|
$retHtmlString .= '</div>';
|
|
|
|
|
$retHtmlString .= "SUCCESS:<br />";
|
|
|
|
|
$retHtmlString .= $anRetMessage["success"];
|
|
|
|
|
$retHtmlString .= "</div>";
|
|
|
|
|
}
|
|
|
|
|
$retHtmlString .= '</div>';
|
|
|
|
|
$retHtmlString .= "</div>";
|
|
|
|
|
}
|
|
|
|
|
return $retHtmlString;
|
|
|
|
|
}
|
|
|
|
|
@@ -576,35 +623,33 @@ function loadMarkdownFile($fileName)
|
|
|
|
|
$fileParts = preg_split('/[\n]*[-]{3}[\n]/', $fileText, 3);
|
|
|
|
|
// not all mdFiles have a yamlHeader, so the mdText can be at different indices
|
|
|
|
|
$yaml = [];
|
|
|
|
|
$mdText = '';
|
|
|
|
|
switch(count($fileParts)) {
|
|
|
|
|
case 1:{
|
|
|
|
|
$mdText = "";
|
|
|
|
|
switch (count($fileParts)) {
|
|
|
|
|
case 1:
|
|
|
|
|
$mdText = $fileParts[0];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 3:{
|
|
|
|
|
case 3:
|
|
|
|
|
$yaml = Spyc::YAMLLoadString($fileParts[1]);
|
|
|
|
|
$mdText = $fileParts[2];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:{
|
|
|
|
|
default:
|
|
|
|
|
$mdText = $fileText;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// get a title, if none is in the markdown
|
|
|
|
|
if (!array_key_exists('title', $yaml)) {
|
|
|
|
|
if (!array_key_exists("title", $yaml)) {
|
|
|
|
|
// find the first heading, set it as header and remove it from the markdown
|
|
|
|
|
if (preg_match('/^#(.*)$/m', $mdText, $matches)) {
|
|
|
|
|
$yaml['title'] = $matches[1];
|
|
|
|
|
$mdText = preg_replace('/^#(.*)$/m', '', $mdText, 1);
|
|
|
|
|
$yaml["title"] = $matches[1];
|
|
|
|
|
$mdText = preg_replace('/^#(.*)$/m', "", $mdText, 1);
|
|
|
|
|
} else {
|
|
|
|
|
// fallback for the title, if not even one heading is found
|
|
|
|
|
$yaml['title'] = '<fehlender Titel>';
|
|
|
|
|
$yaml["title"] = "<fehlender Titel>";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'yaml' => $yaml, 'mdText' => $mdText
|
|
|
|
|
"yaml" => $yaml,
|
|
|
|
|
"mdText" => $mdText,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -614,7 +659,7 @@ function loadMarkdownFile($fileName)
|
|
|
|
|
* @param string $fileName filename to log to
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json')
|
|
|
|
|
function logLoginsToJsonFile($userName, $fileName = "lastLogins.json")
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$lastLogins = json_decode(file_get_contents($fileName), true);
|
|
|
|
|
@@ -624,14 +669,16 @@ function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json')
|
|
|
|
|
if (!array_key_exists($userName, $lastLogins)) {
|
|
|
|
|
$lastLogins[$userName] = [];
|
|
|
|
|
}
|
|
|
|
|
if (!array_key_exists('lastLogins', $lastLogins[$userName])) {
|
|
|
|
|
$lastLogins[$userName]['lastLogins'] = [];
|
|
|
|
|
if (!array_key_exists("lastLogins", $lastLogins[$userName])) {
|
|
|
|
|
$lastLogins[$userName]["lastLogins"] = [];
|
|
|
|
|
}
|
|
|
|
|
$usersLastLogins = $lastLogins[$userName]['lastLogins'];
|
|
|
|
|
$usersLastLogins = array_merge([date('Y-m-d H:i:s')], $usersLastLogins);
|
|
|
|
|
$usersLastLogins = $lastLogins[$userName]["lastLogins"];
|
|
|
|
|
$usersLastLogins = array_merge([date("Y-m-d H:i:s")], $usersLastLogins);
|
|
|
|
|
$usersLastLogins = array_slice($usersLastLogins, 0, 10);
|
|
|
|
|
$lastLogins[$userName]['lastLogins'] = $usersLastLogins;
|
|
|
|
|
$lastLogins[$userName]["lastLogins"] = $usersLastLogins;
|
|
|
|
|
if (is_writable($fileName)) {
|
|
|
|
|
file_put_contents($fileName, json_encode($lastLogins));
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
// silently ignore errors
|
|
|
|
|
}
|
|
|
|
|
@@ -640,15 +687,19 @@ function logLoginsToJsonFile($userName, $fileName = 'lastLogins.json')
|
|
|
|
|
/// @brief Gibt die URL der gerade aufgerufenen Seite zurück
|
|
|
|
|
function getCurPagesUrl()
|
|
|
|
|
{
|
|
|
|
|
$pageURL = 'http';
|
|
|
|
|
if ( array_key_exists("HTTPS", $_SERVER) && ($_SERVER['HTTPS'] == 'on')) {
|
|
|
|
|
$pageURL .= 's';
|
|
|
|
|
$pageURL = "http";
|
|
|
|
|
if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") {
|
|
|
|
|
$pageURL .= "s";
|
|
|
|
|
}
|
|
|
|
|
$pageURL .= '://';
|
|
|
|
|
if ($_SERVER['SERVER_PORT'] != '80') {
|
|
|
|
|
$pageURL .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'];
|
|
|
|
|
$pageURL .= "://";
|
|
|
|
|
if ($_SERVER["SERVER_PORT"] != "80") {
|
|
|
|
|
$pageURL .=
|
|
|
|
|
$_SERVER["SERVER_NAME"] .
|
|
|
|
|
":" .
|
|
|
|
|
$_SERVER["SERVER_PORT"] .
|
|
|
|
|
$_SERVER["REQUEST_URI"];
|
|
|
|
|
} else {
|
|
|
|
|
$pageURL .= $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
|
|
|
|
|
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
|
|
|
|
|
}
|
|
|
|
|
return $pageURL;
|
|
|
|
|
}
|
|
|
|
|
@@ -660,20 +711,25 @@ function getCurPagesUrl()
|
|
|
|
|
*/
|
|
|
|
|
function getHtmlSquareDate($date = null)
|
|
|
|
|
{
|
|
|
|
|
$date = $date ?? new DateTime;
|
|
|
|
|
$date = $date ?? new DateTime();
|
|
|
|
|
|
|
|
|
|
$year = $date->format('Y');
|
|
|
|
|
$month = $date->format('M');
|
|
|
|
|
$day = $date->format('d');
|
|
|
|
|
$year = $date->format("Y");
|
|
|
|
|
$month = $date->format("M");
|
|
|
|
|
$day = $date->format("d");
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
'<div>'
|
|
|
|
|
. '<div>'
|
|
|
|
|
. '<span style="font-size:large">' . $day . '</span>'
|
|
|
|
|
. '<span style="writing-mode: sideways-lr">' . $month . '</span>'
|
|
|
|
|
. '</div>'
|
|
|
|
|
. '<div style="font-size: small">' . $year . '</div>'
|
|
|
|
|
. '</div>';
|
|
|
|
|
return "<div>" .
|
|
|
|
|
"<div>" .
|
|
|
|
|
'<span style="font-size:large">' .
|
|
|
|
|
$day .
|
|
|
|
|
"</span>" .
|
|
|
|
|
'<span style="writing-mode: sideways-lr">' .
|
|
|
|
|
$month .
|
|
|
|
|
"</span>" .
|
|
|
|
|
"</div>" .
|
|
|
|
|
'<div style="font-size: small">' .
|
|
|
|
|
$year .
|
|
|
|
|
"</div>" .
|
|
|
|
|
"</div>";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** filter_var for a pos int
|
|
|
|
|
@@ -686,7 +742,9 @@ function getHtmlSquareDate($date = null)
|
|
|
|
|
* */
|
|
|
|
|
function filterPosInt($id)
|
|
|
|
|
{
|
|
|
|
|
return filter_var($id, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
|
|
|
|
return filter_var($id, FILTER_VALIDATE_INT, [
|
|
|
|
|
"options" => ["default" => null, "min_range" => 1],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** filter_var for a (db)id
|
|
|
|
|
@@ -713,5 +771,7 @@ function filterId($id)
|
|
|
|
|
*/
|
|
|
|
|
function filterCount($variable, int $min = 0)
|
|
|
|
|
{
|
|
|
|
|
return filter_var($variable, FILTER_VALIDATE_INT, ['options' => ['default' => null, 'min_range' => 1]]);
|
|
|
|
|
return filter_var($variable, FILTER_VALIDATE_INT, [
|
|
|
|
|
"options" => ["default" => null, "min_range" => 1],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|