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