71 lines
2 KiB
PHP
71 lines
2 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Alles Watt lauft
|
|
*
|
|
* AJAX endpoint for busbar types (Sammelschienen-Typen)
|
|
*/
|
|
|
|
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
|
|
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
|
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
|
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
|
|
|
$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) die("Include of main fails");
|
|
|
|
dol_include_once('/kundenkarte/class/busbartype.class.php');
|
|
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
$langs->loadLangs(array('kundenkarte@kundenkarte'));
|
|
|
|
$action = GETPOST('action', 'aZ09');
|
|
$systemId = GETPOSTINT('system_id');
|
|
|
|
$response = array('success' => false, 'error' => '');
|
|
|
|
// Security check
|
|
if (!$user->hasRight('kundenkarte', 'read')) {
|
|
$response['error'] = $langs->trans('ErrorPermissionDenied');
|
|
echo json_encode($response);
|
|
exit;
|
|
}
|
|
|
|
$busbarType = new BusbarType($db);
|
|
|
|
switch ($action) {
|
|
case 'list':
|
|
// Get all busbar types for a system (or all if system_id = 0)
|
|
$types = $busbarType->fetchAllBySystem($systemId, 1);
|
|
|
|
$result = array();
|
|
foreach ($types as $t) {
|
|
$result[] = array(
|
|
'id' => $t->id,
|
|
'ref' => $t->ref,
|
|
'label' => $t->label,
|
|
'label_short' => $t->label_short,
|
|
'phases' => $t->phases,
|
|
'phases_config' => $t->phases_config ? json_decode($t->phases_config, true) : null,
|
|
'num_lines' => $t->num_lines,
|
|
'color' => $t->color,
|
|
'default_color' => $t->default_color,
|
|
'line_height' => $t->line_height,
|
|
'line_spacing' => $t->line_spacing,
|
|
'position_default' => $t->position_default,
|
|
'fk_system' => $t->fk_system,
|
|
'system_label' => $t->system_label
|
|
);
|
|
}
|
|
|
|
$response['success'] = true;
|
|
$response['types'] = $result;
|
|
break;
|
|
|
|
default:
|
|
$response['error'] = 'Unknown action';
|
|
break;
|
|
}
|
|
|
|
echo json_encode($response);
|