Refactor contact management functions and remove phpinfo.php

- Updated formatting and structure of functions in edit_contact.inc.php for better readability and consistency.
- Added comments to clarify the purpose of certain code sections, especially regarding mandant handling.
- Removed the deprecated phpinfo.php file to clean up the codebase.
This commit is contained in:
2026-05-11 08:54:44 +02:00
parent 8749bc7994
commit 52ca9249c3
64 changed files with 13445 additions and 3562 deletions

View File

@@ -11,34 +11,36 @@ $domain = $_POST['domain'];
$input_collection_id = $_POST['input_collection_id'];
function getAccessToken($jsonKeyPath) {
function getAccessToken($jsonKeyPath)
{
try {
$jwt = generateJWT($jsonKeyPath);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt,
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
$jwt = generateJWT($jsonKeyPath);
$response = curl_exec($ch);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://oauth2.googleapis.com/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt,
]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/x-www-form-urlencoded',
]);
$jsonResponse = json_decode($response, true);
$response = curl_exec($ch);
curl_close($ch);
$jsonResponse = json_decode($response, true);
} catch (\Throwable $th) {
echo $th;
}
return $jsonResponse['access_token'];
}
function generateJWT($jsonKeyPath) {
function generateJWT($jsonKeyPath)
{
$jsonKey = json_decode(file_get_contents($jsonKeyPath), true);
$header = base64_encode(json_encode([
@@ -64,13 +66,15 @@ function generateJWT($jsonKeyPath) {
return $signatureInput . '.' . $signature;
}
function send($token, $username, $message){
$jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
function send($token, $username, $message)
{
// $jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
$jsonKeyPath = 'secrets/notifications-c5c54-a9705bfea23c.json';
$accessToken = getAccessToken($jsonKeyPath);
/*
{
"message": {
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoxLCJzaG9ydGN1dCI6ImVhIn0.mcO9WT0VV_lXJp48mu3XF9E9bKEdCitoKogAk067LwQ",
@@ -83,7 +87,7 @@ function send($token, $username, $message){
}
}
}
*/
$json = json_encode([
@@ -100,12 +104,12 @@ function send($token, $username, $message){
"apns" => [
"payload" => [
"aps" => [
"content-available" => 1 // Требуется для пробуждения приложения на iOS
"content-available" => 1
]
]
]
]
]);
]);
@@ -114,12 +118,12 @@ function send($token, $username, $message){
$ch = curl_init($url);
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json; charset=UTF-8',
@@ -172,7 +176,7 @@ if ($result->num_rows > 0) {
echo "collection not found";
die();
}
$tokenArray = [];
// print_r($mergedArray);
// print_r($abteilungArray);
@@ -180,24 +184,24 @@ $tokenArray = [];
foreach ($mergedArray as $element) {
// $sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'] . " and main_role_id = " . $element['role'];
// var_dump($sql);
if ( $element['abteilung'] == "" && $element['role'] == "") {
if ($element['abteilung'] == "" && $element['role'] == "") {
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1";
} else if ( $element['abteilung'] == "") {
} else if ($element['abteilung'] == "") {
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_role_id = " . $element['role'];
} else if ( $element['role'] == "") {
} else if ($element['role'] == "") {
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'];
} else {
$sql = "SELECT DISTINCT main_contact_id FROM main_contact_department WHERE main_mandant_id = 1 AND active = 1 and main_department_id = " . $element['abteilung'] . " and main_role_id = " . $element['role'];
}
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$query = "SELECT DISTINCT main_contact.id, main_contact.name, token_contact.token as 'token' FROM main_contact LEFT JOIN token_contact ON token_contact.contact_id = main_contact.id WHERE main_contact.id = '".$row['main_contact_id']."'";
while ($row = $result->fetch_assoc()) {
$query = "SELECT DISTINCT main_contact.id, main_contact.name, token_contact.token as 'token' FROM main_contact LEFT JOIN token_contact ON token_contact.contact_id = main_contact.id WHERE main_contact.id = '" . $row['main_contact_id'] . "'";
// var_dump($query);
$user_result = $conn->query($query);
if ($user_result->num_rows > 0) {
while($contact = $user_result->fetch_assoc()) {
while ($contact = $user_result->fetch_assoc()) {
if ($contact['token'] != null && $contact['token'] != "") {
// send($contact['token'], "Intranet", "Neuer Beitrag im Intranet");
$contact_info = [