loadLangs(array('companies', 'kundenkarte@kundenkarte')); // Berechtigungen if (!$user->hasRight('kundenkarte', 'read')) { accessforbidden(); } $permissiontoread = $user->hasRight('kundenkarte', 'read'); $permissiontoadd = $user->hasRight('kundenkarte', 'write'); $permissiontodelete = $user->hasRight('kundenkarte', 'delete'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); $systemId = GETPOSTINT('system'); $anlageId = GETPOSTINT('anlage_id'); $parentId = GETPOSTINT('parent_id'); // Virtuelle Firma-ID für "Mein Betrieb" - braucht keinen echten Societe-Eintrag // Die Anlage-Tabelle verwendet diese ID nur als Gruppierung $socId = 99999999; // ALLE verfügbaren Systeme laden $allSystems = array(); $sql = "SELECT rowid, code, label, picto, color FROM ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system WHERE active = 1 ORDER BY position ASC"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { $allSystems[$obj->rowid] = $obj; } } // Für diesen virtuellen Betrieb aktivierte Systeme laden $customerSystems = array(); $sql = "SELECT ss.rowid, ss.fk_system, s.code, s.label, s.picto, s.color"; $sql .= " FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system ss"; $sql .= " JOIN ".MAIN_DB_PREFIX."c_kundenkarte_anlage_system s ON s.rowid = ss.fk_system"; $sql .= " WHERE ss.fk_soc = ".((int) $socId)." AND (ss.fk_contact IS NULL OR ss.fk_contact = 0) AND ss.active = 1 AND s.active = 1"; $sql .= " AND s.code != 'GLOBAL'"; $sql .= " ORDER BY s.position ASC"; $resql = $db->query($sql); if ($resql) { while ($obj = $db->fetch_object($resql)) { $customerSystems[$obj->fk_system] = $obj; } } // Standard: Erstes aktiviertes System falls nicht angegeben if (empty($systemId) && !empty($customerSystems)) { $systemId = array_key_first($customerSystems); } // Objekte initialisieren $form = new Form($db); $anlage = new Anlage($db); $anlageType = new AnlageType($db); /* * Actions */ // System hinzufügen if ($action == 'add_system' && $permissiontoadd) { $newSystemId = GETPOSTINT('new_system_id'); if ($newSystemId > 0 && !isset($customerSystems[$newSystemId])) { $sql = "INSERT INTO ".MAIN_DB_PREFIX."kundenkarte_societe_system"; $sql .= " (entity, fk_soc, fk_contact, fk_system, date_creation, fk_user_creat, active)"; $sql .= " VALUES (".$conf->entity.", ".((int) $socId).", 0, ".((int) $newSystemId).", NOW(), ".((int) $user->id).", 1)"; $result = $db->query($sql); if ($result) { setEventMessages($langs->trans('SystemAdded'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$newSystemId); exit; } else { setEventMessages($db->lasterror(), null, 'errors'); } } $action = ''; } // System entfernen if ($action == 'confirm_remove_system' && $confirm == 'yes' && $permissiontodelete) { $removeSystemId = GETPOSTINT('remove_system_id'); if ($removeSystemId > 0) { // Prüfen ob System noch Elemente hat $sql = "SELECT COUNT(*) as cnt FROM ".MAIN_DB_PREFIX."kundenkarte_anlage WHERE fk_soc = ".((int) $socId)." AND (fk_contact IS NULL OR fk_contact = 0) AND fk_system = ".((int) $removeSystemId); $resql = $db->query($sql); $obj = $db->fetch_object($resql); if ($obj->cnt > 0) { setEventMessages($langs->trans('ErrorSystemHasElements'), null, 'errors'); } else { $sql = "DELETE FROM ".MAIN_DB_PREFIX."kundenkarte_societe_system WHERE fk_soc = ".((int) $socId)." AND (fk_contact IS NULL OR fk_contact = 0) AND fk_system = ".((int) $removeSystemId); $db->query($sql); setEventMessages($langs->trans('SystemRemoved'), null, 'mesgs'); unset($customerSystems[$removeSystemId]); if (!empty($customerSystems)) { $systemId = array_key_first($customerSystems); } else { $systemId = 0; } } } header('Location: '.$_SERVER['PHP_SELF'].($systemId ? '?system='.$systemId : '')); exit; } if ($action == 'add' && $permissiontoadd) { $anlage->label = GETPOST('label', 'alphanohtml'); $anlage->fk_soc = $socId; $anlage->fk_anlage_type = GETPOSTINT('fk_anlage_type'); $anlage->fk_parent = GETPOSTINT('fk_parent'); $anlage->fk_system = $systemId; $anlage->fk_product = GETPOSTINT('fk_product') > 0 ? GETPOSTINT('fk_product') : null; $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; $anlage->status = 1; // Dynamische Felder $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { $fieldValues = array(); $fields = $type->fetchFields(); foreach ($fields as $field) { if ($field->field_type === 'header') continue; $value = GETPOST('field_'.$field->field_code, 'alphanohtml'); if ($value !== '') { $fieldValues[$field->field_code] = $value; } } $anlage->setFieldValues($fieldValues); } $result = $anlage->create($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); $action = 'create'; } } if ($action == 'update' && $permissiontoadd) { $anlage->fetch($anlageId); $anlage->label = GETPOST('label', 'alphanohtml'); $anlage->fk_anlage_type = GETPOSTINT('fk_anlage_type'); $anlage->fk_parent = GETPOSTINT('fk_parent'); $anlage->fk_product = GETPOSTINT('fk_product') > 0 ? GETPOSTINT('fk_product') : null; $anlage->note_private = isset($_POST['note_private']) ? $_POST['note_private'] : ''; // Dynamische Felder $type = new AnlageType($db); if ($type->fetch($anlage->fk_anlage_type) > 0) { $fieldValues = array(); $fields = $type->fetchFields(); foreach ($fields as $field) { if ($field->field_type === 'header') continue; $value = GETPOST('field_'.$field->field_code, 'alphanohtml'); if ($value !== '') { $fieldValues[$field->field_code] = $value; } } $anlage->setFieldValues($fieldValues); } $result = $anlage->update($user); if ($result > 0) { setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); header('Location: '.$_SERVER['PHP_SELF'].'?system='.$systemId); exit; } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); $action = 'edit'; } } if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { $anlage->fetch($anlageId); $result = $anlage->delete($user); if ($result > 0) { setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs'); } else { setEventMessages($anlage->error, $anlage->errors, 'errors'); } header('Location: '.$_SERVER['PHP_SELF']); exit; } /* * View */ $title = $langs->trans('CompanyTools'); $jsFiles = array('/kundenkarte/js/kundenkarte.js?v='.time()); $cssFiles = array('/kundenkarte/css/kundenkarte.css?v='.time()); llxHeader('', $title, '', '', 0, 0, $jsFiles, $cssFiles); print load_fiche_titre($title, '', 'fa-wrench'); print '
| '.$langs->trans('Type').' | '; print ''.dol_escape_htmltag($anlage->type_label).' |
| '.$langs->trans('Product').' | '; print ''.dol_escape_htmltag($product->ref).''; print ' - '.dol_escape_htmltag($product->label); if ($product->price > 0) { print ' ('.price($product->price).' €)'; } print ' |
| '.dol_escape_htmltag($field->field_label).' | |
|---|---|
| '.dol_escape_htmltag($field->field_label).' | '; if ($field->field_type === 'date' && $value) { print ''.dol_print_date(strtotime($value), 'day').' | '.($value ? $langs->trans('Yes') : $langs->trans('No')).' | '; } else { print ''.dol_escape_htmltag($value).' | '; } } } } if ($anlage->note_private) { print '
| '.$langs->trans('FieldNotes').' | '; print ''.dol_htmlentitiesbr($anlage->note_private).' |
| '.$langs->trans('Decommissioned').' | '; print ''.$langs->trans('Decommissioned').''; if (!empty($anlage->date_decommissioned)) { print ' '.dol_print_date(strtotime($anlage->date_decommissioned), 'day'); } print ' |
| '.$langs->trans('ProductRef').' | '; print ''.$langs->trans('Label').' | '; print ''.$langs->trans('Qty').' | '; print ''.$langs->trans('Note').' | '; if ($permissiontodelete) { print ''.$langs->trans('Action').' | '; } print '
|---|---|---|---|---|
| '.dol_escape_htmltag($acc->product_ref).' | '; print ''.dol_escape_htmltag($acc->product_label).' | '; print ''.$acc->qty.' | '; print ''.dol_escape_htmltag($acc->note).' | '; if ($permissiontodelete) { print ''; } print ' |
'.$langs->trans('NoAccessories').'
'; } // Zubehör hinzufügen if ($permissiontoadd) { print '