CMXX - Translations, Service report improvements and API security

This commit is contained in:
“VeLiTi”
2025-03-25 15:41:53 +01:00
parent 12abe8cb8a
commit 6fd22ede84
7 changed files with 451 additions and 123 deletions

View File

@@ -1317,10 +1317,44 @@ function serviceReport($history, $request, $country_code)
$maintenance_test = $stmt->fetch();
$test_fail = $maintenance_test['description'];
$maintenance_test = json_decode($maintenance_test['description']);
function combineAndSortKeys($object) {
// Convert object properties to arrays if needed
$key1 = (array)($object->doubletestvalues ?? []);
$key2 = (array)($object->stringtestvalues ?? []);
$key3 = (array)($object->booleantestvalues ?? []);
// Combine all rows
$combined = array_merge($key1, $key2, $key3);
// Group rows based on the "pass" boolean
$grouped = [
'failed' => [],
'passed' => []
];
foreach ($combined as $row) {
// Check if $row is an object and convert if needed
if (is_object($row)) {
$row = (array)$row;
}
if (isset($row['pass']) && $row['pass'] === true) {
$grouped['passed'][] = $row;
} else {
$grouped['failed'][] = $row;
}
}
return $grouped;
}
//check if maintenance test has false test and update renewal date
// Example usage:
$sortedTestResults = combineAndSortKeys($maintenance_test);
//check if maintenance test has false test and update renewal date
if (str_contains($test_fail, "false")){
$service_renewal_date = $service_report_outcome_attention; ;
$service_renewal_date = $service_report_outcome_attention;
}
}
@@ -1340,6 +1374,10 @@ function serviceReport($history, $request, $country_code)
font-size: 18px;
line-height: 1.5;
}
table > thead:first-of-type > tr:last-child {
page-break-after: avoid;
}
.servicereport {
border-collapse: collapse;
@@ -1544,8 +1582,16 @@ function serviceReport($history, $request, $country_code)
</tbody>
</table>
<div id="service_summary" class="service_summary">
<div class="service_summary__title">'.$summary_label1.'</div>
<ul>
<table width="100%">
<thead>
<tr>
<td class="service_summary__title">'.$summary_label1.'</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<ul>
';
$actions = 0;
@@ -1573,11 +1619,24 @@ function serviceReport($history, $request, $country_code)
}
}
if ($actions == 0) {$servicereport .= '<li>'.$message1.'</li>';}
//CLOSE summary table and OPENGROUP_HEADER 8 table
$servicereport .= '
</ul>
<div class="service_summary__title">'.$group_header_8.'</div>
<ul>
</ul>
</td>
</tr>
</tbody>
</table>
<table width="100%">
<thead>
<tr>
<td class="service_summary__title">'.$group_header_8.'</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<ul>
';
if (str_contains($history->description, "service_mandatory_question")) {
foreach ($json_array->final as $final) {
@@ -1616,9 +1675,17 @@ function serviceReport($history, $request, $country_code)
}
if ($repairs == 0) {$servicereport .= '<li>' . $message2 . '</li>';}
$servicereport .='</ul>';
//CLOSE GROUP_HEADER 8 table
$servicereport .='
</ul>
</td>
</tr>
</tbody>
</table>';
if (str_contains($history->description, "service_mandatory_question")) {
//GET NOTES from JSON
//GET NOTES from JSON
$notes ='';
foreach ($json_array->final as $final){
if ($final->id == "service_notes"){
@@ -1626,12 +1693,24 @@ function serviceReport($history, $request, $country_code)
}
}
//GENERATE NOTES SECTION
$servicereport .='
<div class="service_summary__title">'.$group_header_7.'</div>';
<table width="100%">
<thead>
<tr>
<td class="service_summary__title">'.$group_header_7.'</td>
</tr>
</thead>
<tbody>';
if ($notes != '') {
$servicereport .= '<div id="service_notes" class="service_notes">'.$notes.'</div>';
} else {
$servicereport .= '<div id="service_notes" class="service_notes">'.$service_report_no_comments.'</div>'; }
$servicereport .= '<tr><td id="service_notes" class="service_notes">'.$notes.'</td></tr>';
}
else {
$servicereport .= '<tr><td id="service_notes" class="service_notes">'.$service_report_no_comments.'</td></tr>';
}
$servicereport .='</tbody>
</table> ';
}
$servicereport .= '</div>';
@@ -1652,82 +1731,28 @@ function serviceReport($history, $request, $country_code)
<td class="col-value text-center">'.$service_report_maintenance_test_status.'</td>
</tr>
</thead>
';
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check for measurements ++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Check if false test found +++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++
$servicereport .= '<tbody>';
<tbody>';
//Check double test values
foreach($maintenance_test->doubletestvalues as $key => $value)
//SHOW FAILED VALUES
foreach($sortedTestResults['failed'] as $key => $value)
{
//If test is not passed or not
if($value->pass == false){
$text = $service_maintenance_test_fail;
$style = 'error';
}
else
{
$text = $service_maintenance_test_pass;
$style = 'success';
}
$servicereport .='
<tr>
<td class="col-key">'.$value->name.'</td>
<td class="col-value text-center '.$style.'">'.$text.'</td>
</tr>
$servicereport .='
<tr>
<td class="col-key">'.$value['name'].'</td>
<td class="col-value text-center error">'.$service_maintenance_test_fail.'</td>
</tr>
';
}
//Check string test values
foreach($maintenance_test->stringtestvalues as $key => $value)
{
//If test is not passed or not
if($value->pass == false){
$text = $service_maintenance_test_fail;
$style = 'error';
}
else
{
$text = $service_maintenance_test_pass;
$style = 'success';
}
$servicereport .='
<tr>
<td class="col-key">'.$value->name.'</td>
<td class="col-value text-center '.$style.'">'.$text.'</td>
</tr>
';
}
//Check boolean test values
foreach($maintenance_test->booleantestvalues as $key => $value)
{
//If test is not passed or not
if($value->pass == false){
$text = $service_maintenance_test_fail;
$style = 'error';
}
else
{
$text = $service_maintenance_test_pass;
$style = 'success';
}
$servicereport .='
<tr>
<td class="col-key">'.$value->name.'</td>
<td class="col-value text-center '.$style.'">'.$text.'</td>
</tr>
';
}
//SHOW PASSED VALUES
foreach($sortedTestResults['passed'] as $key => $value)
{
$servicereport .='
<tr>
<td class="col-key">'.$value['name'].'</td>
<td class="col-value text-center success">'.$service_maintenance_test_pass.'</td>
</tr>
';
}
$servicereport .= '
</tbody>
</table>
@@ -1834,6 +1859,7 @@ function serviceReport($history, $request, $country_code)
//++++++++++++++++++++++++++++++++++++++++++++++
//Legacy Code
//++++++++++++++++++++++++++++++++++++++++++++++
if (isset($json_array->question25) && isset($json_array->newHistory)) {
$servicereport .= '