dolibarr.idsconnect/lib/idsconnect.lib.php
data 81646f5ea4 feat(launch): Konfigurationsvalidierung & GlobalNotify-Integration v3.4
- Neue Funktion idsconnect_notify() für GlobalNotify-Benachrichtigungen
  mit Fallback auf dol_syslog falls Modul nicht installiert
- Neue Funktion idsconnect_validateSupplierConfig() prüft Supplier-
  Konfiguration vor dem Launch auf Vollständigkeit
- launch.php: Validierung vor Formular-Submit
  - Fehler (leeres Passwort): blockiert Launch, Redirect zur Konfiguration
  - Warnung (leerer Username): erlaubt Launch aber warnt User + Admin
- Löst Problem: Klux "Weiter"-Button fehlte weil ids_username leer war,
  Login schlug still fehl ohne jede Fehlermeldung

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-17 12:58:23 +01:00

167 lines
4.6 KiB
PHP
Executable file
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/**
* \file idsconnect/lib/idsconnect.lib.php
* \ingroup idsconnect
* \brief Bibliotheksfunktionen für IDS Connect
*/
/**
* Admin-Tabs vorbereiten
*
* @return array
*/
function idsconnectAdminPrepareHead()
{
global $langs, $conf;
$langs->load("idsconnect@idsconnect");
$h = 0;
$head = array();
$head[$h][0] = dol_buildpath("/idsconnect/admin/setup.php", 1);
$head[$h][1] = $langs->trans("Settings");
$head[$h][2] = 'settings';
$h++;
$head[$h][0] = dol_buildpath("/idsconnect/admin/about.php", 1);
$head[$h][1] = $langs->trans("About");
$head[$h][2] = 'about';
$h++;
complete_head_from_modules($conf, $langs, null, $head, $h, 'idsconnect@idsconnect');
complete_head_from_modules($conf, $langs, null, $head, $h, 'idsconnect@idsconnect', 'remove');
return $head;
}
/**
* Großhändler-Karte Tabs vorbereiten
*
* @param object $object Großhändler-Objekt
* @return array
*/
function idsconnectSupplierPrepareHead($object)
{
global $langs, $conf;
$langs->load("idsconnect@idsconnect");
$h = 0;
$head = array();
$head[$h][0] = dol_buildpath("/idsconnect/supplier_card.php", 1).'?id='.$object->id;
$head[$h][1] = $langs->trans("IdsconnectSupplierCard");
$head[$h][2] = 'supplier';
$h++;
$head[$h][0] = dol_buildpath("/idsconnect/log_list.php", 1).'?supplier_id='.$object->id;
$head[$h][1] = $langs->trans("IdsconnectLog");
$head[$h][2] = 'log';
$h++;
return $head;
}
/**
* Sendet Benachrichtigung über GlobalNotify (falls verfügbar).
* Fallback: Schreibt ins Dolibarr-Log.
*
* @param string $type 'error', 'warning', 'info', 'action'
* @param string $title Kurzer Titel
* @param string $message Detaillierte Nachricht
* @param string $actionUrl URL für Aktions-Button (optional)
* @param string $actionLabel Label für Aktions-Button (optional)
* @return bool True wenn über GlobalNotify gesendet
*/
function idsconnect_notify($type, $title, $message, $actionUrl = '', $actionLabel = '')
{
if (!isModEnabled('globalnotify')) {
dol_syslog("IDSCONNECT [{$type}]: {$title} - {$message}", LOG_WARNING);
return false;
}
$classFile = dol_buildpath('/globalnotify/class/globalnotify.class.php', 0);
if (!file_exists($classFile)) {
dol_syslog("IDSCONNECT [{$type}]: {$title} - {$message}", LOG_WARNING);
return false;
}
require_once $classFile;
if (!class_exists('GlobalNotify')) {
dol_syslog("IDSCONNECT [{$type}]: {$title} - {$message}", LOG_WARNING);
return false;
}
try {
switch ($type) {
case 'error':
GlobalNotify::error('idsconnect', $title, $message, $actionUrl, $actionLabel);
break;
case 'warning':
GlobalNotify::warning('idsconnect', $title, $message, $actionUrl, $actionLabel);
break;
case 'action':
GlobalNotify::actionRequired('idsconnect', $title, $message, $actionUrl, $actionLabel ?: 'Jetzt beheben');
break;
default:
GlobalNotify::info('idsconnect', $title, $message, $actionUrl, $actionLabel);
}
return true;
} catch (Exception $e) {
dol_syslog("GlobalNotify error in idsconnect: ".$e->getMessage(), LOG_ERR);
return false;
}
}
/**
* Prüft die Supplier-Konfiguration auf Vollständigkeit vor dem Launch.
*
* @param object $supplier IdsSupplier-Objekt
* @return array ['errors' => string[], 'warnings' => string[]]
*/
function idsconnect_validateSupplierConfig($supplier)
{
$result = array('errors' => array(), 'warnings' => array());
if (empty($supplier->ids_password)) {
$result['errors'][] = 'Kein Passwort konfiguriert für "'.$supplier->label.'" IDS-Login nicht möglich.';
}
if (empty($supplier->ids_username)) {
$result['warnings'][] = 'Kein Benutzername (name_kunde) konfiguriert für "'.$supplier->label.'" Login könnte fehlschlagen und der "Weiter"-Button fehlt ggf. im Shop.';
}
return $result;
}
/**
* Testmodus-Banner ausgeben
*
* @return void
*/
function idsconnectShowTestModeBanner()
{
global $langs;
$langs->load("idsconnect@idsconnect");
if (getDolGlobalInt('IDSCONNECT_TESTMODE')) {
print '<div class="idsconnect-testmode-banner">';
print '<strong>'.$langs->trans("IdsconnectTestModeActive").'</strong> - ';
print $langs->trans("IdsconnectTestModeInfo");
print '</div>';
} else {
print '<div class="idsconnect-livemode-banner">';
print '<strong>'.$langs->trans("IdsconnectLiveModeWarning").'</strong>';
print '</div>';
}
}