diff --git a/add_activity.php b/add_activity.php new file mode 100644 index 0000000..b9fafab --- /dev/null +++ b/add_activity.php @@ -0,0 +1,35 @@ +prepare("INSERT INTO activities (LeadID, ActivityType, DueDate, Notes) VALUES (:lead_id, :activity_type, :due_date, :notes)"); + $stmt->execute([ + ':lead_id' => $lead_id, + ':activity_type' => $activity_type, + ':due_date' => !empty($due_date) ? $due_date : null, + ':notes' => $notes + ]); + + $_SESSION['success_message'] = "New activity added successfully!"; + + } catch (PDOException $e) { + $_SESSION['error_message'] = "Error adding activity: " . $e->getMessage(); + } + } else { + $_SESSION['error_message'] = "Lead ID and activity type are required."; + } +} else { + $_SESSION['error_message'] = "Invalid request method."; +} + +header("Location: index.php"); +exit; diff --git a/add_lead.php b/add_lead.php new file mode 100644 index 0000000..ae8b23d --- /dev/null +++ b/add_lead.php @@ -0,0 +1,57 @@ +prepare( + 'INSERT INTO leads (Name, CompanyName, Email, Phone, PotentialAmount, Status) VALUES (?, ?, ?, ?, ?, ?)' + ); + $stmt->execute([ + $name, + $companyName, + $email, + $phone, + $potentialAmount, + 'New' // Default status + ]); + + $_SESSION['success_message'] = 'Lead added successfully!'; + +} catch (PDOException $e) { + // In a real app, log this error. + $_SESSION['error_message'] = 'Failed to add lead. Please try again.'; +} + +header('Location: index.php'); +exit(); diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..cddfe1e --- /dev/null +++ b/dashboard.php @@ -0,0 +1,170 @@ +query('SELECT COUNT(*) FROM leads')->fetchColumn(); + + // Leads per status + $leads_per_status_stmt = $pdo->query('SELECT Status, COUNT(*) as count FROM leads GROUP BY Status'); + $leads_per_status = $leads_per_status_stmt->fetchAll(PDO::FETCH_KEY_PAIR); + + // Total activities + $total_activities = $pdo->query('SELECT COUNT(*) FROM activities')->fetchColumn(); + + // Activities per type + $activities_per_type_stmt = $pdo->query('SELECT ActivityType, COUNT(*) as count FROM activities GROUP BY ActivityType'); + $activities_per_type = $activities_per_type_stmt->fetchAll(PDO::FETCH_KEY_PAIR); + +} catch (PDOException $e) { + $db_error = "Error fetching dashboard data: " . $e->getMessage(); +} + +$projectName = $_SERVER['PROJECT_NAME'] ?? 'CRM'; +?> + + + + + + Dashboard - <?= htmlspecialchars($projectName) ?> + + + + + + + + +
+ +
+ +
+
+
+
+
Total Leads
+

+
+
+
+
+
+
+
Total Activities
+

+
+
+
+
+
+
+
+
Leads by Status
+
+ +
+
+
+
+
+
Activities by Type
+
+ +
+
+
+
+ +
+ + + + + diff --git a/db/config.php b/db/config.php index 1ab5020..2e6be0d 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,45 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; -} +// IMPORTANT: Do not output any HTML or echo statements in this file. +// This file is intended for configuration and database connection logic. + +/** + * Establishes a database connection using PDO. + * + * @return PDO The PDO database connection object. + */ +function db(): PDO +{ + static $pdo = null; + + if ($pdo) { + return $pdo; + } + + // Database credentials from environment variables + $host = getenv('DB_HOST') ?: '127.0.0.1'; + $port = getenv('DB_PORT') ?: '3306'; + // Temporary fix: Hardcoded credentials to solve an environment issue where Apache cannot access the correct variables. + $dbname = 'app_36806'; + $user = 'app_36806'; + $pass = '72fbec7a-4020-4357-9e44-f0aad5499af6'; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;port=$port;dbname=$dbname;charset=$charset"; + + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + + try { + $pdo = new PDO($dsn, $user, $pass, $options); + } catch (PDOException $e) { + // In a real application, you would log this error and show a generic error page. + // For development, it's okay to die and show the error. + throw new PDOException($e->getMessage(), (int)$e->getCode()); + } + + return $pdo; +} \ No newline at end of file diff --git a/db/database.sql b/db/database.sql new file mode 100644 index 0000000..c091ca8 --- /dev/null +++ b/db/database.sql @@ -0,0 +1,22 @@ +CREATE TABLE IF NOT EXISTS leads ( + LeadID INT AUTO_INCREMENT PRIMARY KEY, + Name VARCHAR(255) NOT NULL, + CompanyName VARCHAR(255), + Email VARCHAR(255), + Phone VARCHAR(50), + Source VARCHAR(100) NULL, + Status VARCHAR(50) DEFAULT 'New', + PotentialAmount DECIMAL(12, 2) NULL, + CreatedOn TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE IF NOT EXISTS activities ( + ActivityID INT AUTO_INCREMENT PRIMARY KEY, + LeadID INT, + ActivityType VARCHAR(50) NOT NULL, + DueDate DATE, + Status VARCHAR(50) DEFAULT 'Pending', + Notes TEXT, + CreatedOn TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + FOREIGN KEY (LeadID) REFERENCES leads(LeadID) ON DELETE CASCADE +); diff --git a/db/init_db.php b/db/init_db.php new file mode 100644 index 0000000..a8e752c --- /dev/null +++ b/db/init_db.php @@ -0,0 +1,12 @@ +exec($sql); + echo "Database initialized successfully with 'leads' table. +"; +} catch (PDOException $e) { + die("Database initialization failed: " . $e->getMessage()); +} diff --git a/delete_activity.php b/delete_activity.php new file mode 100644 index 0000000..326df63 --- /dev/null +++ b/delete_activity.php @@ -0,0 +1,28 @@ +prepare("DELETE FROM activities WHERE ActivityID = ?"); + $stmt->execute([$activity_id]); + + if ($stmt->rowCount() > 0) { + $_SESSION['success_message'] = 'Activity deleted successfully!'; + } else { + $_SESSION['error_message'] = 'Activity not found or already deleted.'; + } +} catch (PDOException $e) { + $_SESSION['error_message'] = 'Error deleting activity: ' . $e->getMessage(); +} + +header('Location: index.php'); +exit; diff --git a/delete_lead.php b/delete_lead.php new file mode 100644 index 0000000..fd13a3f --- /dev/null +++ b/delete_lead.php @@ -0,0 +1,28 @@ +prepare("DELETE FROM leads WHERE LeadID = ?"); + $stmt->execute([$lead_id]); + + if ($stmt->rowCount() > 0) { + $_SESSION['success_message'] = 'Lead deleted successfully!'; + } else { + $_SESSION['error_message'] = 'Lead not found or already deleted.'; + } +} catch (PDOException $e) { + $_SESSION['error_message'] = 'Error deleting lead: ' . $e->getMessage(); +} + +header('Location: index.php'); +exit; diff --git a/edit_activity.php b/edit_activity.php new file mode 100644 index 0000000..a7abda3 --- /dev/null +++ b/edit_activity.php @@ -0,0 +1,115 @@ +prepare('SELECT * FROM activities WHERE ActivityID = ?'); + $stmt->execute([$activity_id]); + $activity = $stmt->fetch(); + + if (!$activity) { + $_SESSION['error_message'] = 'Activity not found.'; + header('Location: index.php'); + exit(); + } +} catch (PDOException $e) { + $_SESSION['error_message'] = 'Error fetching activity details: ' . $e->getMessage(); + header('Location: index.php'); + exit(); +} + +$projectName = $_SERVER['PROJECT_NAME'] ?? 'CRM'; +?> + + + + + + Edit Activity - <?= htmlspecialchars($projectName) ?> + + + + + + + +
+
+
+
+
+
Edit Activity
+
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Cancel + +
+
+
+
+
+
+
+ + + + diff --git a/edit_lead.php b/edit_lead.php new file mode 100644 index 0000000..9386866 --- /dev/null +++ b/edit_lead.php @@ -0,0 +1,122 @@ +prepare('SELECT * FROM leads WHERE LeadID = ?'); + $stmt->execute([$lead_id]); + $lead = $stmt->fetch(); + + if (!$lead) { + $_SESSION['error_message'] = 'Lead not found.'; + header('Location: index.php'); + exit(); + } +} catch (PDOException $e) { + $_SESSION['error_message'] = 'Error fetching lead details: ' . $e->getMessage(); + header('Location: index.php'); + exit(); +} + +$projectName = $_SERVER['PROJECT_NAME'] ?? 'CRM'; +?> + + + + + + Edit Lead - <?= htmlspecialchars($projectName) ?> + + + + + + + +
+
+
+
+
+
Edit Lead
+
+
+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Cancel + +
+
+
+
+
+
+
+ + + + diff --git a/index.php b/index.php index 7205f3d..b2ee6ac 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,447 @@ prepare($sql); + $stmt->execute($params); + $leads = $stmt->fetchAll(); + + // Fetch all activities + $stmt = $pdo->query('SELECT ActivityID, LeadID, ActivityType, DueDate, Status, Notes, CreatedOn FROM activities ORDER BY DueDate ASC'); + $all_activities = $stmt->fetchAll(); + + // Group activities by LeadID for easy lookup + $activitiesByLead = []; + foreach ($all_activities as $activity) { + $activitiesByLead[$activity['LeadID']][] = $activity; + } + +} catch (PDOException $e) { + $leads = []; + $activitiesByLead = []; + $db_error = "Error fetching data: " . $e->getMessage(); +} + +$success_message = $_SESSION['success_message'] ?? null; +$error_message = $_SESSION['error_message'] ?? null; + +// Clear session messages +unset($_SESSION['success_message'], $_SESSION['error_message']); + +$projectName = $_SERVER['PROJECT_NAME'] ?? 'CRM'; +$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'A simple and powerful CRM for your business.'; ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + <?= htmlspecialchars($projectName) ?> - Leads + + + + + + + + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+ + + + + +
+
+ + +
+
+
+
Add New Lead
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ + +
+
+
+
Current Leads
+
+
+
+ + +
+ +
+ Clear +
+
+
+ +
+ +
+

