mirror of https://github.com/itflow-org/itflow
Scheduled tickets
- Notify agent DL when scheduled tickets are raised (if configured) - Bugfix: Ticket numbering if two or more scheduled tickets are raised in the same script execution - Bugfix: Email processing if a contact replied to a scheduled ticket email (still showing original #--itflow# line rather than ##- Please type your reply above this line -##)
This commit is contained in:
parent
fe1b8ce88f
commit
41cfd8d27b
91
cron.php
91
cron.php
|
|
@ -45,12 +45,12 @@ $config_recurring_auto_send_invoice = intval($row['config_recurring_auto_send_in
|
||||||
|
|
||||||
// Tickets
|
// Tickets
|
||||||
$config_ticket_prefix = $row['config_ticket_prefix'];
|
$config_ticket_prefix = $row['config_ticket_prefix'];
|
||||||
$config_ticket_next_number = intval($row['config_ticket_next_number']);
|
$config_ticket_from_name = $row['config_ticket_from_name']; // TODO: Sanitize from_name and from_email on assignment, once everything is moved to the database queue
|
||||||
$config_ticket_from_name = $row['config_ticket_from_name'];
|
|
||||||
$config_ticket_from_email = $row['config_ticket_from_email'];
|
$config_ticket_from_email = $row['config_ticket_from_email'];
|
||||||
$config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']);
|
$config_ticket_client_general_notifications = intval($row['config_ticket_client_general_notifications']);
|
||||||
$config_ticket_autoclose = intval($row['config_ticket_autoclose']);
|
$config_ticket_autoclose = intval($row['config_ticket_autoclose']);
|
||||||
$config_ticket_autoclose_hours = intval($row['config_ticket_autoclose_hours']);
|
$config_ticket_autoclose_hours = intval($row['config_ticket_autoclose_hours']);
|
||||||
|
$config_ticket_new_ticket_notification_email = $row['config_ticket_new_ticket_notification_email'];
|
||||||
|
|
||||||
// Get Config for Telemetry
|
// Get Config for Telemetry
|
||||||
$config_theme = $row['config_theme'];
|
$config_theme = $row['config_theme'];
|
||||||
|
|
@ -239,6 +239,7 @@ $sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets
|
||||||
|
|
||||||
if (mysqli_num_rows($sql_scheduled_tickets) > 0) {
|
if (mysqli_num_rows($sql_scheduled_tickets) > 0) {
|
||||||
while ($row = mysqli_fetch_array($sql_scheduled_tickets)) {
|
while ($row = mysqli_fetch_array($sql_scheduled_tickets)) {
|
||||||
|
|
||||||
$schedule_id = intval($row['scheduled_ticket_id']);
|
$schedule_id = intval($row['scheduled_ticket_id']);
|
||||||
$subject = sanitizeInput($row['scheduled_ticket_subject']);
|
$subject = sanitizeInput($row['scheduled_ticket_subject']);
|
||||||
$details_escaped = mysqli_real_escape_string($mysqli, $row['scheduled_ticket_details']);
|
$details_escaped = mysqli_real_escape_string($mysqli, $row['scheduled_ticket_details']);
|
||||||
|
|
@ -250,9 +251,12 @@ if (mysqli_num_rows($sql_scheduled_tickets) > 0) {
|
||||||
$contact_id = intval($row['scheduled_ticket_contact_id']);
|
$contact_id = intval($row['scheduled_ticket_contact_id']);
|
||||||
$asset_id = intval($row['scheduled_ticket_asset_id']);
|
$asset_id = intval($row['scheduled_ticket_asset_id']);
|
||||||
|
|
||||||
//Get the next Ticket Number and add 1 for the new ticket number
|
// Assign this new ticket the next ticket number
|
||||||
$ticket_number = $config_ticket_next_number;
|
$ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1"));
|
||||||
$new_config_ticket_next_number = $config_ticket_next_number + 1;
|
$ticket_number = intval($ticket_number_sql['config_ticket_next_number']);
|
||||||
|
|
||||||
|
// Increment config_ticket_next_number by 1 (for the next ticket)
|
||||||
|
$new_config_ticket_next_number = $ticket_number + 1;
|
||||||
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1");
|
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1");
|
||||||
|
|
||||||
// Raise the ticket
|
// Raise the ticket
|
||||||
|
|
@ -262,53 +266,58 @@ if (mysqli_num_rows($sql_scheduled_tickets) > 0) {
|
||||||
// Logging
|
// Logging
|
||||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_client_id = $client_id, log_user_id = $created_id");
|
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_client_id = $client_id, log_user_id = $created_id");
|
||||||
|
|
||||||
// E-mail client
|
// Notifications
|
||||||
if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) {
|
|
||||||
|
|
||||||
// Get contact/ticket/company details
|
|
||||||
$sql = mysqli_query(
|
// Get client/contact/ticket details
|
||||||
$mysqli,
|
$sql = mysqli_query(
|
||||||
"SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject FROM tickets
|
$mysqli,
|
||||||
|
"SELECT client_name, contact_name, contact_email, ticket_prefix, ticket_number, ticket_priority, ticket_subject, ticket_details FROM tickets
|
||||||
LEFT JOIN clients ON ticket_client_id = client_id
|
LEFT JOIN clients ON ticket_client_id = client_id
|
||||||
LEFT JOIN contacts ON ticket_contact_id = contact_id
|
LEFT JOIN contacts ON ticket_contact_id = contact_id
|
||||||
WHERE ticket_id = $id"
|
WHERE ticket_id = $id"
|
||||||
);
|
);
|
||||||
$row = mysqli_fetch_array($sql);
|
$row = mysqli_fetch_array($sql);
|
||||||
|
|
||||||
$contact_name = $row['contact_name'];
|
|
||||||
$contact_email = $row['contact_email'];
|
|
||||||
$ticket_prefix = $row['ticket_prefix'];
|
|
||||||
$ticket_number = intval($row['ticket_number']);
|
|
||||||
$ticket_subject = $row['ticket_subject'];
|
|
||||||
|
|
||||||
// Verify contact email is valid
|
|
||||||
if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
|
|
||||||
|
|
||||||
$subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)";
|
// Escaped - Do not re-escape in the general subject/body escaping as this would re-escape
|
||||||
$body = "<i style='color: #808080'>#--itflow--#</i><br><br>Hello, $contact_name<br><br>A ticket regarding \"$ticket_subject\" has been automatically created for you.<br><br>--------------------------------<br>$details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: Open<br>Portal: https://$config_base_url/portal/ticket.php?id=$id<br><br>~<br>$company_name<br>Support Department<br>$config_ticket_from_email<br>$company_phone";
|
$config_ticket_from_name_escaped = sanitizeInput($config_ticket_from_name); // TODO: Move this sanitization to the start of cron, once everything uses the queue
|
||||||
|
$config_ticket_from_email_escaped = sanitizeInput($config_ticket_from_email); // TODO: Move this sanitization to the start of cron, once everything uses the queue
|
||||||
|
$contact_name_escaped = sanitizeInput($row['contact_name']);
|
||||||
|
$contact_email_escaped = sanitizeInput($row['contact_email']);
|
||||||
|
|
||||||
$mail = sendSingleEmail(
|
// Unescaped - DANGEROUS unless escaped within the general subject/body escape queries
|
||||||
$config_smtp_host,
|
$client_name = $row['client_name'];
|
||||||
$config_smtp_username,
|
$contact_name = $row['contact_name'];
|
||||||
$config_smtp_password,
|
$contact_email = $row['contact_email'];
|
||||||
$config_smtp_encryption,
|
$ticket_prefix = $row['ticket_prefix'];
|
||||||
$config_smtp_port,
|
$ticket_number = intval($row['ticket_number']);
|
||||||
$config_ticket_from_email,
|
$ticket_priority = $row['ticket_priority'];
|
||||||
$config_ticket_from_name,
|
$ticket_subject = $row['ticket_subject'];
|
||||||
$contact_email,
|
$ticket_details = $row['ticket_details']; // Output on settings_mail_queue.php is sanitized through HTML Purifier
|
||||||
$contact_name,
|
|
||||||
$subject,
|
|
||||||
$body
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($mail !== true) {
|
|
||||||
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email'");
|
|
||||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail'");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// Notify client by email their ticket has been raised, if general notifications are turned on & there is a valid contact email
|
||||||
|
if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1 && filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
|
||||||
|
$email_subject = mysqli_real_escape_string($mysqli, "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)");
|
||||||
|
$email_body = mysqli_real_escape_string($mysqli, "<i style='color: #808080'>##- Please type your reply above this line -##</i><br><br>Hello, $contact_name<br><br>A ticket regarding \"$ticket_subject\" has been automatically created for you.<br><br>--------------------------------<br>$details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: Open<br>Portal: https://$config_base_url/portal/ticket.php?id=$id<br><br>~<br>$company_name<br>Support Department<br>$config_ticket_from_email<br>$company_phone");
|
||||||
|
|
||||||
|
mysqli_query($mysqli, "INSERT INTO email_queue SET email_recipient = '$contact_email_escaped', email_recipient_name = '$contact_name_escaped', email_from = '$config_ticket_from_email_escaped', email_from_name = '$config_ticket_from_name_escaped', email_subject = '$email_subject', email_content = '$email_body'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Notify agent's via the DL address of the new ticket, if it's populated with a valid email
|
||||||
|
if (filter_var($config_ticket_new_ticket_notification_email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
|
||||||
|
$email_subject = mysqli_real_escape_string($mysqli, "ITFlow - New Scheduled Ticket - $client_name: $ticket_subject");
|
||||||
|
$email_body = mysqli_real_escape_string($mysqli, "Hello, <br><br>This is a notification that a new scheduled ticket has been raised in ITFlow. <br>Ticket: $ticket_prefix$ticket_number<br>Client: $client_name<br>Priority: $priority<br>Link: https://$config_base_url/ticket.php?ticket_id=$id <br><br>--------------------------------<br><br><b>$ticket_subject</b><br>$ticket_details");
|
||||||
|
|
||||||
|
mysqli_query($mysqli, "INSERT INTO email_queue SET email_recipient = '$config_ticket_new_ticket_notification_email', email_recipient_name = 'ITFlow Agents', email_from = '$config_ticket_from_email', email_from_name = '$config_ticket_from_name', email_subject = '$email_subject', email_content = '$email_body'");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the next run date
|
// Set the next run date
|
||||||
if ($frequency == "weekly") {
|
if ($frequency == "weekly") {
|
||||||
// Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates
|
// Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates
|
||||||
|
|
@ -673,7 +682,7 @@ while ($row = mysqli_fetch_array($sql_recurring_expenses)) {
|
||||||
|
|
||||||
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = CURDATE(), expense_amount = $recurring_expense_amount, expense_currency_code = '$recurring_expense_currency_code', expense_account_id = $recurring_expense_account_id, expense_vendor_id = $recurring_expense_vendor_id, expense_client_id = $recurring_expense_client_id, expense_category_id = $recurring_expense_category_id, expense_description = '$recurring_expense_description', expense_reference = '$recurring_expense_reference'");
|
mysqli_query($mysqli,"INSERT INTO expenses SET expense_date = CURDATE(), expense_amount = $recurring_expense_amount, expense_currency_code = '$recurring_expense_currency_code', expense_account_id = $recurring_expense_account_id, expense_vendor_id = $recurring_expense_vendor_id, expense_client_id = $recurring_expense_client_id, expense_category_id = $recurring_expense_category_id, expense_description = '$recurring_expense_description', expense_reference = '$recurring_expense_reference'");
|
||||||
|
|
||||||
$expense_id = mysqli_insert_id($mysqli);
|
$expense_id = mysqli_insert_id($mysqli);
|
||||||
|
|
||||||
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Expense Created', notification = 'Expense $recurring_expense_description created from recurring expenses', notification_action = 'expenses.php', notification_client_id = $recurring_expense_client_id, notification_entity_id = $expense_id");
|
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Expense Created', notification = 'Expense $recurring_expense_description created from recurring expenses', notification_action = 'expenses.php', notification_client_id = $recurring_expense_client_id, notification_entity_id = $expense_id");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
|
||||||
$ticket_reply_type = 'Client';
|
$ticket_reply_type = 'Client';
|
||||||
|
|
||||||
// Capture just the latest/most recent email reply content
|
// Capture just the latest/most recent email reply content
|
||||||
// based off the "#--itflow#" line that we prepend the outgoing emails with (similar to the old school --reply above this line--)
|
// based off the "##- Please type your reply above this line -##" line that we prepend the outgoing emails with
|
||||||
$message = explode("##- Please type your reply above this line -##", $message);
|
$message = explode("##- Please type your reply above this line -##", $message);
|
||||||
$message = nl2br($message[0]);
|
$message = nl2br($message[0]);
|
||||||
$message = "<i>Email from: $from_email at $date:-</i> <br><br>$message";
|
$message = "<i>Email from: $from_email at $date:-</i> <br><br>$message";
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,9 @@ if (isset($_POST['add_ticket'])) {
|
||||||
|
|
||||||
$client_id = intval($_POST['client']);
|
$client_id = intval($_POST['client']);
|
||||||
$assigned_to = intval($_POST['assigned_to']);
|
$assigned_to = intval($_POST['assigned_to']);
|
||||||
if($assigned_to == 0){
|
if ($assigned_to == 0) {
|
||||||
$ticket_status = 'Pending-Assignment';
|
$ticket_status = 'Pending-Assignment';
|
||||||
}else{
|
} else {
|
||||||
$ticket_status = 'Assigned';
|
$ticket_status = 'Assigned';
|
||||||
}
|
}
|
||||||
$contact = intval($_POST['contact']);
|
$contact = intval($_POST['contact']);
|
||||||
|
|
@ -24,7 +24,7 @@ if (isset($_POST['add_ticket'])) {
|
||||||
$asset_id = intval($_POST['asset']);
|
$asset_id = intval($_POST['asset']);
|
||||||
$use_primary_contact = intval($_POST['use_primary_contact']);
|
$use_primary_contact = intval($_POST['use_primary_contact']);
|
||||||
|
|
||||||
// Add the primary contact as the ticket contact if use primary contact is checked
|
// Add the primary contact as the ticket contact if "Use primary contact" is checked
|
||||||
if ($use_primary_contact == 1) {
|
if ($use_primary_contact == 1) {
|
||||||
$sql = mysqli_query($mysqli,"SELECT contact_id FROM contacts WHERE contact_client_id = $client_id AND contact_primary = 1");
|
$sql = mysqli_query($mysqli,"SELECT contact_id FROM contacts WHERE contact_client_id = $client_id AND contact_primary = 1");
|
||||||
$row = mysqli_fetch_array($sql);
|
$row = mysqli_fetch_array($sql);
|
||||||
|
|
@ -851,7 +851,7 @@ if (isset($_POST['add_invoice_from_ticket'])) {
|
||||||
$row = mysqli_fetch_array($sql);
|
$row = mysqli_fetch_array($sql);
|
||||||
$tax_percent = floatval($row['tax_percent']);
|
$tax_percent = floatval($row['tax_percent']);
|
||||||
$tax_amount = $subtotal * $tax_percent / 100;
|
$tax_amount = $subtotal * $tax_percent / 100;
|
||||||
}else{
|
} else {
|
||||||
$tax_amount = 0;
|
$tax_amount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,13 +110,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||||
$email_failed_at = nullable_htmlentities($row['email_failed_at']);
|
$email_failed_at = nullable_htmlentities($row['email_failed_at']);
|
||||||
$email_sent_at = nullable_htmlentities($row['email_sent_at']);
|
$email_sent_at = nullable_htmlentities($row['email_sent_at']);
|
||||||
$email_status = intval($row['email_status']);
|
$email_status = intval($row['email_status']);
|
||||||
if($email_status == 0){
|
if ($email_status == 0) {
|
||||||
$email_status_display = "<div class='text-primary'>Queued</div>";
|
$email_status_display = "<div class='text-primary'>Queued</div>";
|
||||||
}elseif($email_status == 1){
|
} elseif($email_status == 1) {
|
||||||
$email_status_display = "<div class='text-warning'>Sending</div>";
|
$email_status_display = "<div class='text-warning'>Sending</div>";
|
||||||
}elseif($email_status == 2){
|
} elseif($email_status == 2) {
|
||||||
$email_status_display = "<div class='text-danger'>Failed</div><small class='text-secondary'>$email_failed_at</small>";
|
$email_status_display = "<div class='text-danger'>Failed</div><small class='text-secondary'>$email_failed_at</small>";
|
||||||
}else{
|
} else {
|
||||||
$email_status_display = "<div class='text-success'>Sent</div><small class='text-secondary'>$email_sent_at</small>";
|
$email_status_display = "<div class='text-success'>Sent</div><small class='text-secondary'>$email_sent_at</small>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue