Skip to content

Commit

Permalink
Recurring tickets
Browse files Browse the repository at this point in the history
- Reword some areas to better separate recurring and scheduled tickets.
- Fix bulk actions not doing anything due to form name mismatch
  • Loading branch information
wrongecho committed Feb 12, 2024
1 parent 85f55a6 commit 2c7b65d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
4 changes: 2 additions & 2 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,9 @@
}

/*
* Looks up info for a given scheduled ticket ID from the database, used to dynamically populate modal edit fields
* Looks up info for a given recurring (was scheduled) ticket ID from the database, used to dynamically populate modal edit fields
*/
if (isset($_GET['scheduled_ticket_get_json_details'])) {
if (isset($_GET['recurring_ticket_get_json_details'])) {
validateTechRole();

$client_id = intval($_GET['client_id']);
Expand Down
6 changes: 3 additions & 3 deletions client_recurring_tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
</div>
</td>

<td class="text-bold"><a href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateScheduledTicketEditModal(<?php echo $client_id, ',', $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?></a></td>
<td class="text-bold"><a href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateRecurringTicketEditModal(<?php echo $client_id, ',', $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?></a></td>

<td><?php echo $scheduled_ticket_priority ?></td>

Expand All @@ -104,13 +104,13 @@
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" data-toggle="modal"
data-target="#editRecurringTicketModal" onclick="populateScheduledTicketEditModal(<?php echo $client_id, ',', $scheduled_ticket_id ?>)">
data-target="#editRecurringTicketModal" onclick="populateRecurringTicketEditModal(<?php echo $client_id, ',', $scheduled_ticket_id ?>)">
<i class="fas fa-fw fa-edit mr-2"></i>Edit
</a>
<?php
if ($session_user_role == 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_scheduled_ticket=<?php echo $scheduled_ticket_id; ?>">
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_recurring_ticket=<?php echo $scheduled_ticket_id; ?>">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</a>
</div>
Expand Down
15 changes: 7 additions & 8 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for tickets that are pending assignment'");
}

// Scheduled tickets
// Recurring (Scheduled) tickets

// Get scheduled tickets for today
// Get recurring tickets for today
$sql_scheduled_tickets = mysqli_query($mysqli, "SELECT * FROM scheduled_tickets WHERE scheduled_ticket_next_run = CURDATE()");

if (mysqli_num_rows($sql_scheduled_tickets) > 0) {
Expand Down Expand Up @@ -263,11 +263,10 @@
$id = mysqli_insert_id($mysqli);

// 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 recurring scheduled $frequency ticket - $subject', log_client_id = $client_id, log_user_id = $created_id");

// Notifications


// Get client/contact/ticket details
$sql = mysqli_query(
$mysqli,
Expand Down Expand Up @@ -313,8 +312,8 @@
// 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 = "ITFlow - New Scheduled Ticket - $client_name: $ticket_subject";
$email_body = "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";
$email_subject = "ITFlow - New Recurring Ticket - $client_name: $ticket_subject";
$email_body = "Hello, <br><br>This is a notification that a recurring 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";

$email = [
'from' => $config_ticket_from_email,
Expand Down Expand Up @@ -358,7 +357,7 @@
}

// Logging
//mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created sent out scheduled tickets'");
//mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created sent out recurring tickets'");


// AUTO CLOSE TICKET - CLOSE
Expand Down Expand Up @@ -729,7 +728,7 @@
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_id') AS num FROM tickets"));
$ticket_count = $row['num'];

// Scheduled Ticket Count
// Recurring (Scheduled) Ticket Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('scheduled_ticket_id') AS num FROM scheduled_tickets"));
$scheduled_ticket_count = $row['num'];

Expand Down
6 changes: 3 additions & 3 deletions js/recurring_tickets_edit_modal.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function populateScheduledTicketEditModal(client_id, ticket_id) {
function populateRecurringTicketEditModal(client_id, ticket_id) {

// Send a GET request to ajax.php as ajax.php?scheduled_ticket_get_json_details=true&client_id=NUM&ticket_id=NUM
// Send a GET request to ajax.php as ajax.php?recurring_ticket_get_json_details=true&client_id=NUM&ticket_id=NUM
jQuery.get(
"ajax.php",
{scheduled_ticket_get_json_details: 'true', client_id: client_id, ticket_id: ticket_id},
{recurring_ticket_get_json_details: 'true', client_id: client_id, ticket_id: ticket_id},
function(data){

// If we get a response from post.php, parse it as JSON
Expand Down
File renamed without changes.
31 changes: 15 additions & 16 deletions post/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -1319,11 +1319,11 @@
exit;
}

if (isset($_POST['add_scheduled_ticket'])) {
if (isset($_POST['add_scheduled_ticket']) || isset($_POST['add_recurring_ticket'])) {

validateTechRole();

require_once 'post/scheduled_ticket_model.php';
require_once 'post/recurring_ticket_model.php';

$start_date = sanitizeInput($_POST['start_date']);

Expand All @@ -1340,18 +1340,18 @@
$scheduled_ticket_id = mysqli_insert_id($mysqli);

// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Create', log_description = '$session_name created scheduled ticket for $subject - $frequency', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Recurring Ticket', log_action = 'Create', log_description = '$session_name created recurring ticket for $subject - $frequency', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");

$_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> created";
$_SESSION['alert_message'] = "Recurring ticket <strong>$subject - $frequency</strong> created";

header("Location: " . $_SERVER["HTTP_REFERER"]);
}

if (isset($_POST['edit_scheduled_ticket'])) {
if (isset($_POST['edit_scheduled_ticket']) || isset($_POST['edit_recurring_ticket'])) {

validateTechRole();

require_once 'post/scheduled_ticket_model.php';
require_once 'post/recurring_ticket_model.php';

$scheduled_ticket_id = intval($_POST['scheduled_ticket_id']);
$next_run_date = sanitizeInput($_POST['next_date']);
Expand All @@ -1367,14 +1367,14 @@
mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_next_run = '$next_run_date', scheduled_ticket_asset_id = $asset_id, scheduled_ticket_contact_id = $contact_id WHERE scheduled_ticket_id = $scheduled_ticket_id");

// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Modify', log_description = '$session_name modified scheduled ticket for $subject - $frequency', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Recurring Ticket', log_action = 'Modify', log_description = '$session_name modified recurring ticket for $subject - $frequency', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");

$_SESSION['alert_message'] = "Scheduled ticket <strong>$subject - $frequency</strong> updated";
$_SESSION['alert_message'] = "Recurring ticket <strong>$subject - $frequency</strong> updated";

header("Location: " . $_SERVER["HTTP_REFERER"]);
}

if (isset($_GET['delete_scheduled_ticket'])) {
if (isset($_GET['delete_scheduled_ticket']) || isset($_POST['delete_recurring_ticket'])) {

validateAdminRole();

Expand All @@ -1399,29 +1399,29 @@
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

if (isset($_POST['bulk_delete_scheduled_tickets'])) {
if (isset($_POST['bulk_delete_scheduled_tickets']) || isset($_POST['bulk_delete_recurring_tickets'])) {
validateAdminRole();
validateCSRFToken($_POST['csrf_token']);

$count = 0; // Default 0
$scheduled_ticket_ids = $_POST['scheduled_ticket_ids']; // Get array of scheduled tickets IDs to be deleted
$scheduled_ticket_ids = $_POST['scheduled_ticket_ids']; // Get array of recurring scheduled tickets IDs to be deleted

if (!empty($scheduled_ticket_ids)) {

// Cycle through array and delete each scheduled ticket
// Cycle through array and delete each recurring scheduled ticket
foreach ($scheduled_ticket_ids as $scheduled_ticket_id) {

$scheduled_ticket_id = intval($scheduled_ticket_id);
mysqli_query($mysqli, "DELETE FROM scheduled_tickets WHERE scheduled_ticket_id = $scheduled_ticket_id");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name deleted scheduled ticket (bulk)', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name deleted recurring ticket (bulk)', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $scheduled_ticket_id");

$count++;
}

// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name bulk deleted $count scheduled tickets', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Scheduled Ticket', log_action = 'Delete', log_description = '$session_name bulk deleted $count recurring tickets', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");

$_SESSION['alert_message'] = "Deleted $count scheduled ticket(s)";
$_SESSION['alert_message'] = "Deleted $count recurring ticket(s)";
}

header("Location: " . $_SERVER["HTTP_REFERER"]);
Expand Down Expand Up @@ -1461,7 +1461,6 @@

if (isset($_POST['edit_ticket_schedule'])) {


validateTechRole();

$ticket_id = intval($_POST['ticket_id']);
Expand Down
4 changes: 2 additions & 2 deletions recurring_ticket_add_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@

</div>
<div class="modal-footer bg-white">
<button type="submit" name="add_scheduled_ticket" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Create</button>
<button type="submit" name="add_recurring_ticket" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Create</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
4 changes: 2 additions & 2 deletions recurring_ticket_edit_modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@
</div>
<div class="modal-footer bg-white">
<button type="submit" name="edit_scheduled_ticket" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
<button type="submit" name="edit_recurring_ticket" class="btn btn-primary text-bold"><i class="fas fa-check mr-2"></i>Save</button>
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fas fa-times mr-2"></i>Cancel</button>
</div>
</form>
</div>
</div>
</div>
</div>
8 changes: 4 additions & 4 deletions recurring_tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<i class="fas fa-fw fa-layer-group mr-2"></i>Bulk Action (<span id="selectedCount">0</span>)
</button>
<div class="dropdown-menu">
<button class="dropdown-item text-danger text-bold" type="submit" form="multi_actions" name="bulk_delete_scheduled_tickets">
<button class="dropdown-item text-danger text-bold" type="submit" form="bulkActions" name="bulk_delete_recurring_tickets">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</button>
</div>
Expand Down Expand Up @@ -117,7 +117,7 @@
</th>

<td>
<a href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateScheduledTicketEditModal(<?php echo $scheduled_ticket_client_id, ",", $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?>
<a href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateRecurringTicketEditModal(<?php echo $scheduled_ticket_client_id, ",", $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?>
</a>
</td>

Expand All @@ -133,13 +133,13 @@
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateScheduledTicketEditModal(<?php echo $scheduled_ticket_client_id, ",", $scheduled_ticket_id ?>)">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editRecurringTicketModal" onclick="populateRecurringTicketEditModal(<?php echo $scheduled_ticket_client_id, ",", $scheduled_ticket_id ?>)">
<i class="fas fa-fw fa-edit mr-2"></i>Edit
</a>
<?php
if ($session_user_role == 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_scheduled_ticket=<?php echo $scheduled_ticket_id; ?>">
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_recurring_ticket=<?php echo $scheduled_ticket_id; ?>">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</a>
<?php } ?>
Expand Down

0 comments on commit 2c7b65d

Please sign in to comment.