30 lines
1 KiB
PHP
Executable file
30 lines
1 KiB
PHP
Executable file
<?php
|
|
define('NOTOKENRENEWAL', 1);
|
|
require '../../../main.inc.php';
|
|
|
|
$facture_id = GETPOST('facture_id', 'int');
|
|
$title = GETPOST('title', 'alpha');
|
|
|
|
if (!$facture_id || !$title) {
|
|
echo json_encode(['success' => false, 'error' => 'Missing parameters']);
|
|
exit;
|
|
}
|
|
|
|
// Hole nächste line_order
|
|
$sql = "SELECT MAX(line_order) as max_order";
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql .= " WHERE fk_facture = ".(int)$facture_id;
|
|
$resql = $db->query($sql);
|
|
$obj = $db->fetch_object($resql);
|
|
$next_order = ($obj->max_order ? $obj->max_order + 1 : 1);
|
|
|
|
// Erstelle Section
|
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql .= " (fk_facture, line_type, title, line_order, date_creation)";
|
|
$sql .= " VALUES (".(int)$facture_id.", 'section', '".$db->escape($title)."', ".$next_order.", NOW())";
|
|
|
|
if ($db->query($sql)) {
|
|
echo json_encode(['success' => true, 'section_id' => $db->last_insert_id(MAIN_DB_PREFIX."facture_lines_manager")]);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => $db->lasterror()]);
|
|
}
|