Skip to content

Commit

Permalink
Merge pull request #943 from wrongecho/ticket-notify-contact-manual-b…
Browse files Browse the repository at this point in the history
…utton

Ticket - Notifications
  • Loading branch information
johnnyq authored Apr 13, 2024
2 parents 034c12d + 1c8b9a3 commit a33a91c
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 8 deletions.
162 changes: 161 additions & 1 deletion post/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@

$ticket_id = intval($_POST['ticket_id']);
$contact_id = intval($_POST['contact']);
$notify = intval($_POST['contact_notify']);
$subject = sanitizeInput($_POST['subject']);
$billable = intval($_POST['billable']);
$priority = sanitizeInput($_POST['priority']);
Expand All @@ -197,10 +198,63 @@
$location_id = intval($_POST['location']);
$project_id = intval($_POST['project']);
$client_id = intval($_POST['client_id']);
$ticket_number = intval($_POST['ticket_number']);
$ticket_number = sanitizeInput($_POST['ticket_number']);

mysqli_query($mysqli, "UPDATE tickets SET ticket_subject = '$subject', ticket_priority = '$priority', ticket_billable = $billable, ticket_details = '$details', ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_contact_id = $contact_id, ticket_vendor_id = $vendor_id, ticket_location_id = $location_id, ticket_asset_id = $asset_id, ticket_project_id = $project_id WHERE ticket_id = $ticket_id");

