From e3d2b4e768ef5a1ebc99d8411f040f0ad72db4aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Thu, 9 Jan 2025 14:45:23 +0100 Subject: [PATCH] CMXX - Translations - updates --- api/v2/get/translations.php | 18 ++- api/v2/get/translations_details.php | 118 +++++++++++++++++++ api/v2/post/products.php | 105 +++++++++++++++++ api/v2/post/translations.php | 105 +++++++++++++++++ api/v2/post/translations_details.php | 103 +++++++++++++++++ assets/functions.php | 33 ++++++ maintenance.php | 21 +++- rma.php | 56 --------- rma_manage.php | 55 --------- rmas.php | 59 ---------- settings/settingsviews.php | 1 + translation_manage.php | 164 ++++++++++++++++++++++++--- translations.php | 49 ++++---- 13 files changed, 670 insertions(+), 217 deletions(-) create mode 100644 api/v2/get/translations_details.php create mode 100644 api/v2/post/products.php create mode 100644 api/v2/post/translations.php create mode 100644 api/v2/post/translations_details.php diff --git a/api/v2/get/translations.php b/api/v2/get/translations.php index 1b62ffb..f068a3d 100644 --- a/api/v2/get/translations.php +++ b/api/v2/get/translations.php @@ -43,7 +43,10 @@ if(isset($get_content) && $get_content!=''){ 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] == 'generatefile') { + $clause .= ' AND language_key = :'.$v[0]; + } elseif ($v[0] == 'search') { //build up search $clause .= ' AND variable like :'.$v[0]; @@ -62,7 +65,9 @@ if(isset($get_content) && $get_content!=''){ if(isset($criterias['totals']) && $criterias['totals'] ==''){ //Request for total rows $sql = 'SELECT count(*) as count FROM text_variables '.$whereclause.''; -} +} elseif (isset($criterias['generatefile']) && $criterias['generatefile'] !=''){ + $sql = 'SELECT tv.variable,tvt.translation FROM text_variables tv JOIN text_variables_translations tvt ON tv.rowID = tvt.variable_ID '.$whereclause.''; +} else { //SQL for Paging $sql = 'SELECT * FROM text_variables '.$whereclause.' LIMIT :page,:num_products'; @@ -82,7 +87,7 @@ if (!empty($criterias)){ if ($key == 'search'){ $search_value = '%'.$value.'%'; $stmt->bindValue($key, $search_value, PDO::PARAM_STR); - } + } else { $stmt->bindValue($key, $value, PDO::PARAM_STR); } @@ -95,10 +100,15 @@ if(isset($criterias['totals']) && $criterias['totals']==''){ $stmt->execute(); $messages = $stmt->fetch(); $messages = $messages[0]; +} elseif(isset($criterias['generatefile']) && $criterias['generatefile'] !=''){ + //Excute Query + $stmt->execute(); + //Get results + $messages = $stmt->fetchAll(PDO::FETCH_ASSOC); } 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('page', ($current_page - 1) * $page_rows_translations, PDO::PARAM_INT); $stmt->bindValue('num_products', $page_rows_translations, PDO::PARAM_INT); //Excute Query diff --git a/api/v2/get/translations_details.php b/api/v2/get/translations_details.php new file mode 100644 index 0000000..914e784 --- /dev/null +++ b/api/v2/get/translations_details.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 translation 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_translations '.$whereclause.''; +} +else { + //SQL for Paging + $sql = 'SELECT * FROM text_variables_translations '.$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/api/v2/post/products.php b/api/v2/post/products.php new file mode 100644 index 0000000..6aab0c3 --- /dev/null +++ b/api/v2/post/products.php @@ -0,0 +1,105 @@ +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 = ' AND accounthierarchy like "'.$condition.'"'; + break; +} + +//SET PARAMETERS FOR QUERY +$id = $post_content['rowID'] ?? ''; //check for rowID +$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT +if (isset($post_content['delete'])){$command = 'delete';} //change command to delete +$date = date('Y-m-d H:i:s'); + +//CREATE EMPTY STRINGS +$clause = ''; +$clause_insert =''; +$input_insert = ''; + +//BUILD UP PARTNERHIERARCHY FROM USER +$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); + +//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE +if ($command == 'update'){ + $post_content['updated'] = $date; + $post_content['updatedby'] = $username ; + +} +elseif ($command == 'insert'){ + $post_content['created'] = $date; + $post_content['createdby'] = $username; + $post_content['accounthierarchy'] = $partner_product; +} +else { + //do nothing +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } +} + +//CLEAN UP INPUT +$clause = substr($clause, 2); //Clean clause - remove first comma +$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma +$input_insert = substr($input_insert, 1); //Clean clause - remove first comma + +//QUERY AND VERIFY ALLOWED +if ($command == 'update' && isAllowed('products',$profile,$permission,'U') === 1){ + $sql = 'UPDATE products SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('products',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO products ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('products',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM products WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'products',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/api/v2/post/translations.php b/api/v2/post/translations.php new file mode 100644 index 0000000..924dbfd --- /dev/null +++ b/api/v2/post/translations.php @@ -0,0 +1,105 @@ +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 = ' AND accounthierarchy like "'.$condition.'"'; + break; +} + +//SET PARAMETERS FOR QUERY +$id = $post_content['rowID'] ?? ''; //check for rowID +$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT +if (isset($post_content['delete'])){$command = 'delete';} //change command to delete +$date = date('Y-m-d H:i:s'); + +//CREATE EMPTY STRINGS +$clause = ''; +$clause_insert =''; +$input_insert = ''; + +//BUILD UP PARTNERHIERARCHY FROM USER +$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); + +//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE +if ($command == 'update'){ + $post_content['updatedby'] = $username ; + +} +elseif ($command == 'insert'){ + $post_content['createdby'] = $username; + $post_content['accounthierarchy'] = $partner_product; +} +else { + //do nothing +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } +} + +//CLEAN UP INPUT +$clause = substr($clause, 2); //Clean clause - remove first comma +$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma +$input_insert = substr($input_insert, 1); //Clean clause - remove first comma + +//QUERY AND VERIFY ALLOWED +if ($command == 'update' && isAllowed('translation_manage',$profile,$permission,'U') === 1){ + $sql = 'UPDATE text_variables SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('translation_manage',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO text_variables('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); + // Return ID + echo json_encode(array('rowID'=> $pdo->lastInsertId())); +} +elseif ($command == 'delete' && isAllowed('translation_manage',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM text_variables WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'text_variables',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/api/v2/post/translations_details.php b/api/v2/post/translations_details.php new file mode 100644 index 0000000..84b4bb6 --- /dev/null +++ b/api/v2/post/translations_details.php @@ -0,0 +1,103 @@ +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 = ' AND accounthierarchy like "'.$condition.'"'; + break; +} + +//SET PARAMETERS FOR QUERY +$id = $post_content['rowID'] ?? ''; //check for rowID +$command = ($id == '')? 'insert' : 'update'; //IF rowID = empty then INSERT +if (isset($post_content['delete'])){$command = 'delete';} //change command to delete +$date = date('Y-m-d H:i:s'); + +//CREATE EMPTY STRINGS +$clause = ''; +$clause_insert =''; +$input_insert = ''; + +//BUILD UP PARTNERHIERARCHY FROM USER +$partner_product = json_encode(array("salesid"=>$partner->salesid,"soldto"=>$partner->soldto), JSON_UNESCAPED_UNICODE); + +//ADD STANDARD PARAMETERS TO ARRAY BASED ON INSERT OR UPDATE +if ($command == 'update'){ + $post_content['updatedby'] = $username ; + +} +elseif ($command == 'insert'){ + $post_content['createdby'] = $username; + $post_content['accounthierarchy'] = $partner_product; +} +else { + //do nothing +} + +//CREAT NEW ARRAY AND MAP TO CLAUSE +if(isset($post_content) && $post_content!=''){ + foreach ($post_content as $key => $var){ + if ($key == 'submit' || $key == 'update' || $key == 'add' ||$key == 'rowID'){ + //do nothing + } + else { + $criterias[$key] = $var; + $clause .= ' , '.$key.' = ?'; + $clause_insert .= ' , '.$key.''; + $input_insert .= ', ?'; // ? for each insert item + $execute_input[]= $var; // Build array for input + } + } +} + +//CLEAN UP INPUT +$clause = substr($clause, 2); //Clean clause - remove first comma +$clause_insert = substr($clause_insert, 2); //Clean clause - remove first comma +$input_insert = substr($input_insert, 1); //Clean clause - remove first comma + +//QUERY AND VERIFY ALLOWED +if ($command == 'update' && isAllowed('translation_manage',$profile,$permission,'U') === 1){ + $sql = 'UPDATE text_variables_translations SET '.$clause.' WHERE rowID = ? '.$whereclause.''; + $execute_input[] = $id; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'insert' && isAllowed('translation_manage',$profile,$permission,'C') === 1){ + $sql = 'INSERT INTO text_variables_translations ('.$clause_insert.') VALUES ('.$input_insert.')'; + $stmt = $pdo->prepare($sql); + $stmt->execute($execute_input); +} +elseif ($command == 'delete' && isAllowed('translation_manage',$profile,$permission,'D') === 1){ + $stmt = $pdo->prepare('DELETE FROM text_variables_translations WHERE rowID = ? '.$whereclause.''); + $stmt->execute([ $id ]); + + //Add deletion to changelog + changelog($dbname,'text_variables_translations',$id,'Delete','Delete',$username); +} else +{ + //do nothing +} + +?> \ No newline at end of file diff --git a/assets/functions.php b/assets/functions.php index c2a96ba..18167e9 100644 --- a/assets/functions.php +++ b/assets/functions.php @@ -2913,4 +2913,37 @@ function getRelativeTime($timestamp) { $years = floor($diff / $year); return $years.(($years != 1)?$time_years:$time_year) . " $suffix"; } +} + +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +// Generate language files ++++++++++++++ +// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +function generateLanguageFile($language_key,$token){ + + //GET TRANSLATION RECORDS + $api_url = '/v2/translations/generatefile='.$language_key; + $responses = ioAPIv2($api_url,'',$token); + + if (!empty($responses)){ + //define translation variable + $translation = ''; + //Target dir + $target_dir = dirname(__FILE__,2).'/settings/translations/'; + //Filename + $input_file = $target_dir.'translations_'.strtoupper($language_key).'.php'; + //store translation to the file + file_put_contents($input_file, $translation); + } } \ No newline at end of file diff --git a/maintenance.php b/maintenance.php index 3d18458..f625356 100644 --- a/maintenance.php +++ b/maintenance.php @@ -34,8 +34,9 @@ if ($update_allowed === 1){ if (isset($_POST['updateequipmentmeusurements'])){ storeMeasurementEquipment(''); } - - + if (isset($_POST['generatefile'])){ + generateLanguageFile($_POST['language'],$_SESSION['userkey']); + } } // Handle success messages @@ -67,6 +68,7 @@ $view .=' $view .= '
'; @@ -99,6 +101,21 @@ if ($update_allowed === 1){ '; } + +if ($update_allowed === 1){ + $view .= '| '.($text_variable_translation_languagekey ?? '').' | +'.($text_variable_translation_translation ?? '').' | +'.$general_created.' | +'.$general_actions.' | +||||
|---|---|---|---|---|---|---|---|
| '.($message_no_text_variables ?? '').' | +|||||||
| + | ++ | '.getRelativeTime($translation['created']).' | ++ + + | ||||
'.$products_p.'
+'.($text_variables_p ?? '').'