Import initial du projet Production
This commit is contained in:
132
Controleur/ControleurAjaxgenererqrcode.php
Normal file
132
Controleur/ControleurAjaxgenererqrcode.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
require_once 'vendor/autoload.php';
|
||||
require_once 'Framework/Controleur.php';
|
||||
|
||||
/*
|
||||
require_once 'Modele/Qrcodemodele.php';
|
||||
|
||||
use Endroid\QrCode\QrCode;
|
||||
use Endroid\QrCode\Writer\PngWriter;
|
||||
use Endroid\QrCode\Color\Color;
|
||||
use Endroid\QrCode\ErrorCorrectionLevel;
|
||||
*/
|
||||
|
||||
class ControleurAjaxgenererqrcode extends Controleur {
|
||||
// private $qrcode;
|
||||
|
||||
public function __construct() {
|
||||
// $this->qrcode = new Qrcodemodele();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
/*
|
||||
header('Content-Type: application/json');
|
||||
|
||||
try {
|
||||
$matricule = $this->requete->getParametreFormulaire("matricule");
|
||||
|
||||
|
||||
|
||||
if (empty($matricule)) {
|
||||
throw new Exception("Matricule manquant");
|
||||
}
|
||||
|
||||
$success = $this->genererEtStockerQRCodeFichier($matricule);
|
||||
|
||||
|
||||
$message = (isset($_SESSION['lang']) && $_SESSION['lang']=="en_US") ? "QR code generated successfully!" : "QR code généré avec succès !";
|
||||
|
||||
echo json_encode([
|
||||
'success' => $success,
|
||||
'message' => $message
|
||||
]);
|
||||
|
||||
|
||||
} catch (Exception $e) {
|
||||
http_response_code(400);
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
function genererEtStockerQRCodeFichier($matricule) {
|
||||
|
||||
/*
|
||||
$cheminDossier = $_SESSION['dossierSociete'].'/qrcodes/';
|
||||
|
||||
|
||||
try {
|
||||
// 1. Validation du matricule
|
||||
if (empty($matricule) || !preg_match('/^[A-Z0-9_-]+$/i', $matricule)) {
|
||||
throw new Exception("Matricule invalide");
|
||||
}
|
||||
|
||||
// 2. Gestion du dossier
|
||||
$cheminDossier = rtrim($cheminDossier, '/') . '/';
|
||||
|
||||
if (!file_exists($cheminDossier)) {
|
||||
if (!mkdir($cheminDossier, 0777, true)) {
|
||||
throw new Exception("Impossible de créer le dossier QR");
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_writable($cheminDossier)) {
|
||||
throw new Exception("Dossier non accessible en écriture");
|
||||
}
|
||||
|
||||
// 3. Suppression ancien QR code
|
||||
$ancienChemin = $this->qrcode->getAncienChemin($matricule);
|
||||
|
||||
|
||||
if ($ancienChemin) {
|
||||
$ancienFichier = $cheminDossier . $ancienChemin;
|
||||
if (file_exists($ancienFichier) && !unlink($ancienFichier)) {
|
||||
error_log("Avertissement: Impossible de supprimer l'ancien QR");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Génération avec endroid/qr-code
|
||||
//$nomFichier = 'qr_' . preg_replace('/[^A-Z0-9]/i', '_', $matricule) . '_' . time() . '.png';
|
||||
|
||||
$nomFichier = $matricule.'.png';
|
||||
|
||||
$cheminComplet = $cheminDossier . $nomFichier;
|
||||
|
||||
|
||||
// Création du QR Code
|
||||
$qrCode = QrCode::create($matricule)
|
||||
->setSize(150)
|
||||
->setMargin(5)
|
||||
->setForegroundColor(new Color(0, 0, 0)) // Noir
|
||||
->setBackgroundColor(new Color(255, 255, 255)) // Blanc
|
||||
->setErrorCorrectionLevel(ErrorCorrectionLevel::High);
|
||||
|
||||
// Création du writer
|
||||
$writer = new PngWriter();
|
||||
$result = $writer->write($qrCode);
|
||||
|
||||
// Sauvegarde du fichier
|
||||
$result->saveToFile($cheminComplet);
|
||||
|
||||
|
||||
// 5. Vérification fichier généré
|
||||
if (!file_exists($cheminComplet)) {
|
||||
throw new Exception("Échec de la génération du fichier");
|
||||
}
|
||||
|
||||
$this->qrcode->majBeneficiaireQr($nomFichier, $matricule);
|
||||
|
||||
return true;
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Erreur QR Code: " . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user