Skip to content

Commit

Permalink
fix(form_language): limit items with langaues for the form only
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Feb 15, 2021
1 parent 2e530b3 commit d103bb4
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion front/form.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
if ($_SESSION['glpiname'] == 'formcreator_temp_user') {
// Form was saved by an annymous user
unset($_SESSION['glpiname']);
Html::redirect('formdisplay.php?answer_saved');
Html::redirect('formdisplay.php?answer_saved&id=' . $form->getID());
}

// redirect to created item
Expand Down
1 change: 1 addition & 0 deletions front/formdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

// Check if plugin is activated...
if (!(new Plugin())->isActivated('formcreator')) {
PluginFormcreatorForm::header();
Html::displayNotFoundError();
}

Expand Down
6 changes: 3 additions & 3 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ public function post_purgeItem() {
PluginFormcreatorSection::class,
PluginFormcreatorForm_Validator::class,
PluginFormcreatorForm_Profile::class,
pluginFormcreatorForm_Language::class,
];
foreach ($associated as $itemtype) {
$item = new $itemtype();
Expand Down Expand Up @@ -2569,8 +2570,7 @@ public function getTranslatableStrings(array $options = []) : array {
}
foreach ($strings[$type] as $id => $original) {
if ($options['is_translated'] === true && !isset($translations[$original])
|| $options['is_translated'] === false && isset($translations[$original]))
{
|| $options['is_translated'] === false && isset($translations[$original])) {
unset($strings[$type][$id]);
unset($strings['id'][$id]);
}
Expand Down Expand Up @@ -2656,7 +2656,7 @@ public function setTranslations(string $language, array $translations) : bool {
*
* @return string the best language for this form and session context
*/
public function getBestLanguage() {
public function getBestLanguage() {
global $DB;

if ($this->isNewItem()) {
Expand Down
2 changes: 1 addition & 1 deletion inc/form_language.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function showForm($ID, $options = []) {
echo '<tr class="tab_bg_1">';
echo '<td><strong>' . __('Name') . ' <span class="red">*</span></strong></td>';
$used = [];
$rows = $this->find();
$rows = $this->find([PluginFormcreatorForm::getForeignKeyField() => $item->getID()]);
foreach ($rows as $row) {
$used[$row['name']] = $row['name'];
}
Expand Down
3 changes: 0 additions & 3 deletions inc/translatable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ public function getMyTranslatableStrings(array $options) : array {
$id = PluginFormcreatorTranslation::getTranslatableStringId($this->fields[$searchOption['field']]);
if ($options['id'] != '' && $id != $options['id']) {
continue;
}
if (isset($options['is_untranslated']) && $options['is_untranslated']) {

}
$strings[$searchOption['datatype']][$id] = $this->fields[$searchOption['field']];
$strings['id'][$id] = $searchOption['datatype'];
Expand Down
2 changes: 1 addition & 1 deletion inc/translation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static function getDropdownValue($post, $json = true) {

$foundCount = 0;
$data = [];
foreach(['itemlink', 'string', 'text'] as $stringType) {
foreach (['itemlink', 'string', 'text'] as $stringType) {
foreach ($strings[$stringType] as $id => $string) {
$foundCount++;
if ($foundCount < ((int) $post['page'] - 1) * (int) $post['page_limit']) {
Expand Down

0 comments on commit d103bb4

Please sign in to comment.