Init Git Prod Mars 2026
This commit is contained in:
commit
d81efe93b1
362 files changed
+86627
No files matched your search
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'client_id' => getenv('GOOGLE_CLIENT_ID') ?: '',
|
||||
'client_secret' => getenv('GOOGLE_CLIENT_SECRET') ?: '',
|
||||
'redirect_uri' => 'https://uslugi.fr/google/oauth_callback.php',
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
require_once __DIR__ .'/../../includes/bootstrap_global.php';
|
||||
require_once '../vendor/autoload.php';
|
||||
$config = require 'config_google.php';
|
||||
|
||||
$client = new Google_Client();
|
||||
$client->setClientId($config['client_id']);
|
||||
$client->setClientSecret($config['client_secret']);
|
||||
$client->setRedirectUri($config['redirect_uri']);
|
||||
$client->addScope(Google_Service_Calendar::CALENDAR_EVENTS);
|
||||
$client->setAccessType('offline'); // important pour refresh_token
|
||||
$client->setPrompt('consent');
|
||||
|
||||
$auth_url = $client->createAuthUrl();
|
||||
header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
|
||||
exit;
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../public/includes/init_praticien.php';
|
||||
|
||||
use Google\Client;
|
||||
use Google\Service\Calendar;
|
||||
use Google\Service\Calendar\Event;
|
||||
|
||||
function envoyerVersGoogleCalendar($praticien_id, $summary, $description, $start_iso, $end_iso = null, $duree_minutes = 60) {
|
||||
global $pdo;
|
||||
|
||||
$config = require 'config_google.php';
|
||||
|
||||
// 1. Récupérer le token Google du praticien
|
||||
$stmt = $pdo->prepare("SELECT * FROM google_tokens WHERE praticien_id = ?");
|
||||
$stmt->execute([$praticien_id]);
|
||||
$row = $stmt->fetch();
|
||||
|
||||
if (!$row) {
|
||||
error_log("❌ Aucun token trouvé pour praticien ID $praticien_id");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. Préparer le client Google
|
||||
$client = new Client();
|
||||
$client->setClientId($config['client_id']);
|
||||
$client->setClientSecret($config['client_secret']);
|
||||
$client->setAccessToken([
|
||||
'access_token' => $row['access_token'],
|
||||
'expires_in' => 3600,
|
||||
'refresh_token' => $row['refresh_token'],
|
||||
'created' => $row['expires_at'] - 3600
|
||||
]);
|
||||
|
||||
// 3. Rafraîchir le token si expiré
|
||||
if ($client->isAccessTokenExpired()) {
|
||||
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
|
||||
|
||||
$new_token = $client->getAccessToken();
|
||||
$stmt = $pdo->prepare("UPDATE google_tokens SET access_token = ?, expires_at = ? WHERE praticien_id = ?");
|
||||
$stmt->execute([
|
||||
$new_token['access_token'],
|
||||
time() + $new_token['expires_in'],
|
||||
$praticien_id
|
||||
]);
|
||||
}
|
||||
|
||||
// 4. Calculer l'heure de fin si elle n'est pas transmise
|
||||
if (!$end_iso) {
|
||||
$start = new DateTime($start_iso);
|
||||
$start->modify("+{$duree_minutes} minutes");
|
||||
$end_iso = $start->format(DateTime::ATOM);
|
||||
}
|
||||
|
||||
// 🔍 Log pour debug (facultatif)
|
||||
error_log("🟢 Google Sync - START: $start_iso");
|
||||
error_log("🟢 Google Sync - END : $end_iso");
|
||||
|
||||
// 5. Préparer le service et l'événement
|
||||
$calendar = new Calendar($client);
|
||||
|
||||
$event = new Event([
|
||||
'summary' => $summary,
|
||||
'description' => $description,
|
||||
'start' => [
|
||||
'dateTime' => $start_iso,
|
||||
'timeZone' => 'Europe/Paris'
|
||||
],
|
||||
'end' => [
|
||||
'dateTime' => $end_iso,
|
||||
'timeZone' => 'Europe/Paris'
|
||||
]
|
||||
]);
|
||||
|
||||
try {
|
||||
$calendar->events->insert('primary', $event);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
error_log("❌ Erreur Google Calendar : " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
session_start();
|
||||
require_once '../vendor/autoload.php';
|
||||
require_once __DIR__ . '/../public/includes/init_praticien.php';
|
||||
$config = require 'config_google.php';
|
||||
|
||||
$client = new Google_Client();
|
||||
$client->setClientId($config['client_id']);
|
||||
$client->setClientSecret($config['client_secret']);
|
||||
$client->setRedirectUri($config['redirect_uri']);
|
||||
|
||||
if (isset($_GET['code'])) {
|
||||
$client->authenticate($_GET['code']);
|
||||
$token = $client->getAccessToken();
|
||||
|
||||
if (!isset($_SESSION['reference_id']) || $_SESSION['role'] !== 'praticien') {
|
||||
die("Utilisateur non connecté.");
|
||||
}
|
||||
|
||||
$praticien_id = $_SESSION['reference_id'];
|
||||
|
||||
// Vérifier si un token existe déjà
|
||||
$stmt = $pdo->prepare("SELECT id FROM google_tokens WHERE praticien_id = ?");
|
||||
$stmt->execute([$praticien_id]);
|
||||
|
||||
$data = [
|
||||
'access_token' => $token['access_token'],
|
||||
'refresh_token' => $token['refresh_token'] ?? '',
|
||||
'expires_at' => time() + $token['expires_in']
|
||||
];
|
||||
|
||||
if ($stmt->fetch()) {
|
||||
$stmt = $pdo->prepare("UPDATE google_tokens SET access_token = ?, refresh_token = ?, expires_at = ? WHERE praticien_id = ?");
|
||||
} else {
|
||||
$stmt = $pdo->prepare("INSERT INTO google_tokens (access_token, refresh_token, expires_at, praticien_id) VALUES (?, ?, ?, ?)");
|
||||
}
|
||||
|
||||
$stmt->execute([$data['access_token'], $data['refresh_token'], $data['expires_at'], $praticien_id]);
|
||||
|
||||
echo <<<HTML
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-center align-items-center" style="min-height:48vh;">
|
||||
<div class="card shadow-lg border-0 text-center" style="max-width:720px; width:100%; border-radius:18px;">
|
||||
<div class="card-body p-4">
|
||||
<div class="display-6 mb-2">✅</div>
|
||||
<h2 class="h4 mb-2">Подключение к Google Календарю выполнено успешно</h2>
|
||||
<p class="text-muted mb-4">Вы можете вернуться в календарь или запустить синхронизацию прямо сейчас.</p>
|
||||
<div class="d-flex gap-2 justify-content-center">
|
||||
<a href="/synchroniser_google.php" class="btn btn-primary btn-lg rounded-pill">
|
||||
Синхронизировать календарь
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
} else {
|
||||
echo <<<HTML
|
||||
<div class="container py-4">
|
||||
<div class="alert alert-danger text-center mx-auto" role="alert" style="max-width:720px;">
|
||||
❌ Не передан код авторизации Google. Попробуйте выполнить вход ещё раз.
|
||||
</div>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
?>
|
||||
|
||||
<link href="/css/bootstrap.min.css" rel="stylesheet">
|
||||
Reference in new issue
Block a user