-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
-- Generation Time: Oct 21, 2025 at 12:42 PM
-- Server version: 8.4.4
-- PHP Version: 8.4.13

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `genivent_services-ae`
--

-- --------------------------------------------------------

--
-- Table structure for table `testimonials`
--

CREATE TABLE `testimonials` (
  `id` int NOT NULL,
  `nom_client` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Nom complet du client',
  `email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Email du client',
  `entreprise` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Nom de l''entreprise du client',
  `poste` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Poste/fonction du client',
  `message` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'Contenu du témoignage',
  `note` int NOT NULL DEFAULT '5' COMMENT 'Note sur 5 étoiles (1-5)',
  `service_utilise` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Service utilisé par le client',
  `image_client` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Chemin vers l''image du client',
  `ip_address` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'Adresse IP du client',
  `user_agent` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT 'User agent du navigateur',
  `approuve` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Statut d''approbation (0=en attente, 1=approuvé)',
  `affiche_page_accueil` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'Afficher sur la page d''accueil (0=non, 1=oui)',
  `date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date de création du témoignage',
  `date_approbation` timestamp NULL DEFAULT NULL COMMENT 'Date d''approbation du témoignage'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Triggers `testimonials`
--
DELIMITER $$
CREATE TRIGGER `update_date_approbation` BEFORE UPDATE ON `testimonials` FOR EACH ROW BEGIN
    -- Mettre à jour la date d'approbation quand le statut passe à approuvé
    IF NEW.approuve = 1 AND OLD.approuve = 0 THEN
        SET NEW.date_approbation = CURRENT_TIMESTAMP;
    END IF;
    
    -- Réinitialiser la date d'approbation si le statut est rejeté
    IF NEW.approuve = 0 AND OLD.approuve = 1 THEN
        SET NEW.date_approbation = NULL;
    END IF;
END
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `testimonials`
--
ALTER TABLE `testimonials`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_approuve` (`approuve`),
  ADD KEY `idx_affiche_accueil` (`affiche_page_accueil`),
  ADD KEY `idx_date_creation` (`date_creation`),
  ADD KEY `idx_note` (`note`),
  ADD KEY `idx_service` (`service_utilise`),
  ADD KEY `idx_search` (`approuve`,`affiche_page_accueil`,`date_creation`),
  ADD KEY `idx_service_approved` (`service_utilise`,`approuve`);
ALTER TABLE `testimonials` ADD FULLTEXT KEY `nom_client` (`nom_client`,`entreprise`,`message`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `testimonials`
--
ALTER TABLE `testimonials`
  MODIFY `id` int NOT NULL AUTO_INCREMENT;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
