based on this inof database (-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1:3306
-- Generation Time: Nov 18, 2024 at 09:31 AM
-- Server version: 10.11.9-MariaDB
-- PHP Version: 7.2.34

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: `u406552082_kaakalia`
--

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

--
-- Table structure for table `ads`
--

CREATE TABLE `ads` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `ad_type` enum('Post','Story') NOT NULL,
  `related_id` int(11) NOT NULL,
  `budget` decimal(10,2) NOT NULL,
  `total_spent` decimal(10,2) DEFAULT 0.00,
  `start_date` date NOT NULL,
  `end_date` date NOT NULL,
  `status` enum('Active','Paused','Completed') DEFAULT 'Active',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `ad_spend_logs`
--

CREATE TABLE `ad_spend_logs` (
  `id` int(11) NOT NULL,
  `ad_id` int(11) NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `spend_date` datetime DEFAULT current_timestamp(),
  `description` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `contact` varchar(50) DEFAULT NULL,
  `delivery_address` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `customers`
--

INSERT INTO `customers` (`id`, `name`, `contact`, `delivery_address`) VALUES
(1, 'Order_3121', '012345689', 'Qena'),
(2, 'order_3212', '51648963', 'Luxor'),
(3, 'Order_323', '01119235049', 'Qena, Egypt'),
(4, 'Order_3231', '0155648963', 'Luxor'),
(5, 'Order_3548464852', '0110215489', 'Qena'),
(6, 'Order_mahmoud', '50495049', 'Qena'),
(7, 'Ahmed', '01119235049', 'Assuit'),
(8, 'Mahmoud Tawfik', '01119235049', 'Qena, Center Qena'),
(9, 'Ahmed', '0101549463', 'Luxor'),
(10, 'Yossef', '0154949463', 'Aswan'),
(11, 'Mona', '0154984315', 'Qena'),
(12, 'Order_132323', '0119548463', 'CXA'),
(13, 'Mostafa', '154946123', 'Assuit'),
(14, 'Order_66960907', '+96566960907', 'kuwait'),
(15, 'Order_84569845', '+96584569845', 'Kuwait'),
(16, 'Order_84656222', '+96584656222', 'Mashrif'),
(17, 'Order_84549651', '+96584549651', 'Luxor'),
(18, 'Order_94531154', '+96594531154', 'Qena'),
(19, 'Order_56123548', '+96556123548', 'luxor'),
(20, 'Order_84562148', '+96584562148', NULL),
(21, 'Order_54632154', '+96554632154', 'Luxor'),
(22, 'Order_84561254', '+96584561254', 'Qena');

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

--
-- Table structure for table `deals`
--

CREATE TABLE `deals` (
  `id` int(11) NOT NULL,
  `influencer_id` int(11) NOT NULL,
  `deal_type` enum('Sponsorship','Booth','Other') NOT NULL,
  `description` text DEFAULT NULL,
  `compensation` decimal(10,2) DEFAULT 0.00,
  `status` enum('Pending','Confirmed','Completed','Cancelled') DEFAULT 'Pending',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `drivers`
--

CREATE TABLE `drivers` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `number` varchar(15) NOT NULL,
  `is_star` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `drivers`
--

INSERT INTO `drivers` (`id`, `name`, `number`, `is_star`) VALUES
(1, 'Fox توصيل', '+965 9944 6116', 0),
(2, 'Perfect M توصيل 3kd', '+965 555 72147', 0),
(3, 'توصيل ٥', '+965 505 02769', 0),
(4, 'Shipping Company توصيل Delivery', '+965 9940 7010', 0),
(5, 'توصيلكم توصيل Delivery', '+965 517 66244', 0),
(6, 'توصيل الكويت ٢', '+965 557 25712', 0),
(7, 'توصيل الكويت 2.5kd', '+965 6049 4960', 0),
(8, 'كلاسك توصيل', '+965 6969 1459', 0),
(9, 'سايق On Call5 Delivery Freelance', '+965 6698 8976', 1),
(10, 'سايق On Call 3 Delivery Freelance', '+965 555 86442', 0),
(11, 'سايق On Call 2 Delivery Freelance', '+965 555 12101', 0),
(12, 'Delivery توصيل', '+965 9851 8182', 0),
(13, 'Kumar Driver', '+965 6673 8688', 1),
(14, 'Pawan Driver', '+965 9733 1565', 0),
(15, 'توصيل - صلاح', '+965 6576 2337', 0);

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

--
-- Table structure for table `influencers`
--

CREATE TABLE `influencers` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `contact_number` varchar(50) NOT NULL,
  `contact_info` varchar(255) NOT NULL,
  `address` text NOT NULL,
  `social_media` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `delivery_datetime` datetime DEFAULT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `influencers`
--

INSERT INTO `influencers` (`id`, `name`, `contact_number`, `contact_info`, `address`, `social_media`, `notes`, `delivery_datetime`, `created_at`, `updated_at`) VALUES
(1, 'Mahmoud', '', '01119235049 - Qena, Mahmoud', '', '@instagram', 'Hello', NULL, '2024-11-18 08:41:55', '2024-11-18 08:41:55'),
(2, 'Ahmed', '945846126', 'mahmoudtawfikh@gmail.com', 'Assuit', 'instagram', 'kilo shobara \r\nhalf kilo monkey bread', '2024-11-19 12:00:00', '2024-11-18 09:15:10', '2024-11-18 09:15:10');

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

--
-- Table structure for table `interactions`
--

CREATE TABLE `interactions` (
  `id` int(11) NOT NULL,
  `influencer_id` int(11) NOT NULL,
  `interaction_date` datetime NOT NULL,
  `method` enum('Email','Phone','In-Person','Social Media','Other') NOT 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 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `notifications`
--

CREATE TABLE `notifications` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `type` enum('order','post','plan','note','ad') NOT NULL,
  `message` varchar(255) NOT NULL,
  `link` varchar(255) NOT NULL,
  `created_at` datetime DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `orders`
--

CREATE TABLE `orders` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) NOT NULL,
  `status` enum('Pending','In Progress','Completed','Delivered') DEFAULT 'Pending',
  `priority` enum('Normal','Important','Quick') DEFAULT 'Normal',
  `order_date` datetime DEFAULT current_timestamp(),
  `delivery_datetime` datetime DEFAULT NULL,
  `delivery_date` date DEFAULT NULL,
  `delivery_fee` decimal(10,2) NOT NULL DEFAULT 0.00,
  `free_shipping` tinyint(1) NOT NULL DEFAULT 0,
  `is_paid` tinyint(1) NOT NULL DEFAULT 0,
  `pickup` tinyint(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `orders`
--

INSERT INTO `orders` (`id`, `customer_id`, `status`, `priority`, `order_date`, `delivery_datetime`, `delivery_date`, `delivery_fee`, `free_shipping`, `is_paid`, `pickup`) VALUES
(4, 4, 'Delivered', 'Normal', '2024-11-09 14:48:25', '2024-11-16 08:50:00', NULL, 0.00, 0, 0, 0),
(5, 5, 'Delivered', 'Normal', '2024-11-09 18:28:01', '2024-11-10 09:00:00', NULL, 0.00, 0, 0, 0),
(6, 6, 'Delivered', 'Important', '2024-11-12 09:49:43', '2024-11-13 16:00:00', NULL, 0.00, 0, 0, 0),
(8, 8, 'Delivered', 'Important', '2024-11-12 17:57:16', '2024-11-13 12:00:00', NULL, 0.00, 0, 0, 0),
(9, 9, 'Delivered', 'Important', '2024-11-12 18:16:47', '2024-11-13 15:00:00', NULL, 1.00, 0, 0, 0),
(10, 10, 'Pending', 'Quick', '2024-11-12 18:50:43', '2024-11-13 18:00:00', NULL, 0.00, 0, 0, 0),
(12, 12, 'Pending', 'Quick', '2024-11-13 12:25:55', NULL, NULL, 0.00, 1, 1, 0),
(17, 17, 'Pending', 'Important', '2024-11-14 22:49:41', '2024-11-16 12:00:00', NULL, 1.00, 0, 1, 0),
(18, 18, 'Pending', 'Important', '2024-11-14 23:03:27', '2024-11-16 14:00:00', NULL, 1.00, 0, 1, 0),
(19, 19, 'Delivered', 'Normal', '2024-11-15 12:18:46', '2024-11-16 14:00:00', NULL, 1.00, 0, 1, 0),
(20, 20, 'Pending', 'Important', '2024-11-16 21:28:35', '2024-11-17 11:00:00', NULL, 0.00, 0, 0, 1),
(21, 21, 'Pending', 'Important', '2024-11-16 21:52:46', '2024-11-18 12:00:00', NULL, 2.00, 0, 0, 0),
(22, 22, 'Pending', 'Important', '2024-11-17 22:21:09', NULL, NULL, 0.00, 0, 0, 1);

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

--
-- Table structure for table `order_items`
--

CREATE TABLE `order_items` (
  `id` int(11) NOT NULL,
  `order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `quantity` int(11) NOT NULL DEFAULT 1,
  `packaging_preferences` varchar(255) DEFAULT NULL,
  `discount_percentage` decimal(5,2) DEFAULT 0.00,
  `discount_reason` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `order_items`
--

INSERT INTO `order_items` (`id`, `order_id`, `product_id`, `quantity`, `packaging_preferences`, `discount_percentage`, `discount_reason`) VALUES
(5, 4, 8, 1, 'This Order type one Mahmoud Tawfik', 0.00, '<br /><b>Deprecated</b>:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in <b>/home/u406552082/domains/longevacare.com/public_html/kaakalia/public/orders/edit_order.php</b> on line <b>692</b><br />'),
(6, 5, 2, 1, '0', 20.00, 'خصم مشرف'),
(7, 4, 6, 2, 'Add Card on it', 30.00, ''),
(8, 6, 6, 1, '0', 0.00, NULL),
(10, 8, 2, 2, 'add Card on box, this card is &quot;Mahmoud Tawfik&quot;', 30.00, 'خصم المشرف'),
(11, 9, 7, 1, 'type on \"Mahmoud\"', 0.00, '<br /><b>Deprecated</b>:  htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in <b>/home/u406552082/domains/longevacare.com/public_html/kaakalia/public/orders/edit_order.php</b> on line <b>749</b><br />'),
(12, 10, 3, 1, 'Type: Mahmoud Tawfik', 0.00, NULL),
(14, 12, 8, 5, '', 0.00, ''),
(19, 12, 8, 1, '0', 0.00, '0'),
(20, 17, 6, 1, '', 30.00, 'خصم مشرف'),
(21, 17, 5, 2, '0', 25.00, '0'),
(22, 18, 7, 1, 'Add Card, Mahmoud', 30.00, 'خصم المشرف'),
(23, 18, 1, 1, 'Add Card, Ahmed', 30.00, 'خصم المشرف'),
(24, 18, 5, 1, 'Add Card, ASC', 30.00, '0'),
(25, 19, 2, 5, 'Add Card :Mahmoud Tawfik:', 30.00, 'خصم مشرف'),
(26, 20, 7, 1, 'Add New Card \"Mahmoud Tawfik\"', 30.00, 'خصم مشرف'),
(27, 21, 9, 1, '', 0.00, ''),
(28, 22, 7, 1, 'Wahab', 30.00, 'خصم مشرف'),
(29, 22, 6, 1, 'add new order', 30.00, 'خصم مشرف');

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

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` int(11) NOT NULL,
  `name` varchar(100) NOT NULL,
  `size` varchar(50) DEFAULT NULL,
  `price` decimal(10,2) NOT NULL,
  `category` varchar(50) DEFAULT NULL,
  `thumbnail` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `name`, `size`, `price`, `category`, `thumbnail`) VALUES
(1, 'Shabora', 'Half Kilo', 6.00, 'Cakes', NULL),
(2, 'Shabora', 'One Kilo', 8.00, 'Cakes', NULL),
(3, 'Shabora', 'Small Basket', 8.00, 'Cakes', NULL),
(4, 'Shabora', 'Large Basket', 10.00, 'Cakes', NULL),
(5, 'Shabora', 'Presentation Plate (Ivory)', 14.00, 'Cakes', NULL),
(6, 'Mahalbiya Crunch', '12 Pieces', 12.00, 'Desserts', NULL),
(7, 'Monkey Bread', 'Large', 12.00, 'Breads', NULL),
(8, 'Monkey Bread Mini', '12 Pieces', 6.00, 'Breads', NULL),
(9, 'Monkey Bread Mini', '9 Pieces', 9.00, 'Breads', NULL),
(11, 'Monkey Bread', 'Presentation Plate', 16.00, 'Breads', NULL);

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(50) NOT NULL,
  `email` varchar(100) DEFAULT NULL,
  `password` varchar(255) NOT NULL,
  `role` enum('admin','staff') NOT NULL,
  `profile_image` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `email`, `password`, `role`, `profile_image`) VALUES
(1, 'kaakalia', 'user@example.com', '$2y$10$tEdSPRwL8WTXljuAxNh.m.af/8sHd/ouDB21Bgs1bC7GkbRq/h0D6', 'admin', 'uploads/profile_images/profile_kaakalia_1731274341.png'),
(2, 'mahmoudtawfik', 'mahmoudtawfikh@gmail.com', '$2y$10$0yxg1R.kfbVV7GL4G9/Q3u5PK.cvv8p29R3ggkfUMC2.aRiAXb2cO', 'admin', 'uploads/profile_images/profile_mahmoudtawfik_1731274427.jpg'),
(3, 'haya', 'haya@gmail.com', '$2y$10$ri1wzOhcmT2YVGkoPYjwu.3fY8xayakQEWHjTaAFGkPfDwJ50PIh6', 'admin', 'uploads/profile_images/profile_haya_1731304053.jpg');

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

--
-- Table structure for table `workspace_notes`
--

CREATE TABLE `workspace_notes` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `content` text NOT NULL,
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `workspace_notes`
--

INSERT INTO `workspace_notes` (`id`, `user_id`, `title`, `content`, `created_at`, `updated_at`) VALUES
(2, 2, 'This important notes', 'HaloHaloHaloHaloHaloHaloHaloHaloHaloHalo', '2024-11-11 09:37:10', '2024-11-11 09:37:10');

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

--
-- Table structure for table `workspace_plans`
--

CREATE TABLE `workspace_plans` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text DEFAULT NULL,
  `audio_path` varchar(255) DEFAULT NULL,
  `due_date` datetime DEFAULT NULL,
  `status` enum('Not Started','In Progress','Completed') DEFAULT 'Not Started',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `priority` enum('Normal','Important','Critical') NOT NULL DEFAULT 'Normal'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

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

--
-- Table structure for table `workspace_posts`
--

CREATE TABLE `workspace_posts` (
  `id` int(11) NOT NULL,
  `user_id` int(11) NOT NULL,
  `platform` enum('Instagram','Facebook','Twitter','Other') NOT NULL,
  `content` text NOT NULL,
  `media_url` varchar(255) DEFAULT NULL,
  `scheduled_datetime` datetime DEFAULT NULL,
  `status` enum('Scheduled','Posted','Failed') DEFAULT 'Scheduled',
  `created_at` datetime DEFAULT current_timestamp(),
  `updated_at` datetime DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `type` enum('Post','Story') DEFAULT 'Post'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Dumping data for table `workspace_posts`
--

INSERT INTO `workspace_posts` (`id`, `user_id`, `platform`, `content`, `media_url`, `scheduled_datetime`, `status`, `created_at`, `updated_at`, `type`) VALUES
(2, 1, 'Instagram', 'Hello', NULL, '2024-11-11 01:19:00', 'Scheduled', '2024-11-10 11:16:10', '2024-11-10 11:16:10', 'Post');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `ads`
--
ALTER TABLE `ads`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `related_id` (`related_id`);

--
-- Indexes for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `ad_id` (`ad_id`);

--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `deals`
--
ALTER TABLE `deals`
  ADD PRIMARY KEY (`id`),
  ADD KEY `influencer_id` (`influencer_id`);

--
-- Indexes for table `drivers`
--
ALTER TABLE `drivers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `influencers`
--
ALTER TABLE `influencers`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `interactions`
--
ALTER TABLE `interactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `influencer_id` (`influencer_id`);

--
-- Indexes for table `notifications`
--
ALTER TABLE `notifications`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `created_at` (`created_at`);

--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `idx_orders_customer_id` (`customer_id`);

--
-- Indexes for table `order_items`
--
ALTER TABLE `order_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_id` (`order_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `idx_order_items_order_id` (`order_id`),
  ADD KEY `idx_order_items_product_id` (`product_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `username` (`username`);

--
-- Indexes for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- Indexes for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `user_id` (`user_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `ads`
--
ALTER TABLE `ads`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;

--
-- AUTO_INCREMENT for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

--
-- AUTO_INCREMENT for table `deals`
--
ALTER TABLE `deals`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `drivers`
--
ALTER TABLE `drivers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;

--
-- AUTO_INCREMENT for table `influencers`
--
ALTER TABLE `influencers`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `interactions`
--
ALTER TABLE `interactions`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `notifications`
--
ALTER TABLE `notifications`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

--
-- AUTO_INCREMENT for table `order_items`
--
ALTER TABLE `order_items`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=30;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12;

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- AUTO_INCREMENT for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `ads`
--
ALTER TABLE `ads`
  ADD CONSTRAINT `fk_ads_related_id` FOREIGN KEY (`related_id`) REFERENCES `workspace_posts` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_ads_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `ad_spend_logs`
--
ALTER TABLE `ad_spend_logs`
  ADD CONSTRAINT `fk_ad_spend_logs_ad_id` FOREIGN KEY (`ad_id`) REFERENCES `ads` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `deals`
--
ALTER TABLE `deals`
  ADD CONSTRAINT `deals_ibfk_1` FOREIGN KEY (`influencer_id`) REFERENCES `influencers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `interactions`
--
ALTER TABLE `interactions`
  ADD CONSTRAINT `interactions_ibfk_1` FOREIGN KEY (`influencer_id`) REFERENCES `influencers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `notifications`
--
ALTER TABLE `notifications`
  ADD CONSTRAINT `notifications_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `fk_orders_customer_id` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `order_items`
--
ALTER TABLE `order_items`
  ADD CONSTRAINT `fk_order_items_order_id` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_order_items_product_id` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `order_items_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `order_items_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_notes`
--
ALTER TABLE `workspace_notes`
  ADD CONSTRAINT `fk_workspace_notes_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_plans`
--
ALTER TABLE `workspace_plans`
  ADD CONSTRAINT `fk_workspace_plans_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `workspace_posts`
--
ALTER TABLE `workspace_posts`
  ADD CONSTRAINT `fk_workspace_posts_user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
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 */;) i want to fix this codes (<?php
// /public/workspace/business_development/add_influencer.php

// Enable comprehensive error reporting for debugging purposes (Disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and utility functions
require_once __DIR__ . '/../../../includes/auth.php';
require_once __DIR__ . '/../../../includes/db_connect.php';
require_once __DIR__ . '/../../../includes/functions.php'; // Contains sanitize_input() and CSRF functions

// Initialize variables
$errors = [];
$success = "";

// Initialize CSRF token
$csrf_token = generate_csrf_token();

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Validate CSRF token
    if (!isset($_POST['csrf_token']) || !verify_csrf_token($_POST['csrf_token'])) {
        $errors[] = "Invalid CSRF token.";
    }

    $name = sanitize_input($_POST['name'] ?? '');
    $contact_number = sanitize_input($_POST['contact_number'] ?? '');
    $address = sanitize_input($_POST['address'] ?? '');
    $contact_info = sanitize_input($_POST['contact_info'] ?? '');
    $social_media = sanitize_input($_POST['social_media'] ?? '');
    $notes = sanitize_input($_POST['notes'] ?? '');
    $delivery_datetime = sanitize_input($_POST['delivery_datetime'] ?? '');

    // Validation
    if (empty($name)) {
        $errors[] = "Name is required.";
    }
    if (empty($contact_number)) {
        $errors[] = "Contact number is required.";
    } elseif (!preg_match('/^\+?[0-9]{7,15}$/', $contact_number)) {
        $errors[] = "Invalid contact number format.";
    }
    if (empty($address)) {
        $errors[] = "Address is required.";
    }
    if (empty($contact_info)) {
        $errors[] = "Contact information is required.";
    } elseif (!filter_var($contact_info, FILTER_VALIDATE_EMAIL)) {
        $errors[] = "Invalid email address.";
    }

    // Validate delivery_datetime format if provided
    if (!empty($delivery_datetime) && !validate_datetime($delivery_datetime)) {
        $errors[] = "Invalid date and time format for Delivery Date-Time.";
    }

    if (empty($errors)) {
        try {
            $stmt = $conn->prepare("INSERT INTO influencers (name, contact_number, address, contact_info, social_media, notes, delivery_datetime) VALUES (?, ?, ?, ?, ?, ?, ?)");
            if (!$stmt) {
                throw new Exception("Prepare statement failed: " . $conn->error);
            }

            // Bind parameters
            if (!empty($delivery_datetime)) {
                $stmt->bind_param("sssssss", $name, $contact_number, $address, $contact_info, $social_media, $notes, $delivery_datetime);
            } else {
                $stmt->bind_param("sssssss", $name, $contact_number, $address, $contact_info, $social_media, $notes, $null = null);
            }

            $stmt->execute();
            $stmt->close();
            $success = "Influencer added successfully.";
            // Clear POST data
            $_POST = [];
            // Optionally, reset CSRF token
            $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
        } catch (Exception $e) {
            $errors[] = "An error occurred while adding the influencer.";
        }
    }
}

// Function to validate datetime format
function validate_datetime($datetime, $format = 'Y-m-d H:i') {
    $d = DateTime::createFromFormat($format, $datetime);
    return $d && $d->format($format) === $datetime;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Add Influencer - Business Development</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Flatpickr CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <!-- Custom Styles -->
    <style>
        body {
            font-family: 'Cairo', sans-serif;
        }
        .tooltip {
            position: relative;
            display: inline-block;
            cursor: pointer;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            width: 220px;
            background-color: #4B5563; /* Tailwind's gray-700 */
            color: #fff;
            text-align: left;
            border-radius: 4px;
            padding: 8px;
            position: absolute;
            z-index: 10;
            bottom: 125%; /* Position above the icon */
            left: 50%;
            margin-left: -110px;
            opacity: 0;
            transition: opacity 0.3s;
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
    </style>
</head>
<body class="bg-gray-100 dark:bg-gray-900">

    <!-- Include header.php from the shared includes directory -->
    <?php include __DIR__ . '/../../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-4 mb-20">
        <!-- Page Title -->
        <h1 class="text-3xl font-bold mb-6 flex items-center text-teal-600">
            <i class="bi bi-person-plus-fill text-teal-500 mr-2"></i> Add New Influencer
        </h1>

        <!-- Display Success Message -->
        <?php if (!empty($success)): ?>
            <div class="mb-6">
                <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded">
                    <?= htmlspecialchars($success) ?>
                </div>
            </div>
        <?php endif; ?>

        <!-- Display Errors -->
        <?php if (!empty($errors)): ?>
            <div class="mb-6">
                <?php foreach ($errors as $error): ?>
                    <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-2">
                        <?= htmlspecialchars($error) ?>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

        <!-- Add Influencer Form -->
        <div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow">
            <form action="add_influencer.php" method="POST">
                <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf_token) ?>">
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <!-- Name -->
                    <div class="mb-4">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="name">
                            Name <span class="text-red-500">*</span>
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Enter the full name of the influencer.
                                </span>
                            </span>
                        </label>
                        <input type="text" id="name" name="name" required
                               class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                               value="<?= htmlspecialchars($_POST['name'] ?? '') ?>" placeholder="Influencer Name">
                    </div>

                    <!-- Contact Number -->
                    <div class="mb-4">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="contact_number">
                            Contact Number <span class="text-red-500">*</span>
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Enter the influencer's phone number.
                                </span>
                            </span>
                        </label>
                        <input type="text" id="contact_number" name="contact_number" required
                               class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                               value="<?= htmlspecialchars($_POST['contact_number'] ?? '') ?>" placeholder="e.g., +1234567890">
                    </div>

                    <!-- Address -->
                    <div class="mb-4 md:col-span-2">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="address">
                            Address <span class="text-red-500">*</span>
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Enter the influencer's physical address.
                                </span>
                            </span>
                        </label>
                        <textarea id="address" name="address" rows="3" required
                                  class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                  placeholder="Influencer Address"><?= htmlspecialchars($_POST['address'] ?? '') ?></textarea>
                    </div>

                    <!-- Contact Info -->
                    <div class="mb-4 md:col-span-2">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="contact_info">
                            Contact Information <span class="text-red-500">*</span>
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Provide the email address or alternative contact info for the influencer.
                                </span>
                            </span>
                        </label>
                        <input type="email" id="contact_info" name="contact_info" required
                               class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                               value="<?= htmlspecialchars($_POST['contact_info'] ?? '') ?>" placeholder="e.g., influencer@example.com">
                    </div>

                    <!-- Social Media Handles -->
                    <div class="mb-4 md:col-span-2">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="social_media">
                            Social Media Handles
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Include the influencer's social media profiles, separated by commas.
                                </span>
                            </span>
                        </label>
                        <input type="text" id="social_media" name="social_media"
                               class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                               value="<?= htmlspecialchars($_POST['social_media'] ?? '') ?>" placeholder="e.g., Instagram: @influencer, Twitter: @influencer">
                    </div>

                    <!-- Delivery Date-Time -->
                    <div class="mb-4 md:col-span-2">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="delivery_datetime">
                            Delivery Date-Time
                            <span class="tooltip">
                                <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                <span class="tooltiptext">
                                    Select the scheduled date and time for delivery to the influencer.
                                </span>
                            </span>
                        </label>
                        <input type="text" id="delivery_datetime" name="delivery_datetime"
                               class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline flatpickr"
                               value="<?= htmlspecialchars($_POST['delivery_datetime'] ?? '') ?>" placeholder="Select Date and Time">
                    </div>

                    <!-- Notes -->
                    <div class="mb-4 md:col-span-2">
                        <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="notes">
                            Notes
                        </label>
                        <textarea id="notes" name="notes" rows="4"
                                  class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                  placeholder="Additional notes about the influencer"><?= htmlspecialchars($_POST['notes'] ?? '') ?></textarea>
                    </div>
                </div>
                <div class="flex items-center justify-between mt-6">
                    <button type="submit"
                            class="bg-teal-500 hover:bg-teal-600 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline flex items-center">
                        <i class="bi bi-plus-circle-fill mr-2"></i> Add Influencer
                    </button>
                    <a href="index.php"
                       class="text-gray-500 hover:text-gray-700 flex items-center">
                        <i class="bi bi-arrow-left-circle-fill mr-2"></i> Back to Influencers
                    </a>
                </div>
            </form>
        </div>
    </main>

    <!-- Include footer.php from the shared includes directory -->
    <?php include __DIR__ . '/../../../includes/footer.php'; ?>

    <!-- Tailwind JS (Optional for interactive components) -->
    <script src="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.js"></script>
    
    <!-- Flatpickr JS -->
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    <script>
        // Initialize Flatpickr for delivery_datetime
        flatpickr("#delivery_datetime", {
            enableTime: true,
            dateFormat: "Y-m-d H:i",
            minDate: "today"
        });
    </script>
</body>
</html>

<?php
// Flush the output buffer
ob_end_flush();
// No closing PHP tag to prevent unwanted output
?>) (Fatal error: Uncaught Error: Call to undefined function generate_csrf_token() in /home/u406552082/domains/longevacare.com/public_html/kaakalia/public/workspace/business_development/add_influencer.php:22 Stack trace: #0 {main} thrown in /home/u406552082/domains/longevacare.com/public_html/kaakalia/public/workspace/business_development/add_influencer.php on line 22) so please fix and add more codes to make it working well and fix this (<?php
// /public/workspace/business_development/delete_influencer.php

// Enable comprehensive error reporting for debugging purposes (Disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and functions
require_once __DIR__ . '/../../../includes/auth.php';
require_once __DIR__ . '/../../../includes/db_connect.php';
require_once __DIR__ . '/../../../includes/functions.php'; // Contains sanitize_input() and log_action()

// Verify that required functions exist
if (!function_exists('sanitize_input') || !function_exists('log_action')) {
    die("Error: Required functions are not defined.");
}

// Ensure the user is authenticated and is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header("Location: /public/login.php");
    exit();
}

// Initialize variables
$errors = [];
$success = "";

// Handle deletion via POST request
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Validate CSRF token
    if (!isset($_POST['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
        $errors[] = "Invalid CSRF token.";
    }

    // Get influencer ID from POST
    if (isset($_POST['id']) && is_numeric($_POST['id'])) {
        $influencer_id = (int) $_POST['id'];

        try {
            // Check if influencer exists
            $stmt = $conn->prepare("SELECT * FROM influencers WHERE id = ?");
            if (!$stmt) {
                throw new Exception("Prepare statement failed: " . $conn->error);
            }
            $stmt->bind_param("i", $influencer_id);
            $stmt->execute();
            $result = $stmt->get_result();
            if ($result->num_rows === 0) {
                throw new Exception("Influencer not found.");
            }
            $stmt->close();

            // Delete influencer
            $stmt = $conn->prepare("DELETE FROM influencers WHERE id = ?");
            if (!$stmt) {
                throw new Exception("Prepare statement failed: " . $conn->error);
            }
            $stmt->bind_param("i", $influencer_id);
            $stmt->execute();
            $stmt->close();

            // Log the deletion action
            log_action($_SESSION['user_id'], 'Delete Influencer', "Deleted influencer ID: $influencer_id");

            $success = "Influencer deleted successfully.";
        } catch (Exception $e) {
            $errors[] = $e->getMessage();
        }
    } else {
        $errors[] = "Invalid influencer ID.";
    }

    // Store feedback in session and redirect back to index
    if (!empty($success)) {
        $_SESSION['delete_success'] = $success;
    }
    if (!empty($errors)) {
        $_SESSION['delete_errors'] = $errors;
    }
    header("Location: index.php");
    exit();
} else {
    // Redirect if accessed via GET
    header("Location: index.php");
    exit();
}
?>) and (<?php
// /public/workspace/business_development/edit_influencer.php

// Enable comprehensive error reporting for debugging purposes (Disable in production)
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// Start output buffering to prevent "headers already sent" errors
ob_start();

// Include authentication, database connection, and functions
require_once __DIR__ . '/../../../includes/auth.php';
require_once __DIR__ . '/../../../includes/db_connect.php';
require_once __DIR__ . '/../../../includes/functions.php'; // Contains sanitize_input() and generate_csrf_token()

// Verify that required functions exist
if (!function_exists('sanitize_input') || !function_exists('generate_csrf_token')) {
    die("Error: Required functions are not defined.");
}

// Ensure the user is authenticated and is an admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header("Location: /public/login.php");
    exit();
}

// Initialize variables
$errors = [];
$success = "";

// Initialize CSRF token
$csrf_token = generate_csrf_token();

// Get influencer ID from GET parameter
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header("Location: index.php");
    exit();
}

$influencer_id = (int) $_GET['id'];

// Fetch existing influencer data
try {
    $stmt = $conn->prepare("SELECT * FROM influencers WHERE id = ?");
    if (!$stmt) {
        throw new Exception("Prepare statement failed: " . $conn->error);
    }
    $stmt->bind_param("i", $influencer_id);
    $stmt->execute();
    $result = $stmt->get_result();
    if ($result->num_rows === 0) {
        throw new Exception("Influencer not found.");
    }
    $influencer = $result->fetch_assoc();
    $stmt->close();
} catch (Exception $e) {
    $errors[] = $e->getMessage();
    $influencer = null;
}

// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $influencer) {
    // Validate CSRF token
    if (!isset($_POST['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
        $errors[] = "Invalid CSRF token.";
    }

    $name = sanitize_input($_POST['name'] ?? '');
    $contact_number = sanitize_input($_POST['contact_number'] ?? '');
    $address = sanitize_input($_POST['address'] ?? '');
    $contact_info = sanitize_input($_POST['contact_info'] ?? '');
    $social_media = sanitize_input($_POST['social_media'] ?? '');
    $notes = sanitize_input($_POST['notes'] ?? '');
    $delivery_datetime = sanitize_input($_POST['delivery_datetime'] ?? '');

    // Validation
    if (empty($name)) {
        $errors[] = "Name is required.";
    }
    if (empty($contact_number)) {
        $errors[] = "Contact number is required.";
    } elseif (!preg_match('/^\+?[0-9]{7,15}$/', $contact_number)) {
        $errors[] = "Invalid contact number format.";
    }
    if (empty($address)) {
        $errors[] = "Address is required.";
    }
    if (empty($contact_info)) {
        $errors[] = "Contact information is required.";
    } elseif (!filter_var($contact_info, FILTER_VALIDATE_EMAIL)) {
        $errors[] = "Invalid email address.";
    }

    // Validate delivery_datetime format if provided
    if (!empty($delivery_datetime) && !validate_datetime($delivery_datetime)) {
        $errors[] = "Invalid date and time format for Delivery Date-Time.";
    }

    if (empty($errors)) {
        try {
            $stmt = $conn->prepare("UPDATE influencers SET name = ?, contact_number = ?, address = ?, contact_info = ?, social_media = ?, notes = ?, delivery_datetime = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ?");
            if (!$stmt) {
                throw new Exception("Prepare statement failed: " . $conn->error);
            }

            // Bind parameters
            if (!empty($delivery_datetime)) {
                $stmt->bind_param("sssssssi", $name, $contact_number, $address, $contact_info, $social_media, $notes, $delivery_datetime, $influencer_id);
            } else {
                $stmt->bind_param("sssssssi", $name, $contact_number, $address, $contact_info, $social_media, $notes, $null = null, $influencer_id);
            }

            $stmt->execute();
            $stmt->close();
            $success = "Influencer updated successfully.";
            // Refresh influencer data
            $influencer['name'] = $name;
            $influencer['contact_number'] = $contact_number;
            $influencer['address'] = $address;
            $influencer['contact_info'] = $contact_info;
            $influencer['social_media'] = $social_media;
            $influencer['notes'] = $notes;
            $influencer['delivery_datetime'] = $delivery_datetime;
            // Optionally, reset CSRF token
            $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
        } catch (Exception $e) {
            $errors[] = "An error occurred while updating the influencer.";
        }
    }
}

// Function to validate datetime format
function validate_datetime($datetime, $format = 'Y-m-d H:i') {
    $d = DateTime::createFromFormat($format, $datetime);
    return $d && $d->format($format) === $datetime;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Edit Influencer - Business Development</title>
    <!-- Tailwind CSS -->
    <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Flatpickr CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
    <!-- Custom Styles -->
    <style>
        body {
            font-family: 'Cairo', sans-serif;
        }
        .tooltip {
            position: relative;
            display: inline-block;
            cursor: pointer;
        }

        .tooltip .tooltiptext {
            visibility: hidden;
            width: 220px;
            background-color: #6B7280; /* Tailwind's gray-500 */
            color: #fff;
            text-align: left;
            border-radius: 4px;
            padding: 8px;
            position: absolute;
            z-index: 10;
            bottom: 125%; /* Position above the icon */
            left: 50%;
            margin-left: -110px;
            opacity: 0;
            transition: opacity 0.3s;
        }

        .tooltip:hover .tooltiptext {
            visibility: visible;
            opacity: 1;
        }
    </style>
</head>
<body class="bg-gray-100 dark:bg-gray-900">

    <!-- Include header.php from the shared includes directory -->
    <?php include __DIR__ . '/../../../includes/header.php'; ?>

    <!-- Main Content -->
    <main class="container mx-auto p-6 mt-4 mb-20">
        <h1 class="text-3xl font-bold mb-6 flex items-center text-teal-600">
            <i class="bi bi-pencil-square text-teal-500 mr-2"></i> Edit Influencer
        </h1>

        <!-- Display Success Message -->
        <?php if (!empty($success)): ?>
            <div class="mb-6">
                <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded">
                    <?= htmlspecialchars($success) ?>
                </div>
            </div>
        <?php endif; ?>

        <!-- Display Errors -->
        <?php if (!empty($errors)): ?>
            <div class="mb-6">
                <?php foreach ($errors as $error): ?>
                    <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-2">
                        <?= htmlspecialchars($error) ?>
                    </div>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>

        <?php if ($influencer): ?>
            <!-- Edit Influencer Form -->
            <div class="bg-white dark:bg-gray-800 p-6 rounded-lg shadow">
                <form action="edit_influencer.php?id=<?= urlencode($influencer_id) ?>" method="POST">
                    <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf_token) ?>">
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <!-- Name -->
                        <div class="mb-4">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="name">
                                Name <span class="text-red-500">*</span>
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Enter the full name of the influencer.
                                    </span>
                                </span>
                            </label>
                            <input type="text" id="name" name="name" required
                                   class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                   value="<?= htmlspecialchars($influencer['name'] ?? '') ?>" placeholder="Influencer Name">
                        </div>

                        <!-- Contact Number -->
                        <div class="mb-4">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="contact_number">
                                Contact Number <span class="text-red-500">*</span>
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Enter the influencer's phone number.
                                    </span>
                                </span>
                            </label>
                            <input type="text" id="contact_number" name="contact_number" required
                                   class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                   value="<?= htmlspecialchars($influencer['contact_number'] ?? '') ?>" placeholder="e.g., +1234567890">
                        </div>

                        <!-- Address -->
                        <div class="mb-4 md:col-span-2">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="address">
                                Address <span class="text-red-500">*</span>
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Enter the influencer's physical address.
                                    </span>
                                </span>
                            </label>
                            <textarea id="address" name="address" rows="3" required
                                      class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                      placeholder="Influencer Address"><?= htmlspecialchars($influencer['address'] ?? '') ?></textarea>
                        </div>

                        <!-- Contact Info -->
                        <div class="mb-4 md:col-span-2">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="contact_info">
                                Contact Information <span class="text-red-500">*</span>
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Provide the email address or alternative contact info for the influencer.
                                    </span>
                                </span>
                            </label>
                            <input type="email" id="contact_info" name="contact_info" required
                                   class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                   value="<?= htmlspecialchars($influencer['contact_info'] ?? '') ?>" placeholder="e.g., influencer@example.com">
                        </div>

                        <!-- Social Media Handles -->
                        <div class="mb-4 md:col-span-2">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="social_media">
                                Social Media Handles
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Include the influencer's social media profiles, separated by commas.
                                    </span>
                                </span>
                            </label>
                            <input type="text" id="social_media" name="social_media"
                                   class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                   value="<?= htmlspecialchars($influencer['social_media'] ?? '') ?>" placeholder="e.g., Instagram: @influencer, Twitter: @influencer">
                        </div>

                        <!-- Delivery Date-Time -->
                        <div class="mb-4 md:col-span-2">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="delivery_datetime">
                                Delivery Date-Time
                                <span class="tooltip">
                                    <i class="bi bi-question-circle text-gray-400 text-sm"></i>
                                    <span class="tooltiptext">
                                        Select the scheduled date and time for delivery to the influencer.
                                    </span>
                                </span>
                            </label>
                            <input type="text" id="delivery_datetime" name="delivery_datetime"
                                   class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline flatpickr"
                                   value="<?= htmlspecialchars($influencer['delivery_datetime'] ?? '') ?>" placeholder="Select Date and Time">
                        </div>

                        <!-- Notes -->
                        <div class="mb-4 md:col-span-2">
                            <label class="block text-gray-700 dark:text-gray-300 text-sm font-bold mb-2" for="notes">
                                Notes
                            </label>
                            <textarea id="notes" name="notes" rows="4"
                                      class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 focus:outline-none focus:shadow-outline"
                                      placeholder="Additional notes about the influencer"><?= htmlspecialchars($influencer['notes'] ?? '') ?></textarea>
                        </div>
                    </div>
                    <div class="flex items-center justify-between mt-6">
                        <button type="submit"
                                class="bg-teal-500 hover:bg-teal-600 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline flex items-center">
                            <i class="bi bi-check-circle-fill mr-2"></i> Update Influencer
                        </button>
                        <a href="index.php"
                           class="text-gray-500 hover:text-gray-700 flex items-center">
                            <i class="bi bi-arrow-left-circle-fill mr-2"></i> Back to Influencers
                        </a>
                    </div>
                </form>
            </div>
        <?php endif; ?>
    </main>

    <!-- Include footer.php from the shared includes directory -->
    <?php include __DIR__ . '/../../../includes/footer.php'; ?>

    <!-- Tailwind JS (Optional for interactive components) -->
    <script src="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.js"></script>
    
    <!-- Flatpickr JS -->
    <script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
    <script>
        // Initialize Flatpickr for delivery_datetime
        flatpickr("#delivery_datetime", {
            enableTime: true,
            dateFormat: "Y-m-d H:i",
            minDate: "today"
        });
    </script>
</body>
</html>

<?php
// Flush the output buffer
ob_end_flush();
// No closing PHP tag to prevent unwanted output
?>) and type full codes