Merge pull request #2361 from int2001/user_lang

Implemented Userlanguages with a lot of help from @AndreasK79
pull/2368/head
Peter Goodhall 2023-08-02 14:00:52 +01:00 zatwierdzone przez GitHub
commit 8f2ed595e9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
9 zmienionych plików z 325 dodań i 97 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE;
|
*/
$config['migration_version'] = 132;
$config['migration_version'] = 133;
/*
|--------------------------------------------------------------------------

Wyświetl plik

@ -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()
@ -33,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');
@ -54,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');
@ -90,14 +90,13 @@ 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);
}
$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,7 +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('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'),
)) {
// Check for errors
case EUSERNAMEEXISTS:
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
@ -171,16 +172,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 +228,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 +346,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 +455,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 +473,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' => FALSE
);
$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 +523,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 +594,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' => time()+1000,
'secure' => FALSE
);
$this->input->set_cookie($cookie);
redirect('dashboard');
} else {
$this->session->set_flashdata('error', 'Incorrect username or password!');
@ -591,9 +635,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 +658,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 +667,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 +720,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 +735,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');

Wyświetl plik

@ -0,0 +1,28 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* This adds a field to user-table to hold/persist language-setting per user
*/
class Migration_add_user_language extends CI_Migration {
public function up()
{
if (!$this->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');
}
}
}

Wyświetl plik

@ -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);
}

Wyświetl plik

@ -1,57 +1,78 @@
<div class="container">
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<h2><?php echo $page_title; ?></h2>
<div class="card">
<div class="card-header">
Maintenance
</div>
<?php if($is_there_qsos_with_no_station_id >= 1) { ?>
<div class="alert alert-danger" role="alert">
<span class="badge badge-pill badge-warning">Warning</span> The Database contains QSOs without a station-profile (location)<br/>
</div>
<div class="card-body">
<p class="card-text">Please reassign those QSOs to an existing station location:</p>
<div class="table-responsive">
<table id="station_locations_table" class="table table-sm table-striped">
<thead>
<tr>
<th scope="col">Call</th>
<th scope="col">Target Location</th>
<th scope="col">Reassign</th>
</tr>
</thead>
<tbody>
<?php
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<h2><?php echo $page_title; ?></h2>
<div class="card">
<div class="card-header">
QSO-DB Maintenance
</div>
<?php if($is_there_qsos_with_no_station_id >= 1) { ?>
<div class="alert alert-danger" role="alert">
<span class="badge badge-pill badge-warning">Warning</span> The Database contains QSOs without a station-profile (location)<br/>
</div>
<div class="card-body">
<p class="card-text">Please reassign those QSOs to an existing station location:</p>
<div class="table-responsive">
<table id="station_locations_table" class="table table-sm table-striped">
<thead>
<tr>
<th scope="col">Call</th>
<th scope="col">Target Location</th>
<th scope="col">Reassign</th>
</tr>
</thead>
<tbody>
<?php
foreach ($calls_wo_sid as $call) {
echo '<tr><td>'.$call['COL_STATION_CALLSIGN'].'</td><td><select name="station_profile" id="station_profile">';
$options='';
foreach ($stations->result() as $station) {
$options.='<option value='.$station->station_id.'>'.$station->station_profile_name.' ('.$station->station_callsign.')</option>';
}
$options='';
foreach ($stations->result() as $station) {
$options.='<option value='.$station->station_id.'>'.$station->station_profile_name.' ('.$station->station_callsign.')</option>';
}
echo $options.'</select></td><td><button class="btn btn-warning" onClick="reassign(\''.$call['COL_STATION_CALLSIGN'].'\',$(\'#station_profile option:selected\').val());"><i class="fas fa-sync"></i>Reassign</a></button></td></tr>';
} ?>
</tbody></table>
</div>
</div>
<?php
} else { ?>
<div class="alert alert-secondary" role="alert">
<span class="badge badge-pill badge-success">Everything ok</span> Every QSO in your Database is assigned to a station-profile (location)
</div>
</tbody>
</table>
</div>
</div>
<?php
} else { ?>
<div class="alert alert-secondary" role="alert">
<span class="badge badge-pill badge-success">Everything ok</span> Every QSO in your Database is assigned to a station-profile (location)
</div>
<?php } ?>
</div>
</div>
<div class="card">
<div class="card-header">
Settings Maintenance
</div>
<?php if(!$this->config->item('cl_multilanguage')) { ?>
<div class="alert alert-danger" role="alert">
<span class="badge badge-pill badge-warning">Warning</span> You didn't enabled Multilanguage support in your config.php
</div>
<div class="card-body">
<p class="card-text">Please edit your ./application/config/config.php File and add some rows to it:</br></br>
Go to your application/config Folder and compare config.sample.php with your config.php</br>
You'll probably find a block with language-settings. Please include this block into your current config.php
</p>
</div>
<?php
} else { ?>
<div class="alert alert-secondary" role="alert">
<span class="badge badge-pill badge-success">Everything ok</span> You have enabled Multuser-Language support
</div>
<?php } ?>
</div>
</div>

Wyświetl plik

@ -190,6 +190,18 @@
</select>
<small id="user_measurement_base_Help" class="form-text text-muted"><?php echo lang('account_choose_which_unit_distances_will_be_shown_in'); ?></small>
</div>
<?php if ($this->config->item('cl_multilanguage')) { ?>
<div class="form-group">
<label for="language">Cloudlog Language</label>
<?php
foreach($existing_languages as $lang){
$options[$lang] = ucfirst($lang);
}
echo form_dropdown('language', $options, $language);
?>
<small id="language_Help" class="form-text text-muted">Choose Cloudlog language.</small>
</div>
<?php } ?>
</div>
</div>

Wyświetl plik

@ -73,11 +73,11 @@
$levels = $this->config->item('auth_level');
foreach ($levels as $key => $value) {
echo '<option value="'. $key . '"';
if($user_type == $key) {
echo "selected=\"selected\"";
}
if($user_type == $key) {
echo "selected=\"selected\"";
}
echo '>' . $value . '</option>';
}
}
?>
</select>
<?php } else {
@ -191,6 +191,19 @@
</select>
<small id="user_measurement_base_Help" class="form-text text-muted"><?php echo lang('account_choose_which_unit_distances_will_be_shown_in'); ?></small>
</div>
<?php if ($this->config->item('cl_multilanguage')) { ?>
<div class="form-group">
<label for="language">Cloudlog Language</label>
<?php
foreach($existing_languages as $lang){
$options[$lang] = ucfirst($lang);
}
echo form_dropdown('language', $options, $language);
?>
<small id="language_Help" class="form-text text-muted">Choose Cloudlog language.</small>
</div>
<?php } ?>
</div>
</div>
</div>

Wyświetl plik

@ -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;
/*
|--------------------------------------------------------------------------