From c8ea174030895a148929468bcc183ab5565fbfe9 Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 2 Aug 2023 06:34:12 +0000 Subject: [PATCH 1/4] Implemented Userlanguages with a lot of help from @AndreasK79 --- application/config/config.sample.php | 57 ++++++++- application/config/migration.php | 2 +- application/controllers/User.php | 89 +++++++++---- .../migrations/133_add_user_language.php | 29 +++++ application/models/User_model.php | 21 ++-- application/views/maintenance/main.php | 117 +++++++++++------- application/views/user/edit.php | 21 +++- 7 files changed, 250 insertions(+), 86 deletions(-) create mode 100644 application/migrations/133_add_user_language.php diff --git a/application/config/config.sample.php b/application/config/config.sample.php index 081a62e8..06b0f77c 100644 --- a/application/config/config.sample.php +++ b/application/config/config.sample.php @@ -151,9 +151,62 @@ $config['url_suffix'] = ''; | there is an available translation if you intend to use something other | than english. | -*/ -$config['language'] = 'english'; + */ +$lang = 'english'; // this language will be used per default +if (isset($_COOKIE["language"])) { + $tmp_value = $_COOKIE["language"]; + if (!empty($tmp_value)) { $lang = $tmp_value; } +} +switch ($lang) { // do this for security-reasons! parse only langs, which are known to us +case 'dutch': + $config['language'] = $lang; + break; +case 'chinese_simplified': + $config['language'] = $lang; + break; +case 'spanish': + $config['language'] = $lang; + break; +case 'czech': + $config['language'] = $lang; + break; +case 'bulgarian': + $config['language'] = $lang; + break; +case 'turkish': + $config['language'] = $lang; + break; +case 'swedish': + $config['language'] = $lang; + break; +case 'polish': + $config['language'] = $lang; + break; +case 'italian': + $config['language'] = $lang; + break; +case 'greek': + $config['language'] = $lang; + break; +case 'french': + $config['language'] = $lang; + break; +case 'finnish': + $config['language'] = $lang; + break; +case 'russian': + $config['language'] = $lang; + break; +case 'english': + $config['language'] = $lang; + break; +case 'german': + $config['language'] = $lang; + break; +} + +$config['cl_multilanguage']=true; /* |-------------------------------------------------------------------------- | Default Character Set diff --git a/application/config/migration.php b/application/config/migration.php index 688dfffe..6a1ed952 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 132; +$config['migration_version'] = 133; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/User.php b/application/controllers/User.php index e713146c..41cda39f 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -7,12 +7,12 @@ class User extends CI_Controller { parent::__construct(); // Load language files - $this->lang->load(array( - 'account', - 'lotw', - 'eqsl', - 'admin', - )); + // $this->lang->load(array( + // 'account', + // 'lotw', + // 'eqsl', + // 'admin', + // )); } public function index() @@ -90,6 +90,7 @@ class User extends CI_Controller { $data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_gridmap_default_band'] = $this->input->post('user_gridmap_default_band'); $data['user_gridmap_confirmation'] = ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''); + $data['language'] = $this->input->post('language'); $this->load->view('user/add', $data); } else { $this->load->view('user/add', $data); @@ -125,6 +126,7 @@ class User extends CI_Controller { $this->input->post('user_amsat_status_upload'), $this->input->post('user_mastodon_url'), $this->input->post('user_gridmap_default_band'), + $this->input->post('language'), ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''))) { // Check for errors case EUSERNAMEEXISTS: @@ -171,16 +173,35 @@ class User extends CI_Controller { $data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_gridmap_default_band'] = $this->input->post('user_gridmap_default_band'); $data['user_gridmap_confirmation'] = ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''); + $data['language'] = $this->input->post('language'); $this->load->view('user/add', $data); $this->load->view('interface_assets/footer'); } } + function find() { + $existing_langs = array(); + $lang_path = APPPATH.'language'; + + $results = scandir($lang_path); + + foreach ($results as $result) { + if ($result === '.' or $result === '..') continue; + + if (is_dir(APPPATH.'language' . '/' . $result)) { + $dirs[] = $result; + } + } + return $dirs; + } + function edit() { $this->load->model('user_model'); if ( ($this->session->userdata('user_id') == '') || ((!$this->user_model->authorize(99)) && ($this->session->userdata('user_id') != $this->uri->segment(3))) ) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->user_model->get_by_id($this->uri->segment(3)); + $data['existing_languages'] = $this->find(); + $this->load->model('bands'); $this->load->library('form_validation'); @@ -208,7 +229,6 @@ class User extends CI_Controller { { $data['page_title'] = "Edit User"; - $this->load->view('interface_assets/header', $data); $q = $query->row(); $data['id'] = $q->user_id; @@ -327,6 +347,13 @@ class User extends CI_Controller { $data['user_date_format'] = $q->user_date_format; } + if($this->input->post('language')) { + $data['language'] = $this->input->post('language', true); + } else { + $data['language'] = $q->language; + } + + if($this->input->post('user_stylesheet')) { $data['user_stylesheet'] = $this->input->post('user_stylesheet', true); } else { @@ -429,11 +456,10 @@ class User extends CI_Controller { $data['user_column5'] = $q->user_column5; } + $this->load->view('interface_assets/header', $data); $this->load->view('user/edit', $data); $this->load->view('interface_assets/footer'); - } - else - { + } else { unset($data); switch($this->user_model->edit($this->input->post())) { // Check for errors @@ -448,6 +474,17 @@ class User extends CI_Controller { break; // All okay, return to user screen case OK: + if ($this->session->userdata('user_id') == $this->uri->segment(3)) { // Editing own User? Set cookie! + $cookie= array( + + 'name' => 'language', + 'value' => $this->input->post('language', true), + 'expire' => time()+1000 + // 'secure' => TRUE + + ); + $this->input->set_cookie($cookie); + } if($this->session->userdata('user_id') == $this->input->post('id', true)) { $this->session->set_flashdata('success', 'User '.$this->input->post('user_name', true).' edited'); redirect('user/edit/'.$this->uri->segment(3)); @@ -487,6 +524,7 @@ class User extends CI_Controller { $data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_gridmap_default_band'] = $this->input->post('user_gridmap_default_band'); $data['user_gridmap_confirmation'] = ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''); + $data['language'] = $this->input->post('language'); $this->load->view('user/edit'); $this->load->view('interface_assets/footer'); } @@ -557,19 +595,26 @@ class User extends CI_Controller { $data['user'] = $query->row(); - if ($this->form_validation->run() == FALSE) - { + + if ($this->form_validation->run() == FALSE) { $data['page_title'] = "Login"; $this->load->view('interface_assets/mini_header', $data); $this->load->view('user/login'); $this->load->view('interface_assets/footer'); - } - else - { + } else { if($this->user_model->login() == 1) { $this->session->set_flashdata('notice', 'User logged in'); $this->user_model->update_session($data['user']->user_id); + $cookie= array( + + 'name' => 'language', + 'value' => $data['user']->language, + 'expire' => '9999', + 'secure' => TRUE + + ); + $this->input->set_cookie($cookie); redirect('dashboard'); } else { $this->session->set_flashdata('error', 'Incorrect username or password!'); @@ -591,9 +636,9 @@ class User extends CI_Controller { /** * Function: forgot_password - * + * * Allows users to input an email address and a password will be sent to that address. - * + * */ function forgot_password() { @@ -614,7 +659,7 @@ class User extends CI_Controller { { // Check email address exists $this->load->model('user_model'); - + $check_email = $this->user_model->check_email_address($this->input->post('email', true)); if($check_email == TRUE) { @@ -623,7 +668,7 @@ class User extends CI_Controller { $reset_code = random_string('alnum', 50); $this->user_model->set_password_reset_code($this->input->post('email', true), $reset_code); - + // Send email with reset code $this->data['reset_code'] = $reset_code; @@ -676,10 +721,10 @@ class User extends CI_Controller { $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); - + $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required|matches[password]'); - + if ($this->form_validation->run() == FALSE) { $data['page_title'] = "Reset Password"; @@ -691,7 +736,7 @@ class User extends CI_Controller { { // Lets reset the password! $this->load->model('user_model'); - + $this->user_model->reset_password($this->input->post('password', true), $reset_code); $this->session->set_flashdata('notice', 'Password Reset.'); redirect('user/login'); diff --git a/application/migrations/133_add_user_language.php b/application/migrations/133_add_user_language.php new file mode 100644 index 00000000..2e5c7609 --- /dev/null +++ b/application/migrations/133_add_user_language.php @@ -0,0 +1,29 @@ +db->field_exists('language', 'users')) { + $fields = array( + 'language varchar(32) default "english"', + ); + + $this->dbforge->add_column('users', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('language', 'users')) { + $this->dbforge->drop_column('users', 'language'); + } + } +} diff --git a/application/models/User_model.php b/application/models/User_model.php index dc9eff52..b1f1511d 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -57,9 +57,9 @@ class User_Model extends CI_Model { /* * Function: check_email_address - * + * * Checks if an email address is already in use - * + * * @param string $email */ function check_email_address($email) { @@ -68,7 +68,7 @@ class User_Model extends CI_Model { $this->db->where('user_email', $clean_email); $query = $this->db->get($this->config->item('auth_table')); - + if ($query->num_rows() > 0) { return true; } else { @@ -80,7 +80,7 @@ class User_Model extends CI_Model { $this->db->where('station_id', $station_id); $this->db->join('station_profile', 'station_profile.user_id = '.$this->config->item('auth_table').'.user_id'); $query = $this->db->get($this->config->item('auth_table')); - + $ret = $query->row(); return $ret->user_email; } @@ -124,7 +124,7 @@ class User_Model extends CI_Model { $measurement, $user_date_format, $user_stylesheet, $user_qth_lookup, $user_sota_lookup, $user_wwff_lookup, $user_pota_lookup, $user_show_notes, $user_column1, $user_column2, $user_column3, $user_column4, $user_column5, $user_show_profile_image, $user_previous_qsl_type, $user_amsat_status_upload, $user_mastodon_url, - $user_gridmap_default_band, $user_gridmap_confirmation) { + $user_gridmap_default_band, $user_gridmap_confirmation, $language) { // Check that the user isn't already used if(!$this->exists($username)) { $data = array( @@ -156,6 +156,7 @@ class User_Model extends CI_Model { 'user_mastodon_url' => xss_clean($user_mastodon_url), 'user_gridmap_default_band' => xss_clean($user_gridmap_default_band), 'user_gridmap_confirmation' => xss_clean($user_gridmap_confirmation), + 'language' => xss_clean($language), ); // Check the password is valid @@ -215,6 +216,7 @@ class User_Model extends CI_Model { 'user_mastodon_url' => xss_clean($fields['user_mastodon_url']), 'user_gridmap_default_band' => xss_clean($fields['user_gridmap_default_band']), 'user_gridmap_confirmation' => (isset($fields['user_gridmap_confirmation_qsl']) ? 'Q' : '').(isset($fields['user_gridmap_confirmation_lotw']) ? 'L' : '').(isset($fields['user_gridmap_confirmation_eqsl']) ? 'E' : ''), + 'language' => xss_clean($fields['language']), ); // Check to see if the user is allowed to change user levels @@ -339,6 +341,7 @@ class User_Model extends CI_Model { 'user_gridmap_default_band' => $u->row()->user_gridmap_default_band, 'user_gridmap_confirmation' => $u->row()->user_gridmap_confirmation, 'active_station_logbook' => $u->row()->active_station_logbook, + 'language' => isset($u->row()->language) ? $u->row()->language: 'english', ); $this->session->set_userdata($userdata); @@ -439,7 +442,7 @@ class User_Model extends CI_Model { * * Stores generated password reset code in the database and sets the date to exactly * when the sql query runs. - * + * * @param string $user_email * @return string $reset_code */ @@ -448,7 +451,7 @@ class User_Model extends CI_Model { 'reset_password_code' => $reset_code, 'reset_password_date' => date('Y-m-d H:i:s') ); - + $this->db->where('user_email', $user_email); $this->db->update('users', $data); } @@ -457,7 +460,7 @@ class User_Model extends CI_Model { * FUNCTION: reset_password * * Sets new password for users account where the reset code matches then clears the password reset code and password reset date. - * + * * @param string $password * @return string $reset_code */ @@ -467,7 +470,7 @@ class User_Model extends CI_Model { 'reset_password_code' => NULL, 'reset_password_date' => NULL ); - + $this->db->where('reset_password_code', $reset_code); $this->db->update('users', $data); } diff --git a/application/views/maintenance/main.php b/application/views/maintenance/main.php index bcc2b22a..354cc2b4 100644 --- a/application/views/maintenance/main.php +++ b/application/views/maintenance/main.php @@ -1,57 +1,78 @@
-
- session->flashdata('message')) { ?> - -
-

session->flashdata('message'); ?>

-
- - -

- -
-
- Maintenance -
-= 1) { ?> - -
-

Please reassign those QSOs to an existing station location:

- - -
- - - - - - - - - - + session->flashdata('message')) { ?> + +
+

session->flashdata('message'); ?>

+
+ + +

+ +
+
+ QSO-DB Maintenance +
+ = 1) { ?> + +
+

Please reassign those QSOs to an existing station location:

+ + +
+
CallTarget LocationReassign
+ + + + + + + + + '; } ?> -
CallTarget LocationReassign
'.$call['COL_STATION_CALLSIGN'].'
-
-
- - + + +
+
+ + + - - - +
+
+ Settings Maintenance +
+ config->item('cl_multilanguage')) { ?> + +
+

Please edit your ./application/config/config.php File and add some rows to it:

+ Go to your application/config Folder and compare config.sample.php with your config.php
+ You'll probably find a block with language-settings. Please include this block into your current config.php +

+
+ + + + +
diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 23c1d781..a3710050 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -73,11 +73,11 @@ $levels = $this->config->item('auth_level'); foreach ($levels as $key => $value) { echo ''; - } + } ?> + + config->item('cl_multilanguage')) { ?> +
+ + + Choose Cloudlog language. +
+ From 5d98554999f759634b6651e5dad643303ef40587 Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 2 Aug 2023 06:37:56 +0000 Subject: [PATCH 2/4] Fixed lifetime of cookie and language-loading --- application/controllers/User.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index 41cda39f..d279da46 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -6,13 +6,12 @@ class User extends CI_Controller { { parent::__construct(); - // Load language files - // $this->lang->load(array( - // 'account', - // 'lotw', - // 'eqsl', - // 'admin', - // )); + $this->lang->load(array( + 'account', + 'lotw', + 'eqsl', + 'admin', + )); } public function index() @@ -479,8 +478,8 @@ class User extends CI_Controller { 'name' => 'language', 'value' => $this->input->post('language', true), - 'expire' => time()+1000 - // 'secure' => TRUE + 'expire' => time()+1000, + 'secure' => FALSE ); $this->input->set_cookie($cookie); @@ -610,8 +609,8 @@ class User extends CI_Controller { 'name' => 'language', 'value' => $data['user']->language, - 'expire' => '9999', - 'secure' => TRUE + 'expire' => time()+1000, + 'secure' => FALSE ); $this->input->set_cookie($cookie); From bca73b12950e89aa066fdc3afbc7fc240e8caf88 Mon Sep 17 00:00:00 2001 From: int2001 Date: Wed, 2 Aug 2023 07:06:34 +0000 Subject: [PATCH 3/4] Commented migscript, Added lang-choser to Useradd --- application/controllers/User.php | 16 ++++++++-------- application/migrations/133_add_user_language.php | 3 +-- application/views/user/add.php | 12 ++++++++++++ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/application/controllers/User.php b/application/controllers/User.php index d279da46..3c417c5f 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -32,6 +32,8 @@ class User extends CI_Controller { $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } + $data['existing_languages'] = $this->find(); + $this->load->model('bands'); $this->load->library('form_validation'); @@ -53,15 +55,14 @@ class User extends CI_Controller { // Get timezones $data['timezones'] = $this->user_model->timezones(); + $data['language'] = 'english'; - if ($this->form_validation->run() == FALSE) - { + if ($this->form_validation->run() == FALSE) { $data['page_title'] = "Add User"; $data['measurement_base'] = $this->config->item('measurement_base'); $this->load->view('interface_assets/header', $data); - if($this->input->post('user_name')) - { + if($this->input->post('user_name')) { $data['user_name'] = $this->input->post('user_name'); $data['user_email'] = $this->input->post('user_email'); $data['user_password'] = $this->input->post('user_password'); @@ -95,9 +96,7 @@ class User extends CI_Controller { $this->load->view('user/add', $data); } $this->load->view('interface_assets/footer'); - } - else - { + } else { switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), @@ -125,8 +124,9 @@ class User extends CI_Controller { $this->input->post('user_amsat_status_upload'), $this->input->post('user_mastodon_url'), $this->input->post('user_gridmap_default_band'), + ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''), $this->input->post('language'), - ($this->input->post('user_gridmap_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_gridmap_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_gridmap_confirmation_eqsl') !== null ? 'E' : ''))) { + )) { // Check for errors case EUSERNAMEEXISTS: $data['username_error'] = 'Username '.$this->input->post('user_name').' already in use!'; diff --git a/application/migrations/133_add_user_language.php b/application/migrations/133_add_user_language.php index 2e5c7609..b6222b7f 100644 --- a/application/migrations/133_add_user_language.php +++ b/application/migrations/133_add_user_language.php @@ -3,8 +3,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); /* - * This adds an option to enable grid and name lookup - * for WWFF references + * This adds a field to user-table to hold/persist language-setting per user */ class Migration_add_user_language extends CI_Migration { diff --git a/application/views/user/add.php b/application/views/user/add.php index a7bd8897..c71104d9 100644 --- a/application/views/user/add.php +++ b/application/views/user/add.php @@ -190,6 +190,18 @@ + config->item('cl_multilanguage')) { ?> +
+ + + Choose Cloudlog language. +
+ From 36f0a30923e65436386153a5744487288af8a1eb Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 2 Aug 2023 13:29:04 +0100 Subject: [PATCH 4/4] Updated the install config with the latest parts for language. --- install/config/config.php | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/install/config/config.php b/install/config/config.php index 9a17f463..1950c5af 100644 --- a/install/config/config.php +++ b/install/config/config.php @@ -153,8 +153,62 @@ $config['url_suffix'] = ''; | there is an available translation if you intend to use something other | than english. | -*/ -$config['language'] = 'english'; + */ +$lang = 'english'; // this language will be used per default + +if (isset($_COOKIE["language"])) { + $tmp_value = $_COOKIE["language"]; + if (!empty($tmp_value)) { $lang = $tmp_value; } +} +switch ($lang) { // do this for security-reasons! parse only langs, which are known to us +case 'dutch': + $config['language'] = $lang; + break; +case 'chinese_simplified': + $config['language'] = $lang; + break; +case 'spanish': + $config['language'] = $lang; + break; +case 'czech': + $config['language'] = $lang; + break; +case 'bulgarian': + $config['language'] = $lang; + break; +case 'turkish': + $config['language'] = $lang; + break; +case 'swedish': + $config['language'] = $lang; + break; +case 'polish': + $config['language'] = $lang; + break; +case 'italian': + $config['language'] = $lang; + break; +case 'greek': + $config['language'] = $lang; + break; +case 'french': + $config['language'] = $lang; + break; +case 'finnish': + $config['language'] = $lang; + break; +case 'russian': + $config['language'] = $lang; + break; +case 'english': + $config['language'] = $lang; + break; +case 'german': + $config['language'] = $lang; + break; +} + +$config['cl_multilanguage']=true; /* |--------------------------------------------------------------------------