Files
cwsvJudo/homepage/participo/api/users.php
2025-12-07 20:40:33 +01:00

83 lines
2.3 KiB
PHP

<?php
/** @var array $CONFIG basic configurations (defined via bootstraping) */
/** @var array $SECRETS passwords and other stuff worth of protection (defined via bootstraping) */
require_once "bootstrap.php";
require_once "participoLib/participo.php";
function init($config, $secrets)
{
dbConnector::setOptions([
"dbCharset" => $config["dbCharset"] ?? "UTF-8",
"outCharset" => $config["outCharset"] ?? "UTF-8",
]);
dbConnector::connect(
$config["db"]["host"],
$config["db"]["name"],
$config["db"]["user"],
$secrets["db"][$config["db"]["user"]],
);
}
function authorize()
{
$allowKey = null;
if (array_key_exists("HTTP_AUTHORIZATION", $_SERVER)) {
if (!empty($_SERVER["HTTP_AUTHORIZATION"])) {
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if ($auth[0] = "Basic") {
$allowKey = ApiKey::loadFromDb($auth[1]);
}
}
}
if (!$allowKey || !$allowKey->isValidFor("api")) {
die(
json_encode([
"success" => false,
"reason" => "apiKey not sufficient or no api key provided",
])
);
}
}
function get()
{
$wkSqlQuery =
"SELECT DISTINCT" .
" `wkParticipo_Users`.* " .
" FROM `wkParticipo_Users`" .
" JOIN `vormundschaft`" .
" ON `wkParticipo_Users`.`id` =`vormundschaft`.`userId`" .
" JOIN `wkParticipo_user<=>userAttributes`" .
" ON `wkParticipo_user<=>userAttributes`.`userId` = `vormundschaft`.`kidId`" .
" WHERE `wkParticipo_user<=>userAttributes`.`attributeId` = 4" .
" ORDER BY `wkParticipo_Users`.`id` ASC;";
$wkSqlResponse = dbConnector::query($wkSqlQuery);
// Postprocessing
// - convert the comma separated list into an array
foreach ($wkSqlResponse as &$user) {
$user["eMail"] = explode(",", $user["eMail"]);
foreach ($user["eMail"] as &$email) {
$email = trim($email);
}
}
return $wkSqlResponse;
}
init($CONFIG["cwsvJudo"], $SECRETS["cwsvJudo"]);
authorize();
$wkSqlResponse = get();
// Sending Response
// - setting header
header("Content-Type: application/json");
// - sending body payload
echo json_encode($wkSqlResponse);
// exit(0);
?>