"#FFAE00", 'highlightColor'=>"#FF8100", 'buttonColor'=>"#291670"]){ //$colorTypes = ["backgroundColor", "highlightColor", "buttonColor"]; $defaultColors =[ // unterstützte Farben und ihre Standardbelegung 'backgroundColor'=> "#FFAE00", // Hintergrundfarbe 'highlightColor'=>"#FF8100", // Markierungen zum hervorheben 'buttonColor'=>"#291670" // Interaktionsflächen ]; // Abfragen der gesamten Konfiguration des Users $tmpBindArray = array( ":userId"=>array('value'=>$userId, 'data_type'=>PDO::PARAM_INT) ); // echo("DBG: setColors-userId".strval($userId)); // echo("DBG: setColors-BindArray");var_dump($tmpBindArray); $usersConfig = dbQuery( $dbConn, "SELECT config FROM `wkParticipo_Users` WHERE id = :userId;", //"SELECT * FROM `wkParticipo_Users` WHERE id = :userId;", array( ":userId"=>array('value'=>(int)$userId, 'data_type'=>PDO::PARAM_INT) ) ); // echo("DBG: setUserColors-usersConfig"); var_dump($usersConfig); // - json-formatierten Konfigurationsstring in ein Assoziatives Array // laden // - Im Fehlerfalle ein leeres Array weitergeben try{ $usersConfig = json_decode($usersConfig[0]['config'], true); if( empty($usersConfig) ) throw new Exception("No usersConfig available!"); } catch(Exception $e) { echo("Message: " .$e->getMessage()); $usersConfig = array(); } // Nicht mehr unterstützte Farben entfernen foreach($usersConfig['colors'] as $colorType=>$colorValue){ // echo("DBG: setUserColors-colorType: ".$colorType); // echo("DBG: setUserColors-defaultColors:"); var_dump($defaultColors); if( !array_key_exists($colorType, $defaultColors) ){ //echo("DBG: ".$colorType." is no defaultColor! DefaultColors are\n");var_dump($defaultColors); unset($usersConfig['colors'][$colorType]); } } // - Neue Farben setzen, sofern sie validiert werden können // - Es werden nur Farben übernommen, die auch unterstützt werden foreach($defaultColors as $key=>$value){ // Alle unterstützten Farben testen if( !preg_match("/^#(?:[0-9a-fA-F]{3}){1,2}$/", $wantedColors[$key]) ){ //echo("DBG: ".$wantedColors[$key]." doesn't regmatches to a color!"); $usersConfig['colors'][$key] = $value; } else{ $usersConfig['colors'][$key] = $wantedColors[$key]; } } // Die aktualiserte Fassung der Konfiguration abspeicher //echo("DBG: update\n"); var_dump($usersConfig); dbQuery( $dbConn, "UPDATE `wkParticipo_Users` SET config = :jsonConfig WHERE id = :userId;", array( ":jsonConfig"=>array('value'=>json_encode($usersConfig), 'data_type'=>PDO::PARAM_STR), ":userId"=>array('value'=>$userId, 'data_type'=>PDO::PARAM_INT) ) ); // Auch die aktuellen sessionDaten noch anpassen $_SESSION['user']['userConfig']['colors'] = $usersConfig['colors']; } function apiActionSetUserColors($parameter){ //echo("DBG: apiActionSetColors-parameter:");var_dump($parameter); // Inputvalidierung try{ if( !is_positive_integer($parameter['userId']) ) throw new Exception("EXP: userId has to be a positive integer, but is !"); if( !is_array($parameter['colors']) ) throw new Exception("EXP: colors not given in an array!"); setUserColors(getCwsvJudoDbConn(), $parameter['userId'], $parameter['colors']); } catch(Exception $e){ echo("apiActionSetUserColors - ".$e->getMessage()."\n"); echo("parameter:"); var_dump($parameter); } return; } // Als allererstes den Header setzen, damit wir auch Fehlermeldungen // ausgeben können if(isset($_POST['backtoUrl'])){ if (filter_var($_POST['backtoUrl'], FILTER_VALIDATE_URL)) { header("Location: ".$_POST['backtoUrl']); } else { header("Location: ".$defaultValues['backtoUrl']); } } //echo("DBG: api-POST"); var_dump($_POST); /// @todo übersichtlichere Variante gewüscht if($_POST['action'] == "setUserColors"){ apiActionSetUserColors(array('userId'=>$_POST['parameter']['userId'], 'colors'=>$_POST['parameter']['colors'])); } ?>