diff --git a/web/add_provider.php b/web/add_provider.php index 1c3d785..20674da 100644 --- a/web/add_provider.php +++ b/web/add_provider.php @@ -28,6 +28,26 @@ function callApi(string $method, string $path, $body = null) return json_decode($response, true); } +// Fetch rate options setting +$rateOptionsSetting = callApi('GET', '/settings/rate_options'); +$rateOptions = []; +if ($rateOptionsSetting && isset($rateOptionsSetting['value'])) { + $parsed = json_decode($rateOptionsSetting['value'], true); + if (is_array($parsed)) { + $rateOptions = $parsed; + } +} + +// Update form handling to process selected rates +$selectedRates = $_POST['rates'] ?? []; +$ratesArray = []; +foreach ($selectedRates as $item) { + $parts = explode(':', $item, 2); + if (count($parts) == 2) { + $ratesArray[] = [$parts[0] => $parts[1]]; + } +} + $created = null; $errors = []; @@ -37,26 +57,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $phone = trim($_POST['phone'] ?? ''); $age = trim($_POST['age'] ?? ''); $photo = trim($_POST['photo'] ?? ''); - $rates = trim($_POST['rates'] ?? ''); $private = isset($_POST['private']) ? true : false; // Basic validation if ($name === '') { $errors[] = 'Name is required.'; } if ($age !== '' && !is_numeric($age)) { $errors[] = 'Age must be a number.'; } - if ($rates !== '' && !is_numeric($rates)) { $errors[] = 'Rates must be a number.'; } - + // Rates now processed from checkboxes if (empty($errors)) { $body = [ 'name' => $name, 'phone' => $phone, 'age' => $age === '' ? null : (int)$age, 'photo' => $photo === '' ? null : $photo, - 'rates' => $rates === '' ? null : (float)$rates, + 'rates' => empty($ratesArray) ? null : $ratesArray, 'private'=> $private ]; $result = callApi('POST', '/providers', $body); if ($result) { - $created = $result; // API returns created provider object + // On successful creation, redirect to the list providers page + header('Location: list_providers.php'); + exit; } else { $errors[] = 'Failed to create provider. API error.'; } @@ -88,20 +108,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { - -
Provider created successfully with ID =htmlspecialchars($created['id'] ?? '')?>.
-