forked from cedrickjames/helpdesk-production
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ticketApproval.php
176 lines (153 loc) · 8.05 KB
/
ticketApproval.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include("includes/connect.php");
if (isset($_GET['id']) && isset($_GET['head'])) {
$sqllink = "SELECT `link` FROM `setting`";
$resultlink = mysqli_query($con, $sqllink);
$link = "";
while ($listlink = mysqli_fetch_assoc($resultlink)) {
$link = $listlink["link"];
}
$id = $_GET['id'];
$query = mysqli_query($con, "SELECT * FROM `request` WHERE `id`='" . $id . "'");
$row = mysqli_fetch_assoc($query);
$approval_date = $row['ict_approval_date'];
$personnelName = $row['assignedPersonnelName'];
$date = new DateTime($row['date_filled']);
$date = $date->format('ym');
$completejoid = $date . '-' . $id;
$requestor = $row['requestor'];
$request_type = $row['request_type'];
$ticket_category = $row['ticket_category'];
$cat_lvl = $row['category_level'];
$detailsOfRequest = $row['request_details'];
$assigned = $row['assignedPersonnel'];
$requestorEmail = $row['email'];
$requestorDepartment = $row['department'];
$ticketNumber = 'TS-' . $completejoid;
$onsthespot = $row['onthespot_ticket'];
$_SESSION['ticket_number'] = $ticketNumber;
$_SESSION['requestor'] = $requestor;
$_SESSION['pdepartment'] = $requestorDepartment;
$_SESSION['dateFiled'] = $row['date_filled'];
$_SESSION['type'] = $request_type;
$_SESSION['details'] = $detailsOfRequest;
$_SESSION['assignedPersonnel'] = $personnelName;
$_SESSION['requestType'] = $request_type;
$_SESSION['ticket_category'] = $ticket_category;
$_SESSION['adminsDate'] = $approval_date;
$_SESSION['onthespot_ticket'] = $onsthespot;
$_SESSION['adminsRemarks'] = $row['admin_remarks'];
$_SESSION['firstAction'] = $row['action1'];
$_SESSION['firstDate'] = $row['action1Date'];
$_SESSION['secondAction'] = $row['action2'];
$_SESSION['secondDate'] = $row['action2Date'];
$_SESSION['thirdAction'] = $row['action3'];
$_SESSION['thirdDate'] = $row['action3Date'];
$_SESSION['finalAction'] = $row['action'];
$_SESSION['recommendation'] = $row['recommendation'];
$_SESSION['dateFinished'] = $row['confirm_finish_date'];
$_SESSION['approved_reco'] = $row['approved_reco'];
$_SESSION['icthead_reco_remarks'] = $row['icthead_reco_remarks'];
$sql1 = "Select * FROM `user` WHERE `username` = '$assigned'";
$result = mysqli_query($con, $sql1);
while ($list = mysqli_fetch_assoc($result)) {
$personnelEmail = $list["email"];
}
if ($approval_date != NULL) {
echo "<script>alert('Request already approved! Date of approval: $approval_date');</script>";
echo "<script>location.href= '$link/login.php';</script>";
} else {
$datenow = date("Y-m-d");
$dateToday = date('Y-m-d H:i:s', time());
$sql = "UPDATE `request` SET `status2` = 'inprogress', `admin_approved_date`='$datenow', `ict_approval_date`='$dateToday' WHERE `id` = '$id';";
$results = mysqli_query($con, $sql);
if ($results) {
$sql2 = "Select * FROM `sender`";
$result2 = mysqli_query($con, $sql2);
while ($list = mysqli_fetch_assoc($result2)) {
$account = $list["email"];
$accountpass = $list["password"];
}
$subject = 'New Ticket Request';
$message = 'Hi ' . $personnelName . ',<br> <br> You have a new ticket request with TS number TS-' . $completejoid . ' from ' . $requestor . '. Please check the details below or by signing in into our Helpdesk. <br> Click this ' . $link . ' to sign in. <br><br>Ticket No.: ' . $ticketNumber . '<br> Requestor: ' . $requestor . '<br> Requestor Email: ' . $requestorEmail . '<br> Requestor Department: ' . $requestorDepartment . '<br>Request Type: ' . $request_type . '<br> Ticket Category: ' . $ticket_category . '<br>Category Level: ' . $cat_lvl . '<br> Request Details: ' . $detailsOfRequest . '<br><br><br> This is a generated email. Please do not reply. <br><br> Helpdesk';
require 'vendor/autoload.php';
require 'dompdf/vendor/autoload.php';
ob_start();
require 'Job Order Report copy.php';
$html = ob_get_clean();
$mail = new PHPMailer(true);
try {
//Server settings
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.glorylocal.com.ph'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $account; // Your Email/ Server Email
$mail->Password = $accountpass; // Your Password
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPSecure = 'none';
$mail->Port = 465;
//Email ICT personnel / FEM admin
//Recipients
$mail->setFrom('[email protected]', 'Helpdesk');
$mail->addAddress($personnelEmail);
$mail->isHTML(true);
$mail->Subject = $subject;
// Generate PDF content using Dompdf
$dompdf = new Dompdf\Dompdf();
$dompdf->loadHtml($html);
$dompdf->setPaper('A5', 'portrait'); // Set paper size and orientation
$dompdf->render();
$pdfContent = $dompdf->output();
// Attach PDF to the email
$mail->addStringAttachment($pdfContent, 'Helpdesk Report.pdf', 'base64', 'application/pdf');
$mail->Body = $message;
$mail->send();
$_SESSION['message'] = 'Message has been sent';
echo "<script>alert('Thank you for approving.') </script>";
echo "<script> location.href='index.php'; </script>";
// header("location: form.php");
} catch (Exception $e) {
$_SESSION['message'] = 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
echo "<script>alert('Message could not be sent. Mailer Error.') </script>";
}
// echo "<script>alert('Request has been approved successfully!');</script>";
// echo "<script>location.href='$link/login.php';</script>";
} else {
echo "<script>alert('There is a problem with filing. Please contact your administrator.');</script>";
}
}
}
if (isset($_GET['id']) && isset($_GET['requestor'])) {
$sqllink = "SELECT `link` FROM `setting`";
$resultlink = mysqli_query($con, $sqllink);
$link = "";
while ($listlink = mysqli_fetch_assoc($resultlink)) {
$link = $listlink["link"];
}
$id = $_GET['id'];
$query = mysqli_query($con, "SELECT * FROM `request` WHERE `id`='" . $id . "'");
$row = mysqli_fetch_assoc($query);
$approval_date = $row['requestor_approval_date'];
if ($approval_date != NULL) {
echo "<script>alert('Request already approved! Date of approval: $approval_date');</script>";
echo "<script>location.href='$link/login.php';</script>";
} else {
$dateToday = date('Y-m-d H:i:s', time());
$sql = "UPDATE `request` SET `requestor_approval_date`='$dateToday' WHERE `id` = '$id';";
$results = mysqli_query($con, $sql);
if ($results) {
echo "<script>alert('Request has been approved successfully!');</script>";
echo "<script>location.href='$link/login.php';</script>";
} else {
echo "<script>alert('There is a problem with filing. Please contact your administrator.');</script>";
}
}
}