Add functionality to edit scheduled tickets. Small other fixes

This commit is contained in:
Marcus Hill 2022-02-05 12:59:07 +00:00
parent 6dda8ce0d6
commit 7b23c04d78
5 changed files with 134 additions and 12 deletions

View File

@ -203,5 +203,5 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<?php
include("ticket_add_modal.php");
include("add_scheduled_ticket_modal.php");
include("scheduled_ticket_add_modal.php");
?>

View File

@ -5326,8 +5326,8 @@ if(isset($_POST['add_scheduled_ticket'])){
$priority = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['priority'])));
$details = trim(mysqli_real_escape_string($mysqli,$_POST['details']));
$asset_id = intval($_POST['asset']);
$frequency = trim(mysqli_real_escape_string($mysqli,$_POST['frequency']));
$start_date = mysqli_real_escape_string($mysqli,$_POST['start_date']);
$frequency = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['frequency'])));
$start_date = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['start_date'])));
if($client_id > 0 AND $contact == 0){
$sql = mysqli_query($mysqli,"SELECT primary_contact FROM clients WHERE client_id = $client_id AND company_id = $session_company_id");
@ -5347,6 +5347,28 @@ if(isset($_POST['add_scheduled_ticket'])){
}
if(isset($_POST['edit_scheduled_ticket'])){
$client_id = intval($_POST['client_id']);
$ticket_id = intval($_POST['ticket_id']);
$subject = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['subject'])));
$priority = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['priority'])));
$details = trim(mysqli_real_escape_string($mysqli,$_POST['details']));
$asset_id = intval($_POST['asset']);
$frequency = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['frequency'])));
$next_run_date = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['next_date'])));
// Edit scheduled ticket
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_updated_at = NOW(), scheduled_ticket_asset_id = '$asset_id', company_id = '$session_company_id' WHERE scheduled_ticket_id = '$ticket_id'");
// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Updated scheduled ticket for $subject - $frequency', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id, log_user_id = $session_user_id");
$_SESSION['alert_message'] = "Scheduled ticket updated.";
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
if(isset($_GET['delete_scheduled_ticket'])){
$scheduled_ticket_id = intval($_GET['delete_scheduled_ticket']);

View File

@ -2,7 +2,7 @@
<div class="modal-dialog modal-lg">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-tag"></i> New Scheduled Ticket</h5>
<h5 class="modal-title"><i class="fa fa-fw fa-sync"></i> New Scheduled Ticket</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
@ -64,7 +64,7 @@
<label>Frequency <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<span class="input-group-text"><i class="fa fa-fw fa-calendar-plus"></i></span>
</div>
<select class="form-control select2" name="frequency" required>
<option>Weekly</option>
@ -77,9 +77,9 @@
<label>Starting date <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
</div>
<input class="form-control" type="date" min="<?php echo date("Y-m-d"); ?>" name="start_date">
<input class="form-control" type="date" min="<?php echo date("Y-m-d"); ?>" name="start_date" required>
</div>
</div>

View File

@ -1,5 +1,4 @@
<?php
//include("config.php");
include("header.php");
//Paging
@ -29,8 +28,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<tr>
<th><a class="text-dark">Client</a></th>
<th><a class="text-dark">Subject</a></th>
<th><a class="text-dark">Frequency</a></th>
<th><a class="text-dark">Priority</a></th>
<th><a class="text-dark">Frequency</a></th>
<th><a class="text-dark">Next Run Date</a></th>
<th class="text-center">Action</th>
</tr>
@ -40,6 +40,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
while($row = mysqli_fetch_array($sql)){
$scheduled_ticket_id = $row['scheduled_ticket_id'];
$scheduled_ticket_client_id = $row['client_id'];
$scheduled_ticket_category = $row['scheduled_ticket_category'];
$scheduled_ticket_subject = $row['scheduled_ticket_subject'];
$scheduled_ticket_details = $row['scheduled_ticket_details'];
@ -55,8 +56,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<tr>
<td><a> <?php echo $scheduled_ticket_client_name ?></a></td>
<td><a> <?php echo $scheduled_ticket_subject ?></a></td>
<td><a> <?php echo $scheduled_ticket_frequency ?></a></td>
<td><a> <?php echo $scheduled_ticket_priority ?></a></td>
<td><a> <?php echo $scheduled_ticket_frequency ?></a></td>
<td><a> <?php echo $scheduled_ticket_next_run ?></a></td>
<td>
<div class="dropdown dropleft text-center">
@ -64,7 +66,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<!--<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editScheduledTicketModal<?php echo $scheduled_ticket_id; ?>">Edit</a>-->
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editScheduledTicketModal<?php echo $scheduled_ticket_id; ?>">Edit</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="post.php?delete_scheduled_ticket=<?php echo $scheduled_ticket_id; ?>">Delete</a>
</div>
@ -73,6 +75,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
</tr>
<?php
include("scheduled_tickets_edit_modal.php");
}
?>
@ -85,5 +88,4 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
<?php
//include(".php");
include("footer.php");

View File

@ -0,0 +1,98 @@
<div class="modal" id="editScheduledTicketModal<?php echo $scheduled_ticket_id ?>" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-sync"></i> Edit Scheduled Ticket - <?php echo "$scheduled_ticket_subject for $scheduled_ticket_client_name "?></h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<div class="modal-body bg-white">
<input type="hidden" name="ticket_id" value="<?php echo $scheduled_ticket_id; ?>">
<input type="hidden" name="client_id" value="<?php echo $scheduled_ticket_client_id; ?>">
<div class="form-group">
<label>Frequency <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar-plus"></i></span>
</div>
<select class="form-control select2" name="frequency" required>
<option <?php if($scheduled_ticket_frequency == "Weekly") {echo "selected";} ?>>Weekly</option>
<option <?php if($scheduled_ticket_frequency == "Monthly") {echo "selected";} ?>>Monthly</option>
</select>
</div>
</div>
<div class="form-group">
<label>Next run date <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
</div>
<input class="form-control" type="date" name="next_date" value="<?php echo $scheduled_ticket_next_run ?>">
</div>
</div>
<div class="form-group">
<label>Priority <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
</div>
<select class="form-control select2" name="priority" required>
<option <?php if($scheduled_ticket_priority == 'Low'){ echo "selected"; } ?> >Low</option>
<option <?php if($scheduled_ticket_priority == 'Medium'){ echo "selected"; } ?> >Medium</option>
<option <?php if($scheduled_ticket_priority == 'High'){ echo "selected"; } ?> >High</option>
</select>
</div>
</div>
<div class="form-group">
<label>Subject <strong class="text-danger">*</strong></label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-tag"></i></span>
</div>
<input type="text" class="form-control" name="subject" placeholder="Subject" required value="<?php echo $scheduled_ticket_subject?>">
</div>
</div>
<div class="form-group">
<label>Asset</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
</div>
<select class="form-control select2" name="asset">
<option value="0">- None -</option>
<?php
$sql_assets = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_client_id = $scheduled_ticket_client_id ORDER BY asset_name ASC");
while($row = mysqli_fetch_array($sql_assets)){
$asset_id_select = $row['asset_id'];
$asset_name_select = $row['asset_name'];
?>
<option value="<?php echo $asset_id_select?>" <?php if($asset_id_select == $scheduled_ticket_asset_id){echo "selected";} ?>><?php echo $asset_name_select; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<textarea class="form-control summernote" rows="8" name="details"><?php echo $scheduled_ticket_details ?></textarea>
</div>
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="edit_scheduled_ticket" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>