format("Y-m-d") .
"\n\n";
foreach ($attendancesAssocArray as $d => $attendees) {
$ret .= "## {$d}\n";
$i = 0;
foreach ($attendees as $a) {
$i += 1;
$ret .= "\n";
$ret .= $i . " " . $a["name"] . ", " . $a["vorname"] . "\n";
$ret .= " - PLZ: " . $a["corona_PLZ"] . "\n";
$ret .= " - Tel.: " . $a["corona_telephon"] . "\n";
$ret .= " - eMail: " . $a["corona_eMail"] . "\n";
}
$ret .= "\n";
}
return $ret;
}
function attendancesAssocArray2text($attendancesAssocArray)
{
$ret = "";
foreach ($attendancesAssocArray as $date => $attendees) {
$ret .= "{$date}\n";
foreach ($attendees as $a) {
$ret .= "\n";
$ret .= "Name: " . $a["name"] . ", " . $a["vorname"] . "\n";
$ret .= "PLZ: " . $a["corona_PLZ"] . "\n";
$ret .= "Tel.: " . $a["corona_telephon"] . "\n";
$ret .= "eMail: " . $a["corona_eMail"] . "\n";
}
$ret .= "\n";
}
return $ret;
}
function sendEmail($toEmail, $emailText)
{
try {
$date = new \DateTime();
mail(
$toEmail,
"Kontakliste CWSV-Judo vom " . $date->format("Y-m-d"),
$emailText,
);
} catch (\Exception $e) {
echo "Message: " . $e->getMessage();
}
}
/// Validaing a phone number
/// true if it validates, false if not
/// @todo input validation functions should be together (wherever the filterInit etc. are..)
function validate_phone_number($phone)
{
// Allow +, - and . in phone number
$filtered_phone_number = filter_var($phone, FILTER_SANITIZE_NUMBER_INT);
// Remove "-" from number
$phone_to_check = str_replace("-", "", $filtered_phone_number);
// Check the lenght of number
// This can be customized if you want phone number from a specific country
if (\strlen($phone_to_check) < 10 || \strlen($phone_to_check) > 14) {
return false;
} else {
return true;
}
}
/// validate different types of input
/// @todo input validation functions should be together (wherever the filterInit etc. are..)
function isValid($toValidate, $type)
{
// for now we disable the name validation: what do i know how people can be called!
// $regexName="/^[A-Z][a-zA-Z]*$/";
$regexPlz = "/^[0-9]{5}$/";
return match ($type) {
"plz" => preg_match($regexPlz, $toValidate) > 0,
"phonenumber" => validate_phone_number($toValidate),
"email" => filter_var($toValidate, FILTER_VALIDATE_EMAIL),
default => false,
};
}
//! Checks if multiple keys exist in an array
//!
//! @param array $array array to check for key
//! @param array|string $keys keys to check for
//!
//! @return bool true, if *all* keys are set in the array
function array_keys_exist(array $array, $keys)
{
if (!\is_array($keys)) {
$keys = \func_get_args();
array_shift($keys);
}
$count = 0;
foreach ($keys as $key) {
if (isset($array[$key]) || \array_key_exists($key, $array)) {
$count++;
}
}
return \count($keys) === $count;
}
function giveJudokasAttendence($date, $ids)
{
$values = [];
try {
foreach ($ids as $id) {
array_push($values, "(\"{$date}\", {$id})");
}
$query =
"INSERT INTO `anwesenheit` (`date`, `userId`) VALUES " .
join(",", $values) .
";";
\dbConnector::query($query, [], ["dontFetch" => true]);
} catch (\PDOException $db_error) {
print "Error!: " . $db_error->getMessage() . "
";
return null;
}
}
// updates corona data of an user
function updateCoronaData($userId, $columnName, $columnValue)
{
$coronaColumnNames = ["corona_PLZ", "corona_telephon", "corona_eMail"];
if (!\in_array($columnName, $coronaColumnNames)) {
return;
}
$query = "UPDATE `wkParticipo_Users` SET ` {$columnName} `=:val WHERE `id`=:id;";
$params = [
":val" => ["value" => $columnValue, "data_type" => \PDO::PARAM_STR],
":id" => ["value" => $userId, "data_type" => \PDO::PARAM_INT],
];
\dbConnector::query($query, $params);
return;
}
function addCoronaUser(
$name,
$vorname,
$corona_PLZ,
$corona_telephon,
$corona_eMail,
) {
$query = << ["value" => $name, "data_type" => \PDO::PARAM_STR],
":vorname" => ["value" => $vorname, "data_type" => \PDO::PARAM_STR],
":plz" => ["value" => $corona_PLZ, "data_type" => \PDO::PARAM_STR],
":telephon" => [
"value" => $corona_telephon,
"data_type" => \PDO::PARAM_STR,
],
":email" => ["value" => $corona_eMail, "data_type" => \PDO::PARAM_STR],
];
\dbConnector::query($query, $params);
$newId = \dbConnector::getDbConnection()->lastInsertId();
giveUserAnUserAttribute($newId, "inTraining");
return;
}