diff --git a/.idea/sortir.iml b/.idea/sortir.iml index c0db0d2..3d6ae95 100644 --- a/.idea/sortir.iml +++ b/.idea/sortir.iml @@ -3,6 +3,7 @@ + diff --git a/assets/styles/app.css b/assets/styles/app.css index 7aab00b..e28b4f4 100644 --- a/assets/styles/app.css +++ b/assets/styles/app.css @@ -25,9 +25,10 @@ main { } footer { - background-color: #f8f9fa; + background-color: #2a8d57; padding: 20px; text-align: center; + color: white; } .star { diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index add8ba8..7a47757 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -2,7 +2,15 @@ namespace App\Controller; +use App\Entity\Participant; +use App\Entity\Ville; +use App\Repository\ParticipantRepository; +use App\Repository\VilleRepository; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\RedirectResponse; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; @@ -15,11 +23,120 @@ class AdminController extends AbstractController 'controller_name' => 'AdminController', ]); } + + //Gestion des utilisateurs #[Route('/admin/user', name: 'app_adminUser')] - public function adminUser(): Response + public function adminUser(ParticipantRepository $participantRepository): Response { return $this->render('admin/user.html.twig', [ + 'participants' => $participantRepository->findAll(), 'controller_name' => 'AdminController', ]); } + #[Route('/admin/user/import', name: 'participant_import', methods: ['POST'])] + public function import(Request $request, EntityManagerInterface $em): Response + { + $file = $request->files->get('csv_file'); + if ($file) { + $csvData = array_map('str_getcsv', file($file->getPathname())); + foreach ($csvData as $index => $row) { + if ($index === 0) continue; + $participant = new Participant(); + $participant->setNom($row[0]); + $participant->setPrenom($row[1]); + $participant->setTelephone($row[2]); + $participant->setEmail($row[3]); + $participant->setAdministrateur((bool)$row[4]); + $participant->setActif((bool)$row[5]); + $participant->setRoles(explode('|', $row[6])); + $participant->setPassword(password_hash($row[7], PASSWORD_BCRYPT)); + $em->persist($participant); + } + $em->flush(); + } + return $this->redirectToRoute('participant_index'); + } + #[Route('/admin/user/export', name: 'participant_export')] + public function export(ParticipantRepository $participantRepository): Response + { + $participants = $participantRepository->findAll(); + $csv = "Nom,Prénom,Téléphone,Email,Administrateur,Actif,Rôles,Password\n"; + foreach ($participants as $participant) { + $csv .= sprintf( + "%s,%s,%s,%s,%s,%s,%s,%s\n", + $participant->getNom(), + $participant->getPrenom(), + $participant->getTelephone(), + $participant->getMail(), + $participant->isAdministrateur() ? '1' : '0', + $participant->isActif() ? '1' : '0', + implode('|', $participant->getRoles()), + $participant->getPassword() + ); + } + $response = new Response($csv); + $response->headers->set('Content-Type', 'text/csv'); + $response->headers->set('Content-Disposition', 'attachment;filename="participants.csv"'); + + return $response; + } + + //Gestion des villes + #[Route('/admin/city', name: 'app_adminCity')] + public function adminCity(VilleRepository $villeRepository): Response + { + return $this->render('admin/city.html.twig', [ + 'citys' => $villeRepository->findAll(), + 'controller_name' => 'AdminController', + ]); + } + #[Route('/admin/city/add', name: 'app_adminCityAdd', methods: ['POST'])] + public function adminCityAdd(Request $request, EntityManagerInterface $entityManager, VilleRepository $villeRepository): RedirectResponse + { + try { + // Récupérer les données envoyées par le formulaire + $postalCode = $request->request->get('postalCode'); + $cityName = $request->request->get('citySelect'); + + // Vérifier que les champs ne sont pas vides + if (!$postalCode || !$cityName) { + return new Response('Tous les champs sont requis.', Response::HTTP_BAD_REQUEST); + } + + // Créer une nouvelle entité City et définir ses propriétés + $city = new Ville(); + $city->setNom($cityName); + $city->setCodePostal($postalCode); + + // Enregistrer la ville dans la base de données + $entityManager->persist($city); + $entityManager->flush(); + $this->addFlash('success', "Ville ajouté !"); + return $this->redirectToRoute('app_adminCity'); + } catch(\Exception $e) { + $this->addFlash('error', "Erreur : " . $e->getMessage()); + return $this->redirectToRoute('app_adminCity'); + } + } + #[Route('/admin/city/delete', name: 'app_adminCityDelete')] + public function adminCityDelete(String $id, EntityManagerInterface $entityManager): RedirectResponse + { + // Récupérer la ville à supprimer + $city = $entityManager->getRepository(Ville::class)->find($id); + + // Vérifier si la ville existe + if (!$city) { + // Si la ville n'existe pas, rediriger avec un message d'erreur + $this->addFlash('error', 'La ville demandée n\'existe pas.'); + return $this->redirectToRoute('app_adminCity'); // Rediriger vers la liste des villes + } + + // Supprimer la ville + $entityManager->remove($city); + $entityManager->flush(); + + // Ajouter un message de succès et rediriger vers la liste des villes + $this->addFlash('success', 'Ville supprimée avec succès.'); + return $this->redirectToRoute('app_adminCity'); + } } diff --git a/templates/admin/city.html.twig b/templates/admin/city.html.twig new file mode 100644 index 0000000..a9260a1 --- /dev/null +++ b/templates/admin/city.html.twig @@ -0,0 +1,119 @@ +{% extends 'main/base.html.twig' %} + +{% block title %}📣 Sortie.com Admin City 🔊{% endblock %} + +{% block content %} +
+ {% include 'admin/sidebar.html.twig' %} + + +
+

Gestion des villes

+ + +
+ + +
+ + +
+ + + + + + + + + + {% for city in citys %} + + + + + + {% else %} + + + + {% endfor %} + +
NomCode postalActions
{{ city.nom }}{{ city.codePostal }} + Supprimer +
Aucune ville trouvée
+
+
+ + + + + +
+{% endblock %} diff --git a/templates/admin/sidebar.html.twig b/templates/admin/sidebar.html.twig index 9fcdf23..c336b3c 100644 --- a/templates/admin/sidebar.html.twig +++ b/templates/admin/sidebar.html.twig @@ -7,12 +7,12 @@
  • - + 👤 Utilisateurs
  • - + 🏙 Villes
  • diff --git a/templates/admin/user.html.twig b/templates/admin/user.html.twig new file mode 100644 index 0000000..b13cfa8 --- /dev/null +++ b/templates/admin/user.html.twig @@ -0,0 +1,83 @@ +{% extends 'main/base.html.twig' %} + +{% block title %}📣 Sortie.com Admin User 🔊{% endblock %} + +{% block content %} +
    + {% include 'admin/sidebar.html.twig' %} + + +
    +

    Gestion des utilisateurs

    + + +
    +
    + + +
    + + Exporter CSV + +
    + + +
    + + + + + + + + + + + + + + + {% for participant in participants %} + + + + + + + + + + + {% else %} + + + + {% endfor %} + +
    NomPrénomTéléphoneEmailAdministrateurActifRôlesActions
    {{ participant.nom }}{{ participant.prenom }}{{ participant.telephone }}{{ participant.mail }} + {{ participant.administrateur ? 'Oui' : 'Non' }} + + {{ participant.actif ? 'Oui' : 'Non' }} + + {{ participant.roles|join(', ') }} + + Modifier + Supprimer +
    Aucun participant trouvé
    +
    +
    +
    +{% endblock %} diff --git a/templates/main/footer.html.twig b/templates/main/footer.html.twig index 2e41dd8..28be863 100644 --- a/templates/main/footer.html.twig +++ b/templates/main/footer.html.twig @@ -8,7 +8,7 @@ -
    +
    ENI © Sortie {{ "now"|date("Y") }}