Vue global collaborateur pour manager
This commit is contained in:
@@ -13,7 +13,6 @@ if ($conn->connect_error) {
|
||||
die(json_encode(["success" => false, "message" => "Erreur DB: " . $conn->connect_error]));
|
||||
}
|
||||
|
||||
// --- Authentification (client credentials) ---
|
||||
$tenantId = "9840a2a0-6ae1-4688-b03d-d2ec291be0f9";
|
||||
$clientId = "4bb4cc24-bac3-427c-b02c-5d14fc67b561";
|
||||
$clientSecret = "ViC8Q~n4F5YweE18wjS0kfhp3kHh6LB2gZ76_b4R";
|
||||
@@ -42,8 +41,9 @@ if (!$accessToken) {
|
||||
}
|
||||
|
||||
// --- ID du groupe cible (Ensup-Groupe) ---
|
||||
$groupId = "c1ea877c-6bca-4f47-bfad-f223640813a0"; // 🔹 Mets l'Object ID de ton groupe ici
|
||||
$groupId = "c1ea877c-6bca-4f47-bfad-f223640813a0";
|
||||
|
||||
// --- Récupérer infos du groupe ---
|
||||
$urlGroup = "https://graph.microsoft.com/v1.0/groups/$groupId?\$select=id,displayName,description,mail,createdDateTime";
|
||||
$ch = curl_init($urlGroup);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $accessToken"]);
|
||||
@@ -57,31 +57,6 @@ if (!isset($group["id"])) {
|
||||
}
|
||||
|
||||
$displayName = $group["displayName"] ?? "";
|
||||
$description = $group["description"] ?? "";
|
||||
$mail = $group["mail"] ?? "";
|
||||
$createdAt = null;
|
||||
if (!empty($group["createdDateTime"])) {
|
||||
$dt = new DateTime($group["createdDateTime"]);
|
||||
$createdAt = $dt->format("Y-m-d H:i:s"); // format MySQL
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// --- Insérer / mettre à jour le groupe dans EntraGroups ---
|
||||
$stmt = $conn->prepare("INSERT INTO EntraGroups (Id, DisplayName, Description, Mail, CreatedAt, UpdatedAt, SyncDate, IsActive)
|
||||
VALUES (?, ?, ?, ?, ?, NOW(), NOW(), 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
DisplayName=?, Description=?, Mail=?, UpdatedAt=NOW(), SyncDate=NOW(), IsActive=1");
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("ssssssss",
|
||||
$groupId, $displayName, $description, $mail, $createdAt,
|
||||
$displayName, $description, $mail
|
||||
);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --- Récupérer les membres du groupe ---
|
||||
$urlMembers = "https://graph.microsoft.com/v1.0/groups/$groupId/members?\$select=id,givenName,surname,mail,department,jobTitle";
|
||||
@@ -100,23 +75,25 @@ foreach ($members as $m) {
|
||||
$nom = $m["surname"] ?? "";
|
||||
$email = $m["mail"] ?? "";
|
||||
$service = $m["department"] ?? "";
|
||||
$role = "Collaborateur"; // par défaut
|
||||
|
||||
if (!$email) continue;
|
||||
|
||||
// Insertion ou mise à jour de l’utilisateur
|
||||
$stmt = $conn->prepare("INSERT INTO CollaborateurAD (entraUserId, prenom, nom, email, service, role)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE prenom=?, nom=?, email=?, service=?, role=?");
|
||||
ON DUPLICATE KEY UPDATE prenom=?, nom=?, email=?, service=?");
|
||||
if ($stmt) {
|
||||
$stmt->bind_param("sssssssssss",
|
||||
$role = "Collaborateur"; // attribué uniquement si nouvel utilisateur
|
||||
$stmt->bind_param("ssssssssss",
|
||||
$entraUserId, $prenom, $nom, $email, $service, $role,
|
||||
$prenom, $nom, $email, $service, $role
|
||||
$prenom, $nom, $email, $service
|
||||
);
|
||||
$stmt->execute();
|
||||
$usersInserted++;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Réponse finale ---
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => "Synchronisation terminée",
|
||||
|
||||
Reference in New Issue
Block a user