diff --git a/homepage/machs/auth.php b/homepage/machs/auth.php index 1ab0da4..93147fc 100644 --- a/homepage/machs/auth.php +++ b/homepage/machs/auth.php @@ -9,7 +9,7 @@ session_start(); $login_status = "
". "Datum: ".date("Y-m-d")."
". - "Angemeldet als ".htmlspecialchars($_SESSION['user']['username'])." angemeldet.
". + "Angemeldet als ".htmlspecialchars($_SESSION['user']['username']).".
". "Sitzung beenden". "
"; } diff --git a/homepage/machs/images.d/seilspringen.svg b/homepage/machs/images.d/seilspringen.svg new file mode 100644 index 0000000..5035465 --- /dev/null +++ b/homepage/machs/images.d/seilspringen.svg @@ -0,0 +1,461 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/homepage/machs/index.php b/homepage/machs/index.php index d613c98..5cd55f3 100644 --- a/homepage/machs/index.php +++ b/homepage/machs/index.php @@ -5,27 +5,29 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); require_once("./local/dbConf.php"); require_once("./local/achievementsConf.php"); + require_once("./lib/db.php"); require_once("./lib/achievementsLib.php"); + require_once("./lib/api.php"); require_once("./auth.php"); $basePath = "/users/cwsvjudo/www"; require_once($basePath."/config/cwsvJudo.config.php"); require_once($basePath."/config/phpcount.config.php"); - require_once($basePath."/ressourcen/phpLib/phpcount/phpcount.php"); - require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php"); +// require_once($basePath."/ressourcen/phpLib/phpcount/phpcount.php"); +// require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php"); - $dbConnection = getCwsvJudoDbConn(); +// $dbConnection = getCwsvJudoDbConn(); + $dbConnection = getPdoDbConnection( + $cwsvJudoConfig["db"]["host"], + $cwsvJudoConfig["db"]["name"], + $cwsvJudoConfig["db"]["user"], + $cwsvJudoConfig["db"]["password"] + ); - try{ - $results = dbQuery( - $dbConnection, - "SELECT * FROM cwsvjudo.achievements;" - ); - } - catch(PDOException $db_error){ - print "Error!: " . $db_error->getMessage() . "
queryString: ".$queryString."
"; var_dump($bindArray); - } +$achievementGroups = getAchievementGroups($dbConnection); + +processPostData($dbConnection, $_POST); ?> @@ -34,24 +36,71 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge'); + + + + + Achievements - -

Achievements

- + + Eigene Achievements" ); + echo( htmlUsersUploadBox($dbConnection, $_SESSION['user']['userId']) ); + echo(htmlAchievementListForUser( + $dbConnection, + $achievementGroups, + $_SESSION['user']['userId'], + getUsersAchievements($dbConnection, $_SESSION['user']['userId']) + )); + } + ?> + + ".$k['vorname']." ".$k['name']."" ); + echo( htmlUsersUploadBox($dbConnection, $k['kidId']) ); + echo(htmlAchievementListForUser( + $dbConnection, + $achievementGroups, + $k['kidId'], + getUsersAchievements($dbConnection, $k['kidId']) + )); + } + } + ?> + +Add Achievements"); + echo(htmlAddAchievementBox()); + + echo("

Update Achievements

