added sheet and config API in insert edit template
This commit is contained in:
@@ -12,22 +12,39 @@ try {
|
||||
// Retrieve and sanitize form data
|
||||
$name = trim($_POST['name'] ?? '');
|
||||
$source_type = strtoupper(trim($_POST['source_type'] ?? 'XLS'));
|
||||
$header_row = isset($_POST['header_row']) && $_POST['header_row'] !== '' ? intval($_POST['header_row']) : null;
|
||||
|
||||
$header_row = isset($_POST['header_row']) && $_POST['header_row'] !== ''
|
||||
? intval($_POST['header_row'])
|
||||
: null;
|
||||
|
||||
$start_column = trim($_POST['start_column'] ?? '');
|
||||
|
||||
$xls_sheet_index = isset($_POST['xls_sheet_index']) && $_POST['xls_sheet_index'] !== ''
|
||||
? intval($_POST['xls_sheet_index'])
|
||||
: 0;
|
||||
|
||||
$api_config_id = isset($_POST['api_config_id']) && $_POST['api_config_id'] !== ''
|
||||
? intval($_POST['api_config_id'])
|
||||
: null;
|
||||
|
||||
$description = trim($_POST['description'] ?? '');
|
||||
$target_table = trim($_POST['target_table'] ?? 'datadb');
|
||||
$idclient = intval($_POST['client_id'] ?? 0);
|
||||
$clientname = trim($_POST['client_name'] ?? '');
|
||||
$idschema = intval($_POST['idschema'] ?? 0);
|
||||
$schemaname = trim($_POST['schemaname'] ?? '');
|
||||
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== '' ? intval($_POST['idroutine']) : null;
|
||||
$idroutine = isset($_POST['idroutine']) && $_POST['idroutine'] !== ''
|
||||
? intval($_POST['idroutine'])
|
||||
: null;
|
||||
|
||||
$button_size = trim($_POST['button_size'] ?? 'medium');
|
||||
$button_bg_color = trim($_POST['button_bg_color'] ?? '#007bff');
|
||||
$button_text_color = trim($_POST['button_text_color'] ?? '#ffffff');
|
||||
$button_label = trim($_POST['button_label'] ?? 'Click Me');
|
||||
|
||||
// Normalize source type
|
||||
if (!in_array($source_type, ['XLS', 'API'], true)) {
|
||||
// API / JSON is saved as API
|
||||
if (!in_array($source_type, ['XLS', 'API', 'PDF'], true)) {
|
||||
$source_type = 'XLS';
|
||||
}
|
||||
|
||||
@@ -41,26 +58,62 @@ try {
|
||||
if ($header_row === null || $header_row <= 0 || $start_column === '') {
|
||||
throw new Exception("Header Row and Start Column are required for XLS templates.");
|
||||
}
|
||||
|
||||
if ($xls_sheet_index < 0) {
|
||||
throw new Exception("XLS Sheet Number cannot be negative.");
|
||||
}
|
||||
|
||||
$api_config_id = null;
|
||||
}
|
||||
|
||||
// API templates do not require XLS coordinates
|
||||
// API / JSON validation
|
||||
if ($source_type === 'API') {
|
||||
if (empty($api_config_id)) {
|
||||
throw new Exception("API / JSON configuration is required for API / JSON templates.");
|
||||
}
|
||||
|
||||
$header_row = null;
|
||||
$start_column = null;
|
||||
$xls_sheet_index = null;
|
||||
}
|
||||
|
||||
// PDF currently does not require XLS coordinates or API configuration
|
||||
if ($source_type === 'PDF') {
|
||||
$header_row = null;
|
||||
$start_column = null;
|
||||
$xls_sheet_index = null;
|
||||
$api_config_id = null;
|
||||
}
|
||||
|
||||
// Database connection
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
// Optional check: verify API configuration exists and is active
|
||||
if ($api_config_id !== null) {
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT COUNT(*)
|
||||
FROM api_configurations
|
||||
WHERE id = ?
|
||||
AND is_active = 1
|
||||
");
|
||||
$stmt->execute([$api_config_id]);
|
||||
|
||||
if ((int)$stmt->fetchColumn() === 0) {
|
||||
throw new Exception("Selected API / JSON configuration does not exist or is not active.");
|
||||
}
|
||||
}
|
||||
|
||||
// Insert the new template
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO excel_templates
|
||||
INSERT INTO excel_templates
|
||||
(
|
||||
name,
|
||||
source_type,
|
||||
header_row,
|
||||
start_column,
|
||||
xls_sheet_index,
|
||||
api_config_id,
|
||||
description,
|
||||
target_table,
|
||||
idclient,
|
||||
@@ -75,7 +128,13 @@ try {
|
||||
created_at,
|
||||
updated_at
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
|
||||
VALUES
|
||||
(
|
||||
?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
NOW(), NOW()
|
||||
)
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
@@ -83,6 +142,8 @@ try {
|
||||
$source_type,
|
||||
$header_row,
|
||||
$start_column,
|
||||
$xls_sheet_index,
|
||||
$api_config_id,
|
||||
$description,
|
||||
$target_table,
|
||||
$idclient,
|
||||
|
||||
Reference in New Issue
Block a user