list, add, and edit providers essential functions working
This commit is contained in:
1 parent
b2a4307eae
commit
269366b7b6
4 files changed
+207
-76
No files matched your search
+35
-3
@@ -34,6 +34,27 @@ function callApi(string $method, string $path, $body = null)
|
||||
$providers = callApi('GET', '/providers');
|
||||
$providers = $providers ?? [];
|
||||
|
||||
// Normalize rates for display
|
||||
foreach ($providers as &$p) {
|
||||
$rates = $p['rates'] ?? '';
|
||||
if (is_string($rates)) {
|
||||
$decoded = json_decode($rates, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
// try stripping slashes
|
||||
$unescaped = stripslashes($rates);
|
||||
$decoded = json_decode($unescaped, true);
|
||||
}
|
||||
if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) {
|
||||
$p['rates'] = $decoded;
|
||||
} else {
|
||||
// leave as is
|
||||
$p['rates'] = $rates;
|
||||
}
|
||||
} elseif (is_array($rates)) {
|
||||
$p['rates'] = $rates;
|
||||
}
|
||||
}
|
||||
unset($p);
|
||||
// -----------------------------------------------------------------------
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
@@ -77,6 +98,19 @@ $providers = $providers ?? [];
|
||||
const providers = <?php echo json_encode($providers); ?>;
|
||||
let currentSort = { field: null, asc: true };
|
||||
|
||||
// Helper to format rates into readable lines
|
||||
function formatRates(rates) {
|
||||
if (!rates) return '';
|
||||
if (Array.isArray(rates)) {
|
||||
return rates.map(r => {
|
||||
const key = Object.keys(r)[0];
|
||||
const val = r[key];
|
||||
return `${key}: ${val}`;
|
||||
}).join('<br>');
|
||||
}
|
||||
return rates;
|
||||
}
|
||||
|
||||
function renderTable(data) {
|
||||
const tbody = document.querySelector('#providers-table tbody');
|
||||
tbody.innerHTML = '';
|
||||
@@ -88,7 +122,7 @@ function renderTable(data) {
|
||||
<td>${p.phone || ''}</td>
|
||||
<td>${p.age || ''}</td>
|
||||
<td>${p.photo ? `<img src="${p.photo}" alt="Photo">` : ''}</td>
|
||||
<td>${p.rates}</td>
|
||||
<td>${formatRates(p.rates)}</td>
|
||||
<td>${p.private ? 'Yes' : 'No'}</td>
|
||||
<td><a href="edit_provider.php?id=${p.id}">Edit</a></td>
|
||||
`;
|
||||
@@ -143,5 +177,3 @@ document.getElementById('search').addEventListener('input', e => {
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in new issue
Block a user