- added simple achievement editor

- added records
This commit is contained in:
marko
2020-11-16 09:32:27 +01:00
parent b610a3b8d6
commit a0ef0bf40c
12 changed files with 924 additions and 91 deletions

View File

@@ -0,0 +1,96 @@
<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("config.php");
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("./lib/record.php");
require_once("./lib/machs/achievementGroup.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");
PHPCount::AddHit("Achievementsystem (".htmlspecialchars($_SESSION['user']['username']).")");
// require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
// $dbConnection = getCwsvJudoDbConn();
$dbConnection = getPdoDbConnection(
$cwsvJudoConfig["db"]["host"],
$cwsvJudoConfig["db"]["name"],
$cwsvJudoConfig["db"]["user"],
$cwsvJudoConfig["db"]["password"]
);
if(!isUserAdmin($dbConnection, $_SESSION['user']['userId']))
header("Location: .");
record::setDbConnection($dbConnection);
achievementGroup::setDbConnection($dbConnection);
$achievementGroups = achievementGroup::getAllAchievementGroups();
processPostData($dbConnection, $_POST);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- 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>
<!-- inits for the materializeCss -->
<?php include("lib/machs/materializeInit.php");?>
<title>machs</title>
<meta name="description" content="Achievementsystem der Judoka des Chemnitzer WSV">
<link rel="icon" href="<?echo($config['ressourceUrl']);?>/graphiken/icons/cwsv.ico" />
<link rel="apple-touch-icon" href="<?echo($config['baseUrl']);?>/apple-touch-icon.png">
</head>
<body>
<!-- sidenav -->
<?php include("lib/machs/sidenav.php");?>
<!-- end sidenav -->
<h1>AchievementBuilder</h1>
<?php
echo("<h2 id=\"addAchievementGroup\">Add AchievementGroup</h2>");
echo(achievementGroup::htmlAddAchievementGroupForm());
echo("<h2>Update Achievements</h2>");
foreach($achievementGroups as $g){
echo("<h3>".$g->getName()."</h3>");
echo($g->htmlEditAchievementGroupForm());
$achievements = $g->getAchievements();
foreach($achievements as $a){
echo("<h4>".$a['name']."</h4>");
echo(htmlUpdateAchievementBox(
$a['id'],
$a['name'],
$a['rootId'],
$a['achievementGroupId'],
$a['level'],
$a['description'],
$a['imgUrl']
));
}
echo("<h4>Add achievement</h4>");
echo(htmlAddAchievementBox());
}
?>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@@ -8,13 +8,16 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("./lib/db.php"); require_once("./lib/db.php");
require_once("./lib/achievementsLib.php"); require_once("./lib/achievementsLib.php");
require_once("./lib/api.php"); require_once("./lib/api.php");
require_once("./lib/record.php");
require_once("./lib/machs/achievementGroup.php");
require_once("./auth.php"); require_once("./auth.php");
$basePath = "/users/cwsvjudo/www"; $basePath = "/users/cwsvjudo/www";
require_once($basePath."/config/cwsvJudo.config.php"); require_once($basePath."/config/cwsvJudo.config.php");
require_once($basePath."/config/phpcount.config.php"); require_once($basePath."/config/phpcount.config.php");
// require_once($basePath."/ressourcen/phpLib/phpcount/phpcount.php"); require_once($basePath."/ressourcen/phpLib/phpcount/phpcount.php");
PHPCount::AddHit("Achievementsystem (".htmlspecialchars($_SESSION['user']['username']).")");
// require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php"); // require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
// $dbConnection = getCwsvJudoDbConn(); // $dbConnection = getCwsvJudoDbConn();
@@ -25,7 +28,9 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
$cwsvJudoConfig["db"]["password"] $cwsvJudoConfig["db"]["password"]
); );
$achievementGroups = getAchievementGroups($dbConnection); record::setDbConnection($dbConnection);
achievementGroup::setDbConnection($dbConnection);
$achievementGroups = achievementGroup::getAllAchievementGroups();
processPostData($dbConnection, $_POST); processPostData($dbConnection, $_POST);
@@ -40,6 +45,8 @@ processPostData($dbConnection, $_POST);
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript --> <!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<!-- inits for the materializeCss -->
<?php include("lib/machs/materializeInit.php");?>
<title>Achievements</title> <title>Achievements</title>
<meta name="description" content="Achievements"> <meta name="description" content="Achievements">
@@ -49,58 +56,36 @@ processPostData($dbConnection, $_POST);
</head> </head>
<body> <body>
<?php echo $login_status; ?>
<!-- sidenav -->
<?php <?php include("lib/machs/sidenav.php");?>
<!-- end sidenav -->
<?php // show own achievements, if oneself is inTraining
if( hasUserAttribute($dbConnection, $_SESSION['user']['userId'], "inTraining" ) ){ if( hasUserAttribute($dbConnection, $_SESSION['user']['userId'], "inTraining" ) ){
echo( "<div class=\"row\">");
echo( "<h2>Eigene Achievements</h2>" ); echo( "<h2>Eigene Achievements</h2>" );
echo( htmlUsersUploadBox($dbConnection, $_SESSION['user']['userId']) ); # var_dump($achievementGroups);
echo(htmlAchievementListForUser( foreach($achievementGroups as $g){
$dbConnection, echo($g->asHtmlCard($_SESSION['user']['userId']));
$achievementGroups,
$_SESSION['user']['userId'],
getUsersAchievements($dbConnection, $_SESSION['user']['userId'])
));
}
?>
<?php
$usersKids = getUsersKids($dbConnection, $_SESSION['user']['userId']);
//var_dump($usersKids);
foreach($usersKids as $k){
if( hasUserAttribute($dbConnection, $k['kidId'], "inTraining" ) and ($k['kidId']!=$_SESSION['user']['userId']) ){
echo( "<h2>".$k['vorname']." ".$k['name']."</h2>" );
echo( htmlUsersUploadBox($dbConnection, $k['kidId']) );
echo(htmlAchievementListForUser(
$dbConnection,
$achievementGroups,
$k['kidId'],
getUsersAchievements($dbConnection, $k['kidId'])
));
}
} }
echo("</div>" );
}
?> ?>
<?php <?php // show the achievements of each kid
if(isUserAdmin($dbConnection, $_SESSION['user']['userId'])){ $usersKids = getUsersKids($dbConnection, $_SESSION['user']['userId']);
echo("<h2 id=\"addAchievementBox\">Add Achievements</h2>"); foreach($usersKids as $k){
echo(htmlAddAchievementBox()); if( hasUserAttribute($dbConnection, $k['kidId'], "inTraining" ) ){
echo( "<h2>".$k['vorname']." ".$k['name']."</h2>" );
echo("<h2>Update Achievements</h2>"); echo( "<div class=\"row\">");
$achievements = getAchievements($dbConnection); foreach($achievementGroups as $g){
foreach($achievements as $a){ echo($g->asHtmlCard($k['kidId'], ['noForm'=>false]));
echo( htmlUpdateAchievementBox( }
$a['id'], echo("</div>" );
$a['name'], }
$a['description'],
$a['rootId'],
$a['level']
));
echo("<hr />");
} }
} ?>
?> </body>
<span id="endOfUpdateAchievementBoxes" style="display:none;" ></span>
</body>
</html> </html>