No leads yet. Add one using the form!

+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NameCompanyContactPotentialStatusDateActions
+ + $ + + + + + Edit + + + Delete + + +
+
+ +
+
+
+
+
+ + +
- + + + + + + + + + + +
+ + + + + + +
+ + + + + + - + \ No newline at end of file diff --git a/update_activity.php b/update_activity.php new file mode 100644 index 0000000..b4d99cd --- /dev/null +++ b/update_activity.php @@ -0,0 +1,44 @@ +prepare( + 'UPDATE activities SET ActivityType = ?, Status = ?, DueDate = ?, Notes = ? WHERE ActivityID = ?' + ); + $stmt->execute([ + $activity_type, + $status, + $due_date, + $notes, + $activity_id + ]); + + $_SESSION['success_message'] = 'Activity updated successfully!'; + +} catch (PDOException $e) { + // In a real app, log this error. + $_SESSION['error_message'] = 'Failed to update activity. Please try again.'; +} + +header('Location: index.php'); +exit(); diff --git a/update_lead.php b/update_lead.php new file mode 100644 index 0000000..64348b7 --- /dev/null +++ b/update_lead.php @@ -0,0 +1,60 @@ +prepare( + 'UPDATE leads SET Name = ?, CompanyName = ?, Email = ?, Phone = ?, PotentialAmount = ?, Status = ? WHERE LeadID = ?' + ); + $stmt->execute([ + $name, + $companyName, + $email, + $phone, + $potentialAmount, + $status, + $lead_id + ]); + + $_SESSION['success_message'] = 'Lead updated successfully!'; + +} catch (PDOException $e) { + // In a real app, log this error. + $_SESSION['error_message'] = 'Failed to update lead. Please try again.'; +} + +header('Location: index.php'); +exit();