From 782588c613d51f55f097b324b523da4c2dd773af Mon Sep 17 00:00:00 2001 From: marko Date: Sun, 25 Oct 2020 16:19:27 +0100 Subject: [PATCH 1/4] First Version --- homepage/mams/.htaccess | 6 ++ homepage/mams/index.php | 64 ++++++++++++ homepage/mams/lib/db.php | 126 ++++++++++++++++++++++++ homepage/mams/local/cwsvJudo.config.php | 6 ++ 4 files changed, 202 insertions(+) create mode 100644 homepage/mams/.htaccess create mode 100644 homepage/mams/index.php create mode 100644 homepage/mams/lib/db.php create mode 100644 homepage/mams/local/cwsvJudo.config.php diff --git a/homepage/mams/.htaccess b/homepage/mams/.htaccess new file mode 100644 index 0000000..34b4883 --- /dev/null +++ b/homepage/mams/.htaccess @@ -0,0 +1,6 @@ +AuthType Basic +AuthName "tempDirectory" +AuthUserFile /users/cwsvjudo/www/.htusers +#AuthGroupFile /users/cwsvjudo/www/.htgroups +Require user marko +#Require group admin diff --git a/homepage/mams/index.php b/homepage/mams/index.php new file mode 100644 index 0000000..3d2eff6 --- /dev/null +++ b/homepage/mams/index.php @@ -0,0 +1,64 @@ + + + +
+ + " /> + + +
+ $attendees);{ + echo("

".$date."

"); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + foreach($attendees as $a){ + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + } + echo("
namevornamePLZTelefoneMail
".$a[0]['name']."".$a[0]['vorname']."".$a[0]['corona_PLZ']."".$a[0]['corona_telephon']."".$a[0]['corona_eMail']."
"); + } + ?> + + diff --git a/homepage/mams/lib/db.php b/homepage/mams/lib/db.php new file mode 100644 index 0000000..e00cd2d --- /dev/null +++ b/homepage/mams/lib/db.php @@ -0,0 +1,126 @@ +getMessage() ); + } +return $dbConnection; +} + +function createDb($dbConnection){ +<< 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(!$pdoResult) + //echo("Strange! \"".$aQueryString."\" failed without exception!"); + + if($someOptions['dontFetch']){ + $ret = NULL; + } + else{ + $ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC); + } + } + catch(PDOException $db_error){ + print "Error!: " . $db_error->getMessage() . "
"; + 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 + ); + } + } +return $ret; +} + +function getLastAttendances($db){ + $query = <<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 giveJudokasAttendence($dbConnection, $date, $ids){ + $values = array(); + 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]); +} +?> diff --git a/homepage/mams/local/cwsvJudo.config.php b/homepage/mams/local/cwsvJudo.config.php new file mode 100644 index 0000000..3998c08 --- /dev/null +++ b/homepage/mams/local/cwsvJudo.config.php @@ -0,0 +1,6 @@ + From 15df17bbd9bfb61f72b67fc868d8b49278fee2b1 Mon Sep 17 00:00:00 2001 From: marko Date: Sun, 25 Oct 2020 17:56:41 +0100 Subject: [PATCH 2/4] Corrected table display --- homepage/mams/index.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/homepage/mams/index.php b/homepage/mams/index.php index 3d2eff6..c52dd10 100644 --- a/homepage/mams/index.php +++ b/homepage/mams/index.php @@ -14,18 +14,20 @@ $judokas = getJudokasInTraining($dbConnection, "inTraining"); $lastAttendances = getLastAttendances($dbConnection); $lastAttendancesAssocArray = array(); foreach($lastAttendances as $a){ - if(!isset($lastAttendances[$a['date']])) + if(!array_key_exists( $a['date'], $lastAttendancesAssocArray)){ $lastAttendancesAssocArray[$a['date']] = array(); - $lastAttendancesAssocArray[$a['date']][] = array( $a ); + } + array_push( $lastAttendancesAssocArray[ $a['date'] ], $a ); } if($_POST['action']){ giveJudokasAttendence($dbConnection, $_POST['attandanceDate'], $_POST['judokaIdsInTraining']); + header("Location: ."); } $dateLastWendsday = new DateTime("last wednesday"); $dateLastFriday = new DateTime("last friday"); -$lastTrainingDay = min($dateLastWendsday, $dateLastFriday); +$lastTrainingDay = max($dateLastWendsday, $dateLastFriday); ?> @@ -38,9 +40,9 @@ $lastTrainingDay = min($dateLastWendsday, $dateLastFriday); - $attendees);{ + $attendees){ echo("

".$date."

"); - echo(""); + echo("
"); echo(""); echo(""); echo(""); @@ -50,11 +52,11 @@ $lastTrainingDay = min($dateLastWendsday, $dateLastFriday); echo(""); foreach($attendees as $a){ echo(""); - echo(""); - echo(""); - echo(""); - echo(""); - echo(""); + echo(""); + echo(""); + echo(""); + echo(""); + echo(""); echo(""); } echo("
namevorname
".$a[0]['name']."".$a[0]['vorname']."".$a[0]['corona_PLZ']."".$a[0]['corona_telephon']."".$a[0]['corona_eMail']."".$a['name']."".$a['vorname']."".$a['corona_PLZ']."".$a['corona_telephon']."".$a['corona_eMail']."
"); From b6f6bbbacc216847583d6ba6b8827d0fed18107f Mon Sep 17 00:00:00 2001 From: marko Date: Tue, 27 Oct 2020 06:40:33 +0100 Subject: [PATCH 3/4] - Usage of materialize css framework - outsourcing functions to new lib/api.php --- homepage/mams/index.php | 36 ++++++++++++++++++++++++----------- homepage/mams/lib/.htaccess | 1 + homepage/mams/lib/api.php | 10 ++++++++++ homepage/mams/lib/db.php | 14 ++++++++++---- homepage/mams/local/.htaccess | 1 + 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 homepage/mams/lib/.htaccess create mode 100644 homepage/mams/lib/api.php create mode 100644 homepage/mams/local/.htaccess diff --git a/homepage/mams/index.php b/homepage/mams/index.php index c52dd10..5f6c355 100644 --- a/homepage/mams/index.php +++ b/homepage/mams/index.php @@ -1,6 +1,7 @@ +
+ + + + + + + +
- - " /> - - +
+ + " /> + + +
$attendees){ echo("

".$date."

"); diff --git a/homepage/mams/lib/.htaccess b/homepage/mams/lib/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/homepage/mams/lib/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/homepage/mams/lib/api.php b/homepage/mams/lib/api.php new file mode 100644 index 0000000..f0576d1 --- /dev/null +++ b/homepage/mams/lib/api.php @@ -0,0 +1,10 @@ + diff --git a/homepage/mams/lib/db.php b/homepage/mams/lib/db.php index e00cd2d..4c8ac6f 100644 --- a/homepage/mams/lib/db.php +++ b/homepage/mams/lib/db.php @@ -117,10 +117,16 @@ return dbQuery($dbConnection, $query, $params); function giveJudokasAttendence($dbConnection, $date, $ids){ $values = array(); - foreach( $ids as $id){ - array_push( $values, "(\"".$date."\", ".$id.")");; + 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() . "
"; + return null; } - $query = "INSERT INTO `cwsvjudo`.`anwesenheit` (`date`, `userId`) VALUES ".join(",", $values).";"; - dbQuery($dbConnection, $query, array(), ['dontFetch' => true]); } ?> diff --git a/homepage/mams/local/.htaccess b/homepage/mams/local/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/homepage/mams/local/.htaccess @@ -0,0 +1 @@ +Deny from all From ba134efcc114ba93d69166d6a2c88d9cf7fd470e Mon Sep 17 00:00:00 2001 From: marko Date: Wed, 28 Oct 2020 09:19:06 +0100 Subject: [PATCH 4/4] - 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 --- homepage/mams/index.php | 34 +++++++++++++---- homepage/mams/lib/api.php | 79 +++++++++++++++++++++++++++++++++++++-- homepage/mams/lib/db.php | 75 ++++++++++++++++++++++++++++++++----- 3 files changed, 169 insertions(+), 19 deletions(-) diff --git a/homepage/mams/index.php b/homepage/mams/index.php index 5f6c355..b6c87d1 100644 --- a/homepage/mams/index.php +++ b/homepage/mams/index.php @@ -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); +

Corona-Anwesenheitsliste der Judoka des Chemnitzer WSV

+

Anwesenheiten hinzufügen

-
+
" /> - ".$j['vorname']." ".$j['name']."");?>
+

Anwesenheiten

+

Sende Anwesenheitsliste an eMail

+
+ + + + +
$attendees){ - echo("

".$date."

"); + echo("

".$date."

"); echo(""); echo(""); echo(""); @@ -68,13 +78,23 @@ $lastTrainingDay = max($dateLastWendsday, $dateLastFriday); echo(""); echo(""); echo(""); - echo(""); - echo(""); - echo(""); + echo(""); + echo(""); + echo(""); echo(""); } echo("
name
".$a['name']."".$a['vorname']."".$a['corona_PLZ']."".$a['corona_telephon']."".$a['corona_eMail']."".( $a['corona_PLZ'] ? $a['corona_PLZ'] : "
")."
".( $a['corona_telephon'] ? $a['corona_telephon'] : "
")."
".( $a['corona_eMail'] ? $a['corona_eMail'] : "
")."
"); } ?> +

Trainee hinzufügen

+
+ + + + + + + +
diff --git a/homepage/mams/lib/api.php b/homepage/mams/lib/api.php index f0576d1..ff7a13f 100644 --- a/homepage/mams/lib/api.php +++ b/homepage/mams/lib/api.php @@ -1,10 +1,83 @@ 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; +} ?> diff --git a/homepage/mams/lib/db.php b/homepage/mams/lib/db.php index 4c8ac6f..493fa49 100644 --- a/homepage/mams/lib/db.php +++ b/homepage/mams/lib/db.php @@ -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 = << 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 = <<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 = << 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; +} ?>