PWA Mobile App für Schaltschrank-Dokumentation vor Ort: - Token-basierte Authentifizierung (15 Tage gültig) - Kundensuche mit Offline-Cache - Anlagen-Auswahl und Offline-Laden - Felder/Hutschienen/Automaten erfassen - Automatische Synchronisierung wenn wieder online - Installierbar auf dem Smartphone Home Screen - Touch-optimiertes Dark Mode Design - Quick-Select für Automaten-Werte (B16, C32, etc.) Schaltplan-Editor Verbesserungen: - Block Hover-Tooltip mit show_in_hover Feldern - Produktinfo mit Icon im Tooltip - Position und Breite in TE Neue Dateien: - pwa.php, pwa_auth.php - PWA Einstieg & Auth - ajax/pwa_api.php - PWA AJAX API - js/pwa.js, css/pwa.css - PWA App & Styles - sw.js, manifest.json - Service Worker & Manifest - img/pwa-icon-192.png, img/pwa-icon-512.png Version: 5.2.0 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
106 lines
2.8 KiB
PHP
Executable file
106 lines
2.8 KiB
PHP
Executable file
<?php
|
|
/* Copyright (C) 2026 Alles Watt lauft
|
|
*
|
|
* AJAX endpoint for field autocomplete suggestions
|
|
* Returns unique values from saved anlage field values
|
|
*/
|
|
|
|
// Load Dolibarr environment
|
|
$res = 0;
|
|
if (!$res && file_exists("../main.inc.php")) {
|
|
$res = @include "../main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../main.inc.php")) {
|
|
$res = @include "../../main.inc.php";
|
|
}
|
|
if (!$res && file_exists("../../../main.inc.php")) {
|
|
$res = @include "../../../main.inc.php";
|
|
}
|
|
if (!$res) {
|
|
die("Include of main fails");
|
|
}
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
// Check permissions
|
|
if (!$user->hasRight('kundenkarte', 'read')) {
|
|
echo json_encode(array('error' => 'Access denied'));
|
|
exit;
|
|
}
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$fieldCode = GETPOST('field_code', 'aZ09');
|
|
$query = GETPOST('query', 'alphanohtml');
|
|
$typeId = GETPOSTINT('type_id');
|
|
|
|
if ($action == 'suggest') {
|
|
$suggestions = array();
|
|
|
|
if (empty($fieldCode)) {
|
|
echo json_encode(array('suggestions' => $suggestions));
|
|
exit;
|
|
}
|
|
|
|
// Get unique saved values for this field code
|
|
// Search in JSON field_values column
|
|
$sql = "SELECT DISTINCT ";
|
|
$sql .= "JSON_UNQUOTE(JSON_EXTRACT(field_values, '$.\"".($db->escape($fieldCode))."\"')) as field_value ";
|
|
$sql .= "FROM ".MAIN_DB_PREFIX."kundenkarte_anlage ";
|
|
$sql .= "WHERE field_values IS NOT NULL ";
|
|
$sql .= "AND JSON_EXTRACT(field_values, '$.\"".($db->escape($fieldCode))."\"') IS NOT NULL ";
|
|
|
|
// Filter by query if provided
|
|
if (!empty($query)) {
|
|
$sql .= "AND JSON_UNQUOTE(JSON_EXTRACT(field_values, '$.\"".($db->escape($fieldCode))."\"')) LIKE '%".$db->escape($query)."%' ";
|
|
}
|
|
|
|
// Optionally filter by type
|
|
if ($typeId > 0) {
|
|
$sql .= "AND fk_anlage_type = ".((int) $typeId)." ";
|
|
}
|
|
|
|
$sql .= "ORDER BY field_value ASC ";
|
|
$sql .= "LIMIT 20";
|
|
|
|
$resql = $db->query($sql);
|
|
if ($resql) {
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
if (!empty($obj->field_value) && $obj->field_value !== 'null') {
|
|
$suggestions[] = $obj->field_value;
|
|
}
|
|
}
|
|
$db->free($resql);
|
|
}
|
|
|
|
echo json_encode(array('suggestions' => $suggestions));
|
|
exit;
|
|
}
|
|
|
|
// Get all autocomplete-enabled fields for a type
|
|
if ($action == 'get_autocomplete_fields') {
|
|
$fields = array();
|
|
|
|
if ($typeId > 0) {
|
|
$sql = "SELECT field_code, field_label FROM ".MAIN_DB_PREFIX."kundenkarte_anlage_type_field ";
|
|
$sql .= "WHERE fk_anlage_type = ".((int) $typeId)." ";
|
|
$sql .= "AND enable_autocomplete = 1 ";
|
|
$sql .= "AND active = 1 ";
|
|
$sql .= "AND field_type IN ('text', 'textarea')";
|
|
|
|
$resql = $db->query($sql);
|
|
if ($resql) {
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
$fields[] = array(
|
|
'code' => $obj->field_code,
|
|
'label' => $obj->field_label
|
|
);
|
|
}
|
|
$db->free($resql);
|
|
}
|
|
}
|
|
|
|
echo json_encode(array('fields' => $fields));
|
|
exit;
|
|
}
|
|
|
|
echo json_encode(array('error' => 'Unknown action'));
|