epcqr/class/actions_epcqr.class.php

147 lines
4 KiB
PHP

<?php
/* Copyright (C) 2025 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file class/actions_epcqr.class.php
* \ingroup epcqr
* \brief Hook-Klasse für QR-Code und Bild-Integration
*/
/**
* Hook-Klasse für EPCQR-Modul
* Verarbeitet ODT-Dokumente und fügt Bilder/QR-Codes ein
*/
class ActionsEpcqr
{
private $db;
private $conf;
private $langs;
public $errors = array();
public $resprints;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
global $conf, $langs;
$this->conf = $conf;
$this->langs = $langs;
}
/**
* Hook nach ODT-Generierung
* Wird aufgerufen nachdem ein ODT-Dokument erstellt wurde
*
* @param array $parameters Hook-Parameter
* @param object $object Dolibarr-Objekt
* @param string $action Aktuelle Aktion
* @return int 0 = OK, <0 = Fehler
*/
public function afterODTCreation($parameters, &$object, &$action)
{
global $conf;
dol_syslog("EPCQR Hook: afterODTCreation aufgerufen", LOG_DEBUG);
// Prüfen ob Parameter vorhanden sind
if (empty($parameters['file'])) {
dol_syslog("EPCQR Hook: Kein Dateipfad in Parametern", LOG_DEBUG);
return 0;
}
$odfFilePath = $parameters['file'];
// Prüfen ob Datei existiert
if (!file_exists($odfFilePath)) {
dol_syslog("EPCQR Hook: ODT-Datei existiert nicht: ".$odfFilePath, LOG_WARNING);
return 0;
}
// Nur ODT-Dateien verarbeiten
if (pathinfo($odfFilePath, PATHINFO_EXTENSION) !== 'odt') {
dol_syslog("EPCQR Hook: Keine ODT-Datei, überspringe", LOG_DEBUG);
return 0;
}
// Prüfen ob Objekt gültig ist
if (!is_object($object) || empty($object->id)) {
dol_syslog("EPCQR Hook: Ungültiges Objekt", LOG_DEBUG);
return 0;
}
// Bilder in ODT einfügen
require_once __DIR__.'/../lib/epcqr.lib.php';
$result = epcqr_processODTImages($odfFilePath, $object);
if ($result) {
dol_syslog("EPCQR Hook: Bilder erfolgreich in ODT eingefügt", LOG_INFO);
} else {
dol_syslog("EPCQR Hook: Fehler beim Einfügen der Bilder", LOG_WARNING);
}
return 0;
}
/**
* Hook für PDF-Generierung (falls später benötigt)
*
* @param array $parameters Hook-Parameter
* @param object $object Dolibarr-Objekt
* @param string $action Aktuelle Aktion
* @return int 0 = OK, <0 = Fehler
*/
public function beforePDFCreation($parameters, &$object, &$action)
{
// Hier könnte später Code für PDF-Verarbeitung eingefügt werden
return 0;
}
/**
* Hook für completesubstitutionarray
* Fügt zusätzliche Substitutionswerte hinzu
*
* @param array $parameters Hook-Parameter
* @param object $object Dolibarr-Objekt
* @param string $action Aktuelle Aktion
* @return int 0 = OK, <0 = Fehler
*/
public function completesubstitutionarray($parameters, &$object, &$action)
{
dol_syslog("EPCQR Hook: completesubstitutionarray aufgerufen", LOG_DEBUG);
if (empty($parameters['substitutionarray'])) {
dol_syslog("EPCQR Hook: Kein substitutionarray in Parametern", LOG_DEBUG);
return 0;
}
// Substitutionsfunktion aufrufen
require_once __DIR__.'/../core/substitutions/functions_epcqr.lib.php';
epcqr_completesubstitutionarray(
$parameters['substitutionarray'],
$this->langs,
$object,
isset($parameters['outputlangs']) ? $parameters['outputlangs'] : null
);
return 0;
}
}