52 lines
1.8 KiB
PHP
Executable file
52 lines
1.8 KiB
PHP
Executable file
<?php
|
|
define('NOTOKENRENEWAL', 1);
|
|
|
|
$res = 0;
|
|
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
|
|
if (!$res && file_exists("../../../../main.inc.php")) $res = @include "../../../../main.inc.php";
|
|
if (!$res) die("Include of main fails");
|
|
require_once __DIR__.'/../lib/subtotaltitle.lib.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$textline_id = GETPOST('textline_id', 'int');
|
|
$text = GETPOST('text', 'restricthtml');
|
|
|
|
subtotaltitle_debug_log('🔄 edit_textline: id=' . $textline_id);
|
|
|
|
if (!$textline_id || !$text) {
|
|
echo json_encode(array('success' => false, 'error' => 'Missing parameters'));
|
|
exit;
|
|
}
|
|
|
|
// Hole erst fk_facturedet (falls Textzeile in Rechnung ist)
|
|
$sql_get = "SELECT fk_facturedet FROM ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql_get .= " WHERE rowid = ".(int)$textline_id;
|
|
$sql_get .= " AND line_type = 'text'";
|
|
$resql = $db->query($sql_get);
|
|
$obj = $db->fetch_object($resql);
|
|
$fk_facturedet = $obj ? $obj->fk_facturedet : null;
|
|
|
|
// Update Manager-Tabelle
|
|
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql .= " SET title = '".$db->escape($text)."'";
|
|
$sql .= " WHERE rowid = ".(int)$textline_id;
|
|
$sql .= " AND line_type = 'text'";
|
|
|
|
if (!$db->query($sql)) {
|
|
echo json_encode(array('success' => false, 'error' => $db->lasterror()));
|
|
exit;
|
|
}
|
|
|
|
// Falls in facturedet vorhanden, dort auch updaten
|
|
if ($fk_facturedet > 0) {
|
|
$sql_fd = "UPDATE ".MAIN_DB_PREFIX."facturedet";
|
|
$sql_fd .= " SET description = '".$db->escape($text)."'";
|
|
$sql_fd .= " WHERE rowid = ".(int)$fk_facturedet;
|
|
$db->query($sql_fd);
|
|
subtotaltitle_debug_log('✅ Textzeile + facturedet geändert');
|
|
} else {
|
|
subtotaltitle_debug_log('✅ Textzeile geändert (nicht in facturedet)');
|
|
}
|
|
|
|
echo json_encode(array('success' => true, 'synced_facturedet' => ($fk_facturedet > 0)));
|