forked from cedrickjames/helpdesk-production
-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoCloseTicket.php
114 lines (104 loc) · 4.6 KB
/
autoCloseTicket.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include("includes/connect.php");
$sqllink = "SELECT `link` FROM `setting`";
$resultlink = mysqli_query($con, $sqllink);
$link = "";
while ($listlink = mysqli_fetch_assoc($resultlink)) {
$link = $listlink["link"];
}
$sql2 = "Select * FROM `sender`";
$result2 = mysqli_query($con, $sql2);
while ($list = mysqli_fetch_assoc($result2)) {
$account = $list["email"];
$accountpass = $list["password"];
}
$datenow = date("Y-m-d");
$dateToday = date('Y-m-d H:i:s', time());
$query = mysqli_query($con, "SELECT * FROM `request` WHERE requestor_approval_date IS NULL AND `rateDate` IS NULL AND completed_date IS NOT NULL AND `ticket_close_date` IS NULL AND completed_date BETWEEN '2024-05-28' AND '$datenow'");
while ($row = $query->fetch_assoc()) {
$id = $row['id'];
$requestor = $row['requestor'];
$email = $row['email'];
$completed_date = new DateTime($row['completed_date']);
$today = new DateTime();
$today->format('Y-m-d');
$date1 = new DateTime($row['date_filled']);
$date = $date1->format('ym');
$request_type = $row['request_type'];
$detailsOfRequest = $row['request_details'];
$r_personnelsName = $row['assignedPersonnelName'];
$ticket_category = $row['request_category'];
$datecompleted = $completed_date->format('F d, Y');
$ticket_filer = $row['ticket_filer'];
$date_filed = $date1->format('F d, Y');
if ($request_type === "Technical Support") {
$completejoid = 'TS-' . $date . '-' . $id;
} else {
$completejoid = 'JO-' . $date . '-' . $id;
}
// Define holidays array
$sqlHoli = "SELECT holidaysDate FROM holidays";
$resultHoli = mysqli_query($con, $sqlHoli);
$holidays = array();
while ($row = mysqli_fetch_assoc($resultHoli)) {
$holidays[] = $row['holidaysDate'];
}
$interval = $completed_date->diff($today);
$days = $interval->days;
// Loop through the days between the two dates
for ($i = 0; $i < $days; $i++) {
// Get the current date
$currentDate = clone $completed_date;
$currentDate->add(new DateInterval('P' . $i . 'D'));
// Check if the current date is a weekend or a holiday
if ($currentDate->format('N') >= 6 || in_array($currentDate->format('Y-m-d'), $holidays)) {
// Subtract 1 from the total number of days
$days--;
}
}
if ($days >= 5) {
$sql = "UPDATE `request` SET `ticket_close_date` = '$dateToday' WHERE `requestor_approval_date` IS NULL AND `rateDate` IS NULL AND `completed_date` IS NOT NULL AND `id` = '$id' AND `ticket_close_date` IS NULL AND completed_date BETWEEN '2024-05-28' AND '$datenow'";
$results = mysqli_query($con, $sql);
if ($results) {
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP();
$mail->Host = 'mail.glorylocal.com.ph';
$mail->SMTPAuth = true;
$mail->Username = $account;
$mail->Password = $accountpass;
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'none';
$mail->Port = 465;
$mail->setFrom('[email protected]', 'Helpdesk');
$mail->addAddress($email);
$mail->isHTML(true);
$mail->Subject = "Ticket Closed";
$mail->Body = "Hi $requestor,<br>
<br>Your request $completejoid has been automatically closed by the system. Please check the details below or by signing in into our Helpdesk. <br> Click this $link to sign in. <br>
<br>Request Type: $request_type
<br>Request Category: $ticket_category
<br>Request Details: $detailsOfRequest
<br>Assigned Personnel: $r_personnelsName
<br>Ticket Filer: $ticket_filer
<br>Date Filed: $date_filed
<br>Date Completed: $datecompleted
<br><br><br> This is a generated email. Please do not reply. <br><br> Helpdesk";
$mail->send();
$_SESSION['message'] = 'Message has been sent';
} catch (Exception $e) {
$_SESSION['message'] = 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
}
}
}
}