271 lines
9.6 KiB
PHP
271 lines
9.6 KiB
PHP
<?php
|
|
require_once("lib/record.php");
|
|
|
|
// Eine Fehler/Warnung/Notiz/Erfolgsmeldung als divBox im String zurückgeben
|
|
function htmlRetMessage($anRetMessage){
|
|
$retHtmlString = "";
|
|
if( !empty($anRetMessage) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
if( !empty($anRetMessage['error']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "ERROR:<br />";
|
|
$retHtmlString .= $anRetMessage['error'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['warning']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "WARNING:<br />";
|
|
$retHtmlString .= $anRetMessage['warning'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['notice']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "Info:<br />";
|
|
$retHtmlString .= $anRetMessage['notice'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
if( !empty($anRetMessage['success']) ){
|
|
$retHtmlString .= "<div style=\"border: 1px solid;\">";
|
|
$retHtmlString .= "SUCCESS:<br />";
|
|
$retHtmlString .= $anRetMessage['success'];
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
$retHtmlString .= "</div>";
|
|
}
|
|
// 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 = <<<SQL
|
|
SELECT * FROM `cwsvjudo`.`wkParticipo_Users` WHERE `kinder` IS NOT NULL;
|
|
SQL;
|
|
|
|
$users = dbQuery($db, $query);
|
|
foreach($users as $user){
|
|
$kidIds = explode(",", $user['kinder']);
|
|
echo("Processing user ".$user['vorname']." ".$user['name']." with kids ".$kidIds."\n");
|
|
foreach($kidIds as $kidId){
|
|
$query = <<<SQL
|
|
INSERT INTO `cwsvjudo`.`vormundschaft` (userId, kidId) VALUE (:userId, :kidId);
|
|
SQL;
|
|
echo("Adding kid ".$kidId." to user ".$user['id']."\n");
|
|
echo($query."\n");
|
|
$params = array(
|
|
':userId' => 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() . "<br/>queryString: ".$queryString."<br />"; 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 .= "<table>";
|
|
if($withCaption) {
|
|
$ret .= "<tr>";
|
|
foreach( $keyList as $caption ){
|
|
$ret .= "<th>".$caption."</th>";
|
|
}
|
|
$ret .= "</tr>";
|
|
}
|
|
foreach($anArray as $row){
|
|
if( !is_array($anArray) )
|
|
continue;
|
|
$ret .= "<tr>";
|
|
foreach( $keyList as $key )
|
|
$ret .= "<td>".$row[$key]."</td>";
|
|
$ret .= "</tr>";
|
|
}
|
|
$ret .= "</table>";
|
|
return $ret;
|
|
}
|
|
|
|
function getUsersAchievements($db, $userId){
|
|
$query = <<<SQL
|
|
SELECT * FROM `cwsvjudo`.`achievements<=>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 .= "<div><dl>";
|
|
$html .= "<dt>Upload Link</dt><dd><a href=\"".$userData['machsUploadUrl']."\">".$userData['machsUploadUrl']."</a></dd>";
|
|
$html .= "<dt>Upload Passwort</dt><dd>".$userData['machsUploadPw']."</dd>";
|
|
$html .= "</dl></div>";
|
|
return $html;
|
|
}
|
|
|
|
function htmlAchievementListForUser($db, $achievementGroups, $userId, $usersAchievmentIds, $noForm=false){
|
|
// var_dump($db, $achievementGroups, $userId, $usersAchievmentIds);
|
|
$ids=[];
|
|
foreach($usersAchievmentIds as $a){
|
|
$ids[]=$a['achievementId'];
|
|
}
|
|
record::setDbConnection($db);
|
|
$userData = record::getUserData($userId);
|
|
$retHtml = "";
|
|
if(!canUserGetAchievementToday( $db, $userId) ){
|
|
$retHtml .= "<div>Heute wurde schon ein Achievement erreicht!</div>";
|
|
}
|
|
$retHtml .= "<div class=\"row\">";
|
|
foreach($achievementGroups as $g){
|
|
$records = (
|
|
($userData[0]['gebDatum']!=null)?
|
|
(record::getGroupsRecords($g->getId(), record::birthday2ageClass($userData[0]['gebDatum']))):
|
|
[]
|
|
);
|
|
$retHtml .= "<div class=\"col s12 m6 l4 xl3\">";
|
|
$retHtml .= "<ul class=\"card\">";
|
|
// see, if there is a record for this group
|
|
$imgUrl = null;
|
|
foreach($g->getAchievements() as $a){
|
|
if($a['imgUrl'] != null){
|
|
$imgUrl = $a['imgUrl'];
|
|
}
|
|
if(in_array($a['id'], $ids)){
|
|
$retHtml .= "<li>✓ ".$a['name'].": ".$a['description'];
|
|
$retHtml .= "</li>";
|
|
}
|
|
else{
|
|
$retHtml .= "<li style=\"color:gray\">".$a['name'].": ".$a['description'];
|
|
//if(isUserAdmin($db, $_SESSION['user']['userId'])){
|
|
if(!$noForm){
|
|
if( canUserGetAchievementToday( $db, $userId) or isUserAdmin($db, $_SESSION['user']['userId']) ){
|
|
$retHtml .= "<form action=\".\" method=\"POST\">";
|
|
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" type=\"hidden\">";
|
|
$retHtml .= "<input name=\"redirectLocation\" value=\"./#achievementList-".$userId."\" type=\"hidden\">";
|
|
$retHtml .= "<input name=\"userId\" value=\"".$userId."\" 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], $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 .= "</div>";
|
|
}
|
|
$retHtml .= "</div>";
|
|
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(){
|
|
$html = "";
|
|
$html .= "<form action=\".\" method=\"POST\">";
|
|
$html .= "<input name=\"action\" type=\"hidden\" value=\"addAchievement\" />";
|
|
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
|
|
$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 name=\"imgUrl\" type=\"text\" placeholder=\"imgUrl\"/>";
|
|
$html .= "<input type=\"submit\"/>";
|
|
$html .= "</form>";
|
|
return $html;
|
|
}
|
|
|
|
function htmlUpdateAchievementBox($achievementId, $name, $rootId, $achievementGroupId, $level, $description, $imgUrl){
|
|
$html = "";
|
|
$html .= "<form action=\".\" method=\"POST\">";
|
|
$html .= "<input name=\"action\" type=\"hidden\" value=\"updateAchievement\" />";
|
|
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"achievementBuilder.php\" />";
|
|
$html .= "<div > achievementId: ".$achievementId;
|
|
$html .= "<input name=\"achievementId\" type=\"hidden\" value=\"".$achievementId."\"/>";
|
|
$html .= "<div/>";
|
|
$html .= "<label for=\"name\">name</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"name\" type=\"text\" value=\"".$name."\"/>";
|
|
$html .= "<label for=\"rootId\">rootId</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"rootId\" type=\"text\" value=\"".$rootId."\"/>";
|
|
$html .= "<label for=\"achievementGroupId\">achievementGroupId</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"achievementGroupId\" type=\"text\" value=\"".$achievementGroupId."\"/>";
|
|
$html .= "<label for=\"level\">level</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"level\" type=\"text\" value=\"".$level."\"/>";
|
|
$html .= "<label for=\"description\">description</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" value=\"".$description."\"/>";
|
|
$html .= "<label for=\"imgUrl\">imgUrl</label>";
|
|
$html .= "<input style=\"width:100%;display:block;\" name=\"imgUrl\" type=\"text\" value=\"".$imgUrl."\"/>";
|
|
$html .= "<input type=\"submit\"/>";
|
|
$html .= "</form>";
|
|
return $html;
|
|
}
|
|
|
|
?>
|