Abgleich mit dem Stand auf dem Server. Irgendwie sind hier Commits verloren/nie gemacht worden.

This commit is contained in:
marko
2019-12-24 14:22:53 +01:00
parent 18394392de
commit f60fef0904
32 changed files with 876 additions and 115 deletions

View File

@@ -4,52 +4,12 @@ ini_set('display_errors',1);
$basePath = "/users/cwsvjudo/www";
require_once($basePath."/config/cwsvJudo.config.php");
require_once($basePath."/ressourcen/phpLib/cwsvJudo/miscAssis.php");
function dbQuery($aDbConnection, $aQueryString, $aBindArray = array(), $someOptions = array( "dbCharset" => "ISO-8859-1", "outCharset" => "UTF-8" ) ){
//echo("Doing ".$aQueryString);
var_dump($aBindArray);
if( empty($someOptions['dbCharset']) ) $someOptions['dbCharset'] = "ISO-8859-1";
if( empty($someOptions['outCharset']) ) $someOptions['outCharset'] = "UTF-8";
/// @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.
try{
$pdoStatement = $aDbConnection->prepare( $aQueryString );
foreach( $aBindArray as $bindName => $bind ){
$pdoStatement->bindValue(
$bindName,
$bind['value'],
(isset($bind['data_type'])?$bind['data_type']:PDO::PARAM_STR)
);
}
$pdoStatement->execute();
$ret = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "<br/>";
return null;
}
//var_dump($ret);
// Zeichensatzkonvertierung
if( is_array($ret) ){
foreach($ret as &$entry){
array_walk(
$entry,
function (&$value, $key, $someOptions) {
$value = iconv($someOptions['dbCharset'], $someOptions['outCharset'], $value);
},
$someOptions
);
}
}
return $ret;
}
/// Ein Array als htmlTabelle darstellen
function array2htmlTableString($anArray){
$ret = "";
if( !is_array($anArray) )
@@ -67,29 +27,83 @@ $ret = "";
return $ret;
}
/// einem User ein Attribut zuordnen
///
/// @param $aDbConnection PDO-Datenbankverbindung, die benutzt werden soll
/// @param $anUserId ID des Users, der das Attribut erhalten soll
/// @param $anAttributeId ID des zu vergebenden Attributes
///
/// - Es erfolgt keine Kontrolle, ob:
/// - die AttributId überhaupt existiert,
/// - ob die UserId überhaupt existiert,
/// - ob der User das Attribut bereits hat,
function giveUserAnUserAttribute($aDbConnection, $anUserId, $anAttributeId){
echo("Entering giveUserAnUserAttribute!");
withdrawUsersAttribute($aDbConnection, $anUserId, $anAttributeId);
try{
dbQuery(
$aDbConnection,
"INSERT INTO `wkParticipo_user<=>userAttributes` (userId, attributeId) VALUES (:userId, :attributeId);",
array(
':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
':attributeId'=>array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT)
':userId' => array('value'=>$anUserId, 'data_type'=>PDO::PARAM_INT),
':attributeId'=> array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT)
)
);
}
catch(PDOException $db_error){
print "Error!: " . $db_error->getMessage() . "<br/>";
print "Error!: " . $db_error->getMessage() . "<br/>queryString: ".$queryString."<br />"; var_dump($bindArray);
}
return;
}
/// einem User ein Attribut entziehen
function withdrawUsersAttribute($aDbConnection, $anUserId, $anAttributeId, $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("withdrawUsersAttribute: userId must be positive integer!");
}
if( is_positive_integer($anAttributeId) ){
$bindArray[':attributeId'] = array('value'=>$anAttributeId, 'data_type'=>PDO::PARAM_INT);
}
else{
throw new InvalidArgumentException("withdrawUsersAttribute: attributeid must be positive integer");
}
if( is_positive_integer( $limit ) ){
$bindArray[':limit'] = array('value' => $limit, 'data_type' => PDO::PARAM_INT);
}
// Zusammenstellen der Query
$queryString =
"DELETE FROM `wkParticipo_user<=>userAttributes` ".
"WHERE `userId`=:userId ".
"AND `attributeId`=:attributeId".
(is_positive_integer( $limit )?" LIMIT :limit":"").
";";
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 withdrawUsersAttribute
#exit();
var_dump($_GET);
$actions = ["giveUserAnUserAttribute"];
$actions = ["giveUserAnUserAttribute", "withdrawUsersAttribute"];
$dbConn = getCwsvJudoDbConn();
@@ -98,16 +112,23 @@ $dbConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
if(isset($_GET['action'])){
switch($_GET['action']){
case "giveUserAnUserAttribute":
//echo("Doing giveUserAnUserAttribute!");
try{
giveUserAnUserAttribute($dbConn, intval($_GET['userIdToGetAttribute']), intval($_GET['attributeIdToGet']));
giveUserAnUserAttribute($dbConn, intval($_GET['userId']), intval($_GET['attributeId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
case "withdrawUsersAttribute":
try{
withdrawUsersAttribute($dbConn, intval($_GET['userId']), intval($_GET['attributeId']));
}
catch(Exception $e){
print("UPS: ".$e->getMessage());
}
break;
default:
echo("Ungültige Aktion erwünscht!");
echo("Ungültige Aktion (".$_GET['action'].") erwünscht!");
break;
}
}
@@ -141,7 +162,7 @@ $userAttributes =
</select>
</label>
<label>User:
<select name="userIdToGetAttribute">
<select name="userId">
<option disabled selected value> -- User auswählen -- </option>
<?php
foreach($users as $user)
@@ -150,7 +171,7 @@ $userAttributes =
</select>
</label>
<label>Attribut:
<select name="attributeIdToGet">
<select name="attributeId">
<option disabled selected value> -- Attribut auswählen -- </option>
<?php
foreach($userAttributes as $userAttribute)
@@ -164,7 +185,7 @@ $userAttributes =
<?php echo(array2htmlTableString($userAttributes));?>
<?php
foreach($userAttributes as $userAttribute){
$attributedUsers =
$attributedUsers =
dbQuery(
$dbConn,
"SELECT * FROM wkParticipo_Users, `wkParticipo_user<=>userAttributes` WHERE wkParticipo_Users.id = `wkParticipo_user<=>userAttributes`.userId AND `wkParticipo_user<=>userAttributes`.attributeId=:attributeId;",