add_stage.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. //error_reporting(E_ERROR | E_PARSE);
  3. error_reporting(E_ALL);
  4. ini_set("display_errors", 1);
  5. date_default_timezone_set("Australia/Hobart");
  6. ini_set("default_charset", "UTF-8");
  7. mb_internal_encoding("UTF-8");
  8. require_once 'config.php';
  9. $cfg = require __DIR__ . '/config.php';
  10. use PHPMailer\PHPMailer\PHPMailer;
  11. use PHPMailer\PHPMailer\Exception;
  12. require_once __DIR__ . '/vendor/autoload.php';
  13. $cfg = require __DIR__ . '/config.php';
  14. $dsn = 'mysql:host=' . $cfg['db_host'] . ';dbname=' . $cfg['db_name'] . ';charset=utf8mb4';
  15. $options = [
  16. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  17. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  18. ];
  19. try {
  20. $pdo = new PDO($dsn, $cfg['db_username'], $cfg['db_password'], $options);
  21. } catch (PDOException $e) {
  22. exit('Database connection failed: ' . $e->getMessage());
  23. }
  24. $app_id = $_POST['application_id'];
  25. $title = $_POST['title'];
  26. $desc = $_POST['description'];
  27. // Save stage
  28. $stmt = $pdo->prepare("INSERT INTO application_stages (application_id, title, description) VALUES (?, ?, ?)");
  29. $stmt->execute([$app_id, $title, $desc]);
  30. // Fetch client email
  31. $stmt = $pdo->prepare("SELECT client_email FROM applications WHERE id = ?");
  32. $stmt->execute([$app_id]);
  33. $email = $stmt->fetchColumn();
  34. function sendStageEmail($to, $title, $desc, $viewUrl) {
  35. global $cfg;
  36. $mail = new PHPMailer(true);
  37. $mail->isSMTP();
  38. $mail->Host = $cfg['smtp_host'];
  39. $mail->SMTPAuth = true;
  40. $mail->Username = $cfg['smtp_username'];
  41. $mail->Password = $cfg['smtp_password'];
  42. $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
  43. $mail->Port = $cfg['smtp_port'];
  44. $mail->setFrom($cfg['from_address'], $cfg['dev_company']);
  45. $mail->addAddress($to);
  46. $mail->isHTML(true);
  47. $subject = "Council Application Progress Update";
  48. $html = <<<HTML
  49. <p>Hello,</p>
  50. <p>Your application has reached a new stage: <strong>{$title}</strong></p>
  51. <p>{$desc}</p>
  52. <p><a href="{$viewUrl}" class="btn btn-primary">View Application Progress</a></p>
  53. <p>Kind regards,<br>{$cfg['dev_name']}<br>{$cfg['dev_company']}</p>
  54. HTML;
  55. $mail->Subject = $subject;
  56. $mail->Body = $html;
  57. $mail->AltBody = "New update: $title\n\n$desc\n\nView: $viewUrl";
  58. $mail->send();
  59. }
  60. // Redirect back to admin dashboard
  61. header("Location: admin_dashboard.php");