🤩 File Manager - Mr.X
PHP:
8.3.33
Server:
Apache
OS:
Linux 5.14.0-611.49.1.el9_7.x86_64
User:
websparkit
Navigate
Upload:
Upload
New File
New Folder
Editing:ajax_operations.php
<?php // admin/ajax_operations.php header('Content-Type: application/json'); require_once '../includes/db.php'; require_once '../includes/functions.php'; // Extract requested action $action = $_POST['action'] ?? ''; if (empty($action)) { echo json_encode(['success' => false, 'message' => 'No action parameters specified.']); exit; } try { // 1. DELETE ORDER ACTION if ($action === 'delete_order') { $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; if ($id <= 0) { echo json_encode(['success' => false, 'message' => 'Invalid order identifier.']); exit; } // Fetch order to clean up its reference image $stmt = $pdo->prepare("SELECT image FROM orders WHERE id = ?"); $stmt->execute([$id]); $order = $stmt->fetch(); if ($order) { // Delete reference photo from uploads directory if (!empty($order['image'])) { $image_path = '../uploads/' . $order['image']; if (file_exists($image_path)) { unlink($image_path); } } // Remove order record from database $delete_stmt = $pdo->prepare("DELETE FROM orders WHERE id = ?"); $delete_stmt->execute([$id]); echo json_encode([ 'success' => true, 'message' => 'Order was successfully deleted from the system.' ]); exit; } else { echo json_encode(['success' => false, 'message' => 'Order not found in database.']); exit; } } // 2. UPDATE STATUS ACTION elseif ($action === 'update_status') { $id = isset($_POST['id']) ? (int)$_POST['id'] : 0; $status = $_POST['status'] ?? ''; $valid_statuses = ['Pending', 'Confirmed', 'Processing', 'Completed', 'Cancelled']; if ($id <= 0 || !in_array($status, $valid_statuses)) { echo json_encode(['success' => false, 'message' => 'Invalid parameters passed for status update.']); exit; } // Update the order status $update_stmt = $pdo->prepare("UPDATE orders SET status = ? WHERE id = ?"); $update_stmt->execute([$status, $id]); echo json_encode([ 'success' => true, 'message' => 'Order status has been updated to ' . $status . '.' ]); exit; } // 3. UNKNOWN ACTION FALLBACK else { echo json_encode(['success' => false, 'message' => 'Requested action is invalid.']); exit; } } catch (Exception $e) { echo json_encode([ 'success' => false, 'message' => 'Server error: ' . $e->getMessage() ]); exit; } ?>
Save Changes
Cancel
Create New File
Create New Folder