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 '
'; llxFooter(); $db->close();