"); + $achievements = getAchievements($dbConnection); + foreach($achievements as $a){ + echo( htmlUpdateAchievementBox( + $a['id'], + $a['name'], + $a['description'], + $a['rootId'], + $a['level'] + )); + echo("
"); + } + } + ?> + diff --git a/homepage/machs/lib/achievementsLib.php b/homepage/machs/lib/achievementsLib.php index e81bfc7..9a63773 100644 --- a/homepage/machs/lib/achievementsLib.php +++ b/homepage/machs/lib/achievementsLib.php @@ -33,4 +33,197 @@ if( !empty($anRetMessage) ){ // print_r($anRetMessage); return $retHtmlString; } + +// one time only function to convert the list of kids within the user +// table itself to an extra entry in a "vormundschafts" table +function convertToVormundschaft($db){ + $query = << array('value' => $user['id'], 'data_type' => PDO::PARAM_INT), + ':kidId' => array('value' => $kidId, 'data_type' => PDO::PARAM_INT), + ); + dbQuery($db, $query, $params); + } + } +return; +} + +/// get all available achievements +function getAchievementList($db){ +$results = null; + try{ + $results = dbQuery( + $db, + "SELECT * FROM cwsvjudo.achievements;" + ); + } + catch(PDOException $db_error){ + print "Error!: " . $db_error->getMessage() . "
queryString: ".$queryString."
"; var_dump($bindArray); + } +return $results; +} + +function getAchievementGroups($db){ +return achievementList2achievementGroups( getAchievementList($db) ); +} + +function arrayKeyed2htmlTableString($anArray, $keyList, $withCaption = false){ +$ret = ""; + if( !is_array($anArray) ) + return ""; + $ret .= ""; + if($withCaption) { + $ret .= ""; + foreach( $keyList as $caption ){ + $ret .= ""; + } + $ret .= ""; + } + foreach($anArray as $row){ + if( !is_array($anArray) ) + continue; + $ret .= ""; + foreach( $keyList as $key ) + $ret .= ""; + $ret .= ""; + } + $ret .= "
".$caption."
".$row[$key]."
"; +return $ret; +} + +function getUsersAchievements($db, $userId){ + $query = <<user` WHERE `userId` = :userId; +SQL; + $params = [':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT)]; + $result = dbQuery($db, $query, $params); +return $result; +} + +function achievementList2achievementGroups ( $list ){ +$groups = []; + foreach($list as $a){ + if(!array_key_exists($a['rootId'], $groups) ){ + $groups[ $a['rootId'] ] = array(); + } + $groups[ $a['rootId'] ][ $a['level']] = $a; + } + foreach($groups as $key=>$g){ + ksort($groups[$key]); + } + ksort($groups); +return $groups; +} + +function htmlUsersUploadBox($db, $userId){ +$html = ""; + $userData = getUserData($db, $userId); + $html .= "
"; + $html .= "
Upload Link
".$userData['machsUploadUrl']."
"; + $html .= "
Upload Passwort
".$userData['machsUploadPw']."
"; + $html .= "
"; +return $html; +} + +function htmlAchievementListForUser($db, $achievementGroups, $userId, $usersAchievmentIds){ +//var_dump($db, $achievementGroups, $userId, $usersAchievmentIds); +$ids=[]; +foreach($usersAchievmentIds as $a){ + $ids[]=$a['achievementId']; +} +$retHtml = ""; + if(!canUserGetAchievementToday( $db, $userId) ){ + $retHtml .= "
Heute wurde schon ein Achievement erreicht!
"; + } + $retHtml .= "
"; + foreach($achievementGroups as $g){ + $retHtml .= "
"; + $retHtml .= "
    "; + $imgUrl = null; + foreach($g as $a){ + if($a['imgUrl'] != null){ + $imgUrl = $a['imgUrl']; + } + if(in_array($a['id'], $ids)){ + $retHtml .= "
  • ✓ ".$a['name'].": ".$a['description']; + $retHtml .= "
  • "; + } + else{ + $retHtml .= "
  • ".$a['name'].": ".$a['description']; + //if(isUserAdmin($db, $_SESSION['user']['userId'])){ + if(canUserGetAchievementToday( $db, $userId) ){ + $retHtml .= "
    "; + $retHtml .= ""; + $retHtml .= ""; + $retHtml .= ""; + $retHtml .= ""; + $retHtml .= "
    "; + } + if( $imgUrl != null ) + $retHtml .= "
    "; + $retHtml .= "
  • "; + break; + } + } + $retHtml .= "
