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

4
module/api/.htaccess Normal file
View File

@@ -0,0 +1,4 @@
<Files "notifications-c5c54-a9705bfea23c.json">
Order allow,deny
Deny from all
</Files>

View File

@@ -2,34 +2,36 @@
error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR);
ini_set('display_errors', 1);
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([
@@ -55,8 +57,10 @@ 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);
$json = json_encode([
@@ -73,18 +77,18 @@ function send($token, $username, $message){
"apns" => [
"payload" => [
"aps" => [
"content-available" => 1 // Требуется для пробуждения приложения на iOS
"content-available" => 1
]
]
]
]
]);
]);
$url = "https://fcm.googleapis.com/v1/projects/notifications-c5c54/messages:send";
$ch = curl_init($url);
$headers = [
'Authorization: Bearer ' . $accessToken,
'Content-Type: application/json; charset=UTF-8',
@@ -99,7 +103,7 @@ function send($token, $username, $message){
curl_close($ch);
}
@@ -111,7 +115,7 @@ $db_port = $env['MAIN_MYSQL_DB_PORT'];
$db_user = $env['MAIN_MYSQL_DB_USER'];
$db_pass = $env['MAIN_MYSQL_DB_PASS'];
$db_schema = $env['MAIN_MYSQL_DB_SCHEMA'];
$conn = new mysqli($db_host, $db_user, $db_pass, $db_schema, $db_port);
@@ -130,16 +134,16 @@ if ($result_collections->num_rows > 0) {
print_r($row["description"]);
print_r($row["id"]);
$article_name = $row["description"];
echo "<br>--------------------<br>";
$department_ids = [];
$role_ids = [];
$query_get_department = "SELECT * FROM intranet_teil_link WHERE content_type = 'collection' AND content_id = " . $row['id'];
$result_department = $conn->query($query_get_department);
while ($row_department = $result_department->fetch_assoc()) {
$department_ids[] = $row_department['main_department_id'];
var_dump($row_department);
@@ -149,19 +153,19 @@ if ($result_collections->num_rows > 0) {
$query_get_role = "SELECT * FROM intranet_role_link WHERE content_type = 'collection' AND content_id = " . $row['id'];
$result_role = $conn->query($query_get_role);
while ($row_role = $result_role->fetch_assoc()) {
$role_ids[] = $row_role['main_role_id'];
var_dump($row_role);
}
// Create comma-separated strings
$abteilung = implode(',', $department_ids);
$role = implode(',', $role_ids);
$abteilungArray = explode(',', $abteilung);
$roleArray = explode(',', $role);
$mergedArray = [];
foreach ($abteilungArray as $abteilung) {
@@ -173,7 +177,7 @@ if ($result_collections->num_rows > 0) {
}
}
$tokenArray = [];
// print_r($mergedArray);
// print_r($abteilungArray);
@@ -181,12 +185,12 @@ if ($result_collections->num_rows > 0) {
var_dump($mergedArray);
foreach ($mergedArray as $element) {
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'];
@@ -195,12 +199,12 @@ if ($result_collections->num_rows > 0) {
var_dump($sql);
$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 = [
@@ -210,7 +214,7 @@ if ($result_collections->num_rows > 0) {
];
if (!in_array($contact_info, $tokenArray, true)) {
$tokenArray[] = $contact_info;
} else {
// echo "Already in array";
}
@@ -226,7 +230,7 @@ if ($result_collections->num_rows > 0) {
// send($token['token'], "Neuer Beitrag im Intranet", $article_name);
// }
}
} else {
echo "No collections found for today.";

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 = [

View File

@@ -8,34 +8,36 @@ $domain = $_POST['domain'];
$news_id = $_POST["news_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([
@@ -65,7 +67,8 @@ function generateJWT($jsonKeyPath) {
$jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
// $jsonKeyPath = '../../notifications-c5c54-a9705bfea23c.json';
$jsonKeyPath = 'secrets/notifications-c5c54-a9705bfea23c.json';
$accessToken = getAccessToken($jsonKeyPath);
@@ -75,7 +78,7 @@ $accessToken = getAccessToken($jsonKeyPath);
$url = 'https://fcm.googleapis.com/v1/projects/notifications-c5c54/messages:send';
$host = $_SERVER['HTTP_HOST'];
// HERE NEW LOGIC
@@ -84,31 +87,31 @@ $mysql_con = new mysqli("localhost", "web4_intranet", "WewJedjuAbEynk3", "web4_i
$allowed_contact_ids = [];
$all_mandants_query = "SELECT main_mandant_id FROM `main_collection_mandant_link` WHERE main_collection_id = ".(int)$news_id;
$all_mandants_query = "SELECT main_mandant_id FROM `main_collection_mandant_link` WHERE main_collection_id = " . (int) $news_id;
$sql_all_mandants = @mysqli_query($mysql_con, $all_mandants_query);
while ($row = @mysqli_fetch_assoc($sql_all_mandants)) {
$all_mandants[] = $row["main_mandant_id"];
}
$all_departments_query = "SELECT main_department_id FROM `main_collection_department_link` WHERE main_collection_id = ".(int)$news_id;
$all_departments_query = "SELECT main_department_id FROM `main_collection_department_link` WHERE main_collection_id = " . (int) $news_id;
$sql_all_departments = @mysqli_query($mysql_con, $all_departments_query);
while ($row = @mysqli_fetch_assoc($sql_all_departments)) {
$all_departments[] = $row["main_department_id"];
}
$all_fachbereich_query = "SELECT main_fachbereich_id FROM `main_collection_fachbereich_link` WHERE main_collection_id = ".(int)$news_id;
$all_fachbereich_query = "SELECT main_fachbereich_id FROM `main_collection_fachbereich_link` WHERE main_collection_id = " . (int) $news_id;
$sql_all_fachbereichs = @mysqli_query($mysql_con, $all_fachbereich_query);
while ($row = @mysqli_fetch_assoc($sql_all_fachbereichs)) {
$all_fachbereichs[] = $row["main_fachbereich_id"];
}
$all_einrichtungen_query = "SELECT main_einricht_id FROM `main_collection_einricht_link` WHERE main_collection_id = ".(int)$news_id;
$all_einrichtungen_query = "SELECT main_einricht_id FROM `main_collection_einricht_link` WHERE main_collection_id = " . (int) $news_id;
$sql_all_einrichtungen = @mysqli_query($mysql_con, $all_einrichtungen_query);
while ($row = @mysqli_fetch_assoc($sql_all_einrichtungen)) {
$all_einrichtungen[] = $row["main_einricht_id"];
}
$all_role_query = "SELECT main_role_id FROM `main_collection_role_link` WHERE main_collection_id = ".(int)$news_id;
$all_role_query = "SELECT main_role_id FROM `main_collection_role_link` WHERE main_collection_id = " . (int) $news_id;
$sql_all_rolles = @mysqli_query($mysql_con, $all_role_query);
while ($row = @mysqli_fetch_assoc($sql_all_rolles)) {
$all_rolles[] = $row["main_role_id"];
@@ -125,7 +128,7 @@ while ($row = mysqli_fetch_assoc($sql_get_all_contacts)) {
$count++;
// 1. Mandant
if (!empty($all_mandants) && !in_array($row["main_mandant_id"], $all_mandants)) {
continue;
continue;
}
// 2. Department
@@ -151,7 +154,7 @@ while ($row = mysqli_fetch_assoc($sql_get_all_contacts)) {
$allowed_contact_ids = array_unique($allowed_contact_ids);
foreach ($allowed_contact_ids as $cid) {
$query_contact_token = "SELECT * FROM token_contact WHERE contact_id = ".(int)$cid." AND in_system = 1 ORDER BY id DESC LIMIT 1";
$query_contact_token = "SELECT * FROM token_contact WHERE contact_id = " . (int) $cid . " AND in_system = 1 ORDER BY id DESC LIMIT 1";
$sql_contactn_token = @mysqli_query($mysql_con, $query_contact_token);
@@ -159,17 +162,19 @@ foreach ($allowed_contact_ids as $cid) {
$contactId = trim($row_token['contact_id'] ?? '');
$token = trim($row_token['token'] ?? '');
$token = trim($row_token['token'] ?? '');
if ($contactId === '' || $contactId === 'undefined' ||
$token === '' || $token === 'undefined') {
if (
$contactId === '' || $contactId === 'undefined' ||
$token === '' || $token === 'undefined'
) {
continue;
}
$data = [
'message' => [
'token' => $row_token["token"],
'token' => $row_token["token"],
'notification' => [
'title' => $title,
'body' => $body,