Skip to content

Commit

Permalink
QAC Send email
Browse files Browse the repository at this point in the history
  • Loading branch information
lechiluan committed Apr 15, 2023
1 parent bd0c1cc commit 64d4894
Show file tree
Hide file tree
Showing 19 changed files with 2,905 additions and 979 deletions.
655 changes: 655 additions & 0 deletions QAC_All_Ideas.php

Large diffs are not rendered by default.

656 changes: 656 additions & 0 deletions QAC_Idea_By_Department.php

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions QAC_Send_Notification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
include("connection.php");
session_start(); // Start the session
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';

if (isset($_GET['topic'])) {
$topic = $_GET['topic'];
$department_id = $_SESSION['department_id'];
// Get all staff email addresses of my department
$sql = "SELECT Email FROM staff WHERE DepartmentID = '$department_id'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
$mail = new PHPMailer(true);

try {
// Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'iebdmpqvvkpjglec';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

$mail->setFrom('[email protected]', 'Greenwich QA');
// Loop through all staff email addresses and add them as recipients
while ($row = mysqli_fetch_assoc($result)) {
$mail->addAddress($row['Email']);
}

// Content
$mail->isHTML(true);
$mail->Subject = 'New idea has been submitted';
$mail->Body = "Dear staff,<br><br>There is a new idea has been submitted for $topic. Plaese add more ideas to this topic to improve the quality of the topic.<br><br>Thank you.<br><br>Greenwich QA<br><br>";
$mail->send();
echo "<script>alert('Email sent successfully.')</script>";
// Reload current page after sending email
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
} catch (Exception $e) {
echo "<script>alert('Message could not be sent. Mailer Error: {$mail->ErrorInfo}')</script>";
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
}
} else {
echo "<script>alert('No staff found in your department.')</script>";
echo "<script>window.location.href = 'QAC_Topic_Detail.php?topic=$topic'</script>";
}
}
?>
2 changes: 1 addition & 1 deletion QAC_Staff.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down
2 changes: 1 addition & 1 deletion QAC_Topic.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down
70 changes: 59 additions & 11 deletions QAC_Topic_Detail.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php
include("connection.php");
session_start(); // Start the session
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
if (!isset($_SESSION['login'])) {
header("Location: index.php");
} else {
Expand Down Expand Up @@ -43,7 +46,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down Expand Up @@ -89,24 +92,29 @@ class="rounded-circle me-2"
<div class="d-flex flex-column justify-content-center mx-auto main-container">
<div class="row">
<div class="col-lg-4">
<?php
if (isset($_GET['topic'])) {
$topic = $_GET['topic'];
}
?>
<!-- Send notification for Staff form -->
<div class="bg-light p-3 text-center mb-3">
<a href="#"
<a href="QAC_Send_Notification.php?topic=<?php echo $topic; ?>"
class="text-decoration-none text-dark d-flex flex-column align-items-center">
<i class="fas fa-bell fa-3x mb-3"></i>
<h5 class="mb-2">Send notification for Staff</h5>
</a>
</div>

<div class="bg-light p-3 text-center mb-3">
<div class="d-flex justify-content-between">
<a href="#"
<a href="QAC_All_Ideas.php?topic=<?php echo $topic; ?>"
class="text-decoration-none text-dark d-flex flex-column align-items-center border rounded p-2">
<i class="fas fa-list fa-2x mb-2"></i>
<span class="font-weight-bold">View All idea post</span>
</a>
<a href="#"
class="text-decoration-none text-dark d-flex flex-column align-items-center border rounded p-2">
<a href="QAC_Idea_By_Department.php?topic=<?php echo $topic; ?>"
class=" text-decoration-none text-dark d-flex flex-column align-items-center
border rounded p-2">
<i class="fas fa-building fa-2x mb-2"></i>
<span class="font-weight-bold">View by department</span>
</a>
Expand Down Expand Up @@ -474,9 +482,6 @@ class="btn btn-outline-secondary btn-sm comment-toggle"
include("connection.php");
// add comment for topic
if (isset($_POST['add-comment'])) {
if (isset($_GET['topic'])) {
$topic = $_GET['topic'];
}
$ideaID = $_POST['ideaID'];
$content = $_POST['commentContent'];
$staffID = $_SESSION['staff_id'];
Expand All @@ -486,8 +491,51 @@ class="btn btn-outline-secondary btn-sm comment-toggle"
$sql = "INSERT INTO Comment (CommentContent, StaffID, IdeaID, is_anonymous, CommentDate) VALUES ('$content', '$staffID', '$ideaID', '$isAnonymous', '$commentDate')";

if (mysqli_query($conn, $sql)) {
echo "<script>alert('Comment added successfully!')</script>";
echo "<script>window.location.href='QAC_Topic_Detail.php?topic=" . $topic . "'</script>";
// The author of an idea receives an automatic email notification whenever a comment is submitted to any of their ideas.
$sql2 = "SELECT * FROM Idea WHERE IdeaID = '$ideaID'";
$result2 = mysqli_query($conn, $sql2);
$row2 = mysqli_fetch_assoc($result2);
$authorID = $row2['StaffID'];
$sql3 = "SELECT * FROM Staff WHERE StaffID = '$authorID'";
$result3 = mysqli_query($conn, $sql3);
$row3 = mysqli_fetch_assoc($result3);
$authorEmail = $row3['Email'];
$authorName = $row3['StaffName'];
$to = $authorEmail;
$subject = "New comment on your idea";
$message = "Dear " . $row3['StaffName'] . ",<br><br> A new comment has been submitted to your idea $row2[Title].<br><br>";
$message .= 'Comment: ' . $content . '<br><br>';
$message .= 'Please login to your account to view the comment.<br><br>';
$message .= 'Thank you,<br>Greenwich Quality Assurance Manager';

// Set up the email headers
$mail = new PHPMailer\PHPMailer\PHPMailer();

try {
// Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'iebdmpqvvkpjglec';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Recipients
$mail->setFrom('[email protected]', 'Greenwich QA');
$mail->addAddress($to, $authorName);

// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;
$mail->send();
echo "<script>alert('Comment added successfully!')</script>";
echo "<script>window.location.href='Staff.php'</script>";
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
} else {
echo "<script>alert('Error: " . $sql . "<br>" . mysqli_error($conn) . "')</script>";
}
Expand Down
101 changes: 49 additions & 52 deletions QAM_Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down Expand Up @@ -125,14 +125,11 @@ class="d-flex align-items-center text-decoration-none text-dark" id="manage-topi
</button>
</div>
<?php
include_once("connection.php");

// use PHPMailer\PHPMailer\PHPMailer;
// use PHPMailer\PHPMailer\Exception;
//
// require 'PHPMailer/src/PHPMailer.php';
// require 'PHPMailer/src/SMTP.php';
// require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';
include_once("connection.php");

// Retrieve the list of roles
$sql = "SELECT * FROM Role";
Expand All @@ -151,50 +148,50 @@ class="d-flex align-items-center text-decoration-none text-dark" id="manage-topi

$sql = "INSERT INTO Staff (FullName, Email, Password, RoleID, DepartmentID) VALUES ('$full_name','$email', '$password', '$role_id', '$dept_id')";
$result = mysqli_query($conn, $sql);
// if ($result) {
// // Send email to the new staff member about login details
// $to = $email;
// $subject = 'Login details for new staff member account';
// $message = 'Dear ' . $full_name . ',<br><br>';
// $message .= 'Your account has been created. Please use the following details to log in:<br><br>';
// $message .= 'Email: ' . $email . '<br>';
// $message .= 'Password: ' . $_POST['password'] . '<br><br>';
// $message .= 'Thank you,<br>The Admin Team';
//
// // Set up the email headers
// $mail = new PHPMailer(true);
//
// try {
// // Server settings
// $mail->SMTPDebug = 0;
// $mail->isSMTP();
// $mail->Host = 'smtp.gmail.com';
// $mail->SMTPAuth = true;
// $mail->Username = '[email protected]';
// $mail->Password = 'iebdmpqvvkpjglec';
// $mail->SMTPSecure = 'tls';
// $mail->Port = 587;
//
// // Recipients
// $mail->setFrom('[email protected]', 'Greenwich QA');
// $mail->addAddress($to, $full_name);
//
// // Content
// $mail->isHTML(true);
// $mail->Subject = $subject;
// $mail->Body = $message;
//
// $mail->send();
echo "<script>alert('Staff member added successfully')</script>";
echo "<script>window.location.href = 'QAM_Account.php'</script>";
// } catch (Exception $e) {
// echo "<script>alert('Error sending email.')</script>";
// echo "<script>window.location.href = 'QAM_Account.php'</script>";
// }
// } else {
// echo "<script>alert('Error adding staff member')</script>";
// echo "<script>window.location.href = 'QAM_Account.php'</script>";
// }
if ($result) {
// Send email to the new staff member about login details
$to = $email;
$subject = 'Login details for new staff member account';
$message = 'Dear ' . $full_name . ',<br><br>';
$message .= 'Your account has been created. Please use the following details to log in:<br><br>';
$message .= 'Email: ' . $email . '<br>';
$message .= 'Password: ' . $_POST['password'] . '<br><br>';
$message .= 'Thank you,<br>Greenwich Quality Assurance Manager';

// Set up the email headers
$mail = new PHPMailer\PHPMailer\PHPMailer();

try {
// Server settings
$mail->SMTPDebug = 0;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = '[email protected]';
$mail->Password = 'iebdmpqvvkpjglec';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;

// Recipients
$mail->setFrom('[email protected]', 'Greenwich QA');
$mail->addAddress($to, $full_name);

// Content
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $message;

$mail->send();
echo "<script>alert('Staff member added successfully')</script>";
echo "<script>window.location.href = 'QAM_Account.php'</script>";
} catch (Exception $e) {
echo "<script>alert('Error sending email.')</script>";
echo "<script>window.location.href = 'QAM_Account.php'</script>";
}
} else {
echo "<script>alert('Error adding staff member')</script>";
echo "<script>window.location.href = 'QAM_Account.php'</script>";
}
}
?>

Expand Down
2 changes: 1 addition & 1 deletion QAM_Department.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down
2 changes: 1 addition & 1 deletion QAM_Ideas.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down
2 changes: 1 addition & 1 deletion QAM_Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- top -->
<!-- avatar -->
<li class="dropdown-item p-1 rounded">
<a href="#" class="d-flex align-items-center text-decoration-none text-dark">
<a href="Settings.php" class="d-flex align-items-center text-decoration-none text-dark">
<div class="p-2">
<img src="https://source.unsplash.com/collection/happy-people" alt="avatar"
class="rounded-circle me-2"
Expand Down
Loading

0 comments on commit 64d4894

Please sign in to comment.