Skip to content

Commit

Permalink
Remove Rack Photo on deletion and do not remove rack_units as the DB …
Browse files Browse the repository at this point in the history
…is set to cacade delete these
  • Loading branch information
johnnyq committed Jun 14, 2024
1 parent 5ba0315 commit aca5a1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client_racks.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class="btn btn-<?php if($archived == 1){ echo "primary"; } else { echo "default"
<i class="fas fa-fw fa-archive mr-2"></i>Archive
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?archive_rack=<?php echo $rack_id; ?>">
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_rack=<?php echo $rack_id; ?>">
<i class="fas fa-fw fa-trash mr-2"></i>Delete
</a>
<?php } ?>
Expand Down
9 changes: 6 additions & 3 deletions post/rack.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,18 @@
$rack_id = intval($_GET['delete_rack']);

// Get Name and Client ID for logging and alert message
$sql = mysqli_query($mysqli,"SELECT rack_name, rack_client_id FROM racks WHERE rack_id = $rack_id");
$sql = mysqli_query($mysqli,"SELECT rack_name, rack_client_id, rack_photo FROM racks WHERE rack_id = $rack_id");
$row = mysqli_fetch_array($sql);
$rack_name = sanitizeInput($row['rack_name']);
$rack_photo = sanitizeInput($row['rack_photo']);
$client_id = intval($row['rack_client_id']);

mysqli_query($mysqli,"DELETE FROM racks WHERE rack_id = $rack_id");

// Delete related units
mysqli_query($mysqli,"DELETE FROM rack_units WHERE unit_rack_id = $rack_id");
// Delete Photo if exists
if ($rack_photo) {
unlink("uploads/clients/$client_id/$rack_photo");
}

//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Rack', log_action = 'Delete', log_description = '$session_name deleted rack $rack_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $rack_id");
Expand Down

0 comments on commit aca5a1e

Please sign in to comment.