Files
willes_AI/saved_emails.php

47 lines
1.5 KiB
PHP

<?php
// /saved_emails.php
session_start();
require_once($_SERVER['DOCUMENT_ROOT'] . '/inc/php/auth.php');
requireLogin();
require_once($_SERVER['DOCUMENT_ROOT'] . '/db.php');
$conn = getConnection();
$user_id = $_SESSION['user_id'] ?? null;
$stmt = $conn->prepare("
SELECT id, subject, body, created_at
FROM saved_emails
WHERE user_id = :user_id
ORDER BY created_at DESC
");
$stmt->execute([':user_id' => $user_id]);
$emails = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/header.php'); ?>
<body>
<div class="container">
<h1>📑 Saved Emails</h1>
<?php if (!empty($emails)): ?>
<table>
<tr><th>Subject</th><th>Preview</th><th>Date</th><th>Action</th></tr>
<?php foreach ($emails as $email): ?>
<tr>
<td><?= htmlspecialchars($email['subject'] ?: '(No Subject)') ?></td>
<td><?= htmlspecialchars(substr($email['body'], 0, 50)) ?>...</td>
<td><?= $email['created_at'] ?></td>
<td>
<a href="/view_email.php?id=<?= $email['id'] ?>"><button>View</button></a>
<a href="/inc/php/delete_email.php?id=<?= $email['id'] ?>" onclick="return confirm('Delete this email?')"><button>Delete</button></a>
</td>
</tr>
<?php endforeach; ?>
</table>
<?php else: ?>
<p>No saved emails yet.</p>
<?php endif; ?>
</div>
<?php include($_SERVER['DOCUMENT_ROOT'] . '/inc/php/footer.php'); ?>