View File

@@ -1,4 +1,6 @@
<?php <?php
require_once("lib/record.php");
// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben // Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
function htmlRetMessage($anRetMessage){ function htmlRetMessage($anRetMessage){
$retHtmlString = ""; $retHtmlString = "";
@@ -138,22 +140,29 @@ $html = "";
return $html; return $html;
} }
function htmlAchievementListForUser($db, $achievementGroups, $userId, $usersAchievmentIds){ function htmlAchievementListForUser($db, $achievementGroups, $userId, $usersAchievmentIds, $noForm=false){
//var_dump($db, $achievementGroups, $userId, $usersAchievmentIds); //var_dump($db, $achievementGroups, $userId, $usersAchievmentIds);
$ids=[]; $ids=[];
foreach($usersAchievmentIds as $a){ foreach($usersAchievmentIds as $a){
$ids[]=$a['achievementId']; $ids[]=$a['achievementId'];
} }
record::setDbConnection($db);
$userData = record::getUserData($userId);
$retHtml = ""; $retHtml = "";
if(!canUserGetAchievementToday( $db, $userId) ){ if(!canUserGetAchievementToday( $db, $userId) ){
$retHtml .= "<div>Heute wurde schon ein Achievement erreicht!</div>"; $retHtml .= "<div>Heute wurde schon ein Achievement erreicht!</div>";
} }
$retHtml .= "<div class=\"row\">"; $retHtml .= "<div class=\"row\">";
foreach($achievementGroups as $g){ foreach($achievementGroups as $g){
// var_dump($userData);
// $records = record::getGroupsRecords($g->getId(), $userData[0]['gebDatum ']);
// var_dump($userData);
$records = record::getGroupsRecords($g->getId(), record::birthday2ageClass($userData[0]['gebDatum']));
$retHtml .= "<div class=\"col s12 m6 l4 xl3\">"; $retHtml .= "<div class=\"col s12 m6 l4 xl3\">";
$retHtml .= "<ul class=\"card\">"; $retHtml .= "<ul class=\"card\">";
// see, if there is a record for this group
$imgUrl = null; $imgUrl = null;
foreach($g as $a){ foreach($g->achievements as $a){
if($a['imgUrl'] != null){ if($a['imgUrl'] != null){
$imgUrl = $a['imgUrl']; $imgUrl = $a['imgUrl'];
} }
@@ -164,13 +173,16 @@ $retHtml = "";
else{ else{
$retHtml .= "<li style=\"color:gray\">".$a['name'].": ".$a['description']; $retHtml .= "<li style=\"color:gray\">".$a['name'].": ".$a['description'];
//if(isUserAdmin($db, $_SESSION['user']['userId'])){ //if(isUserAdmin($db, $_SESSION['user']['userId'])){
if(canUserGetAchievementToday( $db, $userId) ){ if(!$noForm){
$retHtml .= "<form action=\".\" method=\"POST\">"; if( canUserGetAchievementToday( $db, $userId) or isUserAdmin($db, $_SESSION['user']['userId']) ){
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\">"; $retHtml .= "<form action=\".\" method=\"POST\">";
$retHtml .= "<input name=\"userId\" value=\"".$userId."\" type=\"hidden\">"; $retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\">";
$retHtml .= "<input name=\"achievementId\" value=\"".$a['id']."\" type=\"hidden\">"; $retHtml .= "<input name=\"redirectLocation\" value=\"./#achievementList-".$userId."\" type=\"hidden\">";
$retHtml .= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Achievement ".$a['name']." geben\">"; $retHtml .= "<input name=\"userId\" value=\"".$userId."\" type=\"hidden\">";
$retHtml .= "</form>"; $retHtml .= "<input name=\"achievementId\" value=\"".$a['id']."\" type=\"hidden\">";
$retHtml .= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Achievement ".$a['name']." geben\">";
$retHtml .= "</form>";
}
} }
if( $imgUrl != null ) if( $imgUrl != null )
$retHtml .= " <div class=\"card-image\" ><img src=\"".$imgUrl."\"/></div>"; $retHtml .= " <div class=\"card-image\" ><img src=\"".$imgUrl."\"/></div>";
@@ -178,6 +190,13 @@ $retHtml = "";
break; break;
} }
} }
// show the current record
if( validateDate($userData[0]['gebDatum'])){
$retHtml.=record::arrayRecord2htmlCard($records[0], $userData[0], $g->getId(), "li");
}
else{
$retHtml.="<div>Rekorde können erst angezeigt werden, wenn das <a href=./setUserData.php>Geburtsdatum korrekt gesetzt</a> wurde!</div>";
}
$retHtml .= "</ul>"; $retHtml .= "</ul>";
$retHtml .= "</div>"; $retHtml .= "</div>";
} }
@@ -185,42 +204,61 @@ $retHtml = "";
return $retHtml; return $retHtml;
} }
function getRecords($db, $groupId){
$query = <<<SQL
SELECT * FROM `machs_records`
WHERE `achievementGroupId` = :groupId;
SQL;
$params = [':groupId'=>['value'=>$groupId, 'data_type'=>PDO::PARAM_INT]];
return dbQuery($db, $query, $params);
}
function setUserDataBox($userId){
$html = "";
$html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"setBday\" />";
$html .= "<input name=\"userId\" type=\"hidden\" value=\"".$userId."\" />";
$html .= "<label for\"bday\">Geburtstag in der Form JJJJ-MM-TT</label>";
$html .= "<input name=\"bday\" type=\"text\" placeholder=\"JJJJ-MM-TT\"/>";
$html .= "<input type=\"submit\" value=\"Geburtsdatum neu setzen\"/>";
$html .= "</form>";
return $html;
}
function htmlAddAchievementBox(){ function htmlAddAchievementBox(){
$html = ""; $html = "";
$html .= "<form action=\".\" method=\"POST\">"; $html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"addAchievement\" />"; $html .= "<input name=\"action\" type=\"hidden\" value=\"addAchievement\" />";
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"#endOfUpdateAchievementBoxes\" />"; $html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
$html .= "<input name=\"name\" type=\"text\" placeholder=\"name\"/>"; $html .= "<input name=\"name\" type=\"text\" placeholder=\"name\"/>";
$html .= "<input name=\"rootId\" type=\"text\" placeholder=\"rootId\"/>";
$html .= "<input name=\"achievementGroupId\" type=\"text\" placeholder=\"achievementGroupId\"/>";
$html .= "<input name=\"level\" type=\"text\" placeholder=\"level\"/>";
$html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" placeholder=\"mdDescription\"/>"; $html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" placeholder=\"mdDescription\"/>";
$html .= "<input name=\"imgUrl\" type=\"text\" placeholder=\"imgUrl\"/>";
$html .= "<input type=\"submit\"/>"; $html .= "<input type=\"submit\"/>";
$html .= "</form>"; $html .= "</form>";
return $html; return $html;
} }
function htmlUpdateAchievementBox($achievementId, $name, $description, $rootId, $level){ function htmlUpdateAchievementBox($achievementId, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
$html = ""; $html = "";
$html .= "<form action=\".\" method=\"POST\">"; $html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"updateAchievement\" />"; $html .= "<input name=\"action\" type=\"hidden\" value=\"updateAchievement\" />";
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"#addAchievementBox\" />"; $html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
$html .= "<div > achievementId: ".$achievementId; $html .= "<div > achievementId: ".$achievementId;
$html .= "<input name=\"achievementId\" type=\"hidden\" value=\"".$achievementId."\"/>"; $html .= "<input name=\"achievementId\" type=\"hidden\" value=\"".$achievementId."\"/>";
$html .= "<div />"; $html .= "<div/>";
$html .= "<div >";
$html .= "<label for=\"name\">name</label>"; $html .= "<label for=\"name\">name</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"name\" type=\"text\" value=\"".$name."\"/>"; $html .= "<input style=\"width:100%;display:block;\" name=\"name\" type=\"text\" value=\"".$name."\"/>";
$html .= "<div/>";
$html .= "<div>";
$html .= "<label for=\"description\">description</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" value=\"".$description."\"/>";
$html .= "<div/>";
$html .= "<div>";
$html .= "<label for=\"rootId\">rootId</label>"; $html .= "<label for=\"rootId\">rootId</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"rootId\" type=\"text\" value=\"".$rootId."\"/>"; $html .= "<input style=\"width:100%;display:block;\" name=\"rootId\" type=\"text\" value=\"".$rootId."\"/>";
$html .= "<div/>"; $html .= "<label for=\"achievementGroupId\">achievementGroupId</label>";
$html .= "<div>"; $html .= "<input style=\"width:100%;display:block;\" name=\"achievementGroupId\" type=\"text\" value=\"".$achievementGroupId."\"/>";
$html .= "<label for=\"level\">level</label>"; $html .= "<label for=\"level\">level</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"level\" type=\"text\" value=\"".$level."\"/>"; $html .= "<input style=\"width:100%;display:block;\" name=\"level\" type=\"text\" value=\"".$level."\"/>";
$html .= "<div/>"; $html .= "<label for=\"description\">description</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" value=\"".$description."\"/>";
$html .= "<input type=\"submit\"/>"; $html .= "<input type=\"submit\"/>";
$html .= "</form>"; $html .= "</form>";
return $html; return $html;

View File

@@ -13,19 +13,79 @@ function processPostData($db, $post, $redirectLocation = "."){
addAchievement( addAchievement(
$db, $db,
$post['name'], $post['name'],
$post['description'] $post['rootId'],
$post['achievementGroupId'],
$post['level'],
$post['description'],
$post['imgUrl']
); );
} }
if($post['action']=="addAchievementGroup"){
addAchievementGroup(
$db,
$post['name'],
$post['rootId'],
$post['unlockingAchievementId'],
$post['imgUrl']
);
}
if($post['action']=="updateAchievement"){ if($post['action']=="updateAchievement"){
updateAchievement( updateAchievement(
$db, $db,
$post['achievementId'], $post['achievementId'],
$post['name'], $post['name'],
$post['rootId'],
$post['achievementGroupId'],
$post['level'],
$post['description'], $post['description'],
$post['rootId'], $post['imgUrl']
$post['level']
); );
} }
if($post['action']=="updateAchievementGroup"){
updateAchievement(
$db,
$post['achievementGroupId'],
$post['name'],
$post['rootId'],
$post['unlockingAchievementId'],
$post['imgUrl']
);
}
if($post['action']=="setBday"){
setBday(
$db,
$post['userId'],
$post['bday']
);
}
if($post['action']=="setRecord"){
# $u = getUserData($db, $post['userId']);
# $ag = new achievementGroup;
# achievementGroup::setDbConnection($db);
# $ag->loadAchievementGroupFromDb($post['achievementGroupId']);
# $m = $u['vorname']." ".$u['name']." hat in ".$ag->getName()." ".$post['value']." geschafft!";
$m = $post['userId']." hat in ".$post['achievementGroupId']." ".$post['value']." geschafft!";
sendEmail("cwsvjudo@arcor.de", $m, "[machs] Rekord eingetragen");
# setRecord(
# $db,
# $post['userId'],
# $post['achievementGroupId'],
# $post['value']
# );
}
if($post['action']=="reportRecord"){
# $u = getUserData($db, $post['userId']);
# $ag = new achievementGroup;
# achievementGroup::setDbConnection($db);
# $ag->loadAchievementGroupFromDb($post['achievementGroupId']);
$m = $post['userId']." hat in ".$post['achievementGroupId']." ".$post['value']." geschafft!";
# $m = $u['vorname']." ".$u['name']." hat in ".$ag->getName()." ".$post['value']." geschafft!";
sendEmail("cwsvjudo@arcor.de", $m, "[machs] Rekordmeldung");
}
if($post['redirectLocation']) if($post['redirectLocation'])
$redirectLocation = $post['redirectLocation']; $redirectLocation = $post['redirectLocation'];
header("Location: ".$redirectLocation); header("Location: ".$redirectLocation);

View File

@@ -246,6 +246,7 @@ SQL;
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT], 'achievementId'=>['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT]]; $params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT], 'achievementId'=>['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT]];
dbQuery($db, $query, $params); dbQuery($db, $query, $params);
sendEmail("cwsvjudo@arcor.de", "kwT", "User ".$userId." got achievement ".$achievementId); sendEmail("cwsvjudo@arcor.de", "kwT", "User ".$userId." got achievement ".$achievementId);
//var_dump($query, $params);
return; return;
} }
@@ -281,41 +282,126 @@ SQL;
return dbQuery($db, $query); return dbQuery($db, $query);
} }
function addAchievement($db, $name, $description){ function addAchievement($db, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
if($rootId=="")
$rootId=null;
if($imgUrl=="")
$imgUrl=null;
$query = <<<SQL $query = <<<SQL
INSERT INTO `cwsvjudo`.`achievements` (name, description) INSERT INTO `cwsvjudo`.`achievements` (name, rootId, achievementGroupId, level, description, imgUrl)
VALUES (:name, :description); VALUES (:name, :rootId, :achievementGroupId, :level, :description, :imgUrl);
SQL; SQL;
$params=[ $params=[
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR], ':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
':rootId' => ['value'=>$rootId, 'data_type'=>PDO::PARAM_INT],
':achievementGroupId' => ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
':level' => ['value'=>$level, 'data_type'=>PDO::PARAM_INT],
':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR], ':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR],
':imgUrl' => ['value'=>$imgUrl, 'data_type'=>PDO::PARAM_STR],
]; ];
dbQuery($db, $query, $params, ['dontFetch'=>true]); dbQuery($db, $query, $params, ['dontFetch'=>true]);
return; return;
} }
function updateAchievement($db, $achievementId, $name, $description, $rootId, $level){ function addAchievementGroup($db, $name, $unlockingAchievementId, $imgUrl){
if($unlockingAchievementId=="")
$unlockingAchievementId=null;
if($imgUrl=="")
$imgUrl=null;
$query = <<<SQL
INSERT INTO `cwsvjudo`.`machs_achievementGroups` (name, unlockingAchievementId, imgUrl)
VALUES (:name, :unlockingAchievementId, :imgUrl);
SQL;
$params=[
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
':unlockingAchievementId' => ['value'=>$unlockingAchievementId, 'data_type'=>PDO::PARAM_INT],
':imgUrl' => ['value'=>$imgUrl, 'data_type'=>PDO::PARAM_STR],
];
dbQuery($db, $query, $params, ['dontFetch'=>true]);
return;
}
function updateAchievement($db, $achievementId, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
if($rootId=="")
$rootId=null;
if($imgUrl=="")
$imgUrl=null;
$query = <<<SQL $query = <<<SQL
UPDATE `cwsvjudo`.`achievements` UPDATE `cwsvjudo`.`achievements`
SET name=:name, description=:description, rootId=:rootId, level=:level SET name=:name, rootId=:rootId, achievementGroupId=:achievementGroupId, level=:level, description=:description, imgUrl:=imgUrl
WHERE `id`=:achievementId; WHERE `id`=:achievementId;
SQL; SQL;
$params=[ $params=[
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR], ':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR], ':achievementGroupId' => ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
':rootId' => ['value'=>$rootId, 'data_type'=>PDO::PARAM_INT], ':rootId' => ['value'=>$rootId, 'data_type'=>PDO::PARAM_INT],
':level' => ['value'=>$level, 'data_type'=>PDO::PARAM_INT], ':level' => ['value'=>$level, 'data_type'=>PDO::PARAM_INT],
':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR],
':imgUrl' => ['value'=>$imgUrl, 'data_type'=>PDO::PARAM_STR],
':achievementId' => ['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT], ':achievementId' => ['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT],
]; ];
dbQuery($db, $query, $params, ['dontFetch'=>true]); dbQuery($db, $query, $params, ['dontFetch'=>true]);
return; return;
} }
function updateAchievementGroup($db, $achievementGroupId, $name, $unlockingAchievementId, $imgUrl){
if($unlockingAchievementId=="")
$unlockingAchievementId=null;
if($imgUrl=="")
$imgUrl=null;
$query = <<<SQL
UPDATE `cwsvjudo`.`machs_achievementGroups`
SET name=:name, rootId=:rootId, achievementGroupId=:achievementGroupId, level=:level, description=:description, imgUrl:=imgUrl
WHERE `id`=:achievementGroupId;
SQL;
$params=[
':achievementGroupId' => ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
':unlockingAchievementId' => ['value'=>$unlockingAchievementId, 'data_type'=>PDO::PARAM_INT],
':imgUrl' => ['value'=>$imgUrl, 'data_type'=>PDO::PARAM_STR],
];
dbQuery($db, $query, $params, ['dontFetch'=>true]);
return;
}
function setBday($db, $userId, $bday){
$query = <<<SQL
UPDATE `cwsvjudo`.`wkParticipo_Users`
SET gebDatum=:bday
WHERE `id`=:userId;
SQL;
$params=[
':bday' => ['value'=>$bday, 'data_type'=>PDO::PARAM_STR],
':userId' => ['value'=>$userId, 'data_type'=>PDO::PARAM_INT]
];
dbQuery($db, $query, $params, ['dontFetch'=>true]);
return;
}
function setRecord($db, $userId, $achievementGroupId, $value){
$u = getUserData($db, $userId);
$query = <<<SQL
INSERT `cwsvjudo`.`machs_records`
SET achievementGroupId=:achievementGroupId, ageClass=:ageClass, userId=:userId, value=:value
SQL;
$params=[
':achievementGroupId' => ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
':ageClass' => ['value'=>record::birthday2ageClass($u['gebDatum']), 'data_type'=>PDO::PARAM_INT],
':userId' => ['value'=>$userId, 'data_type'=>PDO::PARAM_INT],
':value' => ['value'=>$value, 'data_type'=>PDO::PARAM_INT],
];
dbQuery($db, $query, $params, ['dontFetch'=>true]);
//var_dump($userId, $achievementGroupId, $value);
//var_dump($query, $params);
return;
}
function canUserGetAchievementToday($db, $userId){ function canUserGetAchievementToday($db, $userId){
$achievements = getUsersAchievements($db, $userId); $achievements = getUsersAchievements($db, $userId);
foreach($achievements as $a){ foreach($achievements as $a){
if( date('Ymd') == date('Ymd', strtotime($a['timestamp'])) ) if( date('Ymd') == date('Ymd', strtotime($a['timestamp'])) ){
return false; return false;
}
} }
return true; return true;
} }

