Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Language in admin stuck to deleted language #6553

Merged
merged 4 commits into from
Jun 29, 2024

Conversation

piloujp
Copy link
Contributor

@piloujp piloujp commented Jun 23, 2024

In Admin pages, when using 2 languages and deleting the one (not default) that you are actually using through languages page, you get stuck in that language.
The language drop down menu is not there anymore and although in languages page there is only the default language English, you can't change back to it...
With this modification, language will change back to default using GET parameter when deleting the language that is actually in use.

This modification allows to change back to default language when deleting the language that is actually in use.
@drbyte
Copy link
Member

drbyte commented Jun 28, 2024

Hmm. Haven't tested it yet.
In reading the code, setting it via the session variable should have been enough, since that's what's checked if no GET param is provided.

@piloujp
Copy link
Contributor Author

piloujp commented Jun 28, 2024

I checked that and changing only $_SESSION['languages_id'] do not change language at all, but if I add $_SESSION['language'] then language changes.
actually looking in language init these 3 session variables are set with a new language object.

$_SESSION['language']
 $_SESSION['languages_id']
 $_SESSION['languages_code']

Replacing $_SESSION['languages_id'] by $_SESSION['language'] did the job!

There are 2 solutions for this PR, updating SESSION variable or just use GET parameter:

      // if we just deleted our currently-selected language, need to switch to default lang:
      $lng = $db->Execute("SELECT languages_id, name, code
                           FROM " . TABLE_LANGUAGES . "
                           WHERE code = '" . zen_db_input(DEFAULT_LANGUAGE) . "'");
      if ((int)$_SESSION['languages_id'] == (int)$_POST['lID']) {
          $_SESSION['language'] = $lng->fields['name'];
          $_SESSION['languages_id'] = $lng->fields['languages_id']; // Without this one we got some log files
          $_SESSION['languages_code'] = $lng->fields['code']; // Not sure this one is necessary, it seems to work without it
      }

      $zco_notifier->notify('NOTIFY_ADMIN_LANGUAGE_DELETE', (int)$lID);

      zen_redirect(zen_href_link(FILENAME_LANGUAGES, 'page=' . $_GET['page']));

Or with GET parameter:

      // if we just deleted our currently-selected language, need to switch to default lang:
      if ((int)$_SESSION['languages_id'] == (int)$_POST['lID']) {
          $getlang = '&language=' . DEFAULT_LANGUAGE;
      } else {
          $getlang = '';
      }

      $zco_notifier->notify('NOTIFY_ADMIN_LANGUAGE_DELETE', (int)$lID);

      zen_redirect(zen_href_link(FILENAME_LANGUAGES, 'page=' . $_GET['page'] . $getlang));

I did few test with these two different codes.
With GET parameter everything seems perfect but with Session variables, when I set back French language (the second language I used for testing) the language drop down menu is set to French but admin is in English. It seems language is not completly reinitialized. I could not find any other problem but it does not fell good...
The GET solution seems safer to me.

Uses only GET parameter to change language as it is done when user choose a new language.
@piloujp
Copy link
Contributor Author

piloujp commented Jun 29, 2024

I updated the PR to use GET parameter only.
Using Session variables does not initiate language completely, as you can see in init_languages.php code. Language directory is not reset and notifier for language change is not fired, making it useless for any plugin.

@drbyte
Copy link
Member

drbyte commented Jun 29, 2024

Thank you for investigating this!

@drbyte drbyte merged commit 9570636 into zencart:master Jun 29, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants