From 30b60c8652cd6b7be41a648065a4fcd80b53de5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Wed, 8 Jan 2025 13:20:09 +0100 Subject: [PATCH] CMXX - Initial translation engine --- .vscode/settings.json | 3 + api/v2/get/translations.php | 118 ++++++++++++++++++++++++++ rmas.php | 18 ++-- settings/settingsmenu.php | 11 +-- settings/settingsviews.php | 2 + translation_manage.php | 159 +++++++++++++++++++++++++++++++++++ translations.php | 160 ++++++++++++++++++++++++++++++++++++ 7 files changed, 457 insertions(+), 14 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 api/v2/get/translations.php create mode 100644 translation_manage.php create mode 100644 translations.php diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fa5c670 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "php.version": "8.4" +} \ No newline at end of file diff --git a/api/v2/get/translations.php b/api/v2/get/translations.php new file mode 100644 index 0000000..1b62ffb --- /dev/null +++ b/api/v2/get/translations.php @@ -0,0 +1,118 @@ +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; + +?> \ No newline at end of file diff --git a/rmas.php b/rmas.php index 2437f2b..5b59906 100644 --- a/rmas.php +++ b/rmas.php @@ -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 .= ' '.($rma_rowID ?? 'Request number').' '.($rma_status ?? 'Status').' - '.getRelativeTime($general_created).' + '.$general_created.' '.$general_createdby.' - '.getRelativeTime($general_updated).' + '.$general_updated.' '.$general_actions.' @@ -206,9 +206,9 @@ $view .= ' '.$response['rowID'].' '.$$status_text.' - '.$response['created'].' + '.getRelativeTime($response['created']).' '.$response['createdby'].' - '.$response['updated'].' + '.getRelativeTime($response['updated']).' '.$general_view.' '; diff --git a/settings/settingsmenu.php b/settings/settingsmenu.php index a61ad29..641c394 100644 --- a/settings/settingsmenu.php +++ b/settings/settingsmenu.php @@ -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 diff --git a/settings/settingsviews.php b/settings/settingsviews.php index fce6093..b37c853 100644 --- a/settings/settingsviews.php +++ b/settings/settingsviews.php @@ -62,6 +62,8 @@ $all_views = [ "logfile", "changelog", "language", + "translations", + "translation_manage", "application", "maintenance", "profiles", diff --git a/translation_manage.php b/translation_manage.php new file mode 100644 index 0000000..35dab5c --- /dev/null +++ b/translation_manage.php @@ -0,0 +1,159 @@ + '', + '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 .= '
+ +

'.$success_msg.'

+ +
'; +} + +$view .=' +
+
+

'.($text_variables_h2 ?? '').'

+ '.$button_cancel.' +'; + +if ($delete_allowed === 1){ + $view .= ''; +} +if ($update_allowed === 1){ + $view .= ''; +} + +$view .= '
'; + +$view .= '
+ '.$tab1 .' + '.$tab3.' +
+ '; + +//Define Service and User enabled +$view .= '
+
+ + + + '; + +$view .= '
+
'; + +$view .= '
+
+ + + + + + + + +
+
'; +$view .= '
'; + + +//Output +echo $view; +template_footer() +?> \ No newline at end of file diff --git a/translations.php b/translations.php new file mode 100644 index 0000000..5d8ffb6 --- /dev/null +++ b/translations.php @@ -0,0 +1,160 @@ + +
+ +
+

'.$products_h2.' ('.$query_total.')

+

'.$products_p.'

+
+
+'; + +if (isset($success_msg)){ +$view .= '
+ +

'.$success_msg.'

+ +
'; +} +$view .= ' +
+ '.$button_create_product.' +
+ +
+ '.$general_filters.' +
+ + +
+
+ +
+
+'; + +$view .= ' +
+
+ + + + + + + + + + + + + '; + + if (empty($responses)){ + + $view .= ' + + + '; + } + else { + + var_dump($responses); + foreach ($responses as $response){ + + } + } +$view .= ' + +
'.$product_code.''.$product_category.''.$product_parttype.''.$product_name.''.$general_actions.'
'.$message_no_products.'
+
+
+'; + +$view.=''; +//OUTPUT +echo $view; + +template_footer(); +?> \ No newline at end of file