mirror of
https://github.com/alextselegidis/easyappointments.git
synced 2024-11-24 17:03:27 +03:00
Move the change language operation into a new public controller (#1210)
This commit is contained in:
parent
0100d0bd63
commit
1cf4f5246f
3 changed files with 78 additions and 47 deletions
|
@ -1513,52 +1513,6 @@ class Backend_api extends EA_Controller {
|
|||
->set_output(json_encode($response));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change system language for current user.
|
||||
*
|
||||
* The language setting is stored in session data and retrieved every time the user visits any of the system pages.
|
||||
*/
|
||||
public function ajax_change_language()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if language exists in the available languages.
|
||||
$found = FALSE;
|
||||
|
||||
foreach (config('available_languages') as $lang)
|
||||
{
|
||||
if ($lang == $this->input->post('language'))
|
||||
{
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found)
|
||||
{
|
||||
throw new Exception('Translations for the given language does not exist (' . $this->input->post('language') . ').');
|
||||
}
|
||||
|
||||
$this->session->set_userdata('language', $this->input->post('language'));
|
||||
$this->config->set_item('language', $this->input->post('language'));
|
||||
|
||||
$response = AJAX_SUCCESS;
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->output->set_status_header(500);
|
||||
|
||||
$response = [
|
||||
'message' => $exception->getMessage(),
|
||||
'trace' => config('debug') ? $exception->getTrace() : []
|
||||
];
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($response));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method will return a list of the available google calendars.
|
||||
*
|
||||
|
|
77
application/controllers/Localization.php
Normal file
77
application/controllers/Localization.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Easy!Appointments - Open Source Web Scheduler
|
||||
*
|
||||
* @package EasyAppointments
|
||||
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||
* @copyright Copyright (c) 2013 - 2020, Alex Tselegidis
|
||||
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||
* @link https://easyappointments.org
|
||||
* @since v1.4.3
|
||||
* ---------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Localization Controller
|
||||
*
|
||||
* Contains all the location related methods.
|
||||
*
|
||||
* @package Controllers
|
||||
*/
|
||||
class Localization extends EA_Controller {
|
||||
/**
|
||||
* Change system language for current user.
|
||||
*
|
||||
* The language setting is stored in session data and retrieved every time the user visits any of the system pages.
|
||||
*
|
||||
* Notice: This method used to be in the Backend_api.php.
|
||||
*/
|
||||
public function ajax_change_language()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Check if language exists in the available languages.
|
||||
$found = FALSE;
|
||||
|
||||
$language = $this->input->post('language');
|
||||
|
||||
if (empty($language))
|
||||
{
|
||||
throw new Exception('No language provided.');
|
||||
}
|
||||
|
||||
foreach (config('available_languages') as $available_language)
|
||||
{
|
||||
if ($available_language === $language)
|
||||
{
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found)
|
||||
{
|
||||
throw new Exception('The translations for the provided language do not exist: ' . $language);
|
||||
}
|
||||
|
||||
$this->session->set_userdata('language', $language);
|
||||
|
||||
$this->config->set_item('language', $language);
|
||||
|
||||
$response = AJAX_SUCCESS;
|
||||
}
|
||||
catch (Exception $exception)
|
||||
{
|
||||
$this->output->set_status_header(500);
|
||||
|
||||
$response = [
|
||||
'message' => $exception->getMessage(),
|
||||
'trace' => config('debug') ? $exception->getTrace() : []
|
||||
];
|
||||
}
|
||||
|
||||
$this->output
|
||||
->set_content_type('application/json')
|
||||
->set_output(json_encode($response));
|
||||
}
|
||||
}
|
|
@ -287,7 +287,7 @@ window.GeneralFunctions = window.GeneralFunctions || {};
|
|||
|
||||
$(document).on('click', 'li.language', function () {
|
||||
// Change language with ajax call and refresh page.
|
||||
var url = GlobalVariables.baseUrl + '/index.php/backend_api/ajax_change_language';
|
||||
var url = GlobalVariables.baseUrl + '/index.php/localization/ajax_change_language';
|
||||
|
||||
var data = {
|
||||
csrfToken: GlobalVariables.csrfToken,
|
||||
|
|
Loading…
Reference in a new issue