45 lines
1.4 KiB
PHP
Executable file
45 lines
1.4 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__.'/../class/DocumentTypeHelper.class.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$facture_id = GETPOST('facture_id', 'int');
|
|
$docType = GETPOST('document_type', 'alpha');
|
|
|
|
if (!$facture_id || !$docType) {
|
|
echo json_encode(array('success' => false, 'error' => 'Missing parameters'));
|
|
exit;
|
|
}
|
|
|
|
// Hole die richtigen Tabellennamen für diesen Dokumenttyp
|
|
$tables = DocumentTypeHelper::getTableNames($docType);
|
|
if (!$tables) {
|
|
echo json_encode(array('success' => false, 'error' => 'Invalid document type'));
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT rowid, title, line_order, parent_section FROM ".MAIN_DB_PREFIX."facture_lines_manager";
|
|
$sql .= " WHERE ".$tables['fk_parent']." = ".(int)$facture_id;
|
|
$sql .= " AND document_type = '".$db->escape($docType)."'";
|
|
$sql .= " AND line_type = 'text'";
|
|
$sql .= " ORDER BY line_order";
|
|
$resql = $db->query($sql);
|
|
|
|
$textlines = array();
|
|
while ($obj = $db->fetch_object($resql)) {
|
|
$textlines[] = array(
|
|
'id' => $obj->rowid,
|
|
'title' => $obj->title,
|
|
'line_order' => $obj->line_order,
|
|
'parent_section' => $obj->parent_section
|
|
);
|
|
}
|
|
|
|
echo json_encode(array('success' => true, 'textlines' => $textlines));
|