// Notify new contact if selected
if ($notify && !empty($config_smtp_host)) {

// Get contact/ticket details
$sql = mysqli_query($mysqli, "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_category, ticket_subject, ticket_details, ticket_priority, ticket_status_name, ticket_created_by, ticket_assigned_to, ticket_client_id FROM tickets
LEFT JOIN clients ON ticket_client_id = client_id
LEFT JOIN contacts ON ticket_contact_id = contact_id
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
WHERE ticket_id = $ticket_id
AND ticket_closed_at IS NULL");
$row = mysqli_fetch_array($sql);

$contact_name = sanitizeInput($row['contact_name']);
$contact_email = sanitizeInput($row['contact_email']);
$ticket_prefix = sanitizeInput($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_category = sanitizeInput($row['ticket_category']);
$ticket_subject = sanitizeInput($row['ticket_subject']);
$ticket_details = mysqli_escape_string($mysqli, $row['ticket_details']);
$ticket_priority = sanitizeInput($row['ticket_priority']);
$ticket_status = sanitizeInput($row['ticket_status_name']);
$client_id = intval($row['ticket_client_id']);
$ticket_created_by = intval($row['ticket_created_by']);
$ticket_assigned_to = intval($row['ticket_assigned_to']);

// Get Company Phone Number
$sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1");
$row = mysqli_fetch_array($sql);
$company_name = sanitizeInput($row['company_name']);
$company_phone = sanitizeInput(formatPhoneNumber($row['company_phone']));

// Email content
$data = []; // Queue array

$subject = "Ticket Created - [$ticket_prefix$ticket_number] - $ticket_subject";
$body = "<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 created for you.<br><br>--------------------------------<br>$ticket_details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";


// Only add contact to email queue if email is valid
if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
$data[] = [
'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name,
'recipient' => $contact_email,
'recipient_name' => $contact_name,
'subject' => $subject,
'body' => $body
];
}

addToMailQueue($mysqli, $data);
}

//Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Modify', log_description = '$session_name modified ticket $ticket_number - $subject', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id");

Expand Down Expand Up @@ -235,9 +289,63 @@
$contact_id = intval($_POST['contact']);
$client_id = intval($_POST['client_id']);
$ticket_number = sanitizeInput($_POST['ticket_number']);
$notify = intval($_POST['contact_notify']);

mysqli_query($mysqli, "UPDATE tickets SET ticket_contact_id = $contact_id WHERE ticket_id = $ticket_id");

// Notify new contact if selected
if ($notify && !empty($config_smtp_host)) {

// Get contact/ticket details
$sql = mysqli_query($mysqli, "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_category, ticket_subject, ticket_details, ticket_priority, ticket_status_name, ticket_created_by, ticket_assigned_to, ticket_client_id FROM tickets
LEFT JOIN clients ON ticket_client_id = client_id
LEFT JOIN contacts ON ticket_contact_id = contact_id
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
WHERE ticket_id = $ticket_id
AND ticket_closed_at IS NULL");
$row = mysqli_fetch_array($sql);

$contact_name = sanitizeInput($row['contact_name']);
$contact_email = sanitizeInput($row['contact_email']);
$ticket_prefix = sanitizeInput($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_category = sanitizeInput($row['ticket_category']);
$ticket_subject = sanitizeInput($row['ticket_subject']);
$ticket_details = mysqli_escape_string($mysqli, $row['ticket_details']);
$ticket_priority = sanitizeInput($row['ticket_priority']);
$ticket_status = sanitizeInput($row['ticket_status_name']);
$client_id = intval($row['ticket_client_id']);
$ticket_created_by = intval($row['ticket_created_by']);
$ticket_assigned_to = intval($row['ticket_assigned_to']);

// Get Company Phone Number
$sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1");
$row = mysqli_fetch_array($sql);
$company_name = sanitizeInput($row['company_name']);
$company_phone = sanitizeInput(formatPhoneNumber($row['company_phone']));

// Email content
$data = []; // Queue array

$subject = "Ticket Created - [$ticket_prefix$ticket_number] - $ticket_subject";
$body = "<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 created for you.<br><br>--------------------------------<br>$ticket_details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";


// Only add contact to email queue if email is valid
if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
$data[] = [
'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name,
'recipient' => $contact_email,
'recipient_name' => $contact_name,
'subject' => $subject,
'body' => $body
];
}

addToMailQueue($mysqli, $data);
}

//Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Modify', log_description = '$session_name changed contact for ticket $ticket_number', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id");

Expand All @@ -254,9 +362,61 @@
$client_id = intval($_POST['client_id']);
$ticket_number = sanitizeInput($_POST['ticket_number']);
$watcher_email = sanitizeInput($_POST['watcher_email']);
$notify = intval($_POST['watcher_notify']);

mysqli_query($mysqli, "INSERT INTO ticket_watchers SET watcher_email = '$watcher_email', watcher_ticket_id = $ticket_id");

// Notify watcher
if ($notify && !empty($config_smtp_host)) {

// Get contact/ticket details
$sql = mysqli_query($mysqli, "SELECT ticket_prefix, ticket_number, ticket_category, ticket_subject, ticket_details, ticket_priority, ticket_status_name, ticket_created_by, ticket_assigned_to, ticket_client_id FROM tickets
LEFT JOIN clients ON ticket_client_id = client_id
LEFT JOIN contacts ON ticket_contact_id = contact_id
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
WHERE ticket_id = $ticket_id
AND ticket_closed_at IS NULL");
$row = mysqli_fetch_array($sql);

$ticket_prefix = sanitizeInput($row['ticket_prefix']);
$ticket_number = intval($row['ticket_number']);
$ticket_category = sanitizeInput($row['ticket_category']);
$ticket_subject = sanitizeInput($row['ticket_subject']);
$ticket_details = mysqli_escape_string($mysqli, $row['ticket_details']);
$ticket_priority = sanitizeInput($row['ticket_priority']);
$ticket_status = sanitizeInput($row['ticket_status_name']);
$client_id = intval($row['ticket_client_id']);
$ticket_created_by = intval($row['ticket_created_by']);
$ticket_assigned_to = intval($row['ticket_assigned_to']);

// Get Company Phone Number
$sql = mysqli_query($mysqli, "SELECT company_name, company_phone FROM companies WHERE company_id = 1");
$row = mysqli_fetch_array($sql);
$company_name = sanitizeInput($row['company_name']);
$company_phone = sanitizeInput(formatPhoneNumber($row['company_phone']));

// Email content
$data = []; // Queue array

$subject = "Ticket Notification - [$ticket_prefix$ticket_number] - $ticket_subject";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello,<br><br>You are now a watcher on a ticket regarding \"$ticket_subject\".<br><br>--------------------------------<br>$ticket_details--------------------------------<br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";


// Only add watcher to email queue if email is valid
if (filter_var($watcher_email, FILTER_VALIDATE_EMAIL)) {
$data[] = [
'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name,
'recipient' => $watcher_email,
'recipient_name' => $watcher_email,
'subject' => $subject,
'body' => $body
];
}

addToMailQueue($mysqli, $data);
}

//Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Edit', log_description = '$session_name added watcher $watcher_email to ticket $ticket_number', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id");

Expand Down
7 changes: 4 additions & 3 deletions ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
<div class="mt-1">
<i class="fa fa-fw fa-history text-secondary mr-2"></i>Updated: <strong><?php echo $ticket_updated_at; ?></strong>
</div>

<!-- Ticket closure info -->
<?php
if (!empty($ticket_closed_at)) {
Expand All @@ -346,7 +346,7 @@
<?php } else { ?>
<div class="mt-1">
<a href="#" data-toggle="modal" data-target="#assignTicketModal<?php echo $ticket_id; ?>">
<i class="fas fa-fw fa-user mr-2 text-secondary"></i><?php echo $ticket_assigned_to_display; ?>
<i class="fas fa-fw fa-user mr-2 text-secondary"></i><?php echo $ticket_assigned_to_display; ?>
</a>
</div>
<?php } ?>
Expand Down Expand Up @@ -468,6 +468,7 @@
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#mergeTicketModal<?php echo $ticket_id; ?>">
<i class="fas fa-fw fa-clone mr-2"></i>Merge
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-toggle="modal" id="clientChangeTicketModalLoad" data-target="#clientChangeTicketModal">
<i class="fas fa-fw fa-people-carry mr-2"></i>Change Client
</a>
Expand Down Expand Up @@ -865,7 +866,7 @@
</td>
</tr>

<?php
<?php

require "task_edit_modal.php";
} ?>
Expand Down
14 changes: 13 additions & 1 deletion ticket_add_watcher_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<input type="hidden" name="ticket_id" value="<?php echo $ticket_id; ?>">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="ticket_number" value="<?php echo "$ticket_prefix$ticket_number"; ?>">
<input type="hidden" name="watcher_notify" value="0"> <!-- Default 0 -->
<div class="modal-body bg-white">

<div class="form-group">
Expand All @@ -37,7 +38,18 @@
</select>
</div>
</div>


<?php if (!empty($config_smtp_host)) { ?>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="watcher_notify" value="1" id="checkNotifyWatcher">
<label class="form-check-label" for="checkNotifyWatcher">
Send email notification
</label>
</div>
</div>
<?php } ?>

</div>

<div class="modal-footer bg-white">
Expand Down
15 changes: 13 additions & 2 deletions ticket_edit_contact_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<input type="hidden" name="ticket_id" value="<?php echo $ticket_id; ?>">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="ticket_number" value="<?php echo "$ticket_prefix$ticket_number"; ?>">
<input type="hidden" name="contact_notify" value="0"> <!-- Default 0 -->
<div class="modal-body bg-white">

<div class="form-group">
Expand Down Expand Up @@ -44,15 +45,25 @@
} else {
$contact_title_display_select = "";
}

?>
<option value="<?php echo $contact_id_select; ?>" <?php if ($contact_id_select == $contact_id) { echo "selected"; } ?>><?php echo "$contact_name_select$contact_title_display_select$contact_primary_display_select$contact_technical_display_select"; ?></option>
<?php } ?>
</select>
</div>

</div>

<?php if (!empty($config_smtp_host)) { ?>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="contact_notify" value="1" id="checkNotifyContact" <?php if ($config_ticket_client_general_notifications) { echo "checked"; } ?>>
<label class="form-check-label" for="checkNotifyContact">
Send email notification
</label>
</div>
</div>
<?php } ?>

</div>

<div class="modal-footer bg-white">
Expand Down
14 changes: 13 additions & 1 deletion ticket_edit_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<input type="hidden" name="ticket_id" value="<?php echo $ticket_id; ?>">
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
<input type="hidden" name="ticket_number" value="<?php echo "$ticket_prefix$ticket_number"; ?>">
<input type="hidden" name="contact_notify" value="0"> <!-- Default 0 -->
<div class="modal-body bg-white">

<ul class="nav nav-pills nav-justified mb-3">
Expand Down Expand Up @@ -120,14 +121,25 @@
} else {
$contact_title_display_select = "";
}

?>
<option value="<?php echo $contact_id_select; ?>" <?php if ($contact_id_select == $contact_id) { echo "selected"; } ?>><?php echo "$contact_name_select$contact_title_display_select$contact_primary_display_select$contact_technical_display_select"; ?></option>
<?php } ?>
</select>
</div>
</div>

<?php if (!empty($config_smtp_host)) { ?>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="contact_notify" value="1" id="checkNotifyContact">
<label class="form-check-label" for="checkNotifyContact">
Send email notification
</label>
</div>
</div>
<?php } ?>

</div>

<div class="tab-pane fade" id="pills-assets<?php echo $ticket_id; ?>">
Expand Down

0 comments on commit a33a91c

Please sign in to comment.