diff --git a/post/user/ticket.php b/post/user/ticket.php
index 84d9ad65..e3d36467 100644
--- a/post/user/ticket.php
+++ b/post/user/ticket.php
@@ -1012,104 +1012,121 @@ if (isset($_POST['bulk_resolve_tickets'])) {
// Resolve Selected Tickets
if (isset($_POST['ticket_ids'])) {
- // Get a Ticket Count
- $ticket_count = count($_POST['ticket_ids']);
+ // Intitialze the counts before the loop
+ $ticket_count = 0;
+ $skipped_count = 0;
foreach ($_POST['ticket_ids'] as $ticket_id) {
$ticket_id = intval($ticket_id);
- $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = $ticket_id");
- $row = mysqli_fetch_array($sql);
+ // Check to make sure Tasks are complete before resolving
+ $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('task_id') AS num FROM tasks WHERE task_completed_at IS NULL AND task_ticket_id = $ticket_id"));
+ $num_of_open_tasks = $row['num'];
+
+ if ($num_of_open_tasks == 0) {
+ // Count the Ticket Loop
+ $ticket_count++;
- $ticket_prefix = sanitizeInput($row['ticket_prefix']);
- $ticket_number = intval($row['ticket_number']);
- $ticket_subject = sanitizeInput($row['ticket_subject']);
- $current_ticket_priority = sanitizeInput($row['ticket_priority']);
- $url_key = sanitizeInput($row['ticket_url_key']);
- $client_id = intval($row['ticket_client_id']);
-
- // Update ticket & insert reply
- mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 4, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id");
-
- mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$details', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '$ticket_reply_time_worked', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id");
-
- // Logging
- logAction("Ticket", "Resolve", "$session_name resolved $ticket_prefix$ticket_number - $ticket_subject", $client_id, $ticket_id);
-
- customAction('ticket_resolve', $ticket_id);
-
- // Client notification email
- if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1 && $private_note == 0) {
-
- // Get Contact details
- $ticket_sql = mysqli_query($mysqli, "SELECT contact_name, contact_email FROM tickets
- LEFT JOIN contacts ON ticket_contact_id = contact_id
- WHERE ticket_id = $ticket_id
- ");
- $row = mysqli_fetch_array($ticket_sql);
-
- $contact_name = sanitizeInput($row['contact_name']);
- $contact_email = sanitizeInput($row['contact_email']);
-
- // Sanitize Config vars from get_settings.php
- $from_name = sanitizeInput($config_ticket_from_name);
- $from_email = sanitizeInput($config_ticket_from_email);
- $base_url = sanitizeInput($config_base_url);
-
- // Get Company Info
- $sql = mysqli_query($mysqli, "SELECT company_name, company_phone, company_phone_country_code FROM companies WHERE company_id = 1");
+ $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = $ticket_id");
$row = mysqli_fetch_array($sql);
- $company_name = sanitizeInput($row['company_name']);
- $company_phone = sanitizeInput(formatPhoneNumber($row['company_phone'], $row['company_phone_country_code']));
+
+ $ticket_prefix = sanitizeInput($row['ticket_prefix']);
+ $ticket_number = intval($row['ticket_number']);
+ $ticket_subject = sanitizeInput($row['ticket_subject']);
+ $current_ticket_priority = sanitizeInput($row['ticket_priority']);
+ $url_key = sanitizeInput($row['ticket_url_key']);
+ $client_id = intval($row['ticket_client_id']);
+
+ // Update ticket & insert reply
+ mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 4, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id");
+
+ mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$details', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '$ticket_reply_time_worked', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id");
+
+ // Logging
+ logAction("Ticket", "Resolve", "$session_name resolved $ticket_prefix$ticket_number - $ticket_subject", $client_id, $ticket_id);
+
+ customAction('ticket_resolve', $ticket_id);
+
+ // Client notification email
+ if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1 && $private_note == 0) {
+
+ // Get Contact details
+ $ticket_sql = mysqli_query($mysqli, "SELECT contact_name, contact_email FROM tickets
+ LEFT JOIN contacts ON ticket_contact_id = contact_id
+ WHERE ticket_id = $ticket_id
+ ");
+ $row = mysqli_fetch_array($ticket_sql);
+
+ $contact_name = sanitizeInput($row['contact_name']);
+ $contact_email = sanitizeInput($row['contact_email']);
+
+ // Sanitize Config vars from get_settings.php
+ $from_name = sanitizeInput($config_ticket_from_name);
+ $from_email = sanitizeInput($config_ticket_from_email);
+ $base_url = sanitizeInput($config_base_url);
+
+ // Get Company Info
+ $sql = mysqli_query($mysqli, "SELECT company_name, company_phone, company_phone_country_code FROM companies WHERE company_id = 1");
+ $row = mysqli_fetch_array($sql);
+ $company_name = sanitizeInput($row['company_name']);
+ $company_phone = sanitizeInput(formatPhoneNumber($row['company_phone'], $row['company_phone_country_code']));
- // EMAIL
- $subject = "Ticket resolved - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)";
- $body = "##- Please type your reply above this line -##
Hello $contact_name,
Your ticket regarding \"$ticket_subject\" has been marked as solved and is pending closure.
$details
If your request/issue is resolved, you can simply ignore this email. If you need further assistance, please reply or re-open to let us know!
Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Portal: https://$base_url/client/ticket.php?id=$ticket_id
--
$company_name - Support
$config_ticket_from_email
$company_phone";
+ // EMAIL
+ $subject = "Ticket resolved - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)";
+ $body = "##- Please type your reply above this line -##
Hello $contact_name,
Your ticket regarding \"$ticket_subject\" has been marked as solved and is pending closure.
$details
If your request/issue is resolved, you can simply ignore this email. If you need further assistance, please reply or re-open to let us know!
Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Portal: https://$base_url/client/ticket.php?id=$ticket_id
--
$company_name - Support
$config_ticket_from_email
$company_phone";
- // Check email valid
- if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
+ // Check email valid
+ if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
- $data = [];
+ $data = [];
- // Email Ticket Contact
- // Queue Mail
+ // Email Ticket Contact
+ // Queue Mail
- $data[] = [
- 'from' => $from_email,
- 'from_name' => $from_name,
- 'recipient' => $contact_email,
- 'recipient_name' => $contact_name,
- 'subject' => $subject,
- 'body' => $body
- ];
- }
+ $data[] = [
+ 'from' => $from_email,
+ 'from_name' => $from_name,
+ 'recipient' => $contact_email,
+ 'recipient_name' => $contact_name,
+ 'subject' => $subject,
+ 'body' => $body
+ ];
+ }
- // Also Email all the watchers
- $sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id");
- $body .= "
----------------------------------------
YOU ARE A COLLABORATOR ON THIS TICKET";
- while ($row = mysqli_fetch_array($sql_watchers)) {
- $watcher_email = sanitizeInput($row['watcher_email']);
+ // Also Email all the watchers
+ $sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id");
+ $body .= "
----------------------------------------
YOU ARE A COLLABORATOR ON THIS TICKET";
+ while ($row = mysqli_fetch_array($sql_watchers)) {
+ $watcher_email = sanitizeInput($row['watcher_email']);
- // Queue Mail
- $data[] = [
- 'from' => $from_email,
- 'from_name' => $from_name,
- 'recipient' => $watcher_email,
- 'recipient_name' => $watcher_email,
- 'subject' => $subject,
- 'body' => $body
- ];
- }
- addToMailQueue($data);
- } // End Mail IF
+ // Queue Mail
+ $data[] = [
+ 'from' => $from_email,
+ 'from_name' => $from_name,
+ 'recipient' => $watcher_email,
+ 'recipient_name' => $watcher_email,
+ 'subject' => $subject,
+ 'body' => $body
+ ];
+ }
+ addToMailQueue($data);
+ } // End Mail IF
+ } else {
+ $skipped_count++;
+ } // End Task Check
} // End Loop
} // End Array Empty Check
$_SESSION['alert_message'] = "Resolved $ticket_count Tickets";
+ if ($skipped_count > 0) {
+ $_SESSION['alert_type'] = "info";
+ $_SESSION['alert_message'] .= " $skipped_count ticket(s) could not be resolved because they have open tasks.";
+ }
+
header("Location: " . $_SERVER["HTTP_REFERER"]);
}