kundenkarte/anlage_connection.php
data 1f73e814ff Version 3.3.1 - Visuelle Kabel-Darstellung & Verbindungen
Neue Features:
- Kabelverbindungen zwischen Anlagen-Elementen dokumentieren
- Visuelle Baum-Darstellung mit parallelen vertikalen Linien
- Jedes Element mit eigenem Kabel bekommt eigene Linie
- Horizontale Verbindungslinien zum Element
- Automatische Abstände zwischen Kabel-Gruppen
- Kabeltypen (Medium Types) verwalten
- Gebäude-Typen für Anlagen-Struktur
- Tree-Display-Konfiguration pro System
- Audit-Log für Änderungsverfolgung

Verbesserungen:
- Erste Kabel-Linie rechts, letzte links (korrekte Reihenfolge)
- Horizontale Linien enden am Element-Rand
- Spacer-Zeilen für bessere Übersichtlichkeit
- BOM-Generator für Stücklisten (Prototyp)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-16 15:14:36 +01:00

236 lines
9.3 KiB
PHP

<?php
/* Copyright (C) 2026 Alles Watt lauft
*
* Edit page for Anlage Connection (cable/wire between elements)
*/
$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");
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
dol_include_once('/kundenkarte/class/anlageconnection.class.php');
dol_include_once('/kundenkarte/class/anlage.class.php');
dol_include_once('/kundenkarte/class/mediumtype.class.php');
$langs->loadLangs(array('kundenkarte@kundenkarte'));
$id = GETPOSTINT('id');
$socId = GETPOSTINT('socid');
$systemId = GETPOSTINT('system_id');
$sourceId = GETPOSTINT('source_id');
$action = GETPOST('action', 'aZ09');
// Security check
if (!$user->hasRight('kundenkarte', 'read')) {
accessforbidden();
}
$connection = new AnlageConnection($db);
$anlage = new Anlage($db);
$form = new Form($db);
// Load existing connection
if ($id > 0) {
$result = $connection->fetch($id);
if ($result <= 0) {
setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors');
header('Location: '.DOL_URL_ROOT.'/societe/card.php?socid='.$socId);
exit;
}
// Get socId from source anlage if not provided
if (empty($socId)) {
$tmpAnlage = new Anlage($db);
if ($tmpAnlage->fetch($connection->fk_source) > 0) {
$socId = $tmpAnlage->fk_soc;
$systemId = $tmpAnlage->fk_system;
}
}
}
/*
* Actions
*/
if ($action == 'update' && $user->hasRight('kundenkarte', 'write')) {
$connection->fk_source = GETPOSTINT('fk_source');
$connection->fk_target = GETPOSTINT('fk_target');
$connection->label = GETPOST('label', 'alphanohtml');
$connection->fk_medium_type = GETPOSTINT('fk_medium_type');
$connection->medium_type_text = GETPOST('medium_type_text', 'alphanohtml');
$connection->medium_spec = GETPOST('medium_spec', 'alphanohtml');
$connection->medium_length = GETPOST('medium_length', 'alphanohtml');
$connection->medium_color = GETPOST('medium_color', 'alphanohtml');
$connection->route_description = GETPOST('route_description', 'restricthtml');
$connection->installation_date = GETPOST('installation_date', 'alpha');
if (empty($connection->fk_source) || empty($connection->fk_target)) {
setEventMessages($langs->trans('ErrorFieldRequired', 'Quelle/Ziel'), null, 'errors');
} else {
$result = $connection->update($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.dol_buildpath('/kundenkarte/tabs/anlagen.php', 1).'?id='.$socId.'&system='.$systemId);
exit;
} else {
setEventMessages($connection->error, null, 'errors');
}
}
}
if ($action == 'create' && $user->hasRight('kundenkarte', 'write')) {
$connection->fk_source = GETPOSTINT('fk_source');
$connection->fk_target = GETPOSTINT('fk_target');
$connection->label = GETPOST('label', 'alphanohtml');
$connection->fk_medium_type = GETPOSTINT('fk_medium_type');
$connection->medium_type_text = GETPOST('medium_type_text', 'alphanohtml');
$connection->medium_spec = GETPOST('medium_spec', 'alphanohtml');
$connection->medium_length = GETPOST('medium_length', 'alphanohtml');
$connection->medium_color = GETPOST('medium_color', 'alphanohtml');
$connection->route_description = GETPOST('route_description', 'restricthtml');
$connection->installation_date = GETPOST('installation_date', 'alpha');
$connection->status = 1;
if (empty($connection->fk_source) || empty($connection->fk_target)) {
setEventMessages($langs->trans('ErrorFieldRequired', 'Quelle/Ziel'), null, 'errors');
} else {
$result = $connection->create($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
header('Location: '.dol_buildpath('/kundenkarte/tabs/anlagen.php', 1).'?id='.$socId.'&system='.$systemId);
exit;
} else {
setEventMessages($connection->error, null, 'errors');
}
}
}
if ($action == 'delete' && $user->hasRight('kundenkarte', 'write')) {
$result = $connection->delete($user);
if ($result > 0) {
setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
header('Location: '.dol_buildpath('/kundenkarte/tabs/anlagen.php', 1).'?id='.$socId.'&system='.$systemId);
exit;
} else {
setEventMessages($connection->error, null, 'errors');
}
}
/*
* View
*/
$title = $id > 0 ? 'Verbindung bearbeiten' : 'Neue Verbindung';
llxHeader('', $title);
// Load anlagen for dropdowns
$anlagenList = array();
if ($socId > 0) {
$tree = $anlage->fetchTree($socId, $systemId);
// Flatten tree
$flattenTree = function($nodes, $prefix = '') use (&$flattenTree, &$anlagenList) {
foreach ($nodes as $node) {
$anlagenList[$node->id] = $prefix . $node->label;
if (!empty($node->children)) {
$flattenTree($node->children, $prefix . ' ');
}
}
};
$flattenTree($tree);
}
// Load medium types
$mediumTypes = array();
$sql = "SELECT rowid, label, category FROM ".MAIN_DB_PREFIX."kundenkarte_medium_type WHERE active = 1 ORDER BY category, label";
$resql = $db->query($sql);
if ($resql) {
while ($obj = $db->fetch_object($resql)) {
$mediumTypes[$obj->rowid] = $obj->label;
}
}
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="socid" value="'.$socId.'">';
print '<input type="hidden" name="system_id" value="'.$systemId.'">';
print '<input type="hidden" name="action" value="'.($id > 0 ? 'update' : 'create').'">';
print load_fiche_titre($title, '', 'object_kundenkarte@kundenkarte');
print '<table class="border centpercent">';
// Source
print '<tr><td class="titlefield fieldrequired">'.$langs->trans('Von (Quelle)').'</td>';
print '<td><select name="fk_source" class="flat minwidth300">';
print '<option value="">-- Quelle wählen --</option>';
foreach ($anlagenList as $aid => $alabel) {
$selected = ($connection->fk_source == $aid || $sourceId == $aid) ? ' selected' : '';
print '<option value="'.$aid.'"'.$selected.'>'.dol_escape_htmltag($alabel).'</option>';
}
print '</select></td></tr>';
// Target
print '<tr><td class="fieldrequired">'.$langs->trans('Nach (Ziel)').'</td>';
print '<td><select name="fk_target" class="flat minwidth300">';
print '<option value="">-- Ziel wählen --</option>';
foreach ($anlagenList as $aid => $alabel) {
$selected = ($connection->fk_target == $aid) ? ' selected' : '';
print '<option value="'.$aid.'"'.$selected.'>'.dol_escape_htmltag($alabel).'</option>';
}
print '</select></td></tr>';
// Medium type
print '<tr><td>'.$langs->trans('Kabeltyp').'</td>';
print '<td><select name="fk_medium_type" class="flat minwidth200">';
print '<option value="">-- oder Freitext unten --</option>';
foreach ($mediumTypes as $mid => $mlabel) {
$selected = ($connection->fk_medium_type == $mid) ? ' selected' : '';
print '<option value="'.$mid.'"'.$selected.'>'.dol_escape_htmltag($mlabel).'</option>';
}
print '</select></td></tr>';
// Medium type text (free text)
print '<tr><td>'.$langs->trans('Kabeltyp (Freitext)').'</td>';
print '<td><input type="text" name="medium_type_text" class="flat minwidth300" value="'.dol_escape_htmltag($connection->medium_type_text).'" placeholder="z.B. NYM-J"></td></tr>';
// Medium spec
print '<tr><td>'.$langs->trans('Querschnitt/Typ').'</td>';
print '<td><input type="text" name="medium_spec" class="flat minwidth200" value="'.dol_escape_htmltag($connection->medium_spec).'" placeholder="z.B. 5x2,5mm²"></td></tr>';
// Length
print '<tr><td>'.$langs->trans('Länge').'</td>';
print '<td><input type="text" name="medium_length" class="flat minwidth150" value="'.dol_escape_htmltag($connection->medium_length).'" placeholder="z.B. 15m"></td></tr>';
// Color
print '<tr><td>'.$langs->trans('Farbe').'</td>';
print '<td><input type="text" name="medium_color" class="flat minwidth150" value="'.dol_escape_htmltag($connection->medium_color).'" placeholder="z.B. grau"></td></tr>';
// Label
print '<tr><td>'.$langs->trans('Bezeichnung').'</td>';
print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag($connection->label).'" placeholder="z.B. Zuleitung HAK"></td></tr>';
// Route description
print '<tr><td>'.$langs->trans('Verlegungsweg').'</td>';
print '<td><textarea name="route_description" class="flat" rows="3" style="width:90%;">'.dol_escape_htmltag($connection->route_description).'</textarea></td></tr>';
// Installation date
print '<tr><td>'.$langs->trans('Installationsdatum').'</td>';
print '<td><input type="date" name="installation_date" class="flat" value="'.dol_escape_htmltag($connection->installation_date).'"></td></tr>';
print '</table>';
print '<div class="center" style="margin-top:20px;">';
print '<button type="submit" class="button button-save">'.$langs->trans('Save').'</button>';
print ' <a class="button button-cancel" href="'.dol_buildpath('/kundenkarte/tabs/anlagen.php', 1).'?id='.$socId.'&system='.$systemId.'">'.$langs->trans('Cancel').'</a>';
if ($id > 0 && $user->hasRight('kundenkarte', 'write')) {
print ' <a class="button button-delete" style="margin-left:20px;" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&socid='.$socId.'&system_id='.$systemId.'&action=delete&token='.newToken().'" onclick="return confirm(\'Verbindung wirklich löschen?\');">'.$langs->trans('Delete').'</a>';
}
print '</div>';
print '</form>';
llxFooter();
$db->close();