"; + $retHtml .= "
"; + } + $retHtml .= "
"; +return $retHtml; +} + +function htmlAddAchievementBox(){ +$html = ""; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= ""; + $html .= "
"; +return $html; +} + +function htmlUpdateAchievementBox($achievementId, $name, $description, $rootId, $level){ +$html = ""; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= "
achievementId: ".$achievementId; + $html .= ""; + $html .= "
"; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= "
"; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= "
"; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= "
"; + $html .= "
"; + $html .= ""; + $html .= ""; + $html .= "
"; + $html .= ""; + $html .= ""; +return $html; +} + ?> diff --git a/homepage/machs/lib/api.php b/homepage/machs/lib/api.php new file mode 100644 index 0000000..370ea7a --- /dev/null +++ b/homepage/machs/lib/api.php @@ -0,0 +1,85 @@ +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/machs/lib/db.php b/homepage/machs/lib/db.php new file mode 100644 index 0000000..52c4a31 --- /dev/null +++ b/homepage/machs/lib/db.php @@ -0,0 +1,323 @@ +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 ){ + if( $bind['data_type'] == PDO::PARAM_STR) + $bind['value'] = iconv( + $someOptions['outCharset'], + $someOptions['dbCharset'], + $bind['value'] + ); + $pdoStatement->bindValue( + $bindName, + $bind['value'], + (isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR) + ); + } + $pdoResult = $pdoStatement->execute(); + if(!$pdoResult){ + echo("Error during dbQuery!\n"); + echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo()); +// echo($pdoStatement.errorInfo()); + } + 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 + ); + } + } +//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 = << 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 = <<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 = <<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 hasUserAttribute($dbConnection, $userId, $attributeName){ + $query = <<userAttributes`.userId, `wkParticipo_userAttributes`.name +FROM `wkParticipo_user<=>userAttributes` LEFT JOIN `wkParticipo_userAttributes` +ON `wkParticipo_user<=>userAttributes`.`attributeId` = `wkParticipo_userAttributes`.`id` +WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId;", +SQL; + $params = array( + ':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT), + ':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR) + ); + $attributedUsers = dbQuery($dbConnection, $query, $params); + foreach($attributedUsers as $u) + if($u['userId']==$userId) + return true; +return false; +} + +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() . "
"; + return null; + } +} + +function getUsersKidsIds($db, $userId){ + $query = <<['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]; + $result = dbQuery($db, $query, $params); +return $result; +} + +function getUsersKids($db, $userId){ + $query = <<['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]; + $result = dbQuery($db, $query, $params); +return $result; +} + +// 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; +} + +function giveUserAnAchievement($db, $userId, $achievementId){ + $query = <<user` (`userId`, `achievementId`) VALUE (:userId, :achievementId); +SQL; + $params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT], 'achievementId'=>['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT]]; + dbQuery($db, $query, $params); + sendEmail("cwsvjudo@arcor.de", "kwT", "User ".$userId." got achievement ".$achievementId); +return; +} + +function isUserAdmin($dbConn, $userId){ + $adminUsers = + dbQuery( + $dbConn, + "SELECT `wkParticipo_user<=>userAttributes`.userId, `wkParticipo_userAttributes`.name from `wkParticipo_user<=>userAttributes` LEFT JOIN `wkParticipo_userAttributes` ON `wkParticipo_user<=>userAttributes`.attributeId = `wkParticipo_userAttributes`.id WHERE `wkParticipo_userAttributes`.name = :attributeName;", + array(":attributeName"=>array('value'=>"isAdmin", 'data_type'=>PDO::PARAM_STR)) + ); + foreach($adminUsers as $adminUser) + if($adminUser['userId']==$userId) + return true; +return false; +} + +function getUserData($db, $userId){ + $query = <<['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]; + $userData = dbQuery($db, $query, $params); +return $userData[0]; +} + +function getAchievements($db){ + $query = << ['value'=>$name, 'data_type'=>PDO::PARAM_STR], + ':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR], + ]; + dbQuery($db, $query, $params, ['dontFetch'=>true]); +return; +} + +function updateAchievement($db, $achievementId, $name, $description, $rootId, $level){ + $query = << ['value'=>$name, 'data_type'=>PDO::PARAM_STR], + ':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR], + ':rootId' => ['value'=>$rootId, 'data_type'=>PDO::PARAM_INT], + ':level' => ['value'=>$level, 'data_type'=>PDO::PARAM_INT], + ':achievementId' => ['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT], + ]; + dbQuery($db, $query, $params, ['dontFetch'=>true]); +return; +} + +function canUserGetAchievementToday($db, $userId){ + $achievements = getUsersAchievements($db, $userId); + foreach($achievements as $a){ + if( date('Ymd') == date('Ymd', strtotime($a['timestamp'])) ) + return false; + } +return true; +} + +?> diff --git a/homepage/machs/login.php b/homepage/machs/login.php index 214d393..c8c20bf 100644 --- a/homepage/machs/login.php +++ b/homepage/machs/login.php @@ -30,7 +30,7 @@ function checkCredentials($username, $password, $db_server, $db_user, $db_passwo ), ); $message['success'] = 'Anmeldung erfolgreich, weiter zum Inhalt.'; - header('Location: http://' . $_SERVER['HTTP_HOST'] . '/achievements?user=' . $_POST['f']['username']); + header('Location: http://' . $_SERVER['HTTP_HOST'] . '/machs?user=' . $_POST['f']['username']); } else { sleep(1); $message['error'] = 'Das Kennwort ist nicht korrekt.'; diff --git a/homepage/machs/logout.php b/homepage/machs/logout.php new file mode 100644 index 0000000..f6ee446 --- /dev/null +++ b/homepage/machs/logout.php @@ -0,0 +1,18 @@ +