View File

@@ -0,0 +1,232 @@
<?php
require_once('./lib/db.php');
// A series of achievements
class achievementGroup{
private $id;
private $name;
private $unlockingAchievementId;
private $imageUrl;
private $achievements;
private static $db=null;
// private static $tableName = "`cwsvjudo`.`machs_achievementGroups`";
static function setDbConnection($dbConnection){
if($dbConnection instanceof PDO)
self::$db = $dbConnection;
else
self::$db = null;
return;
}
static function getDbConnection(){
return self::$db;
}
/// Returns an array of all Achievementgroups
static function getAllAchievementGroups(){
$query = <<<SQL
SELECT * FROM `cwsvjudo`.`machs_achievementGroups`;
SQL;
$result = dbQuery(self::$db, $query);
$groups = [];
foreach($result as $r){
$gid = (int)$r['id'];
$groups[$gid] = new achievementGroup;
$groups[$gid]->setAchievementGroupData(
$r['id'],
$r['name'],
$r['unlockingAchievementId'],
$r['imageUrl']
);
$groups[$gid]->getAchievements(['force'=>true]);
}
return $groups;
}
//getter functions for the member variables
function getId(){return $this->id;}
function getName(){return $this->name;}
function getUnlockingAchievementId(){return $this->unlockingAchievementId;}
function getImageUrl(){return $this->imageUrl;}
/// returns list of achievements
/// - returns the previously loaded achievements
/// - reloads them if null or forced
function getAchievements($options=[]){
// standards for Options:
$force = $options['force']??false; // load the achievements from the db even if ther already are some in the group->achievements member
if(($this->achievements == null) or ($force)){
$query = <<<SQL
SELECT * FROM `achievements`
WHERE `achievementGroupId`=:groupId;
SQL;
$params = [':groupId'=>['value'=>$this->id, 'data_type'=>PDO::PARAM_INT]];
$this->achievements = dbQuery(self::$db, $query, $params);
}
return $this->achievements;
} // end getAchievements
/// Load the achievementgroup $id from the db into the
function loadAchievementGroupFromDb($id){
$query = <<<SQL
SELECT * FROM `cwsvjudo`.`machs_achievementGroups` WHERE `id` = :id;
SQL;
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
$result = dbQuery(self::$db, $query, $param);
$this->setAchievementGroupData(
$result[0]['id'],
$result[0]['name'],
$result[0]['unlockingAchievementId'],
$result[0]['imageUrl']
);
$this->getAchievements(['force'=>true]);
}
/// Set the member data of the group
function setAchievementGroupData($id, $name, $unlockingAchievementId=null, $imageUrl=null){
$this->id = (int)$id;
$this->name = $name;
$this->unlockingAchievementId = ($unlockingAchievementId == null ? null : (int)$unlockingAchievementId);
$this->imageUrl = $imageUrl;
}
/// A simple representation of the group in html code
function html(){
$html = "";
$html .= "<div>";
$html .= "<dl>";
$html .= "<dt>Id: </dt><dd>".$this->id."</dd>";
$html .= "<dt>name: </dt><dd>".$this->name."</dd>";
$html .= "<dt>unlockingAchievementId: </dt><dd>".$this->unlockingAchievementId."</dd>";
$html .= "<dt>Achievements: </dt><dd><ul>";
foreach($this->achievements as $a)
$html .= "<li>".$a['name']."</li>";
$html .= "</ul></dd>";
$html .= "</dl>";
$html .= "</div>";
return $html;
}
/// gets all achievements of that user in that group reachedd
function getUsersAchievements($userId, $options=[]){
$getAll = $options['getAll']??false;
$query = "";
$query.= "SELECT * FROM `cwsvjudo`.`achievements<=>user` ";
$query.= "WHERE `userId` = :userId";
if(!$getAll)
$query.=" AND `achievementId` = :achievementId";
$query.= ";";
$params[':userId'] = array('value'=>$userId, 'data_type'=>PDO::PARAM_INT);
if(!$getAll)
$params[':achievementId'] = array('value'=>$this->getId(), 'data_type'=>PDO::PARAM_INT);
$result = dbQuery($this->getDbConnection(), $query, $params);
return $result;
}
/// returns the materialize card html code of the Achievementgroup
///
/// @param $uId id of the user the achievements should be
function asHtmlCard($uId, $options=[]){
$noForm = $options['noForm']??true;
$retHtml = "";
$userData = record::getUserData($uId);
$usersAchievements = $this->getUsersAchievements( $uId, ['getAll'=>true] );
$usersAchievementIds=[null];
foreach($usersAchievements as $a){
$usersAchievementIds[]=(int)$a['achievementId'];
}
if(!in_array($this->getUnlockingAchievementId(), $usersAchievementIds))
return "";
$records = record::getGroupsRecords(
$this->getId(),
record::birthday2ageClass($userData[0]['gebDatum'])
);
$achievements = $this->getAchievements();
$retHtml .= "<div class=\"col s12 m6 l4 xl3\">";
$retHtml .= "<div class=\"card\">";
$retHtml .= "<div class=\"card-content\">";
if($this->imageUrl != null){
$retHtml .= "<div class=\"card-image\"><img src=\"".$this->imageUrl."\">";
}
$retHtml .= "<span class=\"card-title\">".$this->name."</span>";
if($this->imageUrl != null){
$retHtml .= "</div>";
}
$retHtml .= "<ul>";
foreach($achievements as $a){
if(in_array((int)$a['id'], $usersAchievementIds)){
$retHtml .= "<li>&#10003; ".$a['name'].": ".$a['description'];
$retHtml .= "</li>";
}
else{
$retHtml .= "<li style=\"color:gray\">".$a['name'].": ".$a['description'];
if(!$noForm){
if( canUserGetAchievementToday( $this->getDbConnection(), $uId) or isUserAdmin($this->getDbConnection(), $_SESSION['user']['userId']) ){
$retHtml .= "<form action=\".\" method=\"POST\">";
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\">";
$retHtml .= "<input name=\"redirectLocation\" value=\"./#achievementList-".$uId."\" type=\"hidden\">";
$retHtml .= "<input name=\"userId\" value=\"".$uId."\" type=\"hidden\">";
$retHtml .= "<input name=\"achievementId\" value=\"".$a['id']."\" type=\"hidden\">";
$retHtml .= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Achievement ".$a['name']." geben\">";
$retHtml .= "</form>";
}
}
if( $imgUrl != null )
$retHtml .= " <div class=\"card-image\" ><img src=\"".$imgUrl."\"/></div>";
$retHtml .= "</li>";
break;
}
}
// show the current record
if( validateDate($userData[0]['gebDatum'])){
$retHtml.=record::arrayRecord2htmlCard($records[0], $userData[0], $this->getId(), "li");
}
else{
$retHtml.="<div>Rekorde können erst angezeigt werden, wenn das <a href=./setUserData.php>Geburtsdatum korrekt gesetzt</a> wurde!</div>";
}
$retHtml .= "</ul>";
$retHtml .= "</div>";
$retHtml .= "</div>";
$retHtml .= "</div>";
return $retHtml;
}// end asHtmlCard
/// create html code for a for to add an achievementGroup
static function htmlAddAchievementGroupForm(){
$html = "";
$html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"addAchievementGroup\" />";
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
$html .= "<input name=\"name\" type=\"text\" placeholder=\"name\"/>";
$html .= "<input name=\"unlockingAchievementId\" type=\"text\" placeholder=\"unlockingAchievementId\"/>";
$html .= "<input name=\"imageUrl\" type=\"text\" placeholder=\"imageUrl\"/>";
$html .= "<input type=\"submit\"/>";
$html .= "</form>";
return $html;
}
/// create html code for a for to edit an achievementGroup
function htmlEditAchievementGroupForm(){
$html = "";
$html .= "Edit ".$this->getName();
$html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"editAchievementGroup\" />";
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
$html .= "<input name=\"id\" type=\"hidden\" value=\"".$this->getId()."\"/>";
$html .= "<label for\"name\">name</label>";
$html .= "<input name=\"name\" type=\"text\" value=\"".$this->getName()."\"/>";
$html .= "<label for\"name\">unlockingAchievementId</label>";
$html .= "<input name=\"unlockingAchievementId\" type=\"text\" value=\"".$this->getUnlockingAchievementId()."\"/>";
$html .= "<label for\"name\">imageUrl</label>";
$html .= "<input name=\"imageUrl\" type=\"text\" value=\"".$this->getImageUrl()."\"/>";
$html .= "<input type=\"submit\"/>";
$html .= "</form>";
return $html;
}
}
?>

View File

@@ -0,0 +1,14 @@
<!--
Some Inits for the materializeCss
-->
<script>
options={};
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.modal');
var instances = M.Modal.init(elems, options);
});
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems, options);
});
</script>

View File

@@ -0,0 +1,13 @@
<!-- sidenav -->
<ul id="slide-out" class="sidenav">
<li><?php echo $login_status;?></li>
<li><a href=".">Achievements</a></li>
<li><a href="./setUserData.php">Benutzerdaten</a></li>
<?php
if(isUserAdmin($dbConnection, $_SESSION['user']['userId'])){
echo("<li><a href=\"./achievementBuilder.php\">achievementBuilder</a></li>");
}
?>
</ul>
<a href="#" data-target="slide-out" class="sidenav-trigger show-on-large" style="font-size: 2em;">&#9776; M<small>ein</small>ACH<small>ievement</small>S<small>ystem</small></a>
<!-- end sidenav -->

View File

@@ -0,0 +1,221 @@
<?php
require_once('./lib/db.php');
class record{
//< id of the record in the db
private $id;
//< id of current holder in the db
private $userId;
//< the age class the record is for
private $ageClass;
//< when the record was established
private $timestap;
//< what the record is about
private $description;
//< the value to beat
private $value;
//< the achievement needed for the record
private $unlockingAchievement;
private static $db;
/// Names of the columns in the db
private static $colNames = ['id', 'achievementGroupId', 'ageClass', 'userId', 'timestamp', 'value', 'description'];
public static function setDbConnection($dbConnection){
if($dbConnection instanceof PDO)
self::$db = $dbConnection;
else
self::$db = null;
return;
}
public static function getAllRecords(){
$query = <<<SQL
SELECT * FROM `cwsvjudo`.`machs_records`;
SQL;
return dbQuery(self::$db, $query);
}
public static function getUserData($userId){
$query = <<<SQL
SELECT * FROM `cwsvjudo`.`wkParticipo_Users`
WHERE `cwsvjudo`.`wkParticipo_Users`.`id` = :userId ;
SQL;
return dbQuery(self::$db, $query, ['userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]]);
}
// request the records of a group together with its holder
// @param $groupId id of the group of achievements where the records are wanted
// @param $ageClass the age class (as int only) for which the record is holding
//
// a record of an achievement group consists of:
// - a value
// - an age class
public static function getGroupsRecords($groupId, $ageClass=null){
// var_dump($groupId, $ageClass);
//$ageClass = null; // DEBUG
$query = "SELECT * FROM `cwsvjudo`.`machs_records` ";
$query.= "JOIN `cwsvjudo`.`wkParticipo_Users` ";
$query.= " ON `cwsvjudo`.`machs_records`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id` ";
$query.= "WHERE `cwsvjudo`.`machs_records`.`achievementGroupId` = :groupId ";
$params =[
'groupId'=>[ 'value'=>$groupId, 'data_type'=>PDO::PARAM_INT ]
];
if($ageClass != null){
$query.= " AND `cwsvjudo`.`machs_records`.`ageClass` <= :ageClass ";
$params['ageClass'] = [ 'value'=>$ageClass, 'data_type'=>PDO::PARAM_INT ];
}
$query.= "ORDER BY `cwsvjudo`.`machs_records`.`value`;";
//var_dump($query, $params);
return dbQuery(self::$db, $query, $params);
}
/// @param $r record as associative array
public static function arrayRecord2htmlDl($r){
$retHtml = "<dl>";
foreach(self::$colNames as $i)
$retHtml.= "<dt>".$i."</dt><dd>".$r[$i]."</dd>";
$retHtml.= "</dl>";
return $retHtml;
}
/// @param $r record joined with it's holder as associative error
/// @param $u user for whom the record is shown
public static function arrayRecord2htmlCard($r, $u, $gid, $frameTag="div"){
$retHtml = "<".$frameTag." class=\"card\">";
$retHtml.= "<div class=\"card-content\">";
$retHtml.= "<span class=\"card-title\">Zu schlagender Rekord</span>";
if(empty($r)){
$retHtml.= "Noch kein Rekord für die Altersklasse U".record::birthday2ageClass($u['gebDatum']);
}
else{
$retHtml.= $r['vorname']." ".$r['name']." mit ".$r['value']." in der U".$r['ageClass'];
}
$retHtml.= "</div>";
$retHtml.= "<div class=\"card-action\">";
$retHtml.= "<a class=\"waves-effect waves-light btn modal-trigger\" href=\"#reportRecord-user-".$u['id']."-group-".$gid."\">Rekord melden</a>";
$retHtml.= "<div id=\"reportRecord-user-".$u['id']."-group-".$gid."\" class=\"modal\">";
$retHtml.= "<div class=\"modal-content\">";
$retHtml.= "Rekorde stellen in jeder Achievementgruppe und Altersklasse die Bestleistung unter allen Judoka dar. Rekorde können unabhänging vom eigenen, aktuellen Achievementstand aufgestellt werden.";
$retHtml.= "Die Rekorde der jüngeren gelten auch für die älteren, aber nicht umgekehrt. ";
$retHtml.= "Damit ein Rekord auch eingetragen wird, muss er mit einem Nachweis in Videoform gemeldet werden.";
$retHtml.= "<h4>Rekord melden</h4>";
$retHtml.= "Um einen Rekord zu melden, lade ein Video des Rekordes hoch:";
$retHtml.= htmlUsersUploadBox(self::$db, $u['id']);
$retHtml.= "Anschließend kannst Du den Rekord melden:";
$retHtml.= "<form action=\".\" method=\"POST\">";
if(isUserAdmin(record::$db, $_SESSION['user']['userId'])){
$retHtml.= "<input name=\"action\" value=\"setRecord\" type=\"hidden\">";
}
else{
$retHtml.= "<input name=\"action\" value=\"reportRecord\" type=\"hidden\">";
}
$retHtml.= "<input name=\"userId\" value=\"".$u['id']."\" type=\"hidden\">";
$retHtml.= "<input name=\"achievementGroupId\" value=\"".$gid."\" type=\"hidden\">";
$retHtml.= $u['vorname']." ".$u['name']." hat <input name=\"value\" placeholder=\"Zeit/Anzahl\"> geschafft.";
if(isUserAdmin(record::$db, $_SESSION['user']['userId'])){
$retHtml.= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord eintragen\">";
}
else{
$retHtml.= "<input style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord melden\">";
}
$retHtml.= "</form>";
$retHtml.= "</div>";
$retHtml.= "<div class=\"modal-footer\">";
$retHtml.= "<a href=\"#!\" class=\"modal-close waves-effect waves-green btn-flat\">Zurück</a>";
$retHtml.= "</div>";
$retHtml.= "</div>";
$retHtml.= "</div>";
$retHtml.= "</".$frameTag.">";
return $retHtml;
}
public static function birthday2ageClass($birthdateString){
$birthDate = DateTime::createFromFormat("Y-m-d", $birthdateString);
$birthYear= (int)$birthDate->format("Y");
$thisYear = (int)date('Y');
return $thisYear - $birthYear + 1;
}
}
/// Als String gegebene Altersklassen als Jahrgangsintervalle
/// ausdrücken
function akListString2jgArray($akListString, $year = NULL ){
$ret = array();
if($year==NULL)
$year=date("Y");
else{
if( !((int)$year == $year && (int)$year >= 0) )
$year=date("Y");
}
$year = (int)$year;
foreach(explode(" ", $akListString) as $ak)
array_push(
$ret,
akString2jgIntervall($ak, $year)
);
return $ret;
}
/// Aus einer als String gegebenen Altersklasse ein Jahrgangsintervall
/// machen
function akString2jgIntervall($akString, $year=null){
if($year==NULL)
$year=date("Y");
else{
if( !((int)$year == $year && (int)$year >= 0) )
$year=date("Y");
}
$ret= array(NULL, NULL);
// Speziell für die Ux-Altersklassen
// Es fehlt noch das <=U
$akUmatchString = "/(.*)U(.*)/";
$matches = array();
preg_match($akUmatchString, $akString, $matches);
// Wenn wir nicht den gesamten akString Matchen ist etwas schief
// gelaufen
if($matches[0]==$akString){
// Das ausgelesene Alter der Ux sollte eine positive Integer sein,
// sonst ist was schiefgelaufen
$ageLimit = (int)$matches[2];
if( ($ageLimit == $matches[2] && $ageLimit > 0) ){
$ret[0] = $year-$ageLimit+1;
if($matches[1] == "")
$ret[1] = $year-$ageLimit+2;
else{
if($matches[1] == "-")
$ret[1] = $year-$ageLimit+3;
else{
if($matches[1] == "--")
$ret[1] = $year-$ageLimit+4;
}
}
}
return $ret;
}
// Speziell Altersklassen der Form Jg.x-y
$akUmatchString = "/Jg\.(.*)\-(.*)/";
$matches = array();
preg_match($akUmatchString, $akString, $matches);
// Wenn wir nicht den gesamten akString Matchen ist etwas schief
// gelaufen
if($matches[0]==$akString){
$ret[0]=(int)$matches[1];
$ret[1]=(int)$matches[2];
return $ret;
}
return $ret;
}
function validateDate($date, $format = 'Y-m-d')
{
$d = DateTime::createFromFormat($format, $date);
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
return $d && $d->format($format) === $date;
}
?>

View File

@@ -8,6 +8,11 @@ setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("./lib/achievementsLib.php"); require_once("./lib/achievementsLib.php");
$basePath = "/users/cwsvjudo/www";
require_once($basePath."/config/phpcount.config.php");
require_once($basePath."/ressourcen/phpLib/phpcount/phpcount.php");
function checkCredentials($username, $password, $db_server, $db_user, $db_password, $db_name){ function checkCredentials($username, $password, $db_server, $db_user, $db_password, $db_name){
$mysqli = @new mysqli($db_server, $db_user, $db_password, $db_name); $mysqli = @new mysqli($db_server, $db_user, $db_password, $db_name);
if ($mysqli->connect_error) { if ($mysqli->connect_error) {
@@ -30,6 +35,7 @@ function checkCredentials($username, $password, $db_server, $db_user, $db_passwo
), ),
); );
$message['success'] = 'Anmeldung erfolgreich, <a href="index.php">weiter zum Inhalt</a>.'; $message['success'] = 'Anmeldung erfolgreich, <a href="index.php">weiter zum Inhalt</a>.';
PHPCount::AddHit("machs-Login ".$_POST['f']['username']);
header('Location: http://' . $_SERVER['HTTP_HOST'] . '/machs?user=' . $_POST['f']['username']); header('Location: http://' . $_SERVER['HTTP_HOST'] . '/machs?user=' . $_POST['f']['username']);
} else { } else {
sleep(1); sleep(1);
@@ -59,21 +65,27 @@ else{
} }
} }
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>Wettkampfplanung - Login</title> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- Materialize: Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Materialize: Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<title>Login des Achievementsystemes der Judoka des Chemnitzer WSV</title>
<meta name="description" content="Loginseite des Achievementsystemes der Judoka des CWSV"> <meta name="description" content="Loginseite des Achievementsystemes der Judoka des CWSV">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head> </head>
<body> <body class="container">
<h1>Achievementsystem der Judoka des Chemnitzer WSV</h1> <h1>Achievementsystem der Judoka des Chemnitzer WSV</h1>
<?php echo(htmlRetMessage($message));?> <?php echo(htmlRetMessage($message));?>
<form class="loginForm" action="./login.php" method="post"> <form action="./login.php" method="post">
<fieldset> <fieldset>
<legend>Benutzerdaten</legend> <legend>Benutzerdaten</legend>
<div> <div>
@@ -91,9 +103,9 @@ else{
</div> </div>
</fieldset> </fieldset>
<fieldset class="notice"><legend>Hinweise</legend> <fieldset class="notice"><legend>Hinweise</legend>
<ul> <ul style="padding-left: inherit;">
<li>Logindaten sind über den Übungsleiter zu beantragen.</li> <li style="list-style-type: circle;" >Logindaten sind über den Übungsleiter zu beantragen.</li>
<li>Dieses Projekt ist in mehr oder weniger aktiven Entwicklung. Sollte mal was nicht funktionieren, kann es sein, dass ich gerade daran herumschreibe. Also ruhig zu einem späteren Zeitpunkt noch einmal probieren.</li> <li style="list-style-type: circle;" >Dieses Projekt ist in mehr oder weniger aktiven Entwicklung. Sollte mal was nicht funktionieren, kann es sein, dass ich gerade daran herumschreibe. Also ruhig zu einem späteren Zeitpunkt noch einmal probieren.</li>
</ul> </ul>
</fieldset> </fieldset>
</form> </form>

View File

@@ -0,0 +1,76 @@
<?php
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("config.php");
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("./lib/record.php");
require_once("./lib/machs/achievementGroup.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");
PHPCount::AddHit("Achievementsystem setUserData(".htmlspecialchars($_SESSION['user']['username']).")");
// require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
// $dbConnection = getCwsvJudoDbConn();
$dbConnection = getPdoDbConnection(
$cwsvJudoConfig["db"]["host"],
$cwsvJudoConfig["db"]["name"],
$cwsvJudoConfig["db"]["user"],
$cwsvJudoConfig["db"]["password"]
);
achievementGroup::setDbConnection($dbConnection);
$achievementGroups = achievementGroup::getAllAchievementGroups();
processPostData($dbConnection, $_POST);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<!-- 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>
<!-- inits for the materializeCss -->
<?php include("lib/machs/materializeInit.php");?>
<title>Benutzerdaten ändern</title>
<meta name="description" content="Benutzerdaten ändern">
<link rel="icon" href="<?echo($config['ressourceUrl']);?>/graphiken/icons/cwsv.ico" />
<link rel="apple-touch-icon" href="<?echo($config['baseUrl']);?>/apple-touch-icon.png">
</head>
<body>
<!-- sidenav -->
<?php include("lib/machs/sidenav.php");?>
<!-- end sidenav -->
<h1>Benutzerdaten ändern</h1>
<?php
$usersKids = getUsersKids($dbConnection, $_SESSION['user']['userId']);
foreach($usersKids as $k){
if( hasUserAttribute($dbConnection, $k['kidId'], "inTraining" ) ){
echo( "<h2 >".$k['vorname']." ".$k['name']."</h2>" );
echo( htmlUsersUploadBox($dbConnection, $_SESSION['user']['userId']) );
echo( setUserDataBox($k['kidId']) );
}
}
?>
</body>
</html>