public function updateLanguage() { if ($this->template->is_ajax()) { $lang = $this->input->post('language'); if ($this->isDemo()) { echo json_encode(['success' => false, 'message' => lang('language_demo_error')]); } else { if ($this->c_user) { if (User_language::set_user_language($this->c_user->id, $lang)) { $this->session->set_userdata('language', $lang); echo json_encode(['success' => true, 'message' => lang('language_success')]); } else { echo json_encode(['success' => false, 'message' => lang('language_error')]); } } else { $this->session->set_userdata('language', $lang); echo json_encode(['success' => true, 'message' => lang('language_success')]); } } } }
/** * @param null|string $website_part */ public function __construct($website_part = null) { parent::__construct(); $this->demoConfigName = 'demo_settings'; //Load config file only for demo $this->config->load($this->demoConfigName, true, true); $this->disableConfigChanges = (bool) $this->config->item('disable_config_changes', $this->demoConfigName); $this->config->load('languages'); if (!$this->language) { $this->language = $this->config->config['language']; } $this->c_user = $this->getUser(); $this->load->library('session'); if (!$this->isDemo()) { if ($this->c_user) { $lang = User_language::get_user_language($this->c_user->id, $this->session->userdata('language')); } else { $lang = $this->session->userdata('language'); if (!$lang) { $lang = 'en'; } } } else { $lang = 'en'; } $this->language = $this->config->config['languages'][$lang]; $this->language_small = $lang; $this->session->set_userdata('language', $lang); $this->template->set('default_language', $this->language); $this->template->set('available_languages', $this->config->config['languages']); $this->load->helper('my_language_helper'); $this->load->helper('language'); $this->lang->load('global', $this->language); JsSettings::instance()->add(['i18n' => $this->lang->load('global', $this->language)]); /** * Payments enabled block (send var to layout - used for changing 'Register link') */ $this->paymentsEnabled = $this->get('core.status.system')->isPaymentEnabled(); $this->trialEnabled = $this->get('core.status.system')->isTrialEnabled(); if ($this->router->fetch_method() !== 'updateLanguage') { // AUTO LOGIN START $noAuth = $this->config->item('no_auth', $this->demoConfigName); if ($noAuth !== false) { $this->autoLoginUser(); } // AUTO LOGIN END if (!$this->ion_auth->logged_in() && $this->router->fetch_class() !== 'auth' && $this->router->fetch_class() !== 'payment' && $this->router->fetch_class() !== 'subscript') { redirect('auth'); } if ($this->ion_auth->logged_in() && $this->router->fetch_class() !== 'auth' && $this->router->fetch_method() !== 'logout') { if (!$this->c_user) { $message = $this->ion_auth->is_collaborator() ? 'Your major user account is inactive' : 'Authentication error'; $this->ion_auth->logout(); $this->addFlash($message); redirect('auth'); } $this->c_user->user_name = $this->c_user->first_name . ' ' . $this->c_user->last_name; if ($dropdownManagerUsers = $this->ion_auth->checkManagerCodeActuality()) { $this->template->set('dropdownManagerUsers', $dropdownManagerUsers); $this->template->set('currentId', $this->c_user->id); CssJs::getInst()->add_js(array('controller/manager/manager_header.js')); } if ($this->ion_auth->is_manager()) { if ($this->router->fetch_directory() !== 'manager/') { redirect('manager'); } } elseif ($this->ion_auth->is_admin()) { if (!$this->ion_auth->is_superadmin() && $this->router->fetch_class() == 'manage_admins') { redirect('admin'); } if ($this->router->fetch_directory() !== 'admin/') { redirect('admin'); } } else { if ($this->router->fetch_directory() === 'admin/') { redirect('/'); } if ($this->router->fetch_directory() === 'manager/' && !$dropdownManagerUsers) { redirect('/'); } $activeProfile = $this->c_user->social_group->getActive($this->c_user->id); if ($activeProfile) { $this->profile = $activeProfile; $this->template->set('active_profile', $this->profile); $this->template->set('profiles', $this->c_user->social_group->get()); } elseif ($this->router->fetch_class() !== 'profiles' && $this->router->fetch_directory() !== 'settings') { $this->addFlash('Please select active profile or add it.'); redirect('/settings/profiles'); } /** * Redirect to subscriptions plans if user not have active payment */ if ($this->paymentsEnabled && !$this->ion_auth->is_admin() && !$this->ion_auth->is_manager() && !$this->ion_auth->getManagerCode()) { $this->checkActiveSubscription($this->c_user->id); } if (isset($website_part)) { $this->website_part = $website_part; } $this->template->set('website_part', $this->website_part); } } $this->template->set('c_user', $this->c_user); $need_info = false; if ($this->router->fetch_directory() == 'settings/' && $this->c_user->social_group->count() > 1) { $availableProfilesCount = $this->getAAC()->getPlanFeatureValue('profiles_count'); if ($availableProfilesCount || $availableProfilesCount != 1) { $need_info = true; } } $this->template->set('need_info', $need_info); //for demo site $this->configChangePermissionsCheck(); $this->bitly_load(); } $this->template->set('breadcrumbs', true); $this->template->layout = 'layouts/customer'; if ('settings' == $this->website_part) { $this->template->layout = 'layouts/customer_settings'; } $this->piwik_load(); }