Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/PAWECOGmbH/saaster i…
Browse files Browse the repository at this point in the history
…nto development
  • Loading branch information
ptruessel committed Dec 13, 2024
2 parents e890892 + cadf9c5 commit 3a76f92
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 26 deletions.
86 changes: 86 additions & 0 deletions www/backend/core/com/settings.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,90 @@ component displayname="settings" output="false" {

}


// This code generates an SQL script that formats all entries from the given table
public string function generateSqlCode(required string sqlTable, required string primKey) {

// Check if the table exists
local.checkSqlTable = queryExecute(
options = {datasource = application.datasource},
params = {
table_name: {type: "string", value: arguments.sqlTable}
},
sql = "
SELECT COUNT(*) as cnt
FROM information_schema.tables
WHERE table_name = :table_name
"
)

if (local.checkSqlTable.cnt gt 0) {

local.getEntries = queryExecute(
options = {datasource = application.datasource},
sql = "
SELECT *
FROM #arguments.sqlTable#
"
)

if (local.getEntries.recordCount) {

// Get column list and remove the first entry
local.columns = local.getEntries.columnList;
local.columnsArray = listToArray(local.columns, ",");
arrayDeleteAt(local.columnsArray, 1); // Removes the first entry

// Create the filtered list of columns
local.filteredColumns = arrayToList(local.columnsArray, ", ");

// Generate the SQL statement
local.sqlOutput = "INSERT INTO #arguments.sqlTable# (" & local.filteredColumns & ") VALUES" & chr(10);

// Collect values
local.values = [];
for (local.row in local.getEntries) {
local.valueRow = [];
for (local.column in local.columnsArray) {
local.value = "'" & replace(local.row[local.column], "'", "''", "all") & "'"; // Escaping
arrayAppend(local.valueRow, local.value);
}
arrayAppend(local.values, "(" & arrayToList(local.valueRow, ", ") & ")");
}
local.sqlOutput &= arrayToList(local.values, "," & chr(10)) & chr(10);

// ON DUPLICATE KEY UPDATE Logic
local.updateClauses = [];
for (local.column in local.columnsArray) {
if (local.column NEQ arguments.primKey) { // Exclude primary key
arrayAppend(local.updateClauses, local.column & " = VALUES(" & local.column & ")");
}
}
local.sqlOutput &= "ON DUPLICATE KEY UPDATE " & chr(10) & arrayToList(local.updateClauses, "," & chr(10)) & ";";

// Return with textarea
return '
<textarea style="width: 100%; height: 800px;" readonly>' &
local.sqlOutput &
'</textarea>';

} else {

return "No entries in table " & arguments.sqlTable;

}



} else {

return "No table found!"

}




}

}
19 changes: 0 additions & 19 deletions www/backend/core/handler/sysadmin/languages.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@ if (structKeyExists(form, "modal_lng")) {
table = form.table;
key = form.key;
/* if(referer eq "/sysadmin/mappings##frontend" and field neq "strhtmlcodes"){
loop list=form.fieldnames index="i" {
if (listFirst(i, "_") eq "text") {
text_value = evaluate(i);
text_value = application.objGlobal.cleanUpText(text_value);
form[i] = text_value;
}
}
} else if (referer eq "/sysadmin/mappings##frontend" and field eq "strhtmlcodes"){
loop list=form.fieldnames index="i" {
if (listFirst(i, "_") eq "text") {
text_value = evaluate(i);
text_value = toString(binaryDecode(text_value, "base64"));
text_value = left(text_value, 3000);
form[i] = text_value;
}
}
} */
try {
loop list=form.fieldnames index="i" {
Expand Down
33 changes: 31 additions & 2 deletions www/backend/core/views/sysadmin/mappings.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,22 @@
<div class="tab-content">
<div id="custom" class="card tab-pane show active">
<div class="card-body">
<div class="card-title">Custom mappings</div>

<div class="d-flex justify-content-between align-items-center">

<div class="card-title">Custom mappings</div>

<a href="#application.mainURL#/backend/core/views/sysadmin/sql_code.cfm?sql_table=custom_mappings&prim_key=strMapping"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="Generate SQL Code for the table custom_mappings"
class="text-decoration-none" target="_blank">
<i class="fas fa-file-code fa-lg me-3 p-0" style="font-size: 20px;"></i>
</a>

</div>


<p>Here you can create your own mappings. These mappings are not affected by any system updates.</p>
<div class="table-responsive">
<table class="table table-vcenter card-table">
Expand Down Expand Up @@ -153,7 +168,21 @@
</div>
<div id="frontend" class="card tab-pane show">
<div class="card-body">
<div class="card-title">Frontend mappings</div>

<div class="d-flex justify-content-between align-items-center">

<div class="card-title">Frontend mappings</div>

<a href="#application.mainURL#/backend/core/views/sysadmin/sql_code.cfm?sql_table=frontend_mappings&prim_key=strMapping"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="Generate SQL Code for the table frontend_mappings"
class="text-decoration-none" target="_blank">
<i class="fas fa-file-code fa-lg me-3 p-0" style="font-size: 20px;"></i>
</a>

</div>

<p>Here you can create your own Frontend mappings. These mappings are not affected by any system updates.</p>
<div class="table-responsive">
<table class="table table-vcenter card-table">
Expand Down
24 changes: 24 additions & 0 deletions www/backend/core/views/sysadmin/sql_code.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

<cfscript>
// This code generates an SQL script that formats all entries from the given table
if (structKeyExists(session, "sysadmin") and session.sysadmin) {
if (structKeyExists(url, "sql_table")) {
param name="url.prim_key" default="strVariable";
writeOutput(application.objSettings.generateSqlCode(url.sql_table, url.prim_key));
// For frontend mappings we also need the table frontend_mappings_trans
if (url.sql_table eq "frontend_mappings") {
writeOutput(application.objSettings.generateSqlCode("frontend_mappings_trans", "strMapping"));
}
}
}
</cfscript>
39 changes: 34 additions & 5 deletions www/backend/core/views/sysadmin/translations.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,22 @@
<div class="tab-content">
<div id="custom" class="card tab-pane show <cfif url.tr eq "custom">active</cfif>">
<div class="card-body">
<div class="card-title">Custom translations</div>
<div class="d-flex justify-content-between align-items-center">

<div class="card-title">Custom translations</div>

<a href="#application.mainURL#/backend/core/views/sysadmin/sql_code.cfm?sql_table=custom_translations"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="Generate SQL Code for the table custom_translations"
class="text-decoration-none" target="_blank">
<i class="fas fa-file-code fa-lg me-3 p-0" style="font-size: 20px;"></i>
</a>

</div>

<p>Here you can create your own translations (variables). These are used for system texts and are called with the function "getTrans()". These translations are not affected by any system updates.</p>

<div class="row">
<div class="col-lg-4">
<form action="#application.mainURL#/sysadmin/translations" method="post">
Expand Down Expand Up @@ -273,7 +287,22 @@
</div>
<div id="system" class="card tab-pane show <cfif url.tr eq "system">active</cfif>">
<div class="card-body">
<div class="card-title">System translations</div>

<div class="d-flex justify-content-between align-items-center">

<div class="card-title">System translations</div>

<a href="#application.mainURL#/backend/core/views/sysadmin/sql_code.cfm?sql_table=system_translations"
data-bs-toggle="tooltip"
data-bs-placement="top"
title="Generate SQL Code for the table system_translations"
class="text-decoration-none" target="_blank">
<i class="fas fa-file-code fa-lg me-3 p-0" style="font-size: 20px;"></i>
</a>

</div>


<p class="text-red">The system translations are used by the developers of the saaster.io project. Users of the tool should only perform translations and not change any variables. Co-developers can request changes via Github.</p>
<div class="row">
<div class="col-lg-4">
Expand Down Expand Up @@ -392,7 +421,7 @@
A <a href="https://www.deepl.com/pro-api" target="_blank">Deepl API</a> key is required for this. Please check whether the language you want to translate is supported.
</p>
<form onsubmit="loading()" id="submit_form" class="col-lg-9 row" action="#application.mainURL#/sysadm/translations" method="post">

<div class="col-lg-5">
<label for="fromLang">From:</label>
<select onchange="checkIfSame()" id="fromLang" name="fromLang" class="form-select" required>
Expand Down Expand Up @@ -439,7 +468,7 @@
</span>
</label>
</div>
<div>
<div>
<br>
<p>Choose what you would like to translate:</p>
<label class="form-check">
Expand Down Expand Up @@ -487,6 +516,6 @@
</div>
</div>
</cfoutput>


</div>

0 comments on commit 3a76f92

Please sign in to comment.