mirror of
https://github.com/itflow-org/itflow
synced 2026-03-03 04:14:54 +00:00
Add email notifications when cron raises a scheduled ticket
This commit is contained in:
40
cron.php
40
cron.php
@@ -32,6 +32,8 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||||||
// Tickets
|
// Tickets
|
||||||
$config_ticket_prefix = $row['config_ticket_prefix'];
|
$config_ticket_prefix = $row['config_ticket_prefix'];
|
||||||
$config_ticket_next_number = $row['config_ticket_next_number'];
|
$config_ticket_next_number = $row['config_ticket_next_number'];
|
||||||
|
$config_ticket_from_name = $row['config_ticket_from_name'];
|
||||||
|
$config_ticket_from_email = $row['config_ticket_from_email'];
|
||||||
|
|
||||||
// Set Currency Format
|
// Set Currency Format
|
||||||
$currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY);
|
$currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY);
|
||||||
@@ -151,10 +153,48 @@ while($row = mysqli_fetch_array($sql_companies)){
|
|||||||
|
|
||||||
// Raise the ticket
|
// Raise the ticket
|
||||||
mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id, company_id = $company_id");
|
mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id, company_id = $company_id");
|
||||||
|
$id = mysqli_insert_id($mysqli);
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'System created scheduled $frequency ticket - $subject', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_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_created_at = NOW(), log_client_id = $client_id, company_id = $company_id, log_user_id = $created_id");
|
||||||
|
|
||||||
|
// E-mail client
|
||||||
|
if (!empty($config_smtp_host)) {
|
||||||
|
|
||||||
|
// Get contact/ticket/company details
|
||||||
|
$sql = mysqli_query($mysqli,"SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, company_phone FROM tickets
|
||||||
|
LEFT JOIN clients ON ticket_client_id = client_id
|
||||||
|
LEFT JOIN contacts ON ticket_contact_id = contact_id
|
||||||
|
LEFT JOIN companies ON tickets.company_id = companies.company_id
|
||||||
|
WHERE ticket_id = $id AND tickets.company_id = $company_id");
|
||||||
|
$row = mysqli_fetch_array($sql);
|
||||||
|
|
||||||
|
$contact_name = $row['contact_name'];
|
||||||
|
$contact_email = $row['contact_email'];
|
||||||
|
$ticket_prefix = $row['ticket_prefix'];
|
||||||
|
$ticket_number = $row['ticket_number'];
|
||||||
|
$ticket_subject = $row['ticket_subject'];
|
||||||
|
$company_phone = formatPhoneNumber($row['company_phone']);
|
||||||
|
|
||||||
|
// Verify contact email is valid
|
||||||
|
if(filter_var($contact_email, FILTER_VALIDATE_EMAIL)){
|
||||||
|
|
||||||
|
$subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)";
|
||||||
|
$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";
|
||||||
|
|
||||||
|
$mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
|
||||||
|
$config_ticket_from_email, $config_ticket_from_name,
|
||||||
|
$contact_email, $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', notification_timestamp = NOW(), company_id = $company_id");
|
||||||
|
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', company_id = $company_id");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
|
|||||||
Reference in New Issue
Block a user