Releaseversion
This commit is contained in:
@@ -33,4 +33,197 @@ if( !empty($anRetMessage) ){
|
||||
// print_r($anRetMessage);
|
||||
return $retHtmlString;
|
||||
}
|
||||
|
||||
// one time only function to convert the list of kids within the user
|
||||
// table itself to an extra entry in a "vormundschafts" table
|
||||
function convertToVormundschaft($db){
|
||||
$query = <<<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){
|
||||
//var_dump($db, $achievementGroups, $userId, $usersAchievmentIds);
|
||||
$ids=[];
|
||||
foreach($usersAchievmentIds as $a){
|
||||
$ids[]=$a['achievementId'];
|
||||
}
|
||||
$retHtml = "";
|
||||
if(!canUserGetAchievementToday( $db, $userId) ){
|
||||
$retHtml .= "<div>Heute wurde schon ein Achievement erreicht!</div>";
|
||||
}
|
||||
$retHtml .= "<div class=\"row\">";
|
||||
foreach($achievementGroups as $g){
|
||||
$retHtml .= "<div class=\"col s12 m6 l4 xl3\">";
|
||||
$retHtml .= "<ul class=\"card\">";
|
||||
$imgUrl = null;
|
||||
foreach($g 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(canUserGetAchievementToday( $db, $userId) ){
|
||||
$retHtml .= "<form action=\".\" method=\"POST\">";
|
||||
$retHtml .= "<input name=\"action\" value=\"giveUserAnAchievement\" 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;
|
||||
}
|
||||
}
|
||||
$retHtml .= "</ul>";
|
||||
$retHtml .= "</div>";
|
||||
}
|
||||
$retHtml .= "</div>";
|
||||
return $retHtml;
|
||||
}
|
||||
|
||||
function htmlAddAchievementBox(){
|
||||
$html = "";
|
||||
$html .= "<form action=\".\" method=\"POST\">";
|
||||
$html .= "<input name=\"action\" type=\"hidden\" value=\"addAchievement\" />";
|
||||
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"#endOfUpdateAchievementBoxes\" />";
|
||||
$html .= "<input name=\"name\" type=\"text\" placeholder=\"name\"/>";
|
||||
$html .= "<input style=\"width:100%;display:block;\" name=\"description\" type=\"textarea\" placeholder=\"mdDescription\"/>";
|
||||
$html .= "<input type=\"submit\"/>";
|
||||
$html .= "</form>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
function htmlUpdateAchievementBox($achievementId, $name, $description, $rootId, $level){
|
||||
$html = "";
|
||||
$html .= "<form action=\".\" method=\"POST\">";
|
||||
$html .= "<input name=\"action\" type=\"hidden\" value=\"updateAchievement\" />";
|
||||
$html .= "<input name=\"redirectLocation\" type=\"hidden\" value=\"#addAchievementBox\" />";
|
||||
$html .= "<div > achievementId: ".$achievementId;
|
||||
$html .= "<input name=\"achievementId\" type=\"hidden\" value=\"".$achievementId."\"/>";
|
||||
$html .= "<div />";
|
||||
$html .= "<div >";
|
||||
$html .= "<label for=\"name\">name</label>";
|
||||
$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 .= "<input style=\"width:100%;display:block;\" name=\"rootId\" type=\"text\" value=\"".$rootId."\"/>";
|
||||
$html .= "<div/>";
|
||||
$html .= "<div>";
|
||||
$html .= "<label for=\"level\">level</label>";
|
||||
$html .= "<input style=\"width:100%;display:block;\" name=\"level\" type=\"text\" value=\"".$level."\"/>";
|
||||
$html .= "<div/>";
|
||||
$html .= "<input type=\"submit\"/>";
|
||||
$html .= "</form>";
|
||||
return $html;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
85
homepage/machs/lib/api.php
Normal file
85
homepage/machs/lib/api.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
function processPostData($db, $post, $redirectLocation = "."){
|
||||
if($post['action']){
|
||||
if($post['action']=="giveUserAnAchievement"){
|
||||
giveUserAnAchievement(
|
||||
$db,
|
||||
$post['userId'],
|
||||
$post['achievementId']
|
||||
);
|
||||
}
|
||||
if($post['action']=="addAchievement"){
|
||||
addAchievement(
|
||||
$db,
|
||||
$post['name'],
|
||||
$post['description']
|
||||
);
|
||||
}
|
||||
if($post['action']=="updateAchievement"){
|
||||
updateAchievement(
|
||||
$db,
|
||||
$post['achievementId'],
|
||||
$post['name'],
|
||||
$post['description'],
|
||||
$post['rootId'],
|
||||
$post['level']
|
||||
);
|
||||
}
|
||||
if($post['redirectLocation'])
|
||||
$redirectLocation = $post['redirectLocation'];
|
||||
header("Location: ".$redirectLocation);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
function sendEmail($toEmail, $emailText, $emailSubject){
|
||||
try{
|
||||
$date=new DateTime();
|
||||
mail(
|
||||
$toEmail,
|
||||
$emailSubject,
|
||||
$emailText
|
||||
);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo 'Message: ' .$e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function attendancesAssocArray2text($attendancesAssocArray){
|
||||
$ret = "";
|
||||
foreach($attendancesAssocArray as $date => $attendees){
|
||||
$ret .= $date."\n";
|
||||
foreach($attendees as $a){
|
||||
$ret .= "\n";
|
||||
$ret .= "Name: ".$a['name'].", ".$a['vorname']."\n";
|
||||
$ret .= "PLZ: ".$a['corona_PLZ']."\n";
|
||||
$ret .= "Tel.: ".$a['corona_telephon']."\n";
|
||||
$ret .= "eMail: ".$a['corona_eMail']."\n";
|
||||
}
|
||||
$ret .= "\n";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function attendancesAssocArray2mdList($attendancesAssocArray, $date=null){
|
||||
if($date == null)
|
||||
$date=new DateTime();
|
||||
$ret = "# Anwesenheitsliste zur Corona-Kontaktverfolgung der Abteilung Judo des CWSV vom ".$date->format("Y-m-d")."\n\n";
|
||||
foreach($attendancesAssocArray as $d => $attendees){
|
||||
$ret .= "## ".$d."\n";
|
||||
$i=0;
|
||||
foreach($attendees as $a){
|
||||
$i += 1;
|
||||
$ret .= "\n";
|
||||
$ret .= $i." ".$a['name'].", ".$a['vorname']."\n";
|
||||
$ret .= " - PLZ: ".$a['corona_PLZ']."\n";
|
||||
$ret .= " - Tel.: ".$a['corona_telephon']."\n";
|
||||
$ret .= " - eMail: ".$a['corona_eMail']."\n";
|
||||
}
|
||||
$ret .= "\n";
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
?>
|
||||
323
homepage/machs/lib/db.php
Normal file
323
homepage/machs/lib/db.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
// get a Connection to the database
|
||||
function getPdoDbConnection($hostname, $dbName, $user, $password){
|
||||
try{
|
||||
$dbConnection = new PDO(
|
||||
'mysql:host='.$hostname.';dbname='.$dbName,
|
||||
$user,
|
||||
$password
|
||||
);
|
||||
}
|
||||
catch(PDOException $dbError){
|
||||
echo( "Error whilst getting a dbConnection!: " . $dbError->getMessage() );
|
||||
}
|
||||
return $dbConnection;
|
||||
}
|
||||
|
||||
function createDb($dbConnection){
|
||||
<<<SQL
|
||||
CREATE TABLE `cwsvjudo`.`anwesenheit` (
|
||||
`id` INT UNSIGNED NOT NULL ,
|
||||
`userId` INT UNSIGNED NOT NULL ,
|
||||
`date` DATE NOT NULL DEFAULT CURRENT_TIMESTAMP ,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE = InnoDB;
|
||||
ALTER TABLE `cwsvjudo`.`anwesenheit` ADD UNIQUE `attandence` (`userId`, `id`);
|
||||
SQL;
|
||||
}
|
||||
|
||||
/// perform a pdo-query
|
||||
///
|
||||
/// @param aDbConnection
|
||||
/// @param $aQueryString
|
||||
/// @param $aBindArray e.g. array(
|
||||
/// ':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
|
||||
/// ':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT) )
|
||||
/// @param $someOption
|
||||
function dbQuery($aDbConnection, $aQueryString, $aBindArray = array(), $someOptions = array()){
|
||||
// Standardbelegungen
|
||||
if( empty($someOptions['dbCharset' ]) ) $someOptions['dbCharset' ] = "ISO-8859-1";
|
||||
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";
|
||||
if( empty($someOptions['dontFetch' ]) ) $someOptions['dontFetch' ] = false;
|
||||
/// @toDo: Bisher wird nur die Rückgabe konvertiert. Eigentlich muss
|
||||
/// doch auch die Eingabe konvertiert werden. Aber das jetzt
|
||||
/// umzustellen wird schwer! Die User m Wettkampfplaner sind ja z.B.
|
||||
/// als UTF8 in latin1(?) gespeichert.
|
||||
/// @toDo: Die Standardwerte sollten vielleicht aus einer config
|
||||
/// kommen, nicht hardcoded
|
||||
try{
|
||||
$pdoStatement = $aDbConnection->prepare( $aQueryString );
|
||||
foreach( $aBindArray as $bindName => $bind ){
|
||||
if( $bind['data_type'] == PDO::PARAM_STR)
|
||||
$bind['value'] = iconv(
|
||||
$someOptions['outCharset'],
|
||||
$someOptions['dbCharset'],
|
||||
$bind['value']
|
||||
);
|
||||
$pdoStatement->bindValue(
|
||||
$bindName,
|
||||
$bind['value'],
|
||||
(isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR)
|
||||
);
|
||||
}
|
||||
$pdoResult = $pdoStatement->execute();
|
||||
if(!$pdoResult){
|
||||
echo("Error during dbQuery!\n");
|
||||
echo("DB-Error:\n"); var_dump($aDbConnection->errorInfo());
|
||||
// echo($pdoStatement.errorInfo());
|
||||
}
|
||||
if($someOptions['dontFetch']){
|
||||
$ret = NULL;
|
||||
}
|
||||
else{
|
||||
$ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
}
|
||||
catch(PDOException $db_error){
|
||||
print "Error!: " . $db_error->getMessage() . "<br/>";
|
||||
return null;
|
||||
}
|
||||
// Zeichensatzkonvertierung
|
||||
if( is_array($ret) ){
|
||||
foreach($ret as &$entry){
|
||||
array_walk(
|
||||
$entry,
|
||||
function (&$value, $key, $someOptions) {
|
||||
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
|
||||
},
|
||||
$someOptions
|
||||
);
|
||||
}
|
||||
}
|
||||
//var_dump($ret);
|
||||
//var_dump($aQueryString);
|
||||
//var_dump($aBindArray);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getLastAttendances($db, $minDate=null){
|
||||
if ($minDate == null){
|
||||
$minDate = new DateTime;
|
||||
$minDate->sub(new DateInterval("P1M")); // from the current date subtract a *P*eriod of *1* *M*onth
|
||||
}
|
||||
|
||||
$query = <<<SQL
|
||||
SELECT userId, date, vorname, name, corona_PLZ, corona_telephon, corona_eMail
|
||||
FROM `cwsvjudo`.`anwesenheit`
|
||||
JOIN `cwsvjudo`.`wkParticipo_Users`
|
||||
ON `cwsvjudo`.`anwesenheit`.`userId` = `cwsvjudo`.`wkParticipo_Users`.`id`
|
||||
WHERE :minDate <= date
|
||||
ORDER BY `date` DESC, `name`;
|
||||
SQL;
|
||||
$params = array(
|
||||
'minDate' => array('value' => $minDate->format('Y-m-d'), 'data_type' => PDO::PARAM_STR)
|
||||
);
|
||||
$options = array();
|
||||
$ret = dbQuery($db, $query, $params, $options);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function getUsersWithAttribute($dbConnection, $attributeName){
|
||||
$query = <<<SQL
|
||||
SELECT userId, name, vorname
|
||||
FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
JOIN `cwsvjudo`.`wkParticipo_user<=>userAttributes`
|
||||
ON `cwsvjudo`.`wkParticipo_Users`.`id` =`cwsvjudo`.`wkParticipo_user<=>userAttributes`.`userId`
|
||||
WHERE `cwsvjudo`.`wkParticipo_user<=>userAttributes`.`attributeId` IN (
|
||||
SELECT `id` FROM `cwsvjudo`.`wkParticipo_userAttributes` WHERE `name` = :attributeName
|
||||
);
|
||||
SQL;
|
||||
$params = array(
|
||||
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||
);
|
||||
return dbQuery($dbConnection, $query, $params);
|
||||
}
|
||||
|
||||
function giveUserAnUserAttribute($dbConnection, $userId, $attributeName){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`wkParticipo_user<=>userAttributes` (`userId`, `attributeId`)
|
||||
SELECT :userId, `id`
|
||||
FROM `cwsvjudo`.`wkParticipo_userAttributes`
|
||||
WHERE `name` = :attributeName;
|
||||
SQL;
|
||||
$params = array(
|
||||
':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT),
|
||||
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||
);
|
||||
return dbQuery($dbConnection, $query, $params);
|
||||
}
|
||||
|
||||
function hasUserAttribute($dbConnection, $userId, $attributeName){
|
||||
$query = <<<SQL
|
||||
SELECT `wkParticipo_user<=>userAttributes`.userId, `wkParticipo_userAttributes`.name
|
||||
FROM `wkParticipo_user<=>userAttributes` LEFT JOIN `wkParticipo_userAttributes`
|
||||
ON `wkParticipo_user<=>userAttributes`.`attributeId` = `wkParticipo_userAttributes`.`id`
|
||||
WHERE `wkParticipo_userAttributes`.name = :attributeName AND userId=:userId;",
|
||||
SQL;
|
||||
$params = array(
|
||||
':userId' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT),
|
||||
':attributeName' => array('value'=>$attributeName, 'data_type'=>PDO::PARAM_STR)
|
||||
);
|
||||
$attributedUsers = dbQuery($dbConnection, $query, $params);
|
||||
foreach($attributedUsers as $u)
|
||||
if($u['userId']==$userId)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function giveJudokasAttendence($dbConnection, $date, $ids){
|
||||
$values = array();
|
||||
try{
|
||||
foreach( $ids as $id){
|
||||
array_push( $values, "(\"".$date."\", ".$id.")");;
|
||||
}
|
||||
$query = "INSERT INTO `cwsvjudo`.`anwesenheit` (`date`, `userId`) VALUES ".join(",", $values).";";
|
||||
dbQuery($dbConnection, $query, array(), ['dontFetch' => true]);
|
||||
}
|
||||
catch(PDOException $db_error){
|
||||
print "Error!: " . $db_error->getMessage() . "<br/>";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getUsersKidsIds($db, $userId){
|
||||
$query = <<<SQL
|
||||
SELECT `kidId`
|
||||
FROM `vormundschaft`
|
||||
WHERE userId = :userId;
|
||||
SQL;
|
||||
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]];
|
||||
$result = dbQuery($db, $query, $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
function getUsersKids($db, $userId){
|
||||
$query = <<<SQL
|
||||
SELECT *
|
||||
FROM `wkParticipo_Users`
|
||||
JOIN `vormundschaft`
|
||||
ON `wkParticipo_Users`.`id` = `vormundschaft`.`kidId`
|
||||
WHERE `vormundschaft`.`userId` = :userId;
|
||||
SQL;
|
||||
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]];
|
||||
$result = dbQuery($db, $query, $params);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// updates corona data of an user
|
||||
function updateCoronaData($db, $userId, $columnName, $columnValue){
|
||||
$coronaColumnNames = ["corona_PLZ", "corona_telephon", "corona_eMail"];
|
||||
|
||||
if( !in_array( $columnName, $coronaColumnNames) ){
|
||||
return;
|
||||
}
|
||||
$query = "UPDATE `cwsvjudo`.`wkParticipo_Users` SET `".$columnName."`=:val WHERE `id`=:id;";
|
||||
$params = array(
|
||||
':val' => array('value'=>$columnValue, 'data_type'=>PDO::PARAM_STR),
|
||||
':id' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT)
|
||||
);
|
||||
dbQuery($db, $query, $params);
|
||||
return;
|
||||
}
|
||||
|
||||
function addCoronaUser($db, $name, $vorname, $corona_PLZ, $corona_telephon, $corona_eMail){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`wkParticipo_Users` (name, vorname, corona_PLZ, corona_telephon, corona_eMail)
|
||||
VALUES (:name, :vorname, :plz, :telephon, :email);
|
||||
SQL;
|
||||
$params = array(
|
||||
':name' => array('value'=>$name, 'data_type'=>PDO::PARAM_STR),
|
||||
':vorname' => array('value'=>$vorname, 'data_type'=>PDO::PARAM_STR),
|
||||
':plz' => array('value'=>$corona_PLZ, 'data_type'=>PDO::PARAM_STR),
|
||||
':telephon' => array('value'=>$corona_telephon, 'data_type'=>PDO::PARAM_STR),
|
||||
':email' => array('value'=>$corona_eMail, 'data_type'=>PDO::PARAM_STR),
|
||||
);
|
||||
dbQuery($db, $query, $params);
|
||||
|
||||
$newId = $db->lastInsertId();
|
||||
giveUserAnUserAttribute($db, $newId, "inTraining");
|
||||
return;
|
||||
}
|
||||
|
||||
function giveUserAnAchievement($db, $userId, $achievementId){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`achievements<=>user` (`userId`, `achievementId`) VALUE (:userId, :achievementId);
|
||||
SQL;
|
||||
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT], 'achievementId'=>['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT]];
|
||||
dbQuery($db, $query, $params);
|
||||
sendEmail("cwsvjudo@arcor.de", "kwT", "User ".$userId." got achievement ".$achievementId);
|
||||
return;
|
||||
}
|
||||
|
||||
function isUserAdmin($dbConn, $userId){
|
||||
$adminUsers =
|
||||
dbQuery(
|
||||
$dbConn,
|
||||
"SELECT `wkParticipo_user<=>userAttributes`.userId, `wkParticipo_userAttributes`.name from `wkParticipo_user<=>userAttributes` LEFT JOIN `wkParticipo_userAttributes` ON `wkParticipo_user<=>userAttributes`.attributeId = `wkParticipo_userAttributes`.id WHERE `wkParticipo_userAttributes`.name = :attributeName;",
|
||||
array(":attributeName"=>array('value'=>"isAdmin", 'data_type'=>PDO::PARAM_STR))
|
||||
);
|
||||
foreach($adminUsers as $adminUser)
|
||||
if($adminUser['userId']==$userId)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function getUserData($db, $userId){
|
||||
$query = <<<SQL
|
||||
SELECT *
|
||||
FROM `cwsvjudo`.`wkParticipo_Users`
|
||||
WHERE `id` = :userId;
|
||||
SQL;
|
||||
$params = [':userId'=>['value'=>$userId, 'data_type'=>PDO::PARAM_INT]];
|
||||
$userData = dbQuery($db, $query, $params);
|
||||
return $userData[0];
|
||||
}
|
||||
|
||||
function getAchievements($db){
|
||||
$query = <<<SQL
|
||||
SELECT *
|
||||
FROM `cwsvjudo`.`achievements`;
|
||||
SQL;
|
||||
return dbQuery($db, $query);
|
||||
}
|
||||
|
||||
function addAchievement($db, $name, $description){
|
||||
$query = <<<SQL
|
||||
INSERT INTO `cwsvjudo`.`achievements` (name, description)
|
||||
VALUES (:name, :description);
|
||||
SQL;
|
||||
$params=[
|
||||
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
|
||||
':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR],
|
||||
];
|
||||
dbQuery($db, $query, $params, ['dontFetch'=>true]);
|
||||
return;
|
||||
}
|
||||
|
||||
function updateAchievement($db, $achievementId, $name, $description, $rootId, $level){
|
||||
$query = <<<SQL
|
||||
UPDATE `cwsvjudo`.`achievements`
|
||||
SET name=:name, description=:description, rootId=:rootId, level=:level
|
||||
WHERE `id`=:achievementId;
|
||||
SQL;
|
||||
$params=[
|
||||
':name' => ['value'=>$name, 'data_type'=>PDO::PARAM_STR],
|
||||
':description' => ['value'=>$description, 'data_type'=>PDO::PARAM_STR],
|
||||
':rootId' => ['value'=>$rootId, 'data_type'=>PDO::PARAM_INT],
|
||||
':level' => ['value'=>$level, 'data_type'=>PDO::PARAM_INT],
|
||||
':achievementId' => ['value'=>$achievementId, 'data_type'=>PDO::PARAM_INT],
|
||||
];
|
||||
dbQuery($db, $query, $params, ['dontFetch'=>true]);
|
||||
return;
|
||||
}
|
||||
|
||||
function canUserGetAchievementToday($db, $userId){
|
||||
$achievements = getUsersAchievements($db, $userId);
|
||||
foreach($achievements as $a){
|
||||
if( date('Ymd') == date('Ymd', strtotime($a['timestamp'])) )
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user