feat: complete modern PHP tire showcase, calculator, comparison, guide and admin platform
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// api.php
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
require_once __DIR__ . '/includes/db.php';
|
||||
|
||||
$action = $_GET['action'] ?? $_POST['action'] ?? '';
|
||||
|
||||
switch ($action) {
|
||||
case 'get_tires':
|
||||
$tires = TireStore::getTires();
|
||||
$brand = $_GET['brand'] ?? '';
|
||||
$rim = $_GET['rim'] ?? '';
|
||||
$season = $_GET['season'] ?? '';
|
||||
$category = $_GET['category'] ?? '';
|
||||
$q = trim($_GET['q'] ?? '');
|
||||
|
||||
$filtered = array_filter($tires, function($t) use ($brand, $rim, $season, $category, $q) {
|
||||
if ($brand && $t['brand'] !== $brand) return false;
|
||||
if ($rim && (string)$t['rim'] !== (string)$rim) return false;
|
||||
if ($season && $t['season'] !== $season) return false;
|
||||
if ($category && stripos($t['category'], $category) === false) return false;
|
||||
if ($q) {
|
||||
$searchContent = $t['name'] . ' ' . $t['brand'] . ' ' . $t['size_str'] . ' ' . implode(' ', $t['vehicles'] ?? []);
|
||||
if (stripos($searchContent, $q) === false) return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
echo json_encode(["status" => "success", "count" => count($filtered), "data" => array_values($filtered)], JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
|
||||
case 'get_tire':
|
||||
$id = $_GET['id'] ?? '';
|
||||
$tire = TireStore::getTireById($id);
|
||||
if ($tire) {
|
||||
echo json_encode(["status" => "success", "data" => $tire], JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
echo json_encode(["status" => "error", "message" => "تایر مورد نظر یافت نشد."], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'submit_consultation':
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$phone = trim($_POST['phone'] ?? '');
|
||||
$car = trim($_POST['car'] ?? '');
|
||||
$message = trim($_POST['message'] ?? '');
|
||||
|
||||
if (!$name || !$phone) {
|
||||
echo json_encode(["status" => "error", "message" => "لطفاً نام و شماره تماس خود را وارد نمایید."], JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
$res = TireStore::addConsultation([
|
||||
"name" => $name,
|
||||
"phone" => $phone,
|
||||
"car" => $car,
|
||||
"message" => $message
|
||||
]);
|
||||
|
||||
echo json_encode(["status" => "success", "message" => "درخواست مشاوره شما با موفقیت ثبت شد. کارشناسان ما به زودی با شما تماس خواهند گرفت.", "data" => $res], JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
|
||||
default:
|
||||
echo json_encode(["status" => "error", "message" => "Invalid action"], JSON_UNESCAPED_UNICODE);
|
||||
break;
|
||||
}
|
||||
Reference in New Issue
Block a user