- 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:
@@ -12,7 +12,7 @@ $dbConnection = getPdoDbConnection(
|
||||
|
||||
processPostData($dbConnection, $_POST);
|
||||
|
||||
$judokas = getJudokasInTraining($dbConnection, "inTraining");
|
||||
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
||||
|
||||
$lastAttendances = getLastAttendances($dbConnection);
|
||||
$lastAttendancesAssocArray = array();
|
||||
@@ -44,18 +44,28 @@ $lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||
</header>
|
||||
<body>
|
||||
<h1>Corona-Anwesenheitsliste der Judoka des Chemnitzer WSV</h1>
|
||||
<h2>Anwesenheiten hinzufügen</h2>
|
||||
<form action="./index.php" method="POST">
|
||||
<div class="input-field col s12">
|
||||
<div class="input-field">
|
||||
<input id="giveAttendanceAction" name="action" value="giveAttendance" type="hidden" />
|
||||
<input id="attendenceDate" name="attandanceDate" value="<?php echo($lastTrainingDay->format("Y-m-d"));?>" />
|
||||
<select name="judokaIdsInTraining[]" id="judokaIdsInTraining" multiple>
|
||||
<select name="judokaIdsInTraining[]" id="judokaIdsInTraining" multiple><option value="" disabled selected>Anwesende auswählen</option>
|
||||
<?php foreach($judokas as $j) echo("<option value=\"".$j['userId']."\">".$j['vorname']." ".$j['name']."</option>");?>
|
||||
</select>
|
||||
<input type="submit" value="Submit">
|
||||
</div>
|
||||
</form>
|
||||
<h2>Anwesenheiten</h2>
|
||||
<h3>Sende Anwesenheitsliste an eMail</h3>
|
||||
<form method="POST" action="." >
|
||||
<input name="toEmail" type="text" placeholder="toEmail" />
|
||||
<input name="action" type="hidden" value="sendAttandeesPerEmail" />
|
||||
<input name="emailText" type="hidden" value="<?php echo( attendancesAssocArray2mdList($lastAttendancesAssocArray) );?>" />
|
||||
<input type="submit" value="Send Email" />
|
||||
</form>
|
||||
<?php foreach($lastAttendancesAssocArray as $date => $attendees){
|
||||
echo("<h2>".$date."</h2>");
|
||||
echo("<h3>".$date."</h3>");
|
||||
echo("<table border=\"1\">");
|
||||
echo("<tr>");
|
||||
echo("<th>name</th>");
|
||||
@@ -68,13 +78,23 @@ $lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
||||
echo("<tr>");
|
||||
echo("<td>".$a['name']."</td>");
|
||||
echo("<td>".$a['vorname']."</td>");
|
||||
echo("<td>".$a['corona_PLZ']."</td>");
|
||||
echo("<td>".$a['corona_telephon']."</td>");
|
||||
echo("<td>".$a['corona_eMail']."</td>");
|
||||
echo("<td>".( $a['corona_PLZ'] ? $a['corona_PLZ'] : "<form action=\".\" method=\"POST\"><input name=\"action\" value =\"updateCoronaData\" type=\"hidden\" /><input name=\"columnName\" value=\"corona_PLZ\" type=\"hidden\" /><input name=\"userId\" value=\"".$a['userId']."\" type=\"hidden\" /><input name=\"columnValue\" type=\"text\" placeholder=\"PLZ\" /><input type=\"submit\" value=\"Submit\"></form>")."</td>");
|
||||
echo("<td>".( $a['corona_telephon'] ? $a['corona_telephon'] : "<form action=\".\" method=\"POST\"><input name=\"action\" value =\"updateCoronaData\" type=\"hidden\" /><input name=\"columnName\" value=\"corona_telephon\" type=\"hidden\" /><input name=\"userId\" value=\"".$a['userId']."\" type=\"hidden\" /><input name=\"columnValue\" type=\"text\" placeholder=\"Telephpon\" /><input type=\"submit\" value=\"Submit\"></form>")."</td>");
|
||||
echo("<td>".( $a['corona_eMail'] ? $a['corona_eMail'] : "<form action=\".\" method=\"POST\"><input name=\"action\" value =\"updateCoronaData\" type=\"hidden\" /><input name=\"columnName\" value=\"corona_eMail\" type=\"hidden\" /><input name=\"userId\" value=\"".$a['userId']."\" type=\"hidden\" /><input name=\"columnValue\" type=\"text\" placeholder=\"eMail\" /><input type=\"submit\" value=\"Submit\"></form>")."</td>");
|
||||
echo("</tr>");
|
||||
}
|
||||
echo("</table>");
|
||||
}
|
||||
?>
|
||||
<h2>Trainee hinzufügen</h2>
|
||||
<form action="." method="POST">
|
||||
<input name="action" value="addCoronaUser" type="hidden" />
|
||||
<input placeholder="Name" name="name" type="text" />
|
||||
<input placeholder="Vorname" name="vorname" type="text" />
|
||||
<input placeholder="PLZ" name="corona_PLZ" type ="text" />
|
||||
<input placeholder="Telefon" name="corona_telephon" type="text" />
|
||||
<input placeholder="eMail" name="corona_eMail" type="text" />
|
||||
<input type="submit" value="Neuen Corona-User eintragen" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -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