loadLangs(array('kundenkarte@kundenkarte')); $id = GETPOSTINT('id'); $socId = GETPOSTINT('socid'); $contactId = GETPOSTINT('contactid'); $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; } } } // Redirect-URL: zurück zur Kontakt- oder Kunden-Anlagenansicht if ($contactId > 0) { $backUrl = dol_buildpath('/kundenkarte/tabs/contact_anlagen.php', 1).'?id='.$contactId.'&system='.$systemId; } else { $backUrl = dol_buildpath('/kundenkarte/tabs/anlagen.php', 1).'?id='.$socId.'&system='.$systemId; } /* * 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: '.$backUrl); exit; } else { setEventMessages($connection->error, null, 'errors'); } } } if ($action == 'add' && $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: '.$backUrl); 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: '.$backUrl); exit; } else { setEventMessages($connection->error, null, 'errors'); } } /* * View */ $title = $id > 0 ? 'Verbindung bearbeiten' : 'Neue Verbindung'; llxHeader('', $title); // Gebäude-Typ-IDs ermitteln (Verbindungen nur zwischen Geräten, nicht Gebäuden) $buildingTypeIds = array(); $sqlBt = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."kundenkarte_anlage_type t"; $sqlBt .= " LEFT JOIN ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system ts ON t.fk_system = ts.rowid"; $sqlBt .= " WHERE ts.code = 'GLOBAL'"; $resBt = $db->query($sqlBt); if ($resBt) { while ($btObj = $db->fetch_object($resBt)) { $buildingTypeIds[] = (int) $btObj->rowid; } } // Alle Elemente für Dropdowns laden (OHNE System-Filter, da Kabel systemübergreifend sein können) $anlagenList = array(); if ($socId > 0) { if ($contactId > 0) { $tree = $anlage->fetchTreeByContact($socId, $contactId, 0); } else { $tree = $anlage->fetchTree($socId, 0); } // Baum flach machen - nur Geräte, Gebäude als Pfad-Kontext $flattenTree = function($nodes, $path = '') use (&$flattenTree, &$anlagenList, &$buildingTypeIds) { foreach ($nodes as $node) { $isBuilding = in_array((int) $node->fk_anlage_type, $buildingTypeIds); if ($isBuilding) { // Gebäude/Raum: nicht wählbar, aber Pfad als Kontext weitergeben $newPath = $path ? $path.' > '.$node->label : $node->label; if (!empty($node->children)) { $flattenTree($node->children, $newPath); } } else { // Gerät: in Liste aufnehmen mit Gebäude-Pfad als Kontext $typeInfo = !empty($node->type_short) ? $node->type_short : (!empty($node->type_label) ? $node->type_label : ''); $label = ''; if (!empty($path)) { $label = $path.' > '; } $label .= $node->label; if (!empty($typeInfo)) { $label .= ' ['.$typeInfo.']'; } $anlagenList[$node->id] = array( 'label' => $label, 'picto' => !empty($node->type_picto) ? $node->type_picto : 'fa-cube', ); // Rekursion in Geräte-Kinder if (!empty($node->children)) { $flattenTree($node->children, $path); } } } }; $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 '
'; print ''; print ''; print ''; print ''; print ''; print ''; print load_fiche_titre($title, '', 'object_kundenkarte@kundenkarte'); print ''; // Source print ''; print ''; // Target print ''; print ''; // Medium type print ''; print ''; // Medium type text (free text) print ''; print ''; // Medium spec print ''; print ''; // Length print ''; print ''; // Color print ''; print ''; // Label print ''; print ''; // Route description print ''; print ''; // Installation date print ''; print ''; print '
'.$langs->trans('Von (Quelle)').'
'.$langs->trans('Nach (Ziel)').'
'.$langs->trans('Kabeltyp').'
'.$langs->trans('Kabeltyp (Freitext)').'
'.$langs->trans('Querschnitt/Typ').'
'.$langs->trans('Länge').'
'.$langs->trans('Farbe').'
'.$langs->trans('Bezeichnung').'
'.$langs->trans('Verlegungsweg').'
'.$langs->trans('Installationsdatum').'
'; print '
'; print ''; print ' '.$langs->trans('Cancel').''; if ($id > 0 && $user->hasRight('kundenkarte', 'write')) { print ' '.$langs->trans('Delete').''; } print '
'; print '
'; // Select2 mit Icons für Quelle/Ziel-Dropdowns print ''; llxFooter(); $db->close();