- Records page introduced

- rearangements in the include structure
This commit is contained in:
marko
2020-11-19 12:53:28 +01:00
parent a0ef0bf40c
commit de24498f77
15 changed files with 433 additions and 365 deletions

View File

@@ -1,43 +1,23 @@
<?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('machs.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");
PHPCount::AddHit("Achievementbuilder (".htmlspecialchars($_SESSION['user']['username']).")");
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"]
);
$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>
@@ -75,6 +55,9 @@ processPostData($dbConnection, $_POST);
echo($g->htmlEditAchievementGroupForm());
$achievements = $g->getAchievements();
if(empty($achievements)){
echo("<h4>Auto Add Achievements</h4>".achievementGroup::htmlAutoAddAchievementsForm($g->getId()));
}
foreach($achievements as $a){
echo("<h4>".$a['name']."</h4>");
echo(htmlUpdateAchievementBox(

View File

@@ -1,7 +1,7 @@
<?php
/// @file some variable definitions
$config['basePath'] = "/users/cwsvjudo/www";
$config['baseUrl'] = "http://cwsvjudo.bplaced.net";
$config['ressourceUrl'] = "http://cwsvjudo.bplaced.net/ressourcen";

View File

@@ -1,39 +1,20 @@
<?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('machs.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");
PHPCount::AddHit("Achievementsystem (".htmlspecialchars($_SESSION['user']['username']).")");
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"]
);
$dbConnection = getPdoDbConnection(
$cwsvJudoConfig["db"]["host"],
$cwsvJudoConfig["db"]["name"],
$cwsvJudoConfig["db"]["user"],
$cwsvJudoConfig["db"]["password"]
);
record::setDbConnection($dbConnection);
achievementGroup::setDbConnection($dbConnection);
$achievementGroups = achievementGroup::getAllAchievementGroups();
processPostData($dbConnection, $_POST);
?>
<!DOCTYPE html>
<html>
@@ -63,9 +44,8 @@ processPostData($dbConnection, $_POST);
<?php // show own achievements, if oneself is inTraining
if( hasUserAttribute($dbConnection, $_SESSION['user']['userId'], "inTraining" ) ){
echo( "<div class=\"row\">");
echo( "<h2>Eigene Achievements</h2>" );
# var_dump($achievementGroups);
echo( "<div style=\"display:flex; flex-wrap:wrap; align-items:stretch;\" class=\"row\">");
foreach($achievementGroups as $g){
echo($g->asHtmlCard($_SESSION['user']['userId']));
}
@@ -78,7 +58,7 @@ processPostData($dbConnection, $_POST);
foreach($usersKids as $k){
if( hasUserAttribute($dbConnection, $k['kidId'], "inTraining" ) ){
echo( "<h2>".$k['vorname']." ".$k['name']."</h2>" );
echo( "<div class=\"row\">");
echo( "<div style=\"display:flex; flex-wrap:wrap; align-items:stretch;\" class=\"row\">");
foreach($achievementGroups as $g){
echo($g->asHtmlCard($k['kidId'], ['noForm'=>false]));
}

View File

@@ -8,6 +8,13 @@ function processPostData($db, $post, $redirectLocation = "."){
$post['userId'],
$post['achievementId']
);
$u = getUserData($db, $post['userId']);
$a = getAchievement($db, $post['achievementId']);
sendEmail(
"cwsvjudo@arcor.de",
"kwT",
$u['vorname']." ".$u['name']." got achievement ".$a[0]['name']
);
}
if($post['action']=="addAchievement"){
addAchievement(
@@ -31,6 +38,18 @@ function processPostData($db, $post, $redirectLocation = "."){
);
}
if($post['action']=="autoAddAchievements"){
$g=new achievementGroup;
$g->setDbConnection($db);
$g->loadAchievementGroupFromDb($post['achievementGroupId']);
$g->autoAddAchievements(
$post['messageTemplate'],
$post['from'],
$post['to'],
$post['step']
);
}
if($post['action']=="updateAchievement"){
updateAchievement(
$db,
@@ -63,19 +82,21 @@ function processPostData($db, $post, $redirectLocation = "."){
);
}
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']
# );
$u = getUserData($db, $post['userId']);
$g = new achievementGroup;
$g->setDbConnection($db);
$g->loadAchievementGroupFromDb($post['achievementGroupId']);
sendEmail(
"cwsvjudo@arcor.de",
$u['vorname']." ".$u['name']." got ".$post['value']." in ".$g->getName(),
"[machs] Rekord eingetragen"
);
//setRecord(
//$db,
//$post['userId'],
//$post['achievementGroupId'],
//$post['value']
//);
}
if($post['action']=="reportRecord"){
# $u = getUserData($db, $post['userId']);

View File

@@ -64,6 +64,8 @@ if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
if(!$pdoResult){
echo("Error during dbQuery!\n");
echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo());
// var_dump($aQueryString);
// var_dump($aBindArray);
// echo($pdoStatement.errorInfo());
}
if($someOptions['dontFetch']){
@@ -245,8 +247,6 @@ INSERT INTO `cwsvjudo`.`achievements<=>user` (`userId`, `achievementId`) VALUE (
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);
//var_dump($query, $params);
return;
}
@@ -282,7 +282,18 @@ SQL;
return dbQuery($db, $query);
}
function getAchievement($db, $id){
$query = <<<SQL
SELECT *
FROM `cwsvjudo`.`achievements`
WHERE `id`=:id;
SQL;
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
return dbQuery($db, $query, $params);
}
function addAchievement($db, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
// var_dump($db);
if($rootId=="")
$rootId=null;
if($imgUrl=="")

View File

@@ -4,24 +4,34 @@ require_once('./lib/db.php');
// A series of achievements
class achievementGroup{
// data from the achievements group table
// id of the group
private $id;
// name of the group
private $name;
// Achievement, that unlocks the group
private $unlockingAchievementId;
// an image for the group
private $imageUrl;
// achievements, that belong to this group
private $achievements;
// pointer to the db that shall be used for queries
private static $db=null;
// name of the table
// private static $tableName = "`cwsvjudo`.`machs_achievementGroups`";
static function setDbConnection($dbConnection){
// set the dbConnection (just setting, no establishing)
public static function setDbConnection($dbConnection){
if($dbConnection instanceof PDO)
self::$db = $dbConnection;
else
self::$db = null;
return;
}
static function getDbConnection(){
// get the db pointer
public static function getDbConnection(){
return self::$db;
}
@@ -46,7 +56,7 @@ SQL;
return $groups;
}
//getter functions for the member variables
//getter functions for the (primitive) member variables
function getId(){return $this->id;}
function getName(){return $this->name;}
function getUnlockingAchievementId(){return $this->unlockingAchievementId;}
@@ -69,13 +79,13 @@ SQL;
return $this->achievements;
} // end getAchievements
/// Load the achievementgroup $id from the db into the
/// Load the achievementgroup $id from the db (into this)
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);
$result = dbQuery(self::$db, $query, $params);
$this->setAchievementGroupData(
$result[0]['id'],
@@ -94,23 +104,6 @@ SQL;
$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;
@@ -131,7 +124,7 @@ return $result;
///
/// @param $uId id of the user the achievements should be
function asHtmlCard($uId, $options=[]){
$noForm = $options['noForm']??true;
$noForm = $options['noForm']??true; // for deactivating the give achievement form
$retHtml = "";
$userData = record::getUserData($uId);
$usersAchievements = $this->getUsersAchievements( $uId, ['getAll'=>true] );
@@ -139,6 +132,7 @@ return $result;
foreach($usersAchievements as $a){
$usersAchievementIds[]=(int)$a['achievementId'];
}
// If the user hasn't have the needed Achievement
if(!in_array($this->getUnlockingAchievementId(), $usersAchievementIds))
return "";
$records = record::getGroupsRecords(
@@ -149,15 +143,17 @@ return $result;
$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 .= "<span class=\"card-title\">".$this->name."</span>";
$retHtml .= "</div>";
}
$retHtml .= "<ul>";
else
$retHtml .= "<span style=\"padding-left: 1vw;\" class=\"card-title\">".$this->name."</span>";
$retHtml .= "<div class=\"card-content\">";
$retHtml .= "<ul class=\collapsible\">";
foreach($achievements as $a){
if(in_array((int)$a['id'], $usersAchievementIds)){
$retHtml .= "<li>&#10003; ".$a['name'].": ".$a['description'];
@@ -165,34 +161,43 @@ return $result;
}
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>";// end card-content
$retHtml .= "<div class=\"card-action\">";
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 name=\"submit\" type=\"submit\" value=\"".$a['name']." geben\">";
// $retHtml .= "<button class=\"btn\" name=\"submit\" type=\"submit\" >Achievement ".$a['name']." geben</button>";
$retHtml .= "</form>";
}
if( validateDate($userData[0]['gebDatum'])){
$retHtml.=record::arrayRecord2htmlCardAction($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 .= "</div>";
$retHtml .= "</div>";
$retHtml .= "</div>";
$retHtml .= "</div>";// end card
$retHtml .= "</div>";// end col
return $retHtml;
}// end asHtmlCard
@@ -228,5 +233,73 @@ return $result;
return $html;
}
static function htmlAutoAddAchievementsForm($achievementGroupId, $messageTemplate=null, $from=null, $to=null, $step=null){
$html = "";
$html .= "<form action=\".\" method=\"POST\">";
$html .= "<input name=\"action\" type=\"hidden\" value=\"autoAddAchievements\" />";
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
$html .= "<input name=\"achievementGroupId\" type=\"hidden\" value=\"".$achievementGroupId."\"/>";
$html .= "<label for=\"messageTemplate\">messageTemplate ('%value%' is Placeholder for the value that goes from fromValue to toValue in step)</label>";
$html .= "<input style=\"width:100%;display:block;\" name=\"messageTemplate\" type=\"textarea\" value=\"".$messageTemplate."\"/>";
$html .= "<label for\"from\">fromValue</label>";
$html .= "<input name=\"from\" type=\"text\" value=\"".$from."\"/>";
$html .= "<label for\"to\">toValue</label>";
$html .= "<input name=\"to\" type=\"text\" value=\"".$to."\"/>";
$html .= "<label for\"step\">step</label>";
$html .= "<input name=\"step\" type=\"text\" value=\"".$step."\"/>";
$html .= "<input type=\"submit\" value=\"Auto Add Achievements\" />";
$html .= "</form>";
return $html;
}
/// auto generate the achievements for this group
/// @todo only for empty groups?
function autoAddAchievements($messageTemplate, $from, $to, $step){
if(!empty($this->getAchievements())){
echo("Won't auto-add Achievements to non-empty AchievementGroup!");
return;
}
$level = 1;
for ($value = (int)$from; $value <= (int)$to; $value+=(int)$step) {
$name = $this->getName()." ".intToRomanRepresentation($level++);
$description = str_replace("%value%", (string)$value, $messageTemplate);
$this->addAchievement($name, $description, $level);
}
}
// adds an achievement to the group (in the db!)
function addAchievement($name, $description, $level, $rootId=null){
addAchievement(
$this->getDbConnection(),
$name,
$rootId,
$this->getId(),
$level,
$description,
null
);
}
}
/// convert an int number to roman representation
/// @param int $number
/// @return string
function intToRomanRepresentation($number){
$map = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1);
$returnValue = '';
while ($number > 0) {
foreach ($map as $roman => $int) {
if($number >= $int) {
$number -= $int;
$returnValue .= $roman;
break;
}
}
}
return $returnValue;
}
?>

View File

@@ -11,4 +11,8 @@ document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems, options);
});
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.collapsible');
var instances = M.Collapsible.init(elems, options);
});
</script>

View File

@@ -2,6 +2,7 @@
<ul id="slide-out" class="sidenav">
<li><?php echo $login_status;?></li>
<li><a href=".">Achievements</a></li>
<li><a href="records.php">Rekorde</a></li>
<li><a href="./setUserData.php">Benutzerdaten</a></li>
<?php
if(isUserAdmin($dbConnection, $_SESSION['user']['userId'])){

View File

@@ -5,18 +5,18 @@ 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;
//< goup the record is for
private $achievementGroupId;
//< the age class the record is for
private $ageClass;
//< id of current holder in the db
private $userId;
//< 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;
//< what the record is about
private $description;
private static $db;
/// Names of the columns in the db
@@ -28,6 +28,10 @@ class record{
self::$db = null;
return;
}
public static function getDbConnection(){
return self::$db;
}
public static function getAllRecords(){
$query = <<<SQL
@@ -42,6 +46,7 @@ SELECT * FROM `cwsvjudo`.`wkParticipo_Users`
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
@@ -50,12 +55,10 @@ SQL;
// - 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 ";
$query = "SELECT *, `cwsvjudo`.`machs_records`.`id` as `recordId` 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 ]
];
@@ -63,10 +66,10 @@ SQL;
$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);
$query.= "ORDER BY `cwsvjudo`.`machs_records`.`value` DESC;";
return dbQuery(self::$db, $query, $params);
}
/// @param $r record as associative array
public static function arrayRecord2htmlDl($r){
$retHtml = "<dl>";
@@ -75,6 +78,46 @@ SQL;
$retHtml.= "</dl>";
return $retHtml;
}
public static function arrayRecord2htmlCardAction($r, $u, $gid){
// $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.= "<strong>Anschließend</strong> 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 id=\"submit\" style=\"width:100%\" name=\"submit\" type=\"submit\" value=\"Rekord eintragen\">";
}
else{
$retHtml.= "<input disabled=\"true\" id=\"submit\" 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>";
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"){
@@ -88,52 +131,80 @@ SQL;
$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;
}
// get an ageClasses records including its holders
public static function getRecordsOfAgeClass($ageClass, $achievementGroup, $options=[]){
$query = <<<SQL
SELECT * FROM `cwsvjudo`.`machs_records`
JOIN `cwsvjudo`.`wkParticipo_Users`
ON `cwsvjudo`.`machs_records`.`userId` = cwsvjudo`.`wkParticipo_Users`.`id`
WHERE `cwsvjudo`.`machs_records`.`ageClass` = :ageClass ";
AND `cwsvjudo`.`machs_records`.`achievementGroupId` = :achievementGroupId;
SQL;
$params = [
':ageClass'=>['value'=>$ageClass, 'data_type'=>PDO::PARAM_INT],
':achievementGroupId'=>['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT],
];
$returns = query($this->getDbConnection(), $query, $params);
return $records;
}
// returns all age classes with records
public static function getAgeClassesWithRecord($achievementGroupId=null){
$params = null;
$query="SELECT DISTINCT `ageClass` FROM `cwsvjudo`.`machs_records` ";
if($achievementGroupId != null){
$query.="WHERE `achievementGroupId` = :achievementGroupId ";
$params=[];
$params[':achievementGroupId'] = ['value'=>$achievementGroupId, 'data_type'=>PDO::PARAM_INT];
}
$query.="ORDER BY `ageClass`";
$ageClasses = dbQuery(self::$db, $query, $params);
return $ageClasses;
}
// load the achievement from the DB
public function loadFromDb($id){
$query = "SELECT * from `cwsvjudo`.`machs_records` WHERE `id`=:id;";
$params = [':id'=>['value'=>$id, 'data_type'=>PDO::PARAM_INT]];
$achievements = query($this->getDbConnection(), $query, $params);
$this->setFromAssocArray($achievements[0]);
}
// set the members of the record via an associative array (like the ones, that are returned by dbquery)
public function setFromAssocArray($assocArray){
$this->id = (int)$assocArray['id'];
$this->achievementGroupId = (int)$assocArray['achievementGroupId'];
$this->ageClass = (int)$assocArray['ageClass'];
$this->userId = (int)$assocArray['userId'];
$this->timestap = $assocArray['userId'];
$this->value = $assocArray['value'];
}
static public function htmlRanking($recordList){
if(empty($recordList))
return "";
$html = "<table>";
$html.= "<tr><th>Judoka</th><th>Rekord</th><th>Video</th></tr>";
foreach($recordList as $record){
$html.="<tr><td>".$record['vorname']." ".$record['name']."</td><td>".$record['value']."</td><td><a href=\"videos.d/records/".$record['recordId'].".webm\" >Video</a></td></tr>";
}
$html.= "</table>";
return $html;
}
}
/// Als String gegebene Altersklassen als Jahrgangsintervalle

View File

@@ -0,0 +1,12 @@
<?php
/// @file meta config
/// don't place loginData here, as it is in a public directory
//error_reporting(E_ALL | E_STRICT);
//ini_set('display_errors',1);
setlocale (LC_ALL, 'de_DE@euro', 'de_DE', 'de', 'ge');
require_once("config.php");
require_once("./local/dbConf.php");
require_once("./local/achievementsConf.php");
?>

View File

@@ -1,203 +1,23 @@
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);
$basePath = "/users/cwsvjudo/www";
require_once($basePath."/config/cwsvJudo.config.php");
require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
/// einem User ein achievement zuordnen
/// @file main for the achievementsystem
///
/// @param $aDbConnection PDO-Datenbankverbindung, die benutzt werden soll
/// @param $anUserId ID des Users, der das Attribut erhalten soll
/// @param $anachievementId ID des zu vergebenden Attributes
///
/// - Es erfolgt keine Kontrolle, ob:
/// - die achievementId überhaupt existiert,
/// - ob die userId überhaupt existiert,
/// - ob der User das achievement bereits hat,
function giveUserAnAchievment($aDbConnection, $anUserId, $anAchievementId){
withdrawUsersAchievement($aDbConnection, $anUserId, $anAchievementId);
try{
dbQuery(
$aDbConnection,
"INSERT INTO `achievements<=>user` (userId, achievementId) VALUES (:userId, :achievementId);",
array(
':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
':achievementId'=> array('value'=>$anAchievementId, 'data_type'=>PDO::PARAM_INT)
)
);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "<br/>queryString: ".$queryString."<br />"; var_dump($bindArray);
}
return;
}
/// This file includes all other files needed by the achievementsystem
/// einem User ein Achievement entziehen
function withdrawUsersAchievement($aDbConnection, $anUserId, $anAchievementId, $limit = NULL){
try{
// Variablen für das Binden an die Query vorbereiten
// inklusive Validierung der Werte
$bindArray = array();
if( is_positive_integer( $anUserId ) ){
$bindArray[':userId'] = array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT);
}
else{
throw new InvalidArgumentException("withdrawUsersAchievement: userId must be positive integer!");
}
if( is_positive_integer($anAchievementId) ){
$bindArray[':achievementId'] = array('value'=>$anAchievementId, 'data_type'=>PDO::PARAM_INT);
}
else{
throw new InvalidArgumentException("withdrawUsersAchievement: anAchievementId must be positive integer");
}
if( is_positive_integer( $limit ) ){
$bindArray[':limit'] = array('value' => $limit, 'data_type' => PDO::PARAM_INT);
}
require_once('machs-config.php');
// Zusammenstellen der Query
$queryString =
"DELETE FROM `achievements<=>user` ".
"WHERE `userId`=:userId ".
"AND `achievementId`=:achievementId".
(is_positive_integer( $limit )?" LIMIT :limit":"").
";";
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");
echo("queryString: ".$queryString."<br />"); var_dump($bindArray);
dbQuery(
$aDbConnection,
$queryString,
$bindArray
);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "<br/>queryString: ".$queryString."<br />"; var_dump($bindArray);
}
return;
}// Ende withdrawUsersAchievement
var_dump($_GET);
$actions = ["giveUserAnAchievement", "withdrawUsersAchievement"];
$dbConn = getCwsvJudoDbConn();
$dbConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
if(isset($_GET['action'])){
switch($_GET['action']){
case "giveUserAnAchievement":
try{
giveUserAnAchievment($dbConn, intval($_GET['userId']), intval($_GET['achievementId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
case "withdrawUsersAchievement":
try{
withdrawUsersAchievement($dbConn, intval($_GET['userId']), intval($_GET['achievementId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
default:
echo("Ungültige Aktion (".$_GET['action'].") erwünscht!");
break;
}
}
$users =
dbQuery(
$dbConn,
"SELECT * FROM cwsvjudo.wkParticipo_Users;"
);
$userAchievements =
dbQuery(
$dbConn,
"SELECT * FROM cwsvjudo.achievements;"
);
require_once("./auth.php");
// externel libraries, that can't be included by relative path
/// @todo Do it better: how can we include external libraries without a
/// config variable
require_once($config['basePath']."/config/cwsvJudo.config.php");
require_once($config['basePath']."/config/phpcount.config.php");
require_once($config['basePath']."/ressourcen/phpLib/phpcount/phpcount.php");
?>
<html>
<head>
</head>
<body>
<form>
<label>Action:
<select name="action">
<option disabled selected value> -- Aktion auswählen -- </option>
<?php
foreach($actions as $action)
echo("<option>".$action."</option>");
?>
</select>
</label>
<label>User:
<select name="userId">
<option disabled selected value> -- User auswählen -- </option>
<?php
foreach($users as $user)
echo("<option value=\"".$user['id']."\">".$user['loginName']."</option>");
?>
</select>
</label>
<label>Attribut:
<select name="achievementId">
<option disabled selected value> -- Attribut auswählen -- </option>
<?php
foreach($userAchievements as $userAchievement)
echo("<option value=\"".$userAchievement['id']."\">".$userAchievement['name']."</option>");
?>
</select>
</label>
<button type="submit">Eingaben absenden</button>
</form>
<h1>Attribute</h1>
<?php echo(array2htmlTableString($userAchievements));?>
<?php
foreach($userAchievements as $userAchievement){
echo("<h2>".$userAchievement["name"]."</h2>");
// get the users with the attribute by a cross join
// remark: there are two id-columns, from which one gets lost (the one from the user) in the phpArray.
// so we (have to) use the userId from the attribute
// in short attributed => userId, unattributed => id (is the id of the user)
$achievedUsers =
dbQuery(
$dbConn,
"SELECT * FROM wkParticipo_Users, `achievements<=>user` WHERE wkParticipo_Users.id = `achievements<=>user`.userId AND `achievements<=>user`.achievementId = :achievementId;",
array(":achievementId"=>array('value'=>$userAchievement['id'], 'data_type'=>PDO::PARAM_INT))
);
// Add a withthraw link entry
foreach($achievedUsers as $index => $user){
$achievedUsers[$index] += ["withdrawLink" => "<a href=\"?action=withdrawUsersAchievement&userId=".$user["userId"]."&achievementId=".$userAchievement["id"]."\">withdraw ".$userAchievement["name"]."</a>"];
}
echo( "<h3>have it</h3>".arrayKeyed2htmlTableString($achievedUsers, ["userId", "name", "vorname", "withdrawLink"]) );
$achievedKeyList = [];
foreach($achievedUsers as $user){
$achievedKeyList[] = $user["userId"];
}
$unachievedUsers = array();
foreach($users as $user){
if(!in_array($user["id"], $achievedKeyList)){
$unachievedUsers[] = $user;
}
}
// Add a giveAttribute link entry to every user
foreach($unachievedUsers as $index => $user){
$unachievedUsers[$index] += ["giveAchievementLink" => "<a href=\"?action=giveUserAnAchievement&userId=".$user["id"]."&achievementId=".$userAchievement["id"]."\">give Attribute ".$userAchievement["name"]."</a>"];
}
echo( "<h3>give it</h3>".arrayKeyed2htmlTableString($unachievedUsers, ["id", "name", "vorname", "giveAchievementLink"]) );
}
?>
<h1>User</h1>
<?php echo(array2htmlTableString($users));?>
</body>
</html>

11
homepage/machs/readMe.md Normal file
View File

@@ -0,0 +1,11 @@
Animated gif erstellen:
```
convert \
-delay 100 \
-loop 5 \
-resize 256x \
-fuzz 10% \
-layers optimize \
frame-* wechselLiegeUnterarmstuetz.gif
```

View File

@@ -0,0 +1,79 @@
<?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"]
);
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>Achievements</title>
<meta name="description" content="Achievements">
<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>
<?php include("lib/machs/sidenav.php");?>
<?php
echo("<h1>Rekorde</h1>");
foreach($achievementGroups as $group){
$ageClasses = record::getAgeClassesWithRecord($group->getId());
if(empty($ageClasses))
continue;
echo("<h2>".$group->getName()."</h2>");
foreach($ageClasses as $ageClass){
$ageClass = $ageClass['ageClass'];
echo("<h3>Altersklasse U".$ageClass."</h3>");
$records = record::getGroupsRecords($group->getId(), $ageClass);
echo(record::htmlRanking($records));
}
}
?>
</body>
</html>