- add posibility to add missing data within the list
- section for adding new corona trainee - list (of the last month) can be send to an eMail
This commit is contained in:
@@ -1,10 +1,83 @@
|
||||
<?php
|
||||
|
||||
function processPostData($db, $post){
|
||||
function processPostData($db, $post, $redirectLocation = "."){
|
||||
if($post['action']){
|
||||
giveJudokasAttendence($db, $post['attandanceDate'], $post['judokaIdsInTraining']);
|
||||
header("Location: .");
|
||||
if($post['action'] == "giveAttendance"){
|
||||
giveJudokasAttendence($db, $post['attandanceDate'], $post['judokaIdsInTraining']);
|
||||
}
|
||||
if($post['action'] == "updateCoronaData"){
|
||||
updateCoronaData($db, $post['userId'], $post['columnName'], $post['columnValue']);
|
||||
}
|
||||
if($post['action'] == "addCoronaUser"){
|
||||
addCoronaUser(
|
||||
$db,
|
||||
$post['name'],
|
||||
$post['vorname'],
|
||||
$post['corona_PLZ'],
|
||||
$post['corona_telephon'],
|
||||
$post['corona_eMail']
|
||||
);
|
||||
}
|
||||
if($post['action'] == "sendAttandeesPerEmail"){
|
||||
sendEmail(
|
||||
$post['toEmail'],
|
||||
$post['emailText']
|
||||
);
|
||||
}
|
||||
header("Location: ".$redirectLocation);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function sendEmail($toEmail, $emailText){
|
||||
//var_dump($toEmail);
|
||||
//var_dump($emailText);
|
||||
try{
|
||||
$date=new DateTime();
|
||||
mail(
|
||||
$toEmail,
|
||||
"Kontakliste CWSV-Judo vom ".$date->format("Y-m-d"),
|
||||
$emailText
|
||||
);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo 'Message: ' .$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
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 attendancesAssocArray2mdList($attendancesAssocArray, $date=null){
|
||||
if($date == null)
|
||||
$date=new DateTime();
|
||||
$ret = "# Anwesenheitsliste zur Corona-Kontaktverfolgung der Abteilung Judo des CWSV vom ".$date->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;
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -56,9 +56,6 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
||||
}
|
||||
$pdoResult = $pdoStatement->execute();
|
||||
|
||||
//if(!$pdoResult)
|
||||
//echo("Strange! \"".$aQueryString."\" failed without exception!");
|
||||
|
||||
if($someOptions['dontFetch']){
|
||||
$ret = NULL;
|
||||
}
|
||||
@@ -82,24 +79,35 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
||||
);
|
||||
}
|
||||
}
|
||||
//var_dump($ret);
|
||||
//var_dump($aQueryString);
|
||||
//var_dump($aBindArray);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getLastAttendances($db){
|
||||
function getLastAttendances($db, $minDate=null){
|
||||
if ($minDate == null){
|
||||
$minDate = new DateTime;
|
||||
$minDate->sub(new DateInterval("P1M")); // from the current date subtract a *P*eriod of *1* *M*onth
|
||||
}
|
||||
|
||||
$query = <<<SQL
|
||||
SELECT date, vorname, name, corona_PLZ, corona_telephon, corona_eMail
|
||||
SELECT userId, date, vorname, name, corona_PLZ, corona_telephon, corona_eMail
|
||||
FROM `cwsvjudo`.`anwesenheit`
|
||||
JOIN `cwsvjudo`.`wkParticipo_Users`
|
||||
ON `cwsvjudo`.`anwesenheit`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id`
|
||||
JOIN `cwsvjudo`.`wkParticipo_Users`
|
||||
ON `cwsvjudo`.`anwesenheit`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id`
|
||||
WHERE :minDate <= date
|
||||
ORDER BY `date` DESC, `name`;
|
||||
SQL;
|
||||
$params = array();
|
||||
$params = array(
|
||||
'minDate' => array('value' => $minDate->format('Y-m-d'), 'data_type' => PDO::PARAM_STR)
|
||||
);
|
||||
$options = array();
|
||||
$ret = dbQuery($db, $query, $params, $options);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getJudokasInTraining($dbConnection, $attributeName){
|
||||
function getUsersWithAttribute($dbConnection, $attributeName){
|
||||
$query = <<<SQL
|
||||
SELECT userId, name, vorname
|
||||
FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
@@ -115,6 +123,20 @@ SQL;
|
||||
return dbQuery($dbConnection, $query, $params);
|
||||
}
|
||||
|
||||
function giveUserAnUserAttribute($dbConnection, $userId, $attributeName){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`wkParticipo_user<=>userAttributes` (`userId`, `attributeId`)
|
||||
SELECT :userId, `id`
|
||||
FROM `cwsvjudo`.`wkParticipo_userAttributes`
|
||||
WHERE `name` = :attributeName;
|
||||
SQL;
|
||||
$params = array(
|
||||
':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT),
|
||||
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||
);
|
||||
return dbQuery($dbConnection, $query, $params);
|
||||
}
|
||||
|
||||
function giveJudokasAttendence($dbConnection, $date, $ids){
|
||||
$values = array();
|
||||
try{
|
||||
@@ -129,4 +151,39 @@ function giveJudokasAttendence($dbConnection, $date, $ids){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// updates corona data of an user
|
||||
function updateCoronaData($db, $userId, $columnName, $columnValue){
|
||||
$coronaColumnNames = ["corona_PLZ", "corona_telephon", "corona_eMail"];
|
||||
|
||||
if( !in_array( $columnName, $coronaColumnNames) ){
|
||||
return;
|
||||
}
|
||||
$query = "UPDATE `cwsvjudo`.`wkParticipo_Users` SET `".$columnName."`=:val WHERE `id`=:id;";
|
||||
$params = array(
|
||||
':val' => array('value'=>$columnValue, 'data_type'=>PDO::PARAM_STR),
|
||||
':id' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT)
|
||||
);
|
||||
dbQuery($db, $query, $params);
|
||||
return;
|
||||
}
|
||||
|
||||
function addCoronaUser($db, $name, $vorname, $corona_PLZ, $corona_telephon, $corona_eMail){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`wkParticipo_Users` (name, vorname, corona_PLZ, corona_telephon, corona_eMail)
|
||||
VALUES (:name, :vorname, :plz, :telephon, :email);
|
||||
SQL;
|
||||
$params = array(
|
||||
':name' => array('value'=>$name, 'data_type'=>PDO::PARAM_STR),
|
||||
':vorname' => array('value'=>$vorname, 'data_type'=>PDO::PARAM_STR),
|
||||
':plz' => array('value'=>$corona_PLZ, 'data_type'=>PDO::PARAM_STR),
|
||||
':telephon' => array('value'=>$corona_telephon, 'data_type'=>PDO::PARAM_STR),
|
||||
':email' => array('value'=>$corona_eMail, 'data_type'=>PDO::PARAM_STR),
|
||||
);
|
||||
dbQuery($db, $query, $params);
|
||||
|
||||
$newId = $db->lastInsertId();
|
||||
giveUserAnUserAttribute($db, $newId, "inTraining");
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user