Merge branch 'anwesenheitssystem'
This commit is contained in:
6
homepage/mams/.htaccess
Normal file
6
homepage/mams/.htaccess
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
AuthType Basic
|
||||||
|
AuthName "tempDirectory"
|
||||||
|
AuthUserFile /users/cwsvjudo/www/.htusers
|
||||||
|
#AuthGroupFile /users/cwsvjudo/www/.htgroups
|
||||||
|
Require user marko
|
||||||
|
#Require group admin
|
||||||
100
homepage/mams/index.php
Normal file
100
homepage/mams/index.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
require_once("./local/cwsvJudo.config.php");
|
||||||
|
require_once("./lib/db.php");
|
||||||
|
require_once("./lib/api.php");
|
||||||
|
|
||||||
|
$dbConnection = getPdoDbConnection(
|
||||||
|
$cwsvJudoConfig["db"]["host"],
|
||||||
|
$cwsvJudoConfig["db"]["name"],
|
||||||
|
$cwsvJudoConfig["db"]["user"],
|
||||||
|
$cwsvJudoConfig["db"]["password"]
|
||||||
|
);
|
||||||
|
|
||||||
|
processPostData($dbConnection, $_POST);
|
||||||
|
|
||||||
|
$judokas = getUsersWithAttribute($dbConnection, "inTraining");
|
||||||
|
|
||||||
|
$lastAttendances = getLastAttendances($dbConnection);
|
||||||
|
$lastAttendancesAssocArray = array();
|
||||||
|
foreach($lastAttendances as $a){
|
||||||
|
if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){
|
||||||
|
$lastAttendancesAssocArray[$a['date']] = array();
|
||||||
|
}
|
||||||
|
array_push( $lastAttendancesAssocArray[ $a['date'] ], $a );
|
||||||
|
}
|
||||||
|
|
||||||
|
$dateLastWendsday = new DateTime("last wednesday");
|
||||||
|
$dateLastFriday = new DateTime("last friday");
|
||||||
|
$lastTrainingDay = max($dateLastWendsday, $dateLastFriday);
|
||||||
|
|
||||||
|
?>
|
||||||
|
<html>
|
||||||
|
<header>
|
||||||
|
<!-- Compiled and minified CSS -->
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
|
||||||
|
<!-- Compiled and minified JavaScript -->
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
|
||||||
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
var elems = document.querySelectorAll('select');
|
||||||
|
var instances = M.FormSelect.init(elems);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<!--Let browser know website is optimized for mobile-->
|
||||||
|
<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">
|
||||||
|
<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><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("<h3>".$date."</h3>");
|
||||||
|
echo("<table border=\"1\">");
|
||||||
|
echo("<tr>");
|
||||||
|
echo("<th>name</th>");
|
||||||
|
echo("<th>vorname</th>");
|
||||||
|
echo("<th>PLZ</th>");
|
||||||
|
echo("<th>Telefon</th>");
|
||||||
|
echo("<th>eMail</th>");
|
||||||
|
echo("</tr>");
|
||||||
|
foreach($attendees as $a){
|
||||||
|
echo("<tr>");
|
||||||
|
echo("<td>".$a['name']."</td>");
|
||||||
|
echo("<td>".$a['vorname']."</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
homepage/mams/lib/.htaccess
Normal file
1
homepage/mams/lib/.htaccess
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Deny from all
|
||||||
83
homepage/mams/lib/api.php
Normal file
83
homepage/mams/lib/api.php
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function processPostData($db, $post, $redirectLocation = "."){
|
||||||
|
if($post['action']){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
?>
|
||||||
189
homepage/mams/lib/db.php
Normal file
189
homepage/mams/lib/db.php
Normal file
@@ -0,0 +1,189 @@
|
|||||||
|
<?php
|
||||||
|
// get a Connection to the database
|
||||||
|
function getPdoDbConnection($hostname, $dbName, $user, $password){
|
||||||
|
try{
|
||||||
|
$dbConnection = new PDO(
|
||||||
|
'mysql:host='.$hostname.';dbname='.$dbName,
|
||||||
|
$user,
|
||||||
|
$password
|
||||||
|
);
|
||||||
|
}
|
||||||
|
catch(PDOException $dbError){
|
||||||
|
echo( "Error whilst getting a dbConnection!: " . $dbError->getMessage() );
|
||||||
|
}
|
||||||
|
return $dbConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createDb($dbConnection){
|
||||||
|
<<<SQL
|
||||||
|
CREATE TABLE `cwsvjudo`.`anwesenheit` (
|
||||||
|
`id` INT UNSIGNED NOT NULL ,
|
||||||
|
`userId` INT UNSIGNED NOT NULL ,
|
||||||
|
`date` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP ,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE = InnoDB;
|
||||||
|
ALTER TABLE `cwsvjudo`.`anwesenheit` ADD UNIQUE `attandence` (`userId`, `id`);
|
||||||
|
SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// perform a pdo-query
|
||||||
|
///
|
||||||
|
/// @param aDbConnection
|
||||||
|
/// @param $aQueryString
|
||||||
|
/// @param $aBindArray e.g. array(
|
||||||
|
/// ':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
|
||||||
|
/// ':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT) )
|
||||||
|
/// @param $someOption
|
||||||
|
function dbQuery($aDbConnection, $aQueryString, $aBindArray = array(), $someOptions = array()){
|
||||||
|
// Standardbelegungen
|
||||||
|
if( empty($someOptions['dbCharset' ]) ) $someOptions['dbCharset' ] = "ISO-8859-1";
|
||||||
|
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";
|
||||||
|
if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
||||||
|
/// @toDo: Bisher wird nur die Rückgabe konvertiert. Eigentlich muss
|
||||||
|
/// doch auch die Eingabe konvertiert werden. Aber das jetzt
|
||||||
|
/// umzustellen wird schwer! Die User m Wettkampfplaner sind ja z.B.
|
||||||
|
/// als UTF8 in latin1(?) gespeichert.
|
||||||
|
/// @toDo: Die Standardwerte sollten vielleicht aus einer config
|
||||||
|
/// kommen, nicht hardcoded
|
||||||
|
try{
|
||||||
|
$pdoStatement = $aDbConnection->prepare( $aQueryString );
|
||||||
|
foreach( $aBindArray as $bindName => $bind ){
|
||||||
|
$pdoStatement->bindValue(
|
||||||
|
$bindName,
|
||||||
|
$bind['value'],
|
||||||
|
(isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$pdoResult = $pdoStatement->execute();
|
||||||
|
|
||||||
|
if($someOptions['dontFetch']){
|
||||||
|
$ret = NULL;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(PDOException $db_error){
|
||||||
|
print "Error!: " . $db_error->getMessage() . "<br/>";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Zeichensatzkonvertierung
|
||||||
|
if( is_array($ret) ){
|
||||||
|
foreach($ret as &$entry){
|
||||||
|
array_walk(
|
||||||
|
$entry,
|
||||||
|
function (&$value, $key, $someOptions) {
|
||||||
|
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
||||||
|
},
|
||||||
|
$someOptions
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//var_dump($ret);
|
||||||
|
//var_dump($aQueryString);
|
||||||
|
//var_dump($aBindArray);
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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`
|
||||||
|
WHERE :minDate <= date
|
||||||
|
ORDER BY `date` DESC, `name`;
|
||||||
|
SQL;
|
||||||
|
$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 getUsersWithAttribute($dbConnection, $attributeName){
|
||||||
|
$query = <<<SQL
|
||||||
|
SELECT userId, name, vorname
|
||||||
|
FROM `cwsvjudo`.`wkParticipo_Users`
|
||||||
|
JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes`
|
||||||
|
ON `cwsvjudo`.`wkParticipo_Users`.`id` =`cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`
|
||||||
|
WHERE `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` IN (
|
||||||
|
SELECT `id` FROM `cwsvjudo`.`wkParticipo_userAttributes` WHERE `name` = :attributeName
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
$params = array(
|
||||||
|
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||||
|
);
|
||||||
|
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{
|
||||||
|
foreach( $ids as $id){
|
||||||
|
array_push( $values, "(\"".$date."\", ".$id.")");;
|
||||||
|
}
|
||||||
|
$query = "INSERT INTO `cwsvjudo`.`anwesenheit` (`date`, `userId`) VALUES ".join(",", $values).";";
|
||||||
|
dbQuery($dbConnection, $query, array(), ['dontFetch' => true]);
|
||||||
|
}
|
||||||
|
catch(PDOException $db_error){
|
||||||
|
print "Error!: " . $db_error->getMessage() . "<br/>";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
?>
|
||||||
1
homepage/mams/local/.htaccess
Normal file
1
homepage/mams/local/.htaccess
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Deny from all
|
||||||
6
homepage/mams/local/cwsvJudo.config.php
Normal file
6
homepage/mams/local/cwsvJudo.config.php
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?php
|
||||||
|
$cwsvJudoConfig["db"]["host"] = "localhost";
|
||||||
|
$cwsvJudoConfig["db"]["name"] = "cwsvjudo";
|
||||||
|
$cwsvJudoConfig["db"]["user"] = "cwsvjudo";
|
||||||
|
$cwsvJudoConfig["db"]["password"] = "***REMOVED***";
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user