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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user