/
var
/
www
/
vhosts
/
m-auto.co
/
httpdocs
/
admin
/
/var/www/vhosts/m-auto.co/httpdocs/admin
mkdir
upload
Name
Size
Mode
Actions
assets/
-
0755
rm
includes/
-
0755
rm
7-6-2026.zip
10206
0644
edit
dl
rm
about_edit.php
3899
0644
edit
dl
rm
about_process.php
1367
0644
edit
dl
rm
auth.php
684
0644
edit
dl
rm
bookings.php
5367
0644
edit
dl
rm
booking_delete.php
924
0644
edit
dl
rm
branches.php
2470
0644
edit
dl
rm
branch_delete.php
1290
0644
edit
dl
rm
branch_form.php
4694
0644
edit
dl
rm
branch_process.php
1233
0644
edit
dl
rm
brands.php
2578
0644
edit
dl
rm
brand_delete.php
1327
0644
edit
dl
rm
brand_form.php
2369
0644
edit
dl
rm
brand_process.php
1660
0644
edit
dl
rm
cars.php
6946
0644
edit
dl
rm
car_delete.php
2886
0644
edit
dl
rm
car_form.php
40348
0644
edit
dl
rm
car_image_actions.php
5142
0644
edit
dl
rm
car_process.php
10426
0644
edit
dl
rm
categories.php
2167
0644
edit
dl
rm
category_delete.php
746
0644
edit
dl
rm
category_form.php
1607
0644
edit
dl
rm
category_process.php
943
0644
edit
dl
rm
dashboard.php
4965
0644
edit
dl
rm
index.php
2713
0644
edit
dl
rm
login_process.php
1532
0644
edit
dl
rm
logout.php
100
0644
edit
dl
rm
news.php
3448
0644
edit
dl
rm
news_delete.php
771
0644
edit
dl
rm
news_form.php
6769
0644
edit
dl
rm
news_process.php
2527
0644
edit
dl
rm
offers.php
2810
0644
edit
dl
rm
offer_delete.php
1327
0644
edit
dl
rm
offer_form.php
4573
0644
edit
dl
rm
offer_process.php
2115
0644
edit
dl
rm
settings.php
5217
0644
edit
dl
rm
settings_process.php
692
0644
edit
dl
rm
slider.php
3529
0644
edit
dl
rm
slider_delete.php
1345
0644
edit
dl
rm
slider_form.php
4529
0644
edit
dl
rm
slider_process.php
1983
0644
edit
dl
rm
themes.php
4703
0644
edit
dl
rm
theme_delete.php
1332
0644
edit
dl
rm
theme_form.php
1522
0644
edit
dl
rm
theme_process.php
1785
0644
edit
dl
rm
users.php
4480
0644
edit
dl
rm
user_delete.php
1055
0644
edit
dl
rm
user_form.php
5463
0644
edit
dl
rm
user_process.php
3193
0644
edit
dl
rm
videos.php
4942
0644
edit
dl
rm
video_delete.php
1717
0644
edit
dl
rm
video_form.php
7181
0644
edit
dl
rm
video_process.php
3336
0644
edit
dl
rm
Edit:
/var/www/vhosts/m-auto.co/httpdocs/admin/car_image_actions.php
(5142B)
<?php include 'auth.php'; include '../includes/db.php'; header('Content-Type: application/json'); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $action = $_POST['action'] ?? ''; $image_id = intval($_POST['image_id'] ?? 0); if ($image_id <= 0) { echo json_encode(['success' => false, 'message' => 'معرف الصورة غير صحيح']); exit; } switch ($action) { case 'delete': // Get image info before deletion $stmt = $conn->prepare("SELECT image_name, car_id FROM car_images WHERE id = ?"); $stmt->bind_param("i", $image_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 1) { $image = $result->fetch_assoc(); // Delete the image file $image_path = '../uploads/cars/' . $image['image_name']; if (file_exists($image_path)) { unlink($image_path); } // Delete from database $delete_stmt = $conn->prepare("DELETE FROM car_images WHERE id = ?"); $delete_stmt->bind_param("i", $image_id); if ($delete_stmt->execute()) { // If this was the primary image, set another image as primary $check_primary = $conn->prepare("SELECT COUNT(*) as count FROM car_images WHERE car_id = ? AND is_primary = 1"); $check_primary->bind_param("i", $image['car_id']); $check_primary->execute(); $primary_result = $check_primary->get_result(); $primary_count = $primary_result->fetch_assoc()['count']; if ($primary_count == 0) { // Set the first remaining image as primary $set_primary = $conn->prepare("UPDATE car_images SET is_primary = 1 WHERE car_id = ? ORDER BY sort_order ASC LIMIT 1"); $set_primary->bind_param("i", $image['car_id']); $set_primary->execute(); $set_primary->close(); } $check_primary->close(); echo json_encode(['success' => true, 'message' => 'تم حذف الصورة بنجاح']); } else { echo json_encode(['success' => false, 'message' => 'فشل في حذف الصورة من قاعدة البيانات']); } $delete_stmt->close(); } else { echo json_encode(['success' => false, 'message' => 'الصورة غير موجودة']); } $stmt->close(); break; case 'set_primary': // Get car_id for this image $stmt = $conn->prepare("SELECT car_id FROM car_images WHERE id = ?"); $stmt->bind_param("i", $image_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 1) { $image = $result->fetch_assoc(); $car_id = $image['car_id']; // Start transaction $conn->begin_transaction(); try { // Remove primary status from all images of this car $remove_primary = $conn->prepare("UPDATE car_images SET is_primary = 0 WHERE car_id = ?"); $remove_primary->bind_param("i", $car_id); $remove_primary->execute(); $remove_primary->close(); // Set this image as primary $set_primary = $conn->prepare("UPDATE car_images SET is_primary = 1 WHERE id = ?"); $set_primary->bind_param("i", $image_id); $set_primary->execute(); $set_primary->close(); $conn->commit(); echo json_encode(['success' => true, 'message' => 'تم تعيين الصورة الرئيسية بنجاح']); } catch (Exception $e) { $conn->rollback(); echo json_encode(['success' => false, 'message' => 'فشل في تعيين الصورة الرئيسية']); } } else { echo json_encode(['success' => false, 'message' => 'الصورة غير موجودة']); } $stmt->close(); break; default: echo json_encode(['success' => false, 'message' => 'عملية غير صحيحة']); break; } } else { echo json_encode(['success' => false, 'message' => 'طريقة الطلب غير صحيحة']); } $conn->close(); ?>
Save
cmd:
run