diff --git a/public/userarea/update_schemajson.php b/public/userarea/update_schemajson.php index 70b346b..87250c8 100644 --- a/public/userarea/update_schemajson.php +++ b/public/userarea/update_schemajson.php @@ -170,10 +170,30 @@ try { $newDataType = $custom_field['Tipo'] ?? 'Testo'; + /* + * Required logic: + * First read SchemiCustomFieldsDettagli.ObbligatorioWeb. + * + * Values: + * - "Si" => required for this schema + * - "No" => not required for this schema + * - "Predefinito" => use CustomField.ObbligatorioWeb + */ + $schemaRequired = trim((string)($field['ObbligatorioWeb'] ?? 'Predefinito')); + $customRequired = !empty($custom_field['ObbligatorioWeb']); + + if (strcasecmp($schemaRequired, 'Si') === 0) { + $isRequired = 1; + } elseif (strcasecmp($schemaRequired, 'No') === 0) { + $isRequired = 0; + } else { + $isRequired = $customRequired ? 1 : 0; + } + $data = [ ':schema_id' => $schema_id, ':data_type' => $newDataType, - ':is_required' => !empty($custom_field['ObbligatorioWeb']) ? 1 : 0, + ':is_required' => $isRequired, ':default_value' => $custom_field['ValoreDefault'] ?? null, ':has_list' => !empty($custom_field['Elenco']) ? 1 : 0, ':length' => $custom_field['Lunghezza'] ?? 0, @@ -182,7 +202,7 @@ try { ':max_value' => $custom_field['Massimo'] ?? null, ':default_curr_date' => !empty($custom_field['DefaultCurrDate']) ? 1 : 0, ':tablename' => $target_table, - ':field_label' => $custom_field['TitoloTraduzione'] ?? '' + ':field_label' => $custom_field['TitoloTraduzione'] ?? $custom_field['Titolo'] ?? '' ]; $checkStmt->execute([$template_id, $fieldId]); @@ -234,7 +254,6 @@ try { $response["success"] = true; $response["message"] = "Schema JSON updated, mappings synchronized, removed fields deleted, and changed fields updated successfully."; - } catch (Exception $e) { if (isset($pdo) && $pdo->inTransaction()) { $pdo->rollback(); @@ -243,4 +262,4 @@ try { $response["message"] = $e->getMessage(); } -echo json_encode($response); \ No newline at end of file +echo json_encode($response);