prestation/Controleur/ControleurAjaxexporterlocaliseradherent.php
2025-12-01 18:54:33 +00:00

76 lines
1.8 KiB
PHP

<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
require_once 'Framework/Controleurrequete.php'; // OK
require_once 'Modele/Adherent.php';
require_once 'Modele/Police.php';
class ControleurAjaxexporterlocaliseradherent extends Controleurrequete
{
private $adherent;
private $police;
public function __construct()
{
$this->adherent = new Adherent();
$this->police = new Police();
}
public function index()
{
$idPolice = $_SESSION['idPolice_C'];
$entetepolice = $this->police->getentetepolice($idPolice);
$donnees = $this->adherent->getadherentlocaliteexport();
// Excel
/*
localite
nom
prenoms
numeroAdherent
*/
$headerXLS = array
(
_('Localité'),
_('Nom'),
_('Prénoms'),
_('No Adhérent')
);
$dataXLS = array();
foreach ($donnees as $donnee)
{
$dataXLS[]=$donnee;
}
$classeur = new Spreadsheet();
$classeur->getProperties()->setCreator("INTER-SANTE");
$classeur->setActiveSheetIndex(0);
$feuille=$classeur->getActiveSheet();
$feuille->setTitle(_('FAMILLES PAR LOCALITE'));
$feuille->setCellValue('A1', convertirc($_SESSION['nomSociete']));
$feuille->setCellValue('A2', convertirc($entetepolice['souscripteur']));
$feuille->fromArray($headerXLS, NULL, 'A4', true);
$feuille->fromArray($dataXLS, NULL, 'A5', true);
$fichier = 'Temp/TMP_FAM_LOCALITE'."_".uniqid().".xlsx";
$writer = new Xlsx($classeur);
$writer->save($fichier);
$t_html =' <div id ="div_export_a" class="alert alert-info"> ';
$t_html .=' <a style="font-size:15pt;" href="'.$fichier.'" target="_blank" > '._("TELECHARGER").' </a> ';
$t_html .=' </div ';
echo $t_html;
exit();
}
}