Skip to content

Commit a34a325

Browse files
committed
Merge remote-tracking branch 'origin/support/2.13.0' into support/2.14.0
2 parents 8d01aa6 + 3cc58ac commit a34a325

7 files changed

Lines changed: 52 additions & 13 deletions

inc/abstractitiltarget.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ protected function showOLASettings() {
983983

984984
protected function showCategorySettings($rand) {
985985
echo '<tr>';
986-
echo '<td width="15%">' . PluginFormcreatorCategory::getTypeName(1) . '</td>';
986+
echo '<td width="15%">' . ITILCategory::getTypeName(1) . '</td>';
987987
echo '<td width="25%">';
988988
Dropdown::showFromArray(
989989
'category_rule',

inc/form.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,16 @@ public function setTranslations(string $language, array $translations) : bool {
24562456
return false;
24572457
}
24582458

2459+
// CLeanup obsolete strings
2460+
$existing_strings = $this->getTranslatableStrings();
2461+
foreach (array_keys($translations) as $original) {
2462+
if (!in_array($original, $existing_strings['itemlink'])
2463+
&& !in_array($original, $existing_strings['string'])
2464+
&& !in_array($original, $existing_strings['text'])) {
2465+
unset($translations[$original]);
2466+
}
2467+
}
2468+
24592469
$output = "<?php" . PHP_EOL . "return " . var_export($translations, true) . ";";
24602470
$written = file_put_contents(
24612471
$file,

inc/form_language.class.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ public function defineTabs($options = []) {
6464

6565
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
6666
if ($item instanceof PluginFormcreatorForm) {
67-
return self::getTypeName(Session::getPluralNumber());
67+
$nb = (new DbUtils())->countElementsInTable(self::getTable(), [
68+
'plugin_formcreator_forms_id' => $item->getID(),
69+
]);
70+
return self::createTabEntry(
71+
self::getTypeName(Session::getPluralNumber()),
72+
$nb
73+
);
6874
}
6975
if ($item->getType() == self::class) {
7076
$nb = 0;
@@ -350,9 +356,18 @@ public function showTranslations($options = []) {
350356
echo $header;
351357
echo '</thead>';
352358

359+
$all_translated_strings = $form->getTranslatableStrings([
360+
'translated' => true,
361+
'language' => $this->fields['name']
362+
]);
363+
353364
echo '<tbody>';
354365
foreach ($translations as $original => $translated) {
355366
$id = PluginFormcreatorTranslation::getTranslatableStringId($original);
367+
if (!in_array($id, array_keys($all_translated_strings['id']))) {
368+
// String is translated but no longer used in the form or its sub objects
369+
continue;
370+
}
356371
echo '<tr data-itemtype="PluginFormcreatorTranslation" data-id="' . $id . '">';
357372
echo '<td>'
358373
. Html::getCheckbox([

inc/issue.class.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,16 @@ public function rawSearchOptions() {
507507

508508
$tab = [];
509509
$hide_technician = false;
510+
$hide_technician_group = false;
510511
if (!Session::isCron()) {
511-
$hide_technician = \Entity::getUsedConfig(
512-
'anonymize_support_agents',
513-
Session::getActiveEntity()
514-
);
512+
$user = new User();
513+
if (empty($user->getAnonymizedName(Session::getActiveEntity()))) {
514+
$hide_technician = true;
515+
}
516+
$group = new Group();
517+
if (empty($group->getAnonymizedName(Session::getActiveEntity()))) {
518+
$hide_technician_group = true;
519+
}
515520
}
516521

517522
$tab[] = [
@@ -763,8 +768,8 @@ public function rawSearchOptions() {
763768
'datatype' => 'dropdown',
764769
'forcegroupby' => true,
765770
'massiveaction' => false,
766-
'nodisplay' => $hide_technician,
767-
'nosearch' => $hide_technician,
771+
'nodisplay' => $hide_technician_group,
772+
'nosearch' => $hide_technician_group,
768773
'condition' => ['is_assign' => 1],
769774
'joinparams' => [
770775
'beforejoin' => [

inc/restrictedformcriteria.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public static function import(
199199
sprintf(
200200
__('Failed to add or update the %1$s %2$s', 'formceator'),
201201
$type_name,
202-
$input['name']
202+
$input[$item2_input_key]
203203
)
204204
);
205205
}

inc/translation.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static function getEditorFieldsHtml(PluginFormcreatorForm_Language $formL
161161
if (!isset($translatableString['id'][$id])) {
162162
// Show nothing if string definitively not found
163163
// Should not happen
164-
return '';
164+
return '<td colspan="2">' . __('Iternal error : translatable string not found.', 'formcreator') . '</td>';;
165165
}
166166

167167
$type = $translatableString['id'][$id] ?? 'string';
@@ -174,12 +174,12 @@ public static function getEditorFieldsHtml(PluginFormcreatorForm_Language $formL
174174
switch ($type) {
175175
case 'itemlink':
176176
case 'string':
177-
$out .= '<td>' . $original . Html::hidden("id", ['value' => $id]) . '</td>';
177+
$out .= '<td width="50%">' . $original . Html::hidden("id", ['value' => $id]) . '</td>';
178178
$out .= '<td>' . Html::input("value", ['value' => $translatedString]) . '</td>';
179179
break;
180180

181181
case 'text':
182-
$out .= '<td>' . Html::entity_decode_deep($original) . Html::hidden("id", ['value' => $id]) . '</td>';
182+
$out .= '<td width="50%">' . Html::entity_decode_deep($original) . Html::hidden("id", ['value' => $id]) . '</td>';
183183
$out .= '<td>' . Html::textarea([
184184
'name' => "value",
185185
'value' => $translatedString,
@@ -228,7 +228,9 @@ public function add(array $input) : bool {
228228
$type = $translatableStrings['id'][$input['id']];
229229
$original = $translatableStrings[$type][$input['id']];
230230

231-
$translations[$original] = Toolbox::stripslashes_deep($input['value']);
231+
$input['value'] = Sanitizer::unsanitize($input['value']);
232+
$input['value'] = str_replace('\r\n', '', $input['value']);
233+
$translations[$original] = Sanitizer::sanitize($input['value'], false);
232234

233235
if (!$form->setTranslations($formLanguage->fields['name'], $translations)) {
234236
Session::addMessageAfterRedirect(__('Failed to add the translation.', 'formcreator'), false, ERROR);

js/scripts.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ var plugin_formcreator = new function() {
11971197
var translationId = $(element.closest('[data-itemtype="PluginFormcreatorTranslation"]')).attr('data-id');
11981198
var modal;
11991199
modal = glpi_ajax_dialog({
1200+
dialogclass: 'modal-xl',
12001201
url: '../ajax/form_language.php',
12011202
params: {
12021203
action: 'translation',
@@ -1205,6 +1206,12 @@ var plugin_formcreator = new function() {
12051206
},
12061207
title: i18n.textdomain('formcreator').__('Update a translation', 'formcreator'),
12071208
close: function () {
1209+
// Remove unclosed TinyMCE toolbar
1210+
var tinyToolbar = document.querySelector('.tox-tinymce-aux');
1211+
if (tinyToolbar) {
1212+
tinyToolbar.parentNode.removeChild(tinyToolbar);
1213+
}
1214+
// Reload the tab
12081215
reloadTab();
12091216
},
12101217
fail: function () {

0 commit comments

Comments
 (0)