|
|
@@ -312,6 +312,14 @@ function renderAdmin(array $config, string $rawConfigText, ?string $message, str
|
|
|
|
|
|
const countChildren = (node, selector) => node.querySelectorAll(selector).length;
|
|
|
|
|
|
+ const toggleTelegramFields = (row) => {
|
|
|
+ const typeSelect = row.querySelector('select[name*="[type]"]');
|
|
|
+ const telegramFields = row.querySelector('.telegram-fields');
|
|
|
+ if (typeSelect && telegramFields) {
|
|
|
+ telegramFields.style.display = typeSelect.value === 'telegram' ? '' : 'none';
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
document.addEventListener('click', (event) => {
|
|
|
const addType = event.target.getAttribute('data-add');
|
|
|
const removeType = event.target.getAttribute('data-remove');
|
|
|
@@ -348,6 +356,18 @@ function renderAdmin(array $config, string $rawConfigText, ?string $message, str
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ document.addEventListener('change', (event) => {
|
|
|
+ if (event.target.matches('select[name*="[type]"]')) {
|
|
|
+ const row = event.target.closest('[data-webhook-row]');
|
|
|
+ if (row) {
|
|
|
+ toggleTelegramFields(row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Initialize existing webhook rows
|
|
|
+ document.querySelectorAll('[data-webhook-row]').forEach(toggleTelegramFields);
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|
|
|
@@ -358,6 +378,9 @@ function renderWebhookRow(int|string $index, array $webhook): string
|
|
|
{
|
|
|
$headers = $webhook['headers'] ?? [];
|
|
|
$headerJson = json_encode($headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
|
|
+ $type = $webhook['type'] ?? 'generic';
|
|
|
+ $botToken = $webhook['bot_token'] ?? '';
|
|
|
+ $chatId = $webhook['chat_id'] ?? '';
|
|
|
|
|
|
ob_start();
|
|
|
?>
|
|
|
@@ -368,16 +391,23 @@ function renderWebhookRow(int|string $index, array $webhook): string
|
|
|
</div>
|
|
|
<div class="field-grid">
|
|
|
<label>
|
|
|
- ID
|
|
|
- <input type="text" name="webhooks[<?= $index ?>][id]" value="<?= htmlspecialchars((string) ($webhook['id'] ?? ''), ENT_QUOTES) ?>">
|
|
|
+ Label
|
|
|
+ <input type="text" name="webhooks[<?= $index ?>][label]" value="<?= htmlspecialchars((string) ($webhook['label'] ?? ''), ENT_QUOTES) ?>" placeholder="z.B. lager-webhook">
|
|
|
</label>
|
|
|
<label>
|
|
|
Name
|
|
|
<input type="text" name="webhooks[<?= $index ?>][name]" value="<?= htmlspecialchars((string) ($webhook['name'] ?? ''), ENT_QUOTES) ?>">
|
|
|
</label>
|
|
|
+ <label>
|
|
|
+ Typ
|
|
|
+ <select name="webhooks[<?= $index ?>][type]">
|
|
|
+ <option value="generic" <?= $type === 'generic' ? 'selected' : '' ?>>Generic</option>
|
|
|
+ <option value="telegram" <?= $type === 'telegram' ? 'selected' : '' ?>>Telegram</option>
|
|
|
+ </select>
|
|
|
+ </label>
|
|
|
<label>
|
|
|
URL
|
|
|
- <input type="url" name="webhooks[<?= $index ?>][url]" value="<?= htmlspecialchars((string) ($webhook['url'] ?? ''), ENT_QUOTES) ?>">
|
|
|
+ <input type="url" name="webhooks[<?= $index ?>][url]" value="<?= htmlspecialchars((string) ($webhook['url'] ?? ''), ENT_QUOTES) ?>" placeholder="https://example.com/webhook">
|
|
|
</label>
|
|
|
<label>
|
|
|
Aktiv
|
|
|
@@ -387,8 +417,22 @@ function renderWebhookRow(int|string $index, array $webhook): string
|
|
|
</select>
|
|
|
</label>
|
|
|
</div>
|
|
|
+
|
|
|
+ <div class="telegram-fields" style="<?= $type === 'telegram' ? '' : 'display:none;' ?>">
|
|
|
+ <div class="field-grid">
|
|
|
+ <label>
|
|
|
+ Bot Token (nur für Telegram)
|
|
|
+ <input type="text" name="webhooks[<?= $index ?>][bot_token]" value="<?= htmlspecialchars((string) $botToken, ENT_QUOTES) ?>" placeholder="123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11">
|
|
|
+ </label>
|
|
|
+ <label>
|
|
|
+ Chat ID (nur für Telegram)
|
|
|
+ <input type="text" name="webhooks[<?= $index ?>][chat_id]" value="<?= htmlspecialchars((string) $chatId, ENT_QUOTES) ?>" placeholder="-100123456789">
|
|
|
+ </label>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
<label>
|
|
|
- Header als JSON-Objekt
|
|
|
+ Header als JSON-Objekt (für Generic)
|
|
|
<textarea name="webhooks[<?= $index ?>][headers_json]"><?= htmlspecialchars((string) $headerJson, ENT_QUOTES) ?></textarea>
|
|
|
</label>
|
|
|
</div>
|
|
|
@@ -407,8 +451,8 @@ function renderEmailRow(int|string $index, array $email): string
|
|
|
</div>
|
|
|
<div class="field-grid">
|
|
|
<label>
|
|
|
- ID
|
|
|
- <input type="text" name="emails[<?= $index ?>][id]" value="<?= htmlspecialchars((string) ($email['id'] ?? ''), ENT_QUOTES) ?>">
|
|
|
+ Label
|
|
|
+ <input type="text" name="emails[<?= $index ?>][label]" value="<?= htmlspecialchars((string) ($email['label'] ?? ''), ENT_QUOTES) ?>" placeholder="z.B. lager-team">
|
|
|
</label>
|
|
|
<label>
|
|
|
Name
|
|
|
@@ -472,9 +516,6 @@ function renderMachineRow(int|string $machineIndex, array $machine): string
|
|
|
|
|
|
function renderSlotRow(int|string $machineIndex, int|string $slotIndex, array $slot): string
|
|
|
{
|
|
|
- $webhookIds = implode(',', $slot['webhook_ids'] ?? []);
|
|
|
- $emailIds = implode(',', $slot['email_ids'] ?? []);
|
|
|
-
|
|
|
ob_start();
|
|
|
?>
|
|
|
<div class="slot-editor" data-slot-row>
|
|
|
@@ -508,17 +549,9 @@ function renderSlotRow(int|string $machineIndex, int|string $slotIndex, array $s
|
|
|
<input type="number" step="0.01" name="machines[<?= $machineIndex ?>][slots][<?= $slotIndex ?>][distance_per_unit]" value="<?= htmlspecialchars((string) ($slot['distance_per_unit'] ?? ''), ENT_QUOTES) ?>">
|
|
|
</label>
|
|
|
<label>
|
|
|
- Alarm unter Bestand
|
|
|
+ Alarm unter Bestand(Anzahl)
|
|
|
<input type="number" step="1" min="0" name="machines[<?= $machineIndex ?>][slots][<?= $slotIndex ?>][alert_below_units]" value="<?= htmlspecialchars((string) ($slot['alert_below_units'] ?? ''), ENT_QUOTES) ?>">
|
|
|
</label>
|
|
|
- <label>
|
|
|
- Webhook-IDs
|
|
|
- <input type="text" name="machines[<?= $machineIndex ?>][slots][<?= $slotIndex ?>][webhook_ids]" value="<?= htmlspecialchars((string) $webhookIds, ENT_QUOTES) ?>" placeholder="ops,lager">
|
|
|
- </label>
|
|
|
- <label>
|
|
|
- Email-IDs
|
|
|
- <input type="text" name="machines[<?= $machineIndex ?>][slots][<?= $slotIndex ?>][email_ids]" value="<?= htmlspecialchars((string) $emailIds, ENT_QUOTES) ?>" placeholder="lager,service">
|
|
|
- </label>
|
|
|
</div>
|
|
|
</div>
|
|
|
<?php
|
|
|
@@ -529,20 +562,31 @@ function normalizeWebhooks(array $rows): array
|
|
|
{
|
|
|
$items = [];
|
|
|
foreach ($rows as $row) {
|
|
|
- $id = trim((string) ($row['id'] ?? ''));
|
|
|
+ $label = trim((string) ($row['label'] ?? ''));
|
|
|
$url = trim((string) ($row['url'] ?? ''));
|
|
|
- if ($id === '' && $url === '') {
|
|
|
+ if ($label === '' && $url === '') {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$headers = json_decode((string) ($row['headers_json'] ?? '{}'), true);
|
|
|
- $items[] = [
|
|
|
- 'id' => $id,
|
|
|
+ $type = trim((string) ($row['type'] ?? 'generic'));
|
|
|
+
|
|
|
+ $item = [
|
|
|
+ 'label' => $label,
|
|
|
'name' => trim((string) ($row['name'] ?? '')),
|
|
|
+ 'type' => $type,
|
|
|
'url' => $url,
|
|
|
'enabled' => (string) ($row['enabled'] ?? '1') === '1',
|
|
|
'headers' => is_array($headers) ? $headers : [],
|
|
|
];
|
|
|
+
|
|
|
+ // Add Telegram-specific fields
|
|
|
+ if ($type === 'telegram') {
|
|
|
+ $item['bot_token'] = trim((string) ($row['bot_token'] ?? ''));
|
|
|
+ $item['chat_id'] = trim((string) ($row['chat_id'] ?? ''));
|
|
|
+ }
|
|
|
+
|
|
|
+ $items[] = $item;
|
|
|
}
|
|
|
|
|
|
return array_values($items);
|
|
|
@@ -552,14 +596,14 @@ function normalizeEmails(array $rows): array
|
|
|
{
|
|
|
$items = [];
|
|
|
foreach ($rows as $row) {
|
|
|
- $id = trim((string) ($row['id'] ?? ''));
|
|
|
+ $label = trim((string) ($row['label'] ?? ''));
|
|
|
$address = trim((string) ($row['address'] ?? ''));
|
|
|
- if ($id === '' && $address === '') {
|
|
|
+ if ($label === '' && $address === '') {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$items[] = [
|
|
|
- 'id' => $id,
|
|
|
+ 'label' => $label,
|
|
|
'name' => trim((string) ($row['name'] ?? '')),
|
|
|
'address' => $address,
|
|
|
'enabled' => (string) ($row['enabled'] ?? '1') === '1',
|
|
|
@@ -594,8 +638,6 @@ function normalizeMachines(array $rows): array
|
|
|
'empty_distance_mm' => (float) ($slot['empty_distance_mm'] ?? 0),
|
|
|
'distance_per_unit' => max(0.01, (float) ($slot['distance_per_unit'] ?? 1)),
|
|
|
'alert_below_units' => max(0, (int) ($slot['alert_below_units'] ?? 0)),
|
|
|
- 'webhook_ids' => parseIdList((string) ($slot['webhook_ids'] ?? '')),
|
|
|
- 'email_ids' => parseIdList((string) ($slot['email_ids'] ?? '')),
|
|
|
];
|
|
|
}
|
|
|
|