CMXX - Dealers

This commit is contained in:
“VeLiTi”
2025-04-07 20:25:37 +02:00
parent 6f938302ff
commit cb18443af9
7 changed files with 427 additions and 54 deletions

View File

@@ -13,75 +13,85 @@ $delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
if ($create_allowed === 1 && $_POST){
$log_results = [];
foreach ($_POST as $contents){
$tableName = json_decode($_POST['table'],true);
$contents = json_decode($_POST['data'],true);
$contents = json_decode($contents,true);
foreach ($contents as $content){
foreach ($contents as $content){
//CHECK IF VARIABLE EXISTS
$text_variable = ioServer('/v2/translations/variable='.$content['variable'],'');
if (!empty($text_variable)){$text_variable = json_decode($text_variable,true);}else{$text_variable = null;}
switch ($tableName) {
//IF NO ERRORS PROCES IT
if (is_array($text_variable)){
case 'text_variables':
//CHECK IF VARIABLE EXISTS
$text_variable = ioServer('/v2/translations/variable='.$content['variable'],'');
if (!empty($text_variable)){$text_variable = json_decode($text_variable,true);}else{$text_variable = null;}
if (count($text_variable) == 0){
//VARIABLE NOT FOUND -> CREATE
$payload = json_encode(array("variable" => $content['variable']), JSON_UNESCAPED_UNICODE);
//API call
$text_variable_new = ioServer('/v2/translations',$payload);
//returns results
$text_variable_new = json_decode($text_variable_new ,true);
//Provide feedback
$log_results[$content['variable']]['rowID'] = $text_variable_new['rowID'].' created';
}
//IF NO ERRORS PROCES IT
if (is_array($text_variable)){
$text_variable = $text_variable[0] ?? 'new';
//VARIABLE ROWID
$text_variable_rowid = ($text_variable != 'new') ? $text_variable['rowID'] : $text_variable_new['rowID'];
foreach ($content as $key => $var){
if (count($text_variable) == 0){
//VARIABLE NOT FOUND -> CREATE
$payload = json_encode(array("variable" => $content['variable']), JSON_UNESCAPED_UNICODE);
//API call
$text_variable_new = ioServer('/v2/translations',$payload);
//returns results
$text_variable_new = json_decode($text_variable_new ,true);
//Provide feedback
$log_results[$content['variable']]['rowID'] = $text_variable_new['rowID'].' created';
}
$text_variable = $text_variable[0] ?? 'new';
//VARIABLE ROWID
$text_variable_rowid = ($text_variable != 'new') ? $text_variable['rowID'] : $text_variable_new['rowID'];
if ($var != $content['variable']){
$language_key = strtoupper($key);
foreach ($content as $key => $var){
if ($var != $content['variable']){
$language_key = strtoupper($key);
//check if variable_id and language_key combination already exists
$text_translation = ioServer('/v2/translations_details/variable_ID='.$text_variable_rowid.'&language_key='.$language_key,'');
if (!empty($text_translation)){$text_translation = json_decode($text_translation,true);}else{$text_translation = null;}
if (count($text_translation) == 0){
//TRANSLATION NOT FOUND ->CREATE
$payload = json_encode(array("variable_ID" => $text_variable_rowid, "language_key" => $language_key, "translation" => $var), JSON_UNESCAPED_UNICODE);
$text_translation_new = ioServer('/v2/translations_details',$payload);
$text_translation_new = json_decode($text_translation_new ,true);
//Provide feedback
$log_results[$content['variable']][$language_key] = $text_translation_new['rowID'].' created';
}
elseif(count($text_translation) > 0){
//check if variable_id and language_key combination already exists
$text_translation = ioServer('/v2/translations_details/variable_ID='.$text_variable_rowid.'&language_key='.$language_key,'');
if (!empty($text_translation)){$text_translation = json_decode($text_translation,true);}else{$text_translation = null;}
$text_translation = $text_translation[0];
//TRANSLATION FOUND -> UPDATE
$payload = json_encode(array("rowID" => $text_translation['rowID'] , "translation" => $var), JSON_UNESCAPED_UNICODE);
$text_translation = ioServer('/v2/translations_details',$payload);
$text_translation = json_decode($text_translation ,true);
//Provide feedback
$log_results[$content['variable']][$language_key] = $text_translation['rowID'].' updated';
if (count($text_translation) == 0){
//TRANSLATION NOT FOUND ->CREATE
$payload = json_encode(array("variable_ID" => $text_variable_rowid, "language_key" => $language_key, "translation" => $var), JSON_UNESCAPED_UNICODE);
$text_translation_new = ioServer('/v2/translations_details',$payload);
$text_translation_new = json_decode($text_translation_new ,true);
//Provide feedback
$log_results[$content['variable']][$language_key] = $text_translation_new['rowID'].' created';
}
elseif(count($text_translation) > 0){
$text_translation = $text_translation[0];
//TRANSLATION FOUND -> UPDATE
$payload = json_encode(array("rowID" => $text_translation['rowID'] , "translation" => $var), JSON_UNESCAPED_UNICODE);
$text_translation_update = ioServer('/v2/translations_details',$payload);
$text_translation_update = json_decode($text_translation_update ,true);
//Provide feedback
$log_results[$content['variable']][$language_key] = $text_translation['rowID'].' updated';
} else {
$log_results[$content['variable']][$language_key] = 'not updated';
}
} else {
$log_results[$content['variable']][$language_key] = 'not updated';
}
}
} else {
$log_results[$content['variable']] = 'error';
}
} else {
$log_results[$content['variable']] = 'error';
}
break;
case 'dealers':
break;
}
}
print_r($log_results);
return $log_results;
}
@@ -177,6 +187,10 @@ $view ='
<div id="tableOutput" style="display:none;">
<h2>Table Preview</h2>
<div class="controls">
<select name="table_name" id="table_name" class="form-control" required>
<option value="text_variables">'.($menu_translations ?? 'Translations').'</option>
<option value="dealers">'.($menu_dealers ?? 'Dealers').'</option>
</select>
<button id="processDataBtn" class="btn">Process Data</button>
<button id="downloadCsvBtn" class="btn">Download as CSV</button>
</div>
@@ -203,6 +217,7 @@ $view ='
const processingResults = document.getElementById(\'processingResults\');
const resultsContent = document.getElementById(\'resultsContent\');
const downloadCsvBtn = document.getElementById(\'downloadCsvBtn\');
const tableName = document.getElementById(\'table_name\').value;
// Convert pasted Excel data to HTML table
convertBtn.addEventListener(\'click\', function() {
@@ -271,6 +286,7 @@ $view ='
// Use standard form submission approach instead of JSON
const form = new FormData();
form.append(\'table\', JSON.stringify(tableName));
form.append(\'data\', JSON.stringify(tableData));
fetch(window.location.href, {