CMXX - Initial translation engine

This commit is contained in:
“VeLiTi”
2025-01-08 13:20:09 +01:00
parent 2c44556567
commit 30b60c8652
7 changed files with 457 additions and 14 deletions

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"php.version": "8.4"
}

118
api/v2/get/translations.php Normal file
View File

@@ -0,0 +1,118 @@
<?php
defined($security_key) or exit;
//------------------------------------------
// Translations
//------------------------------------------
//Connect to DB
$pdo = dbConnect($dbname);
//SoldTo is empty
if (empty($partner->soldto) || $partner->soldto == ''){$soldto_search = '%';} else {$soldto_search = '-%';}
//default whereclause
$whereclause = '';
switch ($permission) {
case '4':
$whereclause = '';
break;
case '3':
$whereclause = '';
break;
default:
$condition = '__salesid___'.$partner->salesid.'___soldto___'.substr($partner->soldto, 0, strpos($partner->soldto, "-")).$soldto_search;
$whereclause = 'WHERE accounthierarchy like "'.$condition.'"';
break;
}
//NEW ARRAY
$criterias = [];
$clause = '';
//Check for $_GET variables and build up clause
if(isset($get_content) && $get_content!=''){
//GET VARIABLES FROM URL
$requests = explode("&", $get_content);
//Check for keys and values
foreach ($requests as $y){
$v = explode("=", $y);
//INCLUDE VARIABLES IN ARRAY
$criterias[$v[0]] = $v[1];
if ($v[0] == 'page' || $v[0] =='p' || $v[0] =='totals' || $v[0] =='list' || $v[0] =='history'|| $v[0] =='success_msg'){
//do nothing
}
elseif ($v[0] == 'search') {
//build up search
$clause .= ' AND variable like :'.$v[0];
}
else {//create clause
$clause .= ' AND '.$v[0].' = :'.$v[0];
}
}
if ($whereclause == '' && $clause !=''){
$whereclause = 'WHERE '.substr($clause, 4);
} else {
$whereclause .= $clause;
}
}
//Define Query
if(isset($criterias['totals']) && $criterias['totals'] ==''){
//Request for total rows
$sql = 'SELECT count(*) as count FROM text_variables '.$whereclause.'';
}
else {
//SQL for Paging
$sql = 'SELECT * FROM text_variables '.$whereclause.' LIMIT :page,:num_products';
}
$stmt = $pdo->prepare($sql);
//Bind to query
if (str_contains($whereclause, ':condition')){
$stmt->bindValue('condition', $condition, PDO::PARAM_STR);
}
if (!empty($criterias)){
foreach ($criterias as $key => $value){
$key_condition = ':'.$key;
if (str_contains($whereclause, $key_condition)){
if ($key == 'search'){
$search_value = '%'.$value.'%';
$stmt->bindValue($key, $search_value, PDO::PARAM_STR);
}
else {
$stmt->bindValue($key, $value, PDO::PARAM_STR);
}
}
}
}
//Add paging details
if(isset($criterias['totals']) && $criterias['totals']==''){
$stmt->execute();
$messages = $stmt->fetch();
$messages = $messages[0];
}
else {
$current_page = isset($criterias['p']) && is_numeric($criterias['p']) ? (int)$criterias['p'] : 1;
$stmt->bindValue('page', ($current_page - 1) * $page_rows_products, PDO::PARAM_INT);
$stmt->bindValue('num_products', $page_rows_translations, PDO::PARAM_INT);
//Excute Query
$stmt->execute();
//Get results
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
//------------------------------------------
//JSON_ENCODE
//------------------------------------------
$messages = json_encode($messages, JSON_UNESCAPED_UNICODE);
//Send results
echo $messages;
?>

View File

@@ -24,11 +24,11 @@ $rma_status = 'Status';
$rma_sw_version_latest = 'Latest software version';
$rma_servicereport_latest = 'Servicereport created last 7days';
$rma_status0_text = '1';
$rma_status1_text = '2';
$rma_status2_text = '3';
$rma_status3_text = '4';
$rma_status4_text = '5';
$rma_status0_text = 'New';
$rma_status1_text = 'In Progress';
$rma_status2_text = 'Approved';
$rma_status3_text = 'Completed';
$rma_status4_text = 'Cancelled';
$rma_information = 'RMA information';
$rma_return_reason = 'Return reason';
@@ -179,9 +179,9 @@ $view .= '
<tr>
<th class="responsive-hidden">'.($rma_rowID ?? 'Request number').'</th>
<th>'.($rma_status ?? 'Status').'</th>
<th>'.getRelativeTime($general_created).'</th>
<th>'.$general_created.'</th>
<th>'.$general_createdby.'</th>
<th>'.getRelativeTime($general_updated).'</th>
<th>'.$general_updated.'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>
@@ -206,9 +206,9 @@ $view .= '
<tr>
<td class="responsive-hidden">'.$response['rowID'].'</td>
<td>'.$$status_text.'</td>
<td>'.$response['created'].'</td>
<td>'.getRelativeTime($response['created']).'</td>
<td>'.$response['createdby'].'</td>
<td>'.$response['updated'].'</td>
<td>'.getRelativeTime($response['updated']).'</td>
<td><a href="index.php?page=rma&rowID='.$response['rowID'].'" class="btn_link">'.$general_view.'</a></td>
</tr>
';

View File

@@ -16,7 +16,7 @@ $sales_sub = array('accounts','contracts');
$products_sub = array('products');
$admin_sub = array('users','communications','partners');
$reporting_sub = array('report_build','report_contracts_billing','report_healthindex','report_usage');
$settings_sub = array('config','language','logfile','maintenance','profiles');
$settings_sub = array('config','translations','logfile','maintenance','profiles');
//URLS
$urls = array(
@@ -122,11 +122,11 @@ $urls = array(
"icon" => "fas fa-tools",
"name" => "menu_config"
),
"language" => array(
"url" => "language",
"selected" => "language",
"translations" => array(
"url" => "translations",
"selected" => "translations",
"icon" => "fas fa-tachometer-alt",
"name" => "menu_language"
"name" => "menu_translations"
),
"logfile" => array(
"url" => "logfile",
@@ -218,6 +218,7 @@ $page_rows_cartest = 25 ;// list contracts
$page_rows_equipment_servicereporst = 5 ;// Number of service reports on equipment
$page_rows_changelog = 50 ;// Number of changelogs returned
$page_rows_rma = 25; // list RMA
$page_rows_translations = 50; //list translation variables
//------------------------------------------
// Languages supported

View File

@@ -62,6 +62,8 @@ $all_views = [
"logfile",
"changelog",
"language",
"translations",
"translation_manage",
"application",
"maintenance",
"profiles",

159
translation_manage.php Normal file
View File

@@ -0,0 +1,159 @@
<?php
defined(page_security_key) or exit;
$page = 'translation_manage';
/*Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//PAGE Security
$update_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'U');
$delete_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'D');
$create_allowed = isAllowed($page ,$_SESSION['profile'],$_SESSION['permission'],'C');
// Default input product values
$text_variable = [
'rowID' => '',
'variable' => '',
'created' => '',
'createdby' => '',
'updated' => '',
'updatedby' => '',
'accounthierarchy' => ''
];
if (isset($_GET['rowID'])) {
//CALL TO API
$api_url = '/v2/translations/rowID='.$_GET['rowID'];
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = null;}
$text_variable = json_decode(json_encode($responses[0]), true);
if ($update_allowed === 1){
if (isset($_POST['submit'])) {
//GET ALL POST DATA
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v2/translations', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translations&success_msg=2');
exit;
}
}
}
if ($delete_allowed === 1){
if (isset($_POST['delete'])) {
//GET ALL POST DATA
$data = json_encode($_POST , JSON_UNESCAPED_UNICODE);
//Secure data
$payload = generate_payload($data);
//API call
$responses = ioServer('/v2/translations', $payload);
// Redirect and delete product
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translations&success_msg=3');
exit;
}
}
}
} else {
// Create a new variable
if (isset($_POST['submit']) && $create_allowed === 1) {
//GET ALL POST DATA
$data = json_encode($_POST, JSON_UNESCAPED_UNICODE);
//API call
$responses = ioServer('/v2/translations', $payload);
if ($responses === 'NOK'){
} else {
header('Location: index.php?page=translations&success_msg=1');
exit;
}
}
}
//EMPTY VIEW
$view = '';
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 0) {
$success_msg = $error_msg_0;
}
}
template_header('Translation', 'translation', 'manage');
if (isset($success_msg)){
$view .= ' <div class="msg error">
<i class="fas fa-check-circle"></i>
<p>'.$success_msg.'</p>
<i class="fas fa-times"></i>
</div>';
}
$view .='
<form action="" method="post">
<div class="content-title responsive-flex-wrap responsive-pad-bot-3">
<h2 class="responsive-width-100">'.($text_variables_h2 ?? '').'</h2>
<a href="index.php?page=translations" class="btn alt mar-right-2">'.$button_cancel.'</a>
';
if ($delete_allowed === 1){
$view .= '<input type="submit" name="delete" value="Delete" class="btn red mar-right-2" onclick="return confirm(\'Are you sure you want to delete this user?\')">';
}
if ($update_allowed === 1){
$view .= '<input type="submit" name="submit" value="Save" class="btn">';
}
$view .= '</div>';
$view .= '<div class="tabs">
<a href="#" class="active">'.$tab1 .'</a>
<a href="#">'.$tab3.'</a>
</div>
';
//Define Service and User enabled
$view .= '<div class="content-block tab-content active">
<div class="form responsive-width-100">
<label for="variable">'.$text_variable_name ?? ''.'</label>
<input id="variable" type="text" name="variable" placeholder="'.$text_variable_name.'" value="'.$text_variable['variable'].'" pattern="^\S+$" required">
<input type="hidden" name="rowID" value="'.$text_variable['rowID'].'" readonly>
';
$view .= '</div>
</div>';
$view .= '<div class="content-block tab-content">
<div class="form responsive-width-100">
<label for="">'.$general_created.'</label>
<input id="name" type="text" name="" placeholder="'.$general_created.'" value="'.$text_variable['created'].'" readonly>
<label for="">'.$general_createdby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_createdby.'" value="'.$text_variable['createdby'].'" readonly>
<label for="productcode">'.$general_updated.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updated.'" value="'.$text_variable['updated'].'" readonly>
<label for="productcode">'.$general_updatedby.'</label>
<input id="name" type="text" name="" placeholder="'.$general_updatedby.'" value="'.$text_variable['updatedby'].'" readonly>
</div>
</div>';
$view .= '</form>';
//Output
echo $view;
template_footer()
?>

160
translations.php Normal file
View File

@@ -0,0 +1,160 @@
<?php
defined(page_security_key) or exit;
if (debug && debug_id == $_SESSION['id']){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
include_once './assets/functions.php';
include_once './settings/settings.php';
//SET ORIGIN FOR NAVIGATION
$prev_page = $_SESSION['prev_origin'] ?? '';
$page = $_SESSION['origin'] = 'translations';
/*Check if allowed
if (isAllowed($page,$_SESSION['profile'],$_SESSION['permission'],'R') === 0){
header('location: index.php');
exit;
}
*/
//GET PARAMETERS
$pagination_page = isset($_GET['p']) ? $_GET['p'] : 1;
$status = isset($_GET['status']) ? '&status='.$_GET['status'] : '';
$search = isset($_GET['search']) ? '&search='.$_GET['search'] : '';
// Determine the URL
$url = 'index.php?page=translations'.$status.$search;
//GET Details from URL
$GET_VALUES = urlGETdetails($_GET) ?? '';
//CALL TO API
$api_url = '/v2/translations/'.$GET_VALUES;
$responses = ioServer($api_url,'');
//Decode Payload
if (!empty($responses)){$responses = decode_payload($responses);}else{$responses = null;}
//Return QueryTotal from API
$api_url = '/v2/translations/'.$GET_VALUES.'&totals=';
$query_total = ioServer($api_url,'');
//Decode Payload
if (!empty($query_total)){$query_total = decode_payload($query_total);}else{$query_total = null;}
// Handle success messages
if (isset($_GET['success_msg'])) {
if ($_GET['success_msg'] == 1) {
$success_msg = $message_pr_1;
}
if ($_GET['success_msg'] == 2) {
$success_msg = $message_pr_2;
}
if ($_GET['success_msg'] == 3) {
$success_msg = $message_pr_3;
}
}
template_header('Translations', 'translations','view');
$view = '
<div class="content-title">
<div class="title">
<i class="fa-solid fa-box-open"></i>
<div class="txt">
<h2>'.$products_h2.' ('.$query_total.')</h2>
<p>'.$products_p.'</p>
</div>
</div>
</div>';
if (isset($success_msg)){
$view .= ' <div class="msg success">
<i class="fas fa-check-circle"></i>
<p>'.$success_msg.'</p>
<i class="fas fa-times"></i>
</div>';
}
$view .= '
<div class="content-header responsive-flex-column pad-top-5">
<a href="index.php?page=translation_manage" class="btn">'.$button_create_product.'</a>
<form action="" method="get">
<input type="hidden" name="page" value="translations">
<div class="filters">
<a href="#"><i class="fa-solid fa-filter"></i>'.$general_filters.'</a>
<div class="list">
<select name="status">
<option value="" disabled selected>'.$prod_status_text.'</option>
<option value="0"'.($status==0?' selected':'').'>'.$prod_status_0.'</option>
<option value="1"'.($status==1?' selected':'').'>'.$prod_status_1.'</option>
</select>
<button type="submit">'.$button_apply.'</button>
</div>
</div>
<div class="search">
<label for="search">
<input id="search" type="text" name="search" placeholder="'.$product_search .'" value="" class="responsive-width-100">
<i class="fas fa-search"></i>
</label>
</div>
</form>
</div>
';
$view .= '
<div class="content-block">
<div class="table">
<table class="sortable">
<thead>
<tr>
<th>'.$product_code.'</th>
<th>'.$product_category.'</th>
<th>'.$product_parttype.'</th>
<th class="responsive-hidden"></th>
<th>'.$product_name.'</th>
<th>'.$general_actions.'</th>
</tr>
</thead>
<tbody>
';
if (empty($responses)){
$view .= '
<tr>
<td colspan="8" style="text-align:center;">'.$message_no_products.'</td>
</tr>';
}
else {
var_dump($responses);
foreach ($responses as $response){
}
}
$view .= '
</tbody>
</table>
</div>
</div>
';
$view.='<div class="pagination">';
if ($pagination_page > 1) {
$page = $pagination_page-1;
$view .= '<a href="'.$url.'&p=1">'.$general_first.'</a>';
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_prev.'</a>';
}
$totals = ceil($query_total / $page_rows_translations) == 0 ? 1 : ceil($query_total / $page_rows_translations);
$view .= '<span> '.$general_page.$pagination_page.$general_page_of.$totals.'</span>';
if ($pagination_page * $page_rows_translations < $query_total){
$page = $pagination_page+1;
$view .= '<a href="'.$url.'&p='.$page.'">'.$general_next.'</a>';
$view .= '<a href="'.$url.'&p='.$totals.'">'.$general_last.'</a>';
}
$view .= '</div>';
//OUTPUT
echo $view;
template_footer();
?>