Merge pull request #634 from wrongecho/bulk-update
Add bulk delete option for scheduled tickets
This commit is contained in:
@@ -22,7 +22,6 @@ $sql = mysqli_query(
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
?>
|
||||
<script src="js/scheduled_tickets_edit_modal.js"></script>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
@@ -56,11 +55,16 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
<hr>
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<form id="bulk_actions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead class="<?php if ($num_rows[0] == 0) {
|
||||
echo "d-none";
|
||||
} ?>">
|
||||
<tr>
|
||||
<th><a class="text-dark">Select</a></th>
|
||||
<th><a class="text-dark">Subject</a></th>
|
||||
<th><a class="text-dark">Priority</a></th>
|
||||
<th><a class="text-dark">Frequency</a></th>
|
||||
@@ -80,9 +84,18 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="scheduled_ticket_ids[]" onchange="showBulkDeleteButton()" value="<?php echo $scheduled_ticket_id ?>">
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="text-bold"><a href="#" data-toggle="modal" data-target="#editScheduledTicketModal" onclick="populateScheduledTicketEditModal(<?php echo $client_id, ',', $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?></a></td>
|
||||
|
||||
<td><?php echo $scheduled_ticket_priority ?></td>
|
||||
|
||||
<td><?php echo $scheduled_ticket_frequency ?></td>
|
||||
|
||||
<td><?php echo $scheduled_ticket_next_run ?></td>
|
||||
|
||||
<td>
|
||||
@@ -111,16 +124,24 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<?php
|
||||
require_once('pagination.php');
|
||||
require_once("scheduled_ticket_edit_modal.php");
|
||||
?>
|
||||
|
||||
<div class="form-check">
|
||||
<input type="submit" id="button_bulk_delete" form="bulk_actions" name="bulk_delete_scheduled_tickets" value="Bulk Delete" hidden>
|
||||
</div>
|
||||
|
||||
<?php require_once('pagination.php'); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<script src="js/scheduled_tickets_edit_modal.js"></script>
|
||||
<script src="js/scheduled_tickets_bulk_delete_button.js"></script>
|
||||
|
||||
<?php
|
||||
|
||||
require_once("scheduled_ticket_add_modal.php");
|
||||
|
||||
require_once("scheduled_ticket_edit_modal.php");
|
||||
require_once("footer.php");
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
function showBulkDeleteButton() {
|
||||
document.getElementById("button_bulk_delete").hidden = false;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// HTML Purifier
|
||||
require_once("plugins/htmlpurifier/HTMLPurifier.standalone.php");
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
$client_id = intval($_POST['client']);
|
||||
$subject = sanitizeInput($_POST['subject']);
|
||||
$priority = sanitizeInput($_POST['priority']);
|
||||
$details = trim(mysqli_real_escape_string($mysqli, $purifier->purify(html_entity_decode($_POST['details']))));
|
||||
$frequency = sanitizeInput($_POST['frequency']);
|
||||
|
||||
|
||||
$asset_id = "0";
|
||||
if (isset($_POST['asset'])) {
|
||||
$asset_id = intval($_POST['asset']);
|
||||
}
|
||||
|
||||
$contact_id = "0";
|
||||
if (isset($_POST['contact'])) {
|
||||
$contact_id = intval($_POST['contact']);
|
||||
}
|
||||
@@ -7062,29 +7062,17 @@ if(isset($_POST['add_scheduled_ticket'])){
|
||||
|
||||
validateTechRole();
|
||||
|
||||
// HTML Purifier
|
||||
require("plugins/htmlpurifier/HTMLPurifier.standalone.php");
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
$client_id = intval($_POST['client']);
|
||||
$contact = intval($_POST['contact']);
|
||||
$subject = sanitizeInput($_POST['subject']);
|
||||
$priority = sanitizeInput($_POST['priority']);
|
||||
$details = trim(mysqli_real_escape_string($mysqli,$purifier->purify(html_entity_decode($_POST['details']))));
|
||||
$asset_id = intval($_POST['asset']);
|
||||
$frequency = sanitizeInput($_POST['frequency']);
|
||||
require_once('models/scheduled_ticket.php');
|
||||
$start_date = sanitizeInput($_POST['start_date']);
|
||||
|
||||
if($client_id > 0 && $contact == 0){
|
||||
if ($client_id > 0 && $contact_id == 0) {
|
||||
$sql = mysqli_query($mysqli, "SELECT primary_contact FROM clients WHERE client_id = $client_id AND company_id = $session_company_id");
|
||||
$row = mysqli_fetch_array($sql);
|
||||
$contact = intval($row['primary_contact']);
|
||||
$contact_id = intval($row['primary_contact']);
|
||||
}
|
||||
|
||||
// Add scheduled ticket
|
||||
mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_created_by = $session_user_id, scheduled_ticket_client_id = $client_id, scheduled_ticket_contact_id = $contact, scheduled_ticket_asset_id = $asset_id, company_id = $session_company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO scheduled_tickets SET scheduled_ticket_subject = '$subject', scheduled_ticket_details = '$details', scheduled_ticket_priority = '$priority', scheduled_ticket_frequency = '$frequency', scheduled_ticket_start_date = '$start_date', scheduled_ticket_next_run = '$start_date', scheduled_ticket_created_by = $session_user_id, scheduled_ticket_client_id = $client_id, scheduled_ticket_contact_id = $contact_id, scheduled_ticket_asset_id = $asset_id, company_id = $session_company_id");
|
||||
|
||||
$scheduled_ticket_id = mysqli_insert_id($mysqli);
|
||||
|
||||
@@ -7101,19 +7089,8 @@ if(isset($_POST['edit_scheduled_ticket'])){
|
||||
|
||||
validateTechRole();
|
||||
|
||||
// HTML Purifier
|
||||
require("plugins/htmlpurifier/HTMLPurifier.standalone.php");
|
||||
$purifier_config = HTMLPurifier_Config::createDefault();
|
||||
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
|
||||
$purifier = new HTMLPurifier($purifier_config);
|
||||
|
||||
$client_id = intval($_POST['client_id']);
|
||||
require_once('models/scheduled_ticket.php');
|
||||
$scheduled_ticket_id = intval($_POST['scheduled_ticket_id']);
|
||||
$subject = sanitizeInput($_POST['subject']);
|
||||
$priority = sanitizeInput($_POST['priority']);
|
||||
$details = trim(mysqli_real_escape_string($mysqli,$purifier->purify(html_entity_decode($_POST['details']))));
|
||||
$asset_id = intval($_POST['asset']);
|
||||
$frequency = sanitizeInput($_POST['frequency']);
|
||||
$next_run_date = sanitizeInput($_POST['next_date']);
|
||||
|
||||
// Edit scheduled ticket
|
||||
@@ -7153,6 +7130,35 @@ if(isset($_GET['delete_scheduled_ticket'])){
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_delete_scheduled_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
|
||||
|
||||
if (!empty($scheduled_ticket_ids)) {
|
||||
|
||||
// Cycle through array and delete each 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, company_id = $session_company_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, company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Deleted $count scheduled ticket(s)";
|
||||
|
||||
}
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
if(isset($_POST['add_service'])){
|
||||
|
||||
validateTechRole();
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
?>
|
||||
<option value="<?php echo $contact_id; ?>" <?php if ($primary_contact == $contact_id) { echo "selected"; } ?>><?php echo $contact_name; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -47,14 +45,12 @@
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE company_id = $session_company_id ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_array($sql)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$selectable_client_id = intval($row['client_id']);
|
||||
$client_name = htmlentities($row['client_name']);
|
||||
?>
|
||||
<option value="<?php echo $client_id; ?>"><?php echo $client_name; ?></option>
|
||||
<option value="<?php echo $selectable_client_id; ?>"><?php echo $client_name; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -110,6 +106,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (isset($client_id)) { ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Asset</label>
|
||||
<div class="input-group">
|
||||
@@ -119,21 +117,21 @@
|
||||
<select class="form-control select2" name="asset">
|
||||
<option value="0">- None -</option>
|
||||
<?php
|
||||
$sql_assets = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM assets WHERE asset_client_id = $client_id ORDER BY asset_name ASC");
|
||||
|
||||
$sql_assets = mysqli_query($mysqli, "SELECT * FROM assets WHERE asset_client_id = $client_id ORDER BY asset_name ASC");
|
||||
while ($row = mysqli_fetch_array($sql_assets)) {
|
||||
$asset_id_select = intval($row['asset_id']);
|
||||
$asset_name_select = htmlentities($row['asset_name']);
|
||||
?>
|
||||
<option value="<?php echo $asset_id_select; ?>"><?php echo $asset_name_select; ?></option>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<div class="form-group">
|
||||
<textarea class="form-control summernote" rows="8" name="details"></textarea>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<div class="modal-body bg-white">
|
||||
<input type="hidden" name="scheduled_ticket_id" id="editTicketId">
|
||||
<input type="hidden" name="client_id" id="editClientId">
|
||||
<input type="hidden" name="client" id="editClientId">
|
||||
|
||||
<div class="form-group">
|
||||
<label>Frequency <strong class="text-danger">*</strong></label>
|
||||
|
||||
+31
-2
@@ -22,8 +22,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
?>
|
||||
|
||||
<script src="js/scheduled_tickets_edit_modal.js"></script>
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-clock mr-2"></i>Scheduled Tickets</h3>
|
||||
@@ -55,11 +53,16 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
<hr>
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<form id="bulk_actions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<table class="table table-striped table-borderless table-hover">
|
||||
<thead class="<?php if ($num_rows[0] == 0) {
|
||||
echo "d-none";
|
||||
} ?>">
|
||||
<tr>
|
||||
<th><a class="text-dark">Select</a></th>
|
||||
<th><a class="text-dark">Client</a></th>
|
||||
<th><a class="text-dark">Subject</a></th>
|
||||
<th><a class="text-dark">Priority</a></th>
|
||||
@@ -68,7 +71,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_array($sql)) {
|
||||
@@ -82,14 +87,24 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="scheduled_ticket_ids[]" onchange="showBulkDeleteButton()" value="<?php echo $scheduled_ticket_id ?>">
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td class="text-bold"><a href="client_scheduled_tickets.php?client_id=<?php echo $scheduled_ticket_client_id; ?>"><?php echo $scheduled_ticket_client_name ?></a></td>
|
||||
|
||||
<td>
|
||||
<a href="#" data-toggle="modal" data-target="#editScheduledTicketModal"
|
||||
onclick="populateScheduledTicketEditModal(<?php echo $scheduled_ticket_client_id, ",", $scheduled_ticket_id ?>)"> <?php echo $scheduled_ticket_subject ?>
|
||||
</a>
|
||||
</td>
|
||||
|
||||
<td><?php echo $scheduled_ticket_priority ?></td>
|
||||
|
||||
<td><?php echo $scheduled_ticket_frequency ?></td>
|
||||
|
||||
<td class="text-bold"><?php echo $scheduled_ticket_next_run ?></td>
|
||||
|
||||
<td>
|
||||
@@ -112,17 +127,31 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-check">
|
||||
<input type="submit" id="button_bulk_delete" form="bulk_actions" name="bulk_delete_scheduled_tickets" value="Bulk Delete" hidden>
|
||||
</div>
|
||||
|
||||
<?php require_once('pagination.php'); ?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="js/scheduled_tickets_edit_modal.js"></script>
|
||||
<script src="js/scheduled_tickets_bulk_delete_button.js"></script>
|
||||
|
||||
<?php
|
||||
require_once("scheduled_ticket_add_modal.php");
|
||||
require_once("scheduled_ticket_edit_modal.php");
|
||||
|
||||
Reference in New Issue
Block a user