328 Commits
Author SHA1 Message Date
FeFeClochette c3eae9e1d4 estimation frais
Deploy HouseHub / deploy (push) Successful in 1s
2026-09-15 19:18:38 +02:00
FeFeClochette 4cfef07dc6 Create food planning & merge liste into food
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-15 10:58:23 +02:00
FeFeClochette 3c615e3021 doublon lang
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-10 10:00:21 +02:00
FeFeClochette 094a5b2b91 Change showtoast 2026-09-10 09:45:09 +02:00
FeFeClochette dc8a2e5244 fix categ
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-09 12:49:20 +02:00
FeFeClochette 8a7b5b6644 fix css
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-03 16:15:53 +02:00
FeFeClochette a2e0904132 recap carole
Deploy HouseHub / deploy (push) Successful in 1s
2026-09-03 13:40:50 +02:00
FeFeClochette cfe8962bd4 fix migrate
Deploy HouseHub / deploy (push) Successful in 1s
2026-09-02 20:25:50 +02:00
FeFeClochette 42ccb89b66 migrate snapshot
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-02 20:23:51 +02:00
FeFeClochette 21c9b37ae0 color select
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-02 19:13:51 +02:00
FeFeClochette c05802fc79 align account
Deploy HouseHub / deploy (push) Successful in 1s
2026-09-01 16:53:26 +02:00
FeFeClochette 348a8f1811 fix transfert perso
Deploy HouseHub / deploy (push) Successful in 2s
2026-09-01 16:31:30 +02:00
FeFeClochette 28a98f5790 fix delete category
Deploy HouseHub / deploy (push) Successful in 1s
2026-09-01 16:18:14 +02:00
FeFeClochette 32c291ff2c fix vacances
Deploy HouseHub / deploy (push) Successful in 1s
2026-08-27 16:36:24 +02:00
FeFeClochette b3139b577a remember me
Deploy HouseHub / deploy (push) Successful in 2s
2026-08-26 19:02:39 +02:00
FeFeClochette f19a7442de arrange leave type
Deploy HouseHub / deploy (push) Successful in 22s
2026-08-18 16:58:09 +02:00
FeFeClochette 536f479423 fix holidfays
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-31 13:14:50 +02:00
FeFeClochette 685c649e7c update holidays photo
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-30 18:17:03 +02:00
FeFeClochette 074d8e12d2 fix
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-30 12:50:12 +02:00
FeFeClochette f748330a1b gps expense
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-29 14:58:50 +02:00
FeFeClochette ebdbee71db planning mobil
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-28 16:37:39 +02:00
FeFeClochette 659b286967 imprv roadtrip
Deploy HouseHub / deploy (push) Successful in 3s
2026-07-28 08:51:55 +02:00
FeFeClochette ac8ebf7328 update road trip
Deploy HouseHub / deploy (push) Successful in 1s
2026-07-24 17:55:56 +02:00
FeFeClochette 49d4ec7c35 update calendar
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-22 18:36:08 +02:00
FeFeClochette c48a6ba116 pf_holidays
Deploy HouseHub / deploy (push) Successful in 4s
2026-07-20 20:39:26 +02:00
FeFeClochette 20d6c9b7b0 provisions
Deploy HouseHub / deploy (push) Successful in 2s
2026-07-07 21:26:44 +02:00
FeFeClochette d856d0a409 Deploy from parent_id to production
Deploy HouseHub / deploy (push) Successful in 4s
2026-07-01 10:30:34 +02:00
FeFeClochette 71ec8bd68a search note budget 2026-07-01 10:30:23 +02:00
FeFeClochette 86ef3ccbf2 Deploy from parent_id to production
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-24 21:32:27 +02:00
FeFeClochette e7aa3b595b fix CAT 2026-06-24 21:32:13 +02:00
percoandClaude Sonnet 4.6 3e98de9c18 fix(memo): supprime loading=lazy sur les images en vue note
Deploy HouseHub / deploy (push) Successful in 2s
loading="lazy" dans un conteneur parent avec overflow:hidden empêche
le browser de détecter les images comme visibles → elles ne chargent pas.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-24 17:23:38 +02:00
FeFeClochette 6b2f83b68c fix saving
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-24 16:51:23 +02:00
FeFeClochette 7e24ca7612 fix save
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-24 16:47:54 +02:00
FeFeClochette 506cd64a44 order cat
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-21 11:25:17 +02:00
FeFeClochette 041411b070 refresh auto settings
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-21 11:15:51 +02:00
FeFeClochette fa6521f8f5 multi cat recap budget
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-21 10:57:24 +02:00
FeFeClochette 5618448602 carnet de voyage
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-21 09:17:15 +02:00
FeFeClochette 9d22dc29b4 size modale mobile
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-20 19:13:18 +02:00
FeFeClochette b3a4614c59 itineraire waze / G / Apple
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-20 19:08:54 +02:00
FeFeClochette 18740c5e1b temps / modale détail / drag / waze
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 19:01:18 +02:00
FeFeClochette 854c6388ba km parcouru
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 17:32:53 +02:00
FeFeClochette 1e090cf9ca opti save
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 13:05:50 +02:00
FeFeClochette ff83320f9a opti save
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 13:00:53 +02:00
FeFeClochette 557a1451de voyage garage
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 12:50:40 +02:00
FeFeClochette 03a97df8f1 garage conso html
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-20 10:09:22 +02:00
FeFeClochette ad5a845f18 Auto-commit for deploy to staging - 2026-06-20 10:02:41
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-20 10:02:41 +02:00
FeFeClochette 142d4612a9 Submarine
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-19 21:37:20 +02:00
FeFeClochette 2e30569675 save event
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-19 12:30:26 +02:00
FeFeClochette f5c5320189 auto increment
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-19 11:58:43 +02:00
FeFeClochette 5b4f4c68b2 fix alerte
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-19 11:54:38 +02:00
FeFeClochette aad528d15b typhon
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-19 11:13:37 +02:00
FeFeClochette 89d8ad114b fix recap et suivi
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-17 16:55:34 +02:00
FeFeClochette f36bfa828e fix recap annuel
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-17 16:06:59 +02:00
FeFeClochette f9aa368768 test recap
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-17 13:39:00 +02:00
FeFeClochette e73524b2ae fix epargne
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-17 13:04:03 +02:00
FeFeClochette 96df90d372 fix migrate
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-17 12:40:18 +02:00
FeFeClochette d6e95c1b2a ouragan
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-17 12:27:29 +02:00
FeFeClochette 16b08dd03b fix solde theorique
Deploy HouseHub / deploy (push) Successful in 1s
2026-06-14 10:22:27 +02:00
FeFeClochette 6459c225ac settings calendar
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-11 17:57:09 +02:00
FeFeClochette 429a4ccb66 Deploy from parent_id to production
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-09 08:57:39 +02:00
FeFeClochette cd79bbb71d gift dynamique 2026-06-09 08:56:52 +02:00
FeFeClochette ecac9479d5 Deploy from parent_id to production
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-08 10:01:21 +02:00
FeFeClochette 429a964727 refonte socle 2026-06-08 10:00:56 +02:00
FeFeClochette 70462aa78b finish budget and kids 2026-06-04 17:01:45 +02:00
FeFeClochette afa6587eb3 Auto-commit for deploy to staging - 2026-06-04 15:04:00 2026-06-04 15:04:00 +02:00
FeFeClochette c26a369bb6 Deploy from parent_id to production
Deploy HouseHub / deploy (push) Successful in 2s
2026-06-04 14:26:53 +02:00
FeFeClochette 305b58653d fix migration 2026-06-04 14:26:04 +02:00
perco 8e3e7fe3d8 Merge pull request 'Deploiement staging' (#5) from deploiement-staging into main
Deploy HouseHub / deploy (push) Successful in 2s
Reviewed-on: #5
2026-06-04 14:14:19 +02:00
FeFeClochette 2c8bbbb3e1 Merge branch 'parent_id' of http://nas.percolouco.com:3500/perco/HouseHub into parent_id 2026-06-04 13:09:50 +02:00
FeFeClochette 0ff3c42d35 fix bêtises et update schema sql 2026-06-04 13:09:47 +02:00
perco ea04831451 fix(garage): tous les champs optionnels vides → NULL dans INSERT maintenance
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-29 15:05:11 +02:00
perco d9ae5308ea fix(garage): cost vide → null au lieu de chaîne vide (erreur DECIMAL SQL)
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-29 14:56:40 +02:00
perco 2c5fb9da6b Merge pull request 'Merge branch 'main' of http://nas.percolouco.com:3500/perco/HouseHub into parent_id' (#4) from parent_id into main
Deploy HouseHub / deploy (push) Successful in 2s
Reviewed-on: #4
2026-05-21 11:22:12 +02:00
perco 751082308a Merge pull request 'feat(voyage): base de données péages 2026 (24 680 paires, 5 opérateurs)' (#3) from main into parent_id
Reviewed-on: #3
2026-05-21 11:20:16 +02:00
FeFeClochette b44688a654 fix migrate
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-20 19:20:16 +02:00
FeFeClochette f8e2ad67ee refacto parent Calendrier budget et couleur profil.
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-20 17:56:25 +02:00
percoandClaude Sonnet 4.6 6aab112ecb feat(voyage): affichage détaillé des gares de péage par segment
Deploy HouseHub / deploy (push) Successful in 1s
- Chaque segment affiche maintenant la gare d'entrée et de sortie
- Affichage de l'opérateur (APRR, COFIROUTE, SANEF...)
- Style amélioré : distance + gares sur la même ligne
- Ajout du champ 'op' dans la réponse API

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 16:23:34 +02:00
percoandClaude Sonnet 4.6 6e409fb3a1 feat(voyage): calculateur de coût de trajet avec péages et carburant
Deploy HouseHub / deploy (push) Successful in 1s
- GPS database (toll_gps.json): 414 péages géocodés via Nominatim (88.5% coverage, 468 plazas)
- API PHP (voyage/api.php): estimation péages + carburant via OSRM routing
  - Matching opérateur/entrée/sortie par proximité GPS (80km radius)
  - Fallback haversine si OSRM indisponible
- UI holidays/detail.php: panneau "Coût du trajet" (≥2 étapes)
  - Inputs conso L/100km et prix carburant configurables
  - Affichage distance, péages, carburant, total aller
  - Détail par segment en accordéon
- CSS: classes hol-cost-stat pour les stats chiffrées

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 16:17:21 +02:00
percoandClaude Sonnet 4.6 535f1b7dcf feat(voyage): base de données péages 2026 (24 680 paires, 5 opérateurs)
Deploy HouseHub / deploy (push) Successful in 2s
Données extraites depuis les PDFs officiels 2026 :
- APRR : 20 964 paires (réseau A6, A31, A36, A40...)
- Cofiroute : 1 296 paires (A10, A11, A28...)
- SANEF : 1 620 paires (A1, A2, A26...)
- AREA : 674 paires (A41, A43...)
- SAPN : 126 paires (A13, A29...)

Script de parsing : /tmp/build_tolls.py (à conserver pour mises à jour)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 15:54:26 +02:00
FeFeClochette 4130b03a68 reverse
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-20 12:17:37 +02:00
FeFeClochette 315e1b5fb1 headerfefe
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-20 12:12:12 +02:00
FeFeClochette b1d3db4892 Merge branch 'main' of http://nas.percolouco.com:3500/perco/HouseHub into parent_id 2026-05-20 12:12:03 +02:00
Cedric 99ed0e31de rollback
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-20 12:05:58 +02:00
Cedric a1e7bc62fd test
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-20 12:05:10 +02:00
percoandClaude Sonnet 4.6 3675f0c01a ci: ajout branches staging-perco et staging-fefe dans le workflow deploy
Deploy HouseHub / deploy (push) Successful in 1s
- Push sur staging-perco → deploy /opt/container/househub-perco
- Push sur staging-fefe  → deploy /opt/container/househub-fefe
- Push sur main          → deploy /opt/container/househub (production)
- Utiliser `git deploy <env>` pour envoyer sur le bon environnement

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-20 11:52:12 +02:00
perco 836533fcf6 Merge pull request 'refacto : var currency and zone applied' (#2) from param_foyer into main
Deploy HouseHub / deploy (push) Successful in 1s
Reviewed-on: #2
2026-05-20 11:26:08 +02:00
FeFeClochette 5fe9046a63 gitignore extract source 2026-05-20 11:22:06 +02:00
FeFeClochette 5b70cd20e6 Merge branch 'main' of http://nas.percolouco.com:3500/perco/HouseHub into parent_id 2026-05-20 11:19:05 +02:00
FeFeClochette ed2d5a7c9e delete extract source
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-20 11:16:49 +02:00
percoandClaude Sonnet 4.6 6bbee271e3 fix(liste): couleur appliquée sur tout le tab (pas juste un point)
Deploy HouseHub / deploy (push) Successful in 2s
- Tab actif coloré : background + border = couleur choisie, texte blanc
- Tab inactif coloré : border + texte = couleur choisie
- Suppression du .liste-tab-dot inutilisé

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 22:08:42 +02:00
percoandClaude Sonnet 4.6 7b294f300a feat(liste): modal création/édition avec couleur et type de liste
Deploy HouseHub / deploy (push) Successful in 2s
- Remplacement du formulaire inline par un modal complet
- Color picker : 11 couleurs + option "sans couleur"
- Type de liste : Courses, To-do, Voyage, Travail, Maison, Santé, Loisirs, Autre
- Tab affiche un dot coloré + emoji du type
- Bouton "Supprimer" dans le modal d'édition (remplace le × dans le tab)
- DB : columns color + list_type sur pf_lists

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 22:05:59 +02:00
FeFeClochette 3e4374392a refacto : var currency and zone applied 2026-05-19 20:48:39 +02:00
percoandClaude Sonnet 4.6 ab97af0ea3 feat(liste): ajout des catégories d'articles avec détection automatique
Deploy HouseHub / deploy (push) Successful in 1s
- 22 catégories prédéfinies (Fruits & Légumes, Viande, Frais, etc.)
- Détection automatique par dictionnaire ~250 mots-clés français
- Apprentissage des corrections manuelles (pf_item_category_rules)
- Groupement des articles par section dans l'interface
- Badge catégorie cliquable sur chaque article avec popover de sélection
- API: GET categories, POST set_category
- schema_family.sql: category_id + pf_list_categories + pf_item_category_rules

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 19:25:09 +02:00
FeFeClochette cbb8f93435 Merge branch 'main' of http://nas.percolouco.com:3500/perco/HouseHub
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-19 19:16:47 +02:00
FeFeClochette 16bab06b71 Multi-tenant (p.1) 2026-05-19 19:15:38 +02:00
percoandClaude Sonnet 4.6 969bd5c2bf fix(planka): tri intra-liste par drop sur moitié haute/basse de carte
Deploy HouseHub / deploy (push) Successful in 1s
- Chaque carte est une zone de drop: moitié haute = avant, moitié basse = après
- Indicateur visuel: bordure bleue top ou bottom selon la position du curseur
- Suppression des pk-drop-before (zones 4px invisibles remplacées)
- Colonne comme zone de secours pour listes vides

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 18:15:07 +02:00
percoandClaude Sonnet 4.6 e770ccf22b fix(planka): propagation erreurs Planka + noms étiquettes + position dans saveCard
Deploy HouseHub / deploy (push) Successful in 2s
- update_card: transmet position à Planka + retourne erreur réelle si Planka rejette
- saveCard: n'envoie listId que si changé (position requise par Planka), sinon nom/desc/dueDate seul
- Labels: affiche le nom en texte dans le badge coloré (comme Planka)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:55:35 +02:00
percoandClaude Sonnet 4.6 5828d1796d fix(planka): endpoints v2, tri intra-liste, drag&drop robuste
Deploy HouseHub / deploy (push) Successful in 2s
- create_card: POST /api/lists/{id}/cards + type=story (Planka v2 requis)
- create_list: type=active requis
- Drag & drop: zones pk-drop-before avant chaque carte pour tri intra-liste
- moveCard(): position calculée (avg prev/next) + gestion même liste
- Suppression variable dragCardId globale → dataTransfer propre

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:49:26 +02:00
percoandClaude Sonnet 4.6 0db14560a5 fix(planka): drag&drop via dataTransfer + create_list + synchro position
Deploy HouseHub / deploy (push) Successful in 2s
- Drag & drop: utilise e.dataTransfer (pas de variable globale fragile)
- dropCard prend cardId en paramètre, envoie position requis par Planka
- Nouveau bouton 'Ajouter une liste' en fin de board
- Endpoint create_list dans api.php (POST /api/boards/{id}/lists)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:43:16 +02:00
percoandClaude Sonnet 4.6 7d62aa02be fix(planka): position obligatoire pour déplacer une carte + filtre listes None
Deploy HouseHub / deploy (push) Successful in 2s
- dropCard envoie position (max+65535) car Planka l'exige pour changer listId
- Ajout vérification res.ok + toast d'erreur/succès
- Filtre les listes avec name='None' (placeholders Planka sans nom)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:30:12 +02:00
percoandClaude Sonnet 4.6 285273108c fix(planka): drag & drop toute colonne + filtre listes par boardId
Deploy HouseHub / deploy (push) Successful in 2s
- Drop target = toute la colonne .pk-cards (plus la zone invisible de 4px)
- Filtre les listes et cartes strictement par boardId pour éliminer les listes fantômes
- Indicateur visuel 'Déposer ici' sur colonnes vides
- CSS: colonne highlight en bleu pointillé au survol drag

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:21:31 +02:00
percoandClaude Sonnet 4.6 3516225e56 fix: corrige include paths et get_family_pdo() dans api.php Liste
Deploy HouseHub / deploy (push) Successful in 2s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:13:49 +02:00
percoandClaude Sonnet 4.6 987ce43e52 fix: corrige parse error apostrophes fr.php et includes liste.php
Deploy HouseHub / deploy (push) Successful in 1s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:10:55 +02:00
percoandClaude Sonnet 4.6 8176fc4de0 feat: remplace module Courses par Liste multi-listes nommées
Deploy HouseHub / deploy (push) Successful in 1s
- Nouveau module 'liste' : plusieurs listes nommées par espace famille
- Tabs de navigation entre les listes + création/renommage/suppression inline
- Migration automatique : existing pf_grocery_items → list_id=1 (Ma liste)
- Schema: nouvelle table pf_lists, ajout list_id sur pf_grocery_items
- Historique global partagé entre toutes les listes
- Ancien module 'groceries' conservé pour compatibilité ascendante
- Mise à jour settings.php, header.php, index.php, schema_family.sql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 17:07:02 +02:00
FeFeClochette 1a9d5d5d18 README : roadmap variabilisation
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-19 16:50:12 +02:00
perco 0ca3eef7c3 Planka: add to settings page + README section
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-18 12:54:35 +02:00
percoandClaude Sonnet 4.6 7a697213d4 Planka: add native Kanban module with proxy API and SPA board view
Deploy HouseHub / deploy (push) Successful in 1s
Adds modules/planka/api.php (PHP proxy to Planka at 10.200.33.10:1337), planka.css, and planka.php (full SPA with board selector, drag-and-drop cards, card modal with checklist). Registers planka in header nav, all 3 lang files, schema_family.sql and enables it for family 1.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 11:52:35 +02:00
perco 00db9dedfd README: mise à jour complète — tous les modules, PrintVault, Todo Discord, stack technique
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-16 11:29:41 +02:00
percoandClaude Sonnet 4.6 f2b1c05356 PrintVault: remove GCode segment cap + fix PHP upload limits
Deploy HouseHub / deploy (push) Successful in 2s
- PHP upload: 20M → 300M, post_max: 25M → 310M, memory: 256M → 512M
- GCode parser: no segment cap (full file), flat array format for compact JSON
  491k segments = 0.8s parse, 17MB JSON on 80MB GCode file
- Viewer JS updated for flat array stride-7 format

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:46:13 +02:00
percoandClaude Sonnet 4.6 237de1e529 PrintVault: raise GCode segment limit to 300k (max 500k)
Deploy HouseHub / deploy (push) Successful in 2s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:41:19 +02:00
percoandClaude Sonnet 4.6 811d186b46 PrintVault: GCode 3D path viewer with layer color gradient
Deploy HouseHub / deploy (push) Successful in 2s
- New API endpoint gcode_paths: parses G0/G1 moves, returns segments (max 30k)
- Three.js LineSegments renderer: extrusion moves colored by Z height
  Blue(low) → Cyan → Green → Yellow → Red(high), travel moves dimmed
- Legend overlay showing color scale
- GCode files now show viewer + metadata cards (layout unchanged)
- PHP syntax validated, API endpoint tested before deploy

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:34:28 +02:00
percoandClaude Sonnet 4.6 b756517ab5 PrintVault: direct page navigation + GCode metadata cards
Deploy HouseHub / deploy (push) Successful in 2s
- Clicking a model card now navigates to /printvault-viewer.php (no popup)
- viewer page uses HouseHub header/nav (integrated look)
- GCode metadata displayed as cards: ⏱ time, 🧵 filament, 🔥 nozzle, 🟦 bed
- Two-column layout: Three.js viewer left + metadata sidebar right
- viewer.css: new stylesheet for detail page
- Removed now-unused detail/edit modals from printvault.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 11:05:58 +02:00
percoandClaude Sonnet 4.6 1ee0ec820c Fix PrintVault upload: unpack format f3 (not fff) + ob_end_clean() + perms
Deploy HouseHub / deploy (push) Successful in 2s
- unpack('fff',...) in PHP returns only 1 float — must use unpack('f3',...)
  to correctly extract 3 floats from binary STL vertices
- ob_end_clean() in pvOk/pvErr discards PHP warnings from output buffer
  (display_errors=On was causing warnings to corrupt JSON response)
- Upload dirs chowned to www-data so Apache can write files
- QA verified: categories(8), STL parse, DB insert, file write all pass

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 10:58:53 +02:00
percoandClaude Sonnet 4.6 99e135ec74 PrintVault: full native rewrite — local storage, MariaDB, Three.js viewer
Deploy HouseHub / deploy (push) Successful in 1s
- All files stored in HouseHub (/uploads/printvault/), zero dependency on external service
- PHP parsers: binary/ascii STL (dimensions + volume), 3MF (XML bounding box), GCode metadata
- Three.js viewer (STL + 3MF) in printvault-viewer.php with importmap CDN
  · OrbitControls, metallic material, environment lighting, grid floor
  · Screenshot button saves thumbnail back to HouseHub
- printvault.php: model grid + upload drag&drop + detail modal + edit modal
- API: models CRUD, categories, file serve (inline for viewer), thumb save
- pf_pv_models + pf_pv_categories tables added to schema

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 10:25:21 +02:00
percoandClaude Sonnet 4.6 7272772c9f Add PrintVault module: 3D print file manager integrated in HouseHub
Deploy HouseHub / deploy (push) Successful in 1s
- printvault.php: SPA with model grid, sidebar (categories + type filters), search
- modules/printvault/api.php: PHP proxy to PrintVault API (auth + CORS)
- modules/printvault/assets/printvault.js: model grid, upload modal, detail modal
- modules/printvault/assets/printvault.css: full light/dark theme
- Upload: drag&drop + form (name, category, tags)
- Detail modal: metadata, dimensions, GCode info, download, delete, "Voir en 3D" → PrintVault
- Integrated in header nav, home page, settings; translations fr/en/ca

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-15 10:14:03 +02:00
Cedric 9aa61c85df changement
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-15 09:21:25 +02:00
perco 050d8eda8b todo correctif
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 22:40:14 +02:00
perco 3e58b00c1f correctif
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 22:32:44 +02:00
perco f2c2a43d22 correction
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 22:26:00 +02:00
perco b2a3e34bbe correction garage
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-14 22:15:55 +02:00
perco f62f724046 liste V4
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 11:36:41 +02:00
perco 3a2c8eb5cf liste V3
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 10:52:59 +02:00
perco 9ca290c8ac correction liste de course
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-14 10:47:44 +02:00
perco e6de684f28 ajout liste de course
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-14 10:43:17 +02:00
Cedric a2e0061dde calDAV v5
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-13 18:26:09 +02:00
Cedric d9d9587ded calDAV V4
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-13 17:25:56 +02:00
Cedric 8cb9d37154 calDAV V3
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-13 17:17:40 +02:00
Cedric c62e6ef52d correction note
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-13 16:45:25 +02:00
Cedric 5b74c6da04 calDAV v3
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-13 16:20:33 +02:00
Cedric d660d2cc7a calDAV v2
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-13 15:54:10 +02:00
Cedric 912734d2cc calendrier
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-13 14:37:38 +02:00
Cedric 1c274289bf ajout calendrier ios
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-13 14:00:29 +02:00
Cedric 63833abbc7 test
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-12 17:41:22 +02:00
Cedric b3f320975b settings correction
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-12 17:23:24 +02:00
Cedric fd53b33e9f settings correction
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 16:52:27 +02:00
percoandClaude Sonnet 4.6 f68c2b7259 Todo cron: rich Discord embed with notes, priority, list + fix double execute()
Deploy HouseHub / deploy (push) Successful in 1s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 16:48:48 +02:00
percoandClaude Sonnet 4.6 cfc115665b Todo cron: fix timezone (Europe/Paris) — container runs UTC, tasks stored in local time
Deploy HouseHub / deploy (push) Successful in 2s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 16:39:20 +02:00
percoandClaude Sonnet 4.6 401e98e9ee Todo cron: exact HH:MM match (like original app) + fix log path
Deploy HouseHub / deploy (push) Successful in 2s
- Match reminder_time = HH:MM exactly, runs once per minute naturally
- Log was failing silently: /var/log not writable by perco user
- Fixed crontab to log to /home/perco/househub_todo_cron.log

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 16:06:05 +02:00
percoandClaude Sonnet 4.6 c3229cbf11 Fix todo API: PHP warning on missing due_date key corrupted JSON output
Deploy HouseHub / deploy (push) Successful in 1s
Use ?? null before ?: null for optional fields; add ob_start() as safety net.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 15:42:52 +02:00
percoandClaude Sonnet 4.6 9ec78ba77e Todo: fix JSON.parse error + remove quick-add bar
Deploy HouseHub / deploy (push) Successful in 1s
- api() now sends credentials + Accept/X-Requested-With headers so session
  expiry returns proper JSON 401 instead of HTML redirect
- Safer JSON parsing with readable error in console
- Remove quick-add bar (use modal only)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 15:34:41 +02:00
percoandClaude Sonnet 4.6 606dcbf3d7 Todo: daily reminders at fixed time, no date, simplified sidebar
Deploy HouseHub / deploy (push) Successful in 2s
- Remove date field; due_time is now required
- Cron repeats daily via notified_date (resets at midnight)
- Remove Today/Upcoming/Overdue smart views from sidebar
- Task card shows bell icon + time instead of date labels
- Creation no longer sends immediate Discord notification (cron only)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 15:09:46 +02:00
percoandClaude Sonnet 4.6 5d5ccf406d Fix cron: notify tasks with due_time but no due_date (treat as today)
Deploy HouseHub / deploy (push) Successful in 1s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 15:06:28 +02:00
percoandClaude Sonnet 4.6 c758337ff3 Fix budget: widen month columns VARCHAR(7→10) to match Y-m-01 query format
Deploy HouseHub / deploy (push) Successful in 2s
pf_expenses.gestion_month, pf_alloc_values.month_date, pf_savings.month_date
were VARCHAR(7) but budget views query with Y-m-01 (10 chars) — converted
all imported data in househub_f2 accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 15:02:41 +02:00
percoandClaude Sonnet 4.6 2016407a43 Home: meaningful CTAs per module (Réviser, Griffonner, Cocher, Déballer)
Deploy HouseHub / deploy (push) Successful in 2s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 14:57:22 +02:00
percoandClaude Sonnet 4.6 d913f3c0eb Todo: scheduled Discord notifications via cron
Deploy HouseHub / deploy (push) Successful in 2s
- cron/todo_notify.php: checks every minute for tasks due now and sends
  Discord reminder (⏰) only when due_date+due_time is reached
- No immediate notification when due_time is set (cron handles it)
- Immediate notification still fires for tasks without a due_time
- notified column tracks whether reminder was already sent
- Resets notified=0 when a task is edited (new time picked)
- Cron runs via: docker exec househub php /var/www/html/cron/todo_notify.php

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 14:55:27 +02:00
percoandClaude Sonnet 4.6 6ef3b26153 Add due_time field to Todo tasks
Deploy HouseHub / deploy (push) Successful in 1s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 14:52:04 +02:00
percoandClaude Sonnet 4.6 7790375c01 Fix Todo module: ID mismatches, overdue filter, Discord webhook settings
Deploy HouseHub / deploy (push) Successful in 2s
- Rewrite todo.php with correct element IDs matching todo.js
- Fix sidebar: fully dynamic rendering (no more static nav items)
- Fix quick-add: list selector added, Enter key works correctly
- Fix modals: todo-form-*, list-form-name, list-icon-opts IDs
- Fix overdue filter missing from API (list_id=overdue)
- Add settings modal (⚙️) with Discord webhook URL field
- Add settings action in API (GET/PUT via pf_notes table)
- Discord webhook: notify on task create and task done

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 14:46:32 +02:00
percoandClaude Sonnet 4.6 b97cba6e75 Add Todo module: SPA task manager with lists, priorities and due dates
Deploy HouseHub / deploy (push) Successful in 1s
- New todo.php SPA page with sidebar (smart views + user lists)
- modules/todo/api.php: REST API for lists and todos (CRUD, filters, stats)
- modules/todo/assets/todo.js: frontend (quick add, toggle done, modals)
- modules/todo/assets/todo.css: full light/dark theme styles
- pf_todo_lists + pf_todos tables added to schema_family.sql
- Integrated in header nav, home page cards, settings module list
- Translations added in fr/en/ca

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 13:36:25 +02:00
percoandClaude Sonnet 4.6 5a81c1e9f0 Module Memo : intégration PercoMemo dans HouseHub
Deploy HouseHub / deploy (push) Successful in 1s
- SPA PHP/MySQL avec rendu Markdown client-side (marked.js)
- Notes par famille : titre, contenu Markdown, tags, pièces jointes
- Attachements : images, fichiers, URLs avec galerie lightbox
- Recherche full-text (LIKE) + filtrage par tag dans la sidebar
- Preview live Markdown en split-view lors de l'édition
- Drag & drop images + paste depuis presse-papier
- Tables pf_memo_notes + pf_memo_attachments dans schema_family.sql
- Migration des 2 notes existantes depuis PercoMemo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 13:21:57 +02:00
Cedric 3e344f4c1c debug
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 12:05:28 +02:00
Cedric 19ab75f7df test debug dark mode
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 12:00:08 +02:00
Cedric 35c3ef020d dark mode holydays
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 11:53:50 +02:00
Cedric 1ddd080c16 dark mode holydays
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 11:51:59 +02:00
Cedric c25d784471 Merge branches 'main' and 'main' of http://192.168.1.29:3500/perco/HouseHub
Deploy HouseHub / deploy (push) Successful in 1s
2026-05-12 11:37:35 +02:00
Cedric d9d310da37 dark-mode cadeaux 2026-05-12 11:37:33 +02:00
percoandClaude Sonnet 4.6 1e43f4bdc1 Uniformisation body : data-page au lieu de classes par page
Deploy HouseHub / deploy (push) Successful in 2s
- <body data-page="pageName"> uniforme sur toutes les pages
- <main> reçoit la classe module via $mainClass (pas le body)
- home.css : body.pf-home → body[data-page="home"]
- family-calendar.css : .pf-family-calendar .pf-main → .pf-family-calendar.pf-main
- dark-mode.css : mise à jour références body.pf-home

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 10:36:17 +02:00
percoandClaude Sonnet 4.6 63d71ab7e4 Settings : upload image fond page d'accueil
Deploy HouseHub / deploy (push) Successful in 1s
- Section "Image d'accueil" dans settings.php (par famille)
- Stockage dans /uploads/home_bg_{family_id}.{ext}
- Aperçu de l'image actuelle + bouton reset vers le défaut
- /home-bg.php : endpoint sécurisé pour servir l'image
- index.php : override inline CSS si image personnalisée

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 09:40:19 +02:00
Cedric 87eb3189ec rollback
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 09:11:36 +02:00
Cedric c94af542ff test
Deploy HouseHub / deploy (push) Successful in 2s
2026-05-12 09:10:28 +02:00
percoandClaude Sonnet 4.6 aff2d24a34 CI/CD : Gitea Actions deploy + source code volume mount
Deploy HouseHub / deploy (push) Successful in 5s
- .gitea/workflows/deploy.yml : git pull via SSH au push sur main
  → plus besoin de rebuilder le container pour les modifs PHP/CSS/JS
- docker-compose.yml : monte /opt/container/househub:/var/www/html
  → les fichiers sont servis directement depuis le repo local

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 09:07:36 +02:00
Cedric b87146c9cf modif background
Deploy to Pacha Family / deploy (push) Failing after 3s
2026-05-12 09:01:30 +02:00
percoandClaude Sonnet 4.6 20989d608a Dark mode : fix !important + header accueil
Deploy to Pacha Family / deploy (push) Failing after 3s
- Ajout !important sur tous les overrides qui en ont besoin (battaient
  les règles hardcodées des modules avec !important)
- Header page d'accueil : override explicite de body.pf-home .pf-header
- Calendar : planningTable, sticky cols, fc-view-controls
- Budget : th.sticky-col, tab-item.active, sum-selected
- Holidays/gifts : tous les éléments clés

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-12 08:29:38 +02:00
percoandClaude Sonnet 4.6 89299613cb Dark mode : coverage complète tous modules (budget, calendrier, voyages, cadeaux, accueil)
Deploy to Pacha Family / deploy (push) Failing after 3s
Nouveau dark-mode.css chargé globalement après tous les CSS :
- Accueil : cartes modules avec fond sombre semi-transparent
- Budget : tabs, owner-tabs, table, sticky-col, nens-tables
- Calendrier : cells, nav, vue, balance cards, chips
- Vacances : idea-cards, filtres, formulaires
- Cadeaux : gift-cards, child-header, filter-bar, summary-pills

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 22:26:23 +02:00
percoandClaude Sonnet 4.6 8584bf8c1f Home : ordre modules = menu, ajout Garage, respect enabled_modules
Deploy to Pacha Family / deploy (push) Failing after 4s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 22:19:05 +02:00
percoandClaude Sonnet 4.6 b9403ef86b Dark mode : pill toggle switch ☀️/🌙 + fix JS
Deploy to Pacha Family / deploy (push) Failing after 3s
Remplace le bouton emoji par un vrai switch pill CSS (track + thumb
glissant, soleil/lune qui s'estompent). État visuel entièrement piloté
par [data-theme="dark"] via CSS, JS se contente de toggler l'attribut.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:47:07 +02:00
percoandClaude Sonnet 4.6 19031548e1 Dark mode : toggle 🌙/☀️ dans le header, thème persisté en localStorage
Deploy to Pacha Family / deploy (push) Failing after 3s
- [data-theme="dark"] sur <html> avec surcharge des variables CSS
- Couverture complète : header, nav, cartes, modals, formulaires,
  tables, toasts — global + module garage
- Script early-apply dans <head> pour éviter le flash au rechargement
- Bouton toggle dans le header (desktop + mobile via le burger)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:42:27 +02:00
percoandClaude Sonnet 4.6 87035ed3b6 Garage : liste radio scrollable pour pièces connues
Deploy to Pacha Family / deploy (push) Failing after 3s
Remplace les chips par une liste scrollable (max 160px) avec
nom, référence, marque et prix — identique au GarageManager original.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:38:26 +02:00
percoandClaude Sonnet 4.6 b338d7550a Garage : fix select avec valeurs hors-liste (type, fuel_type, category)
Deploy to Pacha Family / deploy (push) Failing after 3s
setSelectVal() ajoute dynamiquement l'option si elle n'existe pas dans
le select, évitant que .value reste vide et soit envoyé null à l'API.
Validation PHP côté serveur : type et date requis sur PUT maintenance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:36:12 +02:00
percoandClaude Sonnet 4.6 5ac4e51efb Garage API : gestion d'erreurs robuste (JSON garanti)
Deploy to Pacha Family / deploy (push) Failing after 3s
- set_exception_handler global : toute exception PDO retourne du JSON
  au lieu d'une page HTML qui casse le JSON.parse côté client
- gOk() : JSON_INVALID_UTF8_SUBSTITUTE pour données UTF-8 corrompues,
  vérification du retour de json_encode
- db.php die() : retourne JSON au lieu de texte brut

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:31:29 +02:00
percoandClaude Sonnet 4.6 7cacf4bdf5 Garage : redesign CSS thème clair HouseHub
Deploy to Pacha Family / deploy (push) Failing after 3s
Remplace le thème sombre GarageManager par le thème clair de HouseHub
(variables --bg-panel, --border-light, --text-main, --primary, etc.)
Cohérent avec global.css et les autres modules.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 17:25:31 +02:00
percoandClaude Sonnet 4.6 eb34657473 Garage module : toutes les features GarageManager
Deploy to Pacha Family / deploy (push) Failing after 3s
- Navigation vers détail entretien (page-maintenance) au clic sur une ligne
- Boutons édition sur entretiens et pièces (openEditMaintenance, openEditPart)
- Formulaire inline ajout pièce sur page entretien avec TVA +20%
- Chips "pièces connues" pour réutiliser rapidement une pièce existante
- Calcul prix TTC dans modal pièce (updatePartPriceTTC) et formulaire inline (updateIPriceTTC)
- API : GET par ID pour maintenances et pièces
- Correction champ garage : name="garage_name" cohérent POST/PUT

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 16:57:57 +02:00
percoandClaude Sonnet 4.6 a443ec389b fix: garage — photos (limite 20MB), entretiens globaux, pièces groupées par véhicule
Deploy to Pacha Family / deploy (push) Failing after 3s
- Dockerfile + docker/php.ini : upload_max_filesize 2M → 20M
- garage.php : onglet Entretiens dans sous-nav + page #page-maintenances-all
- garage.js : loadAllMaintenances() (entretiens groupés par véhicule)
- garage.js : loadParts() redesigné — pièces groupées par véhicule
- garage.js : navigate() gère 'maintenances-all'
- DB : vehicle_id des pièces mis à jour via maintenance

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 16:33:49 +02:00
percoandClaude Sonnet 4.6 52c8e82221 fix: garage — photos upload + JSON error champs numériques vides
Deploy to Pacha Family / deploy (push) Failing after 3s
- docker-compose.yml : suppression volume uploads sur MariaDB (mauvais container)
- modules/garage/api.php : conversion chaînes vides → null pour INT/DECIMAL (year, km, cost, price, quantity)
  empêche le SQLSTATE[22007] lors de l'édition de véhicule/entretien/pièce
- Photos : vérification que /uploads/garage/ est accessible en écriture

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 16:20:40 +02:00
percoandClaude Sonnet 4.6 997d3872ef fix: garage — sous-nav interne + correction modal (.open → .show)
Deploy to Pacha Family / deploy (push) Failing after 2s
- Ajout sous-nav Dashboard/Véhicules/Pièces (nav-link attendus par garage.js)
- CSS modal-backdrop.open → .show (alignement avec garage.js openModal())
- Styles garage-subnav intégrés dans garage.css

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 16:12:18 +02:00
percoandClaude Sonnet 4.6 62eabfb5ee feat: module Garage — véhicules, entretiens, pièces (intégration GarageManager)
Deploy to Pacha Family / deploy (push) Failing after 3s
- modules/garage/api.php : API REST MySQL (vehicles, maintenances, parts, stats, photos)
- modules/garage/assets/garage.css + garage.js : UI adaptée (chemins API mis à jour)
- garage.php : page principale avec header/footer HouseHub + i18n
- docker/schema_family.sql : tables pf_vehicles, pf_maintenances, pf_parts
- docker-compose.yml : volume househub_uploads pour photos
- includes/lang/fr|ca|en.php : ~50 clés de traduction garage
- header.php : lien Garage dans nav desktop + mobile
- settings.php : module garage dans les toggles
- README.md : tableau des modules + mise à jour description

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:57:24 +02:00
percoandClaude Sonnet 4.6 f6de4918bd fix: refus d'enregistrer si aucun module sélectionné (message d'erreur)
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:46:08 +02:00
percoandClaude Sonnet 4.6 3077db5b98 feat: gestion des modules actifs par famille dans settings.php
Deploy to Pacha Family / deploy (push) Failing after 3s
- families.enabled_modules (JSON) en BDD + init schema
- login.php charge les modules actifs en session
- header.php affiche uniquement les modules actifs (nav desktop + mobile)
- settings.php : section Modules avec toggles visuels (partagé par famille)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:40:50 +02:00
percoandClaude Sonnet 4.6 4b2ab275bc fix: ajout clé bud_cat_income manquante dans fr/ca/en
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:31:10 +02:00
percoandClaude Sonnet 4.6 a0f5f04274 fix: remplacement apostrophes typographiques par apostrophes échappées dans fr.php et ca.php
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:16:00 +02:00
percoandClaude Sonnet 4.6 b80a949701 fix: drapeaux FR et EN en SVG inline (compatibilité Windows/Chrome)
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:10:18 +02:00
percoandClaude Sonnet 4.6 d25fa4b8dc fix: autoriser les caractères accentués dans les noms d'utilisateur (é, è, à...)
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:05:27 +02:00
percoandClaude Sonnet 4.6 d856cd8189 fix: Senyera catalane en SVG inline (4 barres rouges sur or)
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:04:18 +02:00
percoandClaude Sonnet 4.6 472d6ac7fd fix: vrai drapeau catalan 🏴󠁥󠁳󠁣󠁴󠁿 dans le sélecteur de langue
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 15:00:25 +02:00
percoandClaude Sonnet 4.6 6acda4ab25 feat: sélecteur de langue dans settings.php — persisté par compte en BDD
Deploy to Pacha Family / deploy (push) Failing after 3s
- Sélecteur FR/EN/CA déplacé du header vers settings.php
- Colonne lang ajoutée à users (meta DB) — langue sauvegardée par compte
- Login charge automatiquement la langue préférée de l'utilisateur
- Header nettoyé du sélecteur de langue

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 14:51:35 +02:00
percoandClaude Sonnet 4.6 94d85dc8da feat: ajout traduction anglaise (EN) — 548 clés traduites
Deploy to Pacha Family / deploy (push) Failing after 4s
- includes/lang/en.php : traduction complète EN (tests, nav, auth, home, calendrier, voyages, budget, cadeaux)
- includes/i18n.php : ajout 'en' dans les langues acceptées
- header.php : ajout du sélecteur EN dans la barre de langues
- README.md : documentation mise à jour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 14:44:23 +02:00
percoandClaude Sonnet 4.6 5bfc8efae4 fix: ajout liens settings + admin dans la navigation (header desktop + mobile)
Deploy to Pacha Family / deploy (push) Failing after 3s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 14:39:05 +02:00
percoandClaude Sonnet 4.6 0494554c30 feat: admin panel + page paramètres + README mis à jour
Deploy to Pacha Family / deploy (push) Failing after 3s
- admin/index.php : gestion familles et utilisateurs (activer/désactiver, rôles, supprimer, regénérer code invite)
- includes/admin_auth.php : protection des routes admin (403 si non-admin)
- settings.php : page de config par compte (profil, mot de passe, code invitation, membres, lien admin)
- login.php : vérification is_active user + famille, is_admin en session
- docker/init/00-setup.sql : ajout colonnes is_admin, is_active sur users + is_active sur families
- invite.php supprimé (remplacé par settings.php)
- README.md : documentation complète multi-tenant, URLs, rôle admin

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 14:30:44 +02:00
percoandClaude Sonnet 4.6 84db4b6619 feat: système multi-tenant (familles + inscription + invitations)
Deploy to Pacha Family / deploy (push) Failing after 3s
- docker/init/00-setup.sql : meta DB househub_meta (families + users) + grants
- docker/schema_family.sql : template DB par famille (toutes les pf_* tables)
- docker-compose.yml : MYSQL_DATABASE=househub_meta, init dir monté
- includes/meta_db.php : PDO vers househub_meta
- includes/db.php : connexion dynamique vers la DB famille (session)
- login.php : auth via meta DB + family_db en session + lien inscription
- register.php : inscription + création famille OU rejoindre via code
- invite.php : voir son code d'invitation + membres de l'espace

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 14:23:53 +02:00
percoandClaude Sonnet 4.6 634e4647da feat: setup Docker + MariaDB pour déploiement self-hosted
Deploy to Pacha Family / deploy (push) Failing after 3s
- Dockerfile (PHP 8.2 Apache + pdo_mysql)
- docker-compose.yml (househub + mariadb + Traefik househub.nas.percolouco.com)
- schema.sql (22 tables + données initiales)
- includes/db.php adapté pour variables d'environnement
- .env.example, .gitignore, README mis à jour

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 12:07:04 +02:00
percoandClaude Sonnet 4.6 3f7ed9c2f1 refactor: renommage PachaFamily → HouseHub
Deploy to Pacha Family / deploy (push) Failing after 3s
- Remplacement de toutes les occurrences PachaFamily/pachafamily/PACHAFAMILY
- Renommage pachafamily_source.md → househub_source.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 11:58:53 +02:00
FeFeClochette 29f341b052 fix calcul voyage
Deploy to Pacha Family / deploy (push) Failing after 3s
2026-05-06 21:46:03 +02:00
FeFeClochette 8792e44f69 paid 2026-05-06 21:37:08 +02:00
FeFeClochette e099fb80cd fix etapes duplicate 2026-05-06 21:27:03 +02:00
FeFeClochette 8a6abe5f8e opti vue mensuelle 2026-05-06 20:49:52 +02:00
FeFeClochette 2b2150870c header mobile 2026-05-06 20:07:20 +02:00
FeFeClochette 31f03b7182 padding logout 2026-05-06 20:04:24 +02:00
FeFeClochette f2af3541f6 header et login mobile 2026-05-06 19:56:18 +02:00
FeFeClochette ab1374472d Auto-commit for deploy to production - 2026-05-06 17:45:08 2026-05-06 17:45:08 +02:00
FeFeClochette 55a2f8a730 smart selector 2026-05-06 17:44:43 +02:00
FeFeClochette 3bfd25d566 infinite scroll 2026-05-06 13:24:27 +02:00
FeFeClochette ff04458a59 css family 2026-05-06 12:55:24 +02:00
Cedric 97389ab0ad debug perco 2026-05-06 12:14:33 +02:00
FeFeClochette 902f093ced login 2026-05-06 11:54:39 +02:00
FeFeClochette 954c07a838 css 2026-05-06 11:38:51 +02:00
FeFeClochette be2edcce82 filtre multiple 2026-05-05 20:50:22 +02:00
FeFeClochette 54edb5ed58 gift revamp 2026-05-05 19:17:42 +02:00
FeFeClochette 9c5620b3e3 harmo 2026-05-05 17:13:12 +02:00
FeFeClochette 4763e6a947 trad et modal 2026-05-05 14:56:42 +02:00
FeFeClochette 7b5c0be72b calendar display mobile 2026-05-05 12:13:41 +02:00
FeFeClochette a2870f2421 hide planning hebdo 2026-05-05 09:10:51 +02:00
FeFeClochette 5b050a7c24 fix holidays 2026-05-05 08:57:15 +02:00
FeFeClochette 2cb62d7ead trad 2026-05-04 18:34:08 +02:00
FeFeClochette 6ce49bffc0 Auto-commit for deploy to production - 2026-05-04 18:30:44 2026-05-04 18:30:44 +02:00
FeFeClochette cc937c544c Sécurisation AJAX 2026-05-04 18:27:38 +02:00
FeFeClochette 281a37c401 Toasts 2026-05-04 18:22:36 +02:00
FeFeClochette cdd2abaa96 Centralisation des constantes 2026-05-04 18:19:42 +02:00
FeFeClochette 1babf4c52e responsive 2026-05-04 15:41:35 +02:00
FeFeClochette 8c4c402f5b modale csv 2026-05-04 12:52:48 +02:00
FeFeClochette 2087cfb945 fix bugs 2026-05-04 11:34:33 +02:00
FeFeClochette 9070390770 Auto-commit for deploy to production - 2026-04-20 11:40:09 2026-04-20 11:40:09 +02:00
FeFeClochette daff54784f fix map 2026-04-20 11:29:26 +02:00
FeFeClochette e42808149d vue mobile 2026-04-19 20:45:53 +02:00
FeFeClochette 9cca683722 fix snapshot 2026-04-17 20:00:02 +02:00
FeFeClochette 377c404d49 meteo mobile 2026-04-17 18:38:13 +02:00
FeFeClochette 10b9f1bb0b preivision 2026-04-17 17:27:57 +02:00
FeFeClochette 12f9e27845 cURL 2026-04-17 16:56:14 +02:00
FeFeClochette fe39eb8f2c weather 2026-04-17 16:51:05 +02:00
FeFeClochette 0db6a71fd7 css planning 2026-04-13 11:29:29 +02:00
FeFeClochette 30599de125 secu menu 2026-04-13 11:18:11 +02:00
FeFeClochette 0412b60b97 trad mobile 2026-04-13 11:14:31 +02:00
FeFeClochette 6d4ba85d00 gift mobile 2026-04-13 11:11:31 +02:00
FeFeClochette feb2f158dd trad 2026-04-13 11:06:08 +02:00
FeFeClochette c4b80c3650 geoloc 2026-04-10 17:47:23 +02:00
FeFeClochette 25b1c27ba9 calendar 2026-04-09 20:42:46 +02:00
FeFeClochette 6d5982d923 fix sum 2026-04-08 16:04:52 +02:00
FeFeClochette 97a8fb546e translate 2026-04-02 17:41:50 +02:00
FeFeClochette 7df7144147 supp inter 2026-04-02 17:03:12 +02:00
FeFeClochette 2882c682f0 return 2026-04-02 16:58:58 +02:00
FeFeClochette eff1628115 fix modale 2026-04-02 16:35:41 +02:00
FeFeClochette d03f6bad80 fix button 2026-04-02 16:04:53 +02:00
FeFeClochette c2aa1e9f7b planning view 2026-04-02 15:54:40 +02:00
FeFeClochette e07c57ea56 maj MAP 2026-04-02 11:57:30 +02:00
FeFeClochette b425ec78aa focus etape 2026-04-02 11:32:42 +02:00
FeFeClochette ebfa0c99f3 notes voyage 2026-04-01 21:18:18 +02:00
FeFeClochette 73676bc20a somme result 2026-03-30 17:49:39 +02:00
FeFeClochette 3930f5f1be fix order 2026-03-30 12:55:51 +02:00
FeFeClochette ca9c774422 css drag and drop 2026-03-30 12:33:57 +02:00
FeFeClochette a403628c07 geoloc 2026-03-30 12:21:47 +02:00
FeFeClochette 7096391561 css 2026-03-30 12:12:14 +02:00
FeFeClochette cdeff93fbd holidays 2026-03-30 12:01:44 +02:00
FeFeClochette 3f842e091a charge à venir 2026-03-30 10:26:43 +02:00
FeFeClochette aeb33930ab recap 2026-03-30 10:08:39 +02:00
FeFeClochette 106d6c99de suivi fix 2026-03-30 09:56:05 +02:00
FeFeClochette 3a8f58ef39 cycle 2026-03-28 18:55:45 +01:00
FeFeClochette 28b8a6d49a order by holidays 2026-03-28 18:20:21 +01:00
FeFeClochette 1f8b28cf8e fix duplicate 2026-03-28 17:41:46 +01:00
FeFeClochette 9424b44fd9 css 2026-03-23 20:13:11 +01:00
FeFeClochette 39b8b64116 input 2026-03-23 18:44:23 +01:00
FeFeClochette bc82a42517 charge 2026-03-23 17:49:41 +01:00
FeFeClochette 71ce5ce008 mapping cat 2026-03-23 17:39:56 +01:00
FeFeClochette 7501339b39 cycle 2026-03-23 17:36:23 +01:00
FeFeClochette 3db060bc0d fix catégorie 2026-03-23 13:53:10 +01:00
FeFeClochette 5859221fca signe expense 2026-03-23 09:48:19 +01:00
FeFeClochette 9b2cc83512 fix theo 2026-03-20 16:35:04 +01:00
FeFeClochette faaf89e1ab théorique 2026-03-20 16:20:49 +01:00
FeFeClochette 4c5646766a suivi 2026-03-20 12:16:58 +01:00
FeFeClochette 5b510a047f fix revenu 2026-03-13 20:32:20 +01:00
FeFeClochette 27564c8e9e note 2026-03-05 09:55:37 +01:00
FeFeClochette 7060a43859 change 2026-03-04 20:24:54 +01:00
FeFeClochette 730c2a363e css 2026-02-20 16:45:57 +01:00
FeFeClochette 5ae38e1e4b css 2026-02-20 16:41:27 +01:00
FeFeClochette e22a7e183c opti family calendar 2026-02-20 16:33:54 +01:00
FeFeClochette 80d39ab8b9 fix 2026-02-17 21:06:56 +01:00
FeFeClochette 695234d182 update epargne auto 2026-02-17 20:58:20 +01:00
FeFeClochette 8e3c90524e fix document 2026-02-17 18:11:16 +01:00
FeFeClochette 1f16135ba5 favicon et mobile 680 2026-02-17 18:06:02 +01:00
FeFeClochette 7c9ca1b705 virement todo 2026-02-17 17:12:59 +01:00
FeFeClochette 6e51a9215c budget 2026 2026-02-17 16:00:03 +01:00
FeFeClochette 36b54ea953 fix edit 2026-02-16 10:44:39 +01:00
FeFeClochette 6cbbfc4811 suivi 2026-02-16 10:40:18 +01:00
FeFeClochette cb2d0b5a06 fix à venir 2026-02-16 10:35:18 +01:00
FeFeClochette a90c1bc11b fix recap 2026-02-16 10:26:53 +01:00
FeFeClochette fde728c888 check à definir 2026-02-16 10:15:00 +01:00
FeFeClochette 910d21da5a income 2026-02-16 10:07:33 +01:00
FeFeClochette c01d793a1e depassement 2026-02-16 09:51:53 +01:00
FeFeClochette 0e6c3edbc3 is_estimate 2026-02-16 09:27:03 +01:00
FeFeClochette 4731efe615 auto check recap 2026-02-16 09:20:18 +01:00
FeFeClochette 92424bdb51 match recap 2026-02-15 12:21:18 +01:00
FeFeClochette 9a3d646ca5 fix php version 2026-02-15 10:51:12 +01:00
FeFeClochette 71db01d159 budget + 2026-02-11 11:50:18 +01:00
FeFeClochette 16e3eb0890 budget header 2026-02-10 21:25:09 +01:00
FeFeClochette 293bfbb0f1 reste a venir 2026-02-10 21:23:31 +01:00
FeFeClochette 5eb1aec8ff Auto-commit for deploy to production - 2026-02-09 17:53:11 2026-02-09 17:53:11 +01:00
FeFeClochette 54c8503ed1 mensuel 2026-02-09 17:46:10 +01:00
FeFeClochette 44e5241ee2 fix modale vacances 2026-02-09 15:33:20 +01:00
FeFeClochette d557636eee refacto holidays 2026-02-09 15:29:12 +01:00
FeFeClochette 43bcdc83a1 budget 2026-02-09 13:07:39 +01:00
FeFeClochette f5822f2694 calendar 2026-01-31 15:57:25 +01:00
FeFeClochette 170f98d8b8 index 2026-01-30 23:52:20 +01:00
FeFeClochette 94cde4ae34 revamp 2026-01-30 23:48:42 +01:00
FeFeClochette e248eee882 revamp gemini 2026-01-30 23:32:25 +01:00
FeFeClochette fbc95815d8 voyage 2026-01-26 20:21:05 +01:00
FeFeClochette c5b89f2bf4 edition suppression 2026-01-26 12:22:09 +01:00
FeFeClochette bc622f0b04 mobile lecture 2026-01-26 12:14:25 +01:00
FeFeClochette 564df35641 Visu mobile 2026-01-26 12:02:15 +01:00
FeFeClochette a8cd460cd6 bouton add 2026-01-26 10:45:24 +01:00
FeFeClochette 7e149d0c1a Anniversary 2026-01-26 10:31:32 +01:00
FeFeClochette c3ba14c8b0 ajustement tableau gift 2026-01-26 09:05:40 +01:00
FeFeClochette 6c8a7ab1b4 tricount 2026-01-23 15:38:01 +01:00
FeFeClochette b22348ebba img 2026-01-23 12:35:53 +01:00
FeFeClochette 3f01cbd8aa christmas 2026-01-23 12:23:47 +01:00
FeFeClochette 2df2fd0b2e boucle login 2026-01-09 14:55:06 +01:00
FeFeClochette 796d3b3fcc calendar storage 2026-01-08 17:25:42 +01:00
FeFeClochette b7533a4d05 bulk 2026-01-07 18:41:12 +01:00
FeFeClochette eee36e4034 fix bulk menu 2026-01-07 15:32:42 +01:00
FeFeClochette abe85cb5d3 menu open 2026-01-07 10:06:56 +01:00
FeFeClochette 907a17a2b9 login redirect 2026-01-07 09:43:38 +01:00
FeFeClochette ab46c105f7 pep malade 2026-01-07 09:36:11 +01:00
FeFeClochette 3b895f3f0c login 2025-12-24 16:19:45 +01:00
FeFeClochette a70cfff122 mobile 2025-12-24 16:14:56 +01:00
FeFeClochette e615156347 list 2025-12-24 16:01:18 +01:00
FeFeClochette 9beb6e1b43 layout 2025-12-24 14:48:49 +01:00
Cedric c6793e2473 picto 2025-12-11 15:28:51 +01:00
Cedric e86816ac7e Auto-commit for deploy to production - 2025-12-11 15:23:25 2025-12-11 15:23:25 +01:00
Cedric a08dc62ba6 Auto-commit for deploy to production - 2025-12-11 15:21:23 2025-12-11 15:21:23 +01:00
Cedric 0de792781a Auto-commit for deploy to production - 2025-12-11 15:10:59 2025-12-11 15:10:59 +01:00
Cedric 4e4177d8d0 Auto-commit for deploy to production - 2025-12-11 15:06:01 2025-12-11 15:06:01 +01:00
Cedric 128a738fae Auto-commit for deploy to production - 2025-12-11 15:01:35 2025-12-11 15:01:35 +01:00
151 changed files with 90976 additions and 1450 deletions

No files matched your search

+27 -12
View File
@@ -1,20 +1,35 @@
name: Deploy to Pacha Family
name: Deploy HouseHub
on:
push:
branches: [main]
branches: [main, staging-perco, staging-fefe]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Production
uses: SamKirkland/FTP-Deploy-Action@v4.3.4
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.0.0
with:
server: ${{ secrets.FTP_SERVER_PERCOLOUCO }}
username: ${{ secrets.FTP_USERNAME_PERCOLOUCO }}
password: ${{ secrets.FTP_PASSWORD_PERCOLOUCO }}
local-dir: ./
server-dir: /www/pachafamily/ # ← Production reste ici
host: 192.168.1.29
username: perco
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
BRANCH="${{ github.ref_name }}"
case "$BRANCH" in
main)
cd /opt/container/househub
git pull
echo "✓ Production mise à jour"
;;
staging-perco)
cd /opt/container/househub-perco
git pull origin staging-perco
echo "✓ Staging Perco mis à jour"
;;
staging-fefe)
cd /opt/container/househub-fefe
git pull origin staging-fefe
echo "✓ Staging Fefe mis à jour"
;;
esac
+5
View File
@@ -0,0 +1,5 @@
househub_db_data
.env
data/.hh_app_secret
extract_source.php
.htaccess
+14
View File
@@ -0,0 +1,14 @@
FROM php:8.2-apache
RUN apt-get update && apt-get install -y \
libpng-dev libjpeg-dev libwebp-dev libzip-dev libonig-dev \
&& docker-php-ext-install pdo pdo_mysql mysqli mbstring zip \
&& a2enmod rewrite \
&& rm -rf /var/lib/apt/lists/*
COPY . /var/www/html/
RUN chown -R www-data:www-data /var/www/html
COPY docker/apache.conf /etc/apache2/sites-available/000-default.conf
COPY docker/php.ini /usr/local/etc/php/conf.d/uploads.ini
+193 -1
View File
@@ -1 +1,193 @@
pachafamily
# 🦙 HouseHub OS
Système de gestion familiale sur-mesure — Budget, Calendrier, Voyages, Tâches, Courses, Notes, Impression 3D et plus.
Stack : PHP 8.2 natif · Vanilla JS · MariaDB 11 · Docker · Traefik
---
## 🚀 Déploiement (Docker)
**Prérequis** : Docker, Docker Compose, Traefik sur le réseau `proxy`.
```bash
# 1. Cloner le repo
git clone http://<gitea>/perco/HouseHub.git && cd HouseHub
# 2. Créer le fichier d'environnement
cp .env.example .env
# Éditer .env pour changer les mots de passe
# 3. Lancer
docker compose up -d --build
# 4. Accéder à l'app
# https://househub.nas.percolouco.com
```
La base de données meta (`househub_meta`) et les permissions sont **initialisées automatiquement** au premier démarrage via `docker/init/00-setup.sql`.
Aucun compte par défaut — le premier utilisateur s'inscrit via `/register.php` et choisit de créer un espace familial.
---
## 👥 Gestion multi-tenant
HouseHub supporte plusieurs familles indépendantes sur la même instance.
| URL | Description |
| --------------- | ------------------------------------------------------------------- |
| `/register.php` | Créer un compte + nouvel espace, ou rejoindre via code d'invitation |
| `/login.php` | Connexion |
| `/settings.php` | Profil, mot de passe, langue, modules actifs, code d'invitation |
| `/admin/` | Panneau d'administration (admin uniquement) |
### Inviter quelqu'un dans son espace
1. Aller sur `/settings.php` → copier le code d'invitation
2. La personne va sur `/register.php` → onglet "Rejoindre" → coller le code
3. Les deux comptes partagent le même environnement de données
### Rôle admin
Le premier utilisateur inscrit doit être promu admin manuellement :
```sql
UPDATE househub_meta.users SET is_admin = 1 WHERE username = 'ton_username';
```
---
## 🧩 Modules
Tous les modules sont activables/désactivables par famille depuis `/settings.php`.
| Module | Route | Description |
| ----------------- | ---------------------- | ------------------------------------------------------------------------------- |
| 💰 Budget | `/budget.php` | Suivi mensuel, prévisionnel, épargne, import CSV bancaire |
| 📅 Calendrier | `/family-calendar.php` | Congés (CP/JRA/JA), modes de garde, planning hebdo, vacances scolaires |
| 🗓️ Calendrier iOS | `/calendar-ios.php` | Synchronisation CalDAV avec iPhone/iPad |
| 🏖️ Voyages | `/holidays.php` | Roadtrips, cartographie Leaflet, itinéraires OSRM, météo Open-Meteo |
| 🎁 Cadeaux | `/gift-list.php` | Listes Noël / anniversaires, intégration Tricount |
| 🚗 Garage | `/garage.php` | Véhicules, historique entretiens, pièces détachées |
| 🛒 Courses | `/groceries.php` | Liste de courses partagée en temps réel |
| ✅ Todo | `/todo.php` | Listes de tâches avec rappels quotidiens via Discord webhook |
| 📝 Mémo | `/memo.php` | Notes personnelles / familiales avec éditeur riche |
| 🖨️ PrintVault | `/printvault.php` | Gestionnaire de fichiers d'impression 3D (STL, 3MF, GCode) avec viewer Three.js |
| 📋 Planka | `/planka.php` | Kanban natif connecté à Planka — boards, listes, cartes, drag & drop, checklist |
---
## 📋 Planka
Module Kanban natif connecté à l'instance Planka du NAS — affichage et gestion directement dans HouseHub sans iframe.
- **Boards** : sélecteur de boards du projet Planka lié à la famille
- **Colonnes** : listes Planka affichées en colonnes scrollables
- **Cartes** : labels colorés, date d'échéance, checklist
- **Actions** : créer, modifier, supprimer des cartes ; drag & drop entre colonnes ; cocher les tâches
- **Par famille** : chaque espace HouseHub peut pointer vers son propre projet Planka
- **Paramètres** : bouton ⚙️ pour configurer le `project_id` Planka
---
## 🖨️ PrintVault
Module de gestion de fichiers d'impression 3D entièrement intégré à HouseHub.
- **Formats supportés** : STL (binaire/ASCII), 3MF, GCode
- **Viewer 3D** : Three.js (STL/3MF) et visualisation des trajectoires GCode avec dégradé de couleur par hauteur Z
- **Métadonnées GCode** : temps d'impression estimé, longueur filament, température buse/plateau
- **Stockage local** : fichiers sur le serveur, métadonnées en MariaDB (`pf_pv_*`)
- **Limite upload** : 300 Mo
---
## ✅ Todo — Rappels Discord
Le module Todo supporte des rappels quotidiens via un **webhook Discord** :
1. Aller sur `/todo.php` → ⚙️ → coller l'URL du webhook Discord
2. Configurer le cron sur l'hôte :
```bash
* * * * * docker exec househub php /var/www/html/cron/todo_notify.php >> /home/perco/househub_todo_cron.log 2>&1
```
Le cron tourne chaque minute et envoie une notification Discord à l'heure exacte configurée sur chaque tâche.
---
## 🛠️ Stack technique
| Composant | Technologie |
| -------------------- | ---------------------------------------- |
| Backend | PHP 8.2 (Apache) |
| Base de données | MariaDB 11 |
| Frontend | Vanilla JS, CSS custom (dark mode natif) |
| Viewer 3D | Three.js (ES modules via importmap CDN) |
| Cartographie | Leaflet + OSRM |
| Conteneurisation | Docker + Docker Compose |
| Reverse proxy | Traefik |
| Internationalisation | FR / CA |
---
## 🔄 Mises à jour & Migrations SQL (Multi-Tenant)
L'architecture de HouseHub isole chaque foyer dans sa propre base de données (`househub_f1`, `househub_f2`, etc.). Lors de l'ajout de nouvelles fonctionnalités impliquant des changements de structure SQL, il faut suivre une double procédure :
1. **Pour les futures familles (Initialisation) :**
Mettre à jour le fichier `docker/schema_family.sql`. Ce fichier est lu par `register.php` à la création d'un nouvel espace.
2. **Pour les familles existantes (Migration) :**
Créer ou mettre à jour le script `migrate.php` à la racine du projet. Ce script boucle sur toutes les bases existantes référencées dans `househub_meta.families` pour y injecter les requêtes `ALTER TABLE` ou `CREATE TABLE`.
- **Exécution** : Accéder à `https://votre-domaine.com/migrate.php` avec un navigateur.
- ⚠️ **Sécurité** : Pensez à supprimer ou sécuriser l'accès à ce fichier après exécution en production.
---
## 🗺️ Roadmap de Variabilisation (Migration Multi-Tenant)
Afin de transformer complètement l'application héritée de Pacha Family en un produit générique et autonome pour chaque espace familial, les chantiers suivants doivent être menés.
🟢 Niveau 1 : Facile (Constantes et configurations globales)
[x] Configuration de base : Extraire la devise (CURRENCY) et la zone de vacances scolaires (ZONE_SCOLAIRE) du fichier config.php pour les stocker dans les paramètres d'espace en BDD.
[x] Suppression des IDs statiques : Supprimer les IDs parents fixes (ID_ALEX = 2, ID_LAIA = 3) dans config.php au profit d'une lecture dynamique basée sur les utilisateurs réels de la famille connectée (liens via la table pf_people).
[x] Charte graphique dynamique : Remplacer les couleurs codées en dur (bleu/orange) par des sélecteurs natifs dans l'espace "Paramètres", en générant les variables CSS et leurs nuances (via color-mix()) à la volée.
[ ] Filtres API Éducation Nationale : Rendre dynamique la zone de l'API (zones LIKE '%Zone C%' dans family-calendar.js) pour s'adapter à la région de chaque foyer.
[ ] Identifiant Planka : Variabiliser le project_id Planka par défaut écrit en dur dans planka/api.php.
🟡 Niveau 2 : Intermédiaire (Listes et dictionnaires en dur)
[ ] Gestion des membres (Cadeaux) : Dans gift-list.php, remplacer la liste d'enfants ($children) et d'adultes ($baseAdults, $extraAdults) codée en dur par une lecture dynamique des membres du foyer déclarés en BDD.
[ ] Occasions festives (Cadeaux) : Rendre configurables les occasions spéciales (TIO, NOEL, ROIS, ANNIV, SANT).
[ ] Configuration des catégories (Budget) : Dans budget/views/suivi.php, migrer le tableau $categoriesConfig (FMCG, Essence, École, etc.), leurs couleurs et leurs suggestions de magasins associés vers un stockage paramétrable.
[ ] Déductions du Reste à venir (Budget) : Rendre dynamiques les libellés de catégories ciblés pour le calcul automatique du reste à venir (Estimacio escola, Estimation gasolina, etc.).
[ ] Types de carburants (Garage) : Variabiliser la liste statique des carburants dans garage.php.
🔴 Niveau 3 : Complexe (Logique métier et Schéma SQL)
[x] Refonte relationnelle du Budget (Prévisionnel) : Refonte totale de budget_prev.php. Modification de la table pf_alloc_values pour basculer sur des colonnes génériques (amount_p1, amount_p2) et suppression définitive de toute logique conditionnelle liée aux prénoms des concepteurs originaux.
[ ] Refonte globale de la répartition (Budget) : Étendre le modèle relationnel (alloc_id, user_id, amount) au reste de l'application pour gérer n'importe quel nombre d'adultes (1, 2, 3 ou plus).
[ ] Destinations de transferts (Budget) : Rendre dynamiques les cibles de virements prévisionnels (vers L.Pol, vers L.Pep, etc.) en fonction des comptes épargne créés par la famille.
[ ] Onglets d'Épargne : Générer dynamiquement les sous-onglets de la vue epargne.php à partir des membres réels au lieu des blocs statiques Alex, Laia et Nens.
[ ] Types de Garde (Calendrier) : Supprimer les types d'événements et compteurs codés en dur (OFF_CAROLE, EXTRA_OFF_CAROLE, CENTRE, AVIS, PEP_SICK) pour permettre à chaque foyer de définir ses propres modalités de garde et compteurs de congés associés.
[ ] Cycles de Congés : Rendre configurables les mois de début de calcul des droits aux congés (Août pour les CP, date d'anniversaire personnalisée pour les JA) par profil utilisateur.
---
## 📌 Versioning
| Version | Changements |
| ------- | ------------------------------------------------------------------------------------------------------------------------- |
| v2.3.0 | Multi-tenant (p.2) : Refonte BDD Budget (p1, p2), suppression IDs statiques et thèmes de profils dynamiques (color-mix()) |
| v2.2.0 | Multi-tenant (p.1) : Paramètres dynamiques du foyer (€, Zone) via BDD + script migration |
| v2.1.0 | Module Planka : Kanban natif connecté à Planka via API proxy PHP |
| v2.0.0 | Module PrintVault : viewer 3D STL/3MF/GCode, stockage local, trajectoires GCode illimitées |
| v1.5.0 | Modules Todo (rappels Discord), Mémo, Courses (liste partagée) |
| v1.4.0 | Synchronisation CalDAV iOS |
| v1.3.0 | Optimisation SQL — suppression des requêtes N+1, temps de réponse ÷3 |
| v1.2.0 | Modernisation UI — Toasts, confirmations sur-mesure |
| v1.1.0 | Refonte expérience mobile (Bottom Sheets) |
| v1.0.0 | Version stable initiale — Budget, Calendrier, Voyages, Cadeaux, Garage |
+196
View File
@@ -0,0 +1,196 @@
<?php
require __DIR__ . '/../includes/admin_auth.php';
require_once __DIR__ . '/../includes/meta_db.php';
require_once __DIR__ . '/../includes/i18n.php';
// ─── Actions POST ──────────────────────────────────────────────────────────────
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
$id = (int)($_POST['id'] ?? 0);
if ($action === 'toggle_user' && $id) {
$meta_pdo->prepare("UPDATE users SET is_active = 1 - is_active WHERE id = ?")->execute([$id]);
} elseif ($action === 'toggle_family' && $id) {
$meta_pdo->prepare("UPDATE families SET is_active = 1 - is_active WHERE id = ?")->execute([$id]);
} elseif ($action === 'toggle_admin' && $id) {
// Ne peut pas se retirer ses propres droits admin
if ($id !== (int)$_SESSION['user']['id']) {
$meta_pdo->prepare("UPDATE users SET is_admin = 1 - is_admin WHERE id = ?")->execute([$id]);
}
} elseif ($action === 'delete_user' && $id) {
if ($id !== (int)$_SESSION['user']['id']) {
$meta_pdo->prepare("DELETE FROM users WHERE id = ?")->execute([$id]);
}
} elseif ($action === 'regen_invite' && $id) {
$new_code = bin2hex(random_bytes(8));
$meta_pdo->prepare("UPDATE families SET invite_code = ? WHERE id = ?")->execute([$new_code, $id]);
}
header('Location: /admin/');
exit;
}
// ─── Données ──────────────────────────────────────────────────────────────────
$families = $meta_pdo->query("
SELECT f.*, COUNT(u.id) as member_count
FROM families f
LEFT JOIN users u ON u.family_id = f.id
GROUP BY f.id
ORDER BY f.id
")->fetchAll();
$users = $meta_pdo->query("
SELECT u.*, f.name as family_name
FROM users u
LEFT JOIN families f ON f.id = u.family_id
ORDER BY u.id
")->fetchAll();
$pageTitle = "Admin — HouseHub";
$activePage = "admin";
require __DIR__ . '/../header.php';
?>
<div class="pf-container" style="max-width:1000px;margin:32px auto;padding:0 16px">
<h1 style="font-size:1.5rem;font-weight:700;margin-bottom:4px">⚙️ Panneau d'administration</h1>
<p style="color:#64748b;margin-bottom:32px">Gestion des espaces familiaux et des utilisateurs</p>
<!-- ── Familles ─────────────────────────────────────────────────────────── -->
<h2 style="font-size:1.1rem;font-weight:600;margin-bottom:16px">
🏠 Espaces familiaux
<span style="background:#e2e8f0;border-radius:12px;padding:2px 10px;font-size:0.85rem;font-weight:500;margin-left:8px"><?= count($families) ?></span>
</h2>
<div style="overflow-x:auto;margin-bottom:40px">
<table style="width:100%;border-collapse:collapse;font-size:0.9rem">
<thead>
<tr style="background:#f8fafc;text-align:left">
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">#</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Nom</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">DB</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Code invitation</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Membres</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Statut</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($families as $f): ?>
<tr style="border-bottom:1px solid var(--border-light)">
<td style="padding:10px 14px;color:#94a3b8"><?= $f['id'] ?></td>
<td style="padding:10px 14px;font-weight:600"><?= htmlspecialchars($f['name']) ?></td>
<td style="padding:10px 14px"><code style="font-size:0.8rem;background:#f1f5f9;padding:2px 6px;border-radius:4px"><?= $f['db_name'] ?></code></td>
<td style="padding:10px 14px">
<code style="font-size:0.85rem"><?= $f['invite_code'] ?></code>
</td>
<td style="padding:10px 14px;text-align:center"><?= $f['member_count'] ?></td>
<td style="padding:10px 14px">
<span style="padding:3px 10px;border-radius:12px;font-size:0.8rem;font-weight:600;
background:<?= $f['is_active'] ? '#dcfce7' : '#fee2e2' ?>;
color:<?= $f['is_active'] ? '#16a34a' : '#dc2626' ?>">
<?= $f['is_active'] ? 'Actif' : 'Inactif' ?>
</span>
</td>
<td style="padding:10px 14px;display:flex;gap:8px;flex-wrap:wrap">
<form method="post" style="display:inline">
<input type="hidden" name="action" value="toggle_family">
<input type="hidden" name="id" value="<?= $f['id'] ?>">
<button class="pf-btn btn-secondary" style="padding:4px 12px;font-size:0.8rem">
<?= $f['is_active'] ? 'Désactiver' : 'Activer' ?>
</button>
</form>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="regen_invite">
<input type="hidden" name="id" value="<?= $f['id'] ?>">
<button class="pf-btn btn-secondary" style="padding:4px 12px;font-size:0.8rem"
onclick="return confirm('Regénérer le code ?')">
🔄 Code
</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- ── Utilisateurs ─────────────────────────────────────────────────────── -->
<h2 style="font-size:1.1rem;font-weight:600;margin-bottom:16px">
👤 Utilisateurs
<span style="background:#e2e8f0;border-radius:12px;padding:2px 10px;font-size:0.85rem;font-weight:500;margin-left:8px"><?= count($users) ?></span>
</h2>
<div style="overflow-x:auto">
<table style="width:100%;border-collapse:collapse;font-size:0.9rem">
<thead>
<tr style="background:#f8fafc;text-align:left">
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">#</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Utilisateur</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Espace famille</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Rôle</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Statut</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Créé le</th>
<th style="padding:10px 14px;border-bottom:2px solid #e2e8f0">Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $u): $isSelf = $u['id'] == $_SESSION['user']['id']; ?>
<tr style="border-bottom:1px solid var(--border-light)<?= $isSelf ? ';background:#fafff4' : '' ?>">
<td style="padding:10px 14px;color:#94a3b8"><?= $u['id'] ?></td>
<td style="padding:10px 14px">
<strong><?= htmlspecialchars($u['display_name']) ?></strong>
<span style="color:#94a3b8;font-size:0.85rem;margin-left:6px">@<?= htmlspecialchars($u['username']) ?></span>
<?php if ($isSelf): ?><span style="font-size:0.75rem;color:#2563eb;margin-left:4px">(vous)</span><?php endif; ?>
</td>
<td style="padding:10px 14px"><?= $u['family_name'] ? htmlspecialchars($u['family_name']) : '<span style="color:#94a3b8">—</span>' ?></td>
<td style="padding:10px 14px">
<?php if ($u['is_admin']): ?>
<span style="background:#dbeafe;color:#1d4ed8;padding:2px 8px;border-radius:10px;font-size:0.8rem;font-weight:600">Admin</span>
<?php else: ?>
<span style="color:#94a3b8;font-size:0.85rem">Membre</span>
<?php endif; ?>
</td>
<td style="padding:10px 14px">
<span style="padding:3px 10px;border-radius:12px;font-size:0.8rem;font-weight:600;
background:<?= $u['is_active'] ? '#dcfce7' : '#fee2e2' ?>;
color:<?= $u['is_active'] ? '#16a34a' : '#dc2626' ?>">
<?= $u['is_active'] ? 'Actif' : 'Inactif' ?>
</span>
</td>
<td style="padding:10px 14px;color:#64748b;font-size:0.85rem"><?= date('d/m/Y', strtotime($u['created_at'])) ?></td>
<td style="padding:10px 14px">
<div style="display:flex;gap:6px;flex-wrap:wrap">
<?php if (!$isSelf): ?>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="toggle_user">
<input type="hidden" name="id" value="<?= $u['id'] ?>">
<button class="pf-btn btn-secondary" style="padding:4px 10px;font-size:0.8rem">
<?= $u['is_active'] ? 'Désactiver' : 'Activer' ?>
</button>
</form>
<form method="post" style="display:inline">
<input type="hidden" name="action" value="toggle_admin">
<input type="hidden" name="id" value="<?= $u['id'] ?>">
<button class="pf-btn btn-secondary" style="padding:4px 10px;font-size:0.8rem">
<?= $u['is_admin'] ? '↓ Membre' : '↑ Admin' ?>
</button>
</form>
<form method="post" style="display:inline" onsubmit="return confirm('Supprimer <?= htmlspecialchars($u['username']) ?> ?')">
<input type="hidden" name="action" value="delete_user">
<input type="hidden" name="id" value="<?= $u['id'] ?>">
<button class="pf-btn btn-secondary" style="padding:4px 10px;font-size:0.8rem;color:#dc2626">🗑</button>
</form>
<?php else: ?>
<span style="color:#94a3b8;font-size:0.8rem">—</span>
<?php endif; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<?php require __DIR__ . '/../footer.php'; ?>
-36
View File
@@ -1,36 +0,0 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../includes/db.php';
$input = json_decode(file_get_contents('php://input'), true);
if (!isset($input['action']) || !isset($input['event_id'])) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Action ou ID manquant.']);
exit;
}
$action = $input['action'];
$eventId = $input['event_id'];
try {
if ($action === 'delete') {
$stmt = $pdo->prepare("DELETE FROM pf_events WHERE id = ?");
$stmt->execute([$eventId]);
echo json_encode(['status' => 'success', 'message' => 'Événement supprimé.']);
} elseif ($action === 'update' && isset($input['new_type'])) {
$stmt = $pdo->prepare("UPDATE pf_events SET event_type = ? WHERE id = ?");
$stmt->execute([$input['new_type'], $eventId]);
echo json_encode(['status' => 'success', 'message' => 'Événement mis à jour.']);
} else {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Action non valide ou données manquantes.']);
}
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
?>
-62
View File
@@ -1,62 +0,0 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../includes/db.php';
$eventsToSave = json_decode(file_get_contents('php://input'), true);
if (empty($eventsToSave) || !is_array($eventsToSave)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Aucune donnée d\'événement reçue.']);
exit;
}
$inserted = [];
try {
$pdo->beginTransaction();
$sql = "INSERT INTO pf_events (event_date, event_type, person_id, duration)
VALUES (:event_date, :event_type, :person_id, :duration)";
$stmt = $pdo->prepare($sql);
foreach ($eventsToSave as $event) {
$person_id = null;
// Si un nom de personne est fourni
if (!empty($event['person'])) {
$personStmt = $pdo->prepare("SELECT id FROM pf_people WHERE name = ?");
$personStmt->execute([$event['person']]);
$personRow = $personStmt->fetch();
if ($personRow) {
$person_id = $personRow['id'];
}
}
$stmt->execute([
':event_date' => $event['date'],
':event_type' => $event['type'],
':person_id' => $person_id,
':duration' => $event['duration'] ?? 1.0,
]);
$inserted[] = [
'id' => $pdo->lastInsertId(),
'date' => $event['date'],
'type' => $event['type'],
'duration' => $event['duration'] ?? 1.0,
'person_id' => $person_id,
];
}
$pdo->commit();
echo json_encode([
'status' => 'success',
'inserted' => $inserted,
]);
} catch (Exception $e) {
$pdo->rollBack();
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => 'Erreur lors de la sauvegarde : ' . $e->getMessage()]);
}
-367
View File
@@ -1,367 +0,0 @@
/* === RESET SIMPLE === */
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
background: #f5f5f5;
color: #222;
}
/* === LAYOUT GLOBAL === */
.pf-container {
max-width: 1200px;
margin: 0 auto;
padding: 0 16px;
}
.pf-header {
background: #243b53;
color: #fff;
padding: 8px 0;
}
.pf-header-content {
display: flex;
align-items: center;
justify-content: space-between;
}
.pf-logo {
font-weight: 600;
font-size: 18px;
}
.pf-nav {
display: flex;
gap: 16px;
}
.pf-nav-link {
color: #d9e2ec;
text-decoration: none;
font-size: 14px;
padding: 4px 8px;
border-radius: 4px;
}
.pf-nav-link:hover {
background: rgba(255, 255, 255, 0.1);
}
.pf-nav-link--active {
background: #102a43;
color: #f0f4f8;
}
.pf-main {
padding: 24px 0 48px;
}
.pf-section {
margin-top: 24px;
}
.pf-section--panel {
background: #fff;
border-radius: 8px;
padding: 16px 16px 20px;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.pf-footer {
border-top: 1px solid #d9e2ec;
padding: 8px 0;
font-size: 12px;
color: #627d98;
background: #f0f4f8;
}
/* === CARDS & FLEX === */
.pf-card.pf-card--wide {
min-width: 400px; /* tu peux monter à 500 ou 600 selon ton goût */
flex: 1 1 400px; /* laisse la carte prendre plus de place dans la ligne */
}
/* Le tableau des vacances occupe toute la largeur disponible */
#schoolHolidaysTable {
width: auto;
table-layout: auto;
border-collapse: collapse;
}
.pf-card.pf-card--wide .pf-table-wrapper {
width: 100%;
overflow-x: auto;
}
/* En-têtes et cellules sans retour à la ligne */
#schoolHolidaysTable th,
#schoolHolidaysTable td {
white-space: nowrap; /* pas de retour à la ligne dans les cellules */
overflow: visible; /* pas de tronquage */
padding: 4px 8px;
text-align: center;
}
.pf-flex {
display: flex;
}
.pf-flex--wrap {
flex-wrap: wrap;
}
.pf-gap-lg {
gap: 24px;
}
.pf-card {
background: #f8fafc;
border-radius: 8px;
border: 1px solid #d9e2ec;
padding: 12px 14px;
}
.pf-card--small {
min-width: 240px;
max-width: 260px;
}
.pf-card-title {
margin: 0 0 8px;
font-size: 15px;
}
.pf-card-body {
font-size: 13px;
}
label {
font-size: 12px;
}
/* === TABLES === */
/* Appliquer un layout fixe pour harmoniser la largeur des colonnes */
#planningTable {
table-layout: fixed;
width: 100%; /* le tableau prend toute la largeur disponible */
}
/* Colonnes : texte centré et césures possibles */
#planningTable th,
#planningTable td {
text-align: center;
white-space: nowrap; /* évite les retours à la ligne sauvages */
overflow: hidden;
text-overflow: ellipsis; /* coupe avec "..." si le texte déborde */
}
/* Colonnes "Mois" et "Semaine" un peu plus étroites */
#planningTable th:nth-child(1),
#planningTable td:nth-child(1) {
width: 2%; /* Mois */
}
#planningTable th:nth-child(2),
#planningTable td:nth-child(2) {
width: 2%; /* Semaine */
}
/* Colonnes jours (Lundi à Vendredi) réparties sur une largeur raisonnable */
#planningTable th:nth-child(3),
#planningTable td:nth-child(3),
#planningTable th:nth-child(4),
#planningTable td:nth-child(4),
#planningTable th:nth-child(5),
#planningTable td:nth-child(5),
#planningTable th:nth-child(6),
#planningTable td:nth-child(6),
#planningTable th:nth-child(7),
#planningTable td:nth-child(7) {
width: 2%; /* ajustable selon ton rendu */
}
/* Colonnes de totaux (Off / Extra / Centre / Avis) un peu plus compactes */
#planningTable th:nth-child(8),
#planningTable td:nth-child(8),
#planningTable th:nth-child(9),
#planningTable td:nth-child(9),
#planningTable th:nth-child(10),
#planningTable td:nth-child(10),
#planningTable th:nth-child(11),
#planningTable td:nth-child(11) {
width: 4%;
}
.pf-table-wrapper {
max-height: 600px;
overflow: auto;
border-radius: 8px;
background: #fff;
border: 1px solid #d9e2ec;
}
.pf-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
.pf-table th,
.pf-table td {
border: 1px solid #d9e2ec;
padding: 4px 6px;
text-align: center;
}
.pf-table thead th {
position: sticky;
top: 0;
background: #f0f4f8;
z-index: 1;
}
.pf-table--compact th,
.pf-table--compact td {
padding: 3px 4px;
}
/* === INPUTS === */
input[type="number"] {
width: 3.1rem;
font-size: 11px;
padding: 2px 3px;
}
/* === COLOR CODING POUR LE FAMILY CALENDAR === */
.fc-row--carole-off {
background: #ffe0e0;
}
.fc-row--bank-holiday {
background: #d9f7be;
}
/* Tableau recap vacances scolaires */
.fc-holidays-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
margin-top: 12px;
}
.fc-holidays-table th,
.fc-holidays-table td {
border: 1px solid #d9e2ec;
padding: 4px 6px;
text-align: left;
}
.fc-holidays-table th {
background-color: #f0f4f8;
}
/* Cellule de jour sélectionnée dans le calendrier */
.fc-day--selected {
background-color: #bde4ff !important; /* Une couleur de sélection claire, !important pour forcer le style */
cursor: pointer;
}
/* Le menu contextuel flottant */
.fc-selection-menu {
display: none; /* Caché par défaut */
position: absolute; /* Permet de le positionner près de la souris */
z-index: 100;
background-color: white;
border: 1px solid #ccc;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
border-radius: 6px;
padding: 8px;
font-size: 12px;
}
.fc-selection-menu .fc-menu-section {
margin-bottom: 8px;
}
.fc-selection-menu .fc-menu-section:last-child {
margin-bottom: 0;
}
.fc-selection-menu strong {
display: block;
margin-bottom: 4px;
font-weight: 600;
}
.fc-selection-menu button {
display: block;
width: 100%;
background: none;
border: 1px solid #ddd;
border-radius: 4px;
padding: 4px 8px;
margin-top: 4px;
text-align: left;
cursor: pointer;
}
.fc-selection-menu button:hover {
background-color: #f0f4f8;
border-color: #b0c4de;
}
/* --- Couleurs de base pour la légende et les jours --- */
.fc-day--school-holiday {
background-color: #e5d9f2;
}
.fc-day--public-holiday {
background-color: #e0e0e0;
}
.fc-day--off-carole {
background-color: #ffe9a7;
}
.fc-day--extra-off-carole {
background-color: #ffd59b;
}
.fc-day--has-guard {
box-sizing: border-box;
}
/* Bordure verte pour Centre */
.fc-day--has-guard.fc-day--centre {
border: 2px solid #4caf50;
}
/* Bordure bleue pour Avis */
.fc-day--has-guard.fc-day--avis {
border: 2px solid #2196f3;
}
/* --- Combinaisons avec dégradés --- */
/* Combinaison Vacances + Off Carole */
.fc-day--school-holiday.fc-day--off-carole {
background-image: linear-gradient(45deg, #e5d9f2 49%, #ffe9a7 51%);
}
/* Combinaison Vacances + Extra Off Carole */
.fc-day--school-holiday.fc-day--extra-off-carole {
background-image: linear-gradient(45deg, #e5d9f2 49%, #ffd59b 51%);
}
/* Eléments pour la légende */
.pf-legend-item {
display: flex;
align-items: center;
margin-bottom: 5px;
}
.pf-legend-color {
width: 20px;
height: 20px;
border: 1px solid #ccc;
margin-right: 10px;
flex-shrink: 0;
}
-792
View File
@@ -1,792 +0,0 @@
/**
* family-calendar.js
* Distinction congés / modes de garde + modif/suppression locales.
*/
document.addEventListener("DOMContentLoaded", () => {
const CONGE_TYPES = ["OFF_CAROLE", "EXTRA_OFF_CAROLE"];
const GUARDE_TYPES = ["CENTRE", "AVIS"];
const MODIFIABLE_TYPES = [...CONGE_TYPES, ...GUARDE_TYPES];
class FamilyCalendar {
constructor() {
this.planningBody = document.getElementById("planningBody");
this.selectionMenu = document.getElementById("selectionMenu");
this.schoolHolidaysTableBody = document.querySelector(
"#schoolHolidaysTable tbody"
);
if (!this.planningBody || !this.selectionMenu) {
console.error("planningBody ou selectionMenu manquant");
return;
}
this.isSelecting = false;
this.selectedCells = [];
this.dbEvents = [];
this.fixedEvents = [];
this.events = [];
this.menuJustOpened = false;
this.init();
window.cal = this;
}
// ================== INIT ==================
async init() {
this.setupEventListeners();
this.weeks = this.generateWeeksStructure();
this.dbEvents = this.loadDbEvents();
this.fixedEvents = await this.fetchPublicAndSchoolHolidays();
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
}
loadDbEvents() {
if (typeof serverData !== "undefined" && Array.isArray(serverData)) {
return serverData.map((evt) => ({
id: evt.id,
date: evt.event_date,
type: evt.event_type,
duration: parseFloat(evt.duration),
person_id: evt.person_id,
}));
}
return [];
}
async fetchPublicAndSchoolHolidays() {
// 1. Jours fériés (fixes)
const publicHolidays = [
{ date: "2025-11-01", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2025-11-11", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2025-12-25", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-01-01", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-04-06", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-05-01", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-05-08", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-05-14", type: "PUBLIC_HOLIDAY", duration: 1 },
{ date: "2026-05-25", type: "PUBLIC_HOLIDAY", duration: 1 },
].map((e, idx) => ({
id: `ph-${idx}`,
...e,
}));
// 2. Vacances scolaires (API)
const schoolHolidayEvents = [];
let holidayRecords = [];
try {
const response = await fetch(
"https://data.education.gouv.fr/api/explore/v2.1/catalog/datasets/fr-en-calendrier-scolaire/records?where=annee_scolaire='2025-2026' AND zones LIKE '%Zone C%'&limit=100"
);
const schoolHolidaysData = await response.json();
holidayRecords = schoolHolidaysData.results || [];
holidayRecords.forEach((record, index) => {
let current = new Date(record.start_date);
let end = new Date(record.end_date);
while (current < end) {
const isoDate = `${current.getFullYear()}-${String(
current.getMonth() + 1
).padStart(2, "0")}-${String(current.getDate()).padStart(2, "0")}`;
schoolHolidayEvents.push({
id: `sh-${isoDate}-${index}`,
date: isoDate,
type: "VACANCES_SCOLAIRES",
duration: 1,
});
current.setDate(current.getDate() + 1);
}
});
// Remplir le tableau HTML des vacances
this.renderSchoolHolidaysTable(holidayRecords);
} catch (error) {
console.error("Impossible de charger les vacances scolaires.", error);
}
// 3. Retourne tous les événements "fixes"
return [...publicHolidays, ...schoolHolidayEvents];
}
generateWeeksStructure() {
const weeks = [];
const start = new Date(2025, 8, 1); // 1er septembre 2025
const end = new Date(2026, 7, 31); // 31 août 2026
let current = new Date(start);
// Remonter au lundi le plus proche <= start
while (current.getDay() !== 1) current.setDate(current.getDate() - 1);
while (current <= end) {
const monday = new Date(current);
// C’est CETTE date qui doit servir de référence pour le mois
const weekMonthDate = monday;
const weekData = {
id: `${monday.getFullYear()}-W${getWeekOfYear(monday)}`,
monthKey: `${weekMonthDate.getFullYear()}-${String(
weekMonthDate.getMonth() + 1
).padStart(2, "0")}`,
monthName: getMonthNameFr(weekMonthDate.getMonth()),
weekLabel: `W${getWeekOfYear(monday)}`,
dayDates: {},
dayFlags: {},
};
["mon", "tue", "wed", "thu", "fri"].forEach((dayKey, index) => {
const dayDate = new Date(monday);
dayDate.setDate(monday.getDate() + index);
weekData.dayDates[dayKey] = dayDate;
weekData.dayFlags[dayKey] = { eventsOnDay: [] };
});
weeks.push(weekData);
current.setDate(current.getDate() + 7);
}
// Juste pour verrouiller l’ordre si un jour tu modifies current ailleurs
weeks.sort((a, b) => a.dayDates.mon - b.dayDates.mon);
return weeks;
}
reprocessAndRender() {
this.reprocessEvents();
this.renderTable();
this.updateGlobalSummary();
}
reprocessEvents() {
this.weeks.forEach((w) => {
w.totals = { offCarole: 0, extraOffCarole: 0, centre: 0, avis: 0 };
Object.values(w.dayFlags).forEach((df) => (df.eventsOnDay = []));
});
this.events.forEach((evt) => {
const evtDate = new Date(evt.date + "T00:00:00");
const week = this.weeks.find(
(w) => evtDate >= w.dayDates.mon && evtDate <= w.dayDates.fri
);
if (!week) return;
const dayKey = Object.keys(week.dayDates).find(
(k) => week.dayDates[k].toDateString() === evtDate.toDateString()
);
if (dayKey) {
week.dayFlags[dayKey].eventsOnDay.push(evt);
}
const dur = parseFloat(evt.duration) || 1;
switch (evt.type) {
case "OFF_CAROLE":
week.totals.offCarole += dur;
break;
case "EXTRA_OFF_CAROLE":
week.totals.extraOffCarole += dur;
break;
case "CENTRE":
week.totals.centre += dur;
break;
case "AVIS":
week.totals.avis += dur;
break;
}
});
}
updateGlobalSummary() {
const summaryDiv = document.getElementById("globalSummary");
if (!summaryDiv) return;
// On filtre uniquement sur les événements "DB" pour le récap (pas les vacances/fériés)
const allEvents = this.dbEvents || [];
const totalOff = allEvents
.filter((e) => e.type === "OFF_CAROLE")
.reduce((sum, e) => sum + Number(e.duration || 1), 0);
const totalExtraOff = allEvents
.filter((e) => e.type === "EXTRA_OFF_CAROLE")
.reduce((sum, e) => sum + Number(e.duration || 1), 0);
summaryDiv.innerHTML = `
<p><strong>Off Carole :</strong> ${totalOff} jours</p>
<p><strong>Extra Off Carole :</strong> ${totalExtraOff} jours</p>
`;
}
renderSchoolHolidaysTable(holidayRecords) {
if (!this.schoolHolidaysTableBody) return;
this.schoolHolidaysTableBody.innerHTML = "";
const uniqueHolidays = new Map();
holidayRecords.forEach((r) =>
uniqueHolidays.set(`${r.start_date}|${r.end_date}`, r)
);
[...uniqueHolidays.values()]
.sort((a, b) => new Date(a.start_date) - new Date(b.start_date))
.forEach((record) => {
const tr = document.createElement("tr");
const startDate = new Date(record.start_date);
const endDate = new Date(record.end_date);
tr.innerHTML = `
<td>${record.description}</td>
<td>${startDate.toLocaleDateString("fr-FR")}</td>
<td>${endDate.toLocaleDateString("fr-FR")}</td>
<td>${record.zones}</td>
`;
this.schoolHolidaysTableBody.appendChild(tr);
});
}
renderTable() {
this.planningBody.innerHTML = "";
const monthSpans = this.weeks.reduce(
(acc, w) => ({ ...acc, [w.monthKey]: (acc[w.monthKey] || 0) + 1 }),
{}
);
const monthRowRendered = {};
const formatTotal = (total) =>
total > 0 ? (Number.isInteger(total) ? total : total.toFixed(1)) : "";
this.weeks.forEach((week) => {
const tr = document.createElement("tr");
if (!monthRowRendered[week.monthKey]) {
monthRowRendered[week.monthKey] = true;
const tdMonth = document.createElement("td");
tdMonth.rowSpan = monthSpans[week.monthKey] || 1;
tdMonth.textContent = week.monthName;
tr.appendChild(tdMonth);
}
const tdWeek = document.createElement("td");
tdWeek.textContent = week.weekLabel;
tr.appendChild(tdWeek);
["mon", "tue", "wed", "thu", "fri"].forEach((dayKey) => {
const td = document.createElement("td");
const dayDate = week.dayDates[dayKey];
td.dataset.date = `${dayDate.getFullYear()}-${String(
dayDate.getMonth() + 1
).padStart(2, "0")}-${String(dayDate.getDate()).padStart(2, "0")}`;
td.textContent = `${String(dayDate.getDate()).padStart(
2,
"0"
)}/${String(dayDate.getMonth() + 1).padStart(2, "0")}`;
td.className = "";
let hasGarde = false;
let gardeType = null;
week.dayFlags[dayKey].eventsOnDay.forEach((evt) => {
const classMap = {
VACANCES_SCOLAIRES: "fc-day--school-holiday",
PUBLIC_HOLIDAY: "fc-day--public-holiday",
OFF_CAROLE: "fc-day--off-carole",
EXTRA_OFF_CAROLE: "fc-day--extra-off-carole",
};
if (classMap[evt.type]) {
td.classList.add(classMap[evt.type]);
}
if (GUARDE_TYPES.includes(evt.type)) {
hasGarde = true;
gardeType = evt.type;
}
});
if (hasGarde) {
td.classList.add("fc-day--has-guard");
if (gardeType === "CENTRE") td.classList.add("fc-day--centre");
if (gardeType === "AVIS") td.classList.add("fc-day--avis");
}
tr.appendChild(td);
});
const tdOff = document.createElement("td");
tdOff.textContent = formatTotal(week.totals.offCarole);
tr.appendChild(tdOff);
const tdExtra = document.createElement("td");
tdExtra.textContent = formatTotal(week.totals.extraOffCarole);
tr.appendChild(tdExtra);
const tdCentre = document.createElement("td");
tdCentre.textContent = formatTotal(week.totals.centre);
tr.appendChild(tdCentre);
const tdAvis = document.createElement("td");
tdAvis.textContent = formatTotal(week.totals.avis);
tr.appendChild(tdAvis);
this.planningBody.appendChild(tr);
});
}
// ================== INTERACTIONS ==================
setupEventListeners() {
this.planningBody.addEventListener("mousedown", (e) =>
this.handleMouseDown(e)
);
document.addEventListener("mousemove", (e) => this.handleMouseMove(e));
document.addEventListener("mouseup", (e) => this.handleMouseUp(e));
document.addEventListener(
"click",
(e) => this.handleClickOutsideMenu(e),
true
);
this.selectionMenu.addEventListener("click", (e) =>
this.handleMenuClick(e)
);
}
handleMouseDown(e) {
const cell = e.target.closest("td[data-date]");
if (!cell) return;
e.preventDefault();
this.clearSelection();
this.isSelecting = true;
cell.classList.add("fc-day--selected");
this.selectedCells.push(cell);
}
handleMouseMove(e) {
if (!this.isSelecting) return;
const cell = e.target.closest("td[data-date]");
if (cell && !this.selectedCells.includes(cell)) {
cell.classList.add("fc-day--selected");
this.selectedCells.push(cell);
}
}
handleMouseUp(e) {
if (!this.isSelecting) return;
this.isSelecting = false;
if (this.selectedCells.length === 0) return;
if (this.selectedCells.length === 1) {
const date = this.selectedCells[0].dataset.date;
const eventsOnDay = this.events.filter(
(evt) => evt.date === date && MODIFIABLE_TYPES.includes(evt.type)
);
const conge = eventsOnDay.find((e) => CONGE_TYPES.includes(e.type));
const garde = eventsOnDay.find((e) => GUARDE_TYPES.includes(e.type));
if (!conge && !garde) {
this.showAddMenu(e);
} else {
this.showEditMenuForDay(e, { conge, garde, date });
}
} else {
// Multi-jours : on reste en mode ajout, avec contrôles plus tard
this.showAddMenu(e);
}
}
handleClickOutsideMenu(e) {
if (this.menuJustOpened) {
this.menuJustOpened = false;
return;
}
if (
this.selectionMenu.style.display === "block" &&
!this.selectionMenu.contains(e.target)
) {
this.clearSelection();
}
}
clearSelection() {
this.selectionMenu.style.display = "none";
this.selectedCells.forEach((cell) =>
cell.classList.remove("fc-day--selected")
);
this.selectedCells = [];
}
showAddMenu(e) {
this.selectionMenu.innerHTML = `
<div class="fc-menu-section"><strong>Ajouter</strong></div>
<button data-action="add" data-type="OFF_CAROLE" data-person="Carole">Off Carole</button>
<button data-action="add" data-type="EXTRA_OFF_CAROLE" data-person="Carole">Extra Off Carole</button>
<div class="fc-menu-section"><strong>Mode de Garde</strong></div>
<button data-action="add" data-type="CENTRE">Centre</button>
<button data-action="add" data-type="AVIS">Avis</button>
`;
this.positionAndShowMenu(e);
}
showEditMenuForDay(e, { conge, garde, date }) {
console.log(
"[EDIT MENU] pour date",
date,
"conge =",
conge,
"garde =",
garde
);
let congeSection = "";
if (conge) {
const oppositeConge =
conge.type === "OFF_CAROLE" ? "EXTRA_OFF_CAROLE" : "OFF_CAROLE";
congeSection = `
<div class="fc-menu-section"><strong>Congé Carole</strong></div>
<button data-action="update" data-event-id="${
conge.id
}" data-new-type="${oppositeConge}">
Remplacer par ${oppositeConge.replace(/_/g, " ")}
</button>
<button data-action="delete" data-event-id="${conge.id}">
Supprimer le congé
</button>
`;
} else {
congeSection = `
<div class="fc-menu-section"><strong>Ajouter un congé</strong></div>
<button data-action="add-single" data-type="OFF_CAROLE" data-date="${date}" data-person="Carole">
Off Carole
</button>
<button data-action="add-single" data-type="EXTRA_OFF_CAROLE" data-date="${date}" data-person="Carole">
Extra Off Carole
</button>
`;
}
let gardeSection = "";
if (garde) {
const oppositeGarde = garde.type === "CENTRE" ? "AVIS" : "CENTRE";
gardeSection = `
<div class="fc-menu-section"><strong>Mode de garde</strong></div>
<button data-action="update" data-event-id="${garde.id}" data-new-type="${oppositeGarde}">
Remplacer par ${oppositeGarde}
</button>
<button data-action="delete" data-event-id="${garde.id}">
Supprimer le mode de garde
</button>
`;
} else {
gardeSection = `
<div class="fc-menu-section"><strong>Ajouter mode de garde</strong></div>
<button data-action="add-single" data-type="CENTRE" data-date="${date}">
Centre
</button>
<button data-action="add-single" data-type="AVIS" data-date="${date}">
Avis
</button>
`;
}
this.selectionMenu.innerHTML = congeSection + gardeSection;
this.positionAndShowMenu(e);
}
positionAndShowMenu(e) {
this.selectionMenu.style.display = "block";
this.selectionMenu.style.left = `${e.pageX + 5}px`;
this.selectionMenu.style.top = `${e.pageY + 5}px`;
this.menuJustOpened = true;
}
async handleMenuClick(e) {
const button = e.target.closest("button[data-action]");
if (!button) return;
const { action, eventId, newType, type, person, date } = button.dataset;
// === AJOUT MULTI-JOURS (sélection de plusieurs cellules) ===
if (action === "add") {
const selectedDates = this.selectedCells.map((c) => c.dataset.date);
const existingOnDates = this.dbEvents.filter((evt) =>
selectedDates.includes(evt.date)
);
// Contrôles métier : pas de double congé / pas de double mode de garde
if (CONGE_TYPES.includes(type)) {
const hasCongeConflict = existingOnDates.some((evt) =>
CONGE_TYPES.includes(evt.type)
);
if (hasCongeConflict) {
alert(
"Impossible d'ajouter un congé : au moins une date a déjà un congé (Off/Extra Off)."
);
this.clearSelection();
return;
}
} else if (GUARDE_TYPES.includes(type)) {
const hasGardeConflict = existingOnDates.some((evt) =>
GUARDE_TYPES.includes(evt.type)
);
if (hasGardeConflict) {
alert(
"Impossible d'ajouter un mode de garde : au moins une date a déjà Centre/Avis."
);
this.clearSelection();
return;
}
}
const newEvents = this.selectedCells.map((cell) => ({
date: cell.dataset.date,
type,
person,
duration: 1.0,
}));
this.clearSelection();
try {
const response = await fetch("/api/save-events.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newEvents),
});
if (!response.ok) {
throw new Error("Erreur HTTP " + response.status);
}
// Resync DB events
const resEvents = await fetch("/api/get-events.php");
if (!resEvents.ok) {
throw new Error("Erreur lors du rechargement des événements.");
}
const dataEvents = await resEvents.json();
this.dbEvents = dataEvents.events || [];
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
} catch (err) {
console.error(err);
alert("Erreur lors de l'ajout.");
}
return;
}
// === AJOUT SUR UNE SEULE DATE (menu combiné d'un jour) ===
if (action === "add-single") {
const targetDate = date;
const existingOnDate = this.dbEvents.filter(
(evt) => evt.date === targetDate
);
if (CONGE_TYPES.includes(type)) {
const hasCongeConflict = existingOnDate.some((evt) =>
CONGE_TYPES.includes(evt.type)
);
if (hasCongeConflict) {
alert("Un congé existe déjà ce jour-là.");
this.clearSelection();
return;
}
} else if (GUARDE_TYPES.includes(type)) {
const hasGardeConflict = existingOnDate.some((evt) =>
GUARDE_TYPES.includes(evt.type)
);
if (hasGardeConflict) {
alert("Un mode de garde existe déjà ce jour-là.");
this.clearSelection();
return;
}
}
const newEvent = {
date: targetDate,
type,
person,
duration: 1.0,
};
this.clearSelection();
try {
const response = await fetch("/api/save-events.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify([newEvent]),
});
if (!response.ok) {
throw new Error("Erreur HTTP " + response.status);
}
// Resync DB events
const resEvents = await fetch("/api/get-events.php");
if (!resEvents.ok) {
throw new Error("Erreur lors du rechargement des événements.");
}
const dataEvents = await resEvents.json();
this.dbEvents = dataEvents.events || [];
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
} catch (err) {
console.error(err);
alert("Erreur lors de l'ajout.");
}
return;
}
// === SUPPRESSION ===
if (action === "delete") {
if (!eventId) {
console.warn("Bouton delete sans eventId, action ignorée.");
this.clearSelection();
return;
}
this.clearSelection();
try {
const response = await fetch("/api/manage-event.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ action: "delete", event_id: eventId }),
});
if (!response.ok) {
const errData = await response.json().catch(() => ({}));
throw new Error(
errData.message || "Erreur HTTP " + response.status
);
}
// Resync DB events
const resEvents = await fetch("/api/get-events.php");
if (!resEvents.ok) {
throw new Error("Erreur lors du rechargement des événements.");
}
const dataEvents = await resEvents.json();
this.dbEvents = dataEvents.events || [];
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
} catch (err) {
console.error(err);
alert("Erreur lors de la suppression : " + err.message);
}
return;
}
// === MODIFICATION (change OFF <-> EXTRA ou CENTRE <-> AVIS) ===
if (action === "update") {
console.log("[UPDATE] click sur bouton update", { eventId, newType });
if (!eventId) {
console.warn("Bouton update sans eventId, action ignorée.");
this.clearSelection();
return;
}
this.clearSelection();
try {
const response = await fetch("/api/manage-event.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
action: "update",
event_id: eventId,
new_type: newType,
}),
});
if (!response.ok) {
const errData = await response.json().catch(() => ({}));
throw new Error(
errData.message || "Erreur HTTP " + response.status
);
}
// Resync DB events
const resEvents = await fetch("/api/get-events.php");
if (!resEvents.ok) {
throw new Error("Erreur lors du rechargement des événements.");
}
const dataEvents = await resEvents.json();
this.dbEvents = dataEvents.events || [];
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
} catch (err) {
console.error("[UPDATE] Erreur lors de la modification :", err);
alert("Erreur lors de la modification : " + err.message);
}
return;
}
}
async manageEvent(payload) {
try {
const response = await fetch("/api/manage-event.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!response.ok) {
const errData = await response.json().catch(() => ({}));
throw new Error(errData.message || "Erreur HTTP " + response.status);
}
const resEvents = await fetch("/api/get-events.php");
if (!resEvents.ok) {
throw new Error("Erreur lors du rechargement des événements.");
}
const dataEvents = await resEvents.json();
this.dbEvents = dataEvents.events || [];
this.events = [...this.dbEvents, ...this.fixedEvents];
this.reprocessAndRender();
} catch (error) {
console.error("Erreur manageEvent :", error);
alert("Erreur: " + error.message);
}
}
}
function getWeekOfYear(date) {
const d = new Date(
Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())
);
d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
return Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
}
function getMonthNameFr(monthIndex) {
return (
[
"Janvier",
"Fevrier",
"Mars",
"Avril",
"Mai",
"Juin",
"Juillet",
"Aout",
"Septembre",
"Octobre",
"Novembre",
"Decembre",
][monthIndex] || ""
);
}
new FamilyCalendar();
});
+96
View File
@@ -0,0 +1,96 @@
<?php
require __DIR__ . '/includes/auth.php';
require __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/i18n.php';
require_login('/login.php');
// ============================================================================
// DIAGNOSTIC ONBOARDING (Vérifie si le budget est prêt à être utilisé)
// ============================================================================
$currentYear = date('Y');
$hasCategories = ((int)$pdo->query("SELECT COUNT(*) FROM pf_budget_categories")->fetchColumn() > 0);
$hasSalaries = ((int)$pdo->query("SELECT COUNT(*) FROM pf_salary_config WHERE year = $currentYear")->fetchColumn() > 0);
$hasAccounts = ((int)$pdo->query("SELECT COUNT(*) FROM pf_bank_accounts")->fetchColumn() > 0);
$hasBudgetItems = ((int)$pdo->query("SELECT COUNT(*) FROM pf_budget_items")->fetchColumn() > 0);
// Le minimum vital pour que ça tourne
$isBudgetSetupOk = ($hasCategories && $hasSalaries && $hasAccounts);
// Gestion de l'onglet actif (par défaut 'suivi')
$tab = $_GET['tab'] ?? 'suivi';
$pageTitle = tr('budget_page_title');
$activePage = "budget";
$pageCss = "/modules/budget/budget.css";
require __DIR__ . '/header.php';
?>
<div class="pf-container">
<div class="pf-hero budget-hero">
<div class="budget-title-group">
<h1><?= tr('budget_main_header') ?></h1>
<!-- Bouton avec séparation claire entre l'engrenage animable et l'alerte fixe -->
<button class="btn-header-settings" onclick="openBudgetSettings()" title="<?= tr('settings') ?>">
<span class="gear-icon-anim">⚙️</span>
<?php if (!$isBudgetSetupOk || !$hasBudgetItems): ?>
<span class="alert-dot">!</span>
<?php endif; ?>
</button>
</div>
<nav class="budget-tabs-container">
<a href="?tab=suivi" class="tab-item <?= $tab == 'suivi' ? 'active' : '' ?>">
<span class="tab-icon">🗓️</span>
<span><?= tr('budget_tab_tracking') ?></span>
</a>
<a href="?tab=budget_prev" class="tab-item <?= $tab == 'budget_prev' ? 'active' : '' ?>">
<span class="tab-icon">🎯</span>
<span><?= tr('budget_tab_prev') ?></span>
</a>
<a href="?tab=epargne" class="tab-item <?= $tab == 'epargne' ? 'active' : '' ?>">
<span class="tab-icon">🐷</span>
<span><?= tr('budget_tab_savings') ?></span>
</a>
<a href="?tab=recap" class="tab-item <?= $tab == 'recap' ? 'active' : '' ?>">
<span class="tab-icon">📊</span>
<span><?= tr('budget_tab_recap') ?></span>
</a>
<a href="?tab=provisions" class="tab-item <?= $tab == 'provisions' ? 'active' : '' ?>">
<span class="tab-icon">🧮</span>
<span><?= tr('budget_tab_provisions') ?></span>
</a>
</nav>
</div>
<section class="pf-section">
<?php
$allowedTabs = ['recap', 'suivi', 'epargne', 'budget_prev', 'provisions'];
if (in_array($tab, $allowedTabs)) {
$viewPath = __DIR__ . "/modules/budget/views/" . $tab . ".php";
if (file_exists($viewPath)) {
include $viewPath;
} else {
echo "<div class='budget-error-msg'>";
echo "<h3>" . tr('budget_err_file_not_found') . "</h3>";
echo "<p>" . sprintf(tr('budget_err_file_detail'), htmlspecialchars($tab)) . "</p>";
echo "</div>";
}
} else {
echo "<p>" . tr('budget_err_not_authorized') . "</p>";
}
?>
</section>
</div>
<?php
require __DIR__ . '/modules/budget/views/settings_modal.php';
require __DIR__ . '/footer.php';
?>
+91
View File
@@ -0,0 +1,91 @@
<?php
require __DIR__ . '/includes/auth.php';
require_login();
require_once __DIR__ . '/includes/i18n.php';
$pageTitle = 'Calendrier iOS — HouseHub';
$activePage = 'calendar-ios';
$mainClass = 'pf-calendar-ios-page';
require __DIR__ . '/header.php';
?>
<link rel="stylesheet" href="/modules/calendar-ios/assets/calendar-ios.css">
<div class="pf-container ios-calendar-wrap">
<section class="pf-panel-card">
<div class="ios-calendar-head">
<h1>📱 <?= tr('menu_calendar_ios') ?></h1>
<div class="ios-calendar-head-actions">
<button type="button" class="ios-agenda-btn ios-agenda-btn--ghost" id="ios-sync-btn">Synchroniser</button>
</div>
</div>
<p class="ios-agenda-intro">Les événements viennent de HouseHub après synchro iCloud. <strong>Synchroniser</strong> met à jour tous les calendriers du compte ; les changements locaux partent au prochain envoi.</p>
<details class="ios-cal-prefs-details" id="ios-cal-prefs-details">
<summary class="ios-cal-prefs-summary">Calendriers affichés et couleurs</summary>
<p class="ios-cal-prefs-help">Décoche un calendrier pour le masquer dans l’agenda. La couleur est libre (repère la teinte iOS sur ton téléphone puis copie-la avec le sélecteur).</p>
<div id="ios-calendar-prefs-rows" class="ios-cal-prefs-rows"></div>
<p id="ios-calendar-prefs-msg" class="ios-cal-prefs-msg" role="status"></p>
<button type="button" class="pf-btn" id="ios-calendar-prefs-save">Enregistrer affichage &amp; couleurs</button>
</details>
</section>
<section class="pf-panel-card ios-agenda-card">
<div class="ios-agenda-toolbar">
<div class="ios-agenda-title" id="ios-agenda-title" aria-live="polite">—</div>
<div class="ios-agenda-segments" role="tablist">
<button type="button" class="ios-seg" data-ios-view="day" role="tab">Jour</button>
<button type="button" class="ios-seg ios-seg--active" data-ios-view="week" role="tab">Semaine</button>
<button type="button" class="ios-seg" data-ios-view="month" role="tab">Mois</button>
</div>
<div class="ios-agenda-nav">
<button type="button" class="ios-agenda-btn" id="ios-agenda-prev" aria-label="Période précédente">‹</button>
<button type="button" class="ios-agenda-btn" id="ios-agenda-next" aria-label="Période suivante">›</button>
<button type="button" class="ios-agenda-today" id="ios-agenda-today">Aujourd'hui</button>
<button type="button" class="ios-agenda-add" id="ios-agenda-add" title="Nouvel événement">+</button>
<button type="button" class="ios-agenda-listlink" id="ios-view-list">Liste</button>
</div>
</div>
<div id="ios-agenda-mount" class="ios-agenda-mount"></div>
</section>
<section class="pf-panel-card" id="ios-edit-panel">
<h2 class="pf-card-h2">Ajouter / Modifier un événement</h2>
<form id="ios-event-form" class="ios-form-grid">
<input type="hidden" id="ios-event-id">
<div class="pf-form-group">
<label class="pf-label">Titre</label>
<input class="pf-input" id="ios-title" required>
</div>
<div class="pf-form-group">
<label class="pf-label">Lieu</label>
<input class="pf-input" id="ios-location">
</div>
<div class="pf-form-group">
<label class="pf-label">Début</label>
<input class="pf-input" id="ios-start" type="datetime-local" required>
</div>
<div class="pf-form-group">
<label class="pf-label">Fin</label>
<input class="pf-input" id="ios-end" type="datetime-local" required>
</div>
<div class="pf-form-group ios-form-full">
<label class="pf-label">Description</label>
<textarea class="pf-input" id="ios-description"></textarea>
</div>
<div class="ios-form-full ios-form-actions">
<button class="pf-btn" type="submit">Enregistrer</button>
<button class="pf-btn btn-secondary" type="button" id="ios-form-reset">Réinitialiser</button>
</div>
</form>
</section>
<section class="pf-panel-card" id="ios-list-section" style="display:none">
<h2 class="pf-card-h2">Événements (liste)</h2>
<div id="ios-sync-status" class="ios-agenda-intro"></div>
<div id="ios-events-list" class="ios-events-list"></div>
</section>
</div>
<script src="/modules/calendar-ios/assets/calendar-ios.js"></script>
<?php require __DIR__ . '/footer.php'; ?>
+20
View File
@@ -0,0 +1,20 @@
<?php
require_once dirname(__DIR__) . '/includes/meta_db.php';
$rows = $meta_pdo->query("SELECT user_id FROM user_calendar_integrations WHERE provider='icloud_caldav' AND status='connected'")->fetchAll();
foreach ($rows as $row) {
$userId = (int)$row['user_id'];
$url = 'http://localhost/modules/calendar-ios/api.php?action=sync';
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => [
'X-Requested-With: XMLHttpRequest',
// Le cron réel devra utiliser un mécanisme d'auth/session technique.
],
]);
curl_exec($ch);
curl_close($ch);
}
+117
View File
@@ -0,0 +1,117 @@
<?php
/**
* Cron: Todo daily reminder notifications via Discord webhook
* Runs every minute — sends Discord reminder when due_time is reached.
* Repeats every day at the same time (resets at midnight via notified_date).
* Usage: php /opt/container/househub/cron/todo_notify.php
*/
date_default_timezone_set('Europe/Paris');
$DB_HOST = getenv('DB_HOST') ?: 'househub-db';
$DB_USER = getenv('DB_USER') ?: 'househub';
$DB_PASS = getenv('DB_PASS') ?: 'changeme';
$DB_ROOT = getenv('DB_ROOT_PASS') ?: 'rootchangeme';
// Load .env if running from CLI outside container
$env_file = dirname(__DIR__) . '/.env';
if (file_exists($env_file)) {
foreach (file($env_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
if (strpos($line, '=') !== false && $line[0] !== '#') {
[$k, $v] = explode('=', $line, 2);
$k = trim($k); $v = trim($v);
if (!getenv($k)) putenv("$k=$v");
}
}
$DB_HOST = getenv('DB_HOST') ?: $DB_HOST;
$DB_USER = getenv('DB_USER') ?: $DB_USER;
$DB_PASS = getenv('DB_PASS') ?: $DB_PASS;
$DB_ROOT = getenv('DB_ROOT_PASS') ?: $DB_ROOT;
}
// Get list of families from meta DB
try {
$meta = new PDO(
"mysql:host=$DB_HOST;dbname=househub_meta;charset=utf8mb4",
'root', $DB_ROOT,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
);
$families = $meta->query("SELECT id FROM families")->fetchAll(PDO::FETCH_COLUMN);
} catch (Exception $e) {
exit("Cannot connect to meta DB: " . $e->getMessage() . "\n");
}
foreach ($families as $family_id) {
$db_name = 'househub_f' . $family_id;
try {
$pdo = new PDO(
"mysql:host=$DB_HOST;dbname=$db_name;charset=utf8mb4",
$DB_USER, $DB_PASS,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]
);
} catch (Exception $e) {
continue;
}
if (!$pdo->query("SHOW TABLES LIKE 'pf_todos'")->fetchColumn()) continue;
$ws = $pdo->prepare("SELECT content FROM pf_notes WHERE note_type='todo_settings' AND reference_id='webhook_discord'");
$ws->execute();
$webhook = $ws->fetchColumn();
if (!$webhook) continue;
// Daily reminder: exact HH:MM match (same logic as the original todo app)
$now = date('H:i');
$stmt = $pdo->prepare("
SELECT t.id, t.title, t.notes, t.due_time, t.priority,
l.name AS list_name, l.icon AS list_icon, l.color AS list_color
FROM pf_todos t
LEFT JOIN pf_todo_lists l ON l.id = t.list_id
WHERE t.due_time IS NOT NULL
AND TIME_FORMAT(t.due_time, '%H:%i') = ?
AND t.done = 0
");
$stmt->execute([$now]);
$priColors = ['high' => 0xef4444, 'medium' => 0xf59e0b, 'low' => 0x22c55e, 'none' => 0x3b82f6];
$priLabels = ['high' => '🔴 Haute', 'medium' => '🟡 Moyenne', 'low' => '🟢 Basse', 'none' => null];
foreach ($stmt->fetchAll() as $t) {
$time = substr($t['due_time'], 0, 5);
$priority = $t['priority'] ?? 'none';
$color = $priColors[$priority] ?? 0x3b82f6;
$fields = [];
if ($t['list_name']) {
$fields[] = ['name' => 'Liste', 'value' => $t['list_icon'] . ' ' . $t['list_name'], 'inline' => true];
}
if ($priLabels[$priority]) {
$fields[] = ['name' => 'Priorité', 'value' => $priLabels[$priority], 'inline' => true];
}
$fields[] = ['name' => 'Heure', 'value' => '⏰ ' . $time, 'inline' => true];
$embed = [
'title' => '🔔 Rappel : ' . $t['title'],
'color' => $color,
'fields' => $fields,
'footer' => ['text' => 'HouseHub Todo'],
];
if (!empty($t['notes'])) {
$embed['description'] = $t['notes'];
}
$payload = ['username' => 'HouseHub Todo', 'embeds' => [$embed]];
$ch = curl_init($webhook);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 5,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
curl_exec($ch);
curl_close($ch);
}
}
+210
View File
@@ -0,0 +1,210 @@
/* ════════════════════════════════════════════════════════════════════
dark-mode.css — Dark mode overrides (Cleaned & Optimized)
Chargé en dernier dans le head pour garantir la cascade.
════════════════════════════════════════════════════════════════════ */
/* ─── FONDS & CONTENEURS PRINCIPAUX ────────────────────────────────── */
[data-theme="dark"] .pf-card,
[data-theme="dark"] .pf-modal-content,
[data-theme="dark"] .budget-tabs-container,
[data-theme="dark"] .fc-header-row,
[data-theme="dark"] .fc-month-nav-row,
[data-theme="dark"] .fc-month-calendar-wrapper,
[data-theme="dark"] .fc-month-balances,
[data-theme="dark"] .hol-idea-card,
[data-theme="dark"] .pf-holidays__titlebar,
[data-theme="dark"] .hol-filters-row,
[data-theme="dark"] .cl-titlebar,
[data-theme="dark"] .pf-child-section,
[data-theme="dark"] .pf-child-totals-bar,
[data-theme="dark"] .pf-gift-card-compact,
[data-theme="dark"] .epargne-grid-table,
[data-theme="dark"] .sticky-col {
background: var(--bg-panel) !important;
border-color: var(--border-light) !important;
color: var(--text-main) !important;
}
[data-theme="dark"] .owner-tabs,
[data-theme="dark"] .fc-view-controls,
[data-theme="dark"] .fc-day--other-month,
[data-theme="dark"] .fc-minimal-balance-card,
[data-theme="dark"] .pf-summary-pill,
[data-theme="dark"] .pf-filter-bar {
background: var(--bg-page) !important;
border-color: var(--border-light) !important;
color: var(--text-muted) !important;
}
/* ─── TYPOGRAPHIE GLOBALE ──────────────────────────────────────────── */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] .pf-modal-title,
[data-theme="dark"] .pf-card-title,
[data-theme="dark"] .hol-main-title,
[data-theme="dark"] .pf-gift-title,
[data-theme="dark"] .budget-view h2,
[data-theme="dark"] .view-header h2,
[data-theme="dark"] .month-header-container {
color: var(--text-main) !important;
}
[data-theme="dark"] .pf-card-desc,
[data-theme="dark"] .tab-item {
color: var(--text-muted);
}
/* ─── INPUTS & SÉLECTEURS ──────────────────────────────────────────── */
[data-theme="dark"] .pf-input,
[data-theme="dark"] .pf-filter-select,
[data-theme="dark"] .hol-year-select,
[data-theme="dark"] .budget-view input,
[data-theme="dark"] .budget-view select,
[data-theme="dark"] .budget-view textarea,
[data-theme="dark"] .hol-idea-card input,
[data-theme="dark"] .hol-idea-card textarea,
[data-theme="dark"] .hol-idea-card select {
background: #1c2128 !important;
border-color: var(--border-light) !important;
color: var(--text-main) !important;
}
[data-theme="dark"] .pf-input::placeholder {
color: #484f58 !important;
}
/* ─── BOUTONS & ÉTATS ACTIFS ───────────────────────────────────────── */
[data-theme="dark"] .pf-btn.btn-secondary,
[data-theme="dark"] .fc-nav-button,
[data-theme="dark"] .fc-view-button,
[data-theme="dark"] .hol-map-toggle,
[data-theme="dark"] .cl-view-btn,
[data-theme="dark"] .pf-btn-icon-text,
[data-theme="dark"] .owner-tab {
background: var(--bg-panel) !important;
color: var(--text-muted) !important;
border-color: var(--border-light) !important;
}
[data-theme="dark"] .pf-btn.btn-secondary:hover,
[data-theme="dark"] .fc-nav-button:hover,
[data-theme="dark"] .hol-map-toggle:hover,
[data-theme="dark"] .pf-btn-icon-text:hover {
background: rgba(255, 255, 255, 0.06) !important;
color: var(--text-main) !important;
}
[data-theme="dark"] .tab-item.active,
[data-theme="dark"] .fc-view-button--active,
[data-theme="dark"] .cl-view-btn.is-active {
background: rgba(59, 130, 246, 0.15) !important;
color: var(--primary) !important;
border-color: rgba(59, 130, 246, 0.3) !important;
}
[data-theme="dark"] .owner-tab.active {
background: var(--primary) !important;
color: #fff !important;
}
/* ─── TABLES ───────────────────────────────────────────────────────── */
[data-theme="dark"] .pf-table,
[data-theme="dark"] .fc-month-table,
[data-theme="dark"] #planningTable-wrapper {
background: var(--bg-panel) !important;
color: var(--text-main);
border-color: var(--border-light) !important;
}
[data-theme="dark"] .pf-table thead th,
[data-theme="dark"] .fc-month-table th,
[data-theme="dark"] #planningTable thead th,
[data-theme="dark"] th.sticky-col,
[data-theme="dark"] .pf-child-header {
background: #1c2128 !important;
color: var(--text-muted) !important;
border-color: var(--border-light) !important;
}
[data-theme="dark"] .pf-table tbody td,
[data-theme="dark"] .fc-month-table td,
[data-theme="dark"] #planningTable tbody td {
border-color: rgba(48, 54, 61, 0.5) !important;
}
[data-theme="dark"] .pf-table tbody tr:hover td,
[data-theme="dark"] .fc-month-table td:hover:not(.fc-day--other-month) {
background: rgba(255, 255, 255, 0.04) !important;
}
[data-theme="dark"] .pf-table tfoot td {
background: #1c2128 !important;
border-color: rgba(48, 54, 61, 0.5) !important;
}
/* ─── MODULES SPÉCIFIQUES ──────────────────────────────────────────── */
/* Accueil */
[data-theme="dark"] body[data-page="home"] .pf-module-card {
background: rgba(22, 27, 34, 0.92) !important;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4) !important;
}
[data-theme="dark"] body[data-page="home"] .pf-module-card:hover {
border-color: var(--primary) !important;
}
/* Épargne & Grilles */
[data-theme="dark"] .eg-header-row {
background: #111827 !important;
border-color: #30363d !important;
color: #e6edf3 !important;
}
[data-theme="dark"] .eg-row:nth-child(even) {
background: rgba(255, 255, 255, 0.02);
}
[data-theme="dark"] .eg-row:hover {
background: rgba(255, 255, 255, 0.05);
}
/* Éléments colorés spécifiques */
[data-theme="dark"] .savings-table .row-extres td,
[data-theme="dark"] .eg-extres-row {
background: rgba(245, 158, 11, 0.08) !important;
}
[data-theme="dark"] .nens-title.theme-pol {
background: rgba(30, 58, 138, 0.2) !important;
color: #93c5fd !important;
border-color: #3b82f6 !important;
}
[data-theme="dark"] .nens-table.theme-pol thead th {
background: rgba(30, 58, 138, 0.15) !important;
color: #93c5fd !important;
}
[data-theme="dark"] .nens-title.theme-pep {
background: rgba(20, 83, 45, 0.2) !important;
color: #86efac !important;
border-color: #22c55e !important;
}
[data-theme="dark"] .nens-table.theme-pep thead th {
background: rgba(20, 83, 45, 0.15) !important;
color: #86efac !important;
}
[data-theme="dark"] .sum-selected {
background: rgba(59, 130, 246, 0.1) !important;
}
[data-theme="dark"] .fc-burn-alert {
background: rgba(239, 68, 68, 0.1) !important;
color: #f87171 !important;
}
[data-theme="dark"] .month-actions .btn-icon-small {
background: #1c2128 !important;
border-color: var(--border-light) !important;
color: var(--text-main) !important;
}
[data-theme="dark"] .month-actions .btn-icon-small:hover {
background: rgba(255, 255, 255, 0.06) !important;
}
+58
View File
@@ -0,0 +1,58 @@
services:
househub:
build: .
container_name: househub
restart: unless-stopped
depends_on:
househub-db:
condition: service_healthy
environment:
DB_HOST: househub-db
DB_NAME: ${DB_NAME:-househub}
DB_USER: ${DB_USER:-househub}
DB_PASS: ${DB_PASS:-changeme}
# Clé applicative pour chiffrer les secrets (iCloud, etc.). Optionnel si absent : fichier data/.hh_app_secret ou dérivation DB.
APP_SECRET_KEY: ${APP_SECRET_KEY:-}
volumes:
- househub_uploads:/uploads
- /opt/container/househub:/var/www/html
networks:
- househub_net
- proxy
labels:
- "traefik.enable=true"
- "traefik.http.routers.househub.rule=Host(`househub.nas.percolouco.com`)"
- "traefik.http.routers.househub.entrypoints=websecure"
- "traefik.http.routers.househub.tls=true"
- "traefik.http.routers.househub.tls.certresolver=letsencrypt"
- "traefik.http.services.househub.loadbalancer.server.port=80"
househub-db:
image: mariadb:11
container_name: househub-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS:-rootchangeme}
MYSQL_DATABASE: househub_meta
MYSQL_USER: ${DB_USER:-househub}
MYSQL_PASSWORD: ${DB_PASS:-changeme}
volumes:
- househub_db_data:/var/lib/mysql
- ./docker/init:/docker-entrypoint-initdb.d:ro
networks:
- househub_net
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 5
volumes:
househub_db_data:
househub_uploads:
networks:
househub_net:
proxy:
external: true
+10
View File
@@ -0,0 +1,10 @@
<VirtualHost *:80>
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
Options -Indexes
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
+49
View File
@@ -0,0 +1,49 @@
-- Initialisation HouseHub — Meta DB + permissions
-- Exécuté automatiquement au premier démarrage MariaDB
USE househub_meta;
CREATE TABLE IF NOT EXISTS families (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
db_name VARCHAR(64) NOT NULL UNIQUE,
invite_code VARCHAR(32) NOT NULL UNIQUE,
is_active TINYINT(1) DEFAULT 1,
enabled_modules JSON DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
display_name VARCHAR(100) NOT NULL,
family_id INT DEFAULT NULL,
is_admin TINYINT(1) DEFAULT 0,
is_active TINYINT(1) DEFAULT 1,
lang VARCHAR(5) DEFAULT 'fr',
remember_token VARCHAR(255) DEFAULT NULL, -- 👈 NOUVEAU CHAMP ICI
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (family_id) REFERENCES families(id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS user_calendar_integrations (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
provider VARCHAR(50) NOT NULL DEFAULT 'icloud_caldav',
username VARCHAR(255) NOT NULL,
secret_encrypted TEXT NOT NULL,
dav_principal_url VARCHAR(1024) DEFAULT NULL,
calendar_url VARCHAR(1024) DEFAULT NULL,
status VARCHAR(30) DEFAULT 'connected',
last_sync_at DATETIME DEFAULT NULL,
calendar_prefs_json TEXT DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_user_provider (user_id, provider),
CONSTRAINT fk_calendar_integration_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- Donner au user applicatif le droit de créer des DBs famille
GRANT ALL PRIVILEGES ON `househub_f%`.* TO 'househub'@'%';
FLUSH PRIVILEGES;
+5
View File
@@ -0,0 +1,5 @@
upload_max_filesize = 300M
post_max_size = 310M
memory_limit = 512M
max_execution_time = 120
max_input_time = 120
+676
View File
@@ -0,0 +1,676 @@
-- HouseHub — Schéma MySQL (Modèle pour une base famille)
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ─── Configuration du foyer ───────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_foyer_settings (
id INT AUTO_INCREMENT PRIMARY KEY,
currency VARCHAR(10) NOT NULL DEFAULT '€',
zone_scolaire VARCHAR(5) NOT NULL DEFAULT 'C',
csv_mapping TEXT DEFAULT NULL,
cares_modes TEXT DEFAULT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT IGNORE INTO pf_foyer_settings (id, currency, zone_scolaire) VALUES (1, '€', 'C');
-- ────────────────────────────────────────────────────────────
-- Paramètres dynamiques des Modules (Key-Value)
-- ────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS `pf_settings` (
`setting_key` varchar(50) NOT NULL,
`setting_value` text DEFAULT NULL,
`module` varchar(50) NOT NULL,
`updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
PRIMARY KEY (`setting_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT IGNORE INTO `pf_settings` (`setting_key`, `setting_value`, `module`) VALUES
('calendar_default_view', 'month', 'calendar'),
('calendar_first_day', '1', 'calendar'),
('calendar_working_hours', '08:00-19:00', 'calendar'),
('budget_start_day', '1', 'budget'),
('budget_default_tab', 'dépenses', 'budget'),
('travel_default_transport', 'car', 'voyage'),
('travel_default_fuel_price', '1.85', 'voyage'),
('gifts_hide_purchased', '0', 'cadeaux'),
('gifts_default_sort', 'person', 'cadeaux'),
('gifts_budget_alert', '500', 'cadeaux');
-- ─── Utilisateurs (Legacy) ────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(100) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
display_name VARCHAR(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Personnes ────────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS `pf_people` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`user_id` int(11) DEFAULT NULL,
`role` varchar(50) DEFAULT NULL,
`care_modes` varchar(255) DEFAULT NULL,
`color` varchar(7) DEFAULT '#0891b2',
`is_active` TINYINT(1) DEFAULT 1,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Calendrier familial ──────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_events (
id INT AUTO_INCREMENT PRIMARY KEY,
event_date DATE NOT NULL,
event_type VARCHAR(50) NOT NULL,
person_id INT NOT NULL,
duration DECIMAL(4,2) DEFAULT 1.0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_leaves (
id INT AUTO_INCREMENT PRIMARY KEY,
person_id INT NOT NULL,
leave_type VARCHAR(50) NOT NULL,
leave_date DATE NOT NULL,
duration DECIMAL(4,2) DEFAULT 1.0,
UNIQUE KEY uq_leave (person_id, leave_type, leave_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_leave_balances (
id INT AUTO_INCREMENT PRIMARY KEY,
person_id INT NOT NULL,
leave_type VARCHAR(50) NOT NULL,
initial_balance DECIMAL(6,2) DEFAULT 0,
balance_year INT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_leave_snapshots (
id INT AUTO_INCREMENT PRIMARY KEY,
person_id INT NOT NULL,
leave_type VARCHAR(50) NOT NULL,
snapshot_date DATE NOT NULL,
remaining_balance DECIMAL(6,2) DEFAULT 0.00,
carry_over_balance DECIMAL(6,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_person_leave_meta (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
person_id INT(11) NOT NULL,
leave_type VARCHAR(50) COLLATE utf8mb4_unicode_ci NOT NULL,
method VARCHAR(20) COLLATE utf8mb4_unicode_ci DEFAULT 'FIXED',
allowance DECIMAL(5,2) DEFAULT 0.00,
carry_over_max_days DECIMAL(5,2) DEFAULT 0.00,
carry_over_deadline_month INT(11) DEFAULT 12,
anniversary_date DATE DEFAULT NULL,
INDEX (person_id),
INDEX (leave_type),
UNIQUE KEY uq_person_leave (person_id, leave_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- ─── Types de Congés (Référentiel) ─────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_leave_types (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(20) COLLATE utf8mb4_general_ci NOT NULL,
label VARCHAR(100) COLLATE utf8mb4_general_ci NOT NULL,
default_allowance DECIMAL(5,2) DEFAULT 0.00,
reset_month INT(11) DEFAULT 1,
UNIQUE KEY code (code)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT IGNORE INTO pf_leave_types (code, label, default_allowance, reset_month) VALUES
('CP', 'Congés Payés', 25.00, 6);
CREATE TABLE IF NOT EXISTS pf_calendar_weeks (
id INT AUTO_INCREMENT PRIMARY KEY,
year INT NOT NULL,
week_iso_year INT NOT NULL,
week_iso_number INT NOT NULL,
week_label VARCHAR(20),
month INT,
month_name VARCHAR(20),
week_start_date DATE,
mon_date DATE, tue_date DATE, wed_date DATE,
thu_date DATE, fri_date DATE, sat_date DATE, sun_date DATE,
UNIQUE KEY uq_week (year, week_iso_year, week_iso_number)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Budget ───────────────────────────────────────────────────────────────────
-- NOUVEAU : Table des comptes bancaires
CREATE TABLE IF NOT EXISTS pf_bank_accounts (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
account_type ENUM('checking', 'savings') DEFAULT 'checking',
owner_person_id INT DEFAULT NULL,
is_default TINYINT(1) DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (owner_person_id) REFERENCES pf_people(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_budget_items (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
amount DECIMAL(10,2) DEFAULT 0,
category VARCHAR(100),
type VARCHAR(50),
payment_day INT DEFAULT NULL,
is_estimate TINYINT(1) DEFAULT 0,
is_dynamic TINYINT(1) DEFAULT 0,
dynamic_code VARCHAR(50) DEFAULT NULL,
reg_month VARCHAR(7) DEFAULT NULL,
mapping_keywords TEXT DEFAULT NULL,
holiday_id INT DEFAULT NULL,
is_checked TINYINT(1) DEFAULT 0,
sort_order INT DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_expenses (
id INT AUTO_INCREMENT PRIMARY KEY,
date_exp DATE NOT NULL,
gestion_month VARCHAR(10) NOT NULL,
category VARCHAR(100),
label VARCHAR(255),
amount DECIMAL(10,2) DEFAULT 0,
import_ref VARCHAR(255) DEFAULT NULL,
budget_item_id INT DEFAULT NULL,
holiday_id INT DEFAULT NULL,
salary_id INT DEFAULT NULL -- 🔥 AJOUT : Lien vers le salaire configuré
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `pf_expected_expenses` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`title` VARCHAR(150) NOT NULL,
`amount` DECIMAL(10,2) NOT NULL DEFAULT 0.00,
`expected_date` DATE NOT NULL,
`is_paid` TINYINT(1) NOT NULL DEFAULT 0,
`created_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
INDEX `idx_expected_date` (`expected_date`),
INDEX `idx_is_paid` (`is_paid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS pf_alloc_categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
target DECIMAL(10,2) DEFAULT 0.00,
transfer_dest VARCHAR(50) DEFAULT NULL,
holiday_id INT DEFAULT NULL,
sort_order INT DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_alloc_values (
id INT AUTO_INCREMENT PRIMARY KEY,
month_date VARCHAR(10) NOT NULL,
cat_id INT NOT NULL,
person_id INT NOT NULL,
amount DECIMAL(10,2) DEFAULT 0.00,
UNIQUE KEY uq_alloc_person (month_date, cat_id, person_id),
FOREIGN KEY (person_id) REFERENCES pf_people(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_savings (
id INT AUTO_INCREMENT PRIMARY KEY,
owner VARCHAR(50) NOT NULL,
month_date VARCHAR(10) NOT NULL,
category VARCHAR(100) NOT NULL,
amount DECIMAL(10,2) DEFAULT 0,
holiday_id INT DEFAULT NULL,
UNIQUE KEY uq_savings (owner, month_date, category)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_bank_snapshots (
id INT AUTO_INCREMENT PRIMARY KEY,
snapshot_date DATE NOT NULL,
amount DECIMAL(12,2) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_salary_config (
id INT AUTO_INCREMENT PRIMARY KEY,
year INT NOT NULL,
person VARCHAR(50) NOT NULL,
salary DECIMAL(10,2) DEFAULT 0,
mensualite DECIMAL(10,2) DEFAULT 0,
frais_func DECIMAL(10,2) DEFAULT 0,
eco_perso DECIMAL(10,2) DEFAULT 0,
eco_family DECIMAL(10,2) DEFAULT 0,
UNIQUE KEY uq_salary (year, person)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_import_rules (
id INT AUTO_INCREMENT PRIMARY KEY,
keyword VARCHAR(255) NOT NULL UNIQUE,
category VARCHAR(100) NOT NULL,
budget_item_id INT(11) NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `pf_advances` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`advance_date` date NOT NULL,
`payer` varchar(50) NOT NULL,
`description` varchar(255) NOT NULL,
`amount` decimal(10,2) DEFAULT 0.00,
`from_savings` tinyint(1) DEFAULT 0,
`is_resolved` tinyint(1) DEFAULT 0,
`created_at` datetime DEFAULT current_timestamp(),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
-- ─── Budget Catégories (Dynamiques) ─────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_budget_categories (
id INT AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(50) NOT NULL UNIQUE,
label VARCHAR(100) NOT NULL,
type VARCHAR(50) NOT NULL,
color VARCHAR(20) DEFAULT '#ccc',
icon VARCHAR(20) DEFAULT '?'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- Insertion des catégories de base pour toute nouvelle famille
INSERT IGNORE INTO pf_budget_categories (code, label, type, color, icon) VALUES
('INCOME', 'Revenus', 'Income', '#10b981', '💵'),
('FIXED', 'Charges Fixes', 'Expense', '#ef4444', '🏢');
-- ─── Notes / Memo ─────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_notes (
id INT AUTO_INCREMENT PRIMARY KEY,
note_type VARCHAR(100) NOT NULL,
reference_id VARCHAR(100) NOT NULL,
content TEXT,
UNIQUE KEY uq_note (note_type, reference_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_memo_notes (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content LONGTEXT DEFAULT '',
tags VARCHAR(1000) DEFAULT '',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FULLTEXT KEY ft_notes (title, content, tags)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_memo_attachments (
id INT AUTO_INCREMENT PRIMARY KEY,
note_id INT NOT NULL,
type ENUM('image','file','url') NOT NULL DEFAULT 'file',
filename VARCHAR(255) DEFAULT NULL,
original_name VARCHAR(255) DEFAULT NULL,
url TEXT DEFAULT NULL,
label VARCHAR(255) DEFAULT NULL,
size INT DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (note_id) REFERENCES pf_memo_notes(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Voyages / Holidays ───────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_holidays (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
period_hint VARCHAR(100) DEFAULT NULL,
start_date DATE DEFAULT NULL,
end_date DATE DEFAULT NULL,
status VARCHAR(50) DEFAULT 'draft',
budget_food DECIMAL(10,2) DEFAULT 0,
budget_extra DECIMAL(10,2) DEFAULT 0,
notes TEXT DEFAULT NULL,
vehicle_id INT DEFAULT NULL,
return_step_id INT DEFAULT NULL,
image_url VARCHAR(500) DEFAULT NULL,
FOREIGN KEY (vehicle_id) REFERENCES pf_vehicles(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_holidays_items (
id INT AUTO_INCREMENT PRIMARY KEY,
holiday_id INT NOT NULL,
category VARCHAR(100),
name VARCHAR(255),
amount DECIMAL(10,2) DEFAULT 0,
is_paid TINYINT(1) DEFAULT 0,
location_name VARCHAR(255) DEFAULT NULL,
lat DECIMAL(10,7) DEFAULT NULL,
lng DECIMAL(10,7) DEFAULT NULL,
sort_order INT DEFAULT 0,
notes TEXT DEFAULT NULL,
item_date DATE DEFAULT NULL,
item_time TIME DEFAULT NULL,
step_type VARCHAR(20) DEFAULT 'stop',
step_start_date DATE DEFAULT NULL,
step_end_date DATE DEFAULT NULL,
duration INT DEFAULT NULL,
expense_context VARCHAR(20) DEFAULT NULL,
FOREIGN KEY (holiday_id) REFERENCES pf_holidays(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_holidays_items (
id INT AUTO_INCREMENT PRIMARY KEY,
holiday_id INT NOT NULL,
category VARCHAR(100),
name VARCHAR(255),
amount DECIMAL(10,2) DEFAULT 0,
is_paid TINYINT(1) DEFAULT 0,
location_name VARCHAR(255) DEFAULT NULL,
lat DECIMAL(10,7) DEFAULT NULL,
lng DECIMAL(10,7) DEFAULT NULL,
sort_order INT DEFAULT 0,
notes TEXT DEFAULT NULL,
item_date DATE DEFAULT NULL,
item_time TIME DEFAULT NULL,
step_start_date DATE DEFAULT NULL,
step_end_date DATE DEFAULT NULL,
duration INT DEFAULT NULL,
is_return TINYINT(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_holidays_ideas (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
period_hint VARCHAR(100) DEFAULT NULL,
start_date DATE DEFAULT NULL,
end_date DATE DEFAULT NULL,
status VARCHAR(50) DEFAULT 'idea',
budget_food DECIMAL(10,2) DEFAULT 0,
budget_extra DECIMAL(10,2) DEFAULT 0,
notes TEXT DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `pf_holidays_attachments` (
`id` INT NOT NULL AUTO_INCREMENT,
`holiday_id` INT NOT NULL,
`item_id` INT DEFAULT NULL,
`file_name` VARCHAR(255) NOT NULL,
`file_path` VARCHAR(255) NOT NULL,
`uploaded_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
CONSTRAINT `fk_holiday_attachment` FOREIGN KEY (`holiday_id`) REFERENCES `pf_holidays`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS pf_geocode_cache (
q_hash CHAR(64) PRIMARY KEY,
q VARCHAR(255),
lat DECIMAL(10,7),
lng DECIMAL(10,7),
display_name TEXT,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Cadeaux ──────────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_gifts (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
year INT(11) NOT NULL,
adult_name VARCHAR(100) NOT NULL,
payer_name VARCHAR(100) DEFAULT NULL,
child_name VARCHAR(100) NOT NULL,
occasion VARCHAR(50) NOT NULL,
gift_description TEXT NOT NULL,
product_link VARCHAR(500) DEFAULT NULL,
amount DECIMAL(8,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS pf_gift_occasions (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
code VARCHAR(50) NOT NULL UNIQUE,
name VARCHAR(100) NOT NULL,
icon VARCHAR(20) DEFAULT '🎁',
month_date VARCHAR(5) DEFAULT NULL,
is_active TINYINT(1) DEFAULT 1,
sort_order INT DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT IGNORE INTO pf_gift_occasions (code, name, icon, month_date, is_active, sort_order) VALUES
('XMAS', 'Noël', '🎄', '12-25', 1, 1),
('BIRTHDAY', 'Anniversaire', '🎂', NULL, 1, 2),
('OTHER', 'Autre', '🎁', NULL, 1, 99);
-- Table des règles (Qui offre à Qui)
CREATE TABLE IF NOT EXISTS pf_gift_rules (
id INT(11) AUTO_INCREMENT PRIMARY KEY,
adult_person_id INT(11) NOT NULL,
child_person_id INT(11) NOT NULL,
occasion_id INT(11) NOT NULL,
INDEX (adult_person_id),
INDEX (child_person_id),
INDEX (occasion_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ─── Garage Manager ───────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_vehicles (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
brand VARCHAR(100) NOT NULL,
model VARCHAR(100) NOT NULL,
year INT DEFAULT NULL,
license_plate VARCHAR(50) DEFAULT NULL,
vin VARCHAR(100) DEFAULT NULL,
fuel_type VARCHAR(50) DEFAULT 'Essence',
consumption decimal(4,2) DEFAULT NULL COMMENT 'Consommation L/100km',
color VARCHAR(50) DEFAULT NULL,
purchase_date DATE DEFAULT NULL,
purchase_price DECIMAL(10,2) DEFAULT NULL,
current_km INT DEFAULT 0,
photo VARCHAR(255) DEFAULT NULL,
notes TEXT DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_maintenances (
id INT AUTO_INCREMENT PRIMARY KEY,
vehicle_id INT NOT NULL,
type VARCHAR(100) NOT NULL,
description TEXT DEFAULT NULL,
date DATE NOT NULL,
km INT DEFAULT NULL,
cost DECIMAL(10,2) DEFAULT 0,
mechanic VARCHAR(100) DEFAULT NULL,
garage_name VARCHAR(100) DEFAULT NULL,
next_km INT DEFAULT NULL,
next_date DATE DEFAULT NULL,
invoice_photo VARCHAR(255) DEFAULT NULL,
notes TEXT DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (vehicle_id) REFERENCES pf_vehicles(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_parts (
id INT AUTO_INCREMENT PRIMARY KEY,
vehicle_id INT DEFAULT NULL,
maintenance_id INT DEFAULT NULL,
brand VARCHAR(100) DEFAULT NULL,
reference VARCHAR(100) DEFAULT NULL,
name VARCHAR(255) NOT NULL,
category VARCHAR(100) DEFAULT 'Autre',
price DECIMAL(10,2) DEFAULT 0,
quantity INT DEFAULT 1,
unit VARCHAR(50) DEFAULT 'pièce',
supplier VARCHAR(100) DEFAULT NULL,
purchase_date DATE DEFAULT NULL,
photo VARCHAR(255) DEFAULT NULL,
notes TEXT DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (vehicle_id) REFERENCES pf_vehicles(id) ON DELETE SET NULL,
FOREIGN KEY (maintenance_id) REFERENCES pf_maintenances(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_garage_documents (
id INT AUTO_INCREMENT PRIMARY KEY,
vehicle_id INT NOT NULL,
maintenance_id INT DEFAULT NULL,
label VARCHAR(255) DEFAULT NULL,
filename VARCHAR(255) NOT NULL,
original_name VARCHAR(255) DEFAULT NULL,
mime VARCHAR(120) DEFAULT NULL,
size INT DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
KEY idx_gd_vehicle (vehicle_id),
KEY idx_gd_maint (maintenance_id),
FOREIGN KEY (vehicle_id) REFERENCES pf_vehicles(id) ON DELETE CASCADE,
FOREIGN KEY (maintenance_id) REFERENCES pf_maintenances(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Todo ─────────────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_todo_lists (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
color VARCHAR(20) DEFAULT '#3b82f6',
icon VARCHAR(10) DEFAULT '📋',
position INT DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_todos (
id INT AUTO_INCREMENT PRIMARY KEY,
list_id INT DEFAULT NULL,
title VARCHAR(500) NOT NULL,
notes TEXT DEFAULT NULL,
due_date DATE DEFAULT NULL,
due_time TIME DEFAULT NULL,
notified TINYINT(1) DEFAULT 0,
notified_date DATE DEFAULT NULL,
priority ENUM('none','low','medium','high') DEFAULT 'none',
done TINYINT(1) DEFAULT 0,
done_at DATETIME DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (list_id) REFERENCES pf_todo_lists(id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Module Liste (Courses partagées) ─────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_lists (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL DEFAULT 'Ma liste',
color VARCHAR(20) DEFAULT NULL,
list_type VARCHAR(50) DEFAULT NULL,
position INT NOT NULL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT IGNORE INTO pf_lists (id, name, position) VALUES (1, 'Ma liste', 0);
CREATE TABLE IF NOT EXISTS pf_grocery_items (
id INT AUTO_INCREMENT PRIMARY KEY,
list_id INT NOT NULL DEFAULT 1,
category_id INT DEFAULT NULL,
label VARCHAR(500) NOT NULL,
in_cart TINYINT(1) NOT NULL DEFAULT 0,
position INT NOT NULL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_items_list (list_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_grocery_history (
id INT AUTO_INCREMENT PRIMARY KEY,
label_hash CHAR(64) NOT NULL,
label_display VARCHAR(500) NOT NULL,
last_used_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_grocery_hist_hash (label_hash),
KEY idx_hist_last (last_used_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_list_categories (
id INT AUTO_INCREMENT PRIMARY KEY,
icon VARCHAR(10) NOT NULL DEFAULT '🏷️',
name VARCHAR(100) NOT NULL,
position INT NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_item_category_rules (
id INT AUTO_INCREMENT PRIMARY KEY,
keyword VARCHAR(255) NOT NULL,
category_id INT NOT NULL,
UNIQUE KEY uq_keyword (keyword)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── Calendar iOS ─────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_calendar_events (
id INT AUTO_INCREMENT PRIMARY KEY,
family_id INT NOT NULL,
created_by_user_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT DEFAULT NULL,
location VARCHAR(255) DEFAULT NULL,
start_at DATETIME NOT NULL,
end_at DATETIME NOT NULL,
is_all_day TINYINT(1) DEFAULT 0,
timezone VARCHAR(64) DEFAULT 'Europe/Paris',
rrule VARCHAR(500) DEFAULT NULL,
status VARCHAR(50) DEFAULT 'confirmed',
external_uid VARCHAR(255) DEFAULT NULL,
sync_state VARCHAR(30) DEFAULT 'pending_push',
deleted_at DATETIME DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_external_uid (external_uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_calendar_event_links (
id INT AUTO_INCREMENT PRIMARY KEY,
calendar_event_id INT NOT NULL,
external_uid VARCHAR(255) NOT NULL,
external_etag VARCHAR(255) DEFAULT NULL,
calendar_url VARCHAR(1024) DEFAULT NULL,
external_href VARCHAR(2048) DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_calendar_event (calendar_event_id),
UNIQUE KEY uq_external_link (external_uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- ─── PrintVault ───────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_pv_models (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT DEFAULT '',
category VARCHAR(100) DEFAULT 'Non classé',
tags VARCHAR(500) DEFAULT '',
file_type VARCHAR(20) NOT NULL,
filename VARCHAR(255) NOT NULL,
original_name VARCHAR(255) NOT NULL,
file_size INT DEFAULT 0,
dim_x DECIMAL(10,3) DEFAULT 0,
dim_y DECIMAL(10,3) DEFAULT 0,
dim_z DECIMAL(10,3) DEFAULT 0,
volume DECIMAL(10,3) DEFAULT 0,
gcode_time VARCHAR(50) DEFAULT '',
gcode_filament VARCHAR(50) DEFAULT '',
gcode_nozzle VARCHAR(20) DEFAULT '',
gcode_bed VARCHAR(20) DEFAULT '',
thumb VARCHAR(255) DEFAULT '',
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS pf_pv_categories (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL UNIQUE,
color VARCHAR(20) DEFAULT '#8b5cf6'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT IGNORE INTO pf_pv_categories (name, color) VALUES
('Non classé','#64748b'),('Déco','#ec4899'),('Fonctionnel','#3b82f6'),
('Mécanique','#f59e0b'),('Jouets','#10b981'),('Outils','#ef4444'),
('Architecture','#8b5cf6'),('Art','#06b6d4');
-- ─── Planka ───────────────────────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_planka_config (
id INT NOT NULL DEFAULT 1,
project_id VARCHAR(32),
admin_token TEXT,
token_expires_at DATETIME,
active_board_id VARCHAR(32),
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
SET FOREIGN_KEY_CHECKS = 1;
-- ─── Planificateur de Repas ───────────────────────────────────────────────────
CREATE TABLE IF NOT EXISTS pf_meals_plan (
id INT AUTO_INCREMENT PRIMARY KEY,
plan_date DATE NOT NULL,
service ENUM('lunch', 'dinner') NOT NULL,
person_id INT NOT NULL,
meal_name VARCHAR(500) DEFAULT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_meal_plan (plan_date, service, person_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+534 -121
View File
@@ -1,135 +1,548 @@
<?php
// Active l'affichage des erreurs pour le développement
// modules/family-calendar/family-calendar.php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// On se connecte à la base de données
require __DIR__ . '/includes/auth.php';
require_login();
require __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/i18n.php';
// --- On récupère TOUS les événements sauvegardés en base ---
$stmt_events = $pdo->query("SELECT * FROM pf_events");
$dbEvents = $stmt_events->fetchAll();
// 1. Récupération de toutes les personnes
$stmtPeople = $pdo->query("SELECT id, name, user_id, role, color, care_modes FROM pf_people WHERE is_active = 1 ORDER BY id ASC");
$familyPeople = $stmtPeople->fetchAll(PDO::FETCH_ASSOC);
// --- Configuration de la page ---
$pageTitle = "PachaFamily - Family Calendar";
$parents = [];
$kids = [];
$helpers = [];
foreach ($familyPeople as $p) {
$role = strtolower($p['role'] ?? '');
if ($role === 'parent') {
$parents[] = $p;
} elseif ($role === 'enfant' || $role === 'child') {
$p['modes'] = json_decode($p['care_modes'] ?? '[]', true) ?: [];
$kids[] = $p;
} elseif ($role === 'helper' || $role === 'nounou') {
$helpers[] = $p; // 🟢 On stocke les intervenants
}
}
// 2. Modes de garde (globaux du foyer, pour synchroniser avec le JS)
$stmtFoyer = $pdo->query("SELECT care_modes, zone_scolaire FROM pf_foyer_settings LIMIT 1");
$foyerData = $stmtFoyer->fetch(PDO::FETCH_ASSOC);
$activeCareModes = json_decode($foyerData['care_modes'] ?? '[]', true);
if (!is_array($activeCareModes)) $activeCareModes = [];
// 3. Matrice de congés dynamique (pour les en-têtes et la modale)
$stmtLeaves = $pdo->query("SELECT person_id, leave_type FROM pf_person_leave_meta ORDER BY id ASC");
$dbLeaves = $stmtLeaves->fetchAll(PDO::FETCH_ASSOC);
$leaveMatrix = [];
$allLeaveTypes = [];
foreach ($dbLeaves as $l) {
$leaveMatrix[$l['person_id']][] = $l['leave_type'];
$allLeaveTypes[$l['leave_type']] = true;
}
$allLeaveTypes = array_keys($allLeaveTypes);
// ==========================================
// VÉRIFICATIONS D'INTÉGRITÉ (ALERTES)
// ==========================================
$calendarAlerts = [];
// 1. Aucun membre adulte/parent configuré
if (empty($parents)) {
$calendarAlerts[] = "<strong>Aucun adulte configuré.</strong> Rendez-vous dans les Paramètres Généraux de HouseHub pour ajouter les membres du foyer.";
}
// 2. Enfants présents, mais aucun mode de garde global défini
if (!empty($kids) && empty($activeCareModes)) {
$calendarAlerts[] = "<strong>Modes de garde manquants.</strong> Vous avez des enfants, mais aucun mode de garde n'est défini. Cliquez sur l'icône ⚙️ (Paramètres du calendrier) pour les ajouter.";
}
// 3. Référentiel des types de congés vide
try {
$countLeaveTypes = $pdo->query("SELECT COUNT(*) FROM pf_leave_types")->fetchColumn();
if ($countLeaveTypes == 0) {
$calendarAlerts[] = "<strong>Types de congés manquants.</strong> Le catalogue des congés (CP, RTT...) est vide. Ajoutez-les dans les paramètres généraux.";
}
} catch (Exception $e) {
// Si la table n'existe pas encore
$calendarAlerts[] = "<strong>Table des congés manquante.</strong> Veuillez mettre à jour la base de données.";
}
// 4. Zone scolaire manquante (si tu l'as stockée dans pf_foyer_settings)
$zoneScolaire = $foyerData['zone_scolaire'] ?? null;
if (empty($zoneScolaire)) {
$calendarAlerts[] = "<strong>Zone scolaire non définie.</strong> Cliquez sur l'icône ⚙️ pour configurer votre zone afin d'afficher les vacances scolaires.";
}
$pageTitle = tr('fc_page_title');
$activePage = "family-calendar";
$mainClass = "pf-family-calendar";
$pageCss = "/modules/family-calendar/family-calendar.css";
require __DIR__ . '/header.php';
?>
<!-- ===================================================================== -->
<!-- INJECTION DES DONNÉES DU SERVEUR VERS JAVASCRIPT -->
<!-- Cette variable `serverData` sera lue par le script JS au démarrage. -->
<!-- ===================================================================== -->
<div class="pf-container" style="--p1-main: <?= $parents[0]['color'] ?? '#0891b2' ?>; --p2-main: <?= $parents[1]['color'] ?? '#f59e0b' ?>; max-width:100%; padding:0;">
<div class="fc-header-row" style="display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; margin-bottom: 24px;">
<!-- Bloc Titre + Roue crantée -->
<div style="display: flex; align-items: center; gap: 12px;">
<h1 style="margin: 0;"><?= tr('fc_main_header') ?></h1>
<button id="btnOpenCalendarSettings" class="btn-settings-gear" title="Paramètres du calendrier" style="font-size: 1.4rem; padding: 4px;">
⚙️
</button>
</div>
<!-- Boutons d'actions -->
<div style="display: flex; gap: 10px; flex-wrap: wrap;">
<button id="btnOpenSnapshotModal" class="pf-btn-icon-text">
<span class="icon">⚖️</span>
<span class="text"><?= tr('fc_btn_correct_balances') ?></span>
</button>
<button id="btnOpenHolidays" class="pf-btn-icon-text">
<span class="icon">🏖️</span>
<span class="text"><?= tr('fc_btn_school_holidays') ?></span>
</button>
</div>
</div>
<?php if (!empty($calendarAlerts)): ?>
<div class="pf-alert pf-alert-warning" style="background: var(--bg-warning, #fffbeb); border: 1px solid var(--border-warning, #fcd34d); color: var(--text-warning, #92400e); padding: 16px; border-radius: 8px; margin-bottom: 24px; display: flex; gap: 12px; align-items: flex-start;">
<div style="font-size: 1.5rem; line-height: 1;">⚠️</div>
<div>
<h4 style="margin: 0 0 8px 0; font-size: 1.05rem;">Configuration incomplète</h4>
<ul style="margin: 0; padding-left: 18px; font-size: 0.95rem; line-height: 1.5;">
<?php foreach ($calendarAlerts as $alert): ?>
<li style="margin-bottom: 4px;"><?= $alert ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<?php endif; ?>
<div id="modalHolidays" class="pf-modal">
<div class="pf-modal-content">
<div class="pf-modal-header">
<h3 class="pf-modal-title">
<?= tr('fc_modal_holidays_title') ?>
<?php if (defined('ZONE_SCOLAIRE') && ZONE_SCOLAIRE !== 'Autre') echo '(Zone ' . htmlspecialchars(ZONE_SCOLAIRE) . ')'; ?>
</h3>
<button id="btnCloseHolidays" class="pf-modal-close" onclick="document.getElementById('modalHolidays').classList.remove('active')">&times;</button>
</div>
<div class="pf-modal-body" style="padding:0;">
<div style="width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;">
<table id="schoolHolidaysTable" class="fc-holidays-table" style="min-width: 400px;">
<thead>
<tr>
<th><?= tr('fc_col_period') ?></th>
<th><?= tr('fc_col_from') ?></th>
<th><?= tr('fc_col_to') ?></th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
</div>
<div id="modalSnapshot" class="pf-modal">
<div class="pf-modal-content">
<div class="pf-modal-header">
<h3 class="pf-modal-title">📸 <?= tr('fc_modal_snap_title') ?></h3>
<button type="button" id="btnCloseSnapshot" class="pf-modal-close" onclick="document.getElementById('modalSnapshot').classList.remove('open'); document.body.classList.remove('no-scroll');">&times;</button>
</div>
<div class="pf-modal-body">
<form id="formSnapshot">
<div class="pf-form-row">
<div class="pf-form-group">
<label class="pf-label"><?= tr('fc_label_person') ?></label>
<select id="snapPerson" class="pf-input" required>
<option value="" disabled selected>-- <?= tr('fc_choose_person') ?> --</option>
<?php foreach ($parents as $person): ?>
<option value="<?= htmlspecialchars($person['id']) ?>">
<?= htmlspecialchars($person['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="pf-form-group">
<label class="pf-label"><?= tr('fc_label_leave_type') ?></label>
<select id="snapType" class="pf-input" required>
<?php foreach ($allLeaveTypes as $type): ?>
<option value="<?= htmlspecialchars($type) ?>"><?= htmlspecialchars($type) ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="pf-form-group">
<label class="pf-label"><?= tr('fc_label_apply_date') ?></label>
<input type="date" id="snapDate" class="pf-input" required title="<?= tr('fc_snap_date_hint') ?>">
</div>
<div class="pf-form-group">
<label class="pf-label"><?= tr('fc_label_remaining_balance') ?></label>
<div style="display:flex; align-items:center;">
<!-- 🔥 STEP 0.01 POUR DEUX DÉCIMALES STRICTES -->
<input type="number" step="0.01" id="snapBalance" class="pf-input" placeholder="<?= tr('fc_placeholder_balance') ?>" style="border-radius: 8px 0 0 8px; border-right: none; font-weight: bold; color: var(--pf-primary);" required>
<span style="background: var(--pf-bg-lighter); border: 1px solid var(--pf-border); padding: 0 12px; height: 42px; display: flex; align-items: center; border-radius: 0 8px 8px 0; color: var(--pf-text-muted); font-size: 0.9rem; font-weight: 600;">
<?= tr('fc_unit_days') ?>
</span>
</div>
</div>
<!-- NOUVEAU BLOC : Solde reporté -->
<div class="pf-form-group" style="margin-top: 15px;">
<label class="pf-label"><?= tr('fc_label_carry_over') ?></label>
<div style="display:flex; align-items:center;">
<!-- 🔥 STEP 0.01 POUR DEUX DÉCIMALES STRICTES -->
<input type="number" step="0.01" id="snapCarryOver" class="pf-input" placeholder="ex: 2.00" value="0" style="border-radius: 8px 0 0 8px; border-right: none; font-weight: bold; color: var(--danger);" required>
<span style="background: var(--pf-bg-lighter); border: 1px solid var(--pf-border); padding: 0 12px; height: 42px; display: flex; align-items: center; border-radius: 0 8px 8px 0; color: var(--pf-text-muted); font-size: 0.9rem; font-weight: 600;">
<?= tr('fc_unit_days') ?>
</span>
</div>
<small class="pf-muted-note"><?= tr('fc_carry_over_note') ?></small>
</div>
<!-- FOOTER INTÉGRÉ DANS LE FORMULAIRE POUR ÉVITER LE BUG DE CIBLAGE -->
<div class="pf-modal-footer" style="margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--pf-border); display: flex; justify-content: flex-end; gap: 10px;">
<button type="button" class="pf-btn pf-btn-secondary" onclick="document.getElementById('modalSnapshot').style.display = 'none'; document.body.classList.remove('no-scroll');"><?= tr('btn_cancel') ?></button>
<button type="submit" id="btnSubmitSnapshot" class="pf-btn pf-btn-primary"><?= tr('fc_btn_save_snap') ?></button>
</div>
</form>
</div>
</div>
</div>
<div id="modalCalendarSettings" class="pf-modal">
<div class="pf-modal-content" style="max-width: 650px; width: 95%;">
<div class="pf-modal-header">
<h3 class="pf-modal-title">⚙️ <?= tr('fc_modal_settings_title') ?></h3>
<button type="button" class="pf-modal-close" onclick="closeCalendarSettings()">&times;</button>
</div>
<div style="display: flex; gap: 4px; background: var(--bg-page); padding: 4px; border-radius: 8px; margin: 1rem;">
<button type="button" id="tab-btn-foyer" class="bs-tab-btn active" style="flex: 1; padding: 8px 12px; font-weight: 600;" onclick="switchCalendarTab('foyer')">
🏡 <?= tr('fc_tab_foyer') ?>
</button>
<button type="button" id="tab-btn-membres" class="bs-tab-btn" style="flex: 1; padding: 8px 12px; font-weight: 600;" onclick="switchCalendarTab('membres')">
👥 <?= tr('fc_tab_members') ?>
</button>
</div>
<div class="pf-modal-body" style="max-height: 65vh; overflow-y: auto; padding-top: 0; padding-bottom: 1rem;">
<div id="cal-pane-foyer" class="cal-settings-pane">
<form id="formCalFoyer" onsubmit="submitCalFoyer(event)">
<div class="pf-form-group">
<label class="pf-label"><?= tr('fc_zone_label') ?></label>
<select id="setZoneScolaire" name="zone_scolaire" class="pf-input" required style="width: 100%;">
<option value="A"><?= tr('fc_zone_a') ?></option>
<option value="B"><?= tr('fc_zone_b') ?></option>
<option value="C"><?= tr('fc_zone_c') ?></option>
<option value="Autre"><?= tr('fc_zone_other') ?></option>
</select>
<small class="pf-muted-note"><?= tr('fc_zone_desc') ?></small>
</div>
<div class="pf-form-group" style="margin-top: 1.5rem;">
<label class="pf-label"><?= tr('fc_care_modes_label') ?></label>
<?php if (!empty($kids)): ?>
<div id="careModesContainer" style="display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; min-height: 38px; padding: 8px; background: var(--bg-page); border-radius: var(--radius); border: 1px solid var(--border-light);"></div>
<div style="display: flex; gap: 8px;">
<input type="text" id="inputNewCareMode" class="pf-input" placeholder="<?= tr('fc_add_mode_placeholder') ?>" style="flex: 1;">
<button type="button" class="pf-btn btn-secondary" style="padding: 0 16px; border-radius: 6px;" onclick="addCareModeTag()">+</button>
</div>
<small class="pf-muted-note"><?= tr('fc_care_modes_desc') ?></small>
<?php else: ?>
<div style="background: var(--bg-subtle); padding: 12px; border-radius: 8px; border: 1px dashed var(--border-main); text-align: center;">
<p style="margin: 0 0 10px 0; color: var(--text-muted); font-size: 0.9rem;">
<?= tr('fc_empty_kids_msg') ?>
</p>
<a href="/settings.php" class="pf-btn btn-secondary" style="text-decoration: none; display: inline-block; font-size: 0.85rem;">
⚙️ <?= tr('fc_link_settings') ?>
</a>
</div>
<?php endif; ?>
</div>
<?php if (!empty($kids)): ?>
<div style="margin-top: 1rem; display: flex; justify-content: flex-end;">
<button type="submit" class="pf-btn pf-btn-primary"><?= tr('save') ?></button>
</div>
<?php endif; ?>
</form>
<div class="pf-form-group" style="margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border-light);">
<h4 style="margin: 0 0 10px 0; color: var(--text-main);">🏖️ <?= tr('fc_leave_catalog_title') ?></h4>
<p style="font-size: 0.85rem; color: var(--text-muted); margin-bottom: 15px;">
<?= tr('fc_leave_catalog_desc') ?>
</p>
<div id="leaveTypesContainer" style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 15px;"></div>
<div style="background: var(--bg-subtle); padding: 12px; border-radius: 8px; border: 1px solid var(--border-light);">
<h5 id="leaveTypeFormTitle" style="margin: 0 0 10px 0;">+ <?= tr('fc_add_leave_type') ?></h5>
<form id="formLeaveType" style="display: flex; flex-direction: column; gap: 10px;">
<input type="hidden" id="lt-mode" value="add">
<div style="display: flex; gap: 10px; flex-wrap: wrap;">
<div style="flex: 0 0 80px;">
<label class="pf-label"><?= tr('fc_col_code') ?> *</label>
<input type="text" id="lt-code" class="pf-input" maxlength="4" style="text-transform: uppercase;" required>
<small class="pf-muted-note" id="lt-code-note"><?= tr('fc_code_irreversible') ?></small>
</div>
<div style="flex: 1; min-width: 150px;">
<label class="pf-label"><?= tr('fc_col_label') ?> *</label>
<input type="text" id="lt-label" class="pf-input" placeholder="<?= tr('fc_leave_label_ph') ?>" required>
</div>
</div>
<div style="display: flex; gap: 10px; flex-wrap: wrap; margin-top: 5px;">
<div style="flex: 1; min-width: 140px;">
<label class="pf-label"><?= tr('fc_carry_max') ?></label>
<input type="number" step="0.5" id="lt-carry-max" class="pf-input" placeholder="ex: 2" value="0" required>
</div>
<div style="flex: 1; min-width: 140px;">
<label class="pf-label"><?= tr('fc_carry_deadline') ?></label>
<select id="lt-carry-deadline" class="pf-input">
<option value="1"><?= tr('month_01') ?></option>
<option value="2"><?= tr('month_02') ?></option>
<option value="3"><?= tr('month_03') ?></option>
<option value="4"><?= tr('month_04') ?></option>
<option value="5"><?= tr('month_05') ?></option>
<option value="6"><?= tr('month_06') ?></option>
<option value="12"><?= tr('fc_deadline_none') ?></option>
</select>
</div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 8px; margin-top: 5px;">
<button type="button" class="pf-btn btn-secondary" onclick="resetLeaveTypeForm()"><?= tr('btn_cancel') ?></button>
<button type="button" class="pf-btn pf-btn-primary" onclick="saveLeaveType()"><?= tr('btn_save') ?></button>
</div>
</form>
</div>
</div>
</div>
<div id="cal-pane-membres" class="cal-settings-pane" style="display: none;">
<div style="margin-bottom: 1.2rem;">
<label class="pf-label"><?= tr('fc_select_member') ?></label>
<select id="selectCalMember" class="pf-input" style="width: 100%; font-weight: 600;" onchange="loadMemberConfigView()">
</select>
</div>
<div id="memberConfigZone" style="background: var(--bg-page); padding: 14px; border-radius: 8px; border: 1px solid var(--border-light); min-height: 150px;">
</div>
</div>
</div>
</div>
</div>
<div class="fc-month-calendar-wrapper">
<div class="fc-month-header">
<div class="fc-month-nav-row">
<button id="fc-prev-month" class="fc-nav-button">‹</button>
<div id="fc-smart-date-selector" style="display:flex; align-items:center; justify-content:center; flex-grow:1; gap:6px;">
<select id="fc-select-month" class="fc-smart-select"></select>
<select id="fc-select-year" class="fc-smart-select"></select>
<span id="fc-multi-month-suffix" style="display:none; font-size:1.3rem; font-weight:800; color:#0f172a; margin-left:4px;"></span>
</div>
<button id="fc-next-month" class="fc-nav-button">›</button>
</div>
<div class="fc-view-controls">
<button id="fc-today-btn" class="fc-today-button" title="<?= tr('fc_today_title') ?>"><?= tr('fc_today_short') ?></button>
<div class="fc-view-divider"></div>
<button class="fc-view-button fc-view-button--active" data-view="1month"><?= tr('fc_view_1m') ?></button>
<button class="fc-view-button" data-view="2months"><?= tr('fc_view_2m') ?></button>
<button class="fc-view-button" data-view="3months"><?= tr('fc_view_3m') ?></button>
</div>
</div>
<div class="fc-calendar-container">
<div id="fc-month-calendar" class="fc-month-calendar"></div>
<div id="fc-month-selectionMenu" class="fc-selection-menu" style="display:none;"></div>
</div>
<div id="fc-month-balances" class="fc-month-balances"></div>
</div>
<section class="pf-section" style="margin-top: 1.5rem;">
<div class="fc-week-header">
<h2><?= tr('fc_weekly_planning') ?></h2>
<div class="fc-week-nav-controls">
<button id="fc-prev-school-year" class="fc-nav-button">‹</button>
<span id="fc-current-school-year-label"></span>
<button id="fc-next-school-year" class="fc-nav-button">›</button>
</div>
</div>
<div id="planningTable-wrapper">
<table id="planningTable">
<thead>
<tr>
<th rowspan="3" class="col-month col-sticky-mois rotated-text"><span><?= tr('fc_col_month') ?></span></th>
<th rowspan="3" class="col-month col-sticky-sem rotated-text"><span><?= tr('fc_col_week') ?></span></th>
<th rowspan="3" class="col-day"><?= tr('day_mon') ?></th>
<th rowspan="3" class="col-day"><?= tr('day_tue') ?></th>
<th rowspan="3" class="col-day"><?= tr('day_wed') ?></th>
<th rowspan="3" class="col-day"><?= tr('day_thu') ?></th>
<th rowspan="3" class="col-day"><?= tr('day_fri') ?></th>
<!-- 1. Congés de l'intervenant -->
<?php foreach ($helpers as $helper):
$hLeaves = $leaveMatrix[$helper['id']] ?? [];
foreach ($hLeaves as $type):
?>
<th rowspan="3" class="col-total rotated-text"><span><?= htmlspecialchars($type) ?> <?= htmlspecialchars($helper['name']) ?></span></th>
<?php endforeach; endforeach; ?>
<!-- 2. Méthodes de garde (sans Nounou si l'intervenant est configuré) -->
<?php foreach ($activeCareModes as $mode):
if (strtolower($mode) === 'nounou' && !empty($helpers)) continue;
?>
<th rowspan="3" class="col-total rotated-text"><span><?= htmlspecialchars($mode) ?></span></th>
<?php endforeach; ?>
<!-- 3. Maladie par enfant -->
<?php foreach ($kids as $kid): ?>
<th rowspan="3" class="col-total rotated-text"><span><?= tr('fc_menu_sick') ?> <?= htmlspecialchars($kid['name']) ?></span></th>
<?php endforeach; ?>
<?php foreach ($parents as $index => $parent):
$parentClass = ($index % 2 === 0) ? 'col-p1' : 'col-p2';
$pLeaves = $leaveMatrix[$parent['id']] ?? [];
$colspan = count($pLeaves) * 2;
?>
<?php if ($colspan > 0): ?>
<th colspan="<?= $colspan ?>" class="<?= $parentClass ?> header-group"><?= htmlspecialchars(strtoupper($parent['name'])) ?></th>
<?php endif; ?>
<?php endforeach; ?>
</tr>
<tr>
<?php foreach ($parents as $index => $parent):
$parentClass = ($index % 2 === 0) ? 'col-p1' : 'col-p2';
$pLeaves = $leaveMatrix[$parent['id']] ?? [];
?>
<?php foreach ($pLeaves as $type): ?>
<th colspan="2" class="<?= $parentClass ?>-sub"><?= htmlspecialchars($type) ?></th>
<?php endforeach; ?>
<?php endforeach; ?>
</tr>
<tr>
<?php foreach ($parents as $index => $parent):
$parentClass = ($index % 2 === 0) ? 'col-p1' : 'col-p2';
$pLeaves = $leaveMatrix[$parent['id']] ?? [];
?>
<?php foreach ($pLeaves as $type): ?>
<th class="<?= $parentClass ?>-sub <?= $parentClass ?>-av"><?= tr('fc_col_av') ?></th>
<th class="<?= $parentClass ?>-sub <?= $parentClass ?>-use"><?= tr('fc_col_use') ?></th>
<?php endforeach; ?>
<?php endforeach; ?>
</tr>
</thead>
<tbody id="planningBody"></tbody>
</table>
<div id="selectionMenu" class="fc-selection-menu" style="display:none;"></div>
</div>
</section>
<?php if (!empty($helpers)): ?>
<section class="pf-section pf-mt-15">
<div id="recapHelperContent"></div>
<div style="display: none;">
<!-- Champs masqués pour maintenir la compatibilité avec la logique JS actuelle -->
<select id="recapHelperMonth" class="pf-input"></select>
<select id="recapHelperYear" class="pf-input"></select>
<input type="date" id="recapHelperStart" class="pf-input">
<input type="date" id="recapHelperEnd" class="pf-input">
</div>
</section>
<?php endif; ?>
<section class="pf-section pf-section--bottom-panels" style="margin-top: 1.5rem;">
<div class="pf-card">
<h2 class="pf-card-title"><?= tr('fc_legend_title') ?></h2>
<div class="pf-card-body">
<div class="pf-legend-grid">
<!-- Fériés & Vacances (Fixes) -->
<div class="pf-legend-item"><div class="pf-legend-color fc-legend-school-holiday"></div><span><?= tr('leg_school_holidays') ?></span></div>
<div class="pf-legend-item"><div class="pf-legend-color fc-legend-public-holiday"></div><span><?= tr('leg_public_holiday') ?></span></div>
<!-- Intervenants (Dynamique selon les congés paramétrés) -->
<?php
$helperColorIndex = 0;
foreach ($helpers as $helper):
$hLeaves = $leaveMatrix[$helper['id']] ?? [];
foreach ($hLeaves as $type):
?>
<div class="pf-legend-item">
<div class="pf-legend-color fc-bg-palette-<?= $helperColorIndex % 8 ?>"></div>
<span><?= htmlspecialchars($type) ?> <?= htmlspecialchars($helper['name']) ?></span>
</div>
<?php $helperColorIndex++; endforeach; endforeach; ?>
<!-- Modes de garde (On masque "Nounou" si l'intervenant gère lui-même ses présences) -->
<?php foreach ($activeCareModes as $index => $mode):
$modeLower = strtolower($mode);
if ($modeLower === 'nounou' && !empty($helpers)) continue;
if ($modeLower === 'avis'): ?>
<div class="pf-legend-item">
<img src="/modules/family-calendar/assets/img/avis.svg" style="width:16px;height:16px;object-fit:contain;margin-right:6px;" alt="Avis">
<span><?= htmlspecialchars($mode) ?></span>
</div>
<?php elseif ($modeLower === 'centre'): ?>
<div class="pf-legend-item">
<span style="font-size:1.1rem; line-height:1; margin-right:6px;">🏫</span>
<span><?= htmlspecialchars($mode) ?></span>
</div>
<?php else: ?>
<div class="pf-legend-item">
<div class="pf-legend-color" style="background: var(--primary);"></div>
<span><?= htmlspecialchars($mode) ?></span>
</div>
<?php endif;
endforeach; ?>
<!-- Enfants Malades (Une puce par enfant) -->
<?php foreach ($kids as $kid):
$color = !empty($kid['color']) ? $kid['color'] : '#e11d48';
?>
<div class="pf-legend-item">
<div class="pf-legend-color" style="background: <?= htmlspecialchars($color) ?>; opacity: 0.8;"></div>
<span>Maladie <?= htmlspecialchars($kid['name']) ?></span>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</section>
</div>
<script>
const serverData = <?php echo json_encode($dbEvents, JSON_NUMERIC_CHECK); ?>;
window.FAMILY_CONFIG = {
parents: <?= json_encode($parents) ?>,
kids: <?= json_encode($kids) ?>,
activeCareModes: <?= json_encode($activeCareModes) ?>,
i18n: {
settings_updated: <?= json_encode(tr('fc_settings_updated')) ?>,
empty_matrix: "Aucun compteur de congés défini pour le moment.",
btn_delete: <?= json_encode(tr('btn_delete') ?? 'Supprimer') ?>
}
};
</script>
<h1>Family Calendar</h1>
<!-- ===================================================================== -->
<!-- PANNEAU DE CONTRÔLE : Légende, Récapitulatif et Vacances -->
<!-- ===================================================================== -->
<section class="pf-section pf-section--panel">
<div class="pf-flex pf-flex--wrap pf-gap-lg">
<!-- LÉGENDE -->
<div class="pf-card pf-card--small">
<h2 class="pf-card-title">Légende</h2>
<div class="pf-card-body">
<div class="pf-legend-item">
<div class="pf-legend-color fc-day--school-holiday"></div>
<span>Vacances scolaires</span>
</div>
<div class="pf-legend-item">
<div class="pf-legend-color fc-day--public-holiday"></div>
<span>Jour férié</span>
</div>
<div class="pf-legend-item">
<div class="pf-legend-color fc-day--off-carole"></div>
<span>Off Carole</span>
</div>
<div class="pf-legend-item">
<div class="pf-legend-color fc-day--extra-off-carole"></div>
<span>Extra Off Carole</span>
</div>
</div>
</div>
<!-- RÉCAPITULATIF ANNUEL -->
<div class="pf-card pf-card--small">
<h2 class="pf-card-title">Récapitulatif annuel</h2>
<div class="pf-card-body" id="globalSummary">
<!-- Rempli par le JavaScript -->
</div>
</div>
<!-- VACANCES SCOLAIRES -->
<div class="pf-card pf-card--small pf-card--wide">
<h2 class="pf-card-title">Vacances scolaires - Zone C (2025-2026)</h2>
<div class="pf-card-body">
<div class="pf-table-wrapper">
<table id="schoolHolidaysTable" class="fc-holidays-table">
<thead>
<tr>
<th>Période</th>
<th>Du</th>
<th>Au</th>
<th>Zones</th>
</tr>
</thead>
<tbody>
<!-- Rempli par JS -->
</tbody>
</table>
</div>
</div>
</div>
</section>
<!-- ===================================================================== -->
<!-- PLANNING PRINCIPAL -->
<!-- ===================================================================== -->
<section class="pf-section">
<h2>Planning par semaine</h2>
<div class="pf-table-wrapper">
<table id="planningTable" class="pf-table pf-table--compact">
<thead>
<tr>
<th>Mois</th>
<th>Semaine</th>
<th>Lundi</th>
<th>Mardi</th>
<th>Mercredi</th>
<th>Jeudi</th>
<th>Vendredi</th>
<th># Off Carole</th>
<th># Extra off Carole</th>
<th>#Centre</th>
<th>#Avis</th>
</tr>
</thead>
<tbody id="planningBody">
<!-- Le contenu de ce tableau est entièrement généré par family-calendar.js -->
</tbody>
</table>
<!-- Le menu contextuel est caché par défaut et son contenu est généré par JS -->
<div id="selectionMenu" class="fc-selection-menu"></div>
</div>
</section>
<!-- ===================================================================== -->
<!-- CHARGEMENT DU SCRIPT JAVASCRIPT PRINCIPAL -->
<!-- ===================================================================== -->
<script src="/assets/js/family-calendar.js"></script>
<?php
// Inclusion du pied de page
require __DIR__ . '/footer.php';
?>
<script src="/modules/family-calendar/family-calendar.js?v=<?= time() ?>"></script>
<?php require __DIR__ . '/footer.php'; ?>
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

+53
View File
@@ -0,0 +1,53 @@
<?php
// food.php
require __DIR__ . '/includes/auth.php';
require __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/i18n.php';
require_login('/login.php');
// Gestion de l'onglet actif
$tab = $_GET['tab'] ?? 'meals';
$pageTitle = tr('mod_food_name');
$activePage = "food";
$pageCss = "/modules/food/food.css";
require __DIR__ . '/header.php';
?>
<div class="pf-container">
<div class="pf-hero budget-hero">
<div class="budget-title-group">
<h1>🍳 <?= tr('mod_food_name') ?></h1>
</div>
<nav class="budget-tabs-container">
<a href="?tab=meals" class="tab-item <?= $tab == 'meals' ? 'active' : '' ?>">
<span class="tab-icon">🍽️</span>
<span><?= tr('food_tab_meals') ?></span>
</a>
<a href="?tab=liste" class="tab-item <?= $tab == 'liste' ? 'active' : '' ?>">
<span class="tab-icon">🛒</span>
<span><?= tr('food_tab_list') ?></span>
</a>
</nav>
</div>
<section class="pf-section">
<?php
$allowedTabs = ['meals', 'liste'];
if (in_array($tab, $allowedTabs)) {
$viewPath = __DIR__ . "/modules/food/views/{$tab}.php";
if (file_exists($viewPath)) {
require $viewPath;
} else {
echo "<p>Vue introuvable : " . htmlspecialchars($tab) . "</p>";
}
} else {
echo "<p>" . tr('error_occured') . "</p>";
}
?>
</section>
</div>
<?php require __DIR__ . '/footer.php'; ?>
+3 -1
View File
@@ -2,8 +2,10 @@
<footer class="pf-footer">
<div class="pf-container">
<small>&copy; <?php echo date('Y'); ?> PachaFamily</small>
<small>&copy; <?php echo date('Y'); ?> HouseHub</small>
</div>
</footer>
</div> <!-- FERMETURE pf-page -->
</body>
</html>
+373
View File
@@ -0,0 +1,373 @@
<?php
require __DIR__ . '/includes/auth.php';
require_login();
require_once __DIR__ . '/includes/i18n.php';
$pageTitle = tr('garage_page_title');
$activePage = "garage";
require __DIR__ . '/header.php';
?>
<link rel="stylesheet" href="/modules/garage/assets/garage.css">
<div id="toasts" class="toast-container"></div>
<!-- Sous-navigation -->
<nav class="garage-subnav">
<button class="nav-link active" data-page="dashboard">📊 Dashboard</button>
<button class="nav-link" data-page="vehicles">🚗 Véhicules</button>
<button class="nav-link" data-page="maintenances-all">🔧 Entretiens</button>
<button class="nav-link" data-page="parts">🔩 Pièces</button>
</nav>
<!-- ── DASHBOARD ─────────────────────────────────────────────────────────── -->
<div id="page-dashboard" class="page active">
<div class="container">
<div class="stats-grid">
<div class="stat-pill blue"><div class="label">Véhicules</div><div class="value" id="stat-vehicles">--</div></div>
<div class="stat-pill green"><div class="label">Entretiens</div><div class="value" id="stat-maintenances">--</div></div>
<div class="stat-pill amber"><div class="label">Pièces</div><div class="value" id="stat-parts">--</div></div>
<div class="stat-pill red"><div class="label">Coût total</div><div class="value" id="stat-cost">--</div></div>
</div>
<div class="garage-dash-layout">
<div class="garage-dash-main">
<div class="card-header garage-card-header" style="margin-bottom:.75rem">
<h2 style="font-size:1rem;font-weight:600">Mes véhicules</h2>
<button class="btn btn-primary btn-sm" onclick="openAddVehicle()">+ Ajouter</button>
</div>
<div id="dashboard-vehicles" class="vehicles-grid"></div>
</div>
<div class="card garage-dash-aside">
<div class="card-header"><div class="card-title">🔔 Rappels & prochains entretiens</div></div>
<div id="reminders-list"></div>
</div>
</div>
</div>
</div>
<!-- ── VÉHICULES ──────────────────────────────────────────────────────────── -->
<div id="page-vehicles" class="page">
<div class="container">
<div class="card-header garage-card-header" style="margin-bottom:1rem">
<h1 style="font-size:1.2rem;font-weight:700">🚗 Mes véhicules</h1>
<button class="btn btn-primary" onclick="openAddVehicle()">+ Ajouter un véhicule</button>
</div>
<div id="vehicles-grid" class="vehicles-grid"></div>
</div>
</div>
<!-- ── DÉTAIL VÉHICULE ─────────────────────────────────────────────────────── -->
<div id="page-vehicle" class="page">
<div class="container">
<div style="margin-bottom:1rem">
<button class="btn btn-secondary btn-sm" onclick="navigate('vehicles')">← Retour</button>
</div>
<div id="vehicle-header"></div>
<div class="tabs garage-tabs">
<button class="tab-btn active" data-tab="maintenances" onclick="switchTab('maintenances')">🔧 Entretiens <span id="maintenance-total" style="color:var(--muted);font-size:.78rem"></span></button>
<button class="tab-btn" data-tab="parts" onclick="switchTab('parts')">🔩 Pièces <span id="parts-total-vehicle" style="color:var(--muted);font-size:.78rem"></span></button>
<button class="tab-btn" data-tab="documents" onclick="switchTab('documents')">📎 Documents <span id="vehicle-docs-tab-count" style="color:var(--muted);font-size:.78rem"></span></button>
</div>
<div id="tab-maintenances" class="tab-pane active">
<div class="garage-tab-actions">
<button class="btn btn-primary btn-sm" onclick="openAddMaintenance()">+ Ajouter un entretien</button>
</div>
<div id="maintenance-list"></div>
</div>
<div id="tab-parts" class="tab-pane">
<div class="garage-tab-actions">
<button class="btn btn-primary btn-sm" onclick="openAddPart()">+ Ajouter une pièce</button>
</div>
<div id="parts-list-vehicle"></div>
</div>
<div id="tab-documents" class="tab-pane">
<div class="garage-doc-upload-bar">
<div class="form-group" style="flex:1;min-width:0;margin:0">
<label class="form-label" for="vehicle-doc-label">Libellé (optionnel)</label>
<input type="text" class="form-control" id="vehicle-doc-label" placeholder="Carte grise, assurance…">
</div>
<div class="form-group" style="margin:0;flex:1;min-width:140px">
<label class="form-label" for="vehicle-doc-file">Fichier</label>
<input type="file" class="form-control" id="vehicle-doc-file" accept=".pdf,.png,.jpg,.jpeg,.webp,.doc,.docx,.xls,.xlsx,.txt">
</div>
<button type="button" class="btn btn-primary btn-sm garage-doc-upload-btn" onclick="uploadVehicleDocument()">Envoyer</button>
</div>
<p class="garage-doc-hint">PDF, images, Office… · max 12 Mo</p>
<div id="vehicle-documents-list"></div>
</div>
</div>
</div>
<!-- ── DÉTAIL ENTRETIEN ─────────────────────────────────────────────────────── -->
<div id="page-maintenance" class="page">
<div class="container">
<div style="margin-bottom:1rem">
<button class="btn btn-secondary btn-sm" id="maintenance-back-btn" onclick="navigate('vehicle',{id:currentVehicleId})">← Retour au véhicule</button>
</div>
<div id="maintenance-detail-header"></div>
<div class="card garage-docs-card" style="margin-top:1rem">
<div class="card-header garage-card-header">
<span class="card-title">📎 Documents & factures (cette révision)</span>
</div>
<div style="padding:0 1.25rem 1rem">
<div class="garage-doc-upload-bar">
<div class="form-group" style="flex:1;min-width:0;margin:0">
<label class="form-label" for="maint-doc-label">Libellé (ex. facture garage)</label>
<input type="text" class="form-control" id="maint-doc-label" placeholder="Facture, devis…">
</div>
<div class="form-group" style="margin:0;flex:1;min-width:140px">
<label class="form-label" for="maint-doc-file">Fichier</label>
<input type="file" class="form-control" id="maint-doc-file" accept=".pdf,.png,.jpg,.jpeg,.webp,.doc,.docx,.xls,.xlsx,.txt">
</div>
<button type="button" class="btn btn-primary btn-sm garage-doc-upload-btn" onclick="uploadMaintenanceDocument()">Envoyer</button>
</div>
<p class="garage-doc-hint">PDF, images… · max 12 Mo</p>
<div id="maintenance-documents-list"></div>
</div>
</div>
<div class="card" style="padding:0;margin-top:1.5rem">
<div class="card-header">
<span class="card-title">🔩 Pièces utilisées <span id="maint-parts-count" class="badge badge-gray" style="margin-left:.5rem"></span></span>
<button class="btn btn-primary btn-sm" onclick="toggleInlinePartForm()">+ Ajouter une pièce</button>
</div>
<!-- Formulaire inline ajout pièce -->
<div id="inline-part-form" style="display:none;background:#f8fafc;border-bottom:1px solid #e2e8f0;padding:1.25rem 1.5rem">
<p style="font-size:.8rem;font-weight:600;color:#64748b;margin-bottom:.75rem;text-transform:uppercase;letter-spacing:.05em">🔄 Réutiliser une pièce connue</p>
<div id="known-parts-list"></div>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:1rem">
<div class="form-group"><label class="form-label">Nom *</label><input class="form-control" id="ipart-name" placeholder="Filtre à huile"></div>
<div class="form-group"><label class="form-label">Référence</label><input class="form-control" id="ipart-reference" placeholder="Ex: 06A115561B" style="font-family:monospace"></div>
</div>
<div style="display:grid;grid-template-columns:1fr 1fr 1fr;gap:1rem">
<div class="form-group"><label class="form-label">Marque</label><input class="form-control" id="ipart-brand" placeholder="Bosch, NGK..."></div>
<div class="form-group">
<label class="form-label">Prix unitaire (€)</label>
<input class="form-control" id="ipart-price" type="number" step="0.01" value="0" oninput="updateIPriceTTC()">
<label style="display:flex;align-items:center;gap:.4rem;margin-top:.4rem;font-size:.8rem;color:#64748b;cursor:pointer">
<input type="checkbox" id="ipart-prix-ht" onchange="updateIPriceTTC()" style="width:14px;height:14px"> Prix HT (+20% TVA)
</label>
<p id="ipart-ttc-preview" style="display:none;font-size:.8rem;color:#2563eb;margin-top:.2rem;font-family:monospace"></p>
</div>
<div class="form-group"><label class="form-label">Quantité</label><input class="form-control" id="ipart-quantity" type="number" value="1" min="1"></div>
</div>
<div class="form-group"><label class="form-label">Photo (optionnel)</label><input class="form-control" id="ipart-photo" type="file" accept="image/*"></div>
<div style="display:flex;gap:.5rem;margin-top:.5rem">
<button class="btn btn-primary btn-sm" onclick="saveInlinePart()">+ Ajouter</button>
<button class="btn btn-secondary btn-sm" onclick="toggleInlinePartForm()">Annuler</button>
</div>
</div>
<div id="maintenance-parts-list"></div>
</div>
</div>
</div>
<!-- ── TOUS LES ENTRETIENS ─────────────────────────────────────────────────── -->
<div id="page-maintenances-all" class="page">
<div class="container">
<div class="card-header garage-card-header" style="margin-bottom:1rem">
<div>
<h1 style="font-size:1.2rem;font-weight:700">🔧 Tous les entretiens</h1>
<p style="color:var(--muted);font-size:.85rem"><span id="all-maint-count">0</span> entretiens · Total : <span id="all-maint-total">--</span></p>
</div>
</div>
<div id="all-maintenances-list"></div>
</div>
</div>
<!-- ── TOUTES LES PIÈCES ──────────────────────────────────────────────────── -->
<div id="page-parts" class="page">
<div class="container">
<div class="card-header garage-card-header" style="margin-bottom:1rem">
<div>
<h1 style="font-size:1.2rem;font-weight:700">🔩 Toutes les pièces</h1>
<p style="color:var(--muted);font-size:.85rem"><span id="all-parts-count">0</span> pièces · Total : <span id="all-parts-total">--</span></p>
</div>
<button class="btn btn-primary" onclick="openAddPart()">+ Ajouter une pièce</button>
</div>
<div id="all-parts-list"></div>
</div>
</div>
<!-- ══ MODALS ════════════════════════════════════════════════════════════════ -->
<!-- MODAL: VEHICLE -->
<div id="modal-vehicle" class="modal-backdrop">
<div class="modal">
<div class="modal-header">
<div class="modal-title" id="modal-vehicle-title">Ajouter un véhicule</div>
<button class="modal-close" onclick="closeModal('modal-vehicle')">✕</button>
</div>
<div class="modal-body">
<form id="form-vehicle" onsubmit="return false">
<input type="hidden" id="form-vehicle-id" name="id">
<div class="form-row">
<div class="form-group"><label class="form-label">Nom *</label><input class="form-control" id="vehicle-name" name="name" required placeholder="Ma Clio"></div>
<div class="form-group"><label class="form-label">Marque *</label><input class="form-control" id="vehicle-brand" name="brand" required placeholder="Renault"></div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Modèle *</label><input class="form-control" id="vehicle-model" name="model" required placeholder="Clio 4"></div>
<div class="form-group"><label class="form-label">Année</label><input class="form-control" id="vehicle-year" name="year" type="number" placeholder="2019"></div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Immatriculation</label><input class="form-control" id="vehicle-license-plate" name="license_plate" placeholder="AB-123-CD"></div>
<div class="form-group"><label class="form-label">Carburant</label>
<select class="form-control" id="vehicle-fuel-type" name="fuel_type">
<option>Essence</option><option>Diesel</option><option>Hybride</option><option>Electrique</option><option>GPL</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Kilométrage</label><input class="form-control" id="vehicle-current-km" name="current_km" type="number" placeholder="85000"></div>
<div class="form-group">
<label class="form-label">Conso. moy. (L/100km)</label>
<input class="form-control" id="vehicle-consumption" name="consumption" type="number" step="0.1" min="0" placeholder="ex: 6.5">
</div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Date d'achat</label><input class="form-control" id="vehicle-purchase-date" name="purchase_date" type="date"></div>
<div class="form-group"><label class="form-label">Prix d'achat (€)</label><input class="form-control" id="vehicle-purchase-price" name="purchase_price" type="number" step="0.01"></div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">VIN</label><input class="form-control" id="vehicle-vin" name="vin" placeholder="VF1..."></div>
<div class="form-group"><label class="form-label">Couleur</label><input class="form-control" id="vehicle-color" name="color" placeholder="Blanc nacré"></div>
</div>
<div class="form-group">
<label class="form-label">Photo</label>
<input class="form-control" id="vehicle-photo" name="photo" type="file" accept="image/*" onchange="previewPhoto('vehicle-photo','vehicle-photo-preview')">
<img id="vehicle-photo-preview" style="display:none;max-height:120px;margin-top:.5rem;border-radius:6px" alt="">
</div>
<div class="form-group"><label class="form-label">Notes</label><textarea class="form-control" id="vehicle-notes" name="notes" rows="2"></textarea></div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModal('modal-vehicle')">Annuler</button>
<button class="btn btn-primary" onclick="saveVehicle()">Enregistrer</button>
</div>
</div>
</div>
<!-- MODAL: MAINTENANCE -->
<div id="modal-maintenance" class="modal-backdrop">
<div class="modal">
<div class="modal-header">
<div class="modal-title" id="modal-maintenance-title">Ajouter un entretien</div>
<button class="modal-close" onclick="closeModal('modal-maintenance')">✕</button>
</div>
<div class="modal-body">
<form id="form-maintenance" onsubmit="return false">
<input type="hidden" id="form-maintenance-id" name="id">
<input type="hidden" id="maintenance-vehicle-id" name="vehicle_id">
<div class="form-row">
<div class="form-group"><label class="form-label">Type *</label>
<select class="form-control" id="maintenance-type" name="type">
<option>Vidange</option><option>Révision</option><option>Freins</option><option>Pneus</option>
<option>Distribution</option><option>Filtres</option><option>Batterie</option><option>Climatisation</option>
<option>Carrosserie</option><option>Diagnostic</option><option>Contrôle technique</option><option>Autre</option>
</select>
</div>
<div class="form-group"><label class="form-label">Date *</label><input class="form-control" id="maintenance-date" name="date" type="date" required></div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Kilométrage</label><input class="form-control" id="maintenance-km" name="km" type="number" placeholder="85000"></div>
<div class="form-group"><label class="form-label">Coût main d'œuvre (€)</label><input class="form-control" id="maintenance-cost" name="cost" type="number" step="0.01" placeholder="0"></div>
</div>
<div class="form-group"><label class="form-label">Description</label><textarea class="form-control" id="maintenance-description" name="description" rows="2"></textarea></div>
<div class="form-row">
<div class="form-group"><label class="form-label">Mécanicien</label><input class="form-control" id="maintenance-mechanic" name="mechanic"></div>
<div class="form-group"><label class="form-label">Garage / Atelier</label><input class="form-control" id="maintenance-garage" name="garage_name"></div>
</div>
<div style="background:rgba(37,99,235,.05);border:1px solid rgba(37,99,235,.1);border-radius:8px;padding:1rem;margin-top:.5rem">
<div style="font-size:.82rem;color:var(--muted);margin-bottom:.75rem;font-weight:600">🔔 Prochain entretien</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Date prévue</label><input class="form-control" id="maintenance-next-date" name="next_date" type="date"></div>
<div class="form-group"><label class="form-label">Kilométrage prévu</label><input class="form-control" id="maintenance-next-km" name="next_km" type="number" placeholder="95000"></div>
</div>
</div>
<div class="form-group" style="margin-top:1rem"><label class="form-label">Notes</label><textarea class="form-control" id="maintenance-notes" name="notes" rows="2"></textarea></div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModal('modal-maintenance')">Annuler</button>
<button class="btn btn-primary" onclick="saveMaintenance()">Enregistrer</button>
</div>
</div>
</div>
<!-- MODAL: PART -->
<div id="modal-part" class="modal-backdrop">
<div class="modal">
<div class="modal-header">
<div class="modal-title" id="modal-part-title">Ajouter une pièce</div>
<button class="modal-close" onclick="closeModal('modal-part')">✕</button>
</div>
<div class="modal-body">
<form id="form-part" onsubmit="return false">
<input type="hidden" id="form-part-id" name="id">
<input type="hidden" id="part-vehicle-id" name="vehicle_id">
<input type="hidden" id="part-maintenance-id" name="maintenance_id">
<div class="form-row">
<div class="form-group"><label class="form-label">Nom *</label><input class="form-control" id="part-name" name="name" required placeholder="Filtre à huile"></div>
<div class="form-group"><label class="form-label">Catégorie</label>
<select class="form-control" id="part-category" name="category">
<option>Moteur</option><option>Freinage</option><option>Suspension</option><option>Transmission</option>
<option>Carrosserie</option><option>Electricite</option><option>Eclairage</option><option>Filtration</option>
<option>Refroidissement</option><option>Echappement</option><option>Pneumatiques</option><option>Autre</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group"><label class="form-label">Marque</label><input class="form-control" id="part-brand" name="brand" placeholder="Bosch, NGK..."></div>
<div class="form-group"><label class="form-label">Référence</label><input class="form-control" id="part-reference" name="reference"></div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">Prix unitaire (€)</label>
<input class="form-control" id="part-price" name="price" type="number" step="0.01" placeholder="12.50" oninput="updatePartPriceTTC()">
<label style="display:flex;align-items:center;gap:.4rem;margin-top:.4rem;font-size:.8rem;color:#64748b;cursor:pointer">
<input type="checkbox" id="part-prix-ht" onchange="updatePartPriceTTC()" style="width:14px;height:14px"> Prix HT (+20% TVA)
</label>
<p id="part-ttc-preview" style="display:none;font-size:.8rem;color:#2563eb;margin-top:.2rem;font-family:monospace"></p>
</div>
<div class="form-group"><label class="form-label">Quantité</label><input class="form-control" id="part-quantity" name="quantity" type="number" value="1" min="1"></div>
</div>
<div class="form-group">
<label class="form-label">Photo</label>
<input class="form-control" id="part-photo" name="photo" type="file" accept="image/*" onchange="previewPhoto('part-photo','part-photo-preview')">
<img id="part-photo-preview" style="display:none;max-height:100px;margin-top:.5rem;border-radius:6px" alt="">
</div>
<div class="form-group"><label class="form-label">Notes</label><textarea class="form-control" id="part-notes" name="notes" rows="2"></textarea></div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModal('modal-part')">Annuler</button>
<button class="btn btn-primary" onclick="savePart()">Enregistrer</button>
</div>
</div>
</div>
<!-- MODAL: UPLOAD PHOTO VÉHICULE -->
<div id="modal-upload-photo" class="modal-backdrop">
<div class="modal" style="max-width:400px">
<div class="modal-header">
<div class="modal-title">📷 Changer la photo</div>
<button class="modal-close" onclick="closeModal('modal-upload-photo')">✕</button>
</div>
<div class="modal-body">
<input type="hidden" id="upload-vehicle-id">
<div class="form-group"><label class="form-label">Nouvelle photo</label><input class="form-control" id="upload-photo-file" type="file" accept="image/*"></div>
</div>
<div class="modal-footer">
<button class="btn btn-secondary" onclick="closeModal('modal-upload-photo')">Annuler</button>
<button class="btn btn-primary" onclick="doUploadPhoto()">Mettre à jour</button>
</div>
</div>
</div>
<script src="/modules/garage/assets/garage.js"></script>
<?php require __DIR__ . '/footer.php'; ?>
+77
View File
@@ -0,0 +1,77 @@
<?php
require_once __DIR__ . '/includes/meta_db.php';
$db_host = getenv('DB_HOST') ?: '127.0.0.1';
$db_user = getenv('DB_USER') ?: 'househub';
$db_pass = getenv('DB_PASS') ?: 'househub_dev';
echo "<h1>📅 Génération du squelette du calendrier (pf_calendar_weeks)</h1>";
$monthsFr = [1=>'Janvier', 2=>'Février', 3=>'Mars', 4=>'Avril', 5=>'Mai', 6=>'Juin', 7=>'Juillet', 8=>'Août', 9=>'Septembre', 10=>'Octobre', 11=>'Novembre', 12=>'Décembre'];
try {
$stmt = $meta_pdo->query("SELECT db_name, name FROM families WHERE is_active = 1");
$families = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($families as $family) {
$dbName = $family['db_name'];
echo "<h3>Famille : {$family['name']} ($dbName)</h3><ul>";
try {
$pdo = new PDO("mysql:host=$db_host;dbname=$dbName;charset=utf8mb4", $db_user, $db_pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
// On utilise REPLACE INTO pour écraser proprement si certaines semaines existent déjà
$sql = "REPLACE INTO pf_calendar_weeks
(year, week_iso_year, week_iso_number, week_label, month, month_name, week_start_date, mon_date, tue_date, wed_date, thu_date, fri_date)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$insertStmt = $pdo->prepare($sql);
// On génère de l'été 2023 jusqu'à fin 2030 !
$startDate = new DateTime('2023-08-28'); // Un lundi
$endDate = new DateTime('2030-12-31');
$count = 0;
while ($startDate <= $endDate) {
$mon = clone $startDate;
$tue = clone $startDate; $tue->modify('+1 day');
$wed = clone $startDate; $wed->modify('+2 days');
$thu = clone $startDate; $thu->modify('+3 days');
$fri = clone $startDate; $fri->modify('+4 days');
$year = (int)$mon->format('Y');
$month = (int)$mon->format('n');
$weekIsoYear = (int)$mon->format('o');
$weekIsoNumber = (int)$mon->format('W');
$weekLabel = "Semaine " . $weekIsoNumber;
$monthName = $monthsFr[$month];
$insertStmt->execute([
$year,
$weekIsoYear,
$weekIsoNumber,
$weekLabel,
$month,
$monthName,
$mon->format('Y-m-d'),
$mon->format('Y-m-d'),
$tue->format('Y-m-d'),
$wed->format('Y-m-d'),
$thu->format('Y-m-d'),
$fri->format('Y-m-d')
]);
$startDate->modify('+1 week');
$count++;
}
echo "<li>✅ $count semaines générées (de 2023 à 2030) !</li>";
} catch (\PDOException $e) {
echo "<li>❌ Erreur : " . $e->getMessage() . "</li>";
}
echo "</ul>";
}
echo "<h2>🎉 Terminé ! Tu peux supprimer ce fichier et rafraîchir ton calendrier.</h2>";
} catch (Exception $e) {
die("Erreur fatale Meta DB : " . $e->getMessage());
}
?>
+974
View File
@@ -0,0 +1,974 @@
<?php
// modules/gift-list/gift-list.php
require __DIR__ . '/includes/auth.php';
require_login('/login.php');
require __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/i18n.php';
if (session_status() === PHP_SESSION_NONE) { session_start(); }
// --- 1. CONFIGURATION DE BASE ---
$year = (int)date('Y');
$pageTitle = tr('gift_page_title');
$activePage = "gift-list";
$mainClass = "pf-gift-list";
$pageCss = "/modules/gift-list/gift-list.css";
// --- 2. RÉCUPÉRATION DYNAMIQUE DES DONNÉES ---
// On inclut les enfants du foyer ET les proches enfants
$stmt = $pdo->query("SELECT name FROM pf_people WHERE role IN ('enfant', 'proche_enfant') ORDER BY name ASC");
$children = $stmt->fetchAll(PDO::FETCH_COLUMN) ?: ['Aucun enfant configuré'];
// On inclut les adultes du foyer ET les proches adultes (On exclut nounou et les enfants)
$stmt = $pdo->query("SELECT name FROM pf_people WHERE role NOT IN ('enfant', 'proche_enfant', 'nounou') ORDER BY name ASC");
$allAdultsList = $stmt->fetchAll(PDO::FETCH_COLUMN) ?: ['Aucun adulte configuré'];
// On récupère toutes les occasions (avec l'icône)
$stmt = $pdo->query("SELECT code, name, icon, month_date FROM pf_gift_occasions WHERE is_active = 1 ORDER BY sort_order ASC, month_date ASC, id ASC");
$activeOccasions = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($activeOccasions)) {
$activeOccasions = [['code' => 'DEMO', 'name' => 'Fête par défaut', 'icon' => '🎁', 'month_date' => null]];
}
$allowedOccasionCodes = array_column($activeOccasions, 'code');
// --- 3. CHARGEMENT DES CADEAUX ---
$inMarks = implode(',', array_fill(0, count($allowedOccasionCodes), '?'));
$sql = "SELECT * FROM pf_gifts WHERE year = ? AND occasion IN ($inMarks) ORDER BY occasion ASC, child_name ASC, adult_name ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute(array_merge([$year], $allowedOccasionCodes));
$gifts = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data = [];
$adultsInView = [];
foreach ($gifts as $g) {
$data[$g['occasion']][$g['child_name']]['gifts'][] = $g;
$data[$g['occasion']][$g['child_name']]['totals'][$g['adult_name']] = ($data[$g['occasion']][$g['child_name']]['totals'][$g['adult_name']] ?? 0) + $g['amount'];
$adultsInView[$g['adult_name']] = true;
if (!empty($g['payer_name'])) {
$adultsInView[$g['payer_name']] = true;
}
}
// --- 4. TRICOUNT (Bilan et Remboursements) ---
$people = array_values(array_unique(array_merge($allAdultsList, array_keys($adultsInView))));
$people = array_filter($people);
sort($people);
$matrix = [];
foreach ($people as $p1) { foreach ($people as $p2) $matrix[$p1][$p2] = 0.0; }
foreach ($gifts as $g) {
$adult = $g['adult_name'];
$payer = $g['payer_name'] ?? $g['adult_name'];
$amt = (float)$g['amount'];
if ($amt > 0 && $adult && $payer && $adult !== $payer) {
$matrix[$adult][$payer] += $amt;
}
}
$settlements = [];
$countPeople = count($people);
for ($i = 0; $i < $countPeople; $i++) {
for ($j = $i + 1; $j < $countPeople; $j++) {
$a = $people[$i]; $b = $people[$j];
$net = $matrix[$a][$b] - $matrix[$b][$a];
if ($net > 0.01) { $settlements[] = ['from' => $a, 'to' => $b, 'amount' => $net]; }
elseif ($net < -0.01) { $settlements[] = ['from' => $b, 'to' => $a, 'amount' => -$net]; }
}
}
require __DIR__ . '/header.php';
?>
<div class="pf-container cl-view-dynamic">
<div class="cl-titlebar">
<div style="display: flex; align-items: center; gap: 12px;">
<h1 style="margin: 0;">🎁 <?= sprintf(tr('gift_main_title'), $year) ?></h1>
<button id="btn-open-gift-settings" class="btn-settings-gear" title="<?= tr('gift_settings') ?>" style="font-size: 1.4rem; padding: 4px;">
⚙️
</button>
</div>
</div>
<div class="pf-filter-bar">
<span class="pf-filter-icon">🔍</span>
<div class="pf-multi-select" id="ms-child">
<div class="pf-ms-trigger" onclick="toggleMS('ms-child-list', this)">
👦 <span id="ms-child-label"><?= tr('gift_filter_all_children') ?></span>
</div>
<div class="pf-ms-dropdown" id="ms-child-list">
<label class="pf-ms-option is-all">
<input type="checkbox" value="all" checked onchange="handleMSChange(this, 'child')">
<?= tr('gift_filter_all_children') ?>
</label>
<?php foreach($children as $c): ?>
<label class="pf-ms-option"><input type="checkbox" value="<?= htmlspecialchars($c) ?>" onchange="handleMSChange(this, 'child')"> <?= htmlspecialchars($c) ?></label>
<?php endforeach; ?>
</div>
</div>
<div class="pf-multi-select" id="ms-adult">
<div class="pf-ms-trigger" onclick="toggleMS('ms-adult-list', this)">
👤 <span id="ms-adult-label"><?= tr('gift_filter_all_adults') ?></span>
</div>
<div class="pf-ms-dropdown" id="ms-adult-list">
<label class="pf-ms-option is-all">
<input type="checkbox" value="all" checked onchange="handleMSChange(this, 'adult')">
<?= tr('gift_filter_all_adults') ?>
</label>
<?php foreach($allAdultsList as $a): ?>
<label class="pf-ms-option"><input type="checkbox" value="<?= htmlspecialchars($a) ?>" onchange="handleMSChange(this, 'adult')"> <?= htmlspecialchars($a) ?></label>
<?php endforeach; ?>
</div>
</div>
</div>
<section class="pf-section">
<?php foreach ($activeOccasions as $occ):
$occCode = $occ['code'];
// Affichage Brut de la BDD pour le nom de l'occasion
$occName = $occ['name'];
$occIcon = $occ['icon'] ?: '🎁';
?>
<div class="js-occ-section">
<h2 class="cl-occasion-title">
<span class="cl-occasion-icon"><?= htmlspecialchars($occIcon) ?></span>
<?= htmlspecialchars($occName) ?>
</h2>
<?php foreach ($children as $child):
$childData = $data[$occCode][$child] ?? ['gifts' => [], 'totals' => []];
?>
<div class="pf-child-section js-child" data-name="<?= htmlspecialchars($child) ?>">
<div class="pf-child-header">
<h3>👦 <?= htmlspecialchars($child) ?></h3>
<button class="pf-btn pf-btn-small btn-add-gift"
data-child="<?= htmlspecialchars($child) ?>"
data-occ="<?= htmlspecialchars($occCode) ?>"
data-adults="<?= htmlspecialchars(json_encode(array_values($allAdultsList))) ?>">
+ <?= tr('gift_add_gift') ?>
</button>
</div>
<div class="pf-child-totals-bar">
<?php foreach ($childData['totals'] as $adult => $tot): ?>
<span class="pf-summary-pill js-pill-adult" data-adult="<?= htmlspecialchars($adult) ?>">👤 <?= htmlspecialchars($adult) ?> : <strong><?= number_format($tot, 2, ',', '') ?> €</strong></span>
<?php endforeach; ?>
</div>
<?php if (empty($childData['gifts'])): ?>
<p class="js-empty-state gift-empty-state"><?= tr('gift_empty_state_no_gifts') ?></p>
<?php else: ?>
<p class="js-empty-state gift-empty-state pf-hidden"><?= tr('gift_empty_state_no_filter') ?></p>
<div class="pf-gift-feed">
<?php foreach ($childData['gifts'] as $g): ?>
<div class="pf-gift-card-compact js-gift-card" data-adult="<?= htmlspecialchars($g['adult_name']) ?>">
<div>
<h4 class="pf-gift-title">
<?= htmlspecialchars($g['gift_description']) ?>
<?php if($g['product_link']): ?><a href="<?= htmlspecialchars($g['product_link']) ?>" target="_blank" class="pf-gift-link">🔗</a><?php endif; ?>
</h4>
<span class="pf-pill-adult">👤 <?= htmlspecialchars($g['adult_name']) ?></span>
<?php if($g['payer_name'] && $g['payer_name'] !== $g['adult_name']): ?>
<div class="pf-gift-payer"><?= sprintf(tr('gift_paid_by'), htmlspecialchars($g['payer_name'])) ?></div>
<?php endif; ?>
</div>
<div class="pf-gift-footer">
<span class="pf-gift-price"><?= number_format($g['amount'], 2, ',', ' ') ?> €</span>
<div class="pf-gift-actions">
<button class="btn-icon-action edit btn-edit-gift" data-gift="<?= htmlspecialchars(json_encode($g)) ?>">✏️</button>
<button class="btn-icon-action delete btn-delete-gift" data-id="<?= $g['id'] ?>">🗑️</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</section>
<section class="pf-section pf-section--panel gift-tricount-section">
<h2 class="gift-tricount-title">⚖️ <?= tr('gift_liquidations') ?></h2>
<?php if (empty($settlements)): ?>
<p class="gift-tricount-success">✅ <?= tr('gift_no_debt') ?></p>
<?php else: ?>
<ul class="pf-tricount-list">
<?php foreach ($settlements as $s): ?>
<li class="pf-tricount-item">
<span><strong><?= htmlspecialchars($s['from']) ?></strong> <?= tr('gift_owes') ?> <?= tr('gift_to') ?> <?= htmlspecialchars($s['to']) ?></span>
<strong class="gift-tricount-debt-amount"><?= number_format($s['amount'], 2, ',', ' ') ?> €</strong>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<details class="gift-matrix-details">
<summary class="gift-matrix-summary"><?= tr('gift_view_matrix') ?></summary>
<div class="gift-matrix-wrapper">
<table class="pf-table pf-table--compact cl-debt-matrix">
<thead>
<tr>
<th class="sticky-col bg-header"><?= tr('gift_debtor') ?> \ <?= tr('gift_creditor') ?></th>
<?php foreach ($people as $p): ?><th><?= htmlspecialchars($p) ?></th><?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($people as $debtor): ?>
<tr>
<th class="sticky-col bg-body"><?= htmlspecialchars($debtor) ?></th>
<?php foreach ($people as $creditor):
$val = $matrix[$debtor][$creditor] ?? 0;
$display = ($debtor === $creditor) || $val == 0 ? '—' : number_format($val, 2, ',', ' ') . ' €';
$cellClass = $val > 0 ? 'gift-cell-danger' : 'gift-cell-muted';
?>
<td class="<?= $cellClass ?>"><?= $display ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</details>
</section>
</div>
<!-- 1. Modale CRUD Cadeau -->
<div id="pf-gift-modal" class="pf-modal">
<div class="pf-modal-content gift-modal-custom-content">
<div class="gift-modal-custom-header">
<h3 id="modalTitle" class="pf-modal-title gift-modal-custom-title">Cadeau</h3>
<button type="button" class="btn-modal-close gift-modal-close-btn">&times;</button>
</div>
<form method="post" action="/modules/gift-list/save-gift.php" id="giftForm">
<input type="hidden" name="year" value="<?= $year ?>">
<input type="hidden" name="child_name" id="modalChild">
<input type="hidden" name="occasion" id="modalOccasion">
<input type="hidden" name="action" id="modalAction">
<input type="hidden" name="gift_id" id="modalGiftId">
<div class="pf-form-group"><label class="pf-label"><?= tr('gift_col_adult') ?></label><select name="adult_name" id="modalAdult" class="pf-input" required></select></div>
<div class="pf-form-group"><label class="pf-label"><?= tr('gift_modal_payer') ?></label><select name="payer_name" id="modalPayer" class="pf-input" required></select></div>
<div class="pf-form-group"><label class="pf-label"><?= tr('gift_modal_gift_name') ?></label><input type="text" name="gift_description" id="modalDesc" class="pf-input" required></div>
<div class="pf-form-group"><label class="pf-label"><?= tr('gift_modal_price') ?></label><input type="number" step="0.01" name="amount" id="modalAmount" class="pf-input"></div>
<div class="pf-form-group gift-form-group-spaced"><label class="pf-label"><?= tr('gift_modal_link') ?></label><input type="url" name="product_link" id="modalLink" class="pf-input"></div>
<div class="modal-footer gift-modal-custom-footer">
<button type="button" class="pf-btn btn-secondary btn-modal-close"><?= tr('btn_cancel') ?></button>
<button type="submit" class="pf-btn"><?= tr('btn_save') ?></button>
</div>
</form>
</div>
</div>
<!-- 2. Modale Paramètres (Occasions & Proches) -->
<div id="modal-gift-settings" class="pf-modal">
<div class="pf-modal-content" style="max-width: 600px; width: 90%;">
<div class="pf-modal-header" style="display: flex; justify-content: space-between; align-items: center;">
<h3 class="pf-modal-title" style="margin: 0;">⚙️ <?= tr('gift_settings') ?></h3>
<button type="button" class="pf-modal-close" style="background:none; border:none; font-size:1.5rem; cursor:pointer;" onclick="closeGiftSettings()">&times;</button>
</div>
<div style="display: flex; gap: 4px; background: var(--bg-page); padding: 4px; border-radius: 8px; margin: 1rem 0;">
<button type="button" id="tab-btn-occasions" class="bs-tab-btn active" style="flex: 1; padding: 8px 12px; font-weight: 600; border-radius: 6px; border: none; cursor: pointer; transition: 0.2s;" onclick="switchGLTab('occasions')"><?= tr('gift_tab_occasions') ?></button>
<button type="button" id="tab-btn-proches" class="bs-tab-btn" style="flex: 1; padding: 8px 12px; font-weight: 600; border-radius: 6px; border: none; cursor: pointer; transition: 0.2s; background: transparent;" onclick="switchGLTab('proches')"><?= tr('gift_tab_proches') ?></button>
</div>
<div class="pf-modal-body" style="min-height: 450px; max-height: 60vh; overflow-y: auto; padding: 0 1rem 1rem 1rem; display: flex; flex-direction: column;">
<div id="gl-pane-occasions" class="gl-pane active" style="display: block; animation: fadeIn 0.3s ease;">
<div id="occasions-list" style="margin-bottom: 20px;">⏳ <?= tr('loading') ?></div>
<hr style="border:0; border-top: 1px solid var(--border-light); margin: 20px 0;">
<h5 style="margin: 0 0 15px 0; font-size: 1rem; color: var(--text-main);"><?= tr('gift_settings_add_occ') ?></h5>
<form id="form-add-occasion" style="display: flex; flex-direction: column; gap: 16px;">
<div>
<label class="pf-label" style="display: block; margin-bottom: 6px;"><?= tr('gift_settings_icon') ?></label>
<input type="hidden" name="icon" id="add-occ-icon" value="🎁">
<div class="emoji-picker" style="display: flex; gap: 8px; flex-wrap: wrap;">
<div class="emoji-option selected" onclick="selectEmoji(this, 'add-occ-icon', '🎁')">🎁</div>
<div class="emoji-option" onclick="selectEmoji(this, 'add-occ-icon', '🎄')">🎄</div>
<div class="emoji-option" onclick="selectEmoji(this, 'add-occ-icon', '🎂')">🎂</div>
<div class="emoji-option" onclick="selectEmoji(this, 'add-occ-icon', '🎉')">🎉</div>
<div class="emoji-option" onclick="selectEmoji(this, 'add-occ-icon', '🎓')">🎓</div>
</div>
</div>
<div style="display: flex; gap: 12px; flex-wrap: wrap;">
<div style="flex: 1; min-width: 150px;">
<label class="pf-label" style="display: block; margin-bottom: 6px;"><?= tr('gift_modal_gift_name') ?> *</label>
<input type="text" name="name" id="add-occ-name" class="pf-input" style="width: 100%;" required>
</div>
<div style="width: 110px;">
<label class="pf-label" style="display: block; margin-bottom: 6px;"><?= tr('gift_settings_date') ?></label>
<input type="text" name="month_date" id="add-occ-date" class="pf-input" style="width: 100%;" placeholder="MM-DD">
</div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 5px;">
<button type="button" class="pf-btn btn-secondary" onclick="document.getElementById('form-add-occasion').reset()"><?= tr('btn_cancel') ?></button>
<button type="submit" class="pf-btn pf-btn-primary"><?= tr('btn_add') ?></button>
</div>
</form>
</div>
<div id="gl-pane-proches" class="gl-pane" style="display: none; animation: fadeIn 0.3s ease;">
<div id="proches-list" style="margin-bottom: 20px;">⏳ <?= tr('loading') ?></div>
<hr style="border:0; border-top: 1px solid var(--border-light); margin: auto 0 20px 0;">
<h5 style="margin: 0 0 15px 0; font-size: 1rem; color: var(--text-main);"><?= tr('gift_settings_add_proche') ?></h5>
<form id="form-add-proche" style="display: flex; flex-direction: column; gap: 16px;">
<div style="display: flex; gap: 12px; flex-wrap: wrap;">
<div style="flex: 1; min-width: 150px;">
<label class="pf-label" style="display: block; margin-bottom: 6px;"><?= tr('gift_ph_proche_name') ?> *</label>
<input type="text" name="name" id="add-proche-name" class="pf-input" style="width: 100%;" required>
</div>
<div style="flex: 1; min-width: 150px;">
<label class="pf-label" style="display: block; margin-bottom: 6px;"><?= tr('gift_role_label') ?> *</label>
<select name="role" id="add-proche-role" class="pf-input" style="width: 100%;" required>
<option value="proche_adulte"><?= tr('gift_role_proche_adulte') ?></option>
<option value="proche_enfant"><?= tr('gift_role_proche_enfant') ?></option>
</select>
</div>
</div>
<div style="display: flex; justify-content: flex-end; gap: 10px; margin-top: 5px;">
<button type="button" class="pf-btn btn-secondary" onclick="document.getElementById('form-add-proche').reset()"><?= tr('btn_cancel') ?></button>
<button type="submit" class="pf-btn pf-btn-primary"><?= tr('btn_add') ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
<script>
// ==========================================
// 1. GESTION DU COMPOSANT MULTI-SELECT VANILLA
// ==========================================
function toggleMS(listId, triggerEl) {
document.querySelectorAll('.pf-ms-dropdown').forEach(el => { if (el.id !== listId) el.classList.remove('open'); });
document.querySelectorAll('.pf-ms-trigger').forEach(el => { if (el !== triggerEl) el.classList.remove('active'); });
const list = document.getElementById(listId);
if (list) list.classList.toggle('open');
if (triggerEl) triggerEl.classList.toggle('active');
}
document.addEventListener('click', e => {
if (!e.target.closest('.pf-multi-select')) {
document.querySelectorAll('.pf-ms-dropdown').forEach(el => el.classList.remove('open'));
document.querySelectorAll('.pf-ms-trigger').forEach(el => el.classList.remove('active'));
}
});
function handleMSChange(cb, type) {
const container = document.getElementById('ms-' + type + '-list');
if (!container) return;
if (cb.value === 'all' && cb.checked) {
container.querySelectorAll('input[type="checkbox"]:not([value="all"])').forEach(i => i.checked = false);
} else if (cb.checked) {
const allCb = container.querySelector('input[value="all"]');
if (allCb) allCb.checked = false;
} else {
const checkedSpecifics = container.querySelectorAll('input[type="checkbox"]:checked:not([value="all"])');
if (checkedSpecifics.length === 0) {
const allCb = container.querySelector('input[value="all"]');
if (allCb) allCb.checked = true;
}
}
const checkedSpecifics = container.querySelectorAll('input[type="checkbox"]:checked:not([value="all"])');
const labelEl = document.getElementById('ms-' + type + '-label');
if (labelEl) {
if (checkedSpecifics.length === 0) {
let defaultText = 'Tous';
if (window.I18N) {
if (type === 'child' && window.I18N['gift_filter_all_children']) defaultText = window.I18N['gift_filter_all_children'];
if (type === 'adult' && window.I18N['gift_filter_all_adults']) defaultText = window.I18N['gift_filter_all_adults'];
}
labelEl.innerText = defaultText;
} else if (checkedSpecifics.length === 1) {
labelEl.innerText = checkedSpecifics[0].value;
} else {
labelEl.innerText = checkedSpecifics.length + ' sélections';
}
}
applyGiftFilters();
}
function applyGiftFilters() {
const cList = document.getElementById('ms-child-list');
const aList = document.getElementById('ms-adult-list');
if (!cList || !aList) return;
const allChildCb = cList.querySelector('input[value="all"]');
const cAll = allChildCb ? allChildCb.checked : true;
const cVals = Array.from(cList.querySelectorAll('input[type="checkbox"]:checked:not([value="all"])')).map(i => i.value);
const allAdultCb = aList.querySelector('input[value="all"]');
const aAll = allAdultCb ? allAdultCb.checked : true;
const aVals = Array.from(aList.querySelectorAll('input[type="checkbox"]:checked:not([value="all"])')).map(i => i.value);
document.querySelectorAll('.js-occ-section').forEach(occSec => {
let occHasVisible = false;
occSec.querySelectorAll('.js-child').forEach(childSec => {
const cName = childSec.getAttribute('data-name');
const matchChild = cAll || (cVals.indexOf(cName) !== -1);
let childHasVisibleCard = false;
if (matchChild) {
childSec.querySelectorAll('.js-gift-card').forEach(card => {
const aName = card.getAttribute('data-adult');
const matchAdult = aAll || (aVals.indexOf(aName) !== -1);
card.style.display = matchAdult ? 'flex' : 'none';
if (matchAdult) childHasVisibleCard = true;
});
childSec.querySelectorAll('.js-pill-adult').forEach(pill => {
const aName = pill.getAttribute('data-adult');
const matchAdult = aAll || (aVals.indexOf(aName) !== -1);
pill.style.opacity = matchAdult ? '1' : '0.2';
});
const empty = childSec.querySelector('.js-empty-state');
if (empty) empty.style.display = childHasVisibleCard ? 'none' : 'block';
childSec.style.display = 'block';
occHasVisible = true;
} else {
childSec.style.display = 'none';
}
});
occSec.style.display = occHasVisible ? 'block' : 'none';
});
}
// ==========================================
// 2. GESTION DE LA MODALE CADEAU (AJOUT/ÉDITION)
// ==========================================
const modal = document.getElementById('pf-gift-modal');
const adultSelect = document.getElementById('modalAdult');
const payerSelect = document.getElementById('modalPayer');
if (adultSelect && payerSelect) {
adultSelect.addEventListener('change', function() {
let exists = false;
for(let i = 0; i < payerSelect.options.length; i++) {
if(payerSelect.options[i].value === this.value) exists = true;
}
if (exists) payerSelect.value = this.value;
});
}
function populateSelects(adults) {
if (!adultSelect || !payerSelect) return;
adultSelect.innerHTML = '';
payerSelect.innerHTML = '';
adults.forEach(name => {
adultSelect.appendChild(new Option(name, name));
payerSelect.appendChild(new Option(name, name));
});
}
document.body.addEventListener('click', async function(e) {
if (e.target.closest('.btn-modal-close')) {
if (modal) {
modal.classList.remove('open');
document.body.classList.remove('no-scroll');
}
return;
}
const btnAdd = e.target.closest('.btn-add-gift');
if (btnAdd) {
const childName = btnAdd.dataset.child;
const occCode = btnAdd.dataset.occ;
const adultsList = JSON.parse(btnAdd.dataset.adults || '[]');
document.getElementById('modalAction').value = 'create';
document.getElementById('modalGiftId').value = '';
document.getElementById('modalChild').value = childName;
document.getElementById('modalOccasion').value = occCode;
document.getElementById('modalDesc').value = '';
document.getElementById('modalAmount').value = '';
document.getElementById('modalLink').value = '';
populateSelects(adultsList);
if (adultSelect && payerSelect) {
if (adultsList.indexOf('Laia') !== -1) {
adultSelect.value = 'Laia'; payerSelect.value = 'Laia';
} else if (adultsList.length > 0) {
adultSelect.value = adultsList[0]; payerSelect.value = adultsList[0];
}
}
const titleStr = window.I18N && window.I18N['gift_modal_title_add'] ? window.I18N['gift_modal_title_add'] : 'Ajouter pour %s';
document.getElementById('modalTitle').textContent = titleStr.replace('%s', childName);
if (modal) { modal.classList.add('open'); document.body.classList.add('no-scroll'); }
return;
}
const btnEdit = e.target.closest('.btn-edit-gift');
if (btnEdit) {
const data = JSON.parse(btnEdit.dataset.gift || '{}');
document.getElementById('modalAction').value = 'update';
document.getElementById('modalGiftId').value = data.id;
document.getElementById('modalChild').value = data.child_name;
document.getElementById('modalOccasion').value = data.occasion;
document.getElementById('modalDesc').value = data.gift_description;
document.getElementById('modalAmount').value = data.amount;
document.getElementById('modalLink').value = data.product_link;
const payerVal = data.payer_name || data.adult_name;
if (adultSelect && payerSelect) {
let adultExists = false, payerExists = false;
for(let i=0; i<adultSelect.options.length; i++) { if(adultSelect.options[i].value === data.adult_name) adultExists = true; }
for(let i=0; i<payerSelect.options.length; i++) { if(payerSelect.options[i].value === payerVal) payerExists = true; }
if (!adultExists) adultSelect.appendChild(new Option(data.adult_name, data.adult_name));
if (!payerExists) payerSelect.appendChild(new Option(payerVal, payerVal));
adultSelect.value = data.adult_name;
payerSelect.value = payerVal;
}
document.getElementById('modalTitle').textContent = window.I18N && window.I18N['gift_modal_title_edit'] ? window.I18N['gift_modal_title_edit'] : 'Modifier le cadeau';
if (modal) { modal.classList.add('open'); document.body.classList.add('no-scroll'); }
return;
}
const btnDel = e.target.closest('.btn-delete-gift');
if (btnDel) {
const giftId = btnDel.dataset.id;
const msg = window.I18N && window.I18N['gift_confirm_delete'] ? window.I18N['gift_confirm_delete'] : 'Supprimer ce cadeau ?';
if (!confirm(msg)) return;
const fd = new FormData();
fd.append('action', 'delete');
fd.append('gift_id', giftId);
try {
await fetch('/modules/gift-list/save-gift.php', { method: 'POST', body: fd });
window.location.reload();
} catch(err) {
console.error(err);
}
return;
}
});
const giftForm = document.getElementById('giftForm');
if (giftForm) {
giftForm.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = e.target.querySelector('button[type="submit"]');
const oldText = btn.innerText;
btn.innerText = '...';
btn.disabled = true;
try {
await fetch(e.target.getAttribute('action'), { method: 'POST', body: new FormData(e.target) });
window.location.reload();
} catch(err) {
console.error(err);
btn.innerText = oldText;
btn.disabled = false;
}
});
}
// ==========================================
// 3. GESTION DES PARAMÈTRES (MODALE FÊTES & PROCHES)
// ==========================================
function closeGiftSettings() {
document.getElementById('modal-gift-settings').classList.remove('open');
document.body.classList.remove('no-scroll');
}
document.getElementById('btn-open-gift-settings')?.addEventListener('click', async (e) => {
e.preventDefault();
document.getElementById('modal-gift-settings').classList.add('open');
document.body.classList.add('no-scroll');
await loadSettingsData();
});
document.querySelectorAll('.btn-close-settings').forEach(btn => btn.addEventListener('click', closeGiftSettings));
function switchGLTab(tabId) {
// Gestion du contenu (Afficher/Cacher)
document.getElementById('gl-pane-occasions').style.display = (tabId === 'occasions') ? 'block' : 'none';
document.getElementById('gl-pane-proches').style.display = (tabId === 'proches') ? 'block' : 'none';
// Gestion du style des boutons d'onglet
const btnOcc = document.getElementById('tab-btn-occasions');
const btnProche = document.getElementById('tab-btn-proches');
if (tabId === 'occasions') {
btnOcc.style.background = 'var(--bg-panel)';
btnOcc.style.color = 'var(--primary)';
btnOcc.style.boxShadow = 'var(--shadow-sm)';
btnProche.style.background = 'transparent';
btnProche.style.color = 'var(--text-muted)';
btnProche.style.boxShadow = 'none';
} else {
btnProche.style.background = 'var(--bg-panel)';
btnProche.style.color = 'var(--primary)';
btnProche.style.boxShadow = 'var(--shadow-sm)';
btnOcc.style.background = 'transparent';
btnOcc.style.color = 'var(--text-muted)';
btnOcc.style.boxShadow = 'none';
}
}
let hasSettingsChanged = false;
async function loadSettingsData() {
try {
const res = await pachaFetch('/modules/gift-list/api-settings.php?action=get_all');
if (!res.success) throw new Error(res.error);
renderOccasions(res.data.occasions);
renderProches(res.data.proches);
} catch (e) {
document.getElementById('occasions-list').innerHTML = `<div class="pf-alert pf-alert--error">Erreur : ${e.message}</div>`;
document.getElementById('proches-list').innerHTML = `<div class="pf-alert pf-alert--error">Erreur : ${e.message}</div>`;
}
}
function renderOccasions(occasions) {
const container = document.getElementById('occasions-list');
if (!occasions.length) { container.innerHTML = `<em class="gift-empty-state">Vide</em>`; return; }
let html = '';
occasions.forEach(occ => {
const isChecked = occ.is_active == 1 ? 'checked' : '';
// ⚠️ Remarque l'ajout de id="row-occ-${occ.id}" ici :
html += `
<div class="gl-list-item" id="row-occ-${occ.id}">
<div>
<span style="font-size:1.2rem; margin-right:8px;">${occ.icon || '🎁'}</span>
<strong>${occ.name}</strong>
<small style="color:var(--text-muted); margin-left:8px;">${occ.month_date || ''}</small>
</div>
<div class="pf-flex-gap-8 align-center">
<label style="display:flex; align-items:center; cursor:pointer;">
<input type="checkbox" class="pf-checkbox-lg" ${isChecked} onchange="toggleOccasion(${occ.id}, this.checked)">
</label>
<button type="button" class="btn-icon-action edit" onclick="transformRowToEditOccasion('row-occ-${occ.id}', ${occ.id}, '${occ.name.replace(/'/g, "\\'")}', '${occ.icon}', '${occ.month_date || ''}')" title="${tr('btn_edit')}">✏️</button>
<button type="button" class="btn-icon-action delete" onclick="deleteOccasion(${occ.id})" title="${tr('btn_delete')}">🗑️</button>
</div>
</div>
`;
});
container.innerHTML = html;
}
function renderProches(proches) {
const container = document.getElementById('proches-list');
if (!proches.length) { container.innerHTML = `<em class="gift-empty-state">Aucun proche configuré.</em>`; return; }
let html = '';
proches.forEach(p => {
const roleLabel = p.role === 'proche_adulte' ? (tr('gift_role_proche_adulte') || 'Adulte') : (tr('gift_role_proche_enfant') || 'Enfant');
html += `
<div class="gl-list-item" id="row-proche-${p.id}">
<div><strong>${p.name}</strong> <small style="color:var(--text-muted);">— ${roleLabel}</small></div>
<div class="pf-flex-gap-8 align-center">
<button type="button" class="btn-icon-action edit" onclick="transformRowToEditProche('row-proche-${p.id}', ${p.id}, '${p.name.replace(/'/g, "\\'")}', '${p.role}')" title="${tr('btn_edit')}">✏️</button>
<button type="button" class="btn-icon-action delete" onclick="deleteProche(${p.id})" title="${tr('btn_delete')}">🗑️</button>
</div>
</div>
`;
});
container.innerHTML = html;
}
// ==========================================
// CRUD : OCCASIONS
// ==========================================
// 1. Ajouter une occasion
document.getElementById('form-add-occasion')?.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = e.target.querySelector('button[type="submit"]');
btn.disabled = true;
hasSettingsChanged = true;
const fd = new FormData(e.target);
fd.append('action', 'save_occasion');
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
// On vide le formulaire
e.target.reset();
// On remet l'émoji par défaut visuellement
document.querySelectorAll('#form-add-occasion .emoji-option').forEach(el => el.classList.remove('selected'));
document.querySelector('#form-add-occasion .emoji-option').classList.add('selected');
document.getElementById('add-occ-icon').value = '🎁';
showToast("Fête ajoutée avec succès !", "success");
loadSettingsData(); // Recharge la liste
} catch (err) {
showToast("Erreur lors de l'ajout", "error");
console.error(err);
} finally {
btn.disabled = false;
}
});
// 2. Sauvegarder la modification (In-place)
async function saveInlineOccasion(id) {
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'save_occasion');
fd.append('id', id);
fd.append('icon', document.getElementById(`inline-occ-icon-${id}`).value);
fd.append('name', document.getElementById(`inline-occ-name-${id}`).value);
fd.append('month_date', document.getElementById(`inline-occ-date-${id}`).value);
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
showToast("Fête modifiée avec succès !", "success");
loadSettingsData();
} catch (err) {
showToast("Erreur lors de la modification", "error");
console.error(err);
}
}
// 3. Supprimer une occasion
async function deleteOccasion(id) {
if (!confirm(tr('confirm_delete') || 'Supprimer définitivement ?')) return;
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'delete_occasion');
fd.append('id', id);
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
showToast("Fête supprimée.", "success");
loadSettingsData();
} catch (err) {
showToast("Erreur lors de la suppression", "error");
}
}
// 4. Activer / Désactiver (Checkbox)
async function toggleOccasion(id, state) {
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'toggle_occasion');
fd.append('id', id);
fd.append('state', state ? 1 : 0);
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
showToast(state ? "Fête activée" : "Fête masquée", "success");
} catch (err) {
showToast("Erreur de mise à jour", "error");
}
}
// ==========================================
// CRUD : PROCHES
// ==========================================
// 1. Ajouter un proche
document.getElementById('form-add-proche')?.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = e.target.querySelector('button[type="submit"]');
btn.disabled = true;
hasSettingsChanged = true;
const fd = new FormData(e.target);
fd.append('action', 'save_proche');
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
e.target.reset();
showToast("Proche ajouté avec succès !", "success");
loadSettingsData();
} catch (err) {
showToast("Erreur lors de l'ajout", "error");
} finally {
btn.disabled = false;
}
});
// 2. Sauvegarder la modification (In-place)
async function saveInlineProche(id) {
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'save_proche');
fd.append('id', id);
fd.append('name', document.getElementById(`inline-proche-name-${id}`).value);
fd.append('role', document.getElementById(`inline-proche-role-${id}`).value);
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
showToast("Proche mis à jour !", "success");
loadSettingsData();
} catch (err) {
showToast("Erreur lors de la mise à jour", "error");
}
}
// 3. Supprimer un proche
async function deleteProche(id) {
if (!confirm(tr('confirm_delete') || 'Supprimer ce proche ?')) return;
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'delete_proche');
fd.append('id', id);
try {
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
showToast("Proche retiré de la liste.", "success");
loadSettingsData();
} catch (err) {
showToast("Erreur lors de la suppression", "error");
}
}
// Rechargement intelligent lors de la fermeture si modifications
document.getElementById('modal-gift-settings').addEventListener('click', (e) => {
if (e.target.id === 'modal-gift-settings' || e.target.classList.contains('btn-close-settings')) {
if (hasSettingsChanged) {
showToast(tr('gift_settings_saved') || 'Paramètres mis à jour !', 'success');
setTimeout(() => window.location.reload(), 1000);
} else {
closeGiftSettings();
}
}
});
// Fonction pour gérer la sélection dans la grille d'émojis (formulaire d'ajout)
function selectEmoji(element, targetInputId, emoji) {
document.getElementById(targetInputId).value = emoji;
// Mise à jour visuelle de la sélection
const siblings = element.parentNode.querySelectorAll('.emoji-option');
siblings.forEach(el => el.classList.remove('selected'));
element.classList.add('selected');
}
// ==========================================
// LOGIQUE D'ÉDITION IN-PLACE (OCCASIONS)
// ==========================================
// On crée une mémoire pour stocker le HTML d'origine de chaque ligne
const rowStates = {};
function transformRowToEditOccasion(rowId, id, name, icon, date) {
const row = document.getElementById(rowId);
// On sauvegarde l'état proprement en JS (fini les bugs d'affichage !)
rowStates[rowId] = row.innerHTML;
row.innerHTML = `
<div style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; background: var(--bg-subtle); padding: 8px; border-radius: 8px; border: 1px solid var(--border-light);">
<select id="inline-occ-icon-${id}" class="pf-input" style="width: 60px; padding: 6px; margin: 0;">
<option value="🎁" ${icon==='🎁'?'selected':''}>🎁</option>
<option value="🎄" ${icon==='🎄'?'selected':''}>🎄</option>
<option value="🎂" ${icon==='🎂'?'selected':''}>🎂</option>
<option value="🎉" ${icon==='🎉'?'selected':''}>🎉</option>
<option value="🎓" ${icon==='🎓'?'selected':''}>🎓</option>
</select>
<input type="text" id="inline-occ-name-${id}" value="${name}" class="pf-input" style="flex: 1; min-width: 100px; padding: 6px; margin: 0;">
<input type="text" id="inline-occ-date-${id}" value="${date}" class="pf-input" style="width: 70px; padding: 6px; margin: 0;" placeholder="MM-JJ">
<div style="display: flex; gap: 4px; margin-left: auto;">
<button type="button" onclick="saveInlineOccasion(${id})" class="pf-btn pf-btn-primary" style="padding: 6px 10px;">💾</button>
<button type="button" onclick="cancelInlineEdit('${rowId}')" class="pf-btn btn-secondary" style="padding: 6px 10px;">❌</button>
</div>
</div>
`;
}
async function saveInlineOccasion(id) {
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'save_occasion');
fd.append('id', id);
fd.append('icon', document.getElementById(`inline-occ-icon-${id}`).value);
fd.append('name', document.getElementById(`inline-occ-name-${id}`).value);
fd.append('month_date', document.getElementById(`inline-occ-date-${id}`).value);
// On met à jour en BDD puis on recharge la liste !
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
loadSettingsData();
}
// ==========================================
// LOGIQUE D'ÉDITION IN-PLACE (PROCHES)
// ==========================================
function transformRowToEditProche(rowId, id, name, role) {
const row = document.getElementById(rowId);
rowStates[rowId] = row.innerHTML;
const roleAdulte = window.I18N ? window.I18N['gift_role_proche_adulte'] : 'Adulte';
const roleEnfant = window.I18N ? window.I18N['gift_role_proche_enfant'] : 'Enfant';
row.innerHTML = `
<div style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; background: var(--bg-subtle); padding: 8px; border-radius: 8px; border: 1px solid var(--border-light);">
<input type="text" id="inline-proche-name-${id}" value="${name}" class="pf-input" style="flex: 1; min-width: 100px; padding: 6px; margin: 0;">
<select id="inline-proche-role-${id}" class="pf-input" style="width: 130px; padding: 6px; margin: 0;">
<option value="proche_adulte" ${role==='proche_adulte'?'selected':''}>${roleAdulte}</option>
<option value="proche_enfant" ${role==='proche_enfant'?'selected':''}>${roleEnfant}</option>
</select>
<div style="display: flex; gap: 4px; margin-left: auto;">
<button type="button" onclick="saveInlineProche(${id})" class="pf-btn pf-btn-primary" style="padding: 6px 10px;">💾</button>
<button type="button" onclick="cancelInlineEdit('${rowId}')" class="pf-btn btn-secondary" style="padding: 6px 10px;">❌</button>
</div>
</div>
`;
}
async function saveInlineProche(id) {
hasSettingsChanged = true;
const fd = new FormData();
fd.append('action', 'save_proche');
fd.append('id', id);
fd.append('name', document.getElementById(`inline-proche-name-${id}`).value);
fd.append('role', document.getElementById(`inline-proche-role-${id}`).value);
await pachaFetch('/modules/gift-list/api-settings.php', { method: 'POST', body: fd });
loadSettingsData();
}
// Fonction pour restaurer la ligne (sans casser le HTML)
function cancelInlineEdit(rowId) {
document.getElementById(rowId).innerHTML = rowStates[rowId];
}
</script>
<?php require __DIR__ . '/footer.php'; ?>
+1887
View File
File diff suppressed because it is too large. Load diff
+42
View File
@@ -0,0 +1,42 @@
<?php
require __DIR__ . '/includes/auth.php';
require_login();
require_once __DIR__ . '/includes/i18n.php';
$pageTitle = tr('mod_groceries_name') . ' — HouseHub';
$activePage = 'groceries';
require __DIR__ . '/header.php';
?>
<link rel="stylesheet" href="/modules/groceries/assets/groceries.css">
<div id="groceries-toasts" class="groceries-toast-container"></div>
<div class="groceries-layout">
<div class="groceries-hero">
<h1>🛒 <?= htmlspecialchars(tr('mod_groceries_name')) ?></h1>
<p><?= htmlspecialchars(tr('mod_groceries_desc')) ?></p>
<p id="groceries-subtitle" class="pf-muted-note" style="margin-top:0.5rem;font-size:0.85rem"></p>
</div>
<div class="groceries-add-card">
<div class="groceries-add-card-inner">
<div class="groceries-quick-add">
<input type="text" id="groceries-new" class="pf-input groceries-add-input" placeholder="<?= htmlspecialchars(tr('groceries_placeholder_add')) ?>" autocomplete="off" maxlength="500" aria-label="<?= htmlspecialchars(tr('groceries_placeholder_add')) ?>">
<button type="button" class="pf-btn groceries-add-submit" onclick="addFromInput()"><?= htmlspecialchars(tr('groceries_btn_add')) ?></button>
</div>
</div>
</div>
<div class="groceries-toolbar">
<button type="button" class="pf-btn btn-secondary groceries-toolbar-btn" onclick="uncheckAll()"><?= htmlspecialchars(tr('groceries_btn_uncheck_all')) ?></button>
<button type="button" class="pf-btn btn-secondary groceries-toolbar-btn groceries-toolbar-btn--danger" onclick="deletePicked()"><?= htmlspecialchars(tr('groceries_btn_delete_picked')) ?></button>
<button type="button" class="pf-btn btn-secondary groceries-toolbar-btn groceries-toolbar-btn--outline" onclick="clearWholeList()"><?= htmlspecialchars(tr('groceries_btn_clear_list')) ?></button>
</div>
<div id="groceries-lists"></div>
<div class="groceries-history-card" id="groceries-history-root" aria-live="polite"></div>
</div>
<script src="/modules/groceries/assets/groceries.js"></script>
<?php require __DIR__ . '/footer.php'; ?>
+240 -17
View File
@@ -1,29 +1,252 @@
<?php
if (!isset($pageTitle)) {
$pageTitle = "PachaFamily";
}
if (!isset($activePage)) {
$activePage = "";
if (session_status() === PHP_SESSION_NONE) session_start();
// 1. Inclusion du moteur de traduction
require_once __DIR__ . '/includes/i18n.php';
/**
* Génère une URL avec le paramètre de langue mis à jour
*/
function getLangUrl($newLang) {
$params = $_GET;
$params['lang'] = $newLang;
return '?' . http_build_query($params);
}
$pageTitle = $pageTitle ?? "HouseHub";
$activePage = $activePage ?? "";
$currentLang = $_SESSION['app_lang'] ?? 'fr';
?>
<!DOCTYPE html>
<html lang="fr">
<html lang="<?= htmlspecialchars($currentLang) ?>">
<head>
<meta charset="UTF-8" />
<title><?php echo htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8'); ?></title>
<link rel="stylesheet" href="/assets/css/style.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title><?= htmlspecialchars($pageTitle) ?></title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="apple-touch-icon" href="/favicon.png">
<link rel="stylesheet" href="/global.css">
<?php if (!empty($pageCss)): ?>
<link rel="stylesheet" href="<?= htmlspecialchars($pageCss) ?>">
<?php endif; ?>
<link rel="stylesheet" href="/dark-mode.css">
<script>(function(){const t=localStorage.getItem('hh-theme');if(t==='dark')document.documentElement.setAttribute('data-theme','dark');})()</script>
<style>
/* Patch CSS pour la zone droite de l'en-tête (Desktop / Mobile) */
.pf-header-right { display: flex; align-items: center; gap: 15px; }
@media (max-width: 768px) {
.pf-desktop-actions { display: none !important; }
}
</style>
</head>
<body>
<body data-page="<?= htmlspecialchars($activePage ?? '') ?>">
<header class="pf-header">
<div class="pf-container pf-header-content">
<div class="pf-logo">PachaFamily</div>
<a href="/index.php" class="pf-logo">HouseHub</a>
<?php if (isset($_SESSION['user'])): ?>
<?php $mods = $_SESSION['enabled_modules'] ?? ['calendar','budget','holidays','gifts','calendar_ios']; ?>
<nav class="pf-nav">
<a href="/index.php"
class="pf-nav-link <?php echo $activePage === 'home' ? 'pf-nav-link--active' : ''; ?>">Accueil</a>
<a href="/family-calendar.php"
class="pf-nav-link <?php echo $activePage === 'family-calendar' ? 'pf-nav-link--active' : ''; ?>">Family calendar</a>
<a href="/index.php" class="pf-nav-link <?= $activePage === 'home' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_home') ?></a>
<?php if (in_array('calendar', $mods)): ?><a href="/family-calendar.php" class="pf-nav-link <?= $activePage === 'family-calendar' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_calendar') ?></a><?php endif; ?>
<?php if (in_array('budget', $mods)): ?><a href="/budget.php" class="pf-nav-link <?= $activePage === 'budget' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_budget') ?></a><?php endif; ?>
<?php if (in_array('holidays', $mods)): ?><a href="/holidays.php" class="pf-nav-link <?= $activePage === 'holidays' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_holidays') ?></a><?php endif; ?>
<?php if (in_array('gifts', $mods)): ?><a href="/gift-list.php" class="pf-nav-link <?= $activePage === 'gift-list' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_gifts') ?></a><?php endif; ?>
<?php if (in_array('garage', $mods)): ?><a href="/garage.php" class="pf-nav-link <?= $activePage === 'garage' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_garage') ?></a><?php endif; ?>
<?php if (in_array('memo', $mods)): ?><a href="/memo.php" class="pf-nav-link <?= $activePage === 'memo' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_memo') ?></a><?php endif; ?>
<?php if (in_array('todo', $mods)): ?><a href="/todo.php" class="pf-nav-link <?= $activePage === 'todo' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_todo') ?></a><?php endif; ?>
<?php if (in_array('food', $mods)): ?><a href="/food.php" class="pf-nav-link <?= $activePage === 'food' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_food') ?></a><?php endif; ?>
<?php if (in_array('calendar_ios', $mods)): ?><a href="/calendar-ios.php" class="pf-nav-link <?= $activePage === 'calendar-ios' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_calendar_ios') ?></a><?php endif; ?>
<?php if (in_array('printvault', $mods)): ?><a href="/printvault.php" class="pf-nav-link <?= $activePage === 'printvault' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_printvault') ?></a><?php endif; ?>
<?php if (in_array('planka', $mods)): ?><a href="/planka.php" class="pf-nav-link <?= $activePage === 'planka' ? 'pf-nav-link--active' : '' ?>"><?= tr('menu_planka') ?></a><?php endif; ?>
</nav>
<?php endif; ?>
<div class="pf-header-right">
<button class="theme-switch" id="theme-toggle" onclick="toggleTheme()" title="Thème sombre / clair" aria-label="Basculer le thème">
<span class="ts-sun" aria-hidden="true">☀️</span>
<span class="ts-track"><span class="ts-thumb"></span></span>
<span class="ts-moon" aria-hidden="true">🌙</span>
</button>
<?php if (isset($_SESSION['user'])): ?>
<div class="pf-desktop-actions" style="display: flex; align-items: center; gap: 10px; border-left: 1px solid #cbd5e1; padding-left: 15px;">
<a href="/settings.php" class="pf-user-badge" style="text-decoration:none;color:inherit" title="Paramètres">
⚙️ <?= htmlspecialchars($_SESSION['user']['display_name'] ?? $_SESSION['user']['username']) ?>
</a>
<?php if (!empty($_SESSION['user']['is_admin'])): ?>
<a href="/admin/" class="pf-nav-link" style="font-size:0.85rem;color:#2563eb" title="Admin">Admin</a>
<?php endif; ?>
<a href="/logout.php" class="pf-logout-btn"><?= tr('btn_logout') ?></a>
</div>
<button class="pf-burger-btn" aria-label="<?= tr('aria_menu') ?>" style="margin-left: 5px;">☰</button>
<?php else: ?>
<a href="/login.php" class="pf-nav-link" style="border-left: 1px solid #cbd5e1; padding-left: 15px; margin-left: 5px;"><?= tr('btn_login') ?></a>
<?php endif; ?>
</div>
</header>
<main class="pf-container pf-main">
<?php if (isset($_SESSION['user'])): ?>
<div class="pf-mobile-overlay" id="mobileOverlay"></div>
<div class="pf-mobile-menu" id="mobileMenu">
<div class="pf-mobile-menu-header">
<span class="pf-logo">HouseHub</span>
<button class="pf-mobile-close-btn" id="closeMobileMenu">&times;</button>
</div>
<div class="pf-mobile-menu-body">
<a href="/index.php" class="pf-mobile-nav-link">🏠 <?= tr('menu_home') ?></a>
<a href="/family-calendar.php" class="pf-mobile-nav-link">📅 <?= tr('menu_calendar') ?></a>
<?php if (in_array('budget', $mods)): ?><a href="/budget.php" class="pf-mobile-nav-link">💰 <?= tr('menu_budget') ?></a><?php endif; ?>
<?php if (in_array('holidays', $mods)): ?><a href="/holidays.php" class="pf-mobile-nav-link">🏖️ <?= tr('menu_holidays') ?></a><?php endif; ?>
<?php if (in_array('gifts', $mods)): ?><a href="/gift-list.php" class="pf-mobile-nav-link">🎁 <?= tr('menu_gifts') ?></a><?php endif; ?>
<?php if (in_array('garage', $mods)): ?><a href="/garage.php" class="pf-mobile-nav-link">🚗 <?= tr('menu_garage') ?></a><?php endif; ?>
<?php if (in_array('memo', $mods)): ?><a href="/memo.php" class="pf-mobile-nav-link">📝 <?= tr('menu_memo') ?></a><?php endif; ?>
<?php if (in_array('todo', $mods)): ?><a href="/todo.php" class="pf-mobile-nav-link">✅ <?= tr('menu_todo') ?></a><?php endif; ?>
<?php if (in_array('food', $mods)): ?><a href="/food.php" class="pf-mobile-nav-link">🍳 <?= tr('menu_food') ?></a><?php endif; ?>
<?php if (in_array('calendar_ios', $mods)): ?><a href="/calendar-ios.php" class="pf-mobile-nav-link">📱 <?= tr('menu_calendar_ios') ?></a><?php endif; ?>
<?php if (in_array('printvault', $mods)): ?><a href="/printvault.php" class="pf-mobile-nav-link">🖨️ <?= tr('menu_printvault') ?></a><?php endif; ?>
<?php if (in_array('planka', $mods)): ?><a href="/planka.php" class="pf-mobile-nav-link">📋 <?= tr('menu_planka') ?></a><?php endif; ?>
<a href="/settings.php" class="pf-mobile-nav-link">⚙️ Paramètres</a>
<?php if (!empty($_SESSION['user']['is_admin'])): ?>
<a href="/admin/" class="pf-mobile-nav-link" style="color:#2563eb">🛡️ Admin</a>
<?php endif; ?>
<a href="/logout.php" class="pf-mobile-nav-link pf-mobile-logout" style="margin-top: auto;">🚪 <?= tr('btn_logout') ?></a>
</div>
</div>
<?php endif; ?>
<main class="pf-main<?= ($mainClass ?? '') ? ' '.htmlspecialchars($mainClass) : '' ?>">
<script>
// CSRF avant I18N : le parseur HTML coupe le script dès la séquence de fin de balise « script » (même dans un commentaire JS).
window.CSRF_TOKEN = "<?= htmlspecialchars(function_exists('csrf_token') ? csrf_token() : '', ENT_QUOTES, 'UTF-8') ?>";
/**
* Pont d'Internationalisation et Configuration
*/
window.I18N = <?php echo json_encode($current_translations_array ?? [], JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_UNESCAPED_UNICODE); ?>;
// ✅ Injection sécurisée
window.CONFIG = {
// Liste complète des profils de la famille (Membres, Nounou, Enfants)
PEOPLE: <?= isset($familyPeople) ? json_encode($familyPeople) : '[]' ?>,
// ID du user global connecté (pour savoir "qui" clique)
CURRENT_USER_ID: <?= isset($_SESSION['user_id']) ? (int)$_SESSION['user_id'] : 'null' ?>,
CURRENCY: '<?php echo defined('CURRENCY') ? CURRENCY : "€"; ?>',
ZONE_SCOLAIRE: '<?php echo defined('ZONE_SCOLAIRE') ? ZONE_SCOLAIRE : "C"; ?>'
};
function tr(key) {
return window.I18N[key] || key;
}
// Thème clair/sombre — état visuel géré entièrement par CSS via [data-theme="dark"]
function toggleTheme(){
const dark=document.documentElement.getAttribute('data-theme')==='dark';
document.documentElement.setAttribute('data-theme',dark?'light':'dark');
localStorage.setItem('hh-theme',dark?'light':'dark');
}
// Gestion du menu mobile (Off-Canvas Sidebar)
<?php if (isset($_SESSION['user'])): ?>
document.addEventListener('DOMContentLoaded', () => {
const burgerBtn = document.querySelector('.pf-burger-btn');
const mobileMenu = document.getElementById('mobileMenu');
const overlay = document.getElementById('mobileOverlay');
const closeBtn = document.getElementById('closeMobileMenu');
function openMenu() {
mobileMenu.classList.add('is-open');
overlay.classList.add('is-visible');
document.body.classList.add('no-scroll');
}
function closeMenu() {
mobileMenu.classList.remove('is-open');
overlay.classList.remove('is-visible');
document.body.classList.remove('no-scroll');
}
if(burgerBtn && mobileMenu && overlay && closeBtn) {
burgerBtn.addEventListener('click', openMenu);
closeBtn.addEventListener('click', closeMenu);
// Fermer le menu si on clique en dehors (sur l'overlay sombre)
overlay.addEventListener('click', closeMenu);
}
});
<?php endif; ?>
/**
* pachaFetch : Utilitaire de requête robuste
*/
async function pachaFetch(url, options = {}) {
const finalUrl = url.startsWith('/') ? url.substring(1) : url;
options.credentials = 'same-origin';
options.headers = {
...options.headers,
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
};
try {
const response = await fetch(finalUrl, options);
const rawText = await response.text();
try {
return JSON.parse(rawText);
} catch (jsonErr) {
console.error("Réponse corrompue (HTML reçu au lieu de JSON) :", rawText);
throw new Error("Erreur serveur : format JSON invalide.");
}
} catch (err) {
console.error(`Erreur pachaFetch [${finalUrl}] :`, err);
throw err;
}
}
/**
* UI Utility : Toasts (Notifications)
*/
function showToast(message, type = 'success') {
const toast = document.createElement('div');
toast.className = `pf-toast pf-toast--${type}`;
toast.innerHTML = message;
document.body.appendChild(toast);
// Animation et suppression
setTimeout(() => toast.classList.add('is-visible'), 100);
setTimeout(() => {
toast.classList.remove('is-visible');
setTimeout(() => toast.remove(), 300);
}, 3000);
}
/**
* UI Utility : Confirmation stylisée (Remplace confirm())
*/
async function pachaConfirm(title, message) {
return new Promise((resolve) => {
const modal = document.createElement('div');
modal.className = 'pf-modal open';
modal.innerHTML = `
<div class="pf-modal-content" style="max-width: 400px; align-self: center;">
<h3 style="margin-top:0;">${title}</h3>
<p style="color:var(--text-muted);">${message}</p>
<div class="modal-footer">
<button class="pf-btn btn-secondary" id="confirm-cancel">${tr('btn_cancel')}</button>
<button class="pf-btn" id="confirm-ok" style="background:var(--danger);">${tr('btn_delete')}</button>
</div>
</div>
`;
document.body.appendChild(modal);
document.getElementById('confirm-cancel').onclick = () => { modal.remove(); resolve(false); };
document.getElementById('confirm-ok').onclick = () => { modal.remove(); resolve(true); };
});
}
</script>
+51
View File
@@ -0,0 +1,51 @@
<?php
// holidays.php
require __DIR__ . '/includes/auth.php';
require_login('/login.php');
require __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/i18n.php'; // Toujours s'assurer de l'accès à tr()
if (session_status() === PHP_SESSION_NONE) { session_start(); }
// 1. On récupère la vue demandée (par défaut 'list')
$tab = $_GET['tab'] ?? 'list';
// 2. Configuration des variables pour le header (Titres traduits)
$pageTitle = ($tab === 'holiday_detail')
? tr('hdl_title_detail')
: tr('hdl_title_list');
$activePage = "holidays";
$mainClass = "pf-holidays";
$pageCss = "/modules/holidays/holidays.css";
require __DIR__ . '/header.php';
$stmtVehicles = $pdo->query("SELECT id, name FROM pf_vehicles ORDER BY name ASC");
$garageVehicles = $stmtVehicles->fetchAll(PDO::FETCH_ASSOC);
// 3. ROUTEUR DU MODULE VACANCES
if ($tab === 'holiday_detail' && isset($_GET['id'])) {
// Si on demande le détail ET qu'un ID est fourni
require __DIR__ . '/modules/holidays/views/detail.php';
} else {
// Vue par défaut : la liste des cartes
require __DIR__ . '/modules/holidays/views/list.php';
}
// 4. Inclusion des librairies globales du module (Flatpickr)
?>
<!-- Flatpickr (Vanilla JS Date Range) -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/dark.css" id="flatpickr-dark-theme" disabled>
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/fr.js"></script>
<script src="https://cdn.jsdelivr.net/npm/flatpickr/dist/l10n/cat.js"></script>
<?php
$jsPath = __DIR__ . '/modules/holidays/holidays.js';
$jsVersion = file_exists($jsPath) ? filemtime($jsPath) : time();
echo '<script src="/modules/holidays/holidays.js?v=' . $jsVersion . '"></script>';
require __DIR__ . '/footer.php';
+18
View File
@@ -0,0 +1,18 @@
<?php
require __DIR__ . '/includes/auth.php';
require_login();
$family_id = $_SESSION['user']['family_id'];
if (!$family_id) { http_response_code(404); exit; }
$file = null;
foreach (glob('/uploads/home_bg_' . $family_id . '.*') as $f) { $file = $f; break; }
if (!$file || !file_exists($file)) { http_response_code(404); exit; }
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
$mime = ['jpg'=>'image/jpeg','jpeg'=>'image/jpeg','png'=>'image/png','webp'=>'image/webp'][$ext] ?? 'image/jpeg';
header('Content-Type: ' . $mime);
header('Cache-Control: private, max-age=3600');
readfile($file);
+16028
View File
File diff suppressed because it is too large. Load diff
+8
View File
@@ -0,0 +1,8 @@
<?php
require_once __DIR__ . '/auth.php';
require_login();
if (empty($_SESSION['user']['is_admin'])) {
http_response_code(403);
die('<h1>403 — Accès réservé aux administrateurs</h1><a href="/">Retour</a>');
}
+108
View File
@@ -0,0 +1,108 @@
<?php
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
/**
* Vérifie qu'un utilisateur est connecté.
* Si non, le redirige vers la page de login avec ?redirect=URL_DEMANDEE
*
* @param string|null $loginPage URL de la page de login (par défaut /login.php)
*/
/**
* Vérifie qu'un utilisateur est connecté.
* Si non, le redirige vers la page de login avec ?redirect=URL_DEMANDEE
*
* @param string|null $loginPage URL de la page de login (par défaut /login.php)
*/
function require_login(?string $loginPage = '/login.php'): void
{
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// --- NOUVEAU : Auto-login via Cookie ---
if (empty($_SESSION['user']) && isset($_COOKIE['hh_remember'])) {
$cookieParts = explode(':', $_COOKIE['hh_remember']);
if (count($cookieParts) === 2) {
$cookieUserId = (int)$cookieParts[0];
$cookieToken = $cookieParts[1];
global $meta_pdo;
require_once __DIR__ . '/meta_db.php';
$stmt = $meta_pdo->prepare("
SELECT u.id, u.username, u.password_hash, u.display_name, u.family_id, u.is_admin, u.is_active, u.lang, u.remember_token,
f.db_name, f.is_active as family_active, f.enabled_modules
FROM users u
LEFT JOIN families f ON f.id = u.family_id
WHERE u.id = ?
");
$stmt->execute([$cookieUserId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// On vérifie que le token correspond au hash stocké
if ($user && $user['remember_token'] && hash_equals($user['remember_token'], hash('sha256', $cookieToken))) {
if ($user['is_active'] && (!$user['family_id'] || $user['family_active'])) {
// Connexion silencieuse réussie, on peuple la session
$_SESSION['user'] = [
'id' => (int)$user['id'],
'username' => $user['username'],
'display_name' => $user['display_name'],
'family_id' => (int)$user['family_id'],
'is_admin' => (bool)$user['is_admin'],
];
$_SESSION['family_db'] = $user['db_name'];
$_SESSION['app_lang'] = $user['lang'] ?? 'fr';
$_SESSION['enabled_modules'] = json_decode($user['enabled_modules'] ?? '["calendar","budget","holidays","gifts","calendar_ios"]', true);
}
}
}
}
// ---------------------------------------
if (empty($_SESSION['user'])) {
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) || (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)) {
header('Content-Type: application/json');
http_response_code(401);
echo json_encode(['success' => false, 'error' => 'Session expirée. Veuillez vous reconnecter.']);
exit;
}
$currentUrl = $_SERVER['REQUEST_URI'] ?? '/';
$redirectParam = urlencode($currentUrl);
$target = ($loginPage ?? '/login.php') . '?redirect=' . $redirectParam;
header('Location: ' . $target);
exit;
}
}
function csrf_token(): string
{
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
return $_SESSION['csrf_token'];
}
function verify_csrf(?string $token): bool
{
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if (empty($_SESSION['csrf_token']) || !$token) {
return false;
}
return hash_equals($_SESSION['csrf_token'], $token);
}
if (!isset($familyPeople) && !empty($family_id)) {
require_once __DIR__ . '/db.php';
$stmtPeople = $pdo->query("SELECT id, name, user_id FROM pf_people ORDER BY id ASC");
$familyPeople = $stmtPeople->fetchAll(PDO::FETCH_ASSOC);
}
+76
View File
@@ -0,0 +1,76 @@
<?php
/**
* Matériau de clé pour chiffrer les secrets (mot de passe d’app iCloud, etc.).
* Ordre de priorité :
* 1. Variable d’environnement APP_SECRET_KEY (recommandé en production)
* 2. Fichier data/.hh_app_secret (généré automatiquement au premier besoin si le dossier est inscriptible)
* 3. Dérivation stable depuis DB_PASS + DB_HOST (évite l’erreur si rien n’est configuré ; change si le mot de passe DB change)
*/
function hh_secret_key_material(): string
{
$fromEnv = trim((string) getenv('APP_SECRET_KEY'));
if ($fromEnv !== '') {
return $fromEnv;
}
$keyFile = dirname(__DIR__) . '/data/.hh_app_secret';
if (is_readable($keyFile)) {
$content = trim((string) file_get_contents($keyFile));
if ($content !== '' && strlen($content) >= 32) {
return $content;
}
}
$dir = dirname($keyFile);
if (!is_dir($dir)) {
@mkdir($dir, 0700, true);
}
if (is_dir($dir) && is_writable($dir)) {
try {
$material = bin2hex(random_bytes(32));
if (@file_put_contents($keyFile, $material, LOCK_EX) !== false) {
@chmod($keyFile, 0600);
return $material;
}
} catch (\Throwable $e) {
// continuer vers la dérivation
}
}
$dbPass = (string) (getenv('DB_PASS') ?: '');
$dbHost = (string) (getenv('DB_HOST') ?: '');
return 'hh-derived|' . $dbPass . '|' . $dbHost . '|HouseHub-calendar-ios-v1';
}
function hh_encryption_key(): string
{
return hash('sha256', hh_secret_key_material(), true);
}
function hh_encrypt_secret(string $plain): string
{
$key = hh_encryption_key();
$iv = random_bytes(16);
$cipher = openssl_encrypt($plain, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($cipher === false) {
throw new RuntimeException('Chiffrement impossible');
}
return base64_encode($iv . $cipher);
}
function hh_decrypt_secret(string $encrypted): string
{
$key = hh_encryption_key();
$raw = base64_decode($encrypted, true);
if ($raw === false || strlen($raw) <= 16) {
throw new RuntimeException('Secret invalide');
}
$iv = substr($raw, 0, 16);
$cipher = substr($raw, 16);
$plain = openssl_decrypt($cipher, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($plain === false) {
throw new RuntimeException('Déchiffrement impossible');
}
return $plain;
}
+27 -22
View File
@@ -1,27 +1,37 @@
<?php
// includes/db.php
if (file_exists(__DIR__ . '/config.php')) {
require_once __DIR__ . '/config.php';
}
// Activer erreurs
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Détection de l'environnement
$isLocal = (strpos($_SERVER['HTTP_HOST'] ?? 'localhost', 'localhost') !== false ||
strpos($_SERVER['HTTP_HOST'] ?? '', '127.0.0.1') !== false ||
strpos($_SERVER['HTTP_HOST'] ?? '', '::1') !== false);
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
if ($isLocal) {
// Configuration XAMPP local
$host = 'localhost';
$db = 'percolo314'; // Même nom que sur OVH pour simplifier
$user = 'root';
$pass = ''; // Généralement vide sur XAMPP
$envHost = getenv('DB_HOST');
// 1. Détection stricte de l'environnement
if ($envHost === 'househub-db') {
// Docker
$host = 'househub-db';
$user = getenv('DB_USER') ?: 'househub';
$pass = getenv('DB_PASS') ?: 'changeme';
} else {
// Configuration serveur OVH
$host = 'percolo314.mysql.db';
$db = 'percolo314';
$user = 'percolo314';
$pass = 'Wxcvbn99';
// XAMPP
$host = '127.0.0.1'; // Plus stable que 'localhost' sous XAMPP
$user = 'root';
$pass = '';
}
// 2. Multi-tenant strict : cibler la DB de la famille courante
$db = 'househub_meta'; // Fallback par défaut
if (!empty($_SESSION['user']['family_id'])) {
$db = 'househub_f' . (int)$_SESSION['user']['family_id'];
}
$charset = 'utf8mb4';
@@ -43,12 +53,7 @@ try {
$pdo->exec("SET collation_database = utf8mb4_general_ci");
$pdo->exec("SET collation_server = utf8mb4_general_ci");
// Debug optionnel (à commenter en production)
// $env = $isLocal ? 'LOCAL' : 'SERVEUR';
// echo "<!-- Connecté en $env sur $host/$db -->";
} catch (\PDOException $e) {
$environment = $isLocal ? 'local (XAMPP)' : 'serveur (OVH)';
die("Erreur de connexion ($environment) : " . $e->getMessage());
die("Erreur de connexion BDD (Host: $host, DB: $db) : " . $e->getMessage());
}
?>
+32
View File
@@ -0,0 +1,32 @@
<?php
// Démarrer la session si ce n'est pas déjà fait (souvent fait dans auth.php, mais on sécurise)
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// 1. Changement de langue si l'utilisateur a cliqué sur un drapeau
if (isset($_GET['lang']) && in_array($_GET['lang'], ['fr', 'ca', 'en'])) {
$_SESSION['app_lang'] = $_GET['lang'];
}
// 2. Langue par défaut = Français
$current_lang = $_SESSION['app_lang'] ?? 'fr';
// 3. Chargement du bon dictionnaire
$lang_file = __DIR__ . '/lang/' . $current_lang . '.php';
if (file_exists($lang_file)) {
$GLOBALS['translations'] = include $lang_file;
} else {
$GLOBALS['translations'] = [];
}
// 4. La fonction magique de traduction
// Si le mot existe dans le dictionnaire on l'affiche, sinon on affiche la clé par défaut
if (!function_exists('tr')) {
function tr($key) {
return $GLOBALS['translations'][$key] ?? $key;
}
}
// Export pour le client (header.php → window.I18N) : pachaConfirm, modules JS, etc.
$current_translations_array = $GLOBALS['translations'] ?? [];
+236
View File
@@ -0,0 +1,236 @@
<?php
/**
* Normalise le mot de passe d’application Apple (supprime les espaces, garde les tirets).
*/
function hh_normalize_apple_app_password(string $password): string
{
return preg_replace('/\s+/', '', trim($password));
}
function hh_caldav_url_is_icloud(string $url): bool
{
$h = strtolower((string) (parse_url(trim($url), PHP_URL_HOST) ?: ''));
return str_contains($h, 'icloud.com');
}
function hh_caldav_is_icloud_well_known_root(string $url): bool
{
$parts = parse_url(rtrim(trim($url), '/'));
if (empty($parts['scheme']) || empty($parts['host'])) {
return false;
}
$host = strtolower($parts['host']);
if ($host !== 'caldav.icloud.com') {
return false;
}
$path = $parts['path'] ?? '';
return $path === '' || $path === '/';
}
function hh_caldav_resolve_href(string $againstUrl, string $href): string
{
$href = trim($href);
if ($href === '') {
return $againstUrl;
}
if (str_starts_with($href, 'http://') || str_starts_with($href, 'https://')) {
return $href;
}
$parts = parse_url($againstUrl);
$scheme = $parts['scheme'] ?? 'https';
$host = $parts['host'] ?? '';
$port = isset($parts['port']) ? ':' . $parts['port'] : '';
if ($href[0] === '/') {
return $scheme . '://' . $host . $port . $href;
}
$base = preg_replace('#/[^/]*$#', '/', $againstUrl);
return rtrim($base, '/') . '/' . ltrim($href, '/');
}
/**
* @return array{code:int, body:string}
*/
function hh_caldav_propfind(string $url, string $username, string $password, string $xml, string $depth = '0'): array
{
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 25,
CURLOPT_CUSTOMREQUEST => 'PROPFIND',
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $username . ':' . $password,
CURLOPT_HTTPHEADER => [
'Content-Type: application/xml; charset=utf-8',
'Depth: ' . $depth,
],
CURLOPT_POSTFIELDS => $xml,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
]);
$body = curl_exec($ch);
$code = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($body === false) {
return ['code' => 0, 'body' => ''];
}
return ['code' => $code, 'body' => $body];
}
function hh_caldav_first_href_by_element(string $xml, string $parentLocalName): ?string
{
$dom = new DOMDocument();
if (!@$dom->loadXML($xml)) {
return null;
}
$xpath = new DOMXPath($dom);
$nodes = $xpath->query("//*[local-name()='{$parentLocalName}']//*[local-name()='href']");
if ($nodes->length === 0) {
return null;
}
return trim($nodes->item(0)->textContent);
}
/**
* @return list<array{href:string, display:string}>
*/
function hh_caldav_parse_calendar_collections(string $xml): array
{
$dom = new DOMDocument();
if (!@$dom->loadXML($xml)) {
return [];
}
$xpath = new DOMXPath($dom);
$responses = $xpath->query("//*[local-name()='response']");
$out = [];
foreach ($responses as $resp) {
$hrefNodes = $xpath->query(".//*[local-name()='href']", $resp);
if ($hrefNodes->length === 0) {
continue;
}
$href = trim($hrefNodes->item(0)->textContent);
$cal = $xpath->query(".//*[local-name()='resourcetype']/*[local-name()='calendar']", $resp);
if ($cal->length === 0 || $href === '') {
continue;
}
$display = '';
$dn = $xpath->query(".//*[local-name()='displayname']", $resp);
if ($dn->length > 0) {
$display = trim($dn->item(0)->textContent);
}
$out[] = ['href' => $href, 'display' => $display];
}
return $out;
}
/**
* Liste les collections calendrier iCloud (URL complète avec / final + nom affiché).
*
* @return list<array{display:string, url:string}>
*
* @throws RuntimeException
*/
function hh_icloud_discover_calendar_entries(string $username, string $password): array
{
$password = hh_normalize_apple_app_password($password);
$root = 'https://caldav.icloud.com/';
$xml1 = '<?xml version="1.0" encoding="UTF-8"?>'
. '<propfind xmlns="DAV:">'
. '<prop><current-user-principal/></prop>'
. '</propfind>';
$r1 = hh_caldav_propfind($root, $username, $password, $xml1, '0');
if ($r1['code'] === 401 || $r1['code'] === 403) {
throw new RuntimeException('Identifiant Apple ou mot de passe d’app refusé (HTTP ' . $r1['code'] . ').');
}
if (!in_array($r1['code'], [200, 207], true)) {
throw new RuntimeException('CalDAV racine inaccessible (HTTP ' . $r1['code'] . ').');
}
$principalHref = hh_caldav_first_href_by_element($r1['body'], 'current-user-principal');
if (!$principalHref) {
throw new RuntimeException('Réponse CalDAV inattendue : principal introuvable.');
}
$principalUrl = hh_caldav_resolve_href($root, $principalHref);
$xml2 = '<?xml version="1.0" encoding="UTF-8"?>'
. '<propfind xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">'
. '<prop><C:calendar-home-set/></prop>'
. '</propfind>';
$r2 = hh_caldav_propfind($principalUrl, $username, $password, $xml2, '0');
if (!in_array($r2['code'], [200, 207], true)) {
throw new RuntimeException('Lecture du principal CalDAV impossible (HTTP ' . $r2['code'] . ').');
}
$homeHref = hh_caldav_first_href_by_element($r2['body'], 'calendar-home-set');
if (!$homeHref) {
throw new RuntimeException('Aucun dossier de calendriers (calendar-home-set) trouvé.');
}
$homeUrl = hh_caldav_resolve_href($principalUrl, $homeHref);
$xml3 = '<?xml version="1.0" encoding="UTF-8"?>'
. '<propfind xmlns="DAV:">'
. '<prop><resourcetype/><displayname/></prop>'
. '</propfind>';
$r3 = hh_caldav_propfind($homeUrl, $username, $password, $xml3, '1');
if (!in_array($r3['code'], [200, 207], true)) {
throw new RuntimeException('Liste des calendriers impossible (HTTP ' . $r3['code'] . ').');
}
$raw = hh_caldav_parse_calendar_collections($r3['body']);
if ($raw === []) {
throw new RuntimeException('Aucun calendrier trouvé sur ce compte iCloud.');
}
$out = [];
foreach ($raw as $e) {
$url = rtrim(hh_caldav_resolve_href($homeUrl, $e['href']), '/') . '/';
$out[] = ['display' => $e['display'], 'url' => $url];
}
return $out;
}
/**
* Depuis la racine iCloud (https://caldav.icloud.com), découvre l’URL d’un calendrier (par défaut « Calendar » / « Calendrier », sinon le premier).
*
* @throws RuntimeException
*/
function hh_icloud_discover_default_calendar_url(string $username, string $password): string
{
$entries = hh_icloud_discover_calendar_entries($username, $password);
$preferred = ['calendar', 'calendrier', 'home', 'par défaut', 'default'];
foreach ($entries as $e) {
$lower = mb_strtolower($e['display']);
foreach ($preferred as $p) {
if ($lower !== '' && str_contains($lower, $p)) {
return $e['url'];
}
}
}
return $entries[0]['url'];
}
/**
* Vérifie qu’une URL de collection calendrier répond en CalDAV (PROPFIND).
*/
function hh_caldav_test_calendar_collection(string $username, string $password, string $calendarUrl): int
{
$password = hh_normalize_apple_app_password($password);
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
. '<propfind xmlns="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">'
. '<prop><resourcetype/><displayname/><C:supported-calendar-component-set/></prop>'
. '</propfind>';
$r = hh_caldav_propfind(rtrim($calendarUrl, '/') . '/', $username, $password, $xml, '0');
return $r['code'];
}
/**
* Si URL = racine iCloud bien connue, découvre et retourne l’URL d’un calendrier ; sinon retourne l’URL telle quelle (trim).
*
* @throws RuntimeException
*/
function hh_icloud_resolve_calendar_url_if_needed(string $username, string $password, string $calendarUrl): string
{
$calendarUrl = trim($calendarUrl);
if (hh_caldav_is_icloud_well_known_root($calendarUrl)) {
return hh_icloud_discover_default_calendar_url($username, $password);
}
return $calendarUrl;
}
+1026
View File
File diff suppressed because it is too large. Load diff
+1029
View File
File diff suppressed because it is too large. Load diff
+1025
View File
File diff suppressed because it is too large. Load diff
+37
View File
@@ -0,0 +1,37 @@
<?php
// includes/meta_db.php
// Connexion à la base meta (gestion des familles et utilisateurs)
$envHost = getenv('DB_HOST');
// Détection stricte : Docker injecte toujours 'househub-db' via le docker-compose
if ($envHost === 'househub-db') {
// Environnement Docker (Ton collègue ou la Prod)
$meta_host = 'househub-db';
$meta_user = getenv('DB_USER') ?: 'househub';
$meta_pass = getenv('DB_PASS') ?: 'changeme';
} else {
// Environnement Local XAMPP (Toi)
$meta_host = '127.0.0.1'; // Plus stable que 'localhost' sous XAMPP
$meta_user = 'root';
$meta_pass = '';
}
$meta_db = 'househub_meta';
try {
$meta_pdo = new PDO(
"mysql:host=$meta_host;dbname=$meta_db;charset=utf8mb4",
$meta_user,
$meta_pass,
[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4 COLLATE utf8mb4_general_ci",
]
);
} catch (\PDOException $e) {
die(json_encode(['error' => 'Meta DB unavailable: ' . $e->getMessage()]));
}
?>
-18
View File
@@ -1,18 +0,0 @@
<?php
$pageTitle = "PachaFamily - Accueil";
$activePage = "home";
require __DIR__ . '/header.php';
?>
<h1>Bienvenue sur PachaFamily</h1>
<p>Centre de controle de l'organisation familiale.</p>
<section class="pf-section">
<h2>Modules</h2>
<ul>
<li><a href="/family-calendar.php">Family calendar (conges, vacances, garde)</a></li>
</ul>
</section>
<?php
require __DIR__ . '/footer.php';
+146
View File
@@ -0,0 +1,146 @@
<?php
// Protection de la page : nécessite d'être connecté
require __DIR__ . '/includes/auth.php';
require_login('/login.php');
// Inclusion i18n (déjà fait dans header, mais par sécurité si besoin de tr() avant)
require_once __DIR__ . '/includes/i18n.php';
// Configuration de la page
$pageTitle = tr('home_title');
$activePage = "home";
// background géré par home.css via body[data-page="home"]
$pageCss = "/modules/home/home.css";
require __DIR__ . '/header.php';
// Override background si image personnalisée uploadée
$_fid = $_SESSION['user']['family_id'] ?? null;
$_has_custom_bg = false;
if ($_fid) {
foreach (glob('/uploads/home_bg_' . $_fid . '.*') as $_f) { $_has_custom_bg = true; break; }
}
if ($_has_custom_bg): ?>
<style>body[data-page="home"] { background-image: url('/home-bg.php?v=<?= filemtime($_f) ?>'); }</style>
<?php endif; ?>
<div class="pf-container">
<div class="pf-hero">
<h1><?= tr('home_welcome') ?></h1>
<p><?= tr('home_subtitle') ?></p>
<?php if (isset($_SESSION['user'])): ?>
<div class="pf-user-info" style="margin-top: 12px; font-weight: 500;">
<?= tr('home_logged_as') ?>
<strong><?= htmlspecialchars($_SESSION['user']['display_name'] ?? $_SESSION['user']['username']) ?></strong>
</div>
<?php endif; ?>
</div>
<section class="pf-section">
<h2 style="color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,0.6);"><?= tr('home_modules_title') ?></h2>
<?php $mods = $_SESSION['enabled_modules'] ?? ['calendar','budget','holidays','gifts','food','garage','calendar_ios']; ?>
<div class="pf-modules-grid">
<?php if (in_array('calendar', $mods)): ?>
<a href="/family-calendar.php" class="pf-module-card">
<div class="pf-card-icon">📅</div>
<h3 class="pf-card-title"><?= tr('mod_calendar_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_calendar_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_open') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('budget', $mods)): ?>
<a href="/budget.php" class="pf-module-card">
<div class="pf-card-icon">💰</div>
<h3 class="pf-card-title"><?= tr('mod_budget_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_budget_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_manage') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('holidays', $mods)): ?>
<a href="/holidays.php" class="pf-module-card">
<div class="pf-card-icon">🏖️</div>
<h3 class="pf-card-title"><?= tr('mod_holidays_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_holidays_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_explore') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('gifts', $mods)): ?>
<a href="/gift-list.php" class="pf-module-card">
<div class="pf-card-icon">🎁</div>
<h3 class="pf-card-title"><?= tr('mod_gifts_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_gifts_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_view_lists') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('garage', $mods)): ?>
<a href="/garage.php" class="pf-module-card">
<div class="pf-card-icon">🚗</div>
<h3 class="pf-card-title"><?= tr('mod_garage_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_garage_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_service') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('food', $mods)): ?>
<a href="/food.php" class="pf-module-card">
<div class="pf-card-icon">🍳</div>
<h3 class="pf-card-title"><?= tr('mod_food_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_food_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_food') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('memo', $mods)): ?>
<a href="/memo.php" class="pf-module-card">
<div class="pf-card-icon">📝</div>
<h3 class="pf-card-title"><?= tr('mod_memo_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_memo_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_jot') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('todo', $mods)): ?>
<a href="/todo.php" class="pf-module-card">
<div class="pf-card-icon">✅</div>
<h3 class="pf-card-title"><?= tr('mod_todo_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_todo_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_check') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('calendar_ios', $mods)): ?>
<a href="/calendar-ios.php" class="pf-module-card">
<div class="pf-card-icon">📱</div>
<h3 class="pf-card-title"><?= tr('mod_calendar_ios_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_calendar_ios_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_sync') ?></span>
</a>
<?php endif; ?>
<?php if (in_array('printvault', $mods)): ?>
<a href="/printvault.php" class="pf-module-card">
<div class="pf-card-icon">🖨️</div>
<h3 class="pf-card-title"><?= tr('mod_printvault_name') ?></h3>
<div class="pf-card-desc"><?= tr('mod_printvault_desc') ?></div>
<span class="pf-card-cta"><?= tr('cta_print') ?></span>
</a>
<?php endif; ?>
</div>
</section>
</div>
<?php
require __DIR__ . '/footer.php';
?>
+129
View File
@@ -0,0 +1,129 @@
<?php
session_start();
require_once __DIR__ . '/includes/i18n.php';
require_once __DIR__ . '/includes/meta_db.php';
require_once __DIR__ . '/includes/auth.php';
$pageTitle = tr('login_title');
$activePage = "login";
if (isset($_SESSION['user'])) {
header('Location: /index.php');
exit;
}
$error = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!verify_csrf($_POST['csrf_token'] ?? null)) {
$error = "Session invalide (CSRF). Rechargez la page.";
} else {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
if (!$username || !$password) {
$error = tr('error_missing_fields');
} else {
$stmt = $meta_pdo->prepare("
SELECT u.id, u.username, u.password_hash, u.display_name, u.family_id, u.is_admin, u.is_active, u.lang,
f.db_name, f.is_active as family_active, f.enabled_modules
FROM users u
LEFT JOIN families f ON f.id = u.family_id
WHERE u.username = ?
");
$stmt->execute([$username]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($password, $user['password_hash'])) {
if (!$user['is_active']) {
$error = "Compte désactivé. Contactez l'administrateur.";
} elseif ($user['family_id'] && !$user['family_active']) {
$error = "Espace familial désactivé. Contactez l'administrateur.";
} else {
session_regenerate_id(true);
$_SESSION['user'] = [
'id' => (int)$user['id'],
'username' => $user['username'],
'display_name' => $user['display_name'],
'family_id' => (int)$user['family_id'],
'is_admin' => (bool)$user['is_admin'],
];
$_SESSION['family_db'] = $user['db_name'];
$_SESSION['app_lang'] = $user['lang'] ?? 'fr';
$_SESSION['enabled_modules'] = json_decode($user['enabled_modules'] ?? '["calendar","budget","holidays","gifts","calendar_ios"]', true);
// --- NOUVEAU : Logique "Se souvenir de moi" ---
if (isset($_POST['remember_me']) && $_POST['remember_me'] === '1') {
$token = bin2hex(random_bytes(32)); // Token aléatoire sécurisé
$hashedToken = hash('sha256', $token); // On stocke le hash en BDD
$meta_pdo->prepare("UPDATE users SET remember_token = ? WHERE id = ?")->execute([$hashedToken, $user['id']]);
// Création du cookie sécurisé (Expire dans 30 jours, HTTPOnly)
$cookieValue = $user['id'] . ':' . $token;
setcookie('hh_remember', $cookieValue, time() + (86400 * 30), '/', '', isset($_SERVER['HTTPS']), true);
}
// ----------------------------------------------
$redirectTo = $_GET['redirect'] ?? '/index.php';
header('Location: ' . $redirectTo);
exit;
}
} else {
$error = tr('error_invalid_credentials');
}
}
}
}
require __DIR__ . '/header.php';
?>
<div class="pf-container pf-login-wrapper">
<div class="pf-login-card">
<header class="pf-login-header">
<img src="/favicon.png" alt="HouseHub Logo" class="pf-login-icon">
<h1><?= tr('login_header') ?></h1>
<p><?= tr('login_subtitle') ?></p>
</header>
<?php if ($error): ?>
<div class="pf-login-error">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="post" action="/login.php<?= isset($_GET['redirect']) ? '?redirect=' . urlencode($_GET['redirect']) : '' ?>">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token()) ?>">
<div class="pf-form-group">
<label class="pf-label" for="username"><?= tr('label_username') ?></label>
<input type="text" id="username" name="username" class="pf-input"
required autofocus placeholder="<?= tr('placeholder_username') ?>"
autocomplete="username" autocapitalize="none">
</div>
<div class="pf-form-group">
<label class="pf-label" for="password"><?= tr('label_password') ?></label>
<input type="password" id="password" name="password" class="pf-input"
required placeholder="••••••" autocomplete="current-password">
</div>
<div class="pf-form-group" style="display: flex; align-items: center; gap: 8px;">
<input type="checkbox" id="remember_me" name="remember_me" value="1" class="pf-checkbox-lg">
<label class="pf-label" for="remember_me" style="margin: 0; cursor: pointer;"><?= tr('login_remember_me') ?? 'Se souvenir de moi' ?></label>
</div>
<button type="submit" class="pf-btn pf-btn-block">
<?= tr('btn_login_submit') ?>
</button>
</form>
<p style="text-align:center;margin-top:20px;font-size:0.9rem;color:#64748b">
Pas encore de compte ? <a href="/register.php" style="color:var(--primary)">Créer un espace</a>
</p>
</div>
</div>
<?php require __DIR__ . '/footer.php'; ?>
+40
View File
@@ -0,0 +1,40 @@
<?php
session_start();
// --- NOUVEAU : Révocation du "Se souvenir de moi" ---
if (isset($_SESSION['user']['id'])) {
require_once __DIR__ . '/includes/meta_db.php';
// On invalide le token en base de données
$stmt = $meta_pdo->prepare("UPDATE users SET remember_token = NULL WHERE id = ?");
$stmt->execute([$_SESSION['user']['id']]);
}
// On détruit le cookie côté navigateur
if (isset($_COOKIE['hh_remember'])) {
setcookie('hh_remember', '', time() - 3600, '/', '', isset($_SERVER['HTTPS']), true);
}
// ----------------------------------------------------
// On vide toutes les variables de session
$_SESSION = [];
// On détruit la session
session_destroy();
// Optionnel : supprimer le cookie de session (plus propre)
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params["path"],
$params["domain"],
$params["secure"],
$params["httponly"]
);
}
// On renvoie vers la page de login
header('Location: /login.php');
exit;
+139
View File
@@ -0,0 +1,139 @@
<?php
require __DIR__ . '/includes/auth.php';
require_login();
require_once __DIR__ . '/includes/i18n.php';
$pageTitle = 'Notes — HouseHub';
$activePage = 'memo';
require __DIR__ . '/header.php';
?>
<link rel="stylesheet" href="/modules/memo/assets/memo.css">
<div id="memo-toasts" class="memo-toast-container"></div>
<div class="memo-layout">
<!-- ── SIDEBAR ────────────────────────────────────────────────────────────── -->
<aside class="memo-sidebar" id="memo-sidebar">
<div class="memo-sidebar-top">
<button class="btn btn-primary" onclick="openCreate()" style="width:100%;justify-content:center">+ Nouvelle note</button>
<div class="memo-search">
<span style="color:var(--text-muted);font-size:.9rem">🔍</span>
<input type="text" id="memo-search-input" placeholder="Rechercher…">
</div>
</div>
<div class="memo-tags-list" id="memo-tags-list"></div>
</aside>
<!-- ── MAIN ───────────────────────────────────────────────────────────────── -->
<div class="memo-main">
<!-- Page : liste ─────────────────────────────────────────────────────── -->
<div id="memo-page-list" class="memo-page active">
<div class="memo-list-header">
<div>
<div id="memo-list-title" style="font-size:1rem;font-weight:700">📝 Notes</div>
<div id="memo-list-subtitle" class="memo-list-subtitle"></div>
</div>
<button class="btn btn-primary btn-sm" onclick="openCreate()">+ Nouvelle note</button>
</div>
<div id="memo-notes-grid" class="notes-grid"></div>
<div id="memo-pagination" style="display:flex;justify-content:space-between;align-items:center;padding:0 1.5rem 1.5rem;gap:.5rem"></div>
</div>
<!-- Page : vue note ──────────────────────────────────────────────────── -->
<div id="memo-page-view" class="memo-page">
<div class="memo-view-header">
<div class="memo-view-title" id="view-title"></div>
<div class="memo-view-meta">
<div id="view-tags" style="display:flex;gap:.35rem;flex-wrap:wrap"></div>
<span id="view-date" style="margin-left:auto"></span>
<div class="memo-view-actions">
<button class="btn btn-secondary btn-sm" onclick="loadList(currentQ,currentTag)">← Retour</button>
<button class="btn btn-secondary btn-sm" onclick="openEdit(currentNoteId)">✏️ Modifier</button>
<button class="btn btn-danger btn-sm" onclick="deleteNote(currentNoteId)">🗑️</button>
</div>
</div>
</div>
<div class="memo-content-area">
<div class="md-body" id="view-md"></div>
</div>
<div class="memo-attachments" id="view-attachments" style="display:none"></div>
</div>
<!-- Page : édition ───────────────────────────────────────────────────── -->
<div id="memo-page-edit" class="memo-page">
<div class="memo-edit-area">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:1.1rem;flex-wrap:wrap;gap:.5rem">
<h2 id="edit-page-title" style="font-size:1rem;font-weight:700;margin:0">Nouvelle note</h2>
<div style="display:flex;gap:.5rem">
<button class="btn btn-secondary" onclick="currentNoteId?viewNote(currentNoteId):loadList()">Annuler</button>
<button class="btn btn-primary" onclick="saveNote()">💾 Enregistrer</button>
</div>
</div>
<div class="memo-edit-form">
<!-- Titre -->
<div class="form-group">
<label class="form-label">Titre *</label>
<input type="text" id="edit-title" class="form-control" placeholder="Titre de la note…" required>
</div>
<!-- Contenu + preview -->
<div class="form-group">
<label class="form-label">Contenu <span style="font-size:.72rem;color:var(--text-muted)">(Markdown supporté)</span></label>
<div class="edit-split">
<textarea id="edit-content" class="form-control edit-textarea" placeholder="Écrivez ici en Markdown…"></textarea>
<div class="md-preview-box md-body" id="md-live-preview" style="min-height:320px"></div>
</div>
</div>
<!-- Tags -->
<div class="form-group">
<label class="form-label">Tags</label>
<div class="tags-input-wrap" onclick="document.getElementById('edit-tags-input').focus()">
<div id="edit-tags-chips" style="display:contents"></div>
<input type="text" id="edit-tags-input" placeholder="Ajouter un tag…" autocomplete="off">
</div>
<div style="font-size:.75rem;color:var(--text-muted);margin-top:.25rem">Appuyez sur Entrée ou virgule pour valider</div>
</div>
<!-- Fichiers -->
<div class="form-group">
<label class="form-label">Fichiers & Images</label>
<div id="edit-drop-zone" class="attach-drop">
📎 Glissez-déposez des fichiers ou cliquez pour choisir (images, PDF…)
<input type="file" id="edit-file-input" multiple accept="image/*,.pdf,.doc,.docx,.txt,.csv,.zip" style="display:none">
</div>
<div id="edit-attach-preview" class="attach-preview-list"></div>
<div id="edit-existing-attachments" style="margin-top:.75rem"></div>
</div>
<!-- URLs -->
<div class="form-group">
<label class="form-label">Liens / URLs</label>
<div id="edit-url-rows"></div>
</div>
</div>
</div>
</div>
</div><!-- memo-main -->
</div><!-- memo-layout -->
<!-- Lightbox -->
<div id="memo-lightbox" class="lightbox">
<img src="" alt="" onclick="event.stopPropagation()">
</div>
<!-- marked.js pour le rendu Markdown -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script>
if(window.marked){
marked.setOptions({breaks:true,gfm:true});
}
</script>
<script src="/modules/memo/assets/memo.js"></script>
<?php require __DIR__ . '/footer.php'; ?>
+81
View File
@@ -0,0 +1,81 @@
<?php
// migrate.php
require __DIR__ . '/includes/auth.php';
require __DIR__ . '/includes/meta_db.php';
require_login();
if (empty($_SESSION['user']['is_admin'])) {
die("Accès refusé. Droits administrateur requis.");
}
try {
$stmt = $meta_pdo->query("SELECT db_name FROM families");
$families = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($families as $fam) {
$dbName = $fam['db_name'];
echo "Migration de la base : $dbName ... <br>";
// --- DÉBUT DU BLOC MODIFIÉ ---
$envHost = getenv('DB_HOST');
if ($envHost === 'househub-db') {
$host = 'househub-db';
$user = getenv('DB_USER') ?: 'househub';
$pass = getenv('DB_PASS') ?: 'changeme';
} else {
$host = '127.0.0.1';
$user = 'root';
$pass = '';
}
$familyPdo = new PDO(
"mysql:host=$host;dbname=$dbName;charset=utf8mb4",
$user,
$pass,
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
// --- FIN DU BLOC MODIFIÉ ---
$sql = "
CREATE TABLE IF NOT EXISTS pf_meals_plan (
id INT AUTO_INCREMENT PRIMARY KEY,
plan_date DATE NOT NULL,
service ENUM('lunch', 'dinner') NOT NULL,
person_id INT NOT NULL,
meal_name VARCHAR(500) DEFAULT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_meal_plan (plan_date, service, person_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
";
$familyPdo->exec($sql);
echo "✅ Table pf_meals_plan créée pour $dbName.<br>";
}
echo "<br>🎉 Migration terminée avec succès.";
// À ajouter dans migrate.php
echo "Migration : Ajout des colonnes dynamiques au Budget...\n";
$stmtFam = $meta_pdo->query("SELECT id, db_name FROM families");
$families = $stmtFam->fetchAll(PDO::FETCH_ASSOC);
foreach ($families as $fam) {
$dbName = $fam['db_name'];
try {
$famPdo = new PDO("mysql:host=$meta_host;dbname=$dbName;charset=utf8mb4", $meta_user, $meta_pass, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
// Vérification si la colonne n'existe pas déjà
$checkCol = $famPdo->query("SHOW COLUMNS FROM pf_budget_items LIKE 'is_dynamic'");
if ($checkCol->rowCount() == 0) {
$famPdo->exec("ALTER TABLE pf_budget_items
ADD COLUMN is_dynamic TINYINT(1) DEFAULT 0 AFTER is_estimate,
ADD COLUMN dynamic_code VARCHAR(50) DEFAULT NULL AFTER is_dynamic");
echo "Famille {$fam['id']} ($dbName) : Colonnes is_dynamic et dynamic_code ajoutées.\n";
}
} catch (\PDOException $e) {
echo "Erreur sur la famille {$fam['id']} ($dbName) : " . $e->getMessage() . "\n";
}
}
} catch (Exception $e) {
die("❌ Erreur lors de la migration : " . $e->getMessage());
}
+626
View File
@@ -0,0 +1,626 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>HouseHub - Planning Repas</title>
<style>
/* --- VARIABLES --- */
:root {
--primary: #3b82f6;
--bg-page: #f8fafc;
--bg-panel: #ffffff;
--bg-subtle: #f1f5f9;
--text-main: #0f172a;
--text-muted: #64748b;
--border-light: #e2e8f0;
--border-strong: #cbd5e1;
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
--shadow-lg: 0 -4px 20px rgba(0, 0, 0, 0.15);
--alert-success-bg: #dcfce7;
}
body {
font-family:
"Inter",
-apple-system,
sans-serif;
background: var(--bg-page);
color: var(--text-main);
margin: 0;
padding: 10px;
overscroll-behavior-y: none;
padding-bottom: 70px; /* Espace pour la toolbar fixe */
}
/* --- EN-TÊTE --- */
.header-bar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 12px;
}
.header-bar h1 {
margin: 0;
font-size: 1.3rem;
color: var(--text-main);
display: flex;
align-items: center;
gap: 8px;
}
.pf-btn {
background: var(--bg-panel);
color: var(--text-main);
border: 1px solid var(--border-strong);
padding: 8px 12px;
border-radius: 8px;
font-weight: 600;
cursor: pointer;
font-size: 0.85rem;
box-shadow: var(--shadow-sm);
}
.pf-btn.primary {
background: var(--primary);
color: white;
border-color: var(--primary);
}
/* --- MATRICE ULTRA-COMPACTE --- */
.meals-wrapper {
background: var(--bg-panel);
border-radius: 8px;
border: 1px solid var(--border-strong);
box-shadow: var(--shadow-sm);
overflow: hidden;
}
.meals-table {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
.meals-table th,
.meals-table td {
border: 1px solid var(--border-light);
padding: 0;
text-align: center;
vertical-align: middle;
}
.meals-table th {
background: var(--bg-subtle);
font-size: 0.6rem;
font-weight: 800;
color: var(--text-muted);
padding: 6px 2px;
text-transform: uppercase;
}
.col-sticky {
width: 40px;
background: var(--bg-subtle);
border-right: 2px solid var(--border-strong) !important;
padding: 4px 2px !important;
}
.day-label {
font-size: 0.65rem;
font-weight: 800;
color: var(--text-main);
text-transform: uppercase;
display: block;
margin-bottom: 2px;
}
.day-label.invisible {
visibility: hidden;
height: 0;
margin: 0;
}
.service-icon {
background: white;
border: 1px solid var(--border-strong);
border-radius: 6px;
font-size: 1rem;
width: 26px;
height: 26px;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto;
cursor: pointer;
box-shadow: var(--shadow-sm);
transition: transform 0.1s;
}
.service-icon:active {
transform: scale(0.9);
}
.row-lunch td {
border-top: 2px solid var(--border-strong) !important;
}
.row-dinner td {
border-top: 1px dashed var(--border-light);
}
.meal-input-cell {
position: relative;
height: 100%;
background: var(--bg-panel);
}
.meal-input {
width: 100%;
height: 44px;
border: none;
background: transparent;
text-align: center;
font-size: 0.75rem;
padding: 4px;
color: var(--text-main);
font-family: inherit;
resize: none;
box-sizing: border-box;
outline: none;
}
.meal-input:focus {
background: #eff6ff;
}
/* --- BARRE CONTEXTUELLE (FIXE EN BAS) --- */
.context-toolbar {
position: fixed;
bottom: -80px;
left: 0;
right: 0;
height: 60px;
background: var(--bg-panel);
border-top: 1px solid var(--border-strong);
box-shadow: var(--shadow-lg);
display: flex;
justify-content: center;
align-items: center;
gap: 12px;
transition: bottom 0.2s cubic-bezier(0.16, 1, 0.3, 1);
z-index: 1000;
padding: 0 10px;
}
.context-toolbar.active {
bottom: 0;
}
.ctx-btn {
background: var(--bg-subtle);
border: 1px solid var(--border-strong);
border-radius: 8px;
padding: 10px 16px;
font-size: 0.85rem;
font-weight: 700;
color: var(--text-main);
cursor: pointer;
display: flex;
align-items: center;
gap: 6px;
}
.ctx-btn.primary {
background: var(--primary);
color: white;
border-color: var(--primary);
}
/* --- MODALE : COPIER VERS (DESIGN GRILLE) --- */
.pf-modal {
display: none;
position: fixed;
inset: 0;
background: rgba(15, 23, 42, 0.6);
align-items: center;
justify-content: center;
z-index: 2000;
}
.pf-modal.open {
display: flex;
animation: fadeInBg 0.2s;
}
.pf-modal-content {
background: var(--bg-panel);
width: 95%;
max-width: 600px;
border-radius: 12px;
padding: 20px;
box-sizing: border-box;
box-shadow: var(--shadow-lg);
max-height: 90vh;
overflow-y: auto;
}
.modal-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
}
.modal-title {
margin: 0;
font-size: 1.1rem;
color: var(--text-main);
font-weight: 800;
display: flex;
align-items: center;
gap: 8px;
}
.modal-close {
background: none;
border: none;
font-size: 1.8rem;
cursor: pointer;
color: var(--text-muted);
line-height: 1;
margin-top: -5px;
}
.modal-source {
font-size: 0.85rem;
color: var(--text-muted);
font-weight: 600;
margin: 0 0 20px 0;
}
/* Grille des Jours */
.week-section-title {
background: var(--bg-subtle);
text-align: center;
padding: 6px;
font-weight: 700;
font-size: 0.85rem;
color: var(--text-muted);
border-radius: 4px;
margin: 15px 0 10px 0;
text-transform: uppercase;
border: 1px solid var(--border-light);
}
.days-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}
.day-card {
background: var(--bg-panel);
border: 1px solid var(--border-light);
border-radius: 8px;
padding: 8px 4px;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
box-shadow: var(--shadow-sm);
}
.day-card-title {
font-size: 0.8rem;
font-weight: 700;
color: var(--text-main);
}
.day-card-actions {
display: flex;
gap: 6px;
justify-content: center;
width: 100%;
}
.day-action-btn {
background: var(--bg-page);
border: 1px solid var(--border-strong);
border-radius: 6px;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1rem;
cursor: pointer;
transition: 0.1s;
}
.day-action-btn:active {
transform: scale(0.9);
background: #e2e8f0;
}
@media (max-width: 380px) {
.days-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@keyframes fadeInBg {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
</style>
</head>
<body>
<div class="header-bar">
<h1>
<span style="opacity: 0.5">🍽️</span>
<span data-i18n="meals_board_title">Planning Repas</span>
</h1>
<button class="pf-btn" title="Générer les courses">
🛒 <span data-i18n="btn_groceries">Courses</span>
</button>
</div>
<!-- BARRE CONTEXTUELLE FIXE (Évite le conflit avec le clavier mobile) -->
<div class="context-toolbar" id="contextToolbar">
<button
class="ctx-btn"
onmousedown="
event.preventDefault();
applyToAllInRow();
"
>
➡️ <span data-i18n="btn_apply_all">Tous</span>
</button>
<button
class="ctx-btn primary"
onmousedown="
event.preventDefault();
openCopySheetFromCell();
"
>
🔄 <span data-i18n="btn_copy_to">Copier vers...</span>
</button>
</div>
<div class="meals-wrapper">
<table class="meals-table" id="mealsTable">
<thead>
<tr>
<th class="col-sticky"></th>
<th>PAPA</th>
<th>MAMAN</th>
<th>E1</th>
<th>E2</th>
</tr>
</thead>
<tbody>
<!-- Injecté via JS -->
</tbody>
</table>
</div>
<!-- MODALE DE COPIE (GRILLE LUNDI-DIMANCHE) -->
<div id="copyModal" class="pf-modal">
<div class="pf-modal-content">
<div class="modal-header">
<h3 class="modal-title">
🔄 <span data-i18n="modal_copy_title">Copier vers...</span>
</h3>
<button class="modal-close" onclick="closeCopyModal()">
&times;
</button>
</div>
<div id="copySourceLabel" class="modal-source">
Source : Plat individuel (Lundi Midi)
</div>
<div class="week-section-title" data-i18n="week_current">
Semaine actuelle
</div>
<div class="days-grid" id="currentWeekGrid"></div>
<div class="week-section-title" data-i18n="week_next">
Semaine prochaine
</div>
<div class="days-grid" id="nextWeekGrid"></div>
</div>
</div>
<script>
// --- I18N MOCKUP ---
window.I18N = {
meals_board_title: "Planning Repas",
btn_groceries: "Courses",
btn_apply_all: "Tous",
btn_copy_to: "Copier vers...",
modal_copy_title: "Copier vers...",
source_individual: "Plat individuel",
source_row: "Repas complet",
week_current: "Semaine actuelle",
week_next: "Semaine prochaine",
};
document
.querySelectorAll("[data-i18n]")
.forEach(
(el) => (el.innerHTML = window.I18N[el.getAttribute("data-i18n")]),
);
const days = ["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"];
const fullDays = [
"Lundi",
"Mardi",
"Mercredi",
"Jeudi",
"Vendredi",
"Samedi",
"Dimanche",
];
const membersCount = 4;
const tbody = document.querySelector("#mealsTable tbody");
let copyState = {
type: null,
dayIdx: null,
service: null,
personIdx: null,
sourceElements: [],
};
// --- 1. GÉNÉRATION DE LA GRILLE PRINCIPALE ---
days.forEach((day, index) => {
let trLunch = document.createElement("tr");
trLunch.className = "row-lunch";
trLunch.innerHTML = `
<td class="col-sticky">
<span class="day-label">${day}</span>
<div class="service-icon" onclick="openCopySheetFromRow(${index}, 'lunch')" title="Copier la ligne">☀️</div>
</td>`;
for (let p = 0; p < membersCount; p++) {
trLunch.innerHTML += `<td class="meal-input-cell"><textarea class="meal-input js-meal-input" data-d="${index}" data-s="lunch" data-p="${p}" placeholder="-"></textarea></td>`;
}
tbody.appendChild(trLunch);
let trDinner = document.createElement("tr");
trDinner.className = "row-dinner";
trDinner.innerHTML = `
<td class="col-sticky">
<span class="day-label invisible">${day}</span>
<div class="service-icon" onclick="openCopySheetFromRow(${index}, 'dinner')" title="Copier la ligne">🌙</div>
</td>`;
for (let p = 0; p < membersCount; p++) {
trDinner.innerHTML += `<td class="meal-input-cell"><textarea class="meal-input js-meal-input" data-d="${index}" data-s="dinner" data-p="${p}" placeholder="-"></textarea></td>`;
}
tbody.appendChild(trDinner);
});
// --- 2. GÉNÉRATION DES GRILLES DE LA MODALE COPIE ---
function buildModalGrid(containerId, weekTarget) {
const container = document.getElementById(containerId);
let html = "";
fullDays.forEach((dayName, idx) => {
html += `
<div class="day-card">
<div class="day-card-title">${dayName}</div>
<div class="day-card-actions">
<button type="button" class="day-action-btn" onclick="executeCopy(${idx}, 'lunch', '${weekTarget}')">☀️</button>
<button type="button" class="day-action-btn" onclick="executeCopy(${idx}, 'dinner', '${weekTarget}')">🌙</button>
</div>
</div>`;
});
container.innerHTML = html;
}
buildModalGrid("currentWeekGrid", "current");
buildModalGrid("nextWeekGrid", "next");
// --- 3. GESTION DU FOCUS & DE LA TOOLBAR ---
document.addEventListener("focusin", (e) => {
if (e.target.classList.contains("js-meal-input")) {
copyState = {
type: "cell",
dayIdx: e.target.getAttribute("data-d"),
service: e.target.getAttribute("data-s"),
personIdx: e.target.getAttribute("data-p"),
sourceElements: [e.target],
};
document.getElementById("contextToolbar").classList.add("active");
}
});
document.addEventListener("focusout", (e) => {
setTimeout(() => {
if (!document.activeElement.classList.contains("js-meal-input")) {
document
.getElementById("contextToolbar")
.classList.remove("active");
}
}, 150);
});
function flashSuccess(input) {
input.style.transition = "background 0.3s";
input.style.background = "var(--alert-success-bg)";
setTimeout(() => (input.style.background = "transparent"), 400);
}
// --- 4. ACTIONS DE COPIE ---
function applyToAllInRow() {
if (
copyState.type !== "cell" ||
!copyState.sourceElements[0].value.trim()
)
return;
const val = copyState.sourceElements[0].value;
const inputs = document.querySelectorAll(
`.js-meal-input[data-d="${copyState.dayIdx}"][data-s="${copyState.service}"]`,
);
inputs.forEach((inp) => {
if (inp !== copyState.sourceElements[0]) {
inp.value = val;
flashSuccess(inp);
}
});
}
function openCopySheetFromCell() {
if (
!copyState.sourceElements[0] ||
!copyState.sourceElements[0].value.trim()
)
return;
document.getElementById("contextToolbar").classList.remove("active");
document.activeElement.blur(); // Masque le clavier mobile
const svcLabel = copyState.service === "lunch" ? "Midi" : "Soir";
document.getElementById("copySourceLabel").innerText =
`Source : ${window.I18N.source_individual} (${fullDays[copyState.dayIdx]} ${svcLabel})`;
document.getElementById("copyModal").classList.add("open");
document.body.classList.add("no-scroll");
}
function openCopySheetFromRow(dIdx, service) {
const inputs = document.querySelectorAll(
`.js-meal-input[data-d="${dIdx}"][data-s="${service}"]`,
);
const hasContent = Array.from(inputs).some(
(inp) => inp.value.trim() !== "",
);
if (!hasContent) return;
copyState = {
type: "row",
dayIdx: dIdx,
service: service,
sourceElements: Array.from(inputs),
};
const svcLabel = service === "lunch" ? "Midi" : "Soir";
document.getElementById("copySourceLabel").innerText =
`Source : ${window.I18N.source_row} (${fullDays[dIdx]} ${svcLabel})`;
document.getElementById("copyModal").classList.add("open");
document.body.classList.add("no-scroll");
}
function closeCopyModal() {
document.getElementById("copyModal").classList.remove("open");
document.body.classList.remove("no-scroll");
}
function executeCopy(targetDayIdx, targetService, targetWeek) {
if (targetWeek === "next") {
alert("Simulation : Copié avec succès vers la SEMAINE PROCHAINE !");
closeCopyModal();
return;
}
if (copyState.type === "cell") {
const val = copyState.sourceElements[0].value;
const targetInput = document.querySelector(
`.js-meal-input[data-d="${targetDayIdx}"][data-s="${targetService}"][data-p="${copyState.personIdx}"]`,
);
if (targetInput) {
targetInput.value = val;
flashSuccess(targetInput);
}
} else if (copyState.type === "row") {
const targetInputs = document.querySelectorAll(
`.js-meal-input[data-d="${targetDayIdx}"][data-s="${targetService}"]`,
);
copyState.sourceElements.forEach((inp, idx) => {
if (inp.value.trim() !== "") {
targetInputs[idx].value = inp.value;
flashSuccess(targetInputs[idx]);
}
});
}
closeCopyModal();
}
</script>
</body>
</html>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,260 @@
<?php
// modules/budget/includes/DynamicBudgetCalculator.php
class DynamicBudgetCalculator {
private \PDO $pdo;
private int $year;
private string $month;
private array $settings = [];
private array $foyerSettings = [];
private array $kids = [];
private string $helperName = 'Intervenant'; // Valeur par défaut
private array $calendarEvents = [];
public function __construct(\PDO $pdo, int|string $year, int|string $month) {
$this->pdo = $pdo;
$this->year = (int)$year;
$this->month = str_pad((string)$month, 2, '0', STR_PAD_LEFT);
$this->loadSettings();
$this->loadPeople();
$this->loadEvents();
}
private function loadSettings(): void {
$stmt = $this->pdo->query("SELECT setting_key, setting_value FROM pf_settings WHERE module = 'budget'");
$this->settings = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
$this->foyerSettings = $this->pdo->query("SELECT * FROM pf_foyer_settings LIMIT 1")->fetch(PDO::FETCH_ASSOC);
}
private function getSetting(string $key, float|int $default = 0): float {
return isset($this->settings[$key]) ? (float)$this->settings[$key] : (float)$default;
}
private function loadPeople(): void {
// 1. Chargement des enfants sans doublons
$stmt = $this->pdo->query("SELECT id, name, care_modes FROM pf_people WHERE role IN ('enfant', 'child') AND is_active = 1");
$rawKids = $stmt->fetchAll(PDO::FETCH_ASSOC);
$this->kids = [];
$seenNames = [];
foreach ($rawKids as $k) {
$nameKey = mb_strtolower(trim($k['name']));
if (!isset($seenNames[$nameKey])) {
$this->kids[] = $k;
$seenNames[$nameKey] = true;
}
}
// 2. Chargement dynamique de l'intervenant (ex: Carole)
$stmtHelper = $this->pdo->query("SELECT name FROM pf_people WHERE role IN ('helper', 'nounou') AND is_active = 1 LIMIT 1");
$helper = $stmtHelper->fetchColumn();
if ($helper) {
$this->helperName = mb_strtoupper($helper);
}
}
private function loadEvents(): void {
$startDate = "{$this->year}-{$this->month}-01";
$endDate = date('Y-m-t', strtotime($startDate));
$stmt = $this->pdo->prepare("SELECT event_date, event_type, person_id FROM pf_events WHERE event_date BETWEEN ? AND ?");
$stmt->execute([$startDate, $endDate]);
$events = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($events as $e) {
$this->calendarEvents[$e['event_date']][] = $e;
}
}
private function getOffDays(): array {
$cacheKey = "offdays_{$this->year}";
$stmt = $this->pdo->prepare("SELECT content FROM pf_notes WHERE note_type = 'system_cache' AND reference_id = ?");
$stmt->execute([$cacheKey]);
$cached = $stmt->fetchColumn();
if ($cached) return json_decode($cached, true);
$offDays = ['feries' => [], 'vacances' => []];
try {
$jsonFeries = @file_get_contents("https://calendrier.api.gouv.fr/jours-feries/metropole/{$this->year}.json");
if ($jsonFeries) $offDays['feries'] = array_keys(json_decode($jsonFeries, true));
} catch (\Throwable $e) {}
$zone = $this->foyerSettings['zone_scolaire'] ?? 'C';
try {
$url = "https://data.education.gouv.fr/api/explore/v2.1/catalog/datasets/fr-en-calendrier-scolaire/records?where=annee_scolaire='{$this->year}-" . ($this->year + 1) . "' AND zones LIKE '%Zone {$zone}%'&limit=100";
$jsonVacances = @file_get_contents($url);
if ($jsonVacances) {
$data = json_decode($jsonVacances, true);
if (!empty($data['results'])) {
foreach ($data['results'] as $r) {
$start = new DateTime(substr($r['start_date'], 0, 10));
$end = new DateTime(substr($r['end_date'], 0, 10));
if ($start->format('N') == 5) $start->modify('+1 day');
while ($start < $end) {
$offDays['vacances'][] = $start->format('Y-m-d');
$start->modify('+1 day');
}
}
}
}
} catch (\Throwable $e) {}
$this->pdo->prepare("INSERT INTO pf_notes (note_type, reference_id, content) VALUES ('system_cache', ?, ?) ON DUPLICATE KEY UPDATE content = VALUES(content)")
->execute([$cacheKey, json_encode($offDays)]);
return $offDays;
}
public function getEstimate(string $dynamicCode): array {
if ($dynamicCode === 'SCHOOL_ESTIMATE') {
return $this->calculateSchoolEstimate();
}
return ['amount' => 0.0, 'details' => tr('error_occured')];
}
private function calculateSchoolEstimate(): array {
$nannyFixed = $this->getSetting('budget_nanny_fixed', 700);
$nannyDaily = $this->getSetting('budget_nanny_daily', 4);
$nannyAid = $this->getSetting('budget_nanny_aid', 120);
$cesuAvg = $this->getSetting('budget_nanny_cesu_avg', 170);
$schoolMeal = $this->getSetting('budget_school_meal', 5.62);
$schoolAftercare = $this->getSetting('budget_school_aftercare', 1.97);
$schoolFullday = $this->getSetting('budget_school_fullday', 21.89);
$offDays = $this->getOffDays();
$totalCost = 0;
$details = sprintf(tr('bud_audit_month') . "\n\n", $this->month, $this->year);
$hasNanny = false;
$nannyOffDays = 0;
$nannyGlobalCost = $nannyFixed - $nannyAid - $cesuAvg;
$kidsStats = [];
// 1. Initialisation stricte
foreach ($this->kids as $k) {
$modes = json_decode($k['care_modes'] ?? '[]', true) ?: [];
$isNanny = count(array_intersect(array_map('strtolower', $modes), ['nounou', 'kangur'])) > 0;
if ($isNanny) $hasNanny = true;
$kidsStats[$k['id']] = [
'name' => $k['name'], 'isNanny' => $isNanny,
'nannyDays' => 0, 'sick' => 0,
'schoolMeal' => 0, 'schoolAftercare' => 0, 'center' => 0
];
}
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, (int)$this->month, $this->year);
// 2. Itération SANS pointeurs de référence
for ($d = 1; $d <= $daysInMonth; $d++) {
$dateStr = sprintf("%04d-%02d-%02d", $this->year, $this->month, $d);
$dayOfWeek = date('N', strtotime($dateStr));
if ($dayOfWeek >= 6) continue;
if (in_array($dateStr, $offDays['feries'])) continue;
$isVacances = in_array($dateStr, $offDays['vacances']);
$events = $this->calendarEvents[$dateStr] ?? [];
$nannyOffToday = false;
foreach ($events as $e) {
if (in_array($e['event_type'], ['HELPER_OFF', 'HELPER_EXTRA'])) $nannyOffToday = true;
}
if ($nannyOffToday) $nannyOffDays++;
foreach ($this->kids as $kid) {
$kidId = $kid['id'];
$isSick = false;
$hasCenterEvent = false;
foreach ($events as $e) {
if ($e['event_type'] === 'CHILD_SICK' && $e['person_id'] == $kidId) $isSick = true;
if (strtoupper($e['event_type']) === 'CENTRE' && $e['person_id'] == $kidId) $hasCenterEvent = true;
}
if ($isSick) {
$kidsStats[$kidId]['sick']++;
continue;
}
if ($kidsStats[$kidId]['isNanny']) {
if (!$nannyOffToday) $kidsStats[$kidId]['nannyDays']++;
} else {
if ($isVacances) {
if ($hasCenterEvent) $kidsStats[$kidId]['center']++;
} else {
if ($dayOfWeek == 3) {
$kidsStats[$kidId]['center']++;
} else {
$kidsStats[$kidId]['schoolMeal']++;
if (in_array($dayOfWeek, [2, 4])) $kidsStats[$kidId]['schoolAftercare']++;
}
}
}
}
}
$totalNannyDays = 0;
foreach ($kidsStats as $stat) {
if ($stat['isNanny']) {
$totalNannyDays += $stat['nannyDays'];
}
}
$totalNannyFees = $totalNannyDays * $nannyDaily;
$nannyGlobalCost = $nannyFixed + $totalNannyFees - $nannyAid - $cesuAvg;
// 3. Rédaction du Bilan
if ($hasNanny) {
$totalCost += max(0, $nannyGlobalCost);
$details .= sprintf(tr('bud_audit_nanny_full') . "\n",
$this->helperName, $nannyFixed, $totalNannyDays, $nannyDaily, $totalNannyFees, $nannyAid, $cesuAvg, max(0, $nannyGlobalCost));
if ($nannyOffDays > 0) {
$details .= sprintf(tr('bud_audit_nanny_abs') . "\n", $this->helperName, $nannyOffDays);
}
$details .= "\n";
}
foreach ($kidsStats as $finalStat) {
if ($finalStat['isNanny']) {
// L'enfant est chez la nounou : on ne l'affiche QUE s'il a été malade
if ($finalStat['sick'] > 0) {
$details .= sprintf(tr('bud_audit_child') . "\n", mb_strtoupper($finalStat['name']));
$details .= sprintf(tr('bud_audit_sick') . "\n", $finalStat['sick']) . "\n\n";
}
} else {
// L'enfant va à l'école / centre
$details .= sprintf(tr('bud_audit_child') . "\n", mb_strtoupper($finalStat['name']));
$costM = $finalStat['schoolMeal'] * $schoolMeal;
$costA = $finalStat['schoolAftercare'] * $schoolAftercare;
$costC = $finalStat['center'] * $schoolFullday;
$kidTotal = $costM + $costA + $costC;
$totalCost += $kidTotal;
$details .= sprintf(tr('bud_audit_school_fee') . "\n",
$finalStat['schoolMeal'], $finalStat['schoolAftercare'], $finalStat['center'], $kidTotal);
if ($finalStat['sick'] > 0) {
$details .= sprintf(tr('bud_audit_sick') . "\n", $finalStat['sick']) . "\n";
}
$details .= "\n";
}
}
return [
'amount' => round($totalCost, 2),
'details' => trim($details)
];
}
}
@@ -0,0 +1,30 @@
<?php
header('Content-Type: application/json');
// On charge l'authentification et l'init PDO de l'espace familial courant automatiquement via tes includes globaux
require_once __DIR__ . '/../../../../includes/auth.php';
require_once __DIR__ . '/../../../../includes/db.php';
require_once __DIR__ . '/../../../../includes/i18n.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'message' => 'Method not allowed']);
exit;
}
$title = trim($_POST['title'] ?? '');
$amount = floatval($_POST['amount'] ?? 0);
$expected_date = $_POST['expected_date'] ?? '';
if (empty($title) || $amount <= 0 || empty($expected_date)) {
echo json_encode(['success' => false, 'message' => tr('error_generic')]);
exit;
}
try {
// Grâce au multi-tenant par BDD, $pdo pointe déjà sur la base de la famille connectée
$stmt = $pdo->prepare("INSERT INTO pf_expected_expenses (title, amount, expected_date) VALUES (?, ?, ?)");
$stmt->execute([$title, $amount, $expected_date]);
echo json_encode(['success' => true, 'message' => tr('success_add_provision')]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'message' => 'Database error: ' . $e->getMessage()]);
}
@@ -0,0 +1,19 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../../../../includes/auth.php';
require_once __DIR__ . '/../../../../includes/db.php';
$id = intval($_POST['id'] ?? 0);
if (!$id) {
echo json_encode(['success' => false, 'message' => 'Invalid ID']);
exit;
}
try {
$stmt = $pdo->prepare("DELETE FROM pf_expected_expenses WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
@@ -0,0 +1,35 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../../../../includes/auth.php';
require_once __DIR__ . '/../../../../includes/db.php';
require_once __DIR__ . '/../../../../includes/i18n.php';
try {
// Récupérer les provisions non payées, classées par date
$stmt = $pdo->query("SELECT id, title, amount, expected_date FROM pf_expected_expenses WHERE is_paid = 0 ORDER BY expected_date ASC");
$provisions = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($provisions)) {
$html = '<p class="pf-text-muted">' . tr('no_provisions') . '</p>';
} else {
$html = '<table class="pf-table" style="width:100%; border-collapse: collapse;">';
$html .= '<thead style="border-bottom: 2px solid var(--border-color); text-align: left;">';
$html .= '<tr><th>' . tr('provision_label') . '</th><th>' . tr('amount') . '</th><th>' . tr('expected_date') . '</th><th style="text-align:right;">Actions</th></tr>';
$html .= '</thead><tbody>';
foreach ($provisions as $p) {
$dateFormated = date('d/m/Y', strtotime($p['expected_date']));
$html .= '<tr style="border-bottom: 1px solid var(--border-color); height: 45px;">';
$html .= '<td>' . htmlspecialchars($p['title']) . '</td>';
$html .= '<td>' . number_format($p['amount'], 2, ',', ' ') . ' €</td>';
$html .= '<td>' . $dateFormated . '</td>';
$html .= '<td style="text-align:right;"><button class="pf-btn pf-btn-danger btn-delete-provision" data-id="' . $p['id'] . '">' . tr('btn_delete') . '</button></td>';
$html .= '</tr>';
}
$html .= '</tbody></table>';
}
echo json_encode(['success' => true, 'html' => $html]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
+161
View File
@@ -0,0 +1,161 @@
<?php
require __DIR__ . '/../../../../includes/auth.php';
require __DIR__ . '/../../../../includes/db.php';
require_login();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
// --- ACTION : SAUVEGARDER (AJOUT OU MODIF DU BUDGET) ---
if ($action === 'save') {
try {
// 1. Sécurisation des données entrantes
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
$name = trim($_POST['name'] ?? '');
$category = $_POST['category'] ?? '';
$type = $_POST['type'] ?? 'Mensuel';
$payment_day = !empty($_POST['payment_day']) ? (int)$_POST['payment_day'] : null;
$is_estimate = isset($_POST['is_estimate']) ? (int)$_POST['is_estimate'] : 0;
$reg_month = !empty($_POST['reg_month']) ? trim($_POST['reg_month']) : null;
$keywords = trim($_POST['mapping_keywords'] ?? '');
$holiday_id = !empty($_POST['holiday_id']) ? (int)$_POST['holiday_id'] : null;
// 2. Gestion du montant (toujours stocker les dépenses en négatif)
$amount = abs((float)($_POST['amount'] ?? 0));
$amount = -$amount; // On force le négatif car le modal Recap ne gère que des charges
// 3. Exécution de la requête
if ($id) {
// UPDATE
$stmt = $pdo->prepare("UPDATE pf_budget_items SET name=?, amount=?, category=?, type=?, payment_day=?, is_estimate=?, reg_month=?, mapping_keywords=?, holiday_id=? WHERE id=?");
$stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords, $holiday_id, $id]);
} else {
// INSERT
$stmt = $pdo->prepare("INSERT INTO pf_budget_items (name, amount, category, type, payment_day, is_estimate, reg_month, mapping_keywords, holiday_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords, $holiday_id]);
}
// 4. Réponse appropriée (JSON si appel via JS fetch, Redirection sinon)
if (!empty($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
} else {
header('Location: /budget.php?tab=recap');
exit;
}
} catch (PDOException $e) {
// En cas d'erreur BDD (ex: contrainte de clé étrangère, colonne manquante)
if (!empty($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => 'Erreur BDD : ' . $e->getMessage()]);
exit;
}
die("Erreur fatale : " . $e->getMessage());
}
}
// --- ACTION : COCHER/DÉCOCHER RAPIDE (VIA JS FETCH) ---
if ($action === 'toggle-check') {
$id = $_POST['id'];
$status = $_POST['status'];
$sql = "UPDATE pf_budget_items SET is_checked = ? WHERE id = ?";
$stmt = $pdo->prepare($sql);
$stmt->execute([$status, $id]);
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
// --- ACTION : SUPPRIMER UNE LIGNE DU BUDGET ---
if ($action === 'delete') {
$id = $_POST['id'];
$pdo->prepare("DELETE FROM pf_budget_items WHERE id = ?")->execute([$id]);
if (isset($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => true]);
} else {
header('Location: /budget.php?tab=recap');
}
exit;
}
// --- ACTION : SUPPRIMER UNE DÉPENSE RÉELLE (Depuis l'onglet Suivi) ---
if ($action === 'delete_expense') {
$id = (int)$_POST['id'];
$pdo->prepare("DELETE FROM pf_expenses WHERE id = ?")->execute([$id]);
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
// --- ACTION : SAUVEGARDER UNE DÉPENSE MANUELLE (FETCH) ---
if ($action === 'save_expense_manual') {
header('Content-Type: application/json');
try {
$id = !empty($_POST['expense_id']) ? (int)$_POST['expense_id'] : null;
$cat = $_POST['category'] ?? '';
$amount = floatval($_POST['amount'] ?? 0);
$date = $_POST['date'] ?? date('Y-m-d');
// Format attendu : YYYY-MM
$gestionMonthRaw = $_POST['gestion_month'] ?? '';
// Si la valeur est vide ou invalide
if (empty($gestionMonthRaw) || strpos($gestionMonthRaw, '0000') !== false) {
$gestionMonth = date('Y-m-01', strtotime($date));
} else {
$gestionMonth = (strlen($gestionMonthRaw) === 7) ? $gestionMonthRaw . '-01' : $gestionMonthRaw;
}
$label = trim($_POST['label'] ?? '');
$rawItemId = $_POST['budget_item_id'] ?? '';
$budgetItemId = null;
$salaryId = null;
$holidayId = !empty($_POST['holiday_id']) ? (int)$_POST['holiday_id'] : null;
if ($cat === 'School' && !empty($_POST['label_select'])) {
$label = trim($_POST['label_select']);
} elseif (!empty($rawItemId)) {
// 🔥 On intercepte si c'est un Salaire (SAL_x) ou une Charge Fixe classique (x)
if (strpos($rawItemId, 'SAL_') === 0) {
$salaryId = (int)str_replace('SAL_', '', $rawItemId);
} else {
$budgetItemId = (int)$rawItemId;
}
}
// Vérification de sécurité
if (empty($label) || $amount <= 0) {
echo json_encode(['success' => false, 'error' => 'Le label et un montant supérieur à 0 sont obligatoires.']);
exit;
}
$is_credit = isset($_POST['is_credit']) ? (int)$_POST['is_credit'] : 0;
$finalAmount = $is_credit ? abs($amount) : -abs($amount);
if ($id) {
// UPDATE (Ajout de salary_id)
$pdo->prepare("UPDATE pf_expenses SET date_exp=?, gestion_month=?, category=?, label=?, amount=?, budget_item_id=?, holiday_id=?, salary_id=? WHERE id=?")
->execute([$date, $gestionMonth, $cat, $label, $finalAmount, $budgetItemId, $holidayId, $salaryId, $id]);
} else {
// INSERT (Ajout de salary_id)
$uniqueRef = "MANUAL_" . uniqid();
$pdo->prepare("INSERT INTO pf_expenses (date_exp, gestion_month, category, label, amount, import_ref, budget_item_id, holiday_id, salary_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
->execute([$date, $gestionMonth, $cat, $label, $finalAmount, $uniqueRef, $budgetItemId, $holidayId, $salaryId]);
}
echo json_encode(['success' => true]);
exit;
} catch (PDOException $e) {
echo json_encode(['success' => false, 'error' => 'Erreur base de données.']);
exit;
}
}
}
@@ -0,0 +1,156 @@
<?php
header('Content-Type: application/json');
require_once __DIR__ . '/../../../../includes/auth.php';
require_once __DIR__ . '/../../../../includes/db.php';
require_once __DIR__ . '/../../../../includes/i18n.php';
$savings_inputs = $_POST['savings'] ?? [];
$current_year = date('Y');
$current_month = date('m');
try {
// 1. Récupération des dépenses prévues
$stmtExpenses = $pdo->prepare("
SELECT title, amount, expected_date
FROM pf_expected_expenses
WHERE is_paid = 0
AND YEAR(expected_date) = ?
AND MONTH(expected_date) = ?
ORDER BY expected_date ASC
");
$stmtExpenses->execute([$current_year, $current_month]);
$expenses = $stmtExpenses->fetchAll(PDO::FETCH_ASSOC);
$q1_expenses_total = 0;
$q2_expenses_total = 0;
$detail_html = '<ul style="padding-left: 1.2rem; margin-bottom: 1rem; color: var(--text-muted); font-size:0.9rem;">';
foreach ($expenses as $e) {
$day = intval(date('d', strtotime($e['expected_date'])));
if ($day <= 15) {
$q1_expenses_total += $e['amount'];
} else {
$q2_expenses_total += $e['amount'];
}
$detail_html .= '<li>' . htmlspecialchars($e['title']) . ' (' . number_format($e['amount'], 2, ',', ' ') . ' € le ' . date('d/m', strtotime($e['expected_date'])) . ')</li>';
}
$detail_html .= '</ul>';
$total_expenses = $q1_expenses_total + $q2_expenses_total;
// 2. Récupération des dettes
$stmtDebts = $pdo->query("SELECT payer, SUM(amount) as total_debt FROM pf_advances WHERE is_resolved = 0 GROUP BY payer");
$debts = $stmtDebts->fetchAll(PDO::FETCH_KEY_PAIR);
// 3. NOUVELLE LOGIQUE : Clearing intelligent (Compensation partielle ou totale)
$total_base_inputs = array_sum(array_map('floatval', $savings_inputs));
$surplus_for_clearing = $total_base_inputs - $total_expenses;
$monthly_savings = 0; // Le vrai total qui sera viré après déduction des dettes
$contributions_html = '<ul style="padding-left: 1.2rem; margin-bottom: 0.5rem; color: var(--text-main); font-size:0.9rem; line-height: 1.6;">';
foreach ($savings_inputs as $person => $amount) {
$base_amount = floatval($amount);
$debt = $debts[$person] ?? 0;
// Formatage bancaire propre pour les textes
$base_fmt = number_format($base_amount, 2, ',', ' ');
if ($debt > 0) {
if ($surplus_for_clearing > 0) {
$compensation = min($debt, $base_amount, $surplus_for_clearing);
$net_amount = $base_amount - $compensation;
$surplus_for_clearing -= $compensation;
$monthly_savings += $net_amount;
$comp_fmt = number_format($compensation, 2, ',', ' ');
$net_fmt = number_format($net_amount, 2, ',', ' ');
$reste_dette = $debt - $compensation;
$txt_reste = ($reste_dette > 0)
? ' <span style="color:var(--danger); font-size:0.8rem; margin-left: 5px;">(Reste ' . number_format($reste_dette, 2, ',', ' ') . ' € de dette)</span>'
: ' <span style="color:var(--success); font-weight:bold; font-size:0.85rem; margin-left: 5px;">(Dette soldée 🎉)</span>';
// Harmonisation en bleu (#2563eb) pour le montant net à verser
$contributions_html .= '<li style="margin-bottom: 5px;"><strong>' . htmlspecialchars($person) . '</strong> : Base ' . $base_fmt . ' € − Remboursé ' . $comp_fmt . ' € = <strong style="color:#2563eb;">' . $net_fmt . ' € à verser</strong>' . $txt_reste . '</li>';
} else {
$monthly_savings += $base_amount;
$contributions_html .= '<li style="margin-bottom: 5px;"><strong>' . htmlspecialchars($person) . '</strong> : <strong style="color:#2563eb;">' . $base_fmt . ' € à verser</strong> <span style="color:var(--danger); font-size:0.8rem; margin-left: 5px;">(Dette gelée, liquidités insuffisantes)</span></li>';
}
} else {
$monthly_savings += $base_amount;
$contributions_html .= '<li style="margin-bottom: 5px;"><strong>' . htmlspecialchars($person) . '</strong> : <strong style="color:#2563eb;">' . $base_fmt . ' € à verser</strong></li>';
}
}
$contributions_html .= '</ul>';
$contributions_html .= '<p style="color: var(--text-main); font-weight: bold; margin-top:5px; font-size:0.95rem;">Total net atterrissant sur les comptes : ' . number_format($monthly_savings, 2, ',', ' ') . ' €</p>';
if(empty($expenses)) {
$detail_html = '<p style="color: var(--success); font-weight:bold; margin-bottom:1rem; font-size:0.9rem;">🎉 Aucune grosse dépense enregistrée sur ce mois.</p>';
}
// --- MOTEUR DE RÈGLES DES QUINZAINES (Remplacement des ** par <strong>) ---
$instructions = [];
$remaining_to_allocate = $monthly_savings;
// Règle 1 : Première quinzaine
if ($q1_expenses_total > 0) {
if ($remaining_to_allocate >= $q1_expenses_total) {
$remaining_to_allocate -= $q1_expenses_total;
$instructions[] = "💼 <strong>Dès le 1er</strong> : Laissez <strong>" . number_format($q1_expenses_total, 2, ',', ' ') . " €</strong> sur le compte commun pour honorer les dépenses de la 1ère quinzaine.";
} else {
$deficit = $q1_expenses_total - $remaining_to_allocate;
$remaining_to_allocate = 0;
$instructions[] = "💼 <strong>Dès le 1er</strong> : Gardez l'intégralité des apports sur le compte commun.";
$instructions[] = "⚠️ <strong>Retrait requis</strong> : Retirez <strong>" . number_format($deficit, 2, ',', ' ') . " €</strong> depuis le Livret A vers le commun pour couvrir la 1ère quinzaine.";
}
}
// Règle 2 : Deuxième quinzaine
if ($q2_expenses_total > 0) {
if ($remaining_to_allocate >= $q2_expenses_total) {
$remaining_to_allocate -= $q2_expenses_total;
$instructions[] = "📈 <strong>Dès le 1er</strong> : Placez <strong>" . number_format($q2_expenses_total, 2, ',', ' ') . " €</strong> sur le Livret A pour générer des intérêts sur la 1ère quinzaine.";
$instructions[] = "🔄 <strong>Le 16 du mois</strong> : Transférez ces <strong>" . number_format($q2_expenses_total, 2, ',', ' ') . " €</strong> sur le compte commun pour payer la dépense.";
} else {
if ($remaining_to_allocate > 0) {
$instructions[] = "📈 <strong>Dès le 1er</strong> : Placez le reste des apports (<strong>" . number_format($remaining_to_allocate, 2, ',', ' ') . " €</strong>) sur le Livret A.";
$instructions[] = "🔄 <strong>Le 16 du mois</strong> : Retirez <strong>" . number_format($q2_expenses_total, 2, ',', ' ') . " €</strong> global du Livret A pour payer la fin de mois.";
$remaining_to_allocate = 0;
} else {
$instructions[] = "🔄 <strong>Le 16 du mois</strong> : Retirez <strong>" . number_format($q2_expenses_total, 2, ',', ' ') . " €</strong> du Livret A vers le commun. <em>Ne le faites pas avant le 16 !</em>";
}
}
}
// Solde résiduel long terme
if ($remaining_to_allocate > 0) {
$instructions[] = "💰 <strong>Épargne stable</strong> : Placez les <strong>" . number_format($remaining_to_allocate, 2, ',', ' ') . " €</strong> restants sur votre Livret A dès le 1er.";
}
// --- CONSTITUTION DU RENDU HTML FINAL ---
$html = '<div style="border-top: 1px dashed var(--border-color); padding-top:0.8rem;">';
// Titre de l'état du Clearing simplifié et clair
$html .= '<h4 style="margin:0 0 0.4rem 0; font-size:0.95rem;">🤝 Résumé des apports et remboursements internes :</h4>';
$html .= '<div style="background: var(--bg-main); padding: 8px; border-radius: 6px; margin-bottom: 1rem; border: 1px solid var(--border-color);">';
$html .= $contributions_html;
$html .= '</div>';
$html .= '<h4 style="margin:0 0 0.4rem 0; font-size:0.95rem;">Analyse des dépenses du mois :</h4>';
$html .= $detail_html;
$html .= '<div style="background: var(--bg-main); padding: 8px; border-radius: 6px; border-left: 4px solid var(--accent-color);">';
$html .= '<h4 style="margin:0 0 0.5rem 0; color: var(--accent-color); font-size:0.95rem;">📋 Plan d\'action recommandé :</h4>';
foreach ($instructions as $ins) {
$html .= '<p style="margin:0 0 0.4rem 0; font-size: 0.9rem; line-height: 1.4;">' . $ins . '</p>';
}
$html .= '</div></div>';
echo json_encode(['success' => true, 'html' => $html]);
} catch (PDOException $e) {
echo json_encode(['success' => false, 'message' => 'Calcul impossible : ' . $e->getMessage()]);
}
+409
View File
@@ -0,0 +1,409 @@
<?php
// modules/budget/includes/api/save-budget.php
require __DIR__ . '/../../../../includes/auth.php';
require __DIR__ . '/../../../../includes/db.php';
require_login();
$action = $_POST['action'] ?? '';
// =================================================================
// LECTURE D'UNE NOTE (AJAX)
// =================================================================
if ($action === 'get_note') {
$noteType = $_POST['note_type'] ?? '';
$refId = $_POST['reference_id'] ?? '';
try {
$stmt = $pdo->prepare("SELECT content FROM pf_notes WHERE note_type = ? AND reference_id = ?");
$stmt->execute([$noteType, $refId]);
// fetchColumn() renvoie false si aucune ligne n'est trouvée, on sécurise avec un coalesce (?? '')
$content = $stmt->fetchColumn();
$content = $content !== false ? $content : '';
echo json_encode(['success' => true, 'content' => $content]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// =================================================================
// 7. SAUVEGARDE D'UNE NOTE GÉNÉRIQUE (pf_notes)
// =================================================================
if ($action === 'save_note') {
// On affiche les erreurs s'il y a un souci SQL pour pouvoir déboguer
ini_set('display_errors', 1);
error_reporting(E_ALL);
header('Content-Type: application/json');
try {
$noteType = $_POST['note_type'] ?? '';
$refId = $_POST['reference_id'] ?? '';
$content = $_POST['content'] ?? '';
if (empty($noteType) || empty($refId)) {
throw new Exception("Le type et la référence de la note sont requis.");
}
// Insère ou met à jour la note si elle existe déjà
$stmt = $pdo->prepare("INSERT INTO pf_notes (note_type, reference_id, content)
VALUES (?, ?, ?)
ON DUPLICATE KEY UPDATE content = VALUES(content)");
$stmt->execute([$noteType, $refId, $content]);
echo json_encode(['success' => true]);
} catch (\Throwable $e) {
echo json_encode(['success' => false, 'error' => 'Erreur SQL: ' . $e->getMessage()]);
}
exit;
}
// =================================================================
// 1. MISE A JOUR TABLEAU SALAIRES (AJAX)
if ($action === 'update_salary_config') {
header('Content-Type: application/json');
$year = $_POST['year'];
$person = $_POST['person'];
$field = $_POST['field']; // salary, mensualite, etc.
$value = floatval($_POST['value']);
// Liste des champs autorisés pour éviter les injections
$allowed = ['salary', 'mensualite', 'frais_func', 'eco_perso', 'eco_family'];
if (!in_array($field, $allowed)) {
echo json_encode(['success' => false, 'error' => 'Champ invalide']);
exit;
}
$stmt = $pdo->prepare("INSERT INTO pf_salary_config (year, person, $field) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE $field = VALUES($field)");
$stmt->execute([$year, $person, $value]);
echo json_encode(['success' => true]);
exit;
}
// 2. MISE A JOUR TABLEAU REPARTITION (AJAX)
if ($action === 'update_allocation') {
header('Content-Type: application/json');
$date = $_POST['month_date'];
$catId = (int)$_POST['cat_id'];
$personId = (int)$_POST['person_id'];
$value = floatval($_POST['value']);
if ($catId <= 0 || $personId <= 0) {
echo json_encode(['success' => false, 'error' => 'Données invalides.']);
exit;
}
$stmt = $pdo->prepare("INSERT INTO pf_alloc_values (month_date, cat_id, person_id, amount)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE amount = VALUES(amount)");
$stmt->execute([$date, $catId, $personId, $value]);
echo json_encode(['success' => true]);
exit;
}
// 3. GESTION DES CATEGORIES (Ajout)
if ($action === 'add_category') {
try {
$name = trim($_POST['name']);
$transfer_dest = trim($_POST['transfer_dest'] ?? '');
$target = floatval($_POST['target'] ?? 0);
$holiday_id = !empty($_POST['holiday_id']) ? (int)$_POST['holiday_id'] : null;
if (!empty($name)) {
$stmt = $pdo->prepare("INSERT INTO pf_alloc_categories (name, target, transfer_dest, holiday_id) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $target, $transfer_dest, $holiday_id]);
}
if (isset($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
header("Location: " . $_SERVER['HTTP_REFERER']);
exit;
} catch (Exception $e) {
if (isset($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
exit;
}
die($e->getMessage());
}
}
// 4. MODIFICATION D'UNE CATEGORIE
if ($action === 'update_category') {
try {
$id = (int)$_POST['cat_id'];
$name = trim($_POST['name']);
$transfer_dest = trim($_POST['transfer_dest'] ?? '');
$target = floatval($_POST['target'] ?? 0);
$holiday_id = !empty($_POST['holiday_id']) ? (int)$_POST['holiday_id'] : null;
if ($id > 0 && !empty($name)) {
$stmt = $pdo->prepare("UPDATE pf_alloc_categories SET name = ?, target = ?, transfer_dest = ?, holiday_id = ? WHERE id = ?");
$stmt->execute([$name, $target, $transfer_dest, $holiday_id, $id]);
}
if (isset($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
header("Location: " . $_SERVER['HTTP_REFERER']);
exit;
} catch (Exception $e) {
if (isset($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
exit;
}
die($e->getMessage());
}
}
// 5. SUPPRESSION CATEGORIE
if ($action === 'delete_category') {
$id = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
if ($id > 0) {
$pdo->prepare("DELETE FROM pf_alloc_categories WHERE id = ?")->execute([$id]);
$pdo->prepare("DELETE FROM pf_alloc_values WHERE cat_id = ?")->execute([$id]);
}
if (isset($_POST['ajax']) || isset($_GET['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['success' => true]);
exit;
}
header("Location: " . ($_SERVER['HTTP_REFERER'] ?? '/budget.php'));
exit;
}
// 6. VALIDATION DES VIREMENTS (Complex Business Logic)
if ($action === 'validate_transfers') {
header('Content-Type: application/json');
$personId = (int)$_POST['person_id']; // Reçoit l'ID parent
$monthDate = $_POST['month_date'];
try {
$pdo->beginTransaction();
$stmtP = $pdo->prepare("SELECT name FROM pf_people WHERE id = ?");
$stmtP->execute([$personId]);
$dbPersonName = $stmtP->fetchColumn();
if (!$dbPersonName) throw new Exception("Parent introuvable.");
$stmtAcc = $pdo->query("SELECT a.name as acc_name, p.name as owner_name FROM pf_bank_accounts a LEFT JOIN pf_people p ON a.owner_person_id = p.id");
$bankAccountsMap = [];
// Fallback intelligent : on récupère tous les prénoms de la famille
$familyNames = $pdo->query("SELECT name FROM pf_people")->fetchAll(PDO::FETCH_COLUMN);
while ($row = $stmtAcc->fetch(PDO::FETCH_ASSOC)) {
$owner = $row['owner_name'];
if (!$owner) {
// Si pas de propriétaire explicite, on cherche un prénom dans le nom du compte (ex: "Livret A Alex")
foreach ($familyNames as $pName) {
if (stripos($row['acc_name'], $pName) !== false) {
$owner = $pName;
break;
}
}
}
$bankAccountsMap['vers ' . $row['acc_name']] = $owner;
}
$stmt = $pdo->prepare("
SELECT v.amount, c.name as cat_name, c.transfer_dest, c.holiday_id
FROM pf_alloc_values v
JOIN pf_alloc_categories c ON v.cat_id = c.id
WHERE v.month_date = ? AND v.person_id = ?
");
$stmt->execute([$monthDate, $personId]);
$budgetLines = $stmt->fetchAll(PDO::FETCH_ASSOC);
$transfersToDo = [];
foreach ($budgetLines as $line) {
$amount = (float)$line['amount'];
if ($amount <= 0) continue;
$dest = trim($line['transfer_dest']);
$catName = trim($line['cat_name']);
$holidayId = $line['holiday_id'];
$targetOwner = null;
if (isset($bankAccountsMap[$dest])) {
$targetOwner = $bankAccountsMap[$dest];
if (!$targetOwner) continue; // Compte commun sans propriétaire
} elseif ($dest === 'vers L.Perso') { $targetOwner = $dbPersonName; }
elseif ($dest === 'vers L.Pol') { $targetOwner = 'Pol'; }
elseif ($dest === 'vers L.Pep') { $targetOwner = 'Pep'; }
elseif ($dest === 'vers commune') { continue; }
if ($targetOwner) {
if (!isset($transfersToDo[$targetOwner])) {
$transfersToDo[$targetOwner] = ['total_add' => 0, 'cats' => []];
}
$transfersToDo[$targetOwner]['total_add'] += $amount;
if (!isset($transfersToDo[$targetOwner]['cats'][$catName])) {
$transfersToDo[$targetOwner]['cats'][$catName] = ['amount' => 0, 'holiday_id' => $holidayId];
}
$transfersToDo[$targetOwner]['cats'][$catName]['amount'] += $amount;
}
}
foreach ($transfersToDo as $owner => $data) {
$stmtCheck = $pdo->prepare("SELECT COUNT(*) FROM pf_savings WHERE owner = ? AND month_date = ? AND category = 'TOTAL_BANQUE'");
$stmtCheck->execute([$owner, $monthDate]);
$exists = $stmtCheck->fetchColumn() > 0;
if (!$exists) {
$prevDate = date('Y-m-d', strtotime($monthDate . ' -1 month'));
$stmtPrev = $pdo->prepare("SELECT category, amount, holiday_id FROM pf_savings WHERE owner = ? AND month_date = ?");
$stmtPrev->execute([$owner, $prevDate]);
$prevLines = $stmtPrev->fetchAll(PDO::FETCH_ASSOC);
if (empty($prevLines)) { $prevLines = [['category' => 'TOTAL_BANQUE', 'amount' => 0, 'holiday_id' => null]]; }
$stmtInsert = $pdo->prepare("INSERT INTO pf_savings (month_date, owner, category, amount, holiday_id) VALUES (?, ?, ?, ?, ?)");
foreach ($prevLines as $row) {
$stmtInsert->execute([$monthDate, $owner, $row['category'], $row['amount'], $row['holiday_id']]);
}
}
$stmtUpdTotal = $pdo->prepare("UPDATE pf_savings SET amount = amount + ? WHERE owner = ? AND month_date = ? AND category = 'TOTAL_BANQUE'");
$stmtUpdTotal->execute([$data['total_add'], $owner, $monthDate]);
foreach ($data['cats'] as $catName => $catInfo) {
$catAmount = $catInfo['amount'];
$catHolidayId = $catInfo['holiday_id'];
if (preg_match('/^(Eco\s|Eco P\d|Livret)/i', $catName)) { continue; }
$stmtCheckCat = $pdo->prepare("SELECT id FROM pf_savings WHERE owner = ? AND month_date = ? AND category = ?");
$stmtCheckCat->execute([$owner, $monthDate, $catName]);
$catId = $stmtCheckCat->fetchColumn();
if ($catId) {
$stmtUpdateCat = $pdo->prepare("UPDATE pf_savings SET amount = amount + ?, holiday_id = ? WHERE id = ?");
$stmtUpdateCat->execute([$catAmount, $catHolidayId, $catId]);
} else {
$stmtInsertCat = $pdo->prepare("INSERT INTO pf_savings (month_date, owner, category, amount, holiday_id) VALUES (?, ?, ?, ?, ?)");
$stmtInsertCat->execute([$monthDate, $owner, $catName, $catAmount, $catHolidayId]);
}
}
}
$stmtSys = $pdo->prepare("SELECT id FROM pf_alloc_categories WHERE name = 'SYSTEM_VALIDATION' LIMIT 1");
$stmtSys->execute();
$sysCatId = $stmtSys->fetchColumn();
if ($sysCatId) {
$stmtVal = $pdo->prepare("INSERT INTO pf_alloc_values (month_date, cat_id, person_id, amount)
VALUES (?, ?, ?, 1)
ON DUPLICATE KEY UPDATE amount = 1");
$stmtVal->execute([$monthDate, $sysCatId, $personId]);
}
$pdo->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
$pdo->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// =================================================================
// 7. GESTION DES AVANCES / TRICOUNT (pf_advances)
// =================================================================
if ($action === 'save_advance') {
header('Content-Type: application/json');
try {
$payer = trim($_POST['payer'] ?? '');
$advance_date = $_POST['advance_date'] ?? date('Y-m-d');
$description = trim($_POST['description'] ?? '');
$amount = abs((float)($_POST['amount'] ?? 0));
$from_savings = isset($_POST['from_savings']) ? 1 : 0;
if (empty($payer) || empty($description) || $amount <= 0) {
throw new Exception("Champs obligatoires manquants ou invalides.");
}
$stmt = $pdo->prepare("INSERT INTO pf_advances (advance_date, payer, description, amount, from_savings) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$advance_date, $payer, $description, $amount, $from_savings]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
if ($action === 'update_advance') {
header('Content-Type: application/json');
try {
$id = (int)($_POST['id'] ?? 0);
$payer = trim($_POST['payer'] ?? '');
$advance_date = $_POST['advance_date'] ?? date('Y-m-d');
$description = trim($_POST['description'] ?? '');
$amount = abs((float)($_POST['amount'] ?? 0));
$from_savings = isset($_POST['from_savings']) ? 1 : 0;
if ($id <= 0 || empty($payer) || empty($description) || $amount <= 0) {
throw new Exception("Paramètres invalides fournis.");
}
$stmt = $pdo->prepare("UPDATE pf_advances SET advance_date = ?, payer = ?, description = ?, amount = ?, from_savings = ? WHERE id = ?");
$stmt->execute([$advance_date, $payer, $description, $amount, $from_savings, $id]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
if ($action === 'resolve_advance') {
header('Content-Type: application/json');
try {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) throw new Exception("ID invalide fourni.");
$stmt = $pdo->prepare("UPDATE pf_advances SET is_resolved = 1 WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
if ($action === 'delete_advance') {
header('Content-Type: application/json');
try {
$id = (int)($_POST['id'] ?? 0);
if ($id <= 0) throw new Exception("ID invalide.");
$stmt = $pdo->prepare("DELETE FROM pf_advances WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
@@ -0,0 +1,164 @@
<?php
require __DIR__ . '/../../../../includes/auth.php';
require __DIR__ . '/../../../../includes/db.php';
require_login();
// 1. Déclaration propre des variables d'entrée
$action = $_POST['action'] ?? '';
$isAjax = !empty($_POST['ajax']);
// Si c'est de l'AJAX, on force les en-têtes HTTP pour garantir du JSON
if ($isAjax) {
header('Content-Type: application/json; charset=utf-8');
}
// =================================================================
// MISE À JOUR D'UNE CELLULE EN DIRECT (AJAX)
// =================================================================
if ($action === 'update_single_entry') {
$month = $_POST['month_date'] ?? '';
$cat = $_POST['category'] ?? '';
$owner = $_POST['owner'] ?? '';
$amount = (float)($_POST['amount'] ?? 0);
$forceInsert = !empty($_POST['force_insert']);
try {
// On supprime la ligne si elle est à 0, SAUF si on demande explicitement son initialisation (force_insert)
if ($amount == 0 && $cat !== 'TOTAL_BANQUE' && !$forceInsert) {
$stmt = $pdo->prepare("DELETE FROM pf_savings WHERE month_date=? AND owner=? AND category=?");
$stmt->execute([$month, $owner, $cat]);
} else {
$stmt = $pdo->prepare("INSERT INTO pf_savings (month_date, owner, category, amount) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE amount = VALUES(amount)");
$stmt->execute([$month, $owner, $cat, $amount]);
}
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// --- ACTION : SUPPRESSION D'UNE ENTRÉE UNIQUE ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'delete_entry') {
$owner = $_POST['owner'] ?? '';
$date = $_POST['month_date'] ?? '';
$cat = $_POST['category'] ?? '';
$stmt = $pdo->prepare("DELETE FROM pf_savings WHERE owner = ? AND month_date = ? AND category = ?");
$stmt->execute([$owner, $date, $cat]);
echo json_encode(['success' => true]);
exit;
}
// --- ACTION : DUPLICATION DE MOIS ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'duplicate_month') {
$owner = $_POST['owner'] ?? '';
$sourceDate = $_POST['source_date'] ?? '';
$targetDate = $_POST['target_date'] ?? '';
$newTotal = floatval($_POST['new_total'] ?? 0);
try {
$pdo->beginTransaction();
// 1. Vérifier si le mois cible existe déjà
$check = $pdo->prepare("SELECT id FROM pf_savings WHERE owner = ? AND month_date = ? LIMIT 1");
$check->execute([$owner, $targetDate]);
if ($check->fetch()) {
echo json_encode(['success' => false, 'error' => 'Ce mois existe déjà !']);
exit;
}
// 2. Insérer le nouveau TOTAL BANQUE
$stmtIns = $pdo->prepare("INSERT INTO pf_savings (owner, month_date, category, amount) VALUES (?, ?, ?, ?)");
$stmtIns->execute([$owner, $targetDate, 'TOTAL_BANQUE', $newTotal]);
// 3. Copier toutes les catégories (sauf TOTAL_BANQUE) du mois source
$sqlCopy = "INSERT INTO pf_savings (owner, month_date, category, amount)
SELECT owner, ?, category, amount
FROM pf_savings
WHERE owner = ? AND month_date = ? AND category != 'TOTAL_BANQUE'";
$stmtCopy = $pdo->prepare($sqlCopy);
$stmtCopy->execute([$targetDate, $owner, $sourceDate]);
$pdo->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// --- ACTION : SUPPRESSION GLOBALE D'UN MOIS ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $action === 'delete_month_global') {
$owner = $_POST['owner'] ?? '';
$date = $_POST['month_date'] ?? '';
try {
$stmt = $pdo->prepare("DELETE FROM pf_savings WHERE owner = ? AND month_date = ?");
$stmt->execute([$owner, $date]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
exit;
}
// --- ACTION : SAUVEGARDE CLASSIQUE (MODALE) ---
// Cette action s'exécute si c'est un POST général sans action précise (le form HTML) ou l'action explicitement nommée.
if ($_SERVER['REQUEST_METHOD'] === 'POST' && in_array($action, ['save_modal', ''])) {
$owner = $_POST['owner'] ?? '';
$redirectTab = $_POST['redirect_tab'] ?? $owner;
$dateInput = $_POST['month_date'] ?? '';
$values = $_POST['values'] ?? []; // Tableau généré par nos champs JS: values[Catégorie]
try {
$dateObj = new DateTime($dateInput);
$monthDate = $dateObj->format('Y-m-01');
$pdo->beginTransaction();
// On supprime d'abord les anciennes données du mois pour cet utilisateur
$stmtDel = $pdo->prepare("DELETE FROM pf_savings WHERE owner = ? AND month_date = ?");
$stmtDel->execute([$owner, $monthDate]);
// On réinsère les nouvelles données
$stmtIns = $pdo->prepare("INSERT INTO pf_savings (owner, month_date, category, amount) VALUES (?, ?, ?, ?)");
foreach ($values as $category => $amount) {
$amount = floatval($amount);
// On enregistre si c'est positif OU si c'est le total banque
if ($amount > 0 || $category === 'TOTAL_BANQUE') {
$stmtIns->execute([$owner, $monthDate, $category, $amount]);
}
}
$pdo->commit();
// On répond proprement selon le contexte (AJAX ou Fallback classique)
if ($isAjax) {
echo json_encode(['success' => true]);
} else {
header("Location: /budget.php?tab=epargne&owner=" . urlencode($redirectTab));
}
exit;
} catch (Exception $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
if ($isAjax) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
} else {
die("Erreur : " . $e->getMessage());
}
exit;
}
}
// Sécurité finale : Si l'action n'est pas reconnue
if ($isAjax) {
echo json_encode(['success' => false, 'error' => 'Action inconnue']);
exit;
}
+231
View File
@@ -0,0 +1,231 @@
<?php
require __DIR__ . '/../../../../includes/auth.php';
require __DIR__ . '/../../../../includes/db.php';
require_once __DIR__ . '/../../../../includes/i18n.php';
require_login();
header('Content-Type: application/json');
$action = $_GET['action'] ?? $_POST['action'] ?? '';
try {
if ($action === 'get_all') {
// 1. Comptes bancaires avec le nom du propriétaire lié (pf_people)
$accounts = $pdo->query("
SELECT a.*, p.name as owner_name
FROM pf_bank_accounts a
LEFT JOIN pf_people p ON a.owner_person_id = p.id
ORDER BY a.is_default DESC, a.name ASC
")->fetchAll(PDO::FETCH_ASSOC);
// 2. Catégories
$categories = $pdo->query("SELECT * FROM pf_budget_categories ORDER BY type ASC, label ASC")->fetchAll(PDO::FETCH_ASSOC);
// 3. Règles d'import
$rules = $pdo->query("
SELECT r.*, c.label as cat_label
FROM pf_import_rules r
LEFT JOIN pf_budget_categories c ON r.category COLLATE utf8mb4_unicode_ci = c.code COLLATE utf8mb4_unicode_ci
ORDER BY r.keyword ASC
")->fetchAll(PDO::FETCH_ASSOC);
// 4. Salaires (Année en cours)
$currentYear = (int)date('Y');
$salaries = $pdo->query("
SELECT p.name as person,
COALESCE(s.salary, 0) as salary,
COALESCE(s.mensualite, 0) as mensualite,
s.id as id
FROM pf_people p
LEFT JOIN pf_salary_config s ON p.name = s.person AND s.year = $currentYear
WHERE p.role NOT IN ('enfant', 'nounou') AND p.is_active = 1
ORDER BY p.name ASC
")->fetchAll(PDO::FETCH_ASSOC);
// 5. Paramètres Foyer (Devise + Mapping CSV)
$foyerData = $pdo->query("SELECT currency, csv_mapping FROM pf_foyer_settings LIMIT 1")->fetch(PDO::FETCH_ASSOC);
$currencySetting = $foyerData['currency'] ?? '€';
$csvMapping = !empty($foyerData['csv_mapping']) ? json_decode($foyerData['csv_mapping'], true) : null;
// --- NOUVEAU : Récupération des paramètres dynamiques ---
$stmtSettings = $pdo->query("SELECT setting_key, setting_value FROM pf_settings WHERE module = 'budget'");
$budgetSettings = $stmtSettings->fetchAll(PDO::FETCH_KEY_PAIR);
// 6. Liste des membres (pour assigner un compte bancaire)
$people = $pdo->query("SELECT id, name FROM pf_people WHERE is_active = 1 ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'data' => [
'accounts' => $accounts,
'categories' => $categories,
'rules' => $rules,
'salaries' => $salaries,
'people' => $people,
'year' => $currentYear,
'currency' => $currencySetting,
'csv_mapping' => $csvMapping,
'budget_settings' => $budgetSettings
]
]);
exit;
}
// --- GESTION DES COMPTES BANCAIRES ---
if ($action === 'add_account') {
$name = trim($_POST['name'] ?? '');
$type = $_POST['type'] ?? 'checking';
$owner_id = !empty($_POST['owner_person_id']) ? (int)$_POST['owner_person_id'] : null;
if (empty($name)) throw new Exception("Le nom du compte est obligatoire.");
$stmt = $pdo->prepare("INSERT INTO pf_bank_accounts (name, account_type, is_default, owner_person_id) VALUES (?, ?, 0, ?)");
$stmt->execute([$name, $type, $owner_id]);
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_account') {
$id = (int)($_POST['id'] ?? 0);
$count = $pdo->query("SELECT COUNT(*) FROM pf_bank_accounts")->fetchColumn();
if ($count <= 1) throw new Exception("Impossible de supprimer le dernier compte.");
$stmt = $pdo->prepare("DELETE FROM pf_bank_accounts WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DES CATÉGORIES ---
if ($action === 'add_category') {
$code = strtoupper(trim($_POST['code'] ?? ''));
$label = trim($_POST['label'] ?? '');
$type = $_POST['type'] ?? 'Expense';
$color = $_POST['color'] ?? '#cccccc';
$icon = trim($_POST['icon'] ?? '📌');
if (empty($code) || empty($label)) throw new Exception("Le code et le libellé sont obligatoires.");
$check = $pdo->prepare("SELECT COUNT(*) FROM pf_budget_categories WHERE code = ?");
$check->execute([$code]);
if ($check->fetchColumn() > 0) throw new Exception("Ce code de catégorie existe déjà.");
$stmt = $pdo->prepare("INSERT INTO pf_budget_categories (code, label, type, color, icon) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$code, $label, $type, $color, $icon]);
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_category') {
$id = (int)($_POST['id'] ?? 0);
$stmtCheck = $pdo->prepare("SELECT code FROM pf_budget_categories WHERE id = ?");
$stmtCheck->execute([$id]);
$catCode = $stmtCheck->fetchColumn();
if ($catCode && in_array(strtoupper($catCode), ['FIXED', 'INCOME'])) {
throw new Exception(tr('bud_err_delete_system_cat'));
}
$stmt = $pdo->prepare("DELETE FROM pf_budget_categories WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DES RÈGLES D'IMPORT ---
if ($action === 'add_rule') {
$keyword = strtoupper(trim($_POST['keyword'] ?? ''));
$category = trim($_POST['category'] ?? '');
if (empty($keyword) || empty($category)) throw new Exception("Le mot-clé et la catégorie sont obligatoires.");
$check = $pdo->prepare("SELECT COUNT(*) FROM pf_import_rules WHERE keyword = ?");
$check->execute([$keyword]);
if ($check->fetchColumn() > 0) throw new Exception("Une règle pour ce mot-clé existe déjà.");
$stmt = $pdo->prepare("INSERT INTO pf_import_rules (keyword, category) VALUES (?, ?)");
$stmt->execute([$keyword, $category]);
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_rule') {
$id = (int)($_POST['id'] ?? 0);
$stmt = $pdo->prepare("DELETE FROM pf_import_rules WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DES SALAIRES ---
if ($action === 'save_salary') {
$id = (int)($_POST['id'] ?? 0);
$salary = (float)($_POST['salary'] ?? 0);
$mensualite = (float)($_POST['mensualite'] ?? 0);
if ($id <= 0) throw new Exception("ID de configuration de salaire invalide.");
$stmt = $pdo->prepare("UPDATE pf_salary_config SET salary = ?, mensualite = ? WHERE id = ?");
$stmt->execute([$salary, $mensualite, $id]);
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DE LA DEVISE GLOBALE ---
if ($action === 'save_currency') {
$currency = trim($_POST['currency'] ?? '€');
$stmt = $pdo->prepare("UPDATE pf_foyer_settings SET currency = ?");
$stmt->execute([$currency]);
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DU FORMAT CSV ---
if ($action === 'save_csv_mapping') {
$mapping = [
'delimiter' => $_POST['csv_delimiter'] ?? ';',
'date_format' => $_POST['csv_date_format'] ?? 'd/m/Y',
'col_date' => (int)($_POST['csv_col_date'] ?? 0),
'col_label' => (int)($_POST['csv_col_label'] ?? 1),
'amount_type' => $_POST['csv_amount_type'] ?? 'single',
'col_debit' => (int)($_POST['csv_col_debit'] ?? 8),
'col_credit' => (int)($_POST['csv_col_credit'] ?? 9),
'col_ref' => (int)($_POST['csv_col_ref'] ?? 3)
];
$jsonContent = json_encode($mapping);
$stmt = $pdo->prepare("UPDATE pf_foyer_settings SET csv_mapping = ?");
$stmt->execute([$jsonContent]);
echo json_encode(['success' => true]);
exit;
}
// SAUVEGARDE DU NOUVEL ORDRE DES CATÉGORIES
if (isset($_POST['action']) && $_POST['action'] === 'save_categories_order') {
$ids = json_decode($_POST['order'], true);
if (is_array($ids)) {
$stmt = $pdo->prepare("UPDATE pf_budget_categories SET sort_order = ? WHERE id = ?");
foreach ($ids as $index => $id) {
$stmt->execute([$index, (int)$id]);
}
}
echo json_encode(['success' => true]);
exit;
}
// --- GESTION DES ESTIMATIONS DYNAMIQUES ---
if ($action === 'save_dynamic_estimates') {
$keys = [
'budget_nanny_fixed', 'budget_nanny_daily', 'budget_nanny_aid', 'budget_nanny_cesu_avg',
'budget_school_meal', 'budget_school_aftercare', 'budget_school_fullday'
];
$pdo->beginTransaction();
$stmt = $pdo->prepare("INSERT INTO pf_settings (setting_key, setting_value, module) VALUES (?, ?, 'budget') ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value), updated_at = NOW()");
foreach ($keys as $k) {
if (isset($_POST[$k])) {
$stmt->execute([$k, $_POST[$k]]);
}
}
$pdo->commit();
echo json_encode(['success' => true]);
exit;
}
throw new Exception("Action API inconnue.");
} catch (\Throwable $e) {
http_response_code(400);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
?>
File diff suppressed because it is too large. Load diff
+610
View File
@@ -0,0 +1,610 @@
<?php
// modules/budget/views/epargne.php
// --- 🧠 CONFIGURATION AGNOSTIQUE DES MEMBRES (MULTI-TENANT) ---
$stmtPeople = $pdo->query("SELECT name, role, color FROM pf_people ORDER BY id ASC");
$familyParents = [];
$familyKids = [];
$personColors = [];
while ($row = $stmtPeople->fetch(PDO::FETCH_ASSOC)) {
$role = strtolower(trim($row['role'] ?? ''));
$personColors[$row['name']] = $row['color'] ?? '#3b82f6';
if ($role === 'parent') {
$familyParents[] = $row['name'];
} elseif ($role === 'nounou' || $role === 'helper') {
continue;
} else {
$familyKids[] = $row['name'];
}
}
if (empty($familyParents)) $familyParents = ['Parent 1', 'Parent 2'];
$requestedOwner = $_GET['owner'] ?? (!empty($familyKids) ? 'KIDS' : ($familyParents[0] ?? 'KIDS'));
$ownersToDisplay = ($requestedOwner === 'KIDS') ? $familyKids : [$requestedOwner];
// --- RÉCUPÉRATION CONFIGURATION DES MOIS ---
$cycleConfigs = [];
$stmtNotes = $pdo->query("SELECT reference_id, content FROM pf_notes WHERE note_type = 'month_config'");
while ($row = $stmtNotes->fetch(PDO::FETCH_ASSOC)) {
$parts = explode('-', $row['reference_id']);
if (count($parts) == 2) {
$mKey = $parts[1] . '-' . $parts[0] . '-01';
$cycleConfigs[$mKey] = json_decode($row['content'], true);
}
}
function getMonthName($dateString) {
$m = date('m', strtotime($dateString));
$y = date('Y', strtotime($dateString));
return tr('month_' . $m) . ' ' . $y;
}
?>
<div class="budget-view">
<div class="view-header">
<div class="owner-tabs">
<?php if (!empty($familyKids)): ?>
<a href="?tab=epargne&owner=KIDS" class="owner-tab <?= $requestedOwner === 'KIDS' ? 'active' : '' ?>">
<?= tr('budget_tab_kids') ?>
</a>
<?php endif; ?>
<?php foreach ($familyParents as $p): ?>
<a href="?tab=epargne&owner=<?= urlencode($p) ?>" class="owner-tab <?= $requestedOwner === $p ? 'active' : '' ?>">
<?= htmlspecialchars($p) ?>
</a>
<?php endforeach; ?>
</div>
</div>
<?php foreach ($ownersToDisplay as $index => $currentOwner):
$stmt = $pdo->prepare("SELECT month_date, category, amount FROM pf_savings WHERE owner = ? ORDER BY month_date DESC");
$stmt->execute([$currentOwner]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data = [];
$months = [];
$allCategories = [];
foreach ($rows as $row) {
$m = $row['month_date'];
$cat = $row['category'];
$val = $row['amount'];
$data[$m][$cat] = $val;
if (!in_array($m, $months)) $months[] = $m;
if ($cat !== 'TOTAL_BANQUE' && !in_array($cat, $allCategories)) $allCategories[] = $cat;
}
$months = array_slice($months, 0, 7);
sort($allCategories);
$safeOwnerCls = htmlspecialchars(str_replace(' ', '_', $currentOwner), ENT_QUOTES);
$ownerColor = $personColors[$currentOwner] ?? '#1e293b';
?>
<div class="epargne-header-bar <?= ($requestedOwner === 'KIDS' && $index > 0) ? 'pf-mt-40' : '' ?>">
<div class="pf-flex-1">
<?php if ($requestedOwner === 'KIDS'): ?>
<h3 class="nens-title" style="--owner-color: <?= htmlspecialchars($ownerColor) ?>;">
<?= htmlspecialchars($currentOwner) ?>
</h3>
<?php endif; ?>
</div>
<div class="pf-flex-gap-12-center">
<?php if (!empty($months)): ?>
<button onclick="duplicateLastMonth('<?= $months[0] ?>', '<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>')" class="pf-btn btn-secondary">
🔁 <?= tr('bud_sav_add_one_month') ?>
</button>
<button onclick="promptNewSavingsLine('<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>', '<?= $months[0] ?>')" class="pf-btn">
+ <?= tr('bud_sav_new_line') ?>
</button>
<?php else: ?>
<button onclick="openCustomSavingsModal('<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>')" class="pf-btn">
+ <?= tr('bud_sav_add_month') ?>
</button>
<?php endif; ?>
</div>
</div>
<div class="table-responsive pf-card-epargne">
<?php if (empty($months)): ?>
<div class="pf-empty-dashed">
<p><?= sprintf(tr('bud_sav_no_data'), htmlspecialchars($currentOwner)) ?></p>
</div>
<?php else: ?>
<div class="epargne-grid-table" style="--cols: <?= count($months) ?>; --owner-color: <?= htmlspecialchars($ownerColor) ?>;">
<div class="eg-header-row">
<div class="eg-cell eg-sticky"><?= tr('bud_sav_post_month') ?></div>
<?php foreach ($months as $month): ?>
<div class="eg-cell">
<div class="month-header-container">
<div class="month-header-title">
<span class="month-name text-inherit"><?= getMonthName($month) ?></span>
<?php
if (isset($cycleConfigs[$month]) && !empty($cycleConfigs[$month]['start_date'])) {
$cStart = date('d/m', strtotime($cycleConfigs[$month]['start_date']));
echo "<span class='month-cycle-start'>" . sprintf(tr('bud_sav_from_date'), $cStart) . "</span>";
}
?>
</div>
<div class="month-actions">
<button class="btn-icon-small btn-safe-click" title="<?= tr('bud_sav_edit_modal') ?>"
data-json="<?= htmlspecialchars(json_encode($data[$month] ?? []), ENT_QUOTES, 'UTF-8') ?>"
onclick='editCustomSavingsMonth("<?= $month ?>", "<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>", JSON.parse(this.getAttribute("data-json")))'>
✏️
</button>
<button class="btn-icon-small btn-safe-click btn-danger-soft" title="<?= tr('bud_sav_delete_month') ?>"
onclick="deleteEntireMonth('<?= $month ?>', '<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>')">
🗑️
</button>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="eg-row eg-total-row">
<div class="eg-cell eg-sticky"><strong><?= tr('bud_sav_total_bank') ?></strong></div>
<?php foreach ($months as $month):
$val = $data[$month]['TOTAL_BANQUE'] ?? 0;
?>
<div class="eg-cell">
<div class="eg-cell-content">
<input type="number" step="0.01"
class="prev-input eg-input eg-input-total total-input-<?= $safeOwnerCls ?>-<?= $month ?>"
value="<?= $val != 0 ? round($val) : '' ?>"
placeholder="0"
onchange="updateEpargneCell('<?= $month ?>', 'TOTAL_BANQUE', '<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>', this)">
<span class="eg-currency-symbol">€</span>
</div>
</div>
<?php endforeach; ?>
</div>
<?php foreach ($allCategories as $cat): ?>
<div class="eg-row">
<div class="eg-cell eg-sticky"><?= htmlspecialchars($cat) ?></div>
<?php foreach ($months as $month):
$amount = $data[$month][$cat] ?? 0;
?>
<div class="eg-cell">
<input type="number" step="0.01"
class="prev-input eg-input cat-input-<?= $safeOwnerCls ?>-<?= $month ?>"
value="<?= $amount != 0 ? round($amount) : '' ?>"
placeholder="-"
onchange="updateEpargneCell('<?= $month ?>', '<?= htmlspecialchars($cat, ENT_QUOTES) ?>', '<?= htmlspecialchars($currentOwner, ENT_QUOTES) ?>', this)">
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
<div class="eg-row eg-extres-row">
<div class="eg-cell eg-sticky"><strong><?= tr('bud_sav_extra') ?></strong></div>
<?php foreach ($months as $month):
$total = $data[$month]['TOTAL_BANQUE'] ?? 0;
$sum = 0;
foreach ($allCategories as $cat) $sum += ($data[$month][$cat] ?? 0);
$extra = $total - $sum;
?>
<div class="eg-cell font-bold sum-target <?= $extra >= 0 ? 'text-success' : 'text-danger' ?>" id="extra_<?= $safeOwnerCls ?>_<?= $month ?>">
<?= number_format($extra, 0, ',', ' ') ?> €
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div id="savingsModal" class="pf-modal">
<div class="pf-modal-content modal-epargne">
<div class="pf-modal-header">
<h3 id="savingsModalTitle" class="pf-modal-title"><?= tr('bud_sav_modal_title_add') ?></h3>
<button type="button" onclick="document.getElementById('savingsModal').classList.remove('open'); document.body.classList.remove('no-scroll');" class="pf-modal-close">&times;</button>
</div>
<form action="/modules/budget/includes/api/save-savings.php" method="POST" id="savingsForm">
<input type="hidden" name="owner" id="sav_owner">
<input type="hidden" name="redirect_tab" id="redirect_tab" value="<?= htmlspecialchars($requestedOwner) ?>">
<input type="hidden" name="month_date" id="sav_date_hidden">
<div class="pf-form-row">
<div class="pf-form-group pf-flex-1 pf-m-0">
<label class="pf-label"><?= tr('bud_sav_month_concerned') ?></label>
<input type="month" id="sav_month" required class="pf-input">
</div>
<div class="pf-form-group pf-flex-1 pf-m-0">
<label class="pf-label"><?= tr('bud_sav_total_bank_eur') ?></label>
<input type="number" step="0.01" name="values[TOTAL_BANQUE]" id="sav_total" required class="pf-input no-spinners pf-input-total">
</div>
</div>
<hr class="pf-divider">
<div class="ventilation-header">
<div>
<h4 class="pf-m-0 text-main"><?= tr('bud_sav_ventilation') ?></h4>
<span class="pf-muted-note"><?= tr('bud_sav_adj_help') ?></span>
</div>
<button type="button" class="pf-btn btn-secondary pf-btn-sm" onclick="addCustomEpargneLine()">+ <?= tr('bud_sav_add_line') ?></button>
</div>
<div class="ventilation-cols">
<div class="vl-col-name"><?= tr('bud_category') ?></div>
<div class="vl-col-base"><?= tr('bud_sav_current') ?></div>
<div class="vl-col-adj"><?= tr('bud_sav_adjust') ?></div>
<div class="vl-col-final"><?= tr('bud_sav_new') ?></div>
<div class="vl-col-btn"></div>
</div>
<div id="linesContainer" class="ventilation-list"></div>
<div class="modal-footer">
<button type="button" onclick="document.getElementById('savingsModal').classList.remove('open'); document.body.classList.remove('no-scroll');" class="pf-btn btn-secondary"><?= tr('btn_cancel') ?></button>
<button type="submit" class="pf-btn"><?= tr('btn_save') ?></button>
</div>
</form>
</div>
</div>
<button id="fabSumMode" class="pf-fab-sum" onclick="toggleSumMode()" title="<?= tr('bud_sav_sum_mode_title') ?>">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M18 4H6a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"></path><line x1="8" y1="12" x2="16" y2="12"></line><line x1="12" y1="8" x2="12" y2="16"></line></svg>
</button>
<div id="sumResultBar" class="pf-sum-bar">
<span class="pf-sum-label"><?= tr('bud_sav_selection') ?></span>
<span id="sumResultValue" class="pf-sum-value">0 €</span>
<button onclick="toggleSumMode()" class="pf-sum-close" title="<?= tr('btn_close') ?>">&times;</button>
</div>
<script>
window.appLang = document.documentElement.lang === "ca" ? "ca-ES" : "fr-FR";
window.I18N = {
...(window.I18N || {}),
'bud_sav_modal_title_add': <?= json_encode(tr('bud_sav_modal_title_add')) ?>,
'bud_sav_modal_title_edit': <?= json_encode(tr('bud_sav_modal_title_edit')) ?>,
'bud_sav_ph_name': <?= json_encode(tr('bud_sav_ph_name')) ?>,
'bud_sav_confirm_delete_month': <?= json_encode(tr('bud_sav_confirm_delete_month')) ?>,
'bud_sav_prompt_duplicate': <?= json_encode(tr('bud_sav_prompt_duplicate')) ?>,
'bud_sav_prompt_new_line': <?= json_encode(tr('bud_sav_prompt_new_line')) ?>,
'bud_err_tech': <?= json_encode(tr('bud_err_tech')) ?>,
'bud_err_server': <?= json_encode(tr('bud_err_server')) ?>,
'bud_err_network_dup': <?= json_encode(tr('bud_err_network_dup')) ?>,
'bud_sav_saving': <?= json_encode(tr('bud_sav_saving')) ?>,
'bud_err_delete': <?= json_encode(tr('bud_err_delete')) ?>,
'btn_delete': <?= json_encode(tr('btn_delete')) ?>
};
const systemCurrency = (typeof window.CONFIG !== 'undefined' && window.CONFIG.CURRENCY) ? window.CONFIG.CURRENCY : '€';
const cycleConfigs = <?= json_encode($cycleConfigs ?? []) ?>;
async function promptNewSavingsLine(owner, latestMonth) {
const catName = prompt(window.I18N['bud_sav_prompt_new_line']);
if (!catName || catName.trim() === "") return;
const formData = new FormData();
formData.append('action', 'update_single_entry');
formData.append('month_date', latestMonth);
formData.append('category', catName.trim());
formData.append('owner', owner);
formData.append('amount', 0);
formData.append('force_insert', '1'); // 🛡️ Empêche la suppression auto par l'API
formData.append('ajax', '1');
try {
const result = await pachaFetch('/modules/budget/includes/api/save-savings.php', {
method: 'POST',
body: formData
});
if (result.success) {
window.location.reload();
} else {
showToast(window.I18N['bud_err_tech'] + " : " + (result.error || "Erreur"), 'error');
}
} catch (err) {
showToast(window.I18N['bud_err_tech'], 'error');
}
}
async function updateEpargneCell(month, category, owner, inputEl) {
const val = parseFloat(inputEl.value) || 0;
const formData = new FormData();
formData.append('action', 'update_single_entry');
formData.append('month_date', month);
formData.append('category', category);
formData.append('owner', owner);
formData.append('amount', val);
formData.append('ajax', '1');
try {
const result = await pachaFetch('/modules/budget/includes/api/save-savings.php', { method: 'POST', body: formData });
if (!result.success) {
alert(window.I18N['bud_err_tech'] + " : " + (result.error || "Erreur serveur"));
return;
}
} catch (err) {
showToast(window.I18N['bud_err_tech'], 'error');
return;
}
const safeOwnerClass = owner.replace(/\s+/g, '_');
const totalInput = document.querySelector(`.total-input-${CSS.escape(safeOwnerClass)}-${month}`);
const totalVal = parseFloat(totalInput ? totalInput.value : 0) || 0;
let sumCats = 0;
document.querySelectorAll(`.cat-input-${CSS.escape(safeOwnerClass)}-${month}`).forEach(inp => {
sumCats += parseFloat(inp.value) || 0;
});
const extra = totalVal - sumCats;
const extraCell = document.getElementById(`extra_${safeOwnerClass}_${month}`);
if (extraCell) {
extraCell.innerText = Math.round(extra).toLocaleString(window.appLang) + ' €';
if (extra >= 0) {
extraCell.classList.remove('text-danger');
extraCell.classList.add('text-success');
} else {
extraCell.classList.remove('text-success');
extraCell.classList.add('text-danger');
}
}
if(isSumModeActive) updateSumResult();
}
function addCustomEpargneLine(catName = '', amount = '') {
const container = document.getElementById('linesContainer');
const baseAmount = (amount !== '' && amount !== null) ? parseFloat(amount).toFixed(2) : '0.00';
const inputName = catName ? `values[${catName}]` : '';
const html = `
<div class="ventilation-line">
<div class="vl-col-name">
<input type="text" class="pf-input cat-name-input pf-input-sm" value="${catName}" placeholder="${window.I18N['bud_sav_ph_name'] || 'Catégorie'}" oninput="updateCustomFieldName(this)" required>
</div>
<div class="vl-col-base">
<input type="number" step="0.01" class="pf-input base-amount no-spinners pf-input-sm bg-white" value="${baseAmount}" oninput="recalculateCustomLine(this)">
</div>
<div class="vl-col-adj">
<input type="number" step="0.01" class="pf-input adjustment-amount no-spinners pf-input-sm vl-input-adj" placeholder="+ / -" oninput="recalculateCustomLine(this)">
</div>
<div class="vl-col-final">
<input type="number" step="0.01" name="${inputName}" class="pf-input final-amount no-spinners pf-input-sm vl-input-final" value="${baseAmount}" readonly>
</div>
<button type="button" class="btn-remove-line" onclick="this.parentElement.remove()" title="${window.I18N['btn_delete']}">&times;</button>
</div>
`;
container.insertAdjacentHTML('beforeend', html);
}
function updateCustomFieldName(inputElement) {
const line = inputElement.closest('.ventilation-line');
const finalInput = line.querySelector('.final-amount');
const newName = inputElement.value.trim();
if (newName) finalInput.name = `values[${newName}]`;
else finalInput.name = '';
}
function recalculateCustomLine(inputElement) {
const line = inputElement.closest('.ventilation-line');
const baseInput = line.querySelector('.base-amount');
const adjInput = line.querySelector('.adjustment-amount');
const finalInput = line.querySelector('.final-amount');
const base = parseFloat(baseInput.value) || 0;
const adj = parseFloat(adjInput.value) || 0;
finalInput.value = (base + adj).toFixed(2);
}
function editCustomSavingsMonth(monthDate, owner, rowData) {
document.getElementById('sav_owner').value = owner;
const ym = monthDate.substring(0, 7);
document.getElementById('sav_month').value = ym;
const dateObj = new Date(monthDate);
const monthName = dateObj.toLocaleDateString(window.appLang, { month: 'long', year: 'numeric' });
document.getElementById('savingsModalTitle').innerText = (window.I18N['bud_sav_modal_title_edit'] || 'Editer') + " " + monthName + " (" + owner + ")";
document.getElementById('sav_total').value = rowData['TOTAL_BANQUE'] || '';
const container = document.getElementById('linesContainer');
container.innerHTML = '';
for (const [cat, val] of Object.entries(rowData)) {
if (cat !== 'TOTAL_BANQUE') addCustomEpargneLine(cat, val);
}
if (container.children.length === 0) addCustomEpargneLine();
document.getElementById('savingsModal').classList.add('open');
document.body.classList.add('no-scroll');
}
function openCustomSavingsModal(owner) {
document.getElementById('sav_owner').value = owner;
document.getElementById('sav_month').value = '';
document.getElementById('sav_total').value = '';
document.getElementById('savingsModalTitle').innerText = (window.I18N['bud_sav_modal_title_add'] || 'Ajouter') + " (" + owner + ")";
const container = document.getElementById('linesContainer');
container.innerHTML = '';
addCustomEpargneLine();
document.getElementById('savingsModal').classList.add('open');
document.body.classList.add('no-scroll');
}
const savingsForm = document.getElementById('savingsForm');
if (savingsForm) {
savingsForm.addEventListener('submit', async function(e) {
e.preventDefault();
const ym = document.getElementById('sav_month').value;
if(ym) {
document.getElementById('sav_date_hidden').value = ym + '-01';
}
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.innerText;
submitBtn.innerText = window.I18N['bud_sav_saving'] || 'Sauvegarde...';
submitBtn.disabled = true;
const formData = new FormData(this);
formData.append('ajax', '1');
try {
const result = await pachaFetch('/modules/budget/includes/api/save-savings.php', { method: 'POST', body: formData });
if (result.success) {
window.location.reload();
} else {
alert((window.I18N['bud_err_server'] || 'Erreur serveur : ') + (result.error || "Inconnue"));
submitBtn.innerText = originalText;
submitBtn.disabled = false;
}
} catch (error) {
showToast(window.I18N['bud_err_tech'], 'error');
submitBtn.innerText = originalText;
submitBtn.disabled = false;
}
});
}
async function deleteEntireMonth(monthDate, owner) {
const rawMsg = window.I18N['bud_sav_confirm_delete_month'];
const msg = rawMsg.replace('%m', monthDate).replace('%o', owner);
if (!confirm(msg)) return;
const formData = new FormData();
formData.append("action", "delete_month_global");
formData.append("month_date", monthDate);
formData.append("owner", owner);
formData.append("ajax", "1");
try {
const result = await pachaFetch('/modules/budget/includes/api/save-savings.php', { method: "POST", body: formData });
if (result.success) window.location.reload();
else alert(result.error || window.I18N['bud_err_delete']);
} catch(err) {
showToast(window.I18N['bud_err_tech'], 'error');
}
}
async function duplicateLastMonth(lastMonthDate, owner) {
let dateObj = new Date(lastMonthDate);
dateObj.setMonth(dateObj.getMonth() + 1);
let year = dateObj.getFullYear();
let month = String(dateObj.getMonth() + 1).padStart(2, '0');
let nextMonthStr = `${year}-${month}-01`;
const formatMonth = (d) => {
let str = new Date(d).toLocaleDateString(window.appLang, { month: 'long', year: 'numeric' });
return str.charAt(0).toUpperCase() + str.slice(1);
};
let defaultTotal = "";
if (cycleConfigs[nextMonthStr] && cycleConfigs[nextMonthStr].start_balance !== undefined) {
defaultTotal = cycleConfigs[nextMonthStr].start_balance;
}
const rawMsg = window.I18N['bud_sav_prompt_duplicate'];
const message = rawMsg.replace('%s', formatMonth(lastMonthDate)).replace(/%t[12]/g, formatMonth(nextMonthStr));
let newTotal = prompt(message, defaultTotal);
if (newTotal !== null && newTotal.trim() !== "") {
const formData = new FormData();
formData.append("action", "duplicate_month");
formData.append("source_date", lastMonthDate);
formData.append("target_date", nextMonthStr);
formData.append("new_total", newTotal);
formData.append("owner", owner);
formData.append("ajax", "1");
try {
const result = await pachaFetch('/modules/budget/includes/api/save-savings.php', { method: "POST", body: formData });
if (result.success) {
window.location.reload();
} else {
alert((window.I18N['bud_err_server'] || 'Erreur serveur : ') + (result.error || "Inconnue"));
}
} catch(err) {
alert(window.I18N['bud_err_network_dup']);
}
}
}
// --- CALCULATRICE ---
let isSumModeActive = false;
let selectedElementsForSum = new Set();
function toggleSumMode() {
isSumModeActive = !isSumModeActive;
const fab = document.getElementById('fabSumMode');
const resultBar = document.getElementById('sumResultBar');
if (isSumModeActive) {
fab.classList.add('active');
document.body.classList.add('sum-mode-active');
resultBar.classList.add('visible');
updateSumResult();
} else {
fab.classList.remove('active');
document.body.classList.remove('sum-mode-active');
resultBar.classList.remove('visible');
selectedElementsForSum.forEach(el => el.classList.remove('sum-selected'));
selectedElementsForSum.clear();
}
}
function extractNumberFromText(text) {
if (!text) return 0;
const cleanText = text.replace(',', '.').replace(/[^\d.-]/g, '');
return parseFloat(cleanText) || 0;
}
function updateSumResult() {
let total = 0;
selectedElementsForSum.forEach(el => {
let val = 0;
if (el.tagName === 'INPUT') {
val = parseFloat(el.value) || 0;
} else {
val = extractNumberFromText(el.innerText);
}
total += val;
});
document.getElementById('sumResultValue').innerText = Math.round(total).toLocaleString(window.appLang) + ' ' + systemCurrency;
}
document.addEventListener('click', function(e) {
if (!isSumModeActive) return;
const targetElement = e.target.closest('input[type="number"], .sum-target');
if (targetElement) {
e.preventDefault();
if (selectedElementsForSum.has(targetElement)) {
selectedElementsForSum.delete(targetElement);
targetElement.classList.remove('sum-selected');
} else {
selectedElementsForSum.add(targetElement);
targetElement.classList.add('sum-selected');
}
updateSumResult();
}
}, true);
</script>
+265
View File
@@ -0,0 +1,265 @@
<?php
// modules/budget/views/provisions.php
// --- RÉCUPÉRATION DES DÉPENSES PRÉVUES (MULTI-TENANT PDO) ---
$stmt = $pdo->query("SELECT id, title, amount, expected_date FROM pf_expected_expenses WHERE is_paid = 0 ORDER BY expected_date ASC");
$provisions = $stmt->fetchAll(PDO::FETCH_ASSOC);
// --- RÉCUPÉRATION DES APPORTS ET DETTES (CLEARING) ---
$currentYear = date('Y');
// 1. Apports de base (Eco Family) des parents configurés pour l'année
$stmtConfig = $pdo->prepare("SELECT person, eco_family FROM pf_salary_config WHERE year = ?");
$stmtConfig->execute([$currentYear]);
$configs = $stmtConfig->fetchAll(PDO::FETCH_KEY_PAIR);
// 2. Dettes non résolues par personne (issues des Avances & Tricount)
$stmtDebts = $pdo->query("SELECT payer, SUM(amount) as total_debt FROM pf_advances WHERE is_resolved = 0 GROUP BY payer");
$debts = $stmtDebts->fetchAll(PDO::FETCH_KEY_PAIR);
function formatDate($dateString) {
if (!$dateString) return '';
return date('d/m/Y', strtotime($dateString));
}
?>
<div class="budget-view">
<div class="view-header">
<h2><?= tr('budget_provisions_title') ?></h2>
<button class="pf-btn pf-btn-primary" onclick="openOptimizeModal()">
✨ <?= tr('btn_optimize_cashflow') ?>
</button>
</div>
<div class="pf-card">
<h3 class="pf-card-h2"><?= tr('add_new_provision') ?></h3>
<form id="form-add-provision" data-action="/modules/budget/includes/api/add-provision.php">
<div class="provisions-form-grid">
<div class="pf-form-group">
<label class="pf-label" for="prov-title"><?= tr('provision_label') ?></label>
<input type="text" id="prov-title" name="title" class="pf-input" placeholder="<?= tr('provision_placeholder_wood') ?>" required>
</div>
<div class="pf-form-group">
<label class="pf-label" for="prov-amount"><?= tr('amount') ?> (€)</label>
<input type="number" id="prov-amount" name="amount" class="pf-input no-spinners input-amount-highlight" step="0.01" min="0.01" required>
</div>
<div class="pf-form-group">
<label class="pf-label" for="prov-date"><?= tr('expected_date') ?></label>
<input type="date" id="prov-date" name="expected_date" class="pf-input" required>
</div>
<button type="submit" class="pf-btn pf-btn-secondary">
<?= tr('btn_add') ?>
</button>
</div>
</form>
</div>
<div class="budget-table-card table-responsive">
<?php if (empty($provisions)): ?>
<div class="optimization-hint" style="padding: 30px;">
<p><?= tr('no_provisions') ?></p>
</div>
<?php else: ?>
<table class="pf-table savings-table provisions-table">
<thead>
<tr>
<th><?= tr('provision_label') ?></th>
<th style="width: 150px;"><?= tr('amount') ?></th>
<th style="width: 150px;"><?= tr('expected_date') ?></th>
<th style="width: 100px;"><?= tr('actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($provisions as $p): ?>
<tr>
<td class="prov-title-cell">
<?= htmlspecialchars($p['title']) ?>
</td>
<td class="prov-amount-cell">
<?= number_format($p['amount'], 2, ',', ' ') ?> €
</td>
<td class="prov-date-cell">
<?= formatDate($p['expected_date']) ?>
</td>
<td class="text-right" style="padding-right: 15px;">
<button class="btn-icon-action delete btn-safe-click" title="<?= tr('btn_delete') ?>" onclick="deleteProvision(<?= $p['id'] ?>)">
🗑️
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<div id="optimizeModal" class="pf-modal">
<div class="pf-modal-content provisions-modal-content">
<div class="pf-modal-header">
<h3 class="pf-modal-title">🧠 <?= tr('optimization_assistant_title') ?></h3>
<button type="button" class="pf-modal-close" onclick="closeOptimizeModal()">&times;</button>
</div>
<form id="form-optimize" data-action="/modules/budget/includes/api/optimize-cashflow.php">
<div id="dynamic-savings-inputs">
<?php if (empty($configs)): ?>
<p class="text-danger font-bold pf-muted-tiny"><?= tr('budget_opti_no_config') ?></p>
<input type="number" step="0.01" min="0" name="savings[Global]" class="pf-input no-spinners" required>
<?php else: ?>
<?php foreach ($configs as $person => $ecoBase):
$debt = $debts[$person] ?? 0;
?>
<div class="pf-form-group provision-person-card">
<label class="pf-label provision-person-header">
<strong class="text-main"><?= htmlspecialchars($person) ?></strong>
<span class="pf-muted-note">
<?php if ($debt > 0): ?>
<span class="text-danger font-bold">(Dette en attente : <?= (float)$debt ?> €)</span>
<?php endif; ?>
</span>
</label>
<div class="provision-input-group">
<input type="number" step="0.01" min="0" name="savings[<?= htmlspecialchars($person) ?>]" class="pf-input no-spinners input-amount-success" value="<?= (float)$ecoBase ?>" required>
<span class="currency-symbol">€</span>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<button type="submit" class="pf-btn pf-btn-primary btn-block">
<?= tr('calculate') ?>
</button>
</form>
<hr class="pf-divider">
<div id="optimization-results">
<p class="optimization-hint">
Vérifiez vos apports théoriques ci-dessus pour calculer la stratégie de répartition (Clearing automatique si aucune dépense).
</p>
</div>
</div>
</div>
<script>
window.appLang = document.documentElement.lang === "ca" ? "ca-ES" : "fr-FR";
window.I18N = {
...(window.I18N || {}),
'btn_delete': <?= json_encode(tr('btn_delete')) ?>,
'error_generic': <?= json_encode(tr('error_generic')) ?>,
'bud_err_tech': <?= json_encode(tr('bud_err_tech')) ?>,
'bud_err_server': <?= json_encode(tr('bud_err_server')) ?>
};
// --- 2. GESTION DU FORMULAIRE D'AJOUT ---
const formAdd = document.getElementById('form-add-provision');
if (formAdd) {
formAdd.addEventListener('submit', async function(e) {
e.preventDefault();
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.innerText;
submitBtn.innerText = '⏳';
submitBtn.disabled = true;
try {
const result = await pachaFetch(this.getAttribute('data-action'), {
method: 'POST',
body: new FormData(this)
});
if (result.success) {
window.location.reload();
} else {
alert(result.message || window.I18N['error_generic']);
submitBtn.innerText = originalText;
submitBtn.disabled = false;
}
} catch (error) {
showToast(window.I18N['bud_err_tech'], 'error');
submitBtn.innerText = originalText;
submitBtn.disabled = false;
}
});
}
// --- 3. GESTION DE LA SUPPRESSION ---
async function deleteProvision(id) {
if (!confirm(window.I18N['btn_delete'] + ' ?')) return;
try {
const result = await pachaFetch('/modules/budget/includes/api/delete-provision.php', {
method: "POST",
body: new URLSearchParams({ id: id })
});
if (result.success) {
window.location.reload();
} else {
alert(result.message);
}
} catch(err) {
showToast(window.I18N['bud_err_tech'], 'error');
}
}
// --- 4. CONTROL DE LA MODALE D'OPTIMISATION ---
function openOptimizeModal() {
document.getElementById('optimization-results').innerHTML = `
<p class="optimization-hint">
Vérifiez vos apports théoriques ci-dessus pour calculer la stratégie de répartition (Clearing automatique si aucune dépense).
</p>`;
document.getElementById('optimizeModal').classList.add('open');
document.body.classList.add('no-scroll');
}
function closeOptimizeModal() {
document.getElementById('optimizeModal').classList.remove('open');
document.body.classList.remove('no-scroll');
}
window.onclick = function(event) {
const modal = document.getElementById('optimizeModal');
if (event.target == modal) {
closeOptimizeModal();
}
}
// --- 5. EXECUTION ET SUBMIT DE L'ALGORITHME (formOptimize) ---
const formOptimize = document.getElementById('form-optimize');
if (formOptimize) {
formOptimize.addEventListener('submit', async function(e) {
e.preventDefault();
const resultsContainer = document.getElementById('optimization-results');
const submitBtn = this.querySelector('button[type="submit"]');
submitBtn.disabled = true;
resultsContainer.innerHTML = '<div class="optimization-hint">⏳ Analyse des quinzaines bancaires...</div>';
try {
const result = await pachaFetch(this.getAttribute('data-action'), {
method: 'POST',
body: new FormData(this)
});
if (result.success) {
resultsContainer.innerHTML = result.html;
} else {
resultsContainer.innerHTML = `<p class="text-danger font-bold text-center">${result.message}</p>`;
}
} catch (error) {
console.error("Erreur d'optimisation :", error);
resultsContainer.innerHTML = `<p class="text-danger font-bold text-center">${window.I18N['bud_err_tech']}</p>`;
} finally {
submitBtn.disabled = false;
}
});
}
</script>
+417
View File
@@ -0,0 +1,417 @@
<?php
// modules/budget/views/recap.php
// 1. Récupération des Catégories dynamiques
$stmtCats = $pdo->query("SELECT code, label, icon, type FROM pf_budget_categories ORDER BY type DESC, label ASC");
$dbCategories = $stmtCats->fetchAll(PDO::FETCH_ASSOC);
// 2. Récupération des Salaires/Mensualités configurés (Revenus automatiques)
$currentYear = isset($_GET['y']) ? (int)$_GET['y'] : date('Y');
$stmtSalaries = $pdo->prepare("SELECT id, person, mensualite FROM pf_salary_config WHERE year = ?");
$stmtSalaries->execute([$currentYear]);
$salaries = $stmtSalaries->fetchAll(PDO::FETCH_ASSOC);
// 3. Récupération des Items du Budget (Charges Fixes et Estimations)
$stmt = $pdo->query("SELECT * FROM pf_budget_items WHERE category != 'SAVINGS' ORDER BY is_estimate ASC, sort_order ASC, name ASC");
$items = $stmt->fetchAll(PDO::FETCH_ASSOC);
// 4. Gestion du mois actif
$stmtActive = $pdo->query("SELECT content FROM pf_notes WHERE note_type = 'active_gestion_month' LIMIT 1");
$defaultActiveMonth = $stmtActive->fetchColumn() ?: date('Y-m-01');
$currentMonth = isset($_GET['m']) ? str_pad((int)$_GET['m'], 2, '0', STR_PAD_LEFT) : date('m', strtotime($defaultActiveMonth));
$viewMonthDate = "$currentYear-$currentMonth-01";
// 5. Récupération optimisée et unifiée du Réel
// On récupère tout en une seule requête pour éviter les décalages entre ID et Catégorie
$stmtReal = $pdo->prepare("
SELECT budget_item_id, category, SUM(amount) as total_real
FROM pf_expenses
WHERE gestion_month = ?
GROUP BY budget_item_id, category
");
$stmtReal->execute([$viewMonthDate]);
$allExpenses = $stmtReal->fetchAll(PDO::FETCH_ASSOC);
// On initialise les tableaux de correspondance
$realTotalsById = []; // Pour les lignes liées par ID
$realTotalsByCat = []; // Pour les lignes orphelines (NULL) liées par Catégorie
foreach ($allExpenses as $row) {
if (!empty($row['budget_item_id'])) {
$realTotalsById[$row['budget_item_id']] = (float)$row['total_real'];
} else {
$realTotalsByCat[$row['category']] = (float)$row['total_real'];
}
}
$stmtSalariesReal = $pdo->prepare("SELECT salary_id, SUM(amount) as total_salary FROM pf_expenses WHERE gestion_month = ? AND salary_id IS NOT NULL GROUP BY salary_id");
$stmtSalariesReal->execute([$viewMonthDate]);
$realTotalsBySalary = $stmtSalariesReal->fetchAll(PDO::FETCH_KEY_PAIR);
// Récupération des détails pour le mapping par mots-clés (si besoin de précision)
$stmtLabels = $pdo->prepare("SELECT label, amount, category FROM pf_expenses WHERE gestion_month = ? AND budget_item_id IS NULL");
$stmtLabels->execute([$viewMonthDate]);
$unlinkedExpenses = $stmtLabels->fetchAll(PDO::FETCH_ASSOC);
// Gestion des libellés et totaux
$currentMonthName = tr('month_' . str_pad((int)$currentMonth, 2, '0', STR_PAD_LEFT)) . ' ' . $currentYear;
$totalDepenses = 0;
$totalRevenus = 0;
?>
<div class="budget-view">
<div class="view-header" style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h2 style="margin:0;"><?= tr('bud_recap_monthly_title') ?></h2>
<button onclick="openRecapModal('add')" class="pf-btn">+ <?= tr('bud_recap_btn_add') ?></button>
</div>
<div class="table-responsive" style="background:white; border-radius:16px; box-shadow:var(--shadow-sm); border:1px solid #e2e8f0; overflow:hidden;">
<table class="pf-table" style="margin:0; box-shadow:none;">
<thead style="background:#f8fafc;">
<tr>
<th><?= tr('bud_label_name') ?></th>
<th><?= tr('bud_planned_amount') ?></th>
<th><?= tr('bud_type') ?></th>
<th><?= tr('bud_day') ?></th>
<th><?= tr('bud_month_state') ?> (<?= $currentMonthName ?>)</th>
<th style="text-align:right;"><?= tr('actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($salaries as $salary):
$mensualite = (float)$salary['mensualite'];
$totalRevenus += $mensualite;
// Calcul du réel perçu
$realPerçu = isset($realTotalsBySalary[$salary['id']]) ? (float)$realTotalsBySalary[$salary['id']] : 0;
$gap = $realPerçu - $mensualite;
$isAutoChecked = ($realPerçu >= ($mensualite - 0.10));
?>
<tr class="row-income" style="border-bottom:1px solid var(--border-light); background:#f0fdf4;">
<td style="padding:15px;">
<strong>Apport <?= htmlspecialchars($salary['person']) ?></strong>
<span title="Le montant cible est défini dans les paramètres" style="font-size:0.8rem; cursor:help;">⚙️</span>
</td>
<td class="cell-amount" style="font-weight:600; padding:15px; color:#10b981;">
+ <?= number_format($mensualite, 2, ',', ' ') ?> €
<?php if ($realPerçu > 0): ?>
<?php if ($gap > 0.05): ?>
<div style="font-size:0.75rem; color:#10b981; font-weight:bold;">Bonus : +<?= number_format($gap, 2, ',', ' ') ?> €</div>
<?php elseif ($gap < -0.05): ?>
<div style="font-size:0.75rem; color:#f59e0b;">Manque : <?= number_format(abs($gap), 2, ',', ' ') ?> €</div>
<?php else: ?>
<div style="font-size:0.75rem; color:#10b981;">Atteint ✓</div>
<?php endif; ?>
<?php endif; ?>
</td>
<td style="padding:15px;">
<span class="badge-type" style="background:#dcfce7; color:#16a34a; padding:4px 8px; border-radius:12px; font-size:0.8rem; font-weight:600;">Revenu Mensuel</span>
</td>
<td style="padding:15px; color:#64748b; font-weight:bold;">-</td>
<td style="padding:15px;">
<?php if ($isAutoChecked): ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#dcfce7; color:#16a34a; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #bbf7d0;"><span>✓</span> Reçu</div>
<?php elseif ($realPerçu > 0): ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#fffbeb; color:#d97706; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #fde68a;"><span>⏳</span> Partiel</div>
<?php else: ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#f8fafc; color:#94a3b8; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #e2e8f0;"><span>○</span> En attente</div>
<?php endif; ?>
</td>
<td style="padding:15px; text-align:right;">
<small style="color:#94a3b8;">Via Paramètres</small>
</td>
</tr>
<?php endforeach; ?>
<?php
foreach ($items as $item):
// 1. Calculs de base
$targetAbs = abs((float)$item['amount']);
// --- 🚀 INTERCEPTION DYNAMIQUE ---
$calcDetails = "";
if (isset($item['is_dynamic']) && $item['is_dynamic'] == 1 && !empty($item['dynamic_code'])) {
require_once __DIR__ . '/../includes/DynamicBudgetCalculator.php';
// Facturation à terme échu : on recule d'un mois pour le calcul
$prevDate = date('Y-m-d', strtotime('-1 month', strtotime("$currentYear-$currentMonth-01")));
$calcYear = date('Y', strtotime($prevDate));
$calcMonth = date('m', strtotime($prevDate));
$calc = new DynamicBudgetCalculator($pdo, $calcYear, $calcMonth);
$estimateData = $calc->getEstimate($item['dynamic_code']);
$targetAbs = $estimateData['amount'];
$calcDetails = $estimateData['details'];
}
// --------------------------------
$amountToAdd = ($item['type'] === 'Annuel') ? $targetAbs / 12 : $targetAbs;
$totalDepenses += $amountToAdd;
// 2. RÉINITIALISATION STRICTE
$realSum = 0;
$hasMatchingExpense = false;
// A. Correspondance par ID direct (Le lien dur)
if (isset($realTotalsById[$item['id']])) {
$realSum = (float)$realTotalsById[$item['id']];
$hasMatchingExpense = true;
}
// B. Correspondance par mots-clés bancaires (Le lien intelligent pour les orphelines)
elseif (!empty($item['mapping_keywords'])) {
$keywords = array_map('trim', explode(',', $item['mapping_keywords']));
foreach ($unlinkedExpenses as $uexp) {
foreach ($keywords as $kw) {
if (!empty($kw) && stripos($uexp['label'], $kw) !== false) {
$realSum += (float)$uexp['amount'];
$hasMatchingExpense = true;
break; // On a trouvé un mot clé sur cette dépense, on passe à l'orpheline suivante
}
}
}
}
// C. Absorption des orphelines par catégories (Le lien Macro/Micro)
if (!empty($item['category'])) {
$catCodes = array_map('trim', explode(',', $item['category']));
foreach ($catCodes as $cCode) {
// Si la catégorie existe dans les orphelines et n'a pas encore été consommée
if (!empty($cCode) && isset($realTotalsByCat[$cCode]) && $realTotalsByCat[$cCode] != 0) {
$realSum += $realTotalsByCat[$cCode];
$hasMatchingExpense = true;
// On la vide pour ne pas la compter 2 fois si une autre ligne utilise la même catégorie
$realTotalsByCat[$cCode] = 0;
}
}
}
// 3. Finalisation des variables d'affichage
$realAbs = abs($realSum);
$isAutoChecked = ($hasMatchingExpense && ($realAbs >= ($targetAbs - 0.10)));
$rowClass = 'row-expense' . ($item['is_estimate'] ? ' row-estimate' : '');
?>
<tr class="<?= $rowClass ?>" style="border-bottom:1px solid var(--border-light);">
<td style="padding:15px;">
<strong><?= htmlspecialchars($item['name']) ?></strong>
<?= $item['is_estimate'] ? ' <small style="color:#64748b;">(Variable)</small>' : '' ?>
<?php if(!empty($item['mapping_keywords'])): ?>
<span title="Reconnaissance bancaire : <?= htmlspecialchars($item['mapping_keywords']) ?>" style="font-size:0.7rem; cursor:help;">🔗</span>
<?php endif; ?>
</td>
<td class="cell-amount" style="font-weight:600; padding:15px; color:#1e293b;">
- <?= number_format($targetAbs, 2, ',', ' ') ?> €
<?php if (!empty($calcDetails)): ?>
<span title="<?= htmlspecialchars($calcDetails) ?>" style="cursor:help; margin-left:4px; font-size:0.85rem;">ℹ️</span>
<?php endif; ?>
<?php if ($hasMatchingExpense): ?>
<?php $gap = $realAbs - $targetAbs;
if ($gap > 0.05): ?>
<div style="font-size:0.75rem; color:#ef4444; font-weight:bold;">Dépassé : +<?= number_format($gap, 2, ',', ' ') ?> €</div>
<?php elseif ($gap < -0.05): ?>
<div style="font-size:0.75rem; color:#f59e0b;">Reste : <?= number_format(abs($gap), 2, ',', ' ') ?> €</div>
<?php else: ?>
<div style="font-size:0.75rem; color:#10b981;">Atteint ✓</div>
<?php endif; ?>
<?php elseif ($item['type'] === 'Annuel'): ?>
<div style="font-size:0.75rem; color:#94a3b8;"><?= number_format($amountToAdd, 2, ',', ' ') ?>/mois</div>
<?php endif; ?>
</td>
<td style="padding:15px;">
<span class="badge-type" style="background:#e2e8f0; padding:4px 8px; border-radius:12px; font-size:0.8rem; font-weight:600; color:#475569;">
<?= htmlspecialchars($item['type']) ?>
</span>
</td>
<td style="padding:15px; color:#64748b; font-weight:bold;"><?= $item['payment_day'] ?: '-' ?></td>
<td style="padding:15px;">
<?php if ($isAutoChecked): ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#f0fdf4; color:#16a34a; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #bbf7d0;"><span>✓</span> Validé</div>
<?php elseif($hasMatchingExpense): ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#fffbeb; color:#d97706; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #fde68a;"><span>⏳</span> Partiel</div>
<?php else: ?>
<div style="display:inline-flex; align-items:center; gap:5px; background:#f8fafc; color:#94a3b8; padding:4px 10px; border-radius:20px; font-size:0.85rem; border:1px solid #e2e8f0;"><span>○</span> En attente</div>
<?php endif; ?>
</td>
<td style="padding:15px; text-align:right;">
<div class="action-buttons" style="display:flex; gap:5px; justify-content:flex-end;">
<button class="btn-icon-action edit" onclick='editRecapItem(<?= htmlspecialchars(json_encode($item), ENT_QUOTES, 'UTF-8') ?>)' title="Modifier">✏️</button>
<button class="btn-icon-action delete" onclick="deleteRecapItem(<?= $item['id'] ?>)" title="Supprimer">🗑️</button>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot style="background:#f8fafc;">
<tr>
<td colspan="1" style="padding:15px;"><strong>Total Revenus Lissés</strong></td>
<td colspan="5" style="padding:15px; color:#10b981;"><strong>+ <?= number_format($totalRevenus, 2, ',', ' ') ?> €</strong></td>
</tr>
<tr>
<td colspan="1" style="padding:15px;"><strong>Total Dépenses & Estimations</strong></td>
<td colspan="5" style="padding:15px; color:#ef4444;"><strong>- <?= number_format($totalDepenses, 2, ',', ' ') ?> €</strong></td>
</tr>
<tr style="border-top: 2px solid #e2e8f0; background: white;">
<td colspan="1" style="padding:15px; font-size:1.1rem;"><strong>Reste à Vivre (Équilibre)</strong></td>
<?php $balance = $totalRevenus - $totalDepenses; ?>
<td colspan="5" style="padding:15px; font-size: 1.3em;">
<strong style="color:<?= $balance >= 0 ? '#10b981' : '#ef4444' ?>;"><?= number_format($balance, 2, ',', ' ') ?> € / mois</strong>
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<div id="budgetRecapModal" class="pf-modal" style="display:none; position:fixed; inset:0; z-index:9999; background:rgba(15, 23, 42, 0.6); backdrop-filter:blur(4px); align-items:center; justify-content:center;">
<div class="pf-modal-content" style="background:white; width:95%; max-width:500px; border-radius:20px; box-shadow:0 20px 25px -5px rgba(0,0,0,0.1); padding:30px; position:relative;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:20px;">
<h3 id="recapModalTitle" style="margin:0; font-size:1.2rem; color:#1e293b;">Ajouter une ligne</h3>
<button type="button" onclick="closeRecapModal()" style="border:none; background:none; font-size:1.8rem; cursor:pointer; color:#64748b; line-height:1;">&times;</button>
</div>
<form action="modules/budget/includes/api/manage-item.php" method="POST" id="recapForm">
<input type="hidden" name="action" value="save">
<input type="hidden" name="id" id="item_id">
<div class="form-group" style="margin-bottom:15px;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">Nom de la ligne</label>
<input type="text" name="name" id="item_name" required class="pf-input" placeholder="ex: Assurance Auto, Estimation Courses..." style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px;">
</div>
<div style="display:flex; gap:15px; margin-bottom:15px;">
<div style="flex:1;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">Montant Prévu (€)</label>
<input type="number" step="0.01" name="amount" id="item_amount" required class="pf-input" style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px;">
</div>
<div style="flex:1;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">Type de Dépense</label>
<select name="is_estimate" id="item_is_estimate" class="pf-input" style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px; background:white;">
<option value="0">Fixe (Facture, Prélèvement)</option>
<option value="1">Variable (Estimation, Enveloppe)</option>
</select>
</div>
</div>
<div style="display:flex; gap:15px; margin-bottom:15px;">
<div style="flex:1;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">
Catégorie(s) Cible(s) <small style="font-weight:normal;">(Maintenez Ctrl/Cmd pour choix multiple)</small>
</label>
<select name="category_multi[]" id="item_category" class="pf-input" style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px; background:white; min-height: 120px;" multiple required>
<?php foreach ($dbCategories as $c): ?>
<?php if(strtolower($c['type']) === 'expense'): ?>
<option value="<?= htmlspecialchars($c['code']) ?>">
<?= htmlspecialchars($c['icon'] . ' ' . $c['label']) ?>
</option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
<div style="flex:1;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">Fréquence</label>
<select name="type" id="item_type" class="pf-input" style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px; background:white;">
<option value="Mensuel">Mensuel</option>
<option value="Annuel">Annuel</option>
</select>
</div>
</div>
<div class="form-group" style="margin-bottom:15px;">
<label class="pf-label" style="display:block; margin-bottom:5px; font-weight:600; color:#475569; font-size:0.9rem;">Mots-clés (Reconnaissance Bancaire)</label>
<input type="text" name="mapping_keywords" id="item_keywords" class="pf-input" placeholder="ex: NETFLIX, DOMOFINANCE..." style="width:100%; padding:10px; border:1px solid #cbd5e1; border-radius:8px; background:#f0f9ff; border-color:#bae6fd;">
<small style="color:#64748b; font-size:0.75rem;">Optionnel. Permet au système de lier automatiquement un import CSV à cette ligne.</small>
</div>
<div style="display:flex; justify-content:flex-end; gap:10px; margin-top: 25px;">
<button type="button" onclick="closeRecapModal()" class="pf-btn btn-secondary" style="width:auto; margin:0; background:#f1f5f9; color:#475569; border:none; padding:10px 20px; border-radius:8px; font-weight:600; cursor:pointer;">Annuler</button>
<button type="submit" class="pf-btn" style="width:auto; margin:0; background:#2563eb; color:white; border:none; padding:10px 20px; border-radius:8px; font-weight:600; cursor:pointer;">Enregistrer</button>
</div>
</form>
</div>
</div>
<script>
function openRecapModal(mode) {
if (mode === "add") {
document.getElementById("recapModalTitle").innerText = 'Ajouter une ligne';
document.getElementById("item_id").value = "";
document.getElementById("recapForm").reset();
}
document.getElementById("budgetRecapModal").style.display = "flex";
document.body.classList.add('no-scroll');
}
function closeRecapModal() {
document.getElementById("budgetRecapModal").style.display = "none";
document.body.classList.remove('no-scroll');
}
window.onclick = function(event) {
if (event.target == document.getElementById('budgetRecapModal')) closeRecapModal();
}
function editRecapItem(item) {
const data = typeof item === "string" ? JSON.parse(item) : item;
document.getElementById("recapModalTitle").innerText = "Editer : " + data.name;
document.getElementById("item_id").value = data.id;
document.getElementById("item_name").value = data.name;
document.getElementById("item_keywords").value = data.mapping_keywords || '';
document.getElementById("item_amount").value = Math.abs(data.amount);
const selectedCats = data.category ? data.category.split(',') : [];
const selectEl = document.getElementById("item_category");
Array.from(selectEl.options).forEach(opt => {
opt.selected = selectedCats.includes(opt.value);
});
document.getElementById("item_type").value = data.type;
document.getElementById("item_is_estimate").value = data.is_estimate;
document.getElementById("budgetRecapModal").style.display = "flex";
document.body.classList.add('no-scroll');
}
document.getElementById('recapForm').addEventListener('submit', async function(e) {
e.preventDefault();
const btn = this.querySelector('button[type="submit"]');
btn.disabled = true; btn.innerText = '⏳ ...';
const formData = new FormData(this);
const cats = formData.getAll('category_multi[]');
formData.delete('category_multi[]');
formData.append('category', cats.join(','));
formData.append('ajax', '1');
const url = this.getAttribute('action');
try {
const res = await fetch(url.startsWith('/') ? url.substring(1) : url, { method: 'POST', body: formData });
const data = await res.json();
if (data.success) window.location.reload();
else alert("Erreur : " + data.error);
} catch (err) {
alert("Erreur technique lors de la sauvegarde.");
} finally {
btn.disabled = false; btn.innerText = 'Enregistrer';
}
});
async function deleteRecapItem(id) {
if (!confirm("Confirmer la suppression ?")) return;
const formData = new FormData();
formData.append("action", "delete"); formData.append("id", id); formData.append("ajax", "1");
try {
const res = await fetch("modules/budget/includes/api/manage-item.php", { method: "POST", body: formData });
const data = await res.json();
if (data.success !== false) window.location.reload();
else alert("Erreur : " + data.error);
} catch (err) {
window.location.reload();
}
}
</script>
+660
View File
@@ -0,0 +1,660 @@
<?php
/**
* @var bool $hasAccounts
* @var bool $hasCategories
* @var bool $hasSalaries
* @var bool $hasBudgetItems
* @var bool $isBudgetSetupOk
*/
// Sécurité : Ce fichier ne doit pas être appelé directement
if (!defined('CURRENCY')) {
define('CURRENCY', '€');
}
?>
<div class="budget-settings-backdrop" id="modal-budget-settings">
<div class="budget-settings-modal">
<div class="bs-header">
<h3>⚙️ <?= tr('budget_settings_title') ?></h3>
<button class="bs-close" onclick="closeBudgetSettings()">×</button>
</div>
<div class="bs-layout">
<div class="bs-sidebar">
<button class="bs-tab-btn active" onclick="switchBsTab('accounts', this)">
<?= tr('bs_tab_accounts') ?>
<?php if (!$hasAccounts): ?><span class="alert-dot alert-dot-inline">!</span><?php endif; ?>
</button>
<button class="bs-tab-btn" onclick="switchBsTab('categories', this)">
<?= tr('bs_tab_categories') ?>
<?php if (!$hasCategories): ?><span class="alert-dot alert-dot-inline">!</span><?php endif; ?>
</button>
<button class="bs-tab-btn" onclick="switchBsTab('rules', this)"><?= tr('bs_tab_rules') ?></button>
<button class="bs-tab-btn" onclick="switchBsTab('salaries', this)">
<?= tr('bs_tab_salaries') ?>
<?php if (!$hasSalaries): ?><span class="alert-dot alert-dot-inline">!</span><?php endif; ?>
</button>
<button class="bs-tab-btn" onclick="switchBsTab('csv', this)"><?= tr('bs_tab_csv') ?></button>
<button class="bs-tab-btn" onclick="switchBsTab('children', this)">👶 <?= tr('bud_settings_dyn_title') ?></button>
</div>
<div class="bs-content">
<?php if (!isset($isBudgetSetupOk) || !$isBudgetSetupOk || !$hasBudgetItems): ?>
<div class="bs-onboarding-card">
<h4 class="bs-onboarding-title">
<span>🚀</span> <?= tr('bs_onb_title') ?>
</h4>
<p class="bs-onboarding-desc"><?= tr('bs_onb_desc') ?></p>
<ul class="bs-onboarding-list">
<li>
<strong class="<?= $hasCategories ? 'text-success' : 'text-danger' ?>"><?= $hasCategories ? '✅' : '❌' ?></strong>
<a class="bs-onboarding-link" onclick="switchBsTab('categories', document.querySelectorAll('.bs-tab-btn')[1]); return false;"><?= tr('bs_onb_cat_link') ?></a> : <?= tr('bs_onb_cat_desc') ?>
</li>
<li>
<strong class="<?= $hasAccounts ? 'text-success' : 'text-danger' ?>"><?= $hasAccounts ? '✅' : '❌' ?></strong>
<a class="bs-onboarding-link" onclick="switchBsTab('accounts', document.querySelectorAll('.bs-tab-btn')[0]); return false;"><?= tr('bs_onb_acc_link') ?></a> : <?= tr('bs_onb_acc_desc') ?>
</li>
<li>
<strong class="<?= $hasSalaries ? 'text-success' : 'text-danger' ?>"><?= $hasSalaries ? '✅' : '❌' ?></strong>
<a class="bs-onboarding-link" onclick="switchBsTab('salaries', document.querySelectorAll('.bs-tab-btn')[3]); return false;"><?= tr('bs_onb_sal_link') ?></a> : <?= tr('bs_onb_sal_desc') ?>
</li>
<li style="margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(180, 83, 9, 0.3);">
<strong class="<?= $hasBudgetItems ? 'text-success' : 'text-warning' ?>" style="color: <?= $hasBudgetItems ? '' : '#f59e0b' ?>"><?= $hasBudgetItems ? '✅' : '⏳' ?></strong>
<a href="?tab=recap" onclick="closeBudgetSettings();" class="bs-onboarding-link"><?= tr('bs_onb_items_link') ?></a> : <?= tr('bs_onb_items_desc') ?>
</li>
</ul>
</div>
<?php endif; ?>
<div id="pane-accounts" class="bs-pane active">
<div class="bs-pane-header">
<h4 class="bs-section-title"><?= tr('bs_tab_accounts') ?></h4>
<div class="bs-currency-selector">
<span><?= tr('bs_currency_label') ?> :</span>
<select id="bs-currency-select" class="pf-input bs-currency-select" onchange="updateBudgetCurrency(this)">
<option value="€">EUR (€)</option>
<option value="$">USD ($)</option>
<option value="£">GBP (£)</option>
<option value="CHF">CHF</option>
</select>
</div>
</div>
<div id="bs-list-accounts" class="bs-list-container">⏳ <?= tr('loading') ?></div>
<hr class="bs-divider">
<h5 class="bs-section-subtitle"><?= tr('bs_add_account_title') ?></h5>
<form id="form-add-account" class="bs-form-inline">
<input type="text" name="name" class="pf-input bs-input-flex" placeholder="<?= tr('bs_account_name_ph') ?>" required>
<select name="type" class="pf-input bs-input-fixed">
<option value="checking"><?= tr('bs_type_checking') ?></option>
<option value="savings"><?= tr('bs_type_savings') ?></option>
</select>
<select name="owner_person_id" id="select-account-owner" class="pf-input bs-input-fixed">
<option value="">Commun</option>
</select>
<button type="submit" class="btn btn-secondary"><?= tr('btn_add') ?></button>
</form>
</div>
<div id="pane-categories" class="bs-pane">
<h4 class="bs-section-title"><?= tr('bs_tab_categories') ?></h4>
<div id="bs-list-categories" class="bs-list-container">⏳ <?= tr('loading') ?></div>
<hr class="bs-divider">
<h5 class="bs-section-subtitle"><?= tr('bs_add_category_title') ?></h5>
<form id="form-add-category" class="bs-form-inline align-center">
<input type="text" name="code" class="pf-input bs-input-fixed" placeholder="<?= tr('bs_cat_code_ph') ?>" required>
<input type="text" name="label" class="pf-input bs-input-flex" placeholder="<?= tr('bs_cat_label_ph') ?>" required>
<select name="type" class="pf-input bs-input-fixed">
<option value="Expense"><?= tr('bs_type_expense') ?></option>
<option value="Income"><?= tr('bs_type_income') ?></option>
<option value="Savings"><?= tr('bs_type_savings_cat') ?></option>
</select>
<select name="icon" class="pf-input bs-input-icon">
<option value="📌">📌</option><option value="🛒">🛒</option><option value="🥖">🥖</option>
<option value="🍽️">🍽️</option><option value="⛽">⛽</option><option value="🚗">🚗</option>
<option value="🚆">🚆</option><option value="🏠">🏠</option><option value="⚡">⚡</option>
<option value="💧">💧</option><option value="⚕️">⚕️</option><option value="🎒">🎒</option>
<option value="👕">👕</option><option value="📱">📱</option><option value="🎮">🎮</option>
<option value="✈️">✈️</option><option value="🎁">🎁</option><option value="🐶">🐶</option>
<option value="💵">💵</option><option value="🐷">🐷</option><option value="📈">📈</option>
</select>
<input type="color" name="color" value="#3b82f6" class="bs-input-color">
<button type="submit" class="btn btn-secondary"><?= tr('btn_add') ?></button>
</form>
</div>
<div id="pane-rules" class="bs-pane">
<h4 class="bs-section-title"><?= tr('bs_tab_rules') ?></h4>
<input type="text" id="input-search-rules" class="bs-rule-search" placeholder="<?= tr('bs_rule_search_ph') ?>" onkeyup="filterRules()">
<div id="bs-list-rules" class="bs-list-container">⏳ <?= tr('loading') ?></div>
<hr class="bs-divider">
<h5 class="bs-section-subtitle"><?= tr('bs_add_rule_title') ?></h5>
<form id="form-add-rule" class="bs-form-inline align-center">
<input type="text" name="keyword" class="pf-input bs-input-flex" placeholder="<?= tr('bs_rule_keyword_ph') ?>" required>
<select name="category" id="select-rule-category" class="pf-input bs-input-fixed" required></select>
<button type="submit" class="btn btn-secondary"><?= tr('btn_add') ?></button>
</form>
</div>
<div id="pane-salaries" class="bs-pane">
<h4 class="bs-section-title"><?= tr('bs_tab_salaries') ?> (<?= date('Y') ?>)</h4>
<div id="bs-list-salaries" class="bs-list-container">⏳ <?= tr('loading') ?></div>
</div>
<div id="pane-csv" class="bs-pane">
<h4 class="bs-section-title"><?= tr('bs_csv_title') ?></h4>
<p class="pf-muted-tiny bs-desc"><?= tr('bs_csv_desc') ?></p>
<div id="csv-drop-zone" class="bs-csv-dropzone">
<div class="bs-csv-icon">📥</div>
<h5 class="bs-csv-title"><?= tr('bs_csv_drop_title') ?></h5>
<p class="pf-muted-tiny bs-csv-subtitle"><?= tr('bs_csv_drop_desc') ?></p>
<input type="file" id="csv_file_input" accept=".csv" style="display: none;">
</div>
<div id="csv-preview-container" class="bs-csv-preview"></div>
<h5 class="bs-section-subtitle bordered"><?= tr('bs_csv_settings_title') ?></h5>
<form id="form-csv-mapping" onsubmit="saveCsvMapping(event)">
<div class="bs-grid-2">
<div>
<label class="pf-label"><?= tr('bs_csv_delimiter') ?></label>
<select name="csv_delimiter" id="csv_delimiter" class="pf-input">
<option value=";"><?= tr('bs_csv_delim_semi') ?></option>
<option value=","><?= tr('bs_csv_delim_comma') ?></option>
<option value="\t"><?= tr('bs_csv_delim_tab') ?></option>
</select>
</div>
<div>
<label class="pf-label"><?= tr('bs_csv_date_format') ?></label>
<select name="csv_date_format" id="csv_date_format" class="pf-input">
<option value="d/m/Y">JJ/MM/AAAA</option>
<option value="Y-m-d">AAAA-MM-JJ</option>
</select>
</div>
</div>
<h5 class="bs-section-subtitle">
<?= tr('bs_csv_col_index') ?>
<small class="bs-text-muted-normal"><?= tr('bs_csv_col_index_help') ?></small>
</h5>
<div class="bs-grid-2">
<div>
<label class="pf-label"><?= tr('bs_csv_col_date') ?></label>
<input type="number" min="0" name="csv_col_date" id="csv_col_date" class="pf-input" value="0" required>
</div>
<div>
<label class="pf-label"><?= tr('bs_csv_col_label') ?></label>
<input type="number" min="0" name="csv_col_label" id="csv_col_label" class="pf-input" value="1" required>
</div>
</div>
<div class="bs-card-gray">
<label class="pf-label"><?= tr('bs_csv_amount_mgmt') ?></label>
<select name="csv_amount_type" id="csv_amount_type" class="pf-input bs-input-mb" onchange="toggleCsvAmountCols(this.value)">
<option value="single"><?= tr('bs_csv_amount_single') ?></option>
<option value="split"><?= tr('bs_csv_amount_split') ?></option>
</select>
<div class="bs-grid-2">
<div>
<label class="pf-label" id="lbl_col_debit"><?= tr('bs_csv_col_amount') ?></label>
<input type="number" min="0" name="csv_col_debit" id="csv_col_debit" class="pf-input" value="8" required>
</div>
<div id="wrapper_col_credit" style="display:none;">
<label class="pf-label"><?= tr('bs_csv_col_credit') ?></label>
<input type="number" min="0" name="csv_col_credit" id="csv_col_credit" class="pf-input" value="9">
</div>
</div>
</div>
<div class="bs-input-mb">
<label class="pf-label"><?= tr('bs_csv_col_ref') ?></label>
<input type="number" min="0" name="csv_col_ref" id="csv_col_ref" class="pf-input" value="3">
</div>
<div class="bs-text-right">
<button type="submit" class="btn btn-secondary">💾 <?= tr('btn_save_format') ?></button>
</div>
</form>
</div>
<!-- NOUVEAU PANE ENFANTS -->
<div id="pane-children" class="bs-pane">
<h4 class="bs-section-title">👶 <?= tr('bud_settings_dyn_title') ?></h4>
<p class="pf-muted-tiny bs-desc">Configurez ici les tarifs pour le calcul dynamique des frais de garde et de cantine.</p>
<form id="form-dynamic-estimates" onsubmit="saveDynamicEstimates(event)">
<h5 class="bs-section-subtitle bordered">Assistante Maternelle</h5>
<div class="bs-grid-2">
<div>
<label class="pf-label"><?= tr('bud_dyn_nanny_fixed') ?></label>
<input type="number" step="0.01" name="budget_nanny_fixed" id="budget_nanny_fixed" class="pf-input" value="700">
</div>
<div>
<label class="pf-label"><?= tr('bud_dyn_nanny_daily') ?></label>
<input type="number" step="0.01" name="budget_nanny_daily" id="budget_nanny_daily" class="pf-input" value="4">
</div>
<div>
<label class="pf-label"><?= tr('bud_dyn_nanny_aid') ?></label>
<input type="number" step="0.01" name="budget_nanny_aid" id="budget_nanny_aid" class="pf-input" value="120">
</div>
<div>
<label class="pf-label"><?= tr('bud_dyn_nanny_cesu_avg') ?></label>
<input type="number" step="0.01" name="budget_nanny_cesu_avg" id="budget_nanny_cesu_avg" class="pf-input" value="170">
</div>
</div>
<h5 class="bs-section-subtitle bordered" style="margin-top: 20px;">École & Centre de loisirs</h5>
<div class="bs-grid-2">
<div>
<label class="pf-label"><?= tr('bud_dyn_school_meal') ?></label>
<input type="number" step="0.01" name="budget_school_meal" id="budget_school_meal" class="pf-input" value="5.62">
</div>
<div>
<label class="pf-label"><?= tr('bud_dyn_school_aftercare') ?></label>
<input type="number" step="0.01" name="budget_school_aftercare" id="budget_school_aftercare" class="pf-input" value="1.97">
</div>
<div>
<label class="pf-label"><?= tr('bud_dyn_school_fullday') ?></label>
<input type="number" step="0.01" name="budget_school_fullday" id="budget_school_fullday" class="pf-input" value="21.89">
</div>
</div>
<div class="bs-text-right" style="margin-top: 20px;">
<button type="submit" class="btn btn-secondary">💾 <?= tr('btn_save') ?></button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const tabsContainer = document.querySelector('.budget-tabs-container');
const activeTab = document.querySelector('.tab-item.active');
if (tabsContainer && activeTab) {
if (tabsContainer.scrollWidth > tabsContainer.clientWidth) {
const scrollPos = activeTab.offsetLeft - (tabsContainer.offsetWidth / 2) + (activeTab.offsetWidth / 2);
tabsContainer.scrollTo({ left: scrollPos, behavior: 'smooth' });
}
}
});
function openBudgetSettings() {
document.getElementById('modal-budget-settings').classList.add('show');
document.body.classList.add('no-scroll');
loadBudgetSettingsData();
}
function closeBudgetSettings() {
document.getElementById('modal-budget-settings').classList.remove('show');
document.body.classList.remove('no-scroll');
window.location.reload();
}
document.getElementById('modal-budget-settings')?.addEventListener('click', (e) => {
if (e.target.id === 'modal-budget-settings') closeBudgetSettings();
});
function switchBsTab(tabId, btnEl) {
document.querySelectorAll('.bs-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.bs-pane').forEach(p => p.classList.remove('active'));
btnEl.classList.add('active');
document.getElementById('pane-' + tabId).classList.add('active');
}
async function loadBudgetSettingsData() {
try {
const response = await pachaFetch('/modules/budget/includes/api/settings.php?action=get_all', { method: 'GET' });
if (!response.success) throw new Error(response.error || tr('error_occured'));
// Alimenter la liste des propriétaires pour les comptes
const ownerSelect = document.getElementById('select-account-owner');
if (ownerSelect && response.data.people) {
ownerSelect.innerHTML = '<option value="">Commun</option>';
response.data.people.forEach(p => {
ownerSelect.innerHTML += `<option value="${p.id}">${p.name}</option>`;
});
}
renderAccounts(response.data.accounts);
renderCategories(response.data.categories);
populateRuleCategories(response.data.categories);
renderRules(response.data.rules);
renderSalaries(response.data.salaries, response.data.year);
const currencySelect = document.getElementById('bs-currency-select');
if (currencySelect && response.data.currency) currencySelect.value = response.data.currency;
const bs = response.data.budget_settings || {};
if (document.getElementById('budget_nanny_fixed')) document.getElementById('budget_nanny_fixed').value = bs.budget_nanny_fixed || 700;
if (document.getElementById('budget_nanny_daily')) document.getElementById('budget_nanny_daily').value = bs.budget_nanny_daily || 4;
if (document.getElementById('budget_nanny_aid')) document.getElementById('budget_nanny_aid').value = bs.budget_nanny_aid || 120;
if (document.getElementById('budget_nanny_cesu_avg')) document.getElementById('budget_nanny_cesu_avg').value = bs.budget_nanny_cesu_avg || 170;
if (document.getElementById('budget_school_meal')) document.getElementById('budget_school_meal').value = bs.budget_school_meal || 5.62;
if (document.getElementById('budget_school_aftercare')) document.getElementById('budget_school_aftercare').value = bs.budget_school_aftercare || 1.97;
if (document.getElementById('budget_school_fullday')) document.getElementById('budget_school_fullday').value = bs.budget_school_fullday || 21.89;
} catch (err) {
console.error("Erreur chargement paramètres :", err);
const errorMsg = `<div class="pf-alert pf-alert--error bs-input-mb">❌ ${tr('error_loading_settings')} : ${err.message}</div>`;
['accounts', 'categories', 'rules', 'salaries'].forEach(id => {
const el = document.getElementById('bs-list-' + id);
if (el) el.innerHTML = errorMsg;
});
}
}
// 1. ONGLET : COMPTES
function renderAccounts(accounts) {
const container = document.getElementById('bs-list-accounts');
if (!container) return;
if (!accounts || accounts.length === 0) {
container.innerHTML = `<em class="text-muted">${tr('bs_empty_accounts')}</em>`;
return;
}
let html = '';
accounts.forEach(acc => {
const typeBadge = acc.account_type === 'checking' ? tr('bs_type_checking') : tr('bs_type_savings');
const defaultBadge = acc.is_default == 1 ? `<span class="bs-badge-default">${tr('bs_badge_default')}</span>` : '';
const ownerText = acc.owner_name ? `${tr('bs_owner')} : ${acc.owner_name}` : tr('bs_shared_account');
html += `
<div class="bs-list-item">
<div>
<strong>${acc.name}</strong> ${defaultBadge}<br>
<small class="text-muted">${typeBadge} · ${ownerText}</small>
</div>
<div class="pf-flex-gap-8">
<button type="button" class="btn-icon-action delete" onclick="deleteAccount(${acc.id})" title="${tr('btn_delete')}">🗑️</button>
</div>
</div>`;
});
container.innerHTML = html;
}
// 2. ONGLET : CATÉGORIES
function renderCategories(categories) {
const container = document.getElementById('bs-list-categories');
if (!container) return;
if (!categories || categories.length === 0) {
container.innerHTML = `<em class="text-muted">${tr('bs_empty_categories')}</em>`;
return;
}
// Tri JS pour respecter l'ordre au chargement de la modale
categories.sort((a, b) => {
if (a.type !== b.type) return a.type === 'Income' ? -1 : 1;
return (a.sort_order || 0) - (b.sort_order || 0);
});
let html = '';
categories.forEach(cat => {
let typeLabel = cat.type === 'Income' ? tr('bs_type_income') : cat.type === 'Expense' ? tr('bs_type_expense') : tr('bs_type_savings_cat');
html += `
<div class="bs-list-item" data-id="${cat.id}" style="border-left: 4px solid ${cat.color || '#ccc'};">
<div>
<span style="font-size:1.2rem; margin-right:8px;">${cat.icon || '📌'}</span>
<strong>${cat.label}</strong> <small class="text-muted">(${cat.code} — ${typeLabel})</small>
</div>
<div class="pf-flex-gap-8">
<button type="button" class="btn-icon-action" onclick="moveCatUp(this)" title="Monter">⬆️</button>
<button type="button" class="btn-icon-action" onclick="moveCatDown(this)" title="Descendre">⬇️</button>
<button type="button" class="btn-icon-action delete" onclick="deleteBudgetCategory(${cat.id})" title="${tr('btn_delete')}">🗑️</button>
</div>
</div>`;
});
container.innerHTML = html;
}
// Nouvelles fonctions pour réordonner visuellement et sauvegarder
function moveCatUp(btn) {
let row = btn.closest('.bs-list-item');
if (row.previousElementSibling) {
row.parentNode.insertBefore(row, row.previousElementSibling);
saveCategoriesOrder();
}
}
function moveCatDown(btn) {
let row = btn.closest('.bs-list-item');
if (row.nextElementSibling) {
row.parentNode.insertBefore(row.nextElementSibling, row);
saveCategoriesOrder();
}
}
async function saveCategoriesOrder() {
let ids = Array.from(document.querySelectorAll('#bs-list-categories .bs-list-item')).map(el => el.dataset.id);
let fd = new FormData();
fd.append('action', 'save_categories_order');
fd.append('order', JSON.stringify(ids));
try {
await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd });
} catch (err) {
console.error("Erreur de sauvegarde de l'ordre :", err);
}
}
// 3. ONGLET : RÈGLES D'IMPORT
function renderRules(rules) {
const container = document.getElementById('bs-list-rules');
if (!container) return;
if (!rules || rules.length === 0) {
container.innerHTML = `<em class="text-muted">${tr('bs_empty_rules')}</em>`;
return;
}
const groupedRules = {};
rules.forEach(r => {
const catName = r.cat_label || r.category;
if (!groupedRules[catName]) groupedRules[catName] = [];
groupedRules[catName].push(r);
});
let html = '';
for (const [catName, catRules] of Object.entries(groupedRules)) {
html += `
<details class="pf-accordion js-rule-group" data-catname="${catName.toLowerCase()}">
<summary class="pf-accordion-summary bs-accordion-summary">
<span>📁 ${catName}</span>
<span class="bs-accordion-count">${catRules.length}</span>
</summary>
<div class="pf-accordion-content" style="padding: 0.5rem;">
<div class="bs-rule-tags">`;
catRules.forEach(r => {
html += `<div class="bs-rule-tag js-rule-tag" data-keyword="${r.keyword.toLowerCase()}">
${r.keyword}
<button type="button" class="bs-rule-tag-del" onclick="deleteRule(${r.id})" title="${tr('btn_delete')}">×</button>
</div>`;
});
html += ` </div>
</div>
</details>`;
}
container.innerHTML = html;
}
function filterRules() {
const searchVal = document.getElementById('input-search-rules').value.toLowerCase();
document.querySelectorAll('.js-rule-group').forEach(group => {
let hasVisibleTag = false;
const catName = group.getAttribute('data-catname');
group.querySelectorAll('.js-rule-tag').forEach(tag => {
const keyword = tag.getAttribute('data-keyword');
if (keyword.includes(searchVal)) { tag.style.display = 'inline-flex'; hasVisibleTag = true; }
else { tag.style.display = 'none'; }
});
if (catName.includes(searchVal) && searchVal.length > 0) {
group.querySelectorAll('.js-rule-tag').forEach(tag => tag.style.display = 'inline-flex');
hasVisibleTag = true;
}
if (hasVisibleTag) {
group.style.display = 'block';
if (searchVal.length > 0) group.setAttribute('open', '');
} else {
group.style.display = 'none'; group.removeAttribute('open');
}
});
}
// 5. ONGLET : SALAIRES
function renderSalaries(salaries, year) {
const container = document.getElementById('bs-list-salaries');
if (!container) return;
if (!salaries || salaries.length === 0) {
container.innerHTML = `<em class="text-muted">${tr('bs_empty_salaries')} ${year}.</em>`;
return;
}
const currency = '<?= CURRENCY ?>';
let html = `<p class="bs-desc">${tr('bs_salaries_year_desc')} <strong>${year}</strong>.</p>`;
salaries.forEach(s => {
html += `
<div class="bs-list-item" id="salary-item-${s.id}">
<div>
<strong>${s.person}</strong><br>
<small class="text-muted">
${tr('bs_salary_net')} : ${s.salary} ${currency}<br>
${tr('bs_salary_fees')} : ${s.mensualite} ${currency}
</small>
</div>
<div class="pf-flex-gap-8">
<button type="button" class="btn-icon-action edit" data-id="${s.id}" data-person="${s.person}" data-salary="${s.salary}" data-mensualite="${s.mensualite}" onclick="inlineEditSalary(this)" title="${tr('btn_edit')}">✏️</button>
</div>
</div>`;
});
container.innerHTML = html;
}
// --- CRUD ACTIONS ---
async function deleteAccount(id) { if (!await pachaConfirm(tr('btn_delete'), tr('bs_confirm_delete'))) return; try { const fd = new FormData(); fd.append('action', 'delete_account'); fd.append('id', id); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); await loadBudgetSettingsData(); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); } }
const formAddAccount = document.getElementById('form-add-account');
if (formAddAccount) formAddAccount.addEventListener('submit', async (e) => { e.preventDefault(); const btn = formAddAccount.querySelector('button'); const oldText = btn.innerText; btn.innerText = '⏳'; btn.disabled = true; try { const fd = new FormData(formAddAccount); fd.append('action', 'add_account'); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); formAddAccount.reset(); await loadBudgetSettingsData(); if (typeof showToast === 'function') showToast("Compte ajouté", 'success'); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); } finally { btn.innerText = oldText; btn.disabled = false; } });
async function deleteBudgetCategory(id) {
if (!await pachaConfirm(tr('btn_delete'), tr('bs_confirm_delete_cat'))) return;
try {
const fd = new FormData();
fd.append('action', 'delete_category');
fd.append('id', id);
const res = await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd });
if (!res.success) throw new Error(res.error || tr('error_occured'));
await loadBudgetSettingsData();
} catch (err) {
if (typeof showToast === 'function') {
showToast(err.message, 'error');
} else {
alert("Erreur : " + err.message);
}
}
}
const formAddCategory = document.getElementById('form-add-category');
if (formAddCategory) {
formAddCategory.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = formAddCategory.querySelector('button');
const oldText = btn.innerText;
btn.innerText = '⏳';
btn.disabled = true;
try {
const fd = new FormData(formAddCategory);
fd.append('action', 'add_category');
const res = await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd });
if (!res.success) throw new Error(res.error || "Erreur lors de l'ajout");
formAddCategory.reset();
await loadBudgetSettingsData();
if (typeof showToast === 'function') showToast("Catégorie ajoutée", "success");
} catch (err) {
if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message);
} finally {
btn.innerText = oldText;
btn.disabled = false;
}
});
}
function populateRuleCategories(categories) { const select = document.getElementById('select-rule-category'); if (!select) return; select.innerHTML = ''; if (!categories) return; categories.forEach(cat => { const opt = document.createElement('option'); opt.value = cat.code; opt.textContent = `${cat.icon || ''} ${cat.label}`; select.appendChild(opt); }); }
async function deleteRule(id) { if (!await pachaConfirm(tr('btn_delete'), tr('bs_confirm_delete_rule'))) return; try { const fd = new FormData(); fd.append('action', 'delete_rule'); fd.append('id', id); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); await loadBudgetSettingsData(); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); } }
const formAddRule = document.getElementById('form-add-rule');
if (formAddRule) formAddRule.addEventListener('submit', async (e) => { e.preventDefault(); const btn = formAddRule.querySelector('button'); const oldText = btn.innerText; btn.innerText = '⏳'; btn.disabled = true; try { const fd = new FormData(formAddRule); fd.append('action', 'add_rule'); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); formAddRule.reset(); await loadBudgetSettingsData(); if (typeof showToast === 'function') showToast("Règle ajoutée", 'success'); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); } finally { btn.innerText = oldText; btn.disabled = false; } });
function inlineEditSalary(btnEl) {
const id = btnEl.dataset.id; const person = btnEl.dataset.person; const salary = btnEl.dataset.salary; const mensualite = btnEl.dataset.mensualite; const currency = '<?= CURRENCY ?>';
document.getElementById(`salary-item-${id}`).innerHTML = `
<form onsubmit="submitInlineSalary(event, ${id})" class="bs-form-inline align-center">
<div class="bs-input-flex"><strong>${person}</strong></div>
<div style="display:flex; align-items:center; gap:4px;"><small class="text-muted">${tr('bs_salary_net')}:</small><input type="number" step="0.01" name="salary" class="pf-input bs-input-fixed" value="${salary}" required> ${currency}</div>
<div style="display:flex; align-items:center; gap:4px;"><small class="text-muted">${tr('bs_salary_fees')}:</small><input type="number" step="0.01" name="mensualite" class="pf-input bs-input-fixed" value="${mensualite}" required> ${currency}</div>
<button type="submit" class="btn btn-secondary">💾</button>
<button type="button" class="btn btn-ghost" onclick="loadBudgetSettingsData()">❌</button>
</form>`;
}
async function submitInlineSalary(event, id) { event.preventDefault(); const form = event.target; const btn = form.querySelector('button'); btn.innerText = '⏳'; btn.disabled = true; try { const fd = new FormData(form); fd.append('action', 'save_salary'); fd.append('id', id); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); await loadBudgetSettingsData(); if (typeof showToast === 'function') showToast("Salaire mis à jour", 'success'); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); btn.innerText = '💾'; btn.disabled = false; } }
async function updateBudgetCurrency(selectEl) { try { const fd = new FormData(); fd.append('action', 'save_currency'); fd.append('currency', selectEl.value); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); if (typeof showToast === 'function') { showToast(`${tr('bs_currency_updated')} ✅`, 'success'); } await loadBudgetSettingsData(); } catch (err) { if (typeof showToast === 'function') showToast(err.message, 'error'); else alert("Erreur : " + err.message); } }
// CSV
function toggleCsvAmountCols(type) { if (type === 'split') { document.getElementById('wrapper_col_credit').style.display = 'block'; document.getElementById('lbl_col_debit').innerText = tr('bs_csv_col_debit'); } else { document.getElementById('wrapper_col_credit').style.display = 'none'; document.getElementById('lbl_col_debit').innerText = tr('bs_csv_col_amount'); } }
function renderCsvMapping(mapping) { if (!mapping) return; document.getElementById('csv_delimiter').value = mapping.delimiter || ';'; document.getElementById('csv_date_format').value = mapping.date_format || 'd/m/Y'; document.getElementById('csv_col_date').value = mapping.col_date ?? 0; document.getElementById('csv_col_label').value = mapping.col_label ?? 1; document.getElementById('csv_col_ref').value = mapping.col_ref ?? 3; const amountType = mapping.amount_type || 'split'; document.getElementById('csv_amount_type').value = amountType; document.getElementById('csv_col_debit').value = mapping.col_debit ?? 8; document.getElementById('csv_col_credit').value = mapping.col_credit ?? 9; toggleCsvAmountCols(amountType); }
async function saveCsvMapping(e) { e.preventDefault(); const form = e.target; const btn = form.querySelector('button'); const oldText = btn.innerText; btn.innerText = '⏳...'; btn.disabled = true; try { const fd = new FormData(form); fd.append('action', 'save_csv_mapping'); await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd }); if (typeof showToast === 'function') showToast(tr('bs_csv_saved'), 'success'); else alert(tr('bs_csv_saved')); } catch (err) { if (typeof showToast === 'function') showToast(tr('error_occured') + " : " + err.message, 'error'); else alert(tr('error_occured') + " : " + err.message); } finally { btn.innerText = oldText; btn.disabled = false; } }
const dropZone = document.getElementById('csv-drop-zone'); const fileInput = document.getElementById('csv_file_input');
if (dropZone && fileInput) {
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', (e) => { e.preventDefault(); dropZone.style.backgroundColor = 'rgba(0, 123, 255, 0.05)'; dropZone.style.borderColor = 'var(--primary-color, #007bff)'; });
dropZone.addEventListener('dragleave', (e) => { e.preventDefault(); dropZone.style.backgroundColor = ''; dropZone.style.borderColor = 'var(--border-light, #ccc)'; });
dropZone.addEventListener('drop', (e) => { e.preventDefault(); dropZone.style.backgroundColor = ''; dropZone.style.borderColor = 'var(--border-light, #ccc)'; if (e.dataTransfer.files.length) { fileInput.files = e.dataTransfer.files; handleCsvUpload(e.dataTransfer.files[0]); } });
fileInput.addEventListener('change', function() { if (this.files.length) { handleCsvUpload(this.files[0]); } });
}
function handleCsvUpload(file) {
if (!file.name.endsWith('.csv')) {
if (typeof showToast === 'function') showToast(tr('bs_csv_err_type'), 'error'); else alert(tr('bs_csv_err_type'));
return;
}
if (typeof showToast === 'function') { showToast(`${tr('bs_csv_file_ok')} : ${file.name}`, 'success'); }
const reader = new FileReader();
reader.onload = function(e) {
const text = e.target.result; const delimiter = document.getElementById('csv_delimiter').value || ';';
const lines = text.split(/\r?\n/).filter(line => line.trim().length > 0);
if (lines.length > 0) {
const headers = lines[0].split(delimiter).map(h => h.replace(/^"|"$/g, '').trim());
const sampleRows = [];
for (let i = 1; i < Math.min(lines.length, 3); i++) { sampleRows.push(lines[i].split(delimiter).map(d => d.replace(/^"|"$/g, '').trim())); }
renderCsvTablePreview(headers, sampleRows);
}
};
reader.readAsText(file, 'ISO-8859-1');
}
async function saveDynamicEstimates(e) {
e.preventDefault();
const form = e.target;
const btn = form.querySelector('button');
const oldText = btn.innerText;
btn.innerText = '⏳...';
btn.disabled = true;
try {
const fd = new FormData(form);
fd.append('action', 'save_dynamic_estimates');
await pachaFetch('/modules/budget/includes/api/settings.php', { method: 'POST', body: fd });
if (typeof showToast === 'function') showToast(window.I18N['fc_settings_updated'] || 'Paramètres enregistrés', 'success');
} catch (err) {
if (typeof showToast === 'function') showToast((window.I18N['error_occured'] || 'Erreur') + " : " + err.message, 'error');
} finally {
btn.innerText = oldText;
btn.disabled = false;
}
}
</script>
File diff suppressed because it is too large. Load diff
+418
View File
@@ -0,0 +1,418 @@
<?php
ob_start();
require_once dirname(__DIR__, 2) . '/includes/auth.php';
require_login();
require_once dirname(__DIR__, 2) . '/includes/db.php';
require_once dirname(__DIR__, 2) . '/includes/meta_db.php';
require_once __DIR__ . '/caldav_sync.php';
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
$action = $_GET['action'] ?? '';
$userId = (int)($_SESSION['user']['id'] ?? 0);
$familyId = (int)($_SESSION['user']['family_id'] ?? 0);
$meta_pdo->exec("
CREATE TABLE IF NOT EXISTS user_calendar_integrations (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
provider VARCHAR(50) NOT NULL DEFAULT 'icloud_caldav',
username VARCHAR(255) NOT NULL,
secret_encrypted TEXT NOT NULL,
dav_principal_url VARCHAR(1024) DEFAULT NULL,
calendar_url VARCHAR(1024) DEFAULT NULL,
status VARCHAR(30) DEFAULT 'connected',
last_sync_at DATETIME DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_user_provider (user_id, provider)
)");
try {
$meta_pdo->exec('ALTER TABLE user_calendar_integrations ADD COLUMN calendar_prefs_json TEXT NULL');
} catch (Throwable $e) {
// colonne déjà présente
}
$pdo->exec("
CREATE TABLE IF NOT EXISTS pf_calendar_events (
id INT AUTO_INCREMENT PRIMARY KEY,
family_id INT NOT NULL,
created_by_user_id INT NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT DEFAULT NULL,
location VARCHAR(255) DEFAULT NULL,
start_at DATETIME NOT NULL,
end_at DATETIME NOT NULL,
is_all_day TINYINT(1) DEFAULT 0,
timezone VARCHAR(64) DEFAULT 'Europe/Paris',
rrule VARCHAR(500) DEFAULT NULL,
status VARCHAR(50) DEFAULT 'confirmed',
external_uid VARCHAR(255) DEFAULT NULL,
sync_state VARCHAR(30) DEFAULT 'pending_push',
deleted_at DATETIME DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_external_uid (external_uid)
)");
$pdo->exec("
CREATE TABLE IF NOT EXISTS pf_calendar_event_links (
id INT AUTO_INCREMENT PRIMARY KEY,
calendar_event_id INT NOT NULL,
external_uid VARCHAR(255) NOT NULL,
external_etag VARCHAR(255) DEFAULT NULL,
calendar_url VARCHAR(1024) DEFAULT NULL,
external_href VARCHAR(2048) DEFAULT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_calendar_event (calendar_event_id),
UNIQUE KEY uq_external_link (external_uid)
)");
try {
$pdo->exec('ALTER TABLE pf_calendar_event_links ADD COLUMN external_href VARCHAR(2048) DEFAULT NULL');
} catch (Throwable $e) {
// colonne déjà présente
}
function ios_ok($data): void { echo json_encode(['ok' => true, 'data' => $data], JSON_UNESCAPED_UNICODE); exit; }
function ios_err(string $message, int $status = 400): void { http_response_code($status); echo json_encode(['ok' => false, 'error' => $message]); exit; }
function ios_body(): array { return json_decode(file_get_contents('php://input'), true) ?? []; }
function ios_require_csrf(): void {
$token = $_SERVER['HTTP_X_CSRF_TOKEN'] ?? null;
if (!verify_csrf($token)) {
ios_err('Token CSRF invalide', 403);
}
}
function ios_normalize_datetime(?string $s): ?string
{
if ($s === null || $s === '') {
return null;
}
$s = str_replace('T', ' ', trim($s));
if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/', $s)) {
$s .= ':00';
}
return $s;
}
function ios_calendar_url_key(?string $url): string
{
if ($url === null || $url === '') {
return '';
}
return rtrim(trim($url), '/');
}
/** @return array<string, array{visible:bool, color:?string}> */
function ios_calendar_prefs_decode(?string $json): array
{
if ($json === null || $json === '') {
return [];
}
$d = json_decode($json, true);
if (!is_array($d)) {
return [];
}
$out = [];
foreach ($d as $k => $v) {
if (!is_string($k) || $k === '' || !is_array($v)) {
continue;
}
$key = ios_calendar_url_key($k);
if ($key === '') {
continue;
}
$out[$key] = [
'visible' => !array_key_exists('visible', $v) ? true : (bool) $v['visible'],
'color' => (isset($v['color']) && is_string($v['color']) && preg_match('/^#[0-9A-Fa-f]{6}$/', $v['color'])) ? $v['color'] : null,
];
}
return $out;
}
/**
* @return list<array{url:string,url_key:string,display:string,visible:bool,color:?string}>
*/
function ios_list_calendar_sources_for_ui(array $integration, string $password, PDO $pdo): array
{
$prefs = ios_calendar_prefs_decode($integration['calendar_prefs_json'] ?? null);
$urlsMeta = [];
$primary = $integration['calendar_url'] ?? '';
if (hh_caldav_url_is_icloud($primary)) {
try {
foreach (hh_icloud_discover_calendar_entries($integration['username'], $password) as $e) {
$k = ios_calendar_url_key($e['url']);
if ($k === '') {
continue;
}
$disp = trim((string) ($e['display'] ?? ''));
if ($disp === '') {
$disp = basename(parse_url($e['url'], PHP_URL_PATH) ?: '') ?: $k;
}
$urlsMeta[$k] = ['url' => rtrim($e['url'], '/') . '/', 'display' => $disp];
}
} catch (Throwable $e) {
}
} else {
$k = ios_calendar_url_key($primary);
if ($k !== '') {
$urlsMeta[$k] = ['url' => rtrim($primary, '/') . '/', 'display' => 'Calendrier'];
}
}
$stmt = $pdo->query("
SELECT DISTINCT l.calendar_url AS u
FROM pf_calendar_event_links l
INNER JOIN pf_calendar_events e ON e.id = l.calendar_event_id
WHERE e.deleted_at IS NULL AND l.calendar_url IS NOT NULL AND TRIM(l.calendar_url) != ''
");
foreach ($stmt->fetchAll(PDO::FETCH_COLUMN) as $u) {
$k = ios_calendar_url_key((string) $u);
if ($k === '' || isset($urlsMeta[$k])) {
continue;
}
$urlsMeta[$k] = [
'url' => rtrim((string) $u, '/') . '/',
'display' => basename(parse_url((string) $u, PHP_URL_PATH) ?: '') ?: $k,
];
}
$out = [];
foreach ($urlsMeta as $key => $meta) {
$p = $prefs[$key] ?? [];
$visible = !array_key_exists('visible', $p) ? true : (bool) $p['visible'];
$color = (isset($p['color']) && is_string($p['color']) && preg_match('/^#[0-9A-Fa-f]{6}$/', $p['color'])) ? $p['color'] : null;
$out[] = [
'url' => $meta['url'],
'url_key' => $key,
'display' => $meta['display'],
'visible' => $visible,
'color' => $color,
];
}
usort($out, static fn ($a, $b) => strcasecmp($a['display'], $b['display']));
return $out;
}
$integrationStmt = $meta_pdo->prepare("SELECT * FROM user_calendar_integrations WHERE user_id = ? AND provider='icloud_caldav'");
$integrationStmt->execute([$userId]);
$integration = $integrationStmt->fetch();
if ($action === 'events' && $method === 'GET') {
$prefs = [];
if ($integration) {
$prefs = ios_calendar_prefs_decode($integration['calendar_prefs_json'] ?? null);
}
$rows = $pdo->query("
SELECT e.*, l.calendar_url AS calendar_source_url
FROM pf_calendar_events e
LEFT JOIN pf_calendar_event_links l ON l.calendar_event_id = e.id
WHERE e.deleted_at IS NULL
ORDER BY e.start_at ASC
")->fetchAll();
$out = [];
foreach ($rows as $r) {
$key = ios_calendar_url_key($r['calendar_source_url'] ?? '');
if ($key !== '' && isset($prefs[$key]['visible']) && $prefs[$key]['visible'] === false) {
continue;
}
$r['display_color'] = null;
if ($key !== '' && !empty($prefs[$key]['color']) && is_string($prefs[$key]['color']) && preg_match('/^#[0-9A-Fa-f]{6}$/', $prefs[$key]['color'])) {
$r['display_color'] = $prefs[$key]['color'];
}
$out[] = $r;
}
ios_ok($out);
}
if ($action === 'calendar_sources' && $method === 'GET') {
if (!$integration) {
ios_ok(['calendars' => []]);
}
try {
$ctx = ios_caldav_prepare($integration, $meta_pdo);
} catch (Throwable $e) {
ios_err('CalDAV: ' . $e->getMessage(), 400);
}
$integrationStmt->execute([$userId]);
$integrationFresh = $integrationStmt->fetch();
if (!$integrationFresh) {
ios_ok(['calendars' => []]);
}
ios_ok(['calendars' => ios_list_calendar_sources_for_ui($integrationFresh, $ctx['password'], $pdo)]);
}
if ($action === 'calendar_prefs' && $method === 'POST') {
ios_require_csrf();
if (!$integration) {
ios_err('Connexion iCloud non configurée.', 400);
}
$body = ios_body();
$raw = $body['prefs'] ?? null;
if (!is_array($raw)) {
ios_err('Format prefs invalide', 400);
}
$clean = [];
foreach ($raw as $key => $p) {
if (!is_array($p)) {
continue;
}
$urlKey = ios_calendar_url_key(is_string($key) ? $key : '');
if ($urlKey === '') {
continue;
}
$visible = array_key_exists('visible', $p) ? (bool) $p['visible'] : true;
$col = $p['color'] ?? null;
if ($col !== null && $col !== '' && is_string($col) && preg_match('/^#[0-9A-Fa-f]{6}$/', $col)) {
$col = '#' . strtolower(substr($col, 1));
} else {
$col = null;
}
$clean[$urlKey] = ['visible' => $visible, 'color' => $col];
}
$existing = ios_calendar_prefs_decode($integration['calendar_prefs_json'] ?? null);
foreach ($clean as $urlKey => $v) {
$existing[$urlKey] = $v;
}
$json = json_encode($existing, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$meta_pdo->prepare('UPDATE user_calendar_integrations SET calendar_prefs_json = ? WHERE id = ?')->execute([$json, $integration['id']]);
ios_ok(['saved' => true]);
}
if ($action === 'events' && $method === 'POST') {
ios_require_csrf();
$d = ios_body();
if (empty($d['title']) || empty($d['start_at']) || empty($d['end_at'])) {
ios_err('Champs requis manquants');
}
$stmt = $pdo->prepare("
INSERT INTO pf_calendar_events (family_id, created_by_user_id, title, description, location, start_at, end_at, timezone, sync_state)
VALUES (?, ?, ?, ?, ?, ?, ?, 'Europe/Paris', 'pending_push')
");
$stmt->execute([
$familyId, $userId, trim($d['title']), $d['description'] ?? null, $d['location'] ?? null,
ios_normalize_datetime($d['start_at'] ?? null), ios_normalize_datetime($d['end_at'] ?? null),
]);
ios_ok(['id' => (int)$pdo->lastInsertId()]);
}
if ($action === 'events' && $method === 'PUT') {
ios_require_csrf();
$d = ios_body();
$id = (int)($d['id'] ?? 0);
if ($id <= 0) ios_err('ID invalide');
$stmt = $pdo->prepare("
UPDATE pf_calendar_events
SET title=?, description=?, location=?, start_at=?, end_at=?, updated_at=NOW(), sync_state='pending_push'
WHERE id=?
");
$stmt->execute([
trim($d['title'] ?? ''), $d['description'] ?? null, $d['location'] ?? null,
ios_normalize_datetime($d['start_at'] ?? null), ios_normalize_datetime($d['end_at'] ?? null), $id,
]);
ios_ok(['updated' => true]);
}
if ($action === 'events' && $method === 'DELETE') {
ios_require_csrf();
$d = ios_body();
$id = (int)($d['id'] ?? 0);
if ($id <= 0) ios_err('ID invalide');
$row = $pdo->prepare("SELECT id FROM pf_calendar_events WHERE id=?");
$row->execute([$id]);
if (!$row->fetch()) ios_err('Événement introuvable', 404);
$pdo->prepare("UPDATE pf_calendar_events SET deleted_at=NOW(), sync_state='pending_delete' WHERE id=?")->execute([$id]);
ios_ok(['deleted' => true]);
}
if ($action === 'sync_status' && $method === 'GET') {
if (!$integration) {
ios_ok(['message' => 'Aucune intégration iCloud configurée.']);
}
$msg = 'Connecté iCloud. Dernière synchro: ' . ($integration['last_sync_at'] ?? 'jamais');
ios_ok(['message' => $msg]);
}
if ($action === 'sync' && $method === 'POST') {
ios_require_csrf();
if (!$integration) ios_err('Connexion iCloud non configurée.', 400);
try {
$ctx = ios_caldav_prepare($integration, $meta_pdo);
$integration = $ctx['integration'];
$davPassword = $ctx['password'];
$syncUrls = ios_sync_calendar_collection_urls($integration, $davPassword);
$remoteEvents = ios_fetch_remote_events_all_calendars($integration, $davPassword);
$localStmt = $pdo->query("SELECT * FROM pf_calendar_events WHERE deleted_at IS NULL");
$localEvents = $localStmt->fetchAll();
$linkStmt = $pdo->prepare('SELECT external_href, calendar_url FROM pf_calendar_event_links WHERE calendar_event_id = ?');
foreach ($localEvents as $evt) {
if ($evt['sync_state'] === 'pending_push' || empty($evt['external_uid'])) {
$linkStmt->execute([$evt['id']]);
$lr = $linkStmt->fetch() ?: [];
$push = ios_push_event_to_remote(
$integration,
$evt,
$davPassword,
$lr['external_href'] ?? null,
$lr['calendar_url'] ?? null
);
if ($push['code'] >= 200 && $push['code'] < 300) {
$uid = $evt['external_uid'] ?: ('hh-' . $evt['id'] . '@househub');
$pdo->prepare("UPDATE pf_calendar_events SET external_uid=?, sync_state='synced', updated_at=NOW() WHERE id=?")->execute([$uid, $evt['id']]);
$pdo->prepare("INSERT INTO pf_calendar_event_links (calendar_event_id, external_uid, calendar_url, external_etag, external_href) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE external_etag=VALUES(external_etag), calendar_url=VALUES(calendar_url), external_href=COALESCE(VALUES(external_href), external_href), updated_at=NOW()")
->execute([$evt['id'], $uid, $integration['calendar_url'], null, $lr['external_href'] ?? null]);
}
}
}
$pendingDelete = $pdo->query("SELECT id, external_uid FROM pf_calendar_events WHERE deleted_at IS NOT NULL AND sync_state='pending_delete'")->fetchAll();
foreach ($pendingDelete as $evt) {
if (!empty($evt['external_uid'])) {
$linkStmt->execute([$evt['id']]);
$lr = $linkStmt->fetch() ?: [];
ios_delete_remote_event(
$integration,
$evt['external_uid'],
$davPassword,
$lr['external_href'] ?? null,
$lr['calendar_url'] ?? null
);
}
$pdo->prepare("DELETE FROM pf_calendar_event_links WHERE calendar_event_id=?")->execute([$evt['id']]);
$pdo->prepare("DELETE FROM pf_calendar_events WHERE id=?")->execute([$evt['id']]);
}
foreach ($remoteEvents as $remote) {
$href = $remote['_resource_url'] ?? null;
$colUrl = $remote['_calendar_collection_url'] ?? $integration['calendar_url'];
$existing = $pdo->prepare("SELECT id, updated_at FROM pf_calendar_events WHERE external_uid=? LIMIT 1");
$existing->execute([$remote['external_uid']]);
$row = $existing->fetch();
if (!$row) {
$pdo->prepare("
INSERT INTO pf_calendar_events (family_id, created_by_user_id, title, description, location, start_at, end_at, timezone, external_uid, sync_state)
VALUES (?, ?, ?, ?, ?, ?, ?, 'Europe/Paris', ?, 'synced')
")->execute([$familyId, $userId, $remote['title'], $remote['description'], $remote['location'], $remote['start_at'], $remote['end_at'], $remote['external_uid']]);
$newId = (int)$pdo->lastInsertId();
$pdo->prepare("INSERT INTO pf_calendar_event_links (calendar_event_id, external_uid, calendar_url, external_etag, external_href) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE calendar_url=VALUES(calendar_url), external_href=COALESCE(VALUES(external_href), external_href), updated_at=NOW()")
->execute([$newId, $remote['external_uid'], $colUrl, null, $href]);
} elseif ($href) {
$pdo->prepare('UPDATE pf_calendar_event_links SET external_href = COALESCE(external_href, ?), calendar_url = COALESCE(calendar_url, ?) WHERE calendar_event_id = ?')
->execute([$href, $colUrl, $row['id']]);
}
}
$meta_pdo->prepare("UPDATE user_calendar_integrations SET last_sync_at=NOW(), status='connected' WHERE id=?")->execute([$integration['id']]);
$n = count($remoteEvents);
$nc = count($syncUrls);
ios_ok(['message' => 'Synchronisation terminée. ' . $n . ' événement(s) depuis ' . $nc . ' calendrier(s) distant(s).']);
} catch (Throwable $e) {
ios_err('CalDAV: ' . $e->getMessage(), 400);
}
}
ios_err('Action inconnue', 404);
@@ -0,0 +1,600 @@
/* ─── Page layout (cartes claires hors agenda) ─────────────────────────── */
.ios-calendar-wrap {
display: flex;
flex-direction: column;
gap: 16px;
}
.ios-calendar-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.ios-calendar-head h1 {
margin: 0;
font-size: 1.4rem;
}
.ios-agenda-intro {
margin: 0;
font-size: 0.9rem;
color: var(--pf-text-muted, #64748b);
line-height: 1.45;
}
.ios-cal-prefs-details {
margin-top: 14px;
border: 1px solid var(--pf-border, #e2e8f0);
border-radius: 10px;
padding: 10px 14px;
background: var(--pf-bg-page, #fff);
}
.ios-cal-prefs-summary {
cursor: pointer;
font-weight: 600;
font-size: 0.95rem;
}
.ios-cal-prefs-help {
margin: 10px 0 12px;
font-size: 0.85rem;
color: var(--pf-text-muted, #64748b);
line-height: 1.45;
}
.ios-cal-prefs-rows {
display: flex;
flex-direction: column;
gap: 10px;
margin-bottom: 12px;
}
.ios-cal-pref-row {
display: grid;
grid-template-columns: auto 1fr auto auto;
align-items: center;
gap: 10px 12px;
padding: 8px 10px;
border: 1px solid var(--pf-border, #e2e8f0);
border-radius: 8px;
background: var(--pf-bg-lighter, #f8fafc);
}
.ios-cal-pref-row input[type="checkbox"] {
width: 18px;
height: 18px;
}
.ios-cal-pref-label {
font-size: 0.88rem;
min-width: 0;
word-break: break-word;
}
.ios-cal-pref-color {
width: 44px;
height: 36px;
padding: 2px;
border: 1px solid var(--pf-border, #e2e8f0);
border-radius: 8px;
cursor: pointer;
background: var(--pf-bg-page, #fff);
}
.ios-cal-pref-reset {
border: none;
background: transparent;
color: var(--pf-text-muted, #64748b);
font-size: 0.78rem;
text-decoration: underline;
cursor: pointer;
padding: 4px;
font-family: inherit;
white-space: nowrap;
}
.ios-cal-pref-reset:hover {
color: var(--pf-text-main, #0f172a);
}
.ios-cal-prefs-msg {
min-height: 1.25em;
font-size: 0.85rem;
margin: 0 0 10px;
}
@media (max-width: 640px) {
.ios-cal-pref-row {
grid-template-columns: auto 1fr;
grid-template-rows: auto auto;
}
.ios-cal-pref-color {
grid-column: 2;
}
.ios-cal-pref-reset {
grid-column: 2;
justify-self: start;
}
}
.ios-form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.ios-form-full {
grid-column: 1 / -1;
}
.ios-form-actions {
display: flex;
gap: 8px;
}
.ios-events-list {
display: grid;
gap: 10px;
}
.ios-event-card {
border: 1px solid var(--pf-border, #e2e8f0);
border-radius: 10px;
padding: 12px;
background: var(--pf-bg-page, #fff);
}
.ios-event-card-head {
display: flex;
justify-content: space-between;
gap: 10px;
align-items: center;
}
.ios-event-card-title {
font-weight: 700;
}
.ios-event-card-meta {
color: var(--pf-text-muted, #64748b);
font-size: 0.9rem;
}
.ios-event-card-actions {
display: flex;
gap: 8px;
}
/* ─── Agenda sombre (style type app calendrier) ─────────────────────────── */
.ios-agenda-card {
--ios-bg: #0a0a0c;
--ios-elev: #12121a;
--ios-border: rgba(255, 255, 255, 0.08);
--ios-text: #f1f5f9;
--ios-muted: #94a3b8;
--ios-now: #ef4444;
--ios-seg-bg: #1a1a22;
background: var(--ios-bg);
border: 1px solid var(--ios-border);
color: var(--ios-text);
border-radius: 12px;
overflow: hidden;
}
.ios-agenda-toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 16px;
border-bottom: 1px solid var(--ios-border);
background: var(--ios-elev);
}
.ios-agenda-title {
font-size: 1.05rem;
font-weight: 700;
text-transform: capitalize;
min-width: 140px;
}
.ios-agenda-segments {
display: inline-flex;
background: var(--ios-seg-bg);
border-radius: 10px;
padding: 3px;
gap: 2px;
}
.ios-seg {
border: none;
background: transparent;
color: var(--ios-muted);
padding: 7px 16px;
border-radius: 8px;
font-size: 0.85rem;
cursor: pointer;
font-family: inherit;
}
.ios-seg:hover {
color: var(--ios-text);
}
.ios-seg--active {
background: #2d2d38;
color: var(--ios-text);
font-weight: 600;
}
.ios-agenda-nav {
display: flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
.ios-agenda-btn {
border: 1px solid var(--ios-border);
background: var(--ios-elev);
color: var(--ios-text);
border-radius: 8px;
padding: 6px 12px;
font-size: 0.85rem;
cursor: pointer;
font-family: inherit;
}
.ios-agenda-btn:hover {
background: #1e1e28;
}
.ios-agenda-btn--ghost {
background: transparent;
}
.ios-agenda-today {
border: none;
background: transparent;
color: var(--ios-now);
font-weight: 600;
font-size: 0.85rem;
cursor: pointer;
padding: 6px 10px;
font-family: inherit;
}
.ios-agenda-add {
width: 36px;
height: 36px;
border-radius: 10px;
border: 1px solid var(--ios-border);
background: var(--ios-elev);
color: var(--ios-text);
font-size: 1.35rem;
line-height: 1;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-family: inherit;
}
.ios-agenda-add:hover {
background: #1e1e28;
}
.ios-agenda-listlink {
border: none;
background: transparent;
color: var(--ios-muted);
font-size: 0.82rem;
text-decoration: underline;
cursor: pointer;
padding: 6px 8px;
font-family: inherit;
}
.ios-agenda-listlink:hover {
color: var(--ios-text);
}
.ios-agenda-mount {
min-height: 200px;
}
.ios-agenda-list-hint {
margin: 0;
padding: 20px 16px;
color: var(--ios-muted);
font-size: 0.9rem;
line-height: 1.5;
}
/* Grille semaine / jour */
.ios-week-wrap {
display: flex;
flex-direction: column;
}
.ios-week-head {
display: grid;
grid-template-columns: 52px repeat(7, minmax(0, 1fr));
border-bottom: 1px solid var(--ios-border);
background: var(--ios-elev);
font-size: 0.78rem;
color: var(--ios-muted);
}
.ios-week-head--day {
grid-template-columns: 52px minmax(0, 1fr);
}
.ios-week-corner {
border-right: 1px solid var(--ios-border);
}
.ios-week-head-day {
text-align: center;
padding: 10px 4px;
border-left: 1px solid var(--ios-border);
}
.ios-week-head-num {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 28px;
height: 28px;
border-radius: 50%;
font-weight: 700;
color: var(--ios-text);
margin-right: 4px;
}
.ios-week-head-day--today .ios-week-head-num {
background: var(--ios-now);
color: #fff;
}
.ios-week-scroll {
max-height: min(70vh, 720px);
overflow-y: auto;
overflow-x: auto;
}
.ios-week-track {
display: flex;
min-width: min(100%, 720px);
align-items: stretch;
}
.ios-agenda-gutter {
width: 52px;
flex-shrink: 0;
border-right: 1px solid var(--ios-border);
background: var(--ios-bg);
}
.ios-agenda-gutter-cell {
height: 44px;
font-size: 0.72rem;
color: var(--ios-muted);
text-align: right;
padding-right: 8px;
line-height: 44px;
box-sizing: border-box;
}
.ios-agenda-cols-wrap {
flex: 1;
position: relative;
min-width: 0;
display: flex;
min-height: 704px;
}
.ios-agenda-cols {
flex: 1;
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
min-width: 0;
min-height: 704px;
}
.ios-agenda-cols--day {
grid-template-columns: minmax(0, 1fr);
}
.ios-agenda-col {
border-left: 1px solid var(--ios-border);
background-color: var(--ios-bg);
background-image: repeating-linear-gradient(
to bottom,
transparent,
transparent 43px,
var(--ios-border) 43px,
var(--ios-border) 44px
);
}
.ios-agenda-col:first-child {
border-left: none;
}
.ios-agenda-col-inner {
position: relative;
}
.ios-event-block {
position: absolute;
border: none;
border-radius: 6px;
padding: 4px 6px;
text-align: left;
cursor: pointer;
overflow: hidden;
box-sizing: border-box;
color: #fff;
font-size: 0.72rem;
line-height: 1.25;
box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.35);
}
.ios-event-block--custom {
border: none !important;
color: #fff !important;
box-shadow: inset 3px 0 0 rgba(255, 255, 255, 0.35) !important;
}
.ios-event-block-title {
display: -webkit-box;
-webkit-line-clamp: 4;
-webkit-box-orient: vertical;
overflow: hidden;
}
.ios-cal-c0 {
background: linear-gradient(135deg, #166534, #15803d);
}
.ios-cal-c1 {
background: linear-gradient(135deg, #1e40af, #2563eb);
}
.ios-cal-c2 {
background: linear-gradient(135deg, #6b21a8, #7c3aed);
}
.ios-cal-c3 {
background: linear-gradient(135deg, #a16207, #ca8a04);
}
.ios-cal-c4 {
background: linear-gradient(135deg, #0f766e, #14b8a6);
}
.ios-cal-c5 {
background: linear-gradient(135deg, #9f1239, #e11d48);
}
.ios-now-overlay {
position: absolute;
inset: 0;
pointer-events: none;
z-index: 6;
}
.ios-now-line-span {
position: absolute;
left: 0;
right: 0;
height: 2px;
background: var(--ios-now);
box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
}
.ios-now-lbl-span {
position: absolute;
left: 6px;
font-size: 0.68rem;
font-weight: 700;
color: var(--ios-now);
text-shadow: 0 0 6px #000;
}
/* Mois (dans carte sombre) */
.ios-month-agenda {
padding: 12px 14px 16px;
}
.ios-month-agenda-weekdays {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
margin-bottom: 8px;
font-size: 0.72rem;
color: var(--ios-muted);
text-align: center;
}
.ios-month-agenda-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 4px;
}
.ios-month-cell {
aspect-ratio: 1;
min-height: 40px;
border: 1px solid var(--ios-border);
border-radius: 8px;
background: var(--ios-elev);
color: var(--ios-text);
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
padding: 4px 2px;
font: inherit;
}
.ios-month-cell--pad {
visibility: hidden;
pointer-events: none;
border: none;
background: transparent;
}
.ios-month-cell--today {
border-color: var(--ios-now);
box-shadow: 0 0 0 1px rgba(239, 68, 68, 0.35);
}
.ios-month-cell--has {
background: #1a1a24;
}
.ios-month-num {
font-size: 0.85rem;
font-weight: 600;
}
.ios-month-dots {
display: flex;
gap: 2px;
flex-wrap: wrap;
justify-content: center;
margin-top: 2px;
}
.ios-month-dot {
width: 4px;
height: 4px;
border-radius: 50%;
background: #60a5fa;
}
@media (max-width: 768px) {
.ios-form-grid {
grid-template-columns: 1fr;
}
.ios-calendar-head {
flex-direction: column;
align-items: flex-start;
}
.ios-event-card-head {
flex-direction: column;
align-items: flex-start;
}
.ios-agenda-toolbar {
flex-direction: column;
align-items: stretch;
}
.ios-agenda-segments {
justify-content: center;
}
.ios-agenda-nav {
justify-content: center;
}
}
+700
View File
@@ -0,0 +1,700 @@
const iosEventsList = document.getElementById("ios-events-list");
const iosSyncStatus = document.getElementById("ios-sync-status");
const iosForm = document.getElementById("ios-event-form");
const iosAgendaMount = document.getElementById("ios-agenda-mount");
const iosAgendaTitle = document.getElementById("ios-agenda-title");
const H_START = 6;
const H_END = 22;
const PX_PER_H = 44;
const TRACK_H = (H_END - H_START) * PX_PER_H;
let iosEventsCache = [];
/** @type {'day'|'week'|'month'} */
let iosViewMode = "week";
/** Ancre de navigation (jour courant dans la période affichée) */
let iosCursor = new Date();
let iosNowTimer = null;
let iosListVisible = false;
const PALETTE = [
"ios-cal-c0",
"ios-cal-c1",
"ios-cal-c2",
"ios-cal-c3",
"ios-cal-c4",
"ios-cal-c5",
];
const SUGGEST_HEX = ["#22c55e", "#3b82f6", "#8b5cf6", "#eab308", "#14b8a6", "#f43f5e"];
function escHtml(s) {
const d = document.createElement("div");
d.textContent = s ?? "";
return d.innerHTML;
}
function sqlToDatetimeLocal(s) {
if (!s) return "";
const m = /^(\d{4})-(\d{2})-(\d{2})[\sT](\d{2}):(\d{2})/.exec(String(s).trim());
if (!m) return "";
return `${m[1]}-${m[2]}-${m[3]}T${m[4]}:${m[5]}`;
}
function localDatetimeToSql(s) {
if (!s) return "";
const t = s.includes("T") ? s.replace("T", " ") : s;
return t.length === 16 ? `${t}:00` : t;
}
function parseEvtDate(iso) {
const d = new Date(String(iso).replace(" ", "T"));
return Number.isNaN(d.getTime()) ? null : d;
}
function darkenHex(hex, amount) {
const n = parseInt(hex.slice(1), 16);
const r = Math.max(0, (n >> 16) - amount);
const g = Math.max(0, ((n >> 8) & 0xff) - amount);
const b = Math.max(0, (n & 0xff) - amount);
return `#${[r, g, b].map((x) => x.toString(16).padStart(2, "0")).join("")}`;
}
function suggestedColorForKey(key) {
const k = String(key || "");
let h = 0;
for (let i = 0; i < k.length; i++) h = (h * 31 + k.charCodeAt(i)) >>> 0;
return SUGGEST_HEX[h % SUGGEST_HEX.length];
}
function colorClassForEvent(evt) {
const key = String(evt.calendar_source_url || evt.external_uid || evt.id || "");
let h = 0;
for (let i = 0; i < key.length; i++) h = (h * 31 + key.charCodeAt(i)) >>> 0;
return PALETTE[h % PALETTE.length];
}
/** Applique couleur perso (API) ou palette par défaut */
function styleEventBlock(el, evt) {
el.className = "ios-event-block";
el.style.background = "";
el.style.boxShadow = "";
const hex = evt.display_color;
if (hex && /^#[0-9A-Fa-f]{6}$/i.test(hex)) {
const c = hex.startsWith("#") ? hex : `#${hex.slice(-6)}`;
el.classList.add("ios-event-block--custom");
el.style.background = `linear-gradient(135deg, ${darkenHex(c, 40)} 0%, ${c} 100%)`;
el.style.boxShadow = "inset 3px 0 0 rgba(255,255,255,0.35)";
} else {
el.classList.add(colorClassForEvent(evt));
}
}
function mondayOf(date) {
const d = new Date(date.getFullYear(), date.getMonth(), date.getDate());
const dow = d.getDay();
const diff = dow === 0 ? -6 : 1 - dow;
d.setDate(d.getDate() + diff);
return d;
}
function addDays(d, n) {
const x = new Date(d);
x.setDate(x.getDate() + n);
return x;
}
function addMonths(d, n) {
const x = new Date(d);
x.setMonth(x.getMonth() + n);
return x;
}
function sameLocalDay(a, b) {
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
}
/** Segment d’un événement visible dans [dayMidnight, dayMidnight+1j[ */
function segmentInLocalDay(evt, dayMidnight) {
const s = parseEvtDate(evt.start_at);
const e = parseEvtDate(evt.end_at);
if (!s || !e) return null;
const dayEnd = addDays(dayMidnight, 1);
if (e <= dayMidnight || s >= dayEnd) return null;
const segStart = s > dayMidnight ? s : dayMidnight;
const segEnd = e < dayEnd ? e : dayEnd;
return { segStart, segEnd, evt };
}
function pxInTrackFromHourFraction(dayMidnight, t) {
const grid0 = new Date(dayMidnight);
grid0.setHours(H_START, 0, 0, 0);
const grid1 = new Date(dayMidnight);
grid1.setHours(H_END, 0, 0, 0);
const tt = Math.min(Math.max(t.getTime(), grid0.getTime()), grid1.getTime());
return ((tt - grid0.getTime()) / 3600000) * PX_PER_H;
}
function heightPxForSegment(dayMidnight, segStart, segEnd) {
const a = pxInTrackFromHourFraction(dayMidnight, segStart);
const b = pxInTrackFromHourFraction(dayMidnight, segEnd);
return Math.max(18, b - a);
}
function nowLineTopPx(colDay) {
const now = new Date();
if (!sameLocalDay(now, colDay)) return null;
return pxInTrackFromHourFraction(colDay, now);
}
function assignLanes(segments) {
if (segments.length === 0) return;
segments.sort((a, b) => a.segStart - b.segStart);
const laneEnds = [];
segments.forEach((seg) => {
let L = 0;
while (laneEnds[L] && seg.segStart < laneEnds[L]) L++;
laneEnds[L] = seg.segEnd;
seg._lane = L;
});
const maxL = segments.reduce((m, s) => Math.max(m, s._lane), 0);
segments.forEach((s) => {
s._laneCount = maxL + 1;
});
}
async function iosApi(action, options = {}) {
const method = options.method || "GET";
const headers = {
Accept: "application/json",
"X-Requested-With": "XMLHttpRequest",
...(options.headers || {}),
};
if (method !== "GET") {
headers["X-CSRF-Token"] = window.CSRF_TOKEN || "";
headers["Content-Type"] = "application/json";
}
const response = await fetch(`/modules/calendar-ios/api.php?action=${encodeURIComponent(action)}`, {
method,
credentials: "same-origin",
headers,
body: options.body ? JSON.stringify(options.body) : undefined,
});
const json = await response.json();
if (!json.ok) throw new Error(json.error || "Erreur inconnue");
return json.data;
}
function formatDate(iso) {
const d = parseEvtDate(iso);
return d ? d.toLocaleString("fr-FR") : iso;
}
function fillForm(evt) {
document.getElementById("ios-event-id").value = evt.id;
document.getElementById("ios-title").value = evt.title || "";
document.getElementById("ios-location").value = evt.location || "";
document.getElementById("ios-description").value = evt.description || "";
document.getElementById("ios-start").value = sqlToDatetimeLocal(evt.start_at);
document.getElementById("ios-end").value = sqlToDatetimeLocal(evt.end_at);
}
function resetForm() {
iosForm.reset();
document.getElementById("ios-event-id").value = "";
}
function eventsForLocalDay(y, m, d) {
return iosEventsCache.filter((evt) => {
const t = parseEvtDate(evt.start_at);
return t && t.getFullYear() === y && t.getMonth() === m && t.getDate() === d;
});
}
function updateToolbarTitle() {
if (!iosAgendaTitle) return;
if (iosViewMode === "day") {
iosAgendaTitle.textContent = iosCursor.toLocaleDateString("fr-FR", {
weekday: "long",
day: "numeric",
month: "long",
year: "numeric",
});
return;
}
if (iosViewMode === "week") {
const mon = mondayOf(iosCursor);
const sun = addDays(mon, 6);
if (mon.getMonth() === sun.getMonth() && mon.getFullYear() === sun.getFullYear()) {
iosAgendaTitle.textContent = `${mon.getDate()} – ${sun.getDate()} ${sun.toLocaleDateString("fr-FR", { month: "long", year: "numeric" })}`;
} else {
iosAgendaTitle.textContent = `${mon.toLocaleDateString("fr-FR", { day: "numeric", month: "short" })} – ${sun.toLocaleDateString("fr-FR", { day: "numeric", month: "short", year: "numeric" })}`;
}
return;
}
iosAgendaTitle.textContent = new Date(iosCursor.getFullYear(), iosCursor.getMonth(), 1).toLocaleDateString("fr-FR", {
month: "long",
year: "numeric",
});
}
function setActiveSegments() {
document.querySelectorAll(".ios-seg").forEach((b) => {
b.classList.toggle("ios-seg--active", b.getAttribute("data-ios-view") === iosViewMode);
});
}
function renderTimeGutter() {
const frag = document.createDocumentFragment();
for (let h = H_START; h < H_END; h++) {
const row = document.createElement("div");
row.className = "ios-agenda-gutter-cell";
row.textContent = `${h} h`;
frag.appendChild(row);
}
return frag;
}
function buildDayColumn(dayMidnight) {
const col = document.createElement("div");
col.className = "ios-agenda-col";
const inner = document.createElement("div");
inner.className = "ios-agenda-col-inner";
inner.style.height = `${TRACK_H}px`;
const segs = [];
iosEventsCache.forEach((evt) => {
const seg = segmentInLocalDay(evt, dayMidnight);
if (seg) segs.push(seg);
});
assignLanes(segs);
segs.forEach((seg) => {
const top = pxInTrackFromHourFraction(dayMidnight, seg.segStart);
const h = heightPxForSegment(dayMidnight, seg.segStart, seg.segEnd);
const w = 100 / seg._laneCount;
const left = (100 * seg._lane) / seg._laneCount;
const blk = document.createElement("button");
blk.type = "button";
styleEventBlock(blk, seg.evt);
blk.style.top = `${top}px`;
blk.style.height = `${h}px`;
blk.style.left = `calc(${left}% + 2px)`;
blk.style.width = `calc(${w}% - 4px)`;
blk.innerHTML = `<span class="ios-event-block-title">${escHtml(seg.evt.title || "(Sans titre)")}</span>`;
blk.title = [seg.evt.title, seg.evt.location, seg.evt.calendar_source_url].filter(Boolean).join("\n");
blk.addEventListener("click", () => {
fillForm(seg.evt);
document.getElementById("ios-edit-panel")?.scrollIntoView({ behavior: "smooth", block: "start" });
});
inner.appendChild(blk);
});
col.appendChild(inner);
return col;
}
function renderWeekOrDay() {
if (!iosAgendaMount) return;
const isDay = iosViewMode === "day";
const weekStart = isDay ? new Date(iosCursor.getFullYear(), iosCursor.getMonth(), iosCursor.getDate()) : mondayOf(iosCursor);
const days = isDay ? [weekStart] : Array.from({ length: 7 }, (_, i) => addDays(weekStart, i));
const wrap = document.createElement("div");
wrap.className = "ios-week-wrap";
const head = document.createElement("div");
head.className = "ios-week-head" + (isDay ? " ios-week-head--day" : "");
const corner = document.createElement("div");
corner.className = "ios-week-corner";
head.appendChild(corner);
const today = new Date();
days.forEach((d) => {
const th = document.createElement("div");
th.className = "ios-week-head-day";
if (sameLocalDay(d, today)) th.classList.add("ios-week-head-day--today");
const num = document.createElement("span");
num.className = "ios-week-head-num";
num.textContent = String(d.getDate());
const wd = d.toLocaleDateString("fr-FR", { weekday: "short" }).replace(/\.$/, "");
th.appendChild(num);
th.appendChild(document.createTextNode(` ${wd}.`));
head.appendChild(th);
});
wrap.appendChild(head);
const scroll = document.createElement("div");
scroll.className = "ios-week-scroll";
const track = document.createElement("div");
track.className = "ios-week-track";
const gutter = document.createElement("div");
gutter.className = "ios-agenda-gutter";
gutter.appendChild(renderTimeGutter());
track.appendChild(gutter);
const colsWrap = document.createElement("div");
colsWrap.className = "ios-agenda-cols-wrap";
const cols = document.createElement("div");
cols.className = `ios-agenda-cols${isDay ? " ios-agenda-cols--day" : ""}`;
days.forEach((d0) => {
const dm = new Date(d0.getFullYear(), d0.getMonth(), d0.getDate());
cols.appendChild(buildDayColumn(dm));
});
colsWrap.appendChild(cols);
const todayCol = days.findIndex((d) => sameLocalDay(d, new Date()));
if (todayCol >= 0) {
const dm = new Date(days[todayCol].getFullYear(), days[todayCol].getMonth(), days[todayCol].getDate());
const nowTop = nowLineTopPx(dm);
if (nowTop !== null) {
const ov = document.createElement("div");
ov.className = "ios-now-overlay";
const line = document.createElement("div");
line.className = "ios-now-line-span";
line.style.top = `${nowTop}px`;
const lbl = document.createElement("div");
lbl.className = "ios-now-lbl-span";
lbl.textContent = new Date().toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" });
lbl.style.top = `${Math.max(2, nowTop - 10)}px`;
ov.appendChild(line);
ov.appendChild(lbl);
colsWrap.appendChild(ov);
}
}
track.appendChild(colsWrap);
scroll.appendChild(track);
wrap.appendChild(scroll);
iosAgendaMount.innerHTML = "";
iosAgendaMount.appendChild(wrap);
}
function renderMonthInAgenda() {
if (!iosAgendaMount) return;
const y = iosCursor.getFullYear();
const m = iosCursor.getMonth();
const first = new Date(y, m, 1);
const last = new Date(y, m + 1, 0);
let startWeekday = first.getDay() - 1;
if (startWeekday < 0) startWeekday = 6;
const wrap = document.createElement("div");
wrap.className = "ios-month-agenda";
const wk = document.createElement("div");
wk.className = "ios-month-agenda-weekdays";
["Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"].forEach((t) => {
const s = document.createElement("span");
s.textContent = t;
wk.appendChild(s);
});
wrap.appendChild(wk);
const grid = document.createElement("div");
grid.className = "ios-month-agenda-grid";
for (let i = 0; i < startWeekday; i++) {
const c = document.createElement("div");
c.className = "ios-month-cell ios-month-cell--pad";
grid.appendChild(c);
}
const today = new Date();
for (let d = 1; d <= last.getDate(); d++) {
const cell = document.createElement("button");
cell.type = "button";
cell.className = "ios-month-cell";
const list = eventsForLocalDay(y, m, d);
if (list.length) cell.classList.add("ios-month-cell--has");
if (y === today.getFullYear() && m === today.getMonth() && d === today.getDate()) {
cell.classList.add("ios-month-cell--today");
}
cell.innerHTML = `<span class="ios-month-num">${d}</span>`;
if (list.length) {
const dots = document.createElement("div");
dots.className = "ios-month-dots";
list.slice(0, 4).forEach(() => {
const dot = document.createElement("span");
dot.className = "ios-month-dot";
dots.appendChild(dot);
});
cell.appendChild(dots);
}
cell.addEventListener("click", () => {
iosViewMode = "day";
iosCursor = new Date(y, m, d);
setActiveSegments();
updateToolbarTitle();
renderAgenda();
});
grid.appendChild(cell);
}
wrap.appendChild(grid);
iosAgendaMount.innerHTML = "";
iosAgendaMount.appendChild(wrap);
}
function renderAgenda() {
updateToolbarTitle();
setActiveSegments();
if (iosViewMode === "month") {
renderMonthInAgenda();
} else {
renderWeekOrDay();
}
}
function startNowTimer() {
if (iosNowTimer) clearInterval(iosNowTimer);
iosNowTimer = setInterval(() => {
if (iosViewMode === "week" || iosViewMode === "day") renderAgenda();
}, 60000);
}
function showListSection(show) {
iosListVisible = !!show;
const sec = document.getElementById("ios-list-section");
if (!sec) return;
sec.style.display = show ? "block" : "none";
if (show && iosAgendaMount) {
iosAgendaMount.innerHTML =
'<p class="ios-agenda-list-hint">Vue liste ci-dessous. Utilise <strong>Jour</strong>, <strong>Semaine</strong> ou <strong>Mois</strong> pour retrouver l’agenda.</p>';
} else {
renderAgenda();
}
}
async function loadEvents() {
const events = await iosApi("events");
iosEventsCache = events;
if (iosEventsList) {
iosEventsList.innerHTML = "";
if (!events.length) {
iosEventsList.innerHTML = "<div class='ios-agenda-intro'>Aucun événement.</div>";
} else {
events.forEach((evt) => {
const card = document.createElement("div");
card.className = "ios-event-card";
if (evt.display_color && /^#[0-9A-Fa-f]{6}$/i.test(evt.display_color)) {
card.style.borderLeft = `4px solid ${evt.display_color}`;
}
card.innerHTML = `
<div class="ios-event-card-head">
<div>
<div class="ios-event-card-title">${escHtml(evt.title || "(Sans titre)")}</div>
<div class="ios-event-card-meta">${escHtml(formatDate(evt.start_at))} → ${escHtml(formatDate(evt.end_at))}</div>
<div class="ios-event-card-meta">${escHtml(evt.location || "")}</div>
</div>
<div class="ios-event-card-actions">
<button type="button" class="ios-agenda-btn" data-edit="${evt.id}">Modifier</button>
<button type="button" class="ios-agenda-btn" data-delete="${evt.id}">Supprimer</button>
</div>
</div>
`;
card.querySelector("[data-edit]").addEventListener("click", () => fillForm(evt));
card.querySelector("[data-delete]").addEventListener("click", async () => {
if (!confirm("Supprimer cet événement ?")) return;
await iosApi("events", { method: "DELETE", body: { id: evt.id } });
await loadEvents();
});
iosEventsList.appendChild(card);
});
}
}
if (!iosListVisible) {
renderAgenda();
}
}
async function loadSyncStatus() {
if (!iosSyncStatus) return;
const status = await iosApi("sync_status");
iosSyncStatus.textContent = status.message;
}
async function loadCalendarPrefs() {
const wrap = document.getElementById("ios-calendar-prefs-rows");
const msg = document.getElementById("ios-calendar-prefs-msg");
if (!wrap) return;
if (msg) msg.textContent = "";
wrap.innerHTML = "<span class=\"ios-agenda-intro\">Chargement des calendriers…</span>";
try {
const data = await iosApi("calendar_sources");
const rows = data.calendars || [];
wrap.innerHTML = "";
if (!rows.length) {
wrap.innerHTML =
"<span class=\"ios-agenda-intro\">Aucun calendrier détecté. Configure iCloud dans Paramètres puis synchronise.</span>";
return;
}
rows.forEach((row, idx) => {
const id = `ios-cal-cb-${idx}`;
const rowEl = document.createElement("div");
rowEl.className = "ios-cal-pref-row";
rowEl.dataset.urlKey = row.url_key;
const cb = document.createElement("input");
cb.type = "checkbox";
cb.id = id;
cb.checked = row.visible !== false;
const lab = document.createElement("label");
lab.className = "ios-cal-pref-label";
lab.htmlFor = id;
lab.textContent = row.display || row.url_key;
const colInp = document.createElement("input");
colInp.type = "color";
colInp.className = "ios-cal-pref-color";
colInp.value = row.color || suggestedColorForKey(row.url_key);
colInp.title = "Couleur dans l’agenda";
const autoBtn = document.createElement("button");
autoBtn.type = "button";
autoBtn.className = "ios-cal-pref-reset";
autoBtn.textContent = "Palette auto";
autoBtn.title = "Couleurs HouseHub par défaut (sans teinte iOS)";
autoBtn.addEventListener("click", () => {
rowEl.dataset.paletteAuto = "1";
colInp.disabled = true;
colInp.style.opacity = "0.35";
});
rowEl.appendChild(cb);
rowEl.appendChild(lab);
rowEl.appendChild(colInp);
rowEl.appendChild(autoBtn);
wrap.appendChild(rowEl);
});
} catch (e) {
wrap.innerHTML = `<span class="ios-agenda-intro">${escHtml(e.message)}</span>`;
}
}
async function saveCalendarPrefs() {
const msg = document.getElementById("ios-calendar-prefs-msg");
const wrap = document.getElementById("ios-calendar-prefs-rows");
if (!wrap) return;
const prefs = {};
wrap.querySelectorAll(".ios-cal-pref-row").forEach((rowEl) => {
const key = rowEl.dataset.urlKey;
if (!key) return;
const vis = rowEl.querySelector('input[type="checkbox"]')?.checked === true;
const colInp = rowEl.querySelector(".ios-cal-pref-color");
let color = null;
if (!rowEl.dataset.paletteAuto && colInp && !colInp.disabled) {
const v = colInp.value;
if (v && /^#[0-9A-Fa-f]{6}$/i.test(v)) {
color = v.startsWith("#") ? v.toLowerCase() : `#${v}`.toLowerCase();
}
}
prefs[key] = { visible: vis, color };
});
try {
await iosApi("calendar_prefs", { method: "POST", body: { prefs } });
if (msg) msg.textContent = "Préférences enregistrées.";
await loadEvents();
await loadCalendarPrefs();
} catch (e) {
if (msg) msg.textContent = e.message;
}
}
iosForm.addEventListener("submit", async (e) => {
e.preventDefault();
const idStr = document.getElementById("ios-event-id").value.trim();
const payload = {
title: document.getElementById("ios-title").value.trim(),
location: document.getElementById("ios-location").value.trim(),
description: document.getElementById("ios-description").value.trim(),
start_at: localDatetimeToSql(document.getElementById("ios-start").value),
end_at: localDatetimeToSql(document.getElementById("ios-end").value),
};
if (idStr) {
payload.id = parseInt(idStr, 10);
await iosApi("events", { method: "PUT", body: payload });
} else {
await iosApi("events", { method: "POST", body: payload });
}
resetForm();
await loadEvents();
});
document.getElementById("ios-form-reset")?.addEventListener("click", resetForm);
document.getElementById("ios-sync-btn")?.addEventListener("click", async () => {
const btn = document.getElementById("ios-sync-btn");
btn.disabled = true;
try {
const data = await iosApi("sync", { method: "POST", body: {} });
if (iosSyncStatus) iosSyncStatus.textContent = data.message;
await loadEvents();
await loadCalendarPrefs();
} finally {
btn.disabled = false;
}
});
document.querySelectorAll(".ios-seg").forEach((btn) => {
btn.addEventListener("click", () => {
iosViewMode = /** @type {'day'|'week'|'month'} */ (btn.getAttribute("data-ios-view"));
showListSection(false);
startNowTimer();
});
});
document.getElementById("ios-view-list")?.addEventListener("click", () => {
showListSection(true);
if (iosNowTimer) clearInterval(iosNowTimer);
});
document.getElementById("ios-agenda-prev")?.addEventListener("click", () => {
if (iosViewMode === "day") iosCursor = addDays(iosCursor, -1);
else if (iosViewMode === "week") iosCursor = addDays(iosCursor, -7);
else iosCursor = addMonths(iosCursor, -1);
renderAgenda();
});
document.getElementById("ios-agenda-next")?.addEventListener("click", () => {
if (iosViewMode === "day") iosCursor = addDays(iosCursor, 1);
else if (iosViewMode === "week") iosCursor = addDays(iosCursor, 7);
else iosCursor = addMonths(iosCursor, 1);
renderAgenda();
});
document.getElementById("ios-agenda-today")?.addEventListener("click", () => {
iosCursor = new Date();
showListSection(false);
startNowTimer();
});
document.getElementById("ios-agenda-add")?.addEventListener("click", () => {
resetForm();
const now = new Date();
now.setMinutes(Math.ceil(now.getMinutes() / 15) * 15, 0, 0);
const end = new Date(now.getTime() + 3600000);
const f = (d) => {
const p = (n) => String(n).padStart(2, "0");
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}T${p(d.getHours())}:${p(d.getMinutes())}`;
};
document.getElementById("ios-start").value = f(now);
document.getElementById("ios-end").value = f(end);
document.getElementById("ios-edit-panel")?.scrollIntoView({ behavior: "smooth", block: "start" });
document.getElementById("ios-title")?.focus();
});
document.getElementById("ios-calendar-prefs-save")?.addEventListener("click", () => saveCalendarPrefs());
window.addEventListener("DOMContentLoaded", async () => {
try {
iosCursor = new Date();
await loadEvents();
await loadCalendarPrefs();
await loadSyncStatus();
showListSection(false);
startNowTimer();
} catch (e) {
if (iosSyncStatus) iosSyncStatus.textContent = e.message;
if (iosAgendaMount) iosAgendaMount.innerHTML = `<p class="ios-agenda-intro">${escHtml(e.message)}</p>`;
}
});
+303
View File
@@ -0,0 +1,303 @@
<?php
require_once dirname(__DIR__, 2) . '/includes/crypto.php';
require_once dirname(__DIR__, 2) . '/includes/icloud_caldav.php';
/**
* Mot de passe normalisé + URL calendrier (découverte si racine iCloud).
*
* @return array{integration: array, password: string}
*/
function ios_caldav_prepare(array $integration, ?PDO $metaPdo = null): array
{
$password = hh_normalize_apple_app_password(hh_decrypt_secret($integration['secret_encrypted']));
$url = trim($integration['calendar_url'] ?? '');
$resolvedUrl = hh_icloud_resolve_calendar_url_if_needed($integration['username'], $password, $url);
$out = $integration;
$out['calendar_url'] = $resolvedUrl;
if ($metaPdo && !empty($integration['id']) && rtrim($url, '/') !== rtrim($resolvedUrl, '/')) {
$metaPdo->prepare('UPDATE user_calendar_integrations SET calendar_url = ? WHERE id = ?')
->execute([$resolvedUrl, $integration['id']]);
}
return ['integration' => $out, 'password' => $password];
}
function ios_make_ics(array $event): string
{
$uid = $event['external_uid'] ?: ('hh-' . $event['id'] . '@househub');
$start = gmdate('Ymd\THis\Z', strtotime($event['start_at']));
$end = gmdate('Ymd\THis\Z', strtotime($event['end_at']));
$summary = addcslashes($event['title'] ?? '', ",;");
$description = addcslashes($event['description'] ?? '', ",;");
$location = addcslashes($event['location'] ?? '', ",;");
$updated = gmdate('Ymd\THis\Z');
return "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//HouseHub//Calendar iOS//FR\r\nBEGIN:VEVENT\r\nUID:$uid\r\nDTSTAMP:$updated\r\nDTSTART:$start\r\nDTEND:$end\r\nSUMMARY:$summary\r\nDESCRIPTION:$description\r\nLOCATION:$location\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
}
function ios_caldav_request(string $url, string $username, string $password, string $method = 'GET', ?string $body = null, array $headers = []): array
{
$ch = curl_init($url);
$defaultCt = ($method === 'REPORT' || $method === 'PROPFIND')
? 'application/xml; charset=utf-8'
: 'text/calendar; charset=utf-8';
$requestHeaders = array_merge([
'Content-Type: ' . $defaultCt,
], $headers);
$timeout = ($method === 'REPORT' || $method === 'PROPFIND') ? 60 : 20;
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => $username . ':' . $password,
CURLOPT_HTTPHEADER => $requestHeaders,
CURLOPT_HEADER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 10,
]);
if ($body !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
$raw = curl_exec($ch);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($raw === false) {
return ['code' => 0, 'headers' => '', 'body' => ''];
}
return [
'code' => $code,
'headers' => substr($raw, 0, $headerSize),
'body' => substr($raw, $headerSize),
];
}
/**
* Déplie les lignes ICS pliées (RFC 5545).
*/
function ios_ics_unfold(string $ics): string
{
$ics = str_replace("\r\n", "\n", $ics);
return preg_replace("/\n[ \t]/", '', $ics);
}
/**
* @return list<array{external_uid:string,title:string,description:string,location:string,start_at:string,end_at:string}>
*/
function ios_parse_vevents_from_ics(string $ics): array
{
$ics = ios_ics_unfold($ics);
$events = [];
if (!preg_match_all('/BEGIN:VEVENT\s*(.*?)\s*END:VEVENT/s', $ics, $matches)) {
return [];
}
foreach ($matches[1] as $chunk) {
if (!preg_match('/^UID:([^\r\n]+)/m', $chunk, $uidM)) {
continue;
}
$uid = trim($uidM[1]);
$summary = '';
if (preg_match('/^SUMMARY:([^\r\n]*)/m', $chunk, $m)) {
$summary = str_replace('\\,', ',', str_replace('\\;', ';', trim($m[1])));
}
$description = '';
if (preg_match('/^DESCRIPTION:([^\r\n]*)/m', $chunk, $m)) {
$description = str_replace('\\,', ',', str_replace('\\;', ';', str_replace('\\n', "\n", trim($m[1]))));
}
$location = '';
if (preg_match('/^LOCATION:([^\r\n]*)/m', $chunk, $m)) {
$location = str_replace('\\,', ',', str_replace('\\;', ';', trim($m[1])));
}
$startRaw = null;
if (preg_match('/^DTSTART[^:]*:([^\r\n]+)/m', $chunk, $m)) {
$startRaw = trim($m[1]);
}
if ($startRaw === null || $startRaw === '') {
continue;
}
$endRaw = null;
if (preg_match('/^DTEND[^:]*:([^\r\n]+)/m', $chunk, $m)) {
$endRaw = trim($m[1]);
}
if (preg_match('/^\d{8}$/', $startRaw)) {
$startTs = strtotime($startRaw . 'T000000 UTC');
} else {
$norm = preg_replace('/^(\d{8})T(\d{6})Z?$/', '$1T$2 UTC', $startRaw);
$startTs = strtotime($norm ?: $startRaw);
if ($startTs === false) {
$startTs = strtotime($startRaw);
}
}
if ($startTs === false) {
continue;
}
if ($endRaw !== null && $endRaw !== '') {
if (preg_match('/^\d{8}$/', $endRaw)) {
$endTs = strtotime($endRaw . 'T000000 UTC');
} else {
$normE = preg_replace('/^(\d{8})T(\d{6})Z?$/', '$1T$2 UTC', $endRaw);
$endTs = strtotime($normE ?: $endRaw);
if ($endTs === false) {
$endTs = strtotime($endRaw);
}
}
} else {
$endTs = $startTs;
}
if ($endTs === false) {
$endTs = $startTs;
}
$events[] = [
'external_uid' => $uid,
'title' => $summary,
'description' => $description,
'location' => $location,
'start_at' => date('Y-m-d H:i:s', $startTs),
'end_at' => date('Y-m-d H:i:s', $endTs),
];
}
return $events;
}
/**
* Associe chaque fragment iCalendar du REPORT à l’URL de ressource CalDAV (nécessaire pour PUT/DELETE sur iCloud).
*
* @return list<array{resource_url:string,ical:string}>
*/
function ios_caldav_parse_report_calendar_fragments(string $xmlBody, string $calendarBaseUrl): array
{
$dom = new DOMDocument();
if (!@$dom->loadXML($xmlBody)) {
return [];
}
$xpath = new DOMXPath($dom);
$responses = $xpath->query("//*[local-name()='response']");
$out = [];
foreach ($responses as $resp) {
$hrefNodes = $xpath->query(".//*[local-name()='href']", $resp);
if ($hrefNodes->length === 0) {
continue;
}
$href = trim($hrefNodes->item(0)->textContent);
if ($href === '') {
continue;
}
$cd = $xpath->query(".//*[local-name()='calendar-data']", $resp);
if ($cd->length === 0) {
continue;
}
$ical = trim($cd->item(0)->textContent);
if ($ical === '' || stripos($ical, 'BEGIN:VEVENT') === false) {
continue;
}
$resourceUrl = (str_starts_with($href, 'http://') || str_starts_with($href, 'https://'))
? $href
: hh_caldav_resolve_href(rtrim($calendarBaseUrl, '/') . '/', $href);
$out[] = ['resource_url' => $resourceUrl, 'ical' => $ical];
}
return $out;
}
/**
* URLs des collections calendrier à interroger (tous les calendriers iCloud du compte, sinon l’URL configurée seule).
*
* @return list<string>
*/
function ios_sync_calendar_collection_urls(array $integration, string $password): array
{
$primary = rtrim($integration['calendar_url'] ?? '', '/') . '/';
if (hh_caldav_url_is_icloud($primary)) {
try {
$entries = hh_icloud_discover_calendar_entries($integration['username'], $password);
return array_values(array_unique(array_map(static function (array $e): string {
return rtrim($e['url'], '/') . '/';
}, $entries)));
} catch (Throwable $e) {
// compte partiellement lisible : au moins le calendrier principal
}
}
return [$primary];
}
/**
* @return list<array<string,mixed>> champs événement + _resource_url + _calendar_collection_url
*/
function ios_fetch_remote_events(array $integration, string $password): array
{
$calUrl = rtrim($integration['calendar_url'], '/') . '/';
$tStart = gmdate('Ymd\THis\Z', strtotime('-3 years'));
$tEnd = gmdate('Ymd\THis\Z', strtotime('+4 years'));
$reportXml = '<?xml version="1.0" encoding="UTF-8"?>'
. '<C:calendar-query xmlns:C="urn:ietf:params:xml:ns:caldav" xmlns:D="DAV:">'
. '<D:prop><C:calendar-data/></D:prop>'
. '<C:filter>'
. '<C:comp-filter name="VCALENDAR">'
. '<C:comp-filter name="VEVENT">'
. '<C:time-range start="' . htmlspecialchars($tStart, ENT_XML1 | ENT_QUOTES, 'UTF-8') . '" end="' . htmlspecialchars($tEnd, ENT_XML1 | ENT_QUOTES, 'UTF-8') . '"/>'
. '</C:comp-filter></C:comp-filter></C:filter>'
. '</C:calendar-query>';
$res = ios_caldav_request($calUrl, $integration['username'], $password, 'REPORT', $reportXml, [
'Accept: application/xml, text/xml',
'Depth: 1',
]);
if (!in_array($res['code'], [200, 207], true)) {
throw new RuntimeException('Lecture CalDAV (REPORT) impossible (HTTP ' . $res['code'] . ').');
}
$fragments = ios_caldav_parse_report_calendar_fragments($res['body'], $calUrl);
$byUid = [];
foreach ($fragments as $frag) {
foreach (ios_parse_vevents_from_ics($frag['ical']) as $ev) {
$ev['_resource_url'] = $frag['resource_url'];
$ev['_calendar_collection_url'] = $calUrl;
$byUid[$ev['external_uid']] = $ev;
}
}
if ($byUid === [] && strpos($res['body'], 'multistatus') === false) {
$get = ios_caldav_request($calUrl, $integration['username'], $password, 'GET', null, ['Accept: text/calendar']);
if ($get['code'] >= 200 && $get['code'] < 400 && str_contains($get['body'], 'BEGIN:VEVENT')) {
foreach (ios_parse_vevents_from_ics($get['body']) as $ev) {
$ev['_resource_url'] = null;
$ev['_calendar_collection_url'] = $calUrl;
$byUid[$ev['external_uid']] = $ev;
}
}
}
return array_values($byUid);
}
/**
* Fusionne tous les calendriers du compte (iCloud) ou une seule collection.
*
* @return list<array<string,mixed>>
*/
function ios_fetch_remote_events_all_calendars(array $integration, string $password): array
{
$urls = ios_sync_calendar_collection_urls($integration, $password);
$merged = [];
foreach ($urls as $url) {
$sub = $integration;
$sub['calendar_url'] = $url;
foreach (ios_fetch_remote_events($sub, $password) as $ev) {
$merged[$ev['external_uid']] = $ev;
}
}
return array_values($merged);
}
function ios_push_event_to_remote(array $integration, array $event, string $password, ?string $resourceUrl = null, ?string $collectionUrlOverride = null): array
{
$uid = $event['external_uid'] ?: ('hh-' . $event['id'] . '@househub');
$collection = rtrim($collectionUrlOverride ?? $integration['calendar_url'], '/');
$url = $resourceUrl ?: ($collection . '/' . rawurlencode($uid) . '.ics');
$ics = ios_make_ics($event);
return ios_caldav_request($url, $integration['username'], $password, 'PUT', $ics);
}
function ios_delete_remote_event(array $integration, string $externalUid, string $password, ?string $resourceUrl = null, ?string $collectionUrlOverride = null): array
{
$collection = rtrim($collectionUrlOverride ?? $integration['calendar_url'], '/');
$url = $resourceUrl ?: ($collection . '/' . rawurlencode($externalUid) . '.ics');
return ios_caldav_request($url, $integration['username'], $password, 'DELETE', null, ['Accept: */*']);
}
@@ -0,0 +1,157 @@
<?php
// /modules/family-calendar/admin/generate-calendar-year.php
require __DIR__ . '/../../../includes/db.php';
// S'assurer que PDO lève des exceptions en cas d'erreur
if (isset($pdo) && $pdo instanceof PDO) {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} else {
die("Erreur : PDO non initialisé dans db.php");
}
$year = isset($_GET['year']) ? (int)$_GET['year'] : (int)date('Y');
if ($year < 2000 || $year > 2100) {
die("Année invalide.");
}
try {
$pdo->beginTransaction();
// On supprime d'abord les semaines de cette année calendaire
$stmtDel = $pdo->prepare("DELETE FROM pf_calendar_weeks WHERE year = :year");
$stmtDel->execute([':year' => $year]);
// 1er janvier de l'année calendaire
$start = new DateTime("$year-01-01");
// On remonte au lundi précédent (ou on reste dessus si déjà lundi)
while ($start->format('N') != 1) { // 1 = lundi
$start->modify('-1 day');
}
// Dernier jour de l'année
$end = new DateTime("$year-12-31");
// Préparation de l'INSERT avec gestion des doublons
// (en supposant une contrainte UNIQUE, par ex. sur (year, week_iso_year, week_iso_number))
$sql = "
INSERT INTO pf_calendar_weeks (
year, week_iso_year, week_iso_number, week_label,
month, month_name,
week_start_date, mon_date, tue_date, wed_date, thu_date, fri_date, sat_date, sun_date
) VALUES (
:year, :week_iso_year, :week_iso_number, :week_label,
:month, :month_name,
:week_start_date, :mon_date, :tue_date, :wed_date, :thu_date, :fri_date, :sat_date, :sun_date
)
ON DUPLICATE KEY UPDATE
week_label = VALUES(week_label),
month = VALUES(month),
month_name = VALUES(month_name),
week_start_date = VALUES(week_start_date),
mon_date = VALUES(mon_date),
tue_date = VALUES(tue_date),
wed_date = VALUES(wed_date),
thu_date = VALUES(thu_date),
fri_date = VALUES(fri_date),
sat_date = VALUES(sat_date),
sun_date = VALUES(sun_date)
";
$stmt = $pdo->prepare($sql);
// fonction mois FR
function getMonthNameFr($monthIndexZeroBased) {
$months = [
"Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin",
"Juillet", "Aout", "Septembre", "Octobre", "Novembre", "Decembre",
];
return $months[$monthIndexZeroBased] ?? "";
}
$current = clone $start;
$insertCount = 0;
while ($current <= $end) {
$monday = clone $current;
// Calcul des 7 jours de la semaine
$mon = clone $monday;
$tue = (clone $monday)->modify('+1 day');
$wed = (clone $monday)->modify('+2 days');
$thu = (clone $monday)->modify('+3 days');
$fri = (clone $monday)->modify('+4 days');
$sat = (clone $monday)->modify('+5 days');
$sun = (clone $monday)->modify('+6 days');
// Année / semaine ISO
$weekIsoYear = (int)$monday->format('o'); // année ISO
$weekIsoNumber = (int)$monday->format('W');
$weekLabel = 'W' . str_pad($weekIsoNumber, 2, '0', STR_PAD_LEFT);
// Détermination du mois d'affectation de la semaine
// -> on compte combien de jours de la semaine tombent dans chaque mois
$days = [$mon, $tue, $wed, $thu, $fri, $sat, $sun];
// compteur mois => nb de jours (clé = numéro de mois 1..12)
$monthCounts = [];
foreach ($days as $d) {
$m = (int)$d->format('n'); // 1-12
if (!isset($monthCounts[$m])) {
$monthCounts[$m] = 0;
}
$monthCounts[$m]++;
}
// On prend le mois ayant le plus de jours
// (si égalité, le mois ayant la plus petite valeur numérique gagnera,
// ce qui est raisonnable, mais on peut changer si besoin)
$chosenMonth = null;
$maxDays = -1;
foreach ($monthCounts as $m => $count) {
if ($count > $maxDays) {
$maxDays = $count;
$chosenMonth = $m;
}
}
$month = $chosenMonth;
$monthName = getMonthNameFr($month - 1);
$stmt->execute([
':year' => $weekIsoYear, // <-- au lieu de $year
':week_iso_year' => $weekIsoYear,
':week_iso_number' => $weekIsoNumber,
':week_label' => $weekLabel,
':month' => $month,
':month_name' => $monthName,
':week_start_date' => $monday->format('Y-m-d'),
':mon_date' => $mon->format('Y-m-d'),
':tue_date' => $tue->format('Y-m-d'),
':wed_date' => $wed->format('Y-m-d'),
':thu_date' => $thu->format('Y-m-d'),
':fri_date' => $fri->format('Y-m-d'),
':sat_date' => $sat->format('Y-m-d'),
':sun_date' => $sun->format('Y-m-d'),
]);
$insertCount++;
$current->modify('+7 days');
}
$pdo->commit();
echo "Calendrier $year généré. Semaines traitées : " . $insertCount;
} catch (PDOException $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
die("Erreur PDO : " . $e->getMessage());
} catch (Exception $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
die("Erreur générale : " . $e->getMessage());
}
+125
View File
@@ -0,0 +1,125 @@
<?xml version="1.0" ?><svg id="Layer_1" style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><style type="text/css">
.st0{fill:#FFFFFF;}
.st1{fill:#C60C30;}
.st2{fill:#003478;}
.st3{fill:#FF9933;}
.st4{fill:#128807;}
.st5{fill:#000088;}
.st6{fill:#032774;}
.st7{fill:#DF0333;}
.st8{fill:#EE2B2C;}
.st9{fill:#032767;}
.st10{fill:#006747;}
.st11{fill:#CD1225;}
.st12{fill:#FBC942;}
.st13{fill:#BD9B37;}
.st14{fill:#9BA068;}
.st15{fill:#707633;}
.st16{fill:#006748;}
.st17{fill:#CC2029;}
.st18{fill:#30C1DB;}
.st19{fill:#F7C740;}
.st20{fill:#0C72A6;}
.st21{fill:#F8A952;}
.st22{fill:#943120;}
.st23{fill:#231F20;}
.st24{fill:#0B8388;}
.st25{fill:#8BBDBE;}
.st26{fill:#05534E;}
.st27{fill:none;stroke:#39B54A;stroke-width:0.25;stroke-miterlimit:10;}
.st28{fill:none;stroke:#00A651;stroke-miterlimit:10;}
.st29{fill:none;stroke:#00A651;stroke-width:0.5;stroke-miterlimit:10;}
.st30{fill:url(#SVGID_1_);}
.st31{fill:url(#SVGID_2_);}
.st32{fill:url(#SVGID_3_);}
.st33{fill:url(#SVGID_4_);}
.st34{fill:url(#SVGID_5_);}
.st35{fill:url(#SVGID_6_);}
.st36{fill:url(#SVGID_7_);}
.st37{fill:url(#SVGID_8_);}
.st38{fill:url(#SVGID_9_);}
.st39{fill:url(#SVGID_10_);}
.st40{fill:url(#SVGID_11_);}
.st41{fill:url(#SVGID_12_);}
.st42{fill:url(#SVGID_13_);}
.st43{fill:url(#SVGID_14_);}
.st44{fill:url(#SVGID_15_);}
.st45{fill:#F8C73E;}
.st46{fill:#77722F;}
.st47{fill:#A7AB71;}
.st48{fill:#949457;}
.st49{fill:#AE6F2A;}
.st50{fill:#FFF200;}
.st51{fill:#C5C6A6;}
.st52{fill:#A3A395;}
.st53{fill:#4C2915;}
.st54{fill:#8E4520;}
.st55{fill:#D1A467;}
.st56{fill:#AA6C2A;}
.st57{fill:#DAAC6D;}
.st58{fill:#8F4620;}
.st59{fill:#BC7E2F;}
.st60{fill:#E6E7E8;}
.st61{fill:#F06D19;}
.st62{fill:#19B43D;}
.st63{fill:#07A3DC;}
.st64{fill:#FBD023;}
.st65{fill:#EC2938;}
.st66{fill:#F9DF47;}
.st67{fill:#0967C4;}
.st68{fill:#C5A310;}
.st69{clip-path:url(#SVGID_17_);}
.st70{fill:#6FD7F2;}
.st71{clip-path:url(#SVGID_19_);}
.st72{fill:#FF0303;}
.st73{fill:#FF6407;}
.st74{fill:#FDFE1F;}
.st75{fill:#00FE1E;}
.st76{fill:#08CCFE;}
.st77{fill:#120FFD;}
.st78{fill:#810480;}
.st79{fill:#0642A1;}
.st80{fill:#02275F;}
.st81{fill:#80A0D1;}
.st82{fill:#FB3B3A;}
.st83{fill:#FF0302;}
.st84{fill:#520200;}
.st85{fill:#940101;}
.st86{clip-path:url(#SVGID_21_);}
.st87{fill:#91BB35;}
.st88{fill:#ECE62B;}
.st89{fill:#C5CA2C;}
.st90{fill:#95C82B;}
.st91{fill:#009D4A;}
.st92{fill:#BF0A30;}
.st93{fill:#002868;}
.st94{fill:#028832;}
.st95{fill:#FBDC1D;}
.st96{fill:#D91219;}
.st97{fill:#0738A6;}
.st98{fill:#FD0302;}
.st99{fill:#060593;}
.st100{fill:#115EAD;}
.st101{fill:#C50C1E;}
.st102{fill:#FEC315;}
.st103{fill:#C7B011;}
.st104{fill:#AC1518;}
.st105{fill:#028E6E;}
.st106{fill:#CBCBCB;}
.st107{fill:#095BBD;}
.st108{fill:#C7B013;}
.st109{fill:#00AEEF;}
.st110{fill:#C7B112;}
.st111{fill:#FED592;}
.st112{fill:#028D6E;}
.st113{fill:#C7B012;}
.st114{fill:#C6B011;}
.st115{fill:#103BEE;}
.st116{fill:#DB4445;}
.st117{fill:#EC72A9;}
.st118{fill:#006133;}
.st119{fill:#D11133;}
.st120{fill:#042B7D;}
.st121{fill:#FEC527;}
.st122{fill:#BF920D;}
</style><g><path class="st96" d="M510.4,284.4c-0.3,2.6-0.7,5.2-1,7.8c-0.2,1-0.3,2.1-0.5,3.2c-0.5,3.2-1.1,6.4-1.7,9.7 c-0.1,0.5-0.2,1-0.3,1.5v0.1c-0.1,0.5-0.2,1-0.2,1c-2.5,11.9-5.6,22.9-9.4,33.7H14.6c-3.4-9.8-6.3-19.8-8.6-30.1 c-0.2-0.5-0.3-1-0.4-1.5c-0.1-0.5-0.2-1-0.3-1.4c-1.6-7.9-2.9-15.8-3.7-23.9H510.4z"/><path class="st95" d="M497.4,341.3c-5.3,14.9-11.9,29.1-19.7,42.6c-2.8,4.9-5.8,9.6-8.9,14.3H43.1c-3.1-4.7-6-9.4-8.8-14.3 c-7.8-13.4-14.4-27.8-19.7-42.6H497.4z"/><path class="st96" d="M468.8,398.2c-4.1,6.1-8.4,12.1-13,17.8c-11.5,14.4-24.5,27.5-38.8,39.1H95c-14.3-11.6-27.4-24.7-38.8-39.1 c-4.6-5.7-9-11.7-13.1-17.8H468.8z"/><path class="st95" d="M417,455.1C372.9,490.7,317,512,256,512c-61,0-117-21.3-161-56.9H417z"/><path class="st96" d="M468.8,113.8H43.2c4.1-6.1,8.4-12.1,13-17.8c11.6-14.4,24.7-27.6,39-39.1h321.7c14.4,11.6,27.4,24.7,39,39.1 C460.4,101.7,464.8,107.6,468.8,113.8z"/><path class="st95" d="M416.8,56.9H95.1C139.1,21.3,195,0,256,0C316.9,0,372.9,21.3,416.8,56.9z"/><path class="st95" d="M497.4,170.7H14.6c5.2-14.9,11.8-29.2,19.7-42.7c2.8-4.8,5.7-9.6,8.9-14.2h425.7c3.1,4.6,6.1,9.4,8.9,14.2 C485.5,141.5,492.1,155.7,497.4,170.7z"/><path class="st96" d="M510.4,227.6H1.6c0,0,0.1-0.3,0.1-0.5V227l0.1-0.6c2.2-19.3,6.6-37.9,12.9-55.7h482.8 c3.2,8.8,5.7,17.9,7.9,27.1c0.1,0.2,0.1,0.5,0.2,0.7c0,0,0.1,0.5,0.2,0.7c1.3,5.9,2.4,11.8,3.4,17.8c0,0,0,0.4,0.1,0.6 c0,0,0.1,0.4,0.1,0.6C509.6,221.3,510.1,224.4,510.4,227.6z"/><path class="st95" d="M512,256c0,1.3,0,2.5-0.1,3.8c0,0.3,0,0.6,0,0.8v0.9l-0.1,0.3c0,0,0,0.4,0,0.6c-0.2,7.4-0.7,14.8-1.4,22.1 H1.6c-0.2-1.6-0.3-3-0.5-4.5c-0.1-0.9-0.2-1.7-0.2-2.5l0,0c-0.5-4.9-0.7-10-0.9-15.1c0-0.2,0-0.4,0-0.4c0-0.4,0-0.6,0-0.6 C0,260,0,258.8,0,257.5c0,0,0-0.3,0-0.6V256c0-1.7,0-3.5,0.1-5.2c0-0.2,0-0.3,0-0.3c0-0.4,0-0.6,0-0.6c0.1-5.3,0.4-10.5,0.9-15.6 c0-0.2,0.1-0.5,0.1-0.5c0-0.5,0.1-0.7,0.1-0.9c0.2-1.7,0.3-3.4,0.5-5.1v-0.2h508.8c0.8,7.2,1.3,14.6,1.5,22.1c0,0,0.1,0.4,0,0.6 c0,0,0.1,0.4,0.1,0.6C511.9,252.5,512,254.3,512,256z"/></g></svg>

After

Width:  |  Height:  |  Size: 5.1 KiB

File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,208 @@
<?php
require __DIR__ . '/../../../../includes/auth.php';
require __DIR__ . '/../../../../includes/db.php';
require_login();
header('Content-Type: application/json');
$action = $_REQUEST['action'] ?? '';
try {
// ─── 1. RECUPÉRATION COMPLÈTE DES PARAMÈTRES (INITIALISATION) ───
if ($action === 'get_all') {
$stmtFoyer = $pdo->query("SELECT zone_scolaire, care_modes FROM pf_foyer_settings LIMIT 1");
$foyer = $stmtFoyer->fetch(PDO::FETCH_ASSOC) ?: ['zone_scolaire' => 'C', 'care_modes' => '[]'];
$stmtPeople = $pdo->query("SELECT id, name, role, care_modes, color FROM pf_people WHERE is_active = 1 ORDER BY role ASC, name ASC");
$people = $stmtPeople->fetchAll(PDO::FETCH_ASSOC);
$stmtLeaves = $pdo->query("SELECT person_id, leave_type, anniversary_date, method, allowance, carry_over_max_days, carry_over_deadline_month FROM pf_person_leave_meta");
$leavesRaw = $stmtLeaves->fetchAll(PDO::FETCH_ASSOC);
$leavesMap = [];
foreach ($leavesRaw as $leave) {
$leavesMap[$leave['person_id']][] = [
'type' => $leave['leave_type'],
'method' => $leave['method'] ?? 'FIXED',
'allowance' => $leave['allowance'] ?? 0,
'date' => $leave['anniversary_date'],
'carry_over_max_days' => $leave['carry_over_max_days'] ?? 0,
'carry_over_deadline_month' => $leave['carry_over_deadline_month'] ?? 12
];
}
$stmtSettings = $pdo->query("SELECT setting_key, setting_value FROM pf_settings WHERE module = 'calendar'");
$calendarSettingsRaw = $stmtSettings->fetchAll(PDO::FETCH_KEY_PAIR);
$calendarSettings = [
'calendar_default_view' => $calendarSettingsRaw['calendar_default_view'] ?? 'month',
'calendar_first_day' => $calendarSettingsRaw['calendar_first_day'] ?? '1',
'calendar_working_hours' => $calendarSettingsRaw['calendar_working_hours'] ?? '08:00-19:00'
];
// Catalogue des congés (Nettoyé des règles de report qui sont maintenant sur la personne)
$stmtLeaveTypes = $pdo->query("SELECT code, label, default_allowance, reset_month FROM pf_leave_types ORDER BY label ASC");
$leaveTypes = $stmtLeaveTypes->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'data' => [
'foyer' => [
'zone_scolaire' => $foyer['zone_scolaire'],
'care_modes' => json_decode($foyer['care_modes'] ?? '[]', true)
],
'people' => $people,
'leaves' => $leavesMap,
'calendar_settings' => $calendarSettings,
'leave_types' => $leaveTypes
]
]);
exit;
}
// ─── 2. SAUVEGARDE DU FOYER (ONGLET 1) ───
if ($action === 'save_foyer') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception("Méthode non autorisée");
$zone = trim($_POST['zone_scolaire'] ?? 'C');
$modesRaw = $_POST['care_modes'] ?? '[]';
$modesArray = json_encode(array_values(array_unique(array_filter(json_decode($modesRaw, true)))));
$stmt = $pdo->prepare("UPDATE pf_foyer_settings SET zone_scolaire = ?, care_modes = ? WHERE id = 1");
$stmt->execute([$zone, $modesArray]);
echo json_encode(['success' => true]);
exit;
}
// ─── 3. SAUVEGARDE DES MODES DE GARDE D'UN ENFANT ───
if ($action === 'save_child_care_modes') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception("Méthode non autorisée");
$person_id = (int)($_POST['person_id'] ?? 0);
$care_modes = $_POST['care_modes'] ?? '[]';
if ($person_id > 0) {
$stmt = $pdo->prepare("UPDATE pf_people SET care_modes = ? WHERE id = ?");
$stmt->execute([$care_modes, $person_id]);
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'error' => 'ID de l\'enfant manquant.']);
}
exit;
}
// ─── 4. GESTION DU CATALOGUE DE CONGÉS (FOYER) ───
if ($action === 'get_leave_types') {
$stmt = $pdo->query("SELECT * FROM pf_leave_types ORDER BY label ASC");
echo json_encode(['success' => true, 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
exit;
}
if ($action === 'save_leave_type') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception(tr('error_occured'));
$mode = $_POST['mode'] ?? 'add';
$code = strtoupper(trim($_POST['code'] ?? ''));
$label = trim($_POST['label'] ?? '');
$carryMax = (float)($_POST['carry_over_max_days'] ?? 0);
$carryDeadline = (int)($_POST['carry_over_deadline_month'] ?? 12);
if (empty($code) || empty($label)) throw new Exception(tr('fc_err_code_label'));
if ($mode === 'add') {
$stmt = $pdo->prepare("INSERT INTO pf_leave_types (code, label, carry_over_max_days, carry_over_deadline_month) VALUES (?, ?, ?, ?)");
$stmt->execute([$code, $label, $carryMax, $carryDeadline]);
} else {
$stmt = $pdo->prepare("UPDATE pf_leave_types SET label = ?, carry_over_max_days = ?, carry_over_deadline_month = ? WHERE code = ?");
$stmt->execute([$label, $carryMax, $carryDeadline, $code]);
}
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_leave_type') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception("Méthode non autorisée");
$code = strtoupper(trim($_POST['code'] ?? ''));
if (empty($code)) throw new Exception("Code du congé manquant.");
$pdo->beginTransaction();
// 1. On supprime d'abord ce congé chez tous les membres à qui on l'avait attribué
$stmtMeta = $pdo->prepare("DELETE FROM pf_person_leave_meta WHERE leave_type = ?");
$stmtMeta->execute([$code]);
// 2. Ensuite, on supprime le congé du catalogue global
$stmtCat = $pdo->prepare("DELETE FROM pf_leave_types WHERE code = ?");
$stmtCat->execute([$code]);
$pdo->commit();
echo json_encode(['success' => true]);
exit;
}
// ─── 5. GESTION DES CONGÉS INDIVIDUELS (MEMBRES) ───
if ($action === 'get_person_leaves') {
$personId = (int)($_GET['person_id'] ?? 0);
$stmt = $pdo->prepare("SELECT id, leave_type, allowance, method, anniversary_date, carry_over_max_days, carry_over_deadline_month FROM pf_person_leave_meta WHERE person_id = ? ORDER BY leave_type ASC");
$stmt->execute([$personId]);
echo json_encode(['success' => true, 'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)]);
exit;
}
if ($action === 'add_person_leave') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception("Méthode non autorisée");
$id = (int)($_POST['meta_id'] ?? 0); // Nouvel ID pour différencier l'Update de l'Insert
$personId = (int)($_POST['person_id'] ?? 0);
$type = strtoupper(trim($_POST['leave_type'] ?? ''));
$allowance = (float)($_POST['allowance'] ?? 0);
$resetMonth = (int)($_POST['reset_month'] ?? 1);
$carryMax = (float)($_POST['carry_over_max_days'] ?? 0);
$carryDeadline = (int)($_POST['carry_over_deadline_month'] ?? 12);
$method = in_array($_POST['method'] ?? '', ['FIXED', 'ACCUMULATED']) ? $_POST['method'] : 'FIXED';
if ($personId <= 0 || empty($type)) throw new Exception("Données invalides.");
// On construit la date anniversaire avec le mois choisi par l'utilisateur
$anniversaryDate = "2000-" . str_pad((string)$resetMonth, 2, "0", STR_PAD_LEFT) . "-01";
if ($id > 0) {
// ✏️ UPDATE (Modification)
$stmt = $pdo->prepare("UPDATE pf_person_leave_meta SET allowance = ?, method = ?, anniversary_date = ?, carry_over_max_days = ?, carry_over_deadline_month = ? WHERE id = ? AND person_id = ?");
$stmt->execute([$allowance, $method, $anniversaryDate, $carryMax, $carryDeadline, $id, $personId]);
} else {
// ➕ INSERT (Ajout)
// Vérification des doublons
$check = $pdo->prepare("SELECT id FROM pf_person_leave_meta WHERE person_id = ? AND leave_type = ?");
$check->execute([$personId, $type]);
if ($check->rowCount() > 0) throw new Exception("Ce congé est déjà attribué à cette personne.");
$stmt = $pdo->prepare("INSERT INTO pf_person_leave_meta (person_id, leave_type, allowance, method, anniversary_date, carry_over_max_days, carry_over_deadline_month) VALUES (?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$personId, $type, $allowance, $method, $anniversaryDate, $carryMax, $carryDeadline]);
}
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_person_leave') {
if ($_SERVER['REQUEST_METHOD'] !== 'POST') throw new Exception("Méthode non autorisée");
$id = (int)($_POST['id'] ?? 0);
$stmt = $pdo->prepare("DELETE FROM pf_person_leave_meta WHERE id = ?");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
throw new Exception("Action inconnue : " . htmlspecialchars($action));
} catch (\Throwable $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
exit;
}
@@ -0,0 +1,61 @@
[2026-01-06T14:39:28+01:00] RAW INPUT: []
[2026-01-06T14:39:28+01:00] RAW INPUT: [{"date":"2025-09-08","type":"PEP_SICK","duration":1}]
[2026-01-06T14:40:04+01:00] RAW INPUT: [{"date":"2025-09-30","type":"OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-06T14:40:04+01:00] RAW INPUT: []
[2026-01-06T14:40:52+01:00] RAW INPUT: [{"date":"2025-09-08","type":"PEP_SICK","duration":1}]
[2026-01-06T14:40:52+01:00] RAW INPUT: []
[2026-01-06T14:46:35+01:00] RAW INPUT: [{"date":"2025-09-22","type":"PEP_SICK","duration":1}]
[2026-01-06T14:47:20+01:00] RAW INPUT: [{"date":"2025-09-29","type":"PEP_SICK","duration":1}]
[2026-01-06T14:48:43+01:00] RAW INPUT: [{"date":"2025-09-30","type":"PEP_SICK","duration":1}]
[2026-01-06T15:00:55+01:00] RAW INPUT: [{"date":"2025-09-29","type":"PEP_SICK","duration":1}]
[2026-01-06T15:04:46+01:00] RAW INPUT: [{"date":"2025-10-17","type":"PEP_SICK","duration":1}]
[2026-01-06T15:10:42+01:00] RAW INPUT: [{"date":"2025-10-21","type":"PEP_SICK","duration":1}]
[2026-01-06T15:11:00+01:00] RAW INPUT: [{"date":"2025-10-24","type":"PEP_SICK","duration":1}]
[2026-01-06T15:11:10+01:00] RAW INPUT: [{"date":"2025-12-02","type":"PEP_SICK","duration":1}]
[2026-01-06T15:11:57+01:00] RAW INPUT: [{"date":"2025-09-23","type":"PEP_SICK","duration":1}]
[2026-01-06T15:17:03+01:00] RAW INPUT: [{"date":"2025-09-10","type":"CENTRE","duration":1}]
[2026-01-06T15:26:35+01:00] RAW INPUT: [{"date":"2025-10-06","type":"PEP_SICK","duration":1},{"date":"2025-10-07","type":"PEP_SICK","duration":1},{"date":"2025-10-08","type":"PEP_SICK","duration":1}]
[2026-01-07T10:04:23+01:00] RAW INPUT: [{"date":"2025-09-19","type":"OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-07T11:10:59+01:00] RAW INPUT: [{"date":"2025-09-04","type":"CENTRE","duration":1}]
[2026-01-07T13:33:21+01:00] RAW INPUT: [{"date":"2025-09-08","type":"CENTRE","duration":1}]
[2026-01-07T13:33:26+01:00] RAW INPUT: [{"date":"2025-09-08","type":"OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-07T13:33:32+01:00] RAW INPUT: [{"date":"2025-09-08","type":"PEP_SICK","duration":1}]
[2026-01-07T13:37:27+01:00] RAW INPUT: [{"date":"2025-10-13","type":"CENTRE","duration":1}]
[2026-01-07T14:26:31+01:00] RAW INPUT: [{"date":"2025-09-08","type":"OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-07T14:26:36+01:00] RAW INPUT: [{"date":"2025-09-08","type":"OFF_CAROLE","person":"Carole","duration":1},{"date":"2025-09-09","type":"OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-07T14:30:24+01:00] RAW INPUT: [{"date":"2025-10-06","type":"CENTRE","duration":1},{"date":"2025-10-07","type":"CENTRE","duration":1}]
[2026-01-08T09:21:34+01:00] RAW INPUT: [{"date":"2025-09-15","type":"EXTRA_OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-08T09:21:38+01:00] RAW INPUT: [{"date":"2025-09-17","type":"EXTRA_OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-08T09:21:58+01:00] RAW INPUT: [{"date":"2025-10-20","type":"CENTRE","duration":1},{"date":"2025-10-21","type":"CENTRE","duration":1},{"date":"2025-10-22","type":"CENTRE","duration":1},{"date":"2025-10-23","type":"CENTRE","duration":1},{"date":"2025-10-24","type":"CENTRE","duration":1}]
[2026-01-08T09:22:43+01:00] RAW INPUT: [{"date":"2025-12-22","type":"EXTRA_OFF_CAROLE","person":"Carole","duration":1},{"date":"2025-12-23","type":"EXTRA_OFF_CAROLE","person":"Carole","duration":1},{"date":"2025-12-24","type":"EXTRA_OFF_CAROLE","person":"Carole","duration":1}]
[2026-01-08T09:23:59+01:00] RAW INPUT: [{"date":"2025-12-22","type":"CENTRE","duration":1}]
[2026-01-08T09:24:00+01:00] RAW INPUT: [{"date":"2025-12-23","type":"CENTRE","duration":1}]
[2026-01-08T09:24:02+01:00] RAW INPUT: [{"date":"2025-12-24","type":"CENTRE","duration":1}]
[2026-01-30T22:49:07+01:00] RAW INPUT: [{"date":"2025-10-24","type":"AVIS","duration":1,"person":null}]
[2026-01-30T22:49:50+01:00] RAW INPUT: [{"date":"2025-10-16","type":"OFF_CAROLE","duration":1,"person":null}]
[2026-01-30T22:50:00+01:00] RAW INPUT: [{"date":"2025-09-11","type":"OFF_CAROLE","duration":1,"person":null}]
[2026-01-30T22:51:16+01:00] RAW INPUT: [{"date":"2025-09-05","type":"AVIS","duration":1,"person":null}]
[2026-01-30T22:53:23+01:00] RAW INPUT: [{"date":"2025-09-03","type":"AVIS","duration":1,"person":null}]
[2026-01-30T23:16:56+01:00] RAW INPUT: [{"date":"2025-09-28","type":"OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-09-29","type":"OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-09-30","type":"OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-01","type":"OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-02","type":"OFF_CAROLE","duration":1,"person":"Carole"}]
[2026-01-30T23:17:02+01:00] RAW INPUT: [{"date":"2025-10-05","type":"EXTRA_OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-06","type":"EXTRA_OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-07","type":"EXTRA_OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-08","type":"EXTRA_OFF_CAROLE","duration":1,"person":"Carole"},{"date":"2025-10-09","type":"EXTRA_OFF_CAROLE","duration":1,"person":"Carole"}]
[2026-01-30T23:17:09+01:00] RAW INPUT: [{"date":"2025-10-05","type":"AVIS","duration":1,"person":"Carole"},{"date":"2025-10-06","type":"AVIS","duration":1,"person":"Carole"},{"date":"2025-10-07","type":"AVIS","duration":1,"person":"Carole"},{"date":"2025-10-08","type":"AVIS","duration":1,"person":"Carole"}]
[2026-02-20T16:05:33+01:00] RAW INPUT: [{"date":"2026-02-21","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-22","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-23","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-24","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-25","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-26","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-27","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-02-28","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-01","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-02","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-03","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-04","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-05","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-06","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-03-07","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-04-18","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-19","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-20","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-21","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-22","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-23","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-24","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-25","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-26","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-27","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-28","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-29","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-04-30","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-05-01","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-05-02","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2026-05-13","type":"VACANCES_SCOLAIRES","duration":1,"person":"Pont de l'Ascension"},{"date":"2026-05-14","type":"VACANCES_SCOLAIRES","duration":1,"person":"Pont de l'Ascension"},{"date":"2026-05-15","type":"VACANCES_SCOLAIRES","duration":1,"person":"Pont de l'Ascension"},{"date":"2026-05-16","type":"VACANCES_SCOLAIRES","duration":1,"person":"Pont de l'Ascension"},{"date":"2025-12-20","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-21","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-22","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-23","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-24","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-25","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-26","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-27","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-28","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-29","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-30","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2025-12-31","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-01-01","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-01-02","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-01-03","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-07-04","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Été"},{"date":"2026-07-05","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Été"},{"date":"2026-07-06","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Été"},{"date":"2026-07-07","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Été"},{"date":"2026-07-08","type":"VACANLine truncated
[2026-02-20T16:15:32+01:00] RAW INPUT: [{"date":"2027-02-06","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-07","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-08","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-09","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-10","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-11","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-12","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-13","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-14","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-15","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-16","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-17","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-18","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-19","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2027-02-20","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances d'Hiver"},{"date":"2026-10-17","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-18","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-19","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-20","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-21","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-22","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-23","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-24","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-25","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-26","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-27","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-28","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-29","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-30","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-10-31","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de la Toussaint"},{"date":"2026-12-19","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-20","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-21","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-22","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-23","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-24","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-25","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-26","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-27","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-28","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-29","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-30","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2026-12-31","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2027-01-01","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2027-01-02","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Noël"},{"date":"2027-04-03","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-04","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-05","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-06","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-07","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-08","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-09","type":"VACANCES_SCOLAIRES","duration":1,"person":"Vacances de Printemps"},{"date":"2027-04-10","type":"VACANCES_SCOLAIRES","duratioLine truncated
[2026-05-06T10:14:03+02:00] RAW INPUT: [{"date":"2026-02-26","type":"AVIS","duration":1,"person":"Carole"}]
[2026-05-06T10:14:28+02:00] RAW INPUT: [{"date":"2026-02-24","type":"PEP_SICK","duration":1,"person":"Carole"}]
[2026-05-06T10:14:34+02:00] RAW INPUT: [{"date":"2026-02-23","type":"CENTRE","duration":1,"person":"Carole"}]
[2026-05-06T10:16:01+02:00] RAW INPUT: [{"date":"2026-01-19","type":"PEP_SICK","duration":1,"person":"Carole"}]
[2026-05-06T10:16:57+02:00] RAW INPUT: [{"date":"2026-03-19","type":"PEP_SICK","duration":1,"person":"Carole"}]
[2026-05-06T20:38:19+02:00] RAW INPUT: [{"date":"2026-05-08","type":"AVIS","duration":1,"person":"Carole"}]
[2026-05-06T20:38:22+02:00] RAW INPUT: [{"date":"2026-05-08","type":"CENTRE","duration":1,"person":"Carole"}]
[2026-05-06T20:38:24+02:00] RAW INPUT: [{"date":"2026-05-08","type":"AVIS","duration":1,"person":"Carole"}]
[2026-05-06T20:43:43+02:00] RAW INPUT: [{"date":"2026-05-06","type":"AVIS","duration":1,"person":"Carole"}]
[2026-05-06T20:44:36+02:00] RAW INPUT: [{"date":"2026-05-06","type":"PEP_SICK","duration":1,"person":"Carole"}]
[2026-05-20T16:40:17+02:00] RAW INPUT: [{"date":"2026-05-19","type":"OFF_CAROLE","duration":1,"person":"Carole"}]
[2026-06-16T14:20:35+02:00] RAW INPUT: [{"date":"2026-07-29","type":"CARE_MODE","duration":1,"person":"Centre"}]
[2026-06-16T14:20:43+02:00] RAW INPUT: [{"date":"2026-06-16","type":"CARE_MODE","duration":1,"person":"Centre"}]
[2026-06-16T14:22:51+02:00] RAW INPUT: [{"date":"2026-06-16","type":"CHILD_SICK","duration":1,"person":"5"}]
[2026-06-16T14:23:10+02:00] RAW INPUT: [{"date":"2026-06-16","type":"CHILD_SICK","duration":1,"person":"5"}]
[2026-06-16T14:23:33+02:00] RAW INPUT: [{"date":"2026-06-18","type":"CARE_MODE","duration":1,"person":"Nounou"}]
[2026-06-16T14:23:54+02:00] RAW INPUT: [{"date":"2026-06-11","type":"HELPER_OFF","duration":1,"person":"1"}]
[2026-06-16T14:23:57+02:00] RAW INPUT: [{"date":"2026-06-25","type":"CHILD_SICK","duration":1,"person":"4"}]
@@ -0,0 +1,68 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
/**
* Paramètre: school_year_start (optionnel)
* - année de début d'année scolaire (ex: 2025 pour 09/2025 -> 08/2026)
* - défaut: année courante si non fourni
*/
$schoolYearStart = isset($_GET['school_year_start'])
? (int)$_GET['school_year_start']
: (int)date('Y');
if ($schoolYearStart < 2000 || $schoolYearStart > 2100) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Année scolaire invalide.']);
exit;
}
$yearStart = $schoolYearStart;
$yearEnd = $schoolYearStart + 1;
// On veut toutes les semaines:
// - de septembre (month >= 9) de yearStart
// - à août (month <= 8) de yearEnd
try {
$sql = "
SELECT
year,
week_iso_year,
week_iso_number,
week_label,
month,
month_name,
week_start_date,
mon_date,
tue_date,
wed_date,
thu_date,
fri_date
FROM pf_calendar_weeks
WHERE
(year = :year_start AND month >= 9)
OR (year = :year_end AND month <= 8)
ORDER BY week_start_date ASC
";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':year_start' => $yearStart,
':year_end' => $yearEnd,
]);
$weeks = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'school_year' => $schoolYearStart,
'weeks' => $weeks,
]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => $e->getMessage(),
]);
}
@@ -0,0 +1,36 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
$year = isset($_GET['year']) ? (int)$_GET['year'] : (int)date('Y');
try {
$stmt = $pdo->prepare("
SELECT
year,
week_iso_year,
week_iso_number,
week_label,
month,
month_name,
week_start_date,
mon_date,
tue_date,
wed_date,
thu_date,
fri_date
FROM pf_calendar_weeks
WHERE year = :year
ORDER BY week_start_date ASC
");
$stmt->execute([':year' => $year]);
$weeks = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['weeks' => $weeks]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => $e->getMessage(),
]);
}
@@ -1,7 +1,7 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../includes/db.php';
require __DIR__ . '/../../../../includes/db.php';
try {
$stmt = $pdo->query("SELECT id, event_date AS date, event_type AS type, person_id, duration FROM pf_events ORDER BY event_date");
@@ -0,0 +1,29 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
try {
// 🔥 LE FIX : On interroge la NOUVELLE table des quotas individuels !
$stmt = $pdo->query("
SELECT
person_id,
leave_type AS type,
allowance,
method,
anniversary_date AS date
FROM pf_person_leave_meta
");
$balances = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'balances' => $balances
]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => $e->getMessage(),
]);
}
?>
@@ -0,0 +1,20 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
try {
$stmt = $pdo->query("
SELECT person_id, leave_type, snapshot_date, remaining_balance, carry_over_balance
FROM pf_leave_snapshots
ORDER BY snapshot_date ASC
");
$snapshots = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['snapshots' => $snapshots]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode([
'status' => 'error',
'message' => $e->getMessage(),
]);
}
@@ -0,0 +1,31 @@
<?php
// api/get-leaves.php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
try {
$stmt = $pdo->query("
SELECT
l.id,
l.person_id,
p.name AS person_name,
l.leave_type,
l.leave_date,
l.duration
FROM pf_leaves l
JOIN pf_people p ON p.id = l.person_id
ORDER BY l.leave_date, l.person_id
");
$leaves = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'status' => 'success',
'leaves' => $leaves,
]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
@@ -0,0 +1,24 @@
<?php
// /modules/family-calendar/includes/api/get-person-leave-meta.php
require __DIR__ . '/../../../../includes/db.php';
header('Content-Type: application/json; charset=utf-8');
try {
$stmt = $pdo->query("
SELECT person_id, anniversary_date
FROM pf_person_leave_meta
");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'meta' => $rows,
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'error' => true,
'message' => $e->getMessage(),
]);
}
@@ -0,0 +1,122 @@
<?php
// modules/family-calendar/includes/api/manage-event.php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
$input = json_decode(file_get_contents('php://input'), true);
$action = $input['action'] ?? '';
if (!$action) {
http_response_code(400);
echo json_encode(['success' => false, 'status' => 'error', 'message' => 'Action manquante.']);
exit;
}
try {
if ($action === 'delete') {
$eventId = (int)($input['event_id'] ?? 0);
if ($eventId <= 0) {
http_response_code(400);
echo json_encode(['success' => false, 'status' => 'error', 'message' => 'ID manquant.']);
exit;
}
$stmt = $pdo->prepare("DELETE FROM pf_events WHERE id = ?");
$stmt->execute([$eventId]);
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
if ($action === 'update') {
$eventId = (int)($input['event_id'] ?? 0);
$newType = $input['new_type'] ?? '';
if ($eventId <= 0 || !$newType) {
http_response_code(400);
echo json_encode(['success' => false, 'status' => 'error', 'message' => 'Données manquantes.']);
exit;
}
$stmt = $pdo->prepare("UPDATE pf_events SET event_type = ? WHERE id = ?");
$stmt->execute([$newType, $eventId]);
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
if ($action === 'bulk_delete_day_types_person') {
$dates = $input['dates'] ?? [];
$types = $input['types'] ?? [];
$person_id = $input['person_id'] ?? null;
$dates = array_filter($dates, function($d) { return preg_match('/^\d{4}-\d{2}-\d{2}$/', $d); });
if (empty($dates) || empty($types)) {
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
$datePlaceholders = implode(',', array_fill(0, count($dates), '?'));
$typePlaceholders = implode(',', array_fill(0, count($types), '?'));
$sql = "DELETE FROM pf_events WHERE event_date IN ($datePlaceholders) AND event_type IN ($typePlaceholders)";
$params = array_merge($dates, $types);
// 🔥 LE CORRECTIF : On cherche le 0 en base de données
if ($person_id === null || $person_id === '' || (int)$person_id === 0) {
$sql .= " AND person_id = 0";
} else {
$sql .= " AND person_id = ?";
$params[] = (int)$person_id;
}
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
if ($action === 'bulk_delete_day_types') {
$dates = $input['dates'] ?? [];
$types = $input['types'] ?? [];
$dates = array_filter($dates, function($d) { return preg_match('/^\d{4}-\d{2}-\d{2}$/', $d); });
if (empty($dates) || empty($types)) {
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
$datePlaceholders = implode(',', array_fill(0, count($dates), '?'));
$typePlaceholders = implode(',', array_fill(0, count($types), '?'));
$sql = "DELETE FROM pf_events WHERE event_date IN ($datePlaceholders) AND event_type IN ($typePlaceholders)";
$stmt = $pdo->prepare($sql);
$stmt->execute(array_merge($dates, $types));
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
if ($action === 'bulk_delete_all') {
$dates = $input['dates'] ?? [];
$dates = array_filter($dates, function($d) { return preg_match('/^\d{4}-\d{2}-\d{2}$/', $d); });
if (empty($dates)) {
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
$datePlaceholders = implode(',', array_fill(0, count($dates), '?'));
$sql = "DELETE FROM pf_events WHERE event_date IN ($datePlaceholders)";
$stmt = $pdo->prepare($sql);
$stmt->execute($dates);
echo json_encode(['success' => true, 'status' => 'success']);
exit;
}
http_response_code(400);
echo json_encode(['success' => false, 'status' => 'error', 'message' => 'Action non reconnue : ' . $action]);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['success' => false, 'status' => 'error', 'message' => $e->getMessage()]);
}
?>
@@ -0,0 +1,139 @@
<?php
// api/manage-leaf.php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
$input = json_decode(file_get_contents('php://input'), true);
if (!is_array($input)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'JSON invalide.']);
exit;
}
$action = $input['action'] ?? null;
if (!$action) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Action manquante.']);
exit;
}
try {
// ===================== DELETE TOUS LES LEAVES D'UN JOUR (EXISTANT) =====================
if ($action === 'delete_day') {
if (empty($input['date'])) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Date manquante pour delete_day.']);
exit;
}
$dateObj = date_create($input['date']);
if (!$dateObj) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Date invalide.']);
exit;
}
$leaveDate = $dateObj->format('Y-m-d');
$stmt = $pdo->prepare("DELETE FROM pf_leaves WHERE leave_date = ?");
$stmt->execute([$leaveDate]);
echo json_encode(['status' => 'success', 'message' => 'Congés supprimés pour ce jour.']);
exit;
}
// ===================== DELETE POUR UNE PERSONNE / JOUR (SINGLE) =====================
if ($action === 'delete_day_person') {
$date = $input['date'] ?? null;
$personId = $input['person_id'] ?? null;
if (empty($date) || empty($personId)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'date ou person_id manquant pour delete_day_person.']);
exit;
}
$dateObj = date_create($date);
if (!$dateObj) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Date invalide pour delete_day_person.']);
exit;
}
$leaveDate = $dateObj->format('Y-m-d');
$stmt = $pdo->prepare("
DELETE FROM pf_leaves
WHERE leave_date = :date
AND person_id = :person_id
");
$stmt->execute([
':date' => $leaveDate,
':person_id' => $personId,
]);
echo json_encode([
'status' => 'success',
'message' => 'Congés supprimés pour cette personne et ce jour.',
'deleted' => $stmt->rowCount(),
]);
exit;
}
// ===================== BULK DELETE POUR UNE PERSONNE / PLUSIEURS JOURS =====================
if ($action === 'bulk_delete_day_person') {
$dates = $input['dates'] ?? null;
$personId = $input['person_id'] ?? null;
if (!is_array($dates) || empty($dates) || empty($personId)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'dates ou person_id manquant pour bulk_delete_day_person.']);
exit;
}
// Normaliser les dates en 'Y-m-d'
$normalizedDates = [];
foreach ($dates as $d) {
$dateObj = date_create($d);
if ($dateObj) {
$normalizedDates[] = $dateObj->format('Y-m-d');
}
}
if (empty($normalizedDates)) {
echo json_encode([
'status' => 'success',
'message' => 'Aucune date valide fournie.',
'deleted' => 0,
]);
exit;
}
// Construire le IN (...)
$placeholders = implode(',', array_fill(0, count($normalizedDates), '?'));
$sql = "
DELETE FROM pf_leaves
WHERE person_id = ?
AND leave_date IN ($placeholders)
";
$stmt = $pdo->prepare($sql);
$params = array_merge([$personId], $normalizedDates);
$stmt->execute($params);
echo json_encode([
'status' => 'success',
'message' => 'Congés supprimés pour cette personne sur les dates fournies.',
'deleted' => $stmt->rowCount(),
]);
exit;
}
// ===================== ACTION NON RECONNUE =====================
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Action non valide.']);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
@@ -0,0 +1,73 @@
<?php
// modules/family-calendar/includes/api/save-events.php
header('Content-Type: application/json');
require_once __DIR__ . '/../../../../includes/db.php';
try {
$rawInput = file_get_contents('php://input');
$eventsToSave = json_decode($rawInput, true);
if (empty($eventsToSave) || !is_array($eventsToSave)) {
throw new Exception("Aucune donnée d'événement reçue.");
}
$pdo->beginTransaction();
$sql = "INSERT INTO pf_events (event_date, event_type, person_id, duration)
VALUES (:event_date, :event_type, :person_id, :duration)";
$stmt = $pdo->prepare($sql);
$inserted = [];
foreach ($eventsToSave as $event) {
if (empty($event['date']) || empty($event['type'])) {
continue; // Sécurité anti-crash
}
$person_id = 0;
if (!empty($event['person_id']) && is_numeric($event['person_id'])) {
$person_id = (int)$event['person_id'];
} elseif (!empty($event['person']) && is_numeric($event['person'])) {
$person_id = (int)$event['person'];
}
// 🔥 LE FIX : On tronque à 50 caractères pour éviter l'erreur "Data truncated"
$safeType = substr(trim($event['type']), 0, 50);
$duration = isset($event['duration']) ? (float)$event['duration'] : 1.0;
$stmt->execute([
':event_date' => $event['date'],
':event_type' => $safeType,
':person_id' => $person_id,
':duration' => $duration,
]);
$inserted[] = [
'id' => $pdo->lastInsertId(),
'date' => $event['date'],
'type' => $safeType,
'duration' => $duration,
'person_id' => $person_id,
];
}
$pdo->commit();
echo json_encode([
'success' => true,
'status' => 'success',
'inserted' => $inserted,
]);
} catch (\Throwable $e) { // 🔥 LE FIX : \Throwable attrape AUSSI les fatals errors PDO
if (isset($pdo) && $pdo->inTransaction()) {
$pdo->rollBack();
}
http_response_code(500);
echo json_encode([
'success' => false,
'status' => 'error',
'message' => 'Erreur Serveur/SQL : ' . $e->getMessage()
]);
}
?>
@@ -0,0 +1,34 @@
<?php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
$input = json_decode(file_get_contents('php://input'), true);
if (!$input || empty($input['person_id']) || empty($input['leave_type']) || empty($input['snapshot_date']) || !isset($input['remaining_balance'])) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Données manquantes.']);
exit;
}
try {
// Étape 1 : Par sécurité, on supprime un éventuel snapshot existant exactement à la même date pour cette personne et ce type
$stmtDel = $pdo->prepare("DELETE FROM pf_leave_snapshots WHERE person_id = ? AND leave_type = ? AND snapshot_date = ?");
$stmtDel->execute([$input['person_id'], $input['leave_type'], $input['snapshot_date']]);
$carry_over_balance = isset($input['carry_over_balance']) ? (float)$input['carry_over_balance'] : 0.00;
// Étape 2 : On insère le nouveau solde
$stmt = $pdo->prepare("INSERT INTO pf_leave_snapshots (person_id, leave_type, snapshot_date, remaining_balance, carry_over_balance) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([
$input['person_id'],
$input['leave_type'],
$input['snapshot_date'],
$input['remaining_balance'],
$carry_over_balance
]);
echo json_encode(['status' => 'success']);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
@@ -0,0 +1,68 @@
<?php
// api/save-leaves.php
header('Content-Type: application/json');
require __DIR__ . '/../../../../includes/db.php';
$input = json_decode(file_get_contents('php://input'), true);
if (!is_array($input) || empty($input)) {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Données invalides (attendu tableau JSON).']);
exit;
}
// Exemple d'élément attendu :
// { date: '2025-09-01', person_id: 2, leave_type: 'CP', duration: 1.0 }
$validLeaveTypes = ['CP', 'JRA', 'JA'];
try {
$pdo->beginTransaction();
$stmtInsert = $pdo->prepare("
INSERT INTO pf_leaves (person_id, leave_type, leave_date, duration)
VALUES (:person_id, :leave_type, :leave_date, :duration)
");
foreach ($input as $item) {
$date = $item['date'] ?? null;
$personId = $item['person_id'] ?? null;
$leaveType = $item['leave_type'] ?? null;
$duration = isset($item['duration']) ? (float)$item['duration'] : 1.0;
if (!$date || !$personId || !$leaveType) {
continue; // on ignore les lignes incomplètes
}
if (!in_array($leaveType, $validLeaveTypes, true)) {
continue; // leave_type invalide
}
// Normalisation de la date
$dateObj = date_create($date);
if (!$dateObj) {
continue;
}
$leaveDate = $dateObj->format('Y-m-d');
$stmtInsert->execute([
':person_id' => (int)$personId,
':leave_type' => $leaveType,
':leave_date' => $leaveDate,
':duration' => $duration,
]);
}
$pdo->commit();
echo json_encode([
'status' => 'success',
'message' => 'Congés enregistrés.',
]);
} catch (PDOException $e) {
$pdo->rollBack();
http_response_code(500);
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
File diff suppressed because it is too large. Load diff
+410
View File
@@ -0,0 +1,410 @@
<?php
// modules/food/includes/api/api-liste.php
ob_start();
require_once dirname(__DIR__, 4) . '/includes/auth.php';
require_login();
header('Content-Type: application/json');
set_exception_handler(function (\Throwable $e) {
if (!headers_sent()) { header('Content-Type: application/json'); http_response_code(500); }
echo json_encode(['ok' => false, 'error' => $e->getMessage()]); exit;
});
require_once dirname(__DIR__, 4) . '/includes/db.php';
// ── Auto-create tables ────────────────────────────────────────────────────────
$pdo->exec("CREATE TABLE IF NOT EXISTS pf_lists (
id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL DEFAULT 'Ma liste',
color VARCHAR(20) DEFAULT NULL, list_type VARCHAR(50) DEFAULT NULL,
position INT NOT NULL DEFAULT 0, created_at DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$pdo->exec("CREATE TABLE IF NOT EXISTS pf_grocery_items (
id INT AUTO_INCREMENT PRIMARY KEY, list_id INT NOT NULL DEFAULT 1,
category_id INT DEFAULT NULL, label VARCHAR(500) NOT NULL,
in_cart TINYINT(1) NOT NULL DEFAULT 0, position INT NOT NULL DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY idx_items_list (list_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$pdo->exec("CREATE TABLE IF NOT EXISTS pf_grocery_history (
id INT AUTO_INCREMENT PRIMARY KEY, label_hash CHAR(64) NOT NULL,
label_display VARCHAR(500) NOT NULL,
last_used_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UNIQUE KEY uq_grocery_hist_hash (label_hash), KEY idx_hist_last (last_used_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$pdo->exec("CREATE TABLE IF NOT EXISTS pf_list_categories (
id INT AUTO_INCREMENT PRIMARY KEY, icon VARCHAR(10) NOT NULL DEFAULT '🏷️',
name VARCHAR(100) NOT NULL, position INT NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
$pdo->exec("CREATE TABLE IF NOT EXISTS pf_item_category_rules (
id INT AUTO_INCREMENT PRIMARY KEY, keyword VARCHAR(255) NOT NULL,
category_id INT NOT NULL, UNIQUE KEY uq_keyword (keyword)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4");
// Migrations
try { $pdo->exec("ALTER TABLE pf_grocery_items ADD COLUMN list_id INT NOT NULL DEFAULT 1 AFTER id"); } catch (\Exception $e) {}
try { $pdo->exec("ALTER TABLE pf_grocery_items ADD COLUMN category_id INT DEFAULT NULL AFTER list_id"); } catch (\Exception $e) {}
try { $pdo->exec("ALTER TABLE pf_grocery_items ADD KEY idx_items_list (list_id)"); } catch (\Exception $e) {}
try { $pdo->exec("ALTER TABLE pf_lists ADD COLUMN color VARCHAR(20) DEFAULT NULL AFTER name"); } catch (\Exception $e) {}
try { $pdo->exec("ALTER TABLE pf_lists ADD COLUMN list_type VARCHAR(50) DEFAULT NULL AFTER color"); } catch (\Exception $e) {}
// ── Seed categories if empty ──────────────────────────────────────────────────
if ((int)$pdo->query("SELECT COUNT(*) FROM pf_list_categories")->fetchColumn() === 0) {
$cats = [
['🍎','Fruits & Légumes'],['🍖','Viande'],['🐟','Poissonnerie'],
['🍞','Boulangerie'],['🥛','Frais'],['❄️','Surgelés'],
['🧃','Boissons'],['🌾','Pâtes, Riz, Féculents'],['🥜','Épicerie salée'],
['🥫','Conserves'],['🍛','Plats cuisinés'],['🧂','Sauces & Condiments'],
['🥐','Petit déjeuner'],['🍪','Biscuits & Gâteaux'],['🍫','Confiserie'],
['🍦','Dessert'],['🧴','Beauté & Hygiène'],['🍼','Bébé'],
['🧼','Entretien'],['🐶','Animaux'],['🏡','Maison & Jardin'],['💊','Pharmacie'],
];
$ins = $pdo->prepare("INSERT INTO pf_list_categories (icon, name, position) VALUES (?,?,?)");
foreach ($cats as $i => $c) $ins->execute([$c[0], $c[1], $i * 10]);
}
// ── Helpers ───────────────────────────────────────────────────────────────────
function liste_normalize(string $s): string {
return mb_strtolower(trim(mb_substr($s, 0, 500)));
}
function liste_normalize_detect(string $s): string {
$s = mb_strtolower(trim($s));
$from = ['é','è','ê','ë','à','â','ä','ù','û','ü','î','ï','ô','ö','ç','œ','æ'];
$to = ['e','e','e','e','a','a','a','u','u','u','i','i','o','o','c','oe','ae'];
$s = str_replace($from, $to, $s);
return trim(preg_replace('/[^a-z0-9 ]/', '', $s));
}
function liste_touch_history(PDO $pdo, string $label): void {
$hash = hash('sha256', liste_normalize($label));
$pdo->prepare("INSERT INTO pf_grocery_history (label_hash, label_display) VALUES (?,?)
ON DUPLICATE KEY UPDATE label_display=VALUES(label_display), last_used_at=NOW()")
->execute([$hash, trim($label)]);
}
function liste_ensure_default(PDO $pdo): int {
if ((int)$pdo->query("SELECT COUNT(*) FROM pf_lists")->fetchColumn() === 0) {
$pdo->exec("INSERT INTO pf_lists (name, position) VALUES ('Ma liste', 0)");
return (int)$pdo->lastInsertId();
}
return (int)$pdo->query("SELECT id FROM pf_lists ORDER BY position, id LIMIT 1")->fetchColumn();
}
function liste_builtin_detect(string $normalized): ?int {
static $map = null;
if ($map === null) $map = [
'pomme'=>1,'poire'=>1,'banane'=>1,'orange'=>1,'citron'=>1,'raisin'=>1,
'fraise'=>1,'framboise'=>1,'myrtille'=>1,'cerise'=>1,'peche'=>1,'abricot'=>1,
'mangue'=>1,'kiwi'=>1,'ananas'=>1,'melon'=>1,'pasteque'=>1,'prune'=>1,
'tomate'=>1,'concombre'=>1,'carotte'=>1,'oignon'=>1,'poireau'=>1,
'courgette'=>1,'aubergine'=>1,'poivron'=>1,'salade'=>1,'laitue'=>1,
'epinard'=>1,'brocoli'=>1,'chou'=>1,'choux'=>1,'haricot'=>1,'pois'=>1,
'champignon'=>1,'ail'=>1,'echalote'=>1,'pomme de terre'=>1,'patate'=>1,
'navet'=>1,'radis'=>1,'betterave'=>1,'fenouil'=>1,'asperge'=>1,
'artichaut'=>1,'celeri'=>1,'butternut'=>1,'courge'=>1,'potiron'=>1,
'gingembre'=>1,'avocat'=>1,'endive'=>1,'ciboulette'=>1,'persil'=>1,
'basilic'=>1,'menthe'=>1,'thym'=>1,'romarin'=>1,'coriandre'=>1,
'girofle'=>1,'citron vert'=>1,'lime'=>1,'pamplemousse'=>1,'litchi'=>1,
'boeuf'=>2,'veau'=>2,'poulet'=>2,'porc'=>2,'agneau'=>2,'dinde'=>2,
'lapin'=>2,'jambon'=>2,'lardon'=>2,'saucisse'=>2,'saucisson'=>2,
'merguez'=>2,'chipolata'=>2,'steak'=>2,'escalope'=>2,'roti'=>2,
'gigot'=>2,'filet'=>2,'cuisses'=>2,'viande hachee'=>2,'andouille'=>2,
'magret'=>2,'canard'=>2,'foie'=>2,'boudin'=>2,'paupiette'=>2,
'entrecote'=>2,'cote de boeuf'=>2,'onglet'=>2,'bavette'=>2,
'saumon'=>3,'thon'=>3,'dorade'=>3,'bar'=>3,'cabillaud'=>3,'sole'=>3,
'truite'=>3,'lieu'=>3,'maquereau'=>3,'sardine'=>3,'anchois'=>3,
'crevette'=>3,'moule'=>3,'huitre'=>3,'coquille'=>3,'poulpe'=>3,
'seiche'=>3,'langoustine'=>3,'lotte'=>3,'merlu'=>3,'colin'=>3,
'tilapia'=>3,'daurade'=>3,'aiglefin'=>3,'homard'=>3,'crabe'=>3,
'pain'=>4,'baguette'=>4,'brioche'=>4,'croissant'=>4,'pain de mie'=>4,
'ficelle'=>4,'fougasse'=>4,'ciabatta'=>4,'biscotte'=>4,'naan'=>4,
'pita'=>4,'toast'=>4,'bagel'=>4,'pain burger'=>4,'wrap'=>4,
'lait'=>5,'creme'=>5,'yaourt'=>5,'yourt'=>5,'beurre'=>5,
'fromage'=>5,'camembert'=>5,'brie'=>5,'comte'=>5,'gruyere'=>5,
'emmental'=>5,'mozzarella'=>5,'ricotta'=>5,'mascarpone'=>5,
'feta'=>5,'chevre'=>5,'oeuf'=>5,'oeufs'=>5,'creme fraiche'=>5,
'fromage blanc'=>5,'petit suisse'=>5,'kefir'=>5,
'surgele'=>6,'pizza surgelee'=>6,'frite surgelee'=>6,'poisson pane'=>6,
'legume surgele'=>6,'glace'=>6,'sorbet'=>6,'plat surgele'=>6,
'nugget'=>6,'edamame'=>6,'petits pois'=>6,'epinards'=>6,
'eau'=>7,'coca'=>7,'cola'=>7,'limonade'=>7,'sirop'=>7,
'biere'=>7,'vin'=>7,'champagne'=>7,'cafe'=>7,'the'=>7,
'tisane'=>7,'soda'=>7,'jus'=>7,'kombucha'=>7,'cidre'=>7,
'whisky'=>7,'rhum'=>7,'vodka'=>7,'prosecco'=>7,'rose'=>7,
'pate'=>8,'spaghetti'=>8,'tagliatelle'=>8,'penne'=>8,'fusilli'=>8,
'macaroni'=>8,'riz'=>8,'couscous'=>8,'quinoa'=>8,'lentille'=>8,
'pois chiche'=>8,'farine'=>8,'semoule'=>8,'polenta'=>8,'boulgour'=>8,
'orge'=>8,'feculent'=>8,'vermicelle'=>8,'nouille'=>8,'gnocchi'=>8,
'chips'=>9,'crackers'=>9,'olives'=>9,'cornichon'=>9,'capres'=>9,
'tapenade'=>9,'houmous'=>9,'tzatziki'=>9,'sel'=>9,'poivre'=>9,
'epice'=>9,'cube bouillon'=>9,'bouillon'=>9,'noix de cajou'=>9,
'amande'=>9,'pistache'=>9,'noix'=>9,'cacahuete'=>9,
'conserve'=>10,'boite de tomate'=>10,'concentre de tomate'=>10,
'mais'=>10,'ratatouille'=>10,'cassoulet'=>10,'pate de foie'=>10,
'sardine boite'=>10,'thon boite'=>10,'maquereau boite'=>10,
'soupe boite'=>10,'haricot boite'=>10,
'quiche'=>11,'lasagne'=>11,'gratin'=>11,'pizza'=>11,'tartiflette'=>11,
'croque'=>11,'hachis parmentier'=>11,'paella'=>11,'moussaka'=>11,
'tarte'=>11,'flamiche'=>11,'pissaladiere'=>11,
'ketchup'=>12,'mayonnaise'=>12,'moutarde'=>12,'vinaigrette'=>12,
'sauce soja'=>12,'tabasco'=>12,'huile'=>12,'vinaigre'=>12,
'sauce tomate'=>12,'pesto'=>12,'sriracha'=>12,'worcester'=>12,
'nuoc mam'=>12,'sauce'=>12,'condiment'=>12,'worcestershire'=>12,
'cereale'=>13,'muesli'=>13,'granola'=>13,'corn flakes'=>13,
'miel'=>13,'confiture'=>13,'nutella'=>13,'beurre de cacahuete'=>13,
'sirop d erable'=>13,'sirop erable'=>13,'chocolat en poudre'=>13,
'biscuit'=>14,'gateau'=>14,'cookie'=>14,'madeleine'=>14,
'financier'=>14,'quatre quarts'=>14,'brownie'=>14,'sable'=>14,
'speculoos'=>14,'oreo'=>14,'lu'=>14,'petit beurre'=>14,'galette'=>14,
'palmier'=>14,'macaron'=>14,'eclair'=>14,
'chocolat'=>15,'bonbon'=>15,'reglisse'=>15,'caramel'=>15,
'nougat'=>15,'marshmallow'=>15,'guimauve'=>15,'sucette'=>15,
'chewing gum'=>15,'pastille'=>15,'calisson'=>15,
'yaourt dessert'=>16,'creme dessert'=>16,'mousse au chocolat'=>16,
'tiramisu'=>16,'creme brulee'=>16,'flan'=>16,'crepe'=>16,
'profiterole'=>16,
'shampoing'=>17,'gel douche'=>17,'savon'=>17,'dentifrice'=>17,
'deodorant'=>17,'crème visage'=>17,'crème corps'=>17,'rasoir'=>17,
'mousse a raser'=>17,'coton'=>17,'lingette'=>17,'maquillage'=>17,
'parfum'=>17,'brosse a dents'=>17,'fil dentaire'=>17,'serum'=>17,
'hydratant'=>17,'demaquillant'=>17,
'couche'=>18,'biberon'=>18,'lait infantile'=>18,'compote bebe'=>18,
'pot bebe'=>18,'puree bebe'=>18,'lingette bebe'=>18,'savon bebe'=>18,
'creme bebe'=>18,'sucette bebe'=>18,
'lessive'=>19,'liquide vaisselle'=>19,'nettoyant'=>19,'degraissant'=>19,
'deboucheur'=>19,'anticalcaire'=>19,'eponge'=>19,'serpillere'=>19,
'sac poubelle'=>19,'papier toilette'=>19,'sopalin'=>19,'essuie tout'=>19,
'aluminium'=>19,'film plastique'=>19,'sac congelation'=>19,
'nettoyant wc'=>19,'desinfectant'=>19,'vitre'=>19,'javel'=>19,
'croquette'=>20,'patee'=>20,'litiere'=>20,'os'=>20,
'friandise animale'=>20,'nourriture chat'=>20,'nourriture chien'=>20,
'ampoule'=>21,'pile'=>21,'bougie'=>21,'allumette'=>21,
'ruban adhesif'=>21,'colle'=>21,'vis'=>21,'terreau'=>21,
'engrais'=>21,'pot de fleur'=>21,'arrosoir'=>21,'graine'=>21,
'tournevis'=>21,'marteau'=>21,'clou'=>21,'cle'=>21,
'doliprane'=>22,'ibuprofene'=>22,'paracetamol'=>22,'aspirine'=>22,
'bandage'=>22,'pansement'=>22,'thermometre'=>22,'serum physiologique'=>22,
'vitamine'=>22,'complement'=>22,'masque'=>22,'gant medical'=>22,
'antihistaminique'=>22,'antidouleur'=>22,
];
if (isset($map[$normalized])) return $map[$normalized];
$words = explode(' ', $normalized);
foreach ($words as $w) {
if (strlen($w) >= 3 && isset($map[$w])) return $map[$w];
}
foreach ($map as $kw => $catPos) {
if (str_contains($normalized, $kw)) return $catPos;
}
return null;
}
function liste_detect_category(PDO $pdo, string $label): ?int {
$norm = liste_normalize_detect($label);
$r = $pdo->prepare("SELECT category_id FROM pf_item_category_rules WHERE keyword=? LIMIT 1");
$r->execute([$norm]);
if ($row = $r->fetch()) return (int)$row['category_id'];
foreach (explode(' ', $norm) as $w) {
if (strlen($w) < 3) continue;
$r = $pdo->prepare("SELECT category_id FROM pf_item_category_rules WHERE keyword=? LIMIT 1");
$r->execute([$w]);
if ($row = $r->fetch()) return (int)$row['category_id'];
}
$pos = liste_builtin_detect($norm);
if ($pos === null) return null;
$r = $pdo->query("SELECT id FROM pf_list_categories ORDER BY position, id");
$ids = $r->fetchAll(PDO::FETCH_COLUMN);
return $ids[$pos - 1] ?? null;
}
function liste_learn(PDO $pdo, string $label, int $category_id): void {
$norm = liste_normalize_detect($label);
if (!$norm) return;
$pdo->prepare("INSERT INTO pf_item_category_rules (keyword, category_id) VALUES (?,?)
ON DUPLICATE KEY UPDATE category_id=VALUES(category_id)")
->execute([$norm, $category_id]);
foreach (explode(' ', $norm) as $w) {
if (strlen($w) >= 4) {
$pdo->prepare("INSERT IGNORE INTO pf_item_category_rules (keyword, category_id) VALUES (?,?)")
->execute([$w, $category_id]);
}
}
}
$action = $_GET['action'] ?? $_POST['action'] ?? '';
$method = $_SERVER['REQUEST_METHOD'];
$body = [];
if ($method === 'PUT' || $method === 'POST') {
$raw = file_get_contents('php://input');
if ($raw) $body = json_decode($raw, true) ?? [];
foreach ($_POST as $k => $v) if (!isset($body[$k])) $body[$k] = $v;
}
// ── CATEGORIES ────────────────────────────────────────────────────────────────
if ($action === 'categories' && $method === 'GET') {
$rows = $pdo->query("SELECT id, icon, name, position FROM pf_list_categories ORDER BY position, id")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['categories' => $rows]);
exit;
}
// ── SET CATEGORY (+ learn) ────────────────────────────────────────────────────
if ($action === 'set_category' && $method === 'POST') {
$item_id = (int)($body['item_id'] ?? 0);
$cat_id_raw = $body['category_id'] ?? null;
$category_id = ($cat_id_raw === null || $cat_id_raw === '' || $cat_id_raw === '0') ? null : (int)$cat_id_raw;
if (!$item_id) { http_response_code(400); echo json_encode(['error' => 'item_id required']); exit; }
$pdo->prepare("UPDATE pf_grocery_items SET category_id=? WHERE id=?")->execute([$category_id, $item_id]);
if ($category_id !== null) {
$row = $pdo->prepare("SELECT label FROM pf_grocery_items WHERE id=?");
$row->execute([$item_id]);
if ($r = $row->fetch()) liste_learn($pdo, $r['label'], $category_id);
}
echo json_encode(['ok' => true]);
exit;
}
// ── LISTS ─────────────────────────────────────────────────────────────────────
if ($action === 'lists') {
if ($method === 'GET') {
$firstId = liste_ensure_default($pdo);
$rows = $pdo->query("SELECT id, name, color, list_type, position FROM pf_lists ORDER BY position, id")->fetchAll(PDO::FETCH_ASSOC);
echo json_encode(['lists' => $rows, 'default_id' => $firstId]);
exit;
}
if ($method === 'POST') {
$name = mb_substr(trim($body['name'] ?? ''), 0, 100);
$color = mb_substr(trim($body['color'] ?? ''), 0, 20) ?: null;
$list_type = mb_substr(trim($body['list_type'] ?? ''), 0, 50) ?: null;
if (!$name) { http_response_code(400); echo json_encode(['error' => 'name required']); exit; }
$pos = (int)$pdo->query("SELECT COALESCE(MAX(position),0)+1 FROM pf_lists")->fetchColumn();
$pdo->prepare("INSERT INTO pf_lists (name, color, list_type, position) VALUES (?,?,?,?)")->execute([$name, $color, $list_type, $pos]);
echo json_encode(['id' => (int)$pdo->lastInsertId(), 'name' => $name, 'color' => $color, 'list_type' => $list_type, 'position' => $pos]);
exit;
}
if ($method === 'PUT') {
$id = (int)($_GET['id'] ?? 0);
$name = mb_substr(trim($body['name'] ?? ''), 0, 100);
$color = array_key_exists('color', $body) ? (mb_substr(trim($body['color'] ?? ''), 0, 20) ?: null) : false;
$list_type = array_key_exists('list_type', $body) ? (mb_substr(trim($body['list_type'] ?? ''), 0, 50) ?: null) : false;
if (!$id || !$name) { http_response_code(400); echo json_encode(['error' => 'invalid']); exit; }
$sets = ['name=?'];
$vals = [$name];
if ($color !== false) { $sets[] = 'color=?'; $vals[] = $color; }
if ($list_type !== false) { $sets[] = 'list_type=?'; $vals[] = $list_type; }
$vals[] = $id;
$pdo->prepare("UPDATE pf_lists SET " . implode(', ', $sets) . " WHERE id=?")->execute($vals);
echo json_encode(['ok' => true]); exit;
}
if ($method === 'DELETE') {
$id = (int)($_GET['id'] ?? 0);
if ((int)$pdo->query("SELECT COUNT(*) FROM pf_lists")->fetchColumn() <= 1) {
http_response_code(400); echo json_encode(['error' => 'cannot delete last list']); exit;
}
$pdo->prepare("DELETE FROM pf_grocery_items WHERE list_id=?")->execute([$id]);
$pdo->prepare("DELETE FROM pf_lists WHERE id=?")->execute([$id]);
echo json_encode(['ok' => true]); exit;
}
}
// ── ITEMS ─────────────────────────────────────────────────────────────────────
if ($action === 'items') {
$list_id = (int)($_GET['list_id'] ?? $body['list_id'] ?? 0);
if ($method === 'GET') {
if (!$list_id) { http_response_code(400); echo json_encode(['error' => 'list_id required']); exit; }
$s = $pdo->prepare("SELECT id, list_id, category_id, label, in_cart, position FROM pf_grocery_items WHERE list_id=? ORDER BY in_cart, position, id");
$s->execute([$list_id]);
echo json_encode(['items' => $s->fetchAll(PDO::FETCH_ASSOC)]); exit;
}
if ($method === 'POST') {
$label = trim($body['label'] ?? '');
if (!$list_id || !$label) { http_response_code(400); echo json_encode(['error' => 'missing fields']); exit; }
$norm = liste_normalize($label);
$dup = $pdo->prepare("SELECT COUNT(*) FROM pf_grocery_items WHERE list_id=? AND LOWER(TRIM(label))=?");
$dup->execute([$list_id, $norm]);
if ((int)$dup->fetchColumn() > 0) { echo json_encode(['duplicate' => true]); exit; }
$q = $pdo->prepare("SELECT COALESCE(MAX(position),0)+1 FROM pf_grocery_items WHERE list_id=?");
$q->execute([$list_id]);
$pos = (int)$q->fetchColumn();
$category_id = liste_detect_category($pdo, $label);
$pdo->prepare("INSERT INTO pf_grocery_items (list_id, category_id, label, in_cart, position) VALUES (?,?,?,0,?)")->execute([$list_id, $category_id, $label, $pos]);
$id = (int)$pdo->lastInsertId();
liste_touch_history($pdo, $label);
echo json_encode(['id' => $id, 'list_id' => $list_id, 'category_id' => $category_id, 'label' => $label, 'in_cart' => 0, 'position' => $pos]); exit;
}
if ($method === 'PUT') {
$id = (int)($_GET['id'] ?? 0);
if (!$id) { http_response_code(400); echo json_encode(['error' => 'id required']); exit; }
if (isset($body['in_cart'])) $pdo->prepare("UPDATE pf_grocery_items SET in_cart=? WHERE id=?")->execute([(int)$body['in_cart'], $id]);
if (isset($body['label'])) {
$label = trim($body['label']);
if ($label) {
$pdo->prepare("UPDATE pf_grocery_items SET label=? WHERE id=?")->execute([$label, $id]);
liste_touch_history($pdo, $label);
}
}
echo json_encode(['ok' => true]); exit;
}
if ($method === 'DELETE') {
$id = (int)($_GET['id'] ?? 0);
if (!$id) { http_response_code(400); echo json_encode(['error' => 'id required']); exit; }
$r = $pdo->prepare("SELECT label FROM pf_grocery_items WHERE id=?"); $r->execute([$id]);
if ($row = $r->fetch()) liste_touch_history($pdo, $row['label']);
$pdo->prepare("DELETE FROM pf_grocery_items WHERE id=?")->execute([$id]);
echo json_encode(['ok' => true]); exit;
}
}
// ── BULK ──────────────────────────────────────────────────────────────────────
if ($action === 'uncheck_all' && $method === 'POST') {
$lid = (int)($body['list_id'] ?? 0);
if ($lid) $pdo->prepare("UPDATE pf_grocery_items SET in_cart=0 WHERE list_id=?")->execute([$lid]);
echo json_encode(['ok' => true]); exit;
}
if ($action === 'delete_picked' && $method === 'POST') {
$lid = (int)($body['list_id'] ?? 0);
if ($lid) {
$rows = $pdo->prepare("SELECT label FROM pf_grocery_items WHERE list_id=? AND in_cart=1"); $rows->execute([$lid]);
foreach ($rows->fetchAll() as $r) liste_touch_history($pdo, $r['label']);
$pdo->prepare("DELETE FROM pf_grocery_items WHERE list_id=? AND in_cart=1")->execute([$lid]);
}
echo json_encode(['ok' => true]); exit;
}
if ($action === 'clear_all' && $method === 'POST') {
$lid = (int)($body['list_id'] ?? 0);
if ($lid) {
$rows = $pdo->prepare("SELECT label FROM pf_grocery_items WHERE list_id=?"); $rows->execute([$lid]);
foreach ($rows->fetchAll() as $r) liste_touch_history($pdo, $r['label']);
$pdo->prepare("DELETE FROM pf_grocery_items WHERE list_id=?")->execute([$lid]);
}
echo json_encode(['ok' => true]); exit;
}
// ── HISTORY ───────────────────────────────────────────────────────────────────
if ($action === 'history' && $method === 'GET') {
$max = 20;
$n = $pdo->prepare("SELECT content FROM pf_notes WHERE note_type='grocery_settings' AND reference_id='history_max'"); $n->execute();
if ($r = $n->fetch()) $max = max(1, min(50, (int)$r['content']));
$s = $pdo->query("SELECT label_display FROM pf_grocery_history ORDER BY last_used_at DESC LIMIT $max");
echo json_encode(['history' => $s->fetchAll(PDO::FETCH_COLUMN)]); exit;
}
http_response_code(400);
echo json_encode(['error' => 'unknown action: ' . $action]);
+73
View File
@@ -0,0 +1,73 @@
<?php
// Désactive l'affichage des erreurs HTML pour garantir un retour JSON strict
ini_set('display_errors', 0);
error_reporting(0);
require dirname(__DIR__, 4) . '/includes/auth.php';
require dirname(__DIR__, 4) . '/includes/db.php';
require dirname(__DIR__, 4) . '/includes/i18n.php';
require_login();
header('Content-Type: application/json; charset=utf-8');
try {
$dateParam = $_GET['date'] ?? date('Y-m-d');
$baseDate = new DateTime($dateParam);
// Aligner sur le lundi de la semaine
$monday = clone $baseDate;
if ($monday->format('N') != 1) {
$monday->modify('last monday');
}
$sunday = clone $monday;
$sunday->modify('+6 days');
$weekData = [
'week_label' => tr('meal_week') . ' ' . $monday->format('W'),
'days' => []
];
// Extraction des repas de la base (person_id = 0 pour le foyer global)
$stmt = $pdo->prepare("SELECT plan_date, service, meal_name FROM pf_meals_plan WHERE plan_date BETWEEN ? AND ? AND person_id = 0");
$stmt->execute([$monday->format('Y-m-d'), $sunday->format('Y-m-d')]);
$meals = [];
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$meals[$row['plan_date']][$row['service']] = $row['meal_name'];
}
$current = clone $monday;
// Mappage vers les clés i18n existantes de HouseHub
$daysMap = [
1 => 'day_mon', 2 => 'day_tue', 3 => 'day_wed',
4 => 'day_thu', 5 => 'day_fri', 6 => 'day_sat', 7 => 'day_sun'
];
for ($i = 0; $i < 7; $i++) {
$dStr = $current->format('Y-m-d');
$dayNum = $current->format('N'); // 1 à 7
$monthNum = $current->format('m'); // 01 à 12
$dayDate = $current->format('d'); // 01 à 31
$dayName = tr($daysMap[$dayNum]);
$monthName = tr('month_' . $monthNum);
$weekData['days'][] = [
'date' => $dStr,
'day_name' => $dayName,
'date_formatted' => $dayDate . ' ' . $monthName,
'lunch' => $meals[$dStr]['lunch'] ?? '',
'dinner' => $meals[$dStr]['dinner'] ?? ''
];
$current->modify('+1 day');
}
echo json_encode(['success' => true, 'data' => $weekData], JSON_UNESCAPED_UNICODE);
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
+277
View File
@@ -0,0 +1,277 @@
<?php
// modules/meals/includes/api/import-pdf.php
require dirname(__DIR__, 4) . '/includes/auth.php';
require dirname(__DIR__, 4) . '/includes/db.php';
require_login();
header('Content-Type: application/json; charset=utf-8');
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_FILES['pdf_file'])) {
echo json_encode(['success' => false, 'error' => 'Aucun fichier reçu.']);
exit;
}
$personId = (int)$_POST['person_id'];
if ($personId <= 0) {
echo json_encode(['success' => false, 'error' => 'Enfant non spécifié.']);
exit;
}
// ---------------------------------------------------------
// PARSEUR PDF SPATIAL NATIF (100% PHP SANS LIBRAIRIE)
// ---------------------------------------------------------
class NativePdfParser {
public static function getMealData($filename) {
$content = file_get_contents($filename);
$texts = [];
// 1. Décompression et Tokenization Mathématique
if (preg_match_all('/stream(.*?)endstream/is', $content, $matches)) {
foreach ($matches[1] as $stream) {
$stream = ltrim($stream, "\r\n");
$decoded = @gzuncompress($stream);
if (!$decoded) $decoded = $stream;
// On éclate le flux par opérateurs PDF clés (Position et Texte)
$parts = preg_split('/(Tm|Td|Tj|TJ)/', $decoded, -1, PREG_SPLIT_DELIM_CAPTURE);
$x = 0; $y = 0;
for ($i = 0; $i < count($parts); $i++) {
$token = $parts[$i];
if ($token === 'Tm' || $token === 'Td') {
$prev = $parts[$i-1];
preg_match_all('/[0-9.-]+/', $prev, $nums);
if (count($nums[0]) >= 2) {
$yRaw = array_pop($nums[0]);
$xRaw = array_pop($nums[0]);
if ($token === 'Tm') {
$x = (float)$xRaw; $y = (float)$yRaw;
} else {
$x += (float)$xRaw; $y += (float)$yRaw;
}
}
} elseif ($token === 'Tj') {
$prev = $parts[$i-1];
if (preg_match('/\((.*?)\)$/', trim($prev), $m)) {
self::addText($texts, $m[1], $x, $y);
}
} elseif ($token === 'TJ') {
$prev = $parts[$i-1];
if (preg_match('/\[(.*?)\]$/', trim($prev), $m)) {
preg_match_all('/\((.*?)\)/', $m[1], $tjs);
$tjX = $x;
foreach ($tjs[1] as $tj) {
self::addText($texts, $tj, $tjX, $y);
$tjX += 10; // Décalage estimé pour les mots suivants du tableau
}
}
}
}
}
}
if (empty($texts)) throw new Exception("Impossible de lire le contenu du PDF. Le fichier est peut-être crypté ou corrompu.");
// 2. Définition des Colonnes Verticles (X) via les En-têtes de Jour
$dayLabels = ['LUNDI', 'MARDI', 'MERCREDI', 'JEUDI', 'VENDREDI'];
$colXs = [];
foreach ($texts as $t) {
$clean = strtoupper(preg_replace('/[^A-Z]/', '', $t['text']));
if (in_array($clean, $dayLabels)) {
$colXs[$clean] = $t['x'];
}
}
// Sécurité si les jours exacts ne sont pas détectés à cause de la police
if (count($colXs) < 5) {
$allXs = array_column($texts, 'x');
sort($allXs);
$minX = $allXs[0] ?? 0;
$maxX = end($allXs) ?? 500;
$step = ($maxX - $minX) / 5;
$colXs = [
'LUNDI' => $minX + $step * 0.5,
'MARDI' => $minX + $step * 1.5,
'MERCREDI' => $minX + $step * 2.5,
'JEUDI' => $minX + $step * 3.5,
'VENDREDI' => $minX + $step * 4.5,
];
}
$sortedXs = array_values($colXs);
sort($sortedXs);
// 3. Définition des Tranches Horizontales (Y) via les Titres de Rangée (Zone Extrême Gauche)
$rowHeaders = [];
foreach ($texts as $t) {
$clean = strtoupper(preg_replace('/[^A-Z]/', '', $t['text']));
if (in_array($clean, ['HORSDEUVRE', 'DECLINAISON', 'PLATCHAUD', 'GARNITURE', 'PRODUITLAITIER', 'DESSERT', 'LESGOUTERS'])) {
// On s'assure de ne capter que la colonne tout à gauche
if ($t['x'] < ($sortedXs[0] - 20)) {
$rowHeaders[] = ['label' => $clean, 'y' => $t['y']];
}
}
}
// Tri de haut en bas (Y du PDF est décroissant du haut vers le bas)
usort($rowHeaders, fn($a, $b) => $b['y'] <=> $a['y']);
$yPlatTop = null; $yPlatBot = null;
$yGarTop = null; $yGarBot = null;
for ($i = 0; $i < count($rowHeaders); $i++) {
if ($rowHeaders[$i]['label'] === 'PLATCHAUD') {
$yPlatTop = $rowHeaders[$i]['y'];
// La limite basse est le label suivant, ou -50 unités
$yPlatBot = $rowHeaders[$i+1]['y'] ?? ($yPlatTop - 50);
}
if ($rowHeaders[$i]['label'] === 'GARNITURE') {
$yGarTop = $rowHeaders[$i]['y'];
$yGarBot = $rowHeaders[$i+1]['y'] ?? ($yGarTop - 50);
}
}
if (!$yPlatTop || !$yGarTop) {
throw new Exception("Structure du menu non reconnue (Mots-clés 'PLAT CHAUD' et 'GARNITURE' introuvables).");
}
// 4. Affectation Chirurgicale par Intersection Grille (X, Y)
$days = [[], [], [], [], []];
foreach ($texts as $t) {
$cleanAlpha = strtoupper(preg_replace('/[^A-Z]/', '', $t['text']));
// Rejet des labels génériques et de la fameuse ligne "Déclinaison"
if (in_array($cleanAlpha, ['DECLINAISON', 'MENUVEGETARIEN', 'PLATCHAUD', 'GARNITURE', 'PRODUITLAITIER', 'HORSDEUVRE', 'LESGOUTERS', 'DESSERT'])) continue;
// Retrait des labels BIO/HVE et mentions superflues
$textVal = trim(preg_replace('/\b(AB|HVE|MSC|Label Rouge)\b/i', '', $t['text']));
$textVal = str_replace(['(plat', 'complet)'], '', $textVal);
$textVal = trim(preg_replace('/[^a-zA-ZÀ-ÿ0-9\s&\-]/u', '', $textVal));
if (strlen($textVal) < 3) continue;
// Filtre Vertical : Est-on dans la tranche Plat Chaud ou Garniture ? (Tolérance +/- 5 unités)
$inPlat = ($t['y'] <= $yPlatTop + 5 && $t['y'] >= $yPlatBot + 5);
$inGar = ($t['y'] <= $yGarTop + 5 && $t['y'] >= $yGarBot + 5);
if ($inPlat || $inGar) {
// Filtre Horizontal : Quel est le jour le plus proche ?
$bestCol = 0;
$minDiff = PHP_FLOAT_MAX;
foreach ($sortedXs as $idx => $cx) {
$diff = abs($t['x'] - $cx);
if ($diff < $minDiff) {
$minDiff = $diff;
$bestCol = $idx;
}
}
$days[$bestCol][] = ['text' => $textVal, 'y' => $t['y'], 'type' => $inPlat ? 'plat' : 'gar'];
}
}
// 5. Concaténation Finale
$finalDays = [];
for ($i = 0; $i < 5; $i++) {
$plats = array_filter($days[$i], fn($item) => $item['type'] === 'plat');
$gars = array_filter($days[$i], fn($item) => $item['type'] === 'gar');
usort($plats, fn($a, $b) => $b['y'] <=> $a['y']);
usort($gars, fn($a, $b) => $b['y'] <=> $a['y']);
$platText = self::concatLines($plats);
$garText = self::concatLines($gars);
$full = trim("$platText + $garText", " +");
$finalDays[] = preg_replace('/\s+/', ' ', $full);
}
return $finalDays;
}
private static function concatLines($items) {
$lines = [];
$currentLine = "";
$lastY = null;
foreach ($items as $item) {
// Si le décalage Y est trop fort, on considère que c'est une nouvelle ligne
if ($lastY !== null && abs($lastY - $item['y']) > 8) {
if ($currentLine) $lines[] = trim($currentLine);
$currentLine = $item['text'];
} else {
$currentLine .= " " . $item['text'];
}
$lastY = $item['y'];
}
if ($currentLine) $lines[] = trim($currentLine);
return implode(' ', array_filter($lines, fn($l) => strlen(trim($l)) > 2));
}
private static function addText(&$texts, $rawText, $x, $y) {
// Décodage de l'octal \123
$m = preg_replace_callback('/\\\\([0-7]{1,3})/', function($cb) { return chr(octdec($cb[1])); }, $rawText);
// Détection de l'UTF-16BE (Le BOM \xFE\xFF indique que le texte est double encodé)
if (str_starts_with($m, "\xFE\xFF")) {
$m = mb_convert_encoding(substr($m, 2), 'UTF-8', 'UTF-16BE');
} else {
// Fallback Latin-1 si pas de BOM
$m = mb_convert_encoding($m, 'UTF-8', 'ISO-8859-1');
}
// Suppression radicale des octets nuls responsables de l'espacement forcé (E s c a l o p e)
$m = str_replace("\0", "", $m);
$m = trim(preg_replace('/[^\p{L}\p{N}\p{P}\p{Z}\+&\'’\-]/u', '', $m));
if ($m !== '') {
$texts[] = ['text' => $m, 'x' => $x, 'y' => $y];
}
}
}
try {
$filename = $_FILES['pdf_file']['name'];
// 1. Extraction robuste de la date depuis le nom de fichier (Menus-du-14-au-20-septembre-2026.pdf)
$mondayDate = null;
if (preg_match('/(\d{1,2})[\s-]+au[\s-]+\d{1,2}[\s-]+([a-zèéû]+)[\s-]+(\d{4})/i', $filename, $m)) {
$monthsMap = ['janvier'=>'01','fevrier'=>'02','février'=>'02','mars'=>'03','avril'=>'04','mai'=>'05','juin'=>'06','juillet'=>'07','aout'=>'08','août'=>'08','septembre'=>'09','octobre'=>'10','novembre'=>'11','decembre'=>'12','décembre'=>'12'];
$month = $monthsMap[strtolower($m[2])] ?? '09';
$mondayDate = $m[3] . '-' . $month . '-' . str_pad($m[1], 2, '0', STR_PAD_LEFT);
}
if (!$mondayDate) {
echo json_encode(['success' => false, 'error' => 'Veuillez nommer le fichier "Menus-du-14-au-20-septembre-2026.pdf".']);
exit;
}
// 2. Lancement de l'Analyse Spatiale
$plats = NativePdfParser::getMealData($_FILES['pdf_file']['tmp_name']);
if (empty($plats) || count($plats) !== 5) {
echo json_encode(['success' => false, 'error' => 'Erreur lors du découpage des 5 colonnes.']);
exit;
}
// 3. Insertion en BDD (Lundi au Vendredi)
$pdo->beginTransaction();
$stmt = $pdo->prepare("
INSERT INTO pf_meals_plan (plan_date, service, person_id, meal_name)
VALUES (?, 'lunch', ?, ?)
ON DUPLICATE KEY UPDATE meal_name = VALUES(meal_name)
");
$currentDate = new DateTime($mondayDate);
for ($i = 0; $i < 5; $i++) {
$fullMeal = $plats[$i];
if (!empty($fullMeal) && $fullMeal !== '+') {
$stmt->execute([$currentDate->format('Y-m-d'), $personId, $fullMeal]);
}
$currentDate->modify('+1 day');
}
$pdo->commit();
echo json_encode(['success' => true]);
} catch (Exception $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
+56
View File
@@ -0,0 +1,56 @@
<?php
require dirname(__DIR__, 4) . '/includes/auth.php';
require dirname(__DIR__, 4) . '/includes/db.php';
require_login();
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'error' => 'Méthode non autorisée']);
exit;
}
$action = $_POST['action'] ?? '';
try {
if ($action === 'save_cell') {
$date = $_POST['plan_date'];
$service = $_POST['service'];
$person_id = (int)$_POST['person_id'];
$meal_name = trim($_POST['meal_name']);
if (empty($meal_name)) {
$stmt = $pdo->prepare("DELETE FROM pf_meals_plan WHERE plan_date=? AND service=? AND person_id=?");
$stmt->execute([$date, $service, $person_id]);
} else {
$stmt = $pdo->prepare("INSERT INTO pf_meals_plan (plan_date, service, person_id, meal_name) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE meal_name = VALUES(meal_name)");
$stmt->execute([$date, $service, $person_id, $meal_name]);
}
echo json_encode(['success' => true]);
exit;
}
if ($action === 'save_bulk') {
$updates = json_decode($_POST['updates'], true);
if (is_array($updates)) {
$pdo->beginTransaction();
$stmtDel = $pdo->prepare("DELETE FROM pf_meals_plan WHERE plan_date=? AND service=? AND person_id=?");
$stmtIns = $pdo->prepare("INSERT INTO pf_meals_plan (plan_date, service, person_id, meal_name) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE meal_name = VALUES(meal_name)");
foreach ($updates as $u) {
if (empty(trim($u['meal_name']))) {
$stmtDel->execute([$u['plan_date'], $u['service'], $u['person_id']]);
} else {
$stmtIns->execute([$u['plan_date'], $u['service'], $u['person_id'], trim($u['meal_name'])]);
}
}
$pdo->commit();
}
echo json_encode(['success' => true]);
exit;
}
} catch (Exception $e) {
if ($pdo->inTransaction()) $pdo->rollBack();
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}
+567
View File
@@ -0,0 +1,567 @@
<?php
// modules/food/views/liste.php
if (!isset($pdo)) { exit; }
?>
<div class="liste-main">
<!-- Tabs des listes -->
<div class="liste-tabs-bar">
<div class="liste-tabs" id="liste-tabs"></div>
<button class="liste-tab-add" id="btn-add-list" title="<?= htmlspecialchars(tr('liste_new_list')) ?>">+</button>
</div>
<!-- Corps de la liste active -->
<div class="liste-body" id="liste-body">
<div class="liste-add-card">
<input type="text" id="liste-input" maxlength="500" placeholder="<?= htmlspecialchars(tr('liste_placeholder_add')) ?>" autocomplete="off">
<button id="btn-liste-add"><?= htmlspecialchars(tr('liste_btn_add')) ?></button>
</div>
<div class="liste-toolbar" id="liste-toolbar">
<button class="btn-tool" id="btn-uncheck-all"><?= htmlspecialchars(tr('liste_btn_uncheck_all')) ?></button>
<button class="btn-tool btn-tool-danger" id="btn-delete-picked"><?= htmlspecialchars(tr('liste_btn_delete_picked')) ?></button>
<button class="btn-tool btn-tool-danger" id="btn-clear-all"><?= htmlspecialchars(tr('liste_btn_clear_all')) ?></button>
</div>
<div id="liste-items-root"></div>
<div id="liste-history-root"></div>
</div>
</div>
<script>
const LISTE_TRANSLATIONS = {
already_in: <?= json_encode(tr('liste_already_in')) ?>,
confirm_clear: <?= json_encode(tr('liste_confirm_clear')) ?>,
confirm_delete_list: <?= json_encode(tr('liste_confirm_delete_list')) ?>,
rename_list: <?= json_encode(tr('liste_rename_list')) ?>,
new_name: <?= json_encode(tr('liste_new_name')) ?>,
list_deleted: <?= json_encode(tr('liste_list_deleted')) ?>,
list_created: <?= json_encode(tr('liste_list_created')) ?>,
list_renamed: <?= json_encode(tr('liste_list_renamed')) ?>,
edit_placeholder: <?= json_encode(tr('liste_edit_placeholder')) ?>,
history_title: <?= json_encode(tr('liste_history_title')) ?>,
added: <?= json_encode(tr('liste_added')) ?>,
updated: <?= json_encode(tr('liste_updated')) ?>,
deleted: <?= json_encode(tr('liste_deleted')) ?>,
cancel: <?= json_encode(tr('cancel')) ?>,
};
// ⚠️ NOUVEAU CHEMIN D'API
const API = '/modules/food/includes/api/api-liste.php';
const T = window.LISTE_TRANSLATIONS || {};
const state = {
lists: [],
currentListId: null,
items: [],
history: [],
categories: [],
catMap: {},
};
// ── Constants ──────────────────────────────────────────────────────────────────
const LIST_COLORS = [
{ id: 'none', hex: null },
{ id: 'blue', hex: '#3b82f6' },
{ id: 'red', hex: '#ef4444' },
{ id: 'amber', hex: '#f59e0b' },
{ id: 'purple', hex: '#8b5cf6' },
{ id: 'pink', hex: '#ec4899' },
{ id: 'emerald', hex: '#10b981' },
{ id: 'orange', hex: '#f97316' },
{ id: 'cyan', hex: '#06b6d4' },
{ id: 'indigo', hex: '#6366f1' },
{ id: 'teal', hex: '#14b8a6' },
{ id: 'gray', hex: '#6b7280' },
];
const LIST_TYPES = [
{ value: '', label: '— Aucun —', emoji: '' },
{ value: 'courses', label: 'Courses', emoji: '🛒' },
{ value: 'todo', label: 'To-do', emoji: '✅' },
{ value: 'voyage', label: 'Voyage', emoji: '✈️' },
{ value: 'travail', label: 'Travail', emoji: '💼' },
{ value: 'maison', label: 'Maison', emoji: '🏠' },
{ value: 'sante', label: 'Santé', emoji: '💊' },
{ value: 'loisirs', label: 'Loisirs', emoji: '🎮' },
{ value: 'autre', label: 'Autre', emoji: '📋' },
];
// ── Utilities ──────────────────────────────────────────────────────────────────
function esc(s) {
return String(s ?? '').replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
function toast(msg, type = 'info') {
let c = document.getElementById('liste-toast-container');
if (!c) {
c = document.createElement('div');
c.id = 'liste-toast-container';
c.className = 'liste-toast-container';
document.body.appendChild(c);
}
const t = document.createElement('div');
t.className = `liste-toast liste-toast-${type}`;
t.textContent = msg;
c.appendChild(t);
setTimeout(() => t.classList.add('show'), 10);
setTimeout(() => { t.classList.remove('show'); setTimeout(() => t.remove(), 300); }, 2500);
}
async function api(action, method = 'GET', body = null, params = {}) {
const url = new URL(API, location.origin);
url.searchParams.set('action', action);
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
const opts = { method, headers: { 'Content-Type': 'application/json' } };
if (body) opts.body = JSON.stringify(body);
const r = await fetch(url, opts);
return r.json();
}
// ── List modal ─────────────────────────────────────────────────────────────────
let activeModal = null;
function openListModal(listId = null) {
if (activeModal) { activeModal.remove(); activeModal = null; }
const list = listId ? state.lists.find(l => l.id === listId) : null;
const isNew = !listId;
const backdrop = document.createElement('div');
backdrop.className = 'liste-modal-backdrop';
backdrop.innerHTML = `
<div class="liste-modal" role="dialog" aria-modal="true">
<div class="liste-modal-header">
<h3>${isNew ? 'Nouvelle liste' : 'Modifier la liste'}</h3>
<button class="liste-modal-close" aria-label="Fermer">×</button>
</div>
<div class="liste-modal-body">
<div class="liste-form-group">
<label class="liste-form-label">Nom</label>
<input class="liste-modal-name" type="text" maxlength="100"
value="${esc(list?.name ?? '')}" placeholder="Ma liste…" autocomplete="off">
</div>
<div class="liste-form-group">
<label class="liste-form-label">Couleur</label>
<div class="liste-color-picker">
${LIST_COLORS.map(c => {
const isActive = (c.hex === null && !list?.color) || (list?.color === c.hex);
const cls = 'liste-color-swatch' + (c.hex === null ? ' liste-color-swatch-none' : '') + (isActive ? ' active' : '');
const style = c.hex ? `style="--swatch:${c.hex}"` : '';
return `<button class="${cls}" data-color="${c.hex ?? ''}" ${style} title="${c.id}"></button>`;
}).join('')}
</div>
</div>
<div class="liste-form-group">
<label class="liste-form-label">Type de liste</label>
<select class="liste-modal-type">
${LIST_TYPES.map(t =>
`<option value="${esc(t.value)}" ${list?.list_type === t.value ? 'selected' : ''}>${t.emoji ? t.emoji + ' ' : ''}${esc(t.label)}</option>`
).join('')}
</select>
</div>
</div>
<div class="liste-modal-footer">
${!isNew && state.lists.length > 1
? `<button class="btn-tool btn-tool-danger liste-modal-delete">Supprimer</button>`
: ''}
<button class="btn-tool liste-modal-cancel">Annuler</button>
<button class="btn-tool btn-tool-primary liste-modal-save">Enregistrer</button>
</div>
</div>`;
document.body.appendChild(backdrop);
activeModal = backdrop;
const nameInput = backdrop.querySelector('.liste-modal-name');
nameInput.focus();
nameInput.setSelectionRange(nameInput.value.length, nameInput.value.length);
// Color swatches
backdrop.querySelectorAll('.liste-color-swatch').forEach(btn => {
btn.addEventListener('click', () => {
backdrop.querySelectorAll('.liste-color-swatch').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
});
});
const close = () => { backdrop.remove(); activeModal = null; };
backdrop.querySelector('.liste-modal-close').addEventListener('click', close);
backdrop.querySelector('.liste-modal-cancel').addEventListener('click', close);
backdrop.addEventListener('click', e => { if (e.target === backdrop) close(); });
backdrop.querySelector('.liste-modal-delete')?.addEventListener('click', () => { close(); deleteList(listId); });
backdrop.querySelector('.liste-modal-save').addEventListener('click', () => saveListModal(backdrop, listId));
nameInput.addEventListener('keydown', e => {
if (e.key === 'Enter') saveListModal(backdrop, listId);
if (e.key === 'Escape') close();
});
}
async function saveListModal(backdrop, listId) {
const name = backdrop.querySelector('.liste-modal-name').value.trim();
if (!name) { backdrop.querySelector('.liste-modal-name').focus(); return; }
const activeSwatch = backdrop.querySelector('.liste-color-swatch.active');
const color = activeSwatch?.dataset.color || null;
const list_type = backdrop.querySelector('.liste-modal-type').value || null;
if (listId) {
const r = await api('lists', 'PUT', { name, color, list_type }, { id: listId });
if (r.ok) {
const list = state.lists.find(l => l.id === listId);
if (list) { list.name = name; list.color = color; list.list_type = list_type; }
backdrop.remove(); activeModal = null;
renderTabs();
toast('Liste mise à jour');
}
} else {
const r = await api('lists', 'POST', { name, color, list_type });
if (r.id) {
state.lists.push({ id: r.id, name, color: r.color, list_type: r.list_type, position: r.position });
state.currentListId = r.id;
backdrop.remove(); activeModal = null;
await loadItems();
renderTabs();
toast('Liste créée : ' + name);
}
}
}
// ── Categories ─────────────────────────────────────────────────────────────────
async function loadCategories() {
if (state.categories.length) return;
const r = await api('categories');
state.categories = r.categories || [];
state.catMap = {};
state.categories.forEach(c => { state.catMap[c.id] = c; });
}
let activePicker = null;
function openCategoryPicker(itemId, anchorEl) {
closeCategoryPicker();
const item = state.items.find(i => i.id === itemId);
if (!item) return;
const picker = document.createElement('div');
picker.className = 'liste-cat-picker';
picker.innerHTML = `
<div class="liste-cat-picker-title">Catégorie</div>
<div class="liste-cat-picker-list">
<button class="liste-cat-picker-item${!item.category_id ? ' active' : ''}" data-cat="0">🏷️ Non classé</button>
${state.categories.map(c =>
`<button class="liste-cat-picker-item${item.category_id == c.id ? ' active' : ''}" data-cat="${c.id}">${esc(c.icon)} ${esc(c.name)}</button>`
).join('')}
</div>`;
const rect = anchorEl.getBoundingClientRect();
let top = rect.bottom + 4;
let left = rect.left;
if (left + 220 > window.innerWidth) left = window.innerWidth - 228;
if (top + 340 > window.innerHeight) top = rect.top - Math.min(340, top + 340 - window.innerHeight) - 4;
picker.style.top = top + 'px';
picker.style.left = left + 'px';
document.body.appendChild(picker);
activePicker = picker;
picker.querySelectorAll('.liste-cat-picker-item').forEach(btn => {
btn.addEventListener('click', async e => {
e.stopPropagation();
const catId = parseInt(btn.dataset.cat) || null;
await api('set_category', 'POST', { item_id: itemId, category_id: catId });
const it = state.items.find(i => i.id === itemId);
if (it) it.category_id = catId;
closeCategoryPicker();
renderItems();
});
});
setTimeout(() => {
document.addEventListener('click', closeCategoryPicker, { once: true });
}, 0);
}
function closeCategoryPicker() {
if (activePicker) { activePicker.remove(); activePicker = null; }
}
// ── Tabs ───────────────────────────────────────────────────────────────────────
function typeEmoji(list_type) {
return LIST_TYPES.find(t => t.value === list_type)?.emoji || '';
}
function renderTabs() {
const container = document.getElementById('liste-tabs');
if (!container) return;
container.innerHTML = '';
state.lists.forEach(list => {
const isActive = list.id === state.currentListId;
const tab = document.createElement('div');
tab.className = 'liste-tab' + (isActive ? ' active' : '');
tab.dataset.id = list.id;
// Apply custom color to entire tab
if (list.color) {
if (isActive) {
tab.style.cssText = `background:${list.color};border-color:${list.color};color:#fff`;
} else {
tab.style.cssText = `border-color:${list.color};color:${list.color}`;
}
}
const emoji = typeEmoji(list.list_type);
const prefix = emoji ? `<span class="liste-tab-type">${emoji}</span>` : '';
if (isActive) {
tab.innerHTML = `
${prefix}
<span class="liste-tab-name">${esc(list.name)}</span>
<button class="liste-tab-btn liste-tab-edit" title="Modifier" data-id="${list.id}">✏</button>
`;
} else {
tab.innerHTML = `${prefix}<span class="liste-tab-name">${esc(list.name)}</span>`;
tab.addEventListener('click', () => switchList(list.id));
}
container.appendChild(tab);
});
container.querySelectorAll('.liste-tab-edit').forEach(btn => {
btn.addEventListener('click', e => { e.stopPropagation(); openListModal(parseInt(btn.dataset.id)); });
});
}
// ── List management ─────────────────────────────────────────────────────────────
document.getElementById('btn-add-list')?.addEventListener('click', () => openListModal(null));
async function deleteList(listId) {
if (!confirm(T.confirm_delete_list || 'Supprimer cette liste et tous ses articles ?')) return;
const r = await api('lists', 'DELETE', null, { id: listId });
if (r.error) { toast(r.error, 'error'); return; }
state.lists = state.lists.filter(l => l.id !== listId);
if (state.currentListId === listId) {
state.currentListId = state.lists[0]?.id ?? null;
}
await loadItems();
renderTabs();
toast(T.list_deleted || 'Liste supprimée');
}
// ── Switch list ─────────────────────────────────────────────────────────────────
async function switchList(listId) {
state.currentListId = listId;
await loadItems();
renderTabs();
}
// ── Items ───────────────────────────────────────────────────────────────────────
async function loadItems() {
if (!state.currentListId) { renderItems(); return; }
const r = await api('items', 'GET', null, { list_id: state.currentListId });
state.items = r.items || [];
renderItems();
}
function renderItems() {
const root = document.getElementById('liste-items-root');
if (!root) return;
const toolbar = document.getElementById('liste-toolbar');
if (!state.currentListId || state.items.length === 0) {
root.innerHTML = state.currentListId
? `<div class="liste-empty-items"><span>📝</span><p>Liste vide — ajoutez un article ci-dessus.</p></div>`
: '';
if (toolbar) toolbar.style.display = 'none';
return;
}
if (toolbar) toolbar.style.display = '';
const pending = state.items.filter(i => !i.in_cart);
const inCart = state.items.filter(i => i.in_cart);
const hasCategories = pending.some(i => i.category_id);
let html = '';
if (hasCategories && state.categories.length) {
const groups = new Map();
pending.forEach(item => {
const key = item.category_id ?? 0;
if (!groups.has(key)) groups.set(key, []);
groups.get(key).push(item);
});
const catIds = state.categories.map(c => parseInt(c.id));
const orderedKeys = catIds.filter(id => groups.has(id));
if (groups.has(0)) orderedKeys.push(0);
orderedKeys.forEach(key => {
const items = groups.get(key);
const cat = key ? state.catMap[key] : null;
const label = cat ? `${cat.icon} ${cat.name}` : '🏷️ Non classé';
html += `<div class="liste-cat-section-header">${esc(label)} <span class="liste-cat-section-count">${items.length}</span></div>`;
html += items.map(rowHtml).join('');
});
} else {
html = pending.map(rowHtml).join('');
}
if (inCart.length) {
html += `<div class="liste-cart-divider">Dans le panier (${inCart.length})</div>` + inCart.map(rowHtml).join('');
}
root.innerHTML = html;
root.querySelectorAll('.liste-check').forEach(cb => {
cb.addEventListener('change', () => toggleCart(parseInt(cb.dataset.id), cb.checked ? 1 : 0));
});
root.querySelectorAll('.btn-edit-item').forEach(btn => {
btn.addEventListener('click', () => editItem(parseInt(btn.dataset.id)));
});
root.querySelectorAll('.btn-delete-item').forEach(btn => {
btn.addEventListener('click', () => deleteItem(parseInt(btn.dataset.id)));
});
root.querySelectorAll('.liste-cat-badge').forEach(btn => {
btn.addEventListener('click', e => { e.stopPropagation(); openCategoryPicker(parseInt(btn.dataset.id), btn); });
});
}
function rowHtml(item) {
const checked = item.in_cart ? 'checked' : '';
const cls = item.in_cart ? 'liste-row in-cart' : 'liste-row';
const cat = item.category_id ? state.catMap[item.category_id] : null;
const badgeCls = 'liste-cat-badge' + (cat ? '' : ' liste-cat-badge-empty');
const badgeIcon = cat ? esc(cat.icon) : '🏷️';
const badgeTip = cat ? esc(cat.name) : 'Non classé';
return `<div class="${cls}" data-id="${item.id}">
<button class="${badgeCls}" data-id="${item.id}" title="${badgeTip}">${badgeIcon}</button>
<label class="liste-check-label">
<input type="checkbox" class="liste-check" data-id="${item.id}" ${checked}>
<span class="liste-label">${esc(item.label)}</span>
</label>
<div class="liste-row-actions">
<button class="btn-edit-item" data-id="${item.id}" title="Modifier">✏</button>
<button class="btn-delete-item" data-id="${item.id}" title="Supprimer">🗑</button>
</div>
</div>`;
}
async function addItem(label) {
const r = await api('items', 'POST', { list_id: state.currentListId, label });
if (r.duplicate) { toast(T.already_in || 'Déjà dans la liste', 'warn'); return; }
if (r.id) {
state.items.push(r);
renderItems();
renderHistory();
toast(T.added || 'Ajouté');
}
}
async function toggleCart(id, next) {
await api('items', 'PUT', { in_cart: next }, { id });
const item = state.items.find(i => i.id === id);
if (item) item.in_cart = next;
renderItems();
}
async function editItem(id) {
const item = state.items.find(i => i.id === id);
if (!item) return;
const newLabel = prompt(T.edit_placeholder || 'Modifier :', item.label);
if (newLabel === null || newLabel.trim() === '') return;
await api('items', 'PUT', { label: newLabel.trim() }, { id });
item.label = newLabel.trim();
renderItems();
toast(T.updated || 'Modifié');
}
async function deleteItem(id) {
await api('items', 'DELETE', null, { id });
state.items = state.items.filter(i => i.id !== id);
renderItems();
toast(T.deleted || 'Supprimé');
}
// ── Toolbar ────────────────────────────────────────────────────────────────────
document.getElementById('btn-uncheck-all')?.addEventListener('click', async () => {
if (!state.currentListId) return;
await api('uncheck_all', 'POST', { list_id: state.currentListId });
state.items.forEach(i => i.in_cart = 0);
renderItems();
});
document.getElementById('btn-delete-picked')?.addEventListener('click', async () => {
if (!state.currentListId) return;
await api('delete_picked', 'POST', { list_id: state.currentListId });
state.items = state.items.filter(i => !i.in_cart);
renderItems();
toast(T.deleted || 'Supprimés');
});
document.getElementById('btn-clear-all')?.addEventListener('click', async () => {
if (!confirm(T.confirm_clear || 'Vider toute la liste ?')) return;
await api('clear_all', 'POST', { list_id: state.currentListId });
state.items = [];
renderItems();
toast(T.deleted || 'Liste vidée');
});
// ── Add input ───────────────────────────────────────────────────────────────────
document.getElementById('btn-liste-add')?.addEventListener('click', () => {
const input = document.getElementById('liste-input');
const v = input?.value.trim();
if (v) { addItem(v); input.value = ''; input.focus(); }
});
document.getElementById('liste-input')?.addEventListener('keydown', e => {
if (e.key === 'Enter') document.getElementById('btn-liste-add')?.click();
});
// ── History ────────────────────────────────────────────────────────────────────
async function loadHistory() {
const r = await api('history');
state.history = r.history || [];
renderHistory();
}
function renderHistory() {
const root = document.getElementById('liste-history-root');
if (!root || !state.history.length) { if (root) root.innerHTML = ''; return; }
const currentLabels = new Set(state.items.map(i => i.label.toLowerCase().trim()));
const suggestions = state.history.filter(h => !currentLabels.has(h.toLowerCase().trim()));
if (!suggestions.length) { root.innerHTML = ''; return; }
root.innerHTML = `
<div class="liste-history-card">
<div class="liste-history-title">${T.history_title || 'Récemment utilisés'}</div>
<div class="liste-history-chips">
${suggestions.map(h => `<button class="liste-chip" data-label="${esc(h)}">${esc(h)}</button>`).join('')}
</div>
</div>`;
root.querySelectorAll('.liste-chip').forEach(btn => {
btn.addEventListener('click', () => {
if (state.currentListId) addItem(btn.dataset.label);
});
});
}
// ── Init ────────────────────────────────────────────────────────────────────────
async function init() {
const [listsR] = await Promise.all([api('lists'), loadCategories()]);
state.lists = listsR.lists || [];
state.currentListId = listsR.default_id || state.lists[0]?.id || null;
renderTabs();
await Promise.all([loadItems(), loadHistory()]);
}
init();
</script>
+357
View File
@@ -0,0 +1,357 @@
<?php
// modules/meals/main.php
// Récupération stricte des membres du foyer (Exclusion des intervenants et proches)
$stmt = $pdo->query("SELECT id, name FROM pf_people WHERE role NOT IN ('helper', 'nounou', 'proche_adulte', 'proche_enfant', 'relative') AND is_active = 1 ORDER BY id ASC");
$members = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($members)) {
echo "<div class='pf-alert pf-alert--warning'>" . tr('meals_no_members') . "</div>";
return;
}
// Calcul des 14 jours (Lundi semaine courante -> Dimanche semaine prochaine)
$start_date = new DateTime();
$start_date->modify('monday this week');
$dates = [];
for ($i = 0; $i < 14; $i++) {
$d = clone $start_date;
$d->modify("+$i days");
$dates[] = $d->format('Y-m-d');
}
$stmtMeals = $pdo->prepare("SELECT plan_date, service, person_id, meal_name FROM pf_meals_plan WHERE plan_date BETWEEN ? AND ?");
$stmtMeals->execute([$dates[0], end($dates)]);
$mealsData = [];
while ($row = $stmtMeals->fetch(PDO::FETCH_ASSOC)) {
$mealsData[$row['plan_date']][$row['service']][$row['person_id']] = $row['meal_name'];
}
?>
<div class="pf-container meals-container">
<div class="meals-header-bar">
<h1 class="meals-title">
<span class="meals-title-icon">🍽️</span>
<span data-i18n="meals_board_title"><?= tr('meals_board_title') ?></span>
</h1>
<div class="meals-actions">
<!-- NOUVEAU : Bouton Import PDF -->
<button type="button" class="pf-btn btn-secondary" onclick="document.getElementById('importMenuModal').classList.add('open'); document.body.classList.add('no-scroll');">
📄 <?= tr('meal_btn_import_pdf') ?>
</button>
</div>
</div>
<!-- Barre contextuelle (Fixe en bas) -->
<div class="context-toolbar" id="contextToolbar">
<button class="ctx-btn" onmousedown="event.preventDefault(); applyToAllInRow()">➡️ <span data-i18n="btn_apply_all"><?= tr('btn_apply_all') ?></span></button>
<button class="ctx-btn primary" onmousedown="event.preventDefault(); openCopySheetFromCell()">🔄 <span data-i18n="btn_copy_to"><?= tr('btn_copy_to') ?></span></button>
</div>
<div class="meals-wrapper">
<?php
$weeks = array_chunk($dates, 7);
foreach ($weeks as $weekIndex => $weekDates):
$startWeekStr = date('d/m', strtotime($weekDates[0]));
$endWeekStr = date('d/m', strtotime(end($weekDates)));
?>
<h2 class="meals-week-title"><?= tr('meal_week') ?> (<?= $startWeekStr ?> - <?= $endWeekStr ?>)</h2>
<div class="meals-table-container">
<table class="meals-table" id="mealsTable_<?= $weekIndex ?>">
<thead>
<tr>
<th class="col-sticky"></th>
<?php foreach ($members as $m): ?>
<th><?= htmlspecialchars(strtoupper($m['name'])) ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($weekDates as $dateStr):
$dayKey = strtolower(date('D', strtotime($dateStr)));
$dayName = tr('day_' . $dayKey);
$dayDate = date('d/m', strtotime($dateStr));
$fullDayName = tr('day_full_' . $dayKey) . ' ' . $dayDate;
?>
<tr class="row-lunch">
<td class="col-sticky">
<span class="day-label"><?= $dayName ?> <?= $dayDate ?></span>
<div class="service-icon" onmousedown="event.preventDefault(); openCopySheetFromRow('<?= $dateStr ?>', 'lunch', '<?= addslashes($fullDayName) ?>')" title="<?= tr('meals_copy_lunch') ?>">☀️</div>
</td>
<?php foreach ($members as $m):
$val = $mealsData[$dateStr]['lunch'][$m['id']] ?? '';
?>
<td class="meal-input-cell">
<textarea class="meal-input js-meal-input" data-d="<?= $dateStr ?>" data-s="lunch" data-p="<?= $m['id'] ?>" placeholder="-"><?= htmlspecialchars($val) ?></textarea>
</td>
<?php endforeach; ?>
</tr>
<tr class="row-dinner">
<td class="col-sticky">
<span class="day-label invisible"><?= $dayName ?> <?= $dayDate ?></span>
<div class="service-icon" onmousedown="event.preventDefault(); openCopySheetFromRow('<?= $dateStr ?>', 'dinner', '<?= addslashes($fullDayName) ?>')" title="<?= tr('meals_copy_dinner') ?>">🌙</div>
</td>
<?php foreach ($members as $m):
$val = $mealsData[$dateStr]['dinner'][$m['id']] ?? '';
?>
<td class="meal-input-cell">
<textarea class="meal-input js-meal-input" data-d="<?= $dateStr ?>" data-s="dinner" data-p="<?= $m['id'] ?>" placeholder="-"><?= htmlspecialchars($val) ?></textarea>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endforeach; ?>
</div>
</div>
<!-- Bottom Sheet de Copie (Format Grille Ultra-compacte) -->
<div id="copyModal" class="pf-modal pf-bottom-sheet">
<div class="pf-modal-content pf-bs-content copy-modal-large">
<div class="bs-header">
<h3 class="bs-title">🔄 <span data-i18n="modal_copy_title"><?= tr('modal_copy_title') ?></span></h3>
<button class="bs-close" onclick="closeCopyModal()">&times;</button>
</div>
<div id="copySourceLabel" class="meals-copy-source">Source : ...</div>
<div class="week-section-title" data-i18n="week_current"><?= tr('week_current') ?></div>
<div class="copy-days-grid">
<?php for($i=0; $i<7; $i++): $dStr = $dates[$i]; $dName = tr('day_full_' . strtolower(date('D', strtotime($dStr)))) . ' ' . date('d/m', strtotime($dStr)); ?>
<div class="copy-day-card">
<div class="copy-day-name"><?= $dName ?></div>
<div class="copy-day-actions">
<button type="button" class="btn-target-service" onmousedown="event.preventDefault(); executeCopy('<?= $dStr ?>', 'lunch')" title="<?= tr('meal_lunch') ?>">☀️</button>
<button type="button" class="btn-target-service" onmousedown="event.preventDefault(); executeCopy('<?= $dStr ?>', 'dinner')" title="<?= tr('meal_dinner') ?>">🌙</button>
</div>
</div>
<?php endfor; ?>
</div>
<div class="week-section-title week-section-mt" data-i18n="week_next"><?= tr('week_next') ?></div>
<div class="copy-days-grid">
<?php for($i=7; $i<14; $i++): $dStr = $dates[$i]; $dName = tr('day_full_' . strtolower(date('D', strtotime($dStr)))) . ' ' . date('d/m', strtotime($dStr)); ?>
<div class="copy-day-card">
<div class="copy-day-name"><?= $dName ?></div>
<div class="copy-day-actions">
<button type="button" class="btn-target-service" onmousedown="event.preventDefault(); executeCopy('<?= $dStr ?>', 'lunch')" title="<?= tr('meal_lunch') ?>">☀️</button>
<button type="button" class="btn-target-service" onmousedown="event.preventDefault(); executeCopy('<?= $dStr ?>', 'dinner')" title="<?= tr('meal_dinner') ?>">🌙</button>
</div>
</div>
<?php endfor; ?>
</div>
</div>
</div>
<!-- NOUVEAU : Modale d'import PDF Cantine -->
<div id="importMenuModal" class="pf-modal">
<div class="pf-modal-content">
<div class="pf-modal-header" style="display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-light); padding-bottom: 15px; margin-bottom: 20px;">
<h3 class="pf-modal-title" style="margin: 0; border: none; padding: 0;">📄 <?= tr('meal_import_title') ?></h3>
<button type="button" class="pf-modal-close" style="background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted);" onclick="document.getElementById('importMenuModal').classList.remove('open'); document.body.classList.remove('no-scroll');">&times;</button>
</div>
<form id="importMenuForm" onsubmit="importPdfMenu(event)" action="/modules/food/includes/api/import-pdf.php" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token()) ?>">
<div class="pf-form-group">
<label class="pf-label"><?= tr('meal_import_child') ?></label>
<select name="person_id" class="pf-input" required>
<option value="" disabled selected>-- <?= tr('meal_select_child') ?> --</option>
<?php foreach ($members as $m): ?>
<option value="<?= $m['id'] ?>"><?= htmlspecialchars($m['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="pf-form-group">
<label class="pf-label"><?= tr('meal_pdf_file') ?></label>
<div class="meal-dropzone" onclick="document.getElementById('canteenPdf').click()">
<span class="meal-dropzone-icon">📥</span>
<span id="pdfFileName"><?= tr('meal_drop_pdf') ?></span>
<input type="file" id="canteenPdf" name="pdf_file" accept=".pdf" style="display: none;" required onchange="document.getElementById('pdfFileName').innerText = this.files[0] ? this.files[0].name : '<?= addslashes(tr('meal_drop_pdf')) ?>';">
</div>
</div>
<div class="modal-footer">
<button type="button" class="pf-btn btn-secondary" onclick="document.getElementById('importMenuModal').classList.remove('open'); document.body.classList.remove('no-scroll');"><?= tr('btn_cancel') ?></button>
<button type="submit" class="pf-btn" id="btnImportPdf"><?= tr('btn_import') ?></button>
</div>
</form>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Sauvegarde automatique AJAX à chaque modification
document.querySelectorAll('.js-meal-input').forEach(input => {
input.addEventListener('change', async function() {
const fd = new FormData();
fd.append('action', 'save_cell');
fd.append('plan_date', this.dataset.d);
fd.append('service', this.dataset.s);
fd.append('person_id', this.dataset.p);
fd.append('meal_name', this.value);
try {
await pachaFetch('/modules/food/includes/api/save-meals.php', { method: 'POST', body: fd });
flashSuccess(this);
} catch(e) {
console.error("Save error", e);
}
});
});
});
// Focus Context Bar
let copyState = { type: null, sourceDate: null, service: null, personIdx: null, sourceElements: [], fullDayName: '' };
document.addEventListener('focusin', (e) => {
if(e.target.classList.contains('js-meal-input')) {
copyState = {
type: 'cell',
sourceDate: e.target.getAttribute('data-d'),
service: e.target.getAttribute('data-s'),
personIdx: e.target.getAttribute('data-p'),
sourceElements: [e.target],
fullDayName: ''
};
document.getElementById('contextToolbar').classList.add('active');
}
});
document.addEventListener('focusout', (e) => {
setTimeout(() => {
if(document.activeElement && !document.activeElement.classList.contains('js-meal-input')) {
document.getElementById('contextToolbar').classList.remove('active');
}
}, 150);
});
// Actions Toolbar
window.applyToAllInRow = async function() {
if(copyState.type !== 'cell' || !copyState.sourceElements[0].value.trim()) return;
const val = copyState.sourceElements[0].value;
const inputs = document.querySelectorAll(`.js-meal-input[data-d="${copyState.sourceDate}"][data-s="${copyState.service}"]`);
let updates = [];
inputs.forEach(inp => {
if(inp !== copyState.sourceElements[0]) {
inp.value = val;
flashSuccess(inp);
updates.push({ plan_date: inp.dataset.d, service: inp.dataset.s, person_id: inp.dataset.p, meal_name: val });
}
});
if (updates.length > 0) {
const fd = new FormData();
fd.append('action', 'save_bulk');
fd.append('updates', JSON.stringify(updates));
await pachaFetch('/modules/food/includes/api/save-meals.php', { method: 'POST', body: fd });
}
};
window.openCopySheetFromCell = function() {
if(!copyState.sourceElements[0] || !copyState.sourceElements[0].value.trim()) return;
if(document.activeElement) document.activeElement.blur();
const svcLabel = copyState.service === 'lunch' ? (window.I18N['meal_lunch'] || 'Midi') : (window.I18N['meal_dinner'] || 'Soir');
const dObj = new Date(copyState.sourceDate);
const dayKey = dObj.toLocaleDateString('en-US', {weekday: 'short'}).toLowerCase();
const dayName = window.I18N['day_full_' + dayKey] || dObj.toLocaleDateString();
document.getElementById('copySourceLabel').innerText = `Source : ${window.I18N['source_individual'] || 'Individuel'} (${dayName} ${svcLabel})`;
document.getElementById('copyModal').classList.add('open');
document.body.classList.add('no-scroll');
};
window.openCopySheetFromRow = function(dateStr, service, fullDayName) {
const inputs = document.querySelectorAll(`.js-meal-input[data-d="${dateStr}"][data-s="${service}"]`);
if (!Array.from(inputs).some(inp => inp.value.trim() !== '')) return;
copyState = { type: 'row', sourceDate: dateStr, service: service, sourceElements: Array.from(inputs), fullDayName: fullDayName };
const svcLabel = service === 'lunch' ? (window.I18N['meal_lunch'] || 'Midi') : (window.I18N['meal_dinner'] || 'Soir');
document.getElementById('copySourceLabel').innerText = `Source : ${window.I18N['source_row'] || 'Repas commun'} (${fullDayName} ${svcLabel})`;
document.getElementById('copyModal').classList.add('open');
document.body.classList.add('no-scroll');
};
window.closeCopyModal = function() {
document.getElementById('copyModal').classList.remove('open');
document.body.classList.remove('no-scroll');
};
window.executeCopy = async function(targetDate, targetService) {
let updates = [];
if(copyState.type === 'cell') {
const val = copyState.sourceElements[0].value;
const targetInput = document.querySelector(`.js-meal-input[data-d="${targetDate}"][data-s="${targetService}"][data-p="${copyState.personIdx}"]`);
if(targetInput) {
targetInput.value = val;
flashSuccess(targetInput);
updates.push({ plan_date: targetDate, service: targetService, person_id: copyState.personIdx, meal_name: val });
}
} else if (copyState.type === 'row') {
const targetInputs = document.querySelectorAll(`.js-meal-input[data-d="${targetDate}"][data-s="${targetService}"]`);
copyState.sourceElements.forEach((inp, idx) => {
if(inp.value.trim() !== '') {
targetInputs[idx].value = inp.value;
flashSuccess(targetInputs[idx]);
updates.push({ plan_date: targetDate, service: targetService, person_id: targetInputs[idx].dataset.p, meal_name: inp.value });
}
});
}
closeCopyModal();
if (updates.length > 0) {
const fd = new FormData();
fd.append('action', 'save_bulk');
fd.append('updates', JSON.stringify(updates));
await pachaFetch('/modules/meals/includes/api/save-meals.php', { method: 'POST', body: fd });
}
};
function flashSuccess(input) {
input.style.transition = 'background 0.3s';
input.style.background = 'var(--alert-success-bg)';
setTimeout(() => input.style.background = 'transparent', 400);
}
// NOUVEAU : Fonction Javascript d'Import PDF
window.importPdfMenu = async function(e) {
e.preventDefault();
const form = e.target;
const btn = document.getElementById('btnImportPdf');
const oldText = btn.innerText;
btn.disabled = true;
btn.innerText = '⏳...';
const fd = new FormData(form);
const actionUrl = form.getAttribute('action');
try {
const res = await pachaFetch(actionUrl, { method: 'POST', body: fd });
if (res && res.success) {
document.getElementById('importMenuModal').classList.remove('open');
document.body.classList.remove('no-scroll');
if (window.showToast) showToast(window.I18N['meal_import_success'] || 'Menus importés !', 'success');
setTimeout(() => window.location.reload(), 1000);
} else {
if (window.showToast) showToast(res.error || window.I18N['error_occured'], 'error');
else alert(res.error);
}
} catch(err) {
if (window.showToast) showToast(window.I18N['error_occured'], 'error');
} finally {
btn.disabled = false;
btn.innerText = oldText;
form.reset();
document.getElementById('pdfFileName').innerText = window.I18N['meal_drop_pdf'] || 'Cliquer pour ajouter le PDF';
}
};
</script>
+430
View File
@@ -0,0 +1,430 @@
<?php
require_once dirname(__DIR__, 2) . '/includes/auth.php';
require_login();
header('Content-Type: application/json');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(200); exit; }
set_exception_handler(function(\Throwable $e) {
if (!headers_sent()) { header('Content-Type: application/json'); http_response_code(500); }
echo json_encode(['ok' => false, 'error' => $e->getMessage()]);
exit;
});
require_once dirname(__DIR__, 2) . '/includes/db.php';
$UPLOAD_DIR = '/uploads/garage/';
if (!is_dir($UPLOAD_DIR)) { @mkdir($UPLOAD_DIR, 0755, true); }
$pdo->exec("
CREATE TABLE IF NOT EXISTS pf_garage_documents (
id INT AUTO_INCREMENT PRIMARY KEY,
vehicle_id INT NOT NULL,
maintenance_id INT DEFAULT NULL,
label VARCHAR(255) DEFAULT NULL,
filename VARCHAR(255) NOT NULL,
original_name VARCHAR(255) DEFAULT NULL,
mime VARCHAR(120) DEFAULT NULL,
size INT DEFAULT 0,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
KEY idx_gd_vehicle (vehicle_id),
KEY idx_gd_maint (maintenance_id),
FOREIGN KEY (vehicle_id) REFERENCES pf_vehicles(id) ON DELETE CASCADE,
FOREIGN KEY (maintenance_id) REFERENCES pf_maintenances(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
");
$method = $_SERVER['REQUEST_METHOD'];
$action = $_GET['action'] ?? '';
function gOk($d) {
$flags = JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE;
$json = json_encode(['ok' => true, 'data' => $d], $flags);
if ($json === false) { http_response_code(500); echo json_encode(['ok' => false, 'error' => 'Erreur encodage JSON : ' . json_last_error_msg()]); exit; }
echo $json; exit;
}
function gErr($m, $c = 400) { http_response_code($c); echo json_encode(['ok' => false, 'error' => $m]); exit; }
function gBody() { return json_decode(file_get_contents('php://input'), true) ?? []; }
function handleUpload(string $field, string $dir): ?string {
if (!isset($_FILES[$field]) || $_FILES[$field]['error'] !== 0) return null;
$ext = strtolower(pathinfo($_FILES[$field]['name'], PATHINFO_EXTENSION));
if (!in_array($ext, ['jpg','jpeg','png','gif','webp'])) return null;
$fname = uniqid('g', true) . '.' . $ext;
if (move_uploaded_file($_FILES[$field]['tmp_name'], $dir . $fname)) return $fname;
return null;
}
function handleGarageDocumentUpload(string $field, string $dir): ?array {
if (!isset($_FILES[$field]) || $_FILES[$field]['error'] !== UPLOAD_ERR_OK) {
return null;
}
if ($_FILES[$field]['size'] > 12 * 1024 * 1024) {
gErr('Fichier trop volumineux (max 12 Mo).', 400);
}
$ext = strtolower(pathinfo($_FILES[$field]['name'], PATHINFO_EXTENSION));
$allowed = ['pdf','jpg','jpeg','png','gif','webp','doc','docx','xls','xlsx','odt','txt'];
if (!in_array($ext, $allowed, true)) {
gErr('Format non autorisé.', 400);
}
$fname = 'd_' . uniqid('', true) . '.' . $ext;
if (!move_uploaded_file($_FILES[$field]['tmp_name'], $dir . $fname)) {
return null;
}
$mimeMap = [
'pdf' => 'application/pdf', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg',
'png' => 'image/png', 'gif' => 'image/gif', 'webp' => 'image/webp',
'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'odt' => 'application/vnd.oasis.opendocument.text', 'txt' => 'text/plain',
];
return [
'filename' => $fname,
'original_name' => $_FILES[$field]['name'],
'mime' => $mimeMap[$ext] ?? 'application/octet-stream',
'size' => (int) $_FILES[$field]['size'],
];
}
// ─── Vehicles ─────────────────────────────────────────────────────────────────
if ($action === 'vehicles') {
if ($method === 'GET') {
$id = $_GET['id'] ?? null;
if ($id) {
$v = $pdo->prepare("SELECT * FROM pf_vehicles WHERE id = ?"); $v->execute([$id]);
$vehicle = $v->fetch(); if (!$vehicle) gErr('Véhicule introuvable', 404);
$s = $pdo->prepare("SELECT COUNT(*) as cnt, COALESCE(SUM(cost),0) as total FROM pf_maintenances WHERE vehicle_id = ?"); $s->execute([$id]); $vehicle['stats'] = $s->fetch();
$p = $pdo->prepare("SELECT COUNT(*) as cnt, COALESCE(SUM(price*quantity),0) as total FROM pf_parts WHERE vehicle_id = ?"); $p->execute([$id]); $vehicle['parts_stats'] = $p->fetch();
$dc = $pdo->prepare("SELECT COUNT(*) FROM pf_garage_documents WHERE vehicle_id = ? AND maintenance_id IS NULL");
$dc->execute([$id]);
$vehicle['vehicle_docs_count'] = (int) $dc->fetchColumn();
$dm = $pdo->prepare("SELECT COUNT(*) FROM pf_garage_documents WHERE vehicle_id = ? AND maintenance_id IS NOT NULL");
$dm->execute([$id]);
$vehicle['maint_docs_count'] = (int) $dm->fetchColumn();
gOk($vehicle);
}
$stmt = $pdo->query("SELECT v.*, (SELECT COUNT(*) FROM pf_maintenances m WHERE m.vehicle_id = v.id) as maintenance_count, (SELECT COALESCE(SUM(cost),0) FROM pf_maintenances m WHERE m.vehicle_id = v.id) as total_cost, (SELECT date FROM pf_maintenances m WHERE m.vehicle_id = v.id ORDER BY date DESC LIMIT 1) as last_maintenance FROM pf_vehicles v ORDER BY v.created_at DESC");
gOk($stmt->fetchAll());
}
if ($method === 'POST') {
$photo = handleUpload('photo', $UPLOAD_DIR);
$d = $_POST ?: gBody();
// 🔥 LE FIX EST ICI : Fonctions boucliers pour MySQL Strict Mode
$nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt = $pdo->prepare("INSERT INTO pf_vehicles (name,brand,model,year,license_plate,vin,fuel_type,consumption,color,purchase_date,purchase_price,current_km,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([
$d['name'] ?? '',
$d['brand'] ?? '',
$d['model'] ?? '',
$nullInt($d['year'] ?? null),
$nullStr($d['license_plate'] ?? null),
$nullStr($d['vin'] ?? null),
$d['fuel_type'] ?? 'Essence',
$nullFloat($d['consumption'] ?? null),
$nullStr($d['color'] ?? null),
$nullStr($d['purchase_date'] ?? null),
$nullFloat($d['purchase_price'] ?? null),
$nullInt($d['current_km'] ?? null) ?? 0,
$photo,
$nullStr($d['notes'] ?? null)
]);
gOk(['id' => $pdo->lastInsertId()]);
}
if ($method === 'PUT') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody();
$int_fields = ['year','current_km'];
$float_fields = ['purchase_price', 'consumption'];
$fields = ['name','brand','model','year','license_plate','vin','fuel_type','consumption','color','purchase_date','purchase_price','current_km','notes'];
$sets = array_map(fn($f) => "$f = ?", $fields);
$vals = array_map(function($f) use ($d, $int_fields, $float_fields) {
$v = $d[$f] ?? null;
if ($v === '' || $v === null) return null;
if (in_array($f, $int_fields)) return (int)$v;
if (in_array($f, $float_fields)) return (float)$v;
return $v;
}, $fields);
$vals[] = $id;
$pdo->prepare("UPDATE pf_vehicles SET " . implode(', ', $sets) . ", updated_at = NOW() WHERE id = ?")->execute($vals);
gOk(['updated' => true]);
}
if ($method === 'DELETE') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant');
$docs = $pdo->prepare('SELECT filename FROM pf_garage_documents WHERE vehicle_id = ?');
$docs->execute([$id]);
foreach ($docs->fetchAll(PDO::FETCH_COLUMN) as $fn) {
if ($fn) {
@unlink($UPLOAD_DIR . basename($fn));
}
}
$v = $pdo->prepare("SELECT photo FROM pf_vehicles WHERE id=?"); $v->execute([$id]); $row = $v->fetch(); if ($row['photo']) @unlink($UPLOAD_DIR . $row['photo']);
$pdo->prepare("DELETE FROM pf_vehicles WHERE id = ?")->execute([$id]); gOk(['deleted' => true]);
}
}
// ─── Documents (véhicule / entretien — factures, PDF, etc.) ───────────────────
if ($action === 'garage_documents') {
if ($method === 'GET') {
$vid = $_GET['vehicle_id'] ?? null;
$mid = $_GET['maintenance_id'] ?? null;
$vehicleOnly = ($_GET['vehicle_only'] ?? '') === '1';
if ($mid) {
$stmt = $pdo->prepare("SELECT d.*, v.name as vehicle_name FROM pf_garage_documents d JOIN pf_vehicles v ON v.id = d.vehicle_id WHERE d.maintenance_id = ? ORDER BY d.created_at DESC");
$stmt->execute([$mid]);
gOk($stmt->fetchAll());
}
if (!$vid) {
gErr('vehicle_id ou maintenance_id requis');
}
if ($vehicleOnly) {
$stmt = $pdo->prepare("SELECT * FROM pf_garage_documents WHERE vehicle_id = ? AND maintenance_id IS NULL ORDER BY created_at DESC");
$stmt->execute([$vid]);
} else {
$stmt = $pdo->prepare("SELECT * FROM pf_garage_documents WHERE vehicle_id = ? ORDER BY created_at DESC");
$stmt->execute([$vid]);
}
gOk($stmt->fetchAll());
}
if ($method === 'POST') {
$d = $_POST;
$vid = (int) ($d['vehicle_id'] ?? 0);
if ($vid < 1) {
gErr('vehicle_id manquant');
}
$mid = isset($d['maintenance_id']) && $d['maintenance_id'] !== '' ? (int) $d['maintenance_id'] : null;
if ($mid) {
$chk = $pdo->prepare("SELECT id FROM pf_maintenances WHERE id = ? AND vehicle_id = ?");
$chk->execute([$mid, $vid]);
if (!$chk->fetch()) {
gErr('Entretien invalide pour ce véhicule');
}
}
$up = handleGarageDocumentUpload('file', $UPLOAD_DIR);
if (!$up) {
gErr('Upload échoué ou fichier manquant');
}
$label = trim($d['label'] ?? '');
$pdo->prepare("INSERT INTO pf_garage_documents (vehicle_id, maintenance_id, label, filename, original_name, mime, size) VALUES (?,?,?,?,?,?,?)")
->execute([$vid, $mid, $label ?: null, $up['filename'], $up['original_name'], $up['mime'], $up['size']]);
gOk(['id' => (int) $pdo->lastInsertId()]);
}
if ($method === 'DELETE') {
$id = (int) ($_GET['id'] ?? 0);
if ($id < 1) {
gErr('ID manquant');
}
$r = $pdo->prepare("SELECT filename FROM pf_garage_documents WHERE id = ?");
$r->execute([$id]);
$row = $r->fetch();
if (!$row) {
gErr('Document introuvable', 404);
}
if (!empty($row['filename'])) {
@unlink($UPLOAD_DIR . $row['filename']);
}
$pdo->prepare("DELETE FROM pf_garage_documents WHERE id = ?")->execute([$id]);
gOk(['deleted' => true]);
}
}
if ($action === 'garage_document') {
$id = (int) ($_GET['id'] ?? 0);
if ($id < 1) {
gErr('ID manquant');
}
$stmt = $pdo->prepare('SELECT * FROM pf_garage_documents WHERE id = ?');
$stmt->execute([$id]);
$doc = $stmt->fetch();
if (!$doc || empty($doc['filename'])) {
http_response_code(404);
exit;
}
$f = basename($doc['filename']);
$path = $UPLOAD_DIR . $f;
if (!preg_match('/^d_[a-zA-Z0-9._-]+$/', $f) || !is_file($path)) {
http_response_code(404);
exit;
}
$mime = $doc['mime'] ?: 'application/octet-stream';
header('Content-Type: ' . $mime);
$disp = $doc['original_name'] ?: $f;
header('Content-Disposition: inline; filename="' . rawurlencode($disp) . '"');
header('Cache-Control: private, max-age=3600');
readfile($path);
exit;
}
// ─── Maintenances ─────────────────────────────────────────────────────────────
if ($action === 'maintenances') {
$vid = $_GET['vehicle_id'] ?? null;
if ($method === 'GET') {
$id = $_GET['id'] ?? null;
if ($id) {
$stmt = $pdo->prepare("SELECT m.*, v.name as vehicle_name, v.license_plate, v.current_km FROM pf_maintenances m JOIN pf_vehicles v ON v.id = m.vehicle_id WHERE m.id = ?");
$stmt->execute([$id]); $m = $stmt->fetch(); if (!$m) gErr('Entretien introuvable', 404);
$dc = $pdo->prepare("SELECT COUNT(*) FROM pf_garage_documents WHERE maintenance_id = ?");
$dc->execute([$id]);
$m['documents_count'] = (int) $dc->fetchColumn();
gOk($m);
}
if ($vid) {
$stmt = $pdo->prepare("SELECT m.*, GROUP_CONCAT(p.name SEPARATOR ', ') as parts_names, COUNT(p.id) as parts_count, COALESCE(SUM(p.price*p.quantity),0) as parts_cost, (SELECT COUNT(*) FROM pf_garage_documents d WHERE d.maintenance_id = m.id) as documents_count FROM pf_maintenances m LEFT JOIN pf_parts p ON p.maintenance_id = m.id WHERE m.vehicle_id = ? GROUP BY m.id ORDER BY m.date DESC, m.created_at DESC");
$stmt->execute([$vid]); gOk($stmt->fetchAll());
}
$stmt = $pdo->query("SELECT m.*, v.name as vehicle_name, v.license_plate, v.current_km FROM pf_maintenances m JOIN pf_vehicles v ON v.id = m.vehicle_id WHERE m.next_date IS NOT NULL OR m.next_km IS NOT NULL ORDER BY m.next_date ASC");
gOk($stmt->fetchAll());
}
if ($method === 'POST') {
$photo = handleUpload('invoice_photo', $UPLOAD_DIR); $d = $_POST ?: gBody();
if (!($d['vehicle_id'] ?? null)) gErr('vehicle_id manquant');
$stmt = $pdo->prepare("INSERT INTO pf_maintenances (vehicle_id,type,description,date,km,cost,mechanic,garage_name,next_km,next_date,invoice_photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
$nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt->execute([
$d['vehicle_id'],
$d['type'] ?? '',
$nullStr($d['description'] ?? null),
$d['date'] ?? date('Y-m-d'),
$nullInt($d['km'] ?? null),
$nullFloat($d['cost'] ?? null),
$nullStr($d['mechanic'] ?? null),
$nullStr($d['garage_name'] ?? null),
$nullInt($d['next_km'] ?? null),
$nullStr($d['next_date'] ?? null),
$photo,
$nullStr($d['notes'] ?? null),
]);
$mid = $pdo->lastInsertId();
if (!empty($d['km'])) { $pdo->prepare("UPDATE pf_vehicles SET current_km = GREATEST(current_km, ?), updated_at = NOW() WHERE id = ?")->execute([$d['km'], $d['vehicle_id']]); }
gOk(['id' => $mid]);
}
if ($method === 'PUT') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody();
if (empty($d['type'])) gErr('Le type est requis');
if (empty($d['date'])) gErr('La date est requise');
$int_f = ['km','next_km']; $float_f = ['cost'];
$fields = ['type','description','date','km','cost','mechanic','garage_name','next_km','next_date','notes'];
$sets = array_map(fn($f) => "$f = ?", $fields);
$vals = array_map(function($f) use ($d, $int_f, $float_f) {
$v = $d[$f] ?? null;
if ($v === '' || $v === null) return null;
if (in_array($f, $int_f)) return (int)$v;
if (in_array($f, $float_f)) return (float)$v;
return $v;
}, $fields);
$vals[] = $id;
$pdo->prepare("UPDATE pf_maintenances SET " . implode(', ', $sets) . " WHERE id = ?")->execute($vals); gOk(['updated' => true]);
}
if ($method === 'DELETE') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant');
$docs = $pdo->prepare('SELECT filename FROM pf_garage_documents WHERE maintenance_id = ?');
$docs->execute([$id]);
foreach ($docs->fetchAll(PDO::FETCH_COLUMN) as $fn) {
if ($fn) {
@unlink($UPLOAD_DIR . basename($fn));
}
}
$pdo->prepare("DELETE FROM pf_maintenances WHERE id = ?")->execute([$id]); gOk(['deleted' => true]);
}
}
// ─── Parts ────────────────────────────────────────────────────────────────────
if ($action === 'parts') {
if ($method === 'GET') {
$vid = $_GET['vehicle_id'] ?? null; $mid = $_GET['maintenance_id'] ?? null;
$id = $_GET['id'] ?? null;
if ($id) { $stmt = $pdo->prepare("SELECT * FROM pf_parts WHERE id = ?"); $stmt->execute([$id]); $p = $stmt->fetch(); if (!$p) gErr('Pièce introuvable', 404); gOk($p); }
if ($mid) { $stmt = $pdo->prepare("SELECT * FROM pf_parts WHERE maintenance_id = ? ORDER BY created_at DESC"); $stmt->execute([$mid]); gOk($stmt->fetchAll()); }
if ($vid) { $stmt = $pdo->prepare("SELECT p.*, m.type as maintenance_type, m.date as maintenance_date FROM pf_parts p LEFT JOIN pf_maintenances m ON m.id = p.maintenance_id WHERE p.vehicle_id = ? ORDER BY p.created_at DESC"); $stmt->execute([$vid]); gOk($stmt->fetchAll()); }
$stmt = $pdo->query("SELECT p.*, v.name as vehicle_name, m.type as maintenance_type, m.date as maintenance_date FROM pf_parts p LEFT JOIN pf_vehicles v ON v.id = p.vehicle_id LEFT JOIN pf_maintenances m ON m.id = p.maintenance_id ORDER BY p.created_at DESC");
gOk($stmt->fetchAll());
}
if ($method === 'POST') {
$photo = handleUpload('photo', $UPLOAD_DIR); $d = $_POST ?: gBody();
$nullInt = fn($v) => ($v === '' || $v === null) ? null : (int)$v;
$nullFloat = fn($v) => ($v === '' || $v === null) ? null : (float)$v;
$nullStr = fn($v) => ($v === '' || $v === null) ? null : $v;
$stmt = $pdo->prepare("INSERT INTO pf_parts (vehicle_id,maintenance_id,brand,reference,name,category,price,quantity,unit,supplier,purchase_date,photo,notes) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->execute([
$nullInt($d['vehicle_id'] ?? null),
$nullInt($d['maintenance_id'] ?? null),
$nullStr($d['brand'] ?? null),
$nullStr($d['reference'] ?? null),
$d['name'] ?? '',
$d['category'] ?? 'Autre',
$nullFloat($d['price'] ?? null) ?? 0,
$nullInt($d['quantity'] ?? null) ?? 1,
$d['unit'] ?? 'pièce',
$nullStr($d['supplier'] ?? null),
$nullStr($d['purchase_date'] ?? null),
$photo,
$nullStr($d['notes'] ?? null)
]);
gOk(['id' => $pdo->lastInsertId()]);
}
if ($method === 'PUT') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody();
$int_f = ['quantity']; $float_f = ['price'];
$fields = ['brand','reference','name','category','price','quantity','unit','supplier','purchase_date','notes'];
$sets = array_map(fn($f) => "$f = ?", $fields);
$vals = array_map(function($f) use ($d, $int_f, $float_f) {
$v = $d[$f] ?? null;
if ($v === '' || $v === null) return null;
if (in_array($f, $int_f)) return (int)$v;
if (in_array($f, $float_f)) return (float)$v;
return $v;
}, $fields);
$vals[] = $id;
$pdo->prepare("UPDATE pf_parts SET " . implode(', ', $sets) . " WHERE id = ?")->execute($vals); gOk(['updated' => true]);
}
if ($method === 'DELETE') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant');
$r = $pdo->prepare("SELECT photo FROM pf_parts WHERE id=?"); $r->execute([$id]); $row = $r->fetch(); if ($row['photo']) @unlink($UPLOAD_DIR . $row['photo']);
$pdo->prepare("DELETE FROM pf_parts WHERE id = ?")->execute([$id]); gOk(['deleted' => true]);
}
}
// ─── Stats ────────────────────────────────────────────────────────────────────
if ($action === 'stats') {
gOk([
'vehicles' => $pdo->query("SELECT COUNT(*) FROM pf_vehicles")->fetchColumn(),
'maintenances' => $pdo->query("SELECT COUNT(*) FROM pf_maintenances")->fetchColumn(),
'parts' => $pdo->query("SELECT COUNT(*) FROM pf_parts")->fetchColumn(),
'total_cost' => $pdo->query("SELECT COALESCE(SUM(cost),0) FROM pf_maintenances")->fetchColumn(),
'total_parts_cost' => $pdo->query("SELECT COALESCE(SUM(price*quantity),0) FROM pf_parts")->fetchColumn(),
'upcoming_reminders'=> $pdo->query("SELECT COUNT(*) FROM pf_maintenances WHERE next_date >= CURDATE() OR next_km IS NOT NULL")->fetchColumn(),
]);
}
// ─── Photo upload ──────────────────────────────────────────────────────────────
if ($action === 'upload_vehicle_photo') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant');
$photo = handleUpload('photo', $UPLOAD_DIR); if (!$photo) gErr('Upload échoué');
$old = $pdo->prepare("SELECT photo FROM pf_vehicles WHERE id=?"); $old->execute([$id]); $row = $old->fetch(); if ($row['photo']) @unlink($UPLOAD_DIR . $row['photo']);
$pdo->prepare("UPDATE pf_vehicles SET photo = ?, updated_at = NOW() WHERE id = ?")->execute([$photo, $id]); gOk(['photo' => $photo]);
}
if ($action === 'photo') {
$f = basename($_GET['file'] ?? '');
if ($f && preg_match('/^[a-zA-Z0-9._-]+$/', $f) && file_exists($UPLOAD_DIR . $f)) {
$ext = strtolower(pathinfo($f, PATHINFO_EXTENSION));
$mime = ['jpg'=>'image/jpeg','jpeg'=>'image/jpeg','png'=>'image/png','gif'=>'image/gif','webp'=>'image/webp'][$ext] ?? 'image/jpeg';
header('Content-Type: ' . $mime);
readfile($UPLOAD_DIR . $f);
exit;
}
http_response_code(404); exit;
}
if ($action === 'upload_part_photo') {
$id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant');
$photo = handleUpload('photo', $UPLOAD_DIR); if (!$photo) gErr('Upload échoué');
$pdo->prepare("UPDATE pf_parts SET photo = ? WHERE id = ?")->execute([$photo, $id]); gOk(['photo' => $photo]);
}
gErr('Action inconnue', 404);
+525
View File
@@ -0,0 +1,525 @@
/* Garage module — light theme matching HouseHub global.css */
/* Aliases pour les inline styles JS qui utilisent var(--muted) / var(--fg) */
:root {
--muted: #64748b;
--fg: #0f172a;
}
/* ─── SOUS-NAVIGATION ──────────────────────────────────────────────────────── */
.garage-subnav {
display: flex;
gap: 4px;
padding: 10px 20px;
background: var(--bg-panel);
border-bottom: 1px solid var(--border-light);
}
.garage-subnav .nav-link {
background: none;
border: 1px solid transparent;
border-radius: 8px;
padding: 7px 16px;
font-size: 0.875rem;
font-weight: 500;
cursor: pointer;
color: var(--text-muted);
transition: all .15s;
}
.garage-subnav .nav-link:hover { background: #f1f5f9; color: var(--text-main); }
.garage-subnav .nav-link.active { background: #eff6ff; color: var(--primary); border-color: #bfdbfe; }
/* ─── CONTAINER & PAGES ────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page { display: none; }
.page.active { display: block; }
/* ─── CARD ──────────────────────────────────────────────────────────────────── */
.card {
background: var(--bg-panel);
border: 1px solid var(--border-light);
border-radius: var(--radius);
padding: 1.25rem;
box-shadow: var(--shadow);
}
.card-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: .75rem;
flex-wrap: wrap;
margin-bottom: .25rem;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text-main); }
/* ─── STATS GRID ────────────────────────────────────────────────────────────── */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 1rem;
margin-bottom: 1.5rem;
}
.stat-pill {
background: var(--bg-panel);
border: 1px solid var(--border-light);
border-radius: var(--radius);
padding: 1.25rem 1.5rem;
border-left: 4px solid var(--border-light);
box-shadow: var(--shadow);
}
.stat-pill .label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .35rem; }
.stat-pill .value { font-size: 1.75rem; font-weight: 700; line-height: 1; color: var(--text-main); }
.stat-pill.blue { border-left-color: var(--primary); }
.stat-pill.blue .value { color: var(--primary); }
.stat-pill.green { border-left-color: var(--success); }
.stat-pill.green .value { color: var(--success); }
.stat-pill.amber { border-left-color: var(--warning); }
.stat-pill.amber .value { color: var(--warning); }
.stat-pill.red { border-left-color: var(--danger); }
.stat-pill.red .value { color: var(--danger); }
/* ─── VEHICLES GRID ─────────────────────────────────────────────────────────── */
.vehicles-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 1.25rem;
}
.vehicle-card {
background: var(--bg-panel);
border: 1px solid var(--border-light);
border-radius: var(--radius);
overflow: hidden;
cursor: pointer;
transition: border-color .2s, box-shadow .2s, transform .15s;
box-shadow: var(--shadow);
}
.vehicle-card:hover {
border-color: var(--primary);
box-shadow: var(--shadow-lg);
transform: translateY(-2px);
}
.vehicle-card-img {
width: 100%; height: 180px; overflow: hidden; background: #f1f5f9;
position: relative; display: flex; align-items: center; justify-content: center;
}
.vehicle-card-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.no-photo { font-size: 3.5rem; color: #cbd5e1; }
.vehicle-card-body { padding: 1rem; }
.vehicle-card-title { font-size: 1rem; font-weight: 700; color: var(--text-main); margin-bottom: .25rem; }
.vehicle-card-sub { font-size: .82rem; color: var(--text-muted); margin-bottom: .6rem; }
.vehicle-card-stats { display: flex; gap: .75rem; flex-wrap: wrap; }
.vc-stat { font-size: .82rem; color: var(--text-muted); }
.vehicle-card-footer {
padding: .6rem 1rem;
border-top: 1px solid var(--border-light);
display: flex; justify-content: space-between; align-items: center;
font-size: .8rem; color: var(--text-muted);
background: #fafafa;
}
/* ─── FUEL BADGE ────────────────────────────────────────────────────────────── */
.fuel-badge {
position: absolute; top: .5rem; right: .5rem;
font-size: .7rem; font-weight: 700;
padding: .18rem .5rem; border-radius: 6px;
text-transform: uppercase; letter-spacing: .03em;
}
.fuel-Essence { background: rgba(59,130,246,.15); color: #2563eb; }
.fuel-Diesel { background: rgba(139,92,246,.15); color: #7c3aed; }
.fuel-Hybride { background: rgba(16,185,129,.15); color: #059669; }
.fuel-Electrique { background: rgba(6,182,212,.15); color: #0891b2; }
.fuel-GPL { background: rgba(245,158,11,.15); color: #d97706; }
/* ─── PLATE ──────────────────────────────────────────────────────────────────── */
.plate {
display: inline-block; background: #1d4ed8; color: #fff;
font-family: 'Courier New', monospace; font-weight: 700;
font-size: .78rem; padding: .18rem .55rem;
border-radius: 5px; letter-spacing: .1em;
}
/* ─── TABLE ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border-light); }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table-wrap table th {
background: #f8fafc; color: var(--text-muted);
font-weight: 600; text-align: left;
padding: .65rem .9rem; border-bottom: 1px solid var(--border-light); white-space: nowrap;
}
.table-wrap table td {
padding: .65rem .9rem; border-bottom: 1px solid var(--border-light);
vertical-align: middle; color: var(--text-main);
}
.table-wrap table tr:last-child td { border-bottom: none; }
.table-wrap table tr:hover td { background: #fafbff; }
/* ─── BADGES ─────────────────────────────────────────────────────────────────── */
.badge {
display: inline-block; font-size: .72rem; font-weight: 600;
padding: .22rem .55rem; border-radius: 999px;
}
.badge-green { background: #dcfce7; color: #15803d; }
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-amber { background: #fef3c7; color: #b45309; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }
.badge-purple { background: #ede9fe; color: #6d28d9; }
/* ─── BUTTONS ────────────────────────────────────────────────────────────────── */
.btn {
display: inline-flex; align-items: center; gap: .4rem;
padding: .5rem 1rem; border-radius: 8px;
font-size: .875rem; font-weight: 500; cursor: pointer;
border: 1px solid transparent; transition: all .15s;
white-space: nowrap; text-decoration: none; line-height: 1.4;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-secondary { background: var(--bg-panel); color: var(--text-main); border-color: var(--border-light); }
.btn-secondary:hover { background: #f1f5f9; }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-icon { padding: .3rem; min-width: 30px; justify-content: center; }
/* ─── FORMS ──────────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-label { font-size: .82rem; font-weight: 600; color: var(--text-muted); }
.form-control {
background: #fff; border: 1px solid var(--border-light); color: var(--text-main);
border-radius: 8px; padding: .5rem .75rem; font-size: .875rem;
width: 100%; outline: none; transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.form-control::placeholder { color: #cbd5e1; }
select.form-control option { background: #fff; }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .9rem; }
/* ─── MODALS ─────────────────────────────────────────────────────────────────── */
.modal-backdrop {
display: none; position: fixed; inset: 0; z-index: 200;
background: rgba(15,23,42,.5); backdrop-filter: blur(4px);
align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.show { display: flex; }
.modal {
background: var(--bg-panel);
border: 1px solid var(--border-light);
border-radius: var(--radius);
width: 100%; max-width: 640px;
max-height: 90vh; display: flex; flex-direction: column;
box-shadow: var(--shadow-lg);
animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.96) translateY(-8px); } to { opacity: 1; transform: none; } }
.modal-header {
display: flex; align-items: center; justify-content: space-between;
padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-light); flex-shrink: 0;
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1.25rem; line-height: 1; padding: .2rem; border-radius: 6px; }
.modal-close:hover { background: #f1f5f9; color: var(--text-main); }
.modal-body { padding: 1.25rem; overflow-y: auto; display: flex; flex-direction: column; gap: .9rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; gap: .5rem; flex-shrink: 0; }
/* ─── VEHICLE DETAIL HEADER ─────────────────────────────────────────────────── */
.vehicle-detail-header {
display: flex; gap: 1.5rem; align-items: flex-start;
background: var(--bg-panel); border: 1px solid var(--border-light);
border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
box-shadow: var(--shadow);
}
.vehicle-detail-img {
width: 180px; height: 130px; border-radius: 8px; flex-shrink: 0;
background: #f1f5f9; overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.vehicle-detail-img img { width: 100%; height: 100%; object-fit: cover; }
.vehicle-meta h2 { font-size: 1.4rem; font-weight: 800; color: var(--text-main); margin-bottom: .25rem; }
.vehicle-meta .sub { font-size: .9rem; color: var(--text-muted); margin-bottom: .75rem; }
.meta-grid { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: .5rem; }
.meta-item .k { font-size: .72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.meta-item .v { font-size: .95rem; font-weight: 600; color: var(--text-main); }
/* ─── TABS ───────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border-light); }
.tab-btn {
background: none; border: none; cursor: pointer;
color: var(--text-muted); font-size: .9rem; font-weight: 500;
padding: .6rem 1rem; border-bottom: 2px solid transparent;
margin-bottom: -1px; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--text-main); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }
/* ─── PARTS ──────────────────────────────────────────────────────────────────── */
.part-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border-light); }
/* ─── EMPTY STATE ────────────────────────────────────────────────────────────── */
.empty-state {
display: flex; flex-direction: column; align-items: center;
gap: .75rem; padding: 3rem 1rem; color: var(--text-muted); text-align: center;
}
.empty-state .icon { font-size: 2.5rem; opacity: .4; }
.empty-state p { font-size: .9rem; }
/* ─── TOASTS ─────────────────────────────────────────────────────────────────── */
.toast-container {
position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
display: flex; flex-direction: column; align-items: flex-end;
gap: .5rem; pointer-events: none;
}
.toast {
background: var(--bg-panel); border: 1px solid var(--border-light);
border-radius: 10px; padding: .75rem 1rem;
font-size: .875rem; min-width: 220px; max-width: 360px; color: var(--text-main);
box-shadow: var(--shadow-lg); animation: toastIn .2s ease; pointer-events: auto;
border-left: 4px solid var(--border-light);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--primary); }
.toast.warning { border-left-color: var(--warning); }
@keyframes toastIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
/* ─── SCROLL LIST (pièces connues) ──────────────────────────────────────────── */
.scroll-list {
max-height: 160px; overflow-y: auto;
border: 1px solid var(--border-light); border-radius: 8px;
background: #fff; margin-bottom: 1rem;
}
.scroll-list-item {
display: flex; align-items: center; gap: .75rem;
padding: .45rem .75rem; cursor: pointer;
border-bottom: 1px solid var(--border-light); transition: background .12s;
user-select: none;
}
.scroll-list-item:last-child { border-bottom: none; }
.scroll-list-item:hover { background: #f8fafc; }
.scroll-list-item input[type="radio"] { flex-shrink: 0; }
.item-name { flex: 1; font-size: .875rem; font-weight: 500; color: var(--text-main); }
.item-ref { font-size: .72rem; font-family: monospace; color: var(--text-muted); }
.item-brand { font-size: .75rem; color: var(--text-muted); }
.item-price { font-size: .875rem; font-weight: 600; color: var(--primary); white-space: nowrap; }
/* ─── DASHBOARD LAYOUT ─────────────────────────────────────────────────────── */
.garage-dash-layout {
display: grid;
grid-template-columns: 1fr minmax(260px, 380px);
gap: 1.5rem;
align-items: start;
}
.garage-dash-main { min-width: 0; }
.garage-dash-aside { padding: 1rem 1.25rem; }
.garage-card-header { flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.garage-tab-actions {
margin-bottom: 1rem;
display: flex;
justify-content: flex-end;
flex-wrap: wrap;
gap: 0.5rem;
}
/* ─── TABS (scroll mobile) ─────────────────────────────────────────────────── */
.garage-tabs {
flex-wrap: nowrap;
overflow-x: auto;
-webkit-overflow-scrolling: touch;
scrollbar-width: thin;
gap: 0.15rem;
padding-bottom: 2px;
}
.garage-tabs .tab-btn {
flex-shrink: 0;
white-space: nowrap;
padding: 0.55rem 0.75rem;
font-size: 0.82rem;
}
/* ─── VEHICLE HEADER ACTIONS ───────────────────────────────────────────────── */
.vehicle-detail-actions {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
align-self: flex-start;
}
.garage-docs-recap {
margin-top: 0.75rem;
padding: 0.65rem 0.85rem;
background: #f8fafc;
border: 1px solid var(--border-light);
border-radius: 8px;
font-size: 0.82rem;
color: var(--text-muted);
line-height: 1.45;
}
.garage-docs-recap strong { color: var(--text-main); }
.btn-link-sm {
display: inline;
margin: 0;
padding: 0;
border: none;
background: none;
color: var(--primary);
font-size: inherit;
font-weight: 600;
cursor: pointer;
text-decoration: underline;
text-underline-offset: 2px;
}
.btn-link-sm:hover { color: var(--primary-dark); }
.garage-maint-doc-badge { font-size: 0.65rem; vertical-align: middle; margin-left: 0.15rem; }
/* ─── DOCUMENTS ───────────────────────────────────────────────────────────── */
.garage-docs-card .card-header { padding: 1rem 1.25rem; }
.garage-doc-upload-bar {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 0.75rem 1rem;
margin-top: 0.75rem;
}
.garage-doc-upload-btn { align-self: flex-end; flex-shrink: 0; }
.garage-doc-hint {
font-size: 0.78rem;
color: var(--text-muted);
margin: 0.35rem 0 0.75rem;
}
.garage-doc-empty { padding: 1.25rem !important; }
.garage-doc-list {
list-style: none;
margin: 0;
padding: 0;
border: 1px solid var(--border-light);
border-radius: 8px;
overflow: hidden;
}
.garage-doc-item {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem 0.75rem;
padding: 0.65rem 0.85rem;
border-bottom: 1px solid var(--border-light);
background: #fff;
}
.garage-doc-item:last-child { border-bottom: none; }
.garage-doc-link {
flex: 1;
min-width: 0;
font-weight: 500;
color: var(--primary);
text-decoration: none;
word-break: break-word;
}
.garage-doc-link:hover { text-decoration: underline; }
.garage-doc-meta {
font-size: 0.75rem;
color: var(--text-muted);
white-space: nowrap;
}
.garage-doc-item .btn-icon { flex-shrink: 0; margin-left: auto; }
/* ─── RESPONSIVE ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
.container { padding: 1rem; }
.vehicle-detail-header { flex-direction: column; }
.vehicle-detail-img { width: 100%; height: 200px; }
.vehicle-detail-actions {
width: 100%;
flex-direction: column;
align-self: stretch;
}
.vehicle-detail-actions .btn { width: 100%; justify-content: center; }
.form-row, .form-row-3 { grid-template-columns: 1fr; }
.stats-grid { grid-template-columns: repeat(2, 1fr); }
.modal { max-height: 95vh; }
.vehicles-grid { grid-template-columns: 1fr; }
.meta-grid { gap: 0.75rem; }
.garage-subnav { padding: 8px 12px; overflow-x: auto; flex-wrap: nowrap; }
.garage-subnav .nav-link { white-space: nowrap; }
.garage-dash-layout { grid-template-columns: 1fr; }
.garage-dash-aside { order: -1; }
.garage-doc-upload-bar { flex-direction: column; align-items: stretch; }
.garage-doc-upload-btn { width: 100%; align-self: stretch; }
.garage-doc-item { flex-direction: column; align-items: stretch; }
.garage-doc-item .btn-icon { margin-left: 0; align-self: flex-end; }
.garage-doc-meta { white-space: normal; }
.toast-container {
left: 0.75rem;
right: 0.75rem;
bottom: max(1rem, env(safe-area-inset-bottom, 0px));
align-items: stretch;
}
.toast { max-width: none; min-width: 0; width: 100%; }
}
@media (max-width: 640px) {
.table-wrap {
margin-left: -0.25rem;
margin-right: -0.25rem;
border-radius: 6px;
}
.table-wrap table { min-width: 640px; }
#inline-part-form .form-row,
#inline-part-form .form-row-3 { grid-template-columns: 1fr !important; }
}
/* ══ DARK MODE — Garage module ══════════════════════════════════ */
[data-theme="dark"] { --muted: #8b949e; --fg: #e6edf3; }
[data-theme="dark"] .garage-subnav { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .garage-subnav .nav-link { color: var(--text-muted); }
[data-theme="dark"] .garage-subnav .nav-link:hover { background: rgba(255,255,255,.06); color: var(--text-main); }
[data-theme="dark"] .garage-subnav .nav-link.active { background: rgba(59,130,246,.15); color: var(--primary); border-color: rgba(59,130,246,.3); }
[data-theme="dark"] .card,
[data-theme="dark"] .vehicle-detail-header { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .stat-pill { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .stat-pill .label { color: var(--text-muted); }
[data-theme="dark"] .vehicle-card { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .vehicle-card:hover { border-color: var(--primary); }
[data-theme="dark"] .vehicle-card-img { background: #1c2128; }
[data-theme="dark"] .vehicle-card-footer { background: #1c2128; border-color: var(--border-light); }
[data-theme="dark"] .vehicle-card-title { color: var(--text-main); }
[data-theme="dark"] .vehicle-card-sub { color: var(--text-muted); }
[data-theme="dark"] .vehicle-detail-img { background: #1c2128; }
[data-theme="dark"] .vehicle-meta h2 { color: var(--text-main); }
[data-theme="dark"] .meta-item .v { color: var(--text-main); }
[data-theme="dark"] .card-title, [data-theme="dark"] .modal-title { color: var(--text-main); }
[data-theme="dark"] .table-wrap { border-color: var(--border-light); }
[data-theme="dark"] .table-wrap table th { background: #1c2128; color: var(--text-muted); border-color: var(--border-light); }
[data-theme="dark"] .table-wrap table td { border-color: rgba(48,54,61,.4); color: var(--text-main); }
[data-theme="dark"] .table-wrap table tr:hover td { background: rgba(255,255,255,.03); }
[data-theme="dark"] .tabs { border-color: var(--border-light); }
[data-theme="dark"] .tab-btn { color: var(--text-muted); }
[data-theme="dark"] .tab-btn:hover { color: var(--text-main); }
[data-theme="dark"] .form-label { color: var(--text-muted); }
[data-theme="dark"] .form-control { background: #1c2128; border-color: var(--border-light); color: var(--text-main); }
[data-theme="dark"] .form-control::placeholder { color: #484f58; }
[data-theme="dark"] select.form-control option { background: #1c2128; }
[data-theme="dark"] .modal { background: var(--bg-panel); border-color: var(--border-light); }
[data-theme="dark"] .modal-header,
[data-theme="dark"] .modal-footer { border-color: var(--border-light); }
[data-theme="dark"] .modal-close:hover { background: rgba(255,255,255,.06); }
[data-theme="dark"] .btn-secondary { background: #1c2128; border-color: var(--border-light); color: var(--text-main); }
[data-theme="dark"] .btn-secondary:hover { background: rgba(255,255,255,.06); }
[data-theme="dark"] .btn-danger { background: #1c2128; border-color: rgba(239,68,68,.4); }
[data-theme="dark"] .btn-danger:hover { background: rgba(239,68,68,.08); }
[data-theme="dark"] .badge-gray { background: rgba(139,148,158,.15); color: var(--text-muted); }
[data-theme="dark"] .toast { background: var(--bg-panel); border-color: var(--border-light); color: var(--text-main); }
[data-theme="dark"] .part-thumb { border-color: var(--border-light); }
[data-theme="dark"] .scroll-list { background: #1c2128; border-color: var(--border-light); }
[data-theme="dark"] .scroll-list-item { border-color: rgba(48,54,61,.5); }
[data-theme="dark"] .scroll-list-item:hover { background: rgba(255,255,255,.04); }
[data-theme="dark"] .item-name { color: var(--text-main); }
[data-theme="dark"] #inline-part-form { background: #1c2128 !important; border-color: var(--border-light) !important; }
[data-theme="dark"] .garage-docs-recap { background: rgba(255,255,255,.04); border-color: var(--border-light); color: var(--text-muted); }
[data-theme="dark"] .garage-docs-recap strong { color: var(--text-main); }
[data-theme="dark"] .btn-link-sm { color: var(--primary); }
[data-theme="dark"] .garage-doc-list { border-color: var(--border-light); }
[data-theme="dark"] .garage-doc-item { background: #1c2128; border-color: rgba(48,54,61,.5); }
[data-theme="dark"] .garage-doc-link { color: #93c5fd; }
[data-theme="dark"] .garage-doc-meta { color: var(--text-muted); }
File diff suppressed because it is too large. Load diff
+84
View File
@@ -0,0 +1,84 @@
<?php
require __DIR__ . '/../../includes/auth.php';
require __DIR__ . '/../../includes/db.php';
require_login();
header('Content-Type: application/json');
$action = $_POST['action'] ?? $_GET['action'] ?? '';
try {
if ($action === 'get_all') {
$occ = $pdo->query("SELECT * FROM pf_gift_occasions ORDER BY sort_order ASC, id ASC")->fetchAll();
$proches = $pdo->query("SELECT * FROM pf_people WHERE role IN ('proche_adulte', 'proche_enfant') ORDER BY name ASC")->fetchAll();
echo json_encode(['success' => true, 'data' => ['occasions' => $occ, 'proches' => $proches]]);
exit;
}
if ($action === 'save_occasion') {
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
$name = trim($_POST['name']);
$icon = trim($_POST['icon']) ?: '🎁';
$month_date = trim($_POST['month_date']) ?: null;
if (empty($name)) throw new Exception("Le nom est obligatoire.");
if ($id) {
$stmt = $pdo->prepare("UPDATE pf_gift_occasions SET name=?, icon=?, month_date=? WHERE id=?");
$stmt->execute([$name, $icon, $month_date, $id]);
} else {
$code = 'CUST_' . strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', $name), 0, 4)) . '_' . rand(100, 999);
$stmt = $pdo->prepare("INSERT INTO pf_gift_occasions (code, name, icon, month_date) VALUES (?, ?, ?, ?)");
$stmt->execute([$code, $name, $icon, $month_date]);
}
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_occasion') {
$id = (int)$_POST['id'];
$pdo->prepare("DELETE FROM pf_gift_occasions WHERE id=?")->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
if ($action === 'toggle_occasion') {
$id = (int)$_POST['id'];
$state = (int)$_POST['state'];
$pdo->prepare("UPDATE pf_gift_occasions SET is_active=? WHERE id=?")->execute([$state, $id]);
echo json_encode(['success' => true]);
exit;
}
if ($action === 'save_proche') {
$id = !empty($_POST['id']) ? (int)$_POST['id'] : null;
$name = trim($_POST['name']);
$role = $_POST['role'];
if (empty($name)) throw new Exception("Le nom est obligatoire.");
if (!in_array($role, ['proche_adulte', 'proche_enfant'])) throw new Exception("Rôle invalide.");
if ($id) {
// Sécurité : on s'assure qu'on modifie bien un proche et pas un parent
$stmt = $pdo->prepare("UPDATE pf_people SET name=?, role=? WHERE id=? AND role IN ('proche_adulte', 'proche_enfant')");
$stmt->execute([$name, $role, $id]);
} else {
$stmt = $pdo->prepare("INSERT INTO pf_people (name, role, color) VALUES (?, ?, '#94a3b8')");
$stmt->execute([$name, $role]);
}
echo json_encode(['success' => true]);
exit;
}
if ($action === 'delete_proche') {
$id = (int)$_POST['id'];
$stmt = $pdo->prepare("DELETE FROM pf_people WHERE id=? AND role IN ('proche_adulte', 'proche_enfant')");
$stmt->execute([$id]);
echo json_encode(['success' => true]);
exit;
}
} catch (Exception $e) {
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
exit;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Loaded 100 of 151 files, more files were not shown because too many files have changed in this diff. Show more