Cleaned up code a bit

这个提交包含在:
Peter Goodhall 2024-05-02 13:48:45 +01:00
父节点 9037bf8dad
当前提交 c33ce3fdbb

查看文件

@ -1,6 +1,7 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller { class User extends CI_Controller
{
function __construct() function __construct()
{ {
@ -14,23 +15,39 @@ class User extends CI_Controller {
)); ));
} }
/**
* Index method for the User controller.
* This method loads the user model, authorizes the user, and displays the user accounts.
*/
public function index() public function index()
{ {
$this->load->model('user_model'); $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'); }
// Check if the user is authorized
if (!$this->user_model->authorize(99)) {
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
redirect('dashboard');
}
// Get the user accounts
$data['results'] = $this->user_model->users(); $data['results'] = $this->user_model->users();
// Set the page title
$data['page_title'] = $this->lang->line('admin_user_accounts'); $data['page_title'] = $this->lang->line('admin_user_accounts');
// Load the views
$this->load->view('interface_assets/header', $data); $this->load->view('interface_assets/header', $data);
$this->load->view('user/main'); $this->load->view('user/main');
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} }
function add() { function add()
{
$this->load->model('user_model'); $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'); } 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(); $data['existing_languages'] = $this->find();
@ -74,7 +91,7 @@ class User extends CI_Controller {
$option_value = $item->option_value; $option_value = $item->option_value;
if ($option_name == 'dashboard_upcoming_dx_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_upcoming_dx_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_upcoming_dx_card'] = true; $data['dashboard_upcoming_dx_card'] = true;
} else { } else {
$data['dashboard_upcoming_dx_card'] = false; $data['dashboard_upcoming_dx_card'] = false;
@ -82,7 +99,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_qslcards_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_qslcards_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_qslcard_card'] = true; $data['dashboard_qslcard_card'] = true;
} else { } else {
$data['dashboard_qslcard_card'] = false; $data['dashboard_qslcard_card'] = false;
@ -90,7 +107,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_eqslcards_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_eqslcards_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_eqslcard_card'] = true; $data['dashboard_eqslcard_card'] = true;
} else { } else {
$data['dashboard_eqslcard_card'] = false; $data['dashboard_eqslcard_card'] = false;
@ -98,7 +115,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_lotw_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_lotw_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_lotw_card'] = true; $data['dashboard_lotw_card'] = true;
} else { } else {
$data['dashboard_lotw_card'] = false; $data['dashboard_lotw_card'] = false;
@ -106,7 +123,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_vuccgrids_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_vuccgrids_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_vuccgrids_card'] = true; $data['dashboard_vuccgrids_card'] = true;
} else { } else {
$data['dashboard_vuccgrids_card'] = false; $data['dashboard_vuccgrids_card'] = false;
@ -119,7 +136,7 @@ class User extends CI_Controller {
$data['measurement_base'] = $this->config->item('measurement_base'); $data['measurement_base'] = $this->config->item('measurement_base');
$this->load->view('interface_assets/header', $data); $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_name'] = $this->input->post('user_name');
$data['user_email'] = $this->input->post('user_email'); $data['user_email'] = $this->input->post('user_email');
$data['user_password'] = $this->input->post('user_password'); $data['user_password'] = $this->input->post('user_password');
@ -146,7 +163,7 @@ class User extends CI_Controller {
$data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload'); $data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload');
$data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_mastodon_url'] = $this->input->post('user_mastodon_url');
$data['user_default_band'] = $this->input->post('user_default_band'); $data['user_default_band'] = $this->input->post('user_default_band');
$data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '').($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''); $data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '') . ($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '') . ($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '') . ($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : '');
$data['user_qso_end_times'] = $this->input->post('user_qso_end_times'); $data['user_qso_end_times'] = $this->input->post('user_qso_end_times');
$data['user_quicklog'] = $this->input->post('user_quicklog'); $data['user_quicklog'] = $this->input->post('user_quicklog');
$data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter'); $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter');
@ -159,7 +176,8 @@ class User extends CI_Controller {
} }
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} else { } else {
switch($this->user_model->add($this->input->post('user_name'), switch ($this->user_model->add(
$this->input->post('user_name'),
$this->input->post('user_password'), $this->input->post('user_password'),
$this->input->post('user_email'), $this->input->post('user_email'),
$this->input->post('user_type'), $this->input->post('user_type'),
@ -186,7 +204,7 @@ class User extends CI_Controller {
$this->input->post('user_amsat_status_upload'), $this->input->post('user_amsat_status_upload'),
$this->input->post('user_mastodon_url'), $this->input->post('user_mastodon_url'),
$this->input->post('user_default_band'), $this->input->post('user_default_band'),
($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '').($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''), ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '') . ($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '') . ($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '') . ($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''),
$this->input->post('user_qso_end_times'), $this->input->post('user_qso_end_times'),
$this->input->post('user_quicklog'), $this->input->post('user_quicklog'),
$this->input->post('user_quicklog_enter'), $this->input->post('user_quicklog_enter'),
@ -196,17 +214,17 @@ class User extends CI_Controller {
)) { )) {
// Check for errors // Check for errors
case EUSERNAMEEXISTS: case EUSERNAMEEXISTS:
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!'; $data['username_error'] = 'Username <b>' . $this->input->post('user_name') . '</b> already in use!';
break; break;
case EEMAILEXISTS: case EEMAILEXISTS:
$data['email_error'] = 'E-mail address <b>'.$this->input->post('user_email').'</b> already in use!'; $data['email_error'] = 'E-mail address <b>' . $this->input->post('user_email') . '</b> already in use!';
break; break;
case EPASSWORDINVALID: case EPASSWORDINVALID:
$data['password_error'] = 'Invalid password!'; $data['password_error'] = 'Invalid password!';
break; break;
// All okay, return to user screen // All okay, return to user screen
case OK: case OK:
$this->session->set_flashdata('notice', 'User '.$this->input->post('user_name').' added'); $this->session->set_flashdata('notice', 'User ' . $this->input->post('user_name') . ' added');
redirect('user'); redirect('user');
return; return;
} }
@ -238,7 +256,7 @@ class User extends CI_Controller {
$data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload'); $data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload');
$data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_mastodon_url'] = $this->input->post('user_mastodon_url');
$data['user_default_band'] = $this->input->post('user_default_band'); $data['user_default_band'] = $this->input->post('user_default_band');
$data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '').($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''); $data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '') . ($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '') . ($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '') . ($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : '');
$data['user_qso_end_times'] = $this->input->post('user_qso_end_times'); $data['user_qso_end_times'] = $this->input->post('user_qso_end_times');
$data['user_quicklog'] = $this->input->post('user_quicklog'); $data['user_quicklog'] = $this->input->post('user_quicklog');
$data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter'); $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter');
@ -248,25 +266,30 @@ class User extends CI_Controller {
} }
} }
function find() { function find()
{
$existing_langs = array(); $existing_langs = array();
$lang_path = APPPATH.'language'; $lang_path = APPPATH . 'language';
$results = scandir($lang_path); $results = scandir($lang_path);
foreach ($results as $result) { foreach ($results as $result) {
if ($result === '.' or $result === '..') continue; if ($result === '.' or $result === '..') continue;
if (is_dir(APPPATH.'language' . '/' . $result)) { if (is_dir(APPPATH . 'language' . '/' . $result)) {
$dirs[] = $result; $dirs[] = $result;
} }
} }
return $dirs; return $dirs;
} }
function edit() { function edit()
{
$this->load->model('user_model'); $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'); } 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)); $query = $this->user_model->get_by_id($this->uri->segment(3));
$data['existing_languages'] = $this->find(); $data['existing_languages'] = $this->find();
@ -276,8 +299,7 @@ class User extends CI_Controller {
$this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean'); $this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean');
$this->form_validation->set_rules('user_email', 'E-mail', 'required|xss_clean'); $this->form_validation->set_rules('user_email', 'E-mail', 'required|xss_clean');
if($this->session->userdata('user_type') == 99) if ($this->session->userdata('user_type') == 99) {
{
$this->form_validation->set_rules('user_type', 'Type', 'required|xss_clean'); $this->form_validation->set_rules('user_type', 'Type', 'required|xss_clean');
} }
$this->form_validation->set_rules('user_firstname', 'First name', 'required|xss_clean'); $this->form_validation->set_rules('user_firstname', 'First name', 'required|xss_clean');
@ -286,7 +308,7 @@ class User extends CI_Controller {
$this->form_validation->set_rules('user_locator', 'Locator', 'callback_check_locator'); $this->form_validation->set_rules('user_locator', 'Locator', 'callback_check_locator');
$this->form_validation->set_rules('user_timezone', 'Timezone', 'required'); $this->form_validation->set_rules('user_timezone', 'Timezone', 'required');
$data['user_form_action'] = site_url('user/edit')."/".$this->uri->segment(3);; $data['user_form_action'] = site_url('user/edit') . "/" . $this->uri->segment(3);;
$data['bands'] = $this->bands->get_user_bands(); $data['bands'] = $this->bands->get_user_bands();
// Get themes list // Get themes list
@ -295,256 +317,255 @@ class User extends CI_Controller {
// Get timezones // Get timezones
$data['timezones'] = $this->user_model->timezones(); $data['timezones'] = $this->user_model->timezones();
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == FALSE) {
{
$data['page_title'] = "Edit User"; $data['page_title'] = "Edit User";
$q = $query->row(); $q = $query->row();
$data['id'] = $q->user_id; $data['id'] = $q->user_id;
if($this->input->post('user_name', true)) { if ($this->input->post('user_name', true)) {
$data['user_name'] = $this->input->post('user_name', true); $data['user_name'] = $this->input->post('user_name', true);
} else { } else {
$data['user_name'] = $q->user_name; $data['user_name'] = $q->user_name;
} }
if($this->input->post('user_email', true)) { if ($this->input->post('user_email', true)) {
$data['user_email'] = $this->input->post('user_email', true); $data['user_email'] = $this->input->post('user_email', true);
} else { } else {
$data['user_email'] = $q->user_email; $data['user_email'] = $q->user_email;
} }
if($this->input->post('user_password', true)) { if ($this->input->post('user_password', true)) {
$data['user_password'] = $this->input->post('user_password',true); $data['user_password'] = $this->input->post('user_password', true);
} else { } else {
$data['user_password'] = $q->user_password; $data['user_password'] = $q->user_password;
} }
if($this->input->post('user_type', true)) { if ($this->input->post('user_type', true)) {
$data['user_type'] = $this->input->post('user_type',true); $data['user_type'] = $this->input->post('user_type', true);
} else { } else {
$data['user_type'] = $q->user_type; $data['user_type'] = $q->user_type;
} }
if($this->input->post('user_callsign', true)) { if ($this->input->post('user_callsign', true)) {
$data['user_callsign'] = $this->input->post('user_callsign', true); $data['user_callsign'] = $this->input->post('user_callsign', true);
} else { } else {
$data['user_callsign'] = $q->user_callsign; $data['user_callsign'] = $q->user_callsign;
} }
if($this->input->post('user_locator', true)) { if ($this->input->post('user_locator', true)) {
$data['user_locator'] = $this->input->post('user_locator', true); $data['user_locator'] = $this->input->post('user_locator', true);
} else { } else {
$data['user_locator'] = $q->user_locator; $data['user_locator'] = $q->user_locator;
} }
if($this->input->post('user_firstname', true)) { if ($this->input->post('user_firstname', true)) {
$data['user_firstname'] = $this->input->post('user_firstname', true); $data['user_firstname'] = $this->input->post('user_firstname', true);
} else { } else {
$data['user_firstname'] = $q->user_firstname; $data['user_firstname'] = $q->user_firstname;
} }
if($this->input->post('user_lastname', true)) { if ($this->input->post('user_lastname', true)) {
$data['user_lastname'] = $this->input->post('user_lastname', true); $data['user_lastname'] = $this->input->post('user_lastname', true);
} else { } else {
$data['user_lastname'] = $q->user_lastname; $data['user_lastname'] = $q->user_lastname;
} }
if($this->input->post('user_callsign', true)) { if ($this->input->post('user_callsign', true)) {
$data['user_callsign'] = $this->input->post('user_callsign', true); $data['user_callsign'] = $this->input->post('user_callsign', true);
} else { } else {
$data['user_callsign'] = $q->user_callsign; $data['user_callsign'] = $q->user_callsign;
} }
if($this->input->post('user_locator', true)) { if ($this->input->post('user_locator', true)) {
$data['user_locator'] = $this->input->post('user_locator', true); $data['user_locator'] = $this->input->post('user_locator', true);
} else { } else {
$data['user_locator'] = $q->user_locator; $data['user_locator'] = $q->user_locator;
} }
if($this->input->post('user_timezone')) { if ($this->input->post('user_timezone')) {
$data['user_timezone'] = $this->input->post('user_timezone', true); $data['user_timezone'] = $this->input->post('user_timezone', true);
} else { } else {
$data['user_timezone'] = $q->user_timezone; $data['user_timezone'] = $q->user_timezone;
} }
if($this->input->post('user_lotw_name')) { if ($this->input->post('user_lotw_name')) {
$data['user_lotw_name'] = $this->input->post('user_lotw_name', true); $data['user_lotw_name'] = $this->input->post('user_lotw_name', true);
} else { } else {
$data['user_lotw_name'] = $q->user_lotw_name; $data['user_lotw_name'] = $q->user_lotw_name;
} }
if($this->input->post('user_clublog_name')) { if ($this->input->post('user_clublog_name')) {
$data['user_clublog_name'] = $this->input->post('user_clublog_name', true); $data['user_clublog_name'] = $this->input->post('user_clublog_name', true);
} else { } else {
$data['user_clublog_name'] = $q->user_clublog_name; $data['user_clublog_name'] = $q->user_clublog_name;
} }
if($this->input->post('user_clublog_password')) { if ($this->input->post('user_clublog_password')) {
$data['user_clublog_password'] = $this->input->post('user_clublog_password', true); $data['user_clublog_password'] = $this->input->post('user_clublog_password', true);
} else { } else {
$data['user_clublog_password'] = $q->user_clublog_password; $data['user_clublog_password'] = $q->user_clublog_password;
} }
if($this->input->post('user_lotw_password')) { if ($this->input->post('user_lotw_password')) {
$data['user_lotw_password'] = $this->input->post('user_lotw_password', true); $data['user_lotw_password'] = $this->input->post('user_lotw_password', true);
} else { } else {
$data['user_lotw_password'] = $q->user_lotw_password; $data['user_lotw_password'] = $q->user_lotw_password;
} }
if($this->input->post('user_eqsl_name')) { if ($this->input->post('user_eqsl_name')) {
$data['user_eqsl_name'] = $this->input->post('user_eqsl_name', true); $data['user_eqsl_name'] = $this->input->post('user_eqsl_name', true);
} else { } else {
$data['user_eqsl_name'] = $q->user_eqsl_name; $data['user_eqsl_name'] = $q->user_eqsl_name;
} }
if($this->input->post('user_eqsl_password')) { if ($this->input->post('user_eqsl_password')) {
$data['user_eqsl_password'] = $this->input->post('user_eqsl_password', true); $data['user_eqsl_password'] = $this->input->post('user_eqsl_password', true);
} else { } else {
$data['user_eqsl_password'] = $q->user_eqsl_password; $data['user_eqsl_password'] = $q->user_eqsl_password;
} }
if($this->input->post('user_measurement_base')) { if ($this->input->post('user_measurement_base')) {
$data['user_measurement_base'] = $this->input->post('user_measurement_base', true); $data['user_measurement_base'] = $this->input->post('user_measurement_base', true);
} else { } else {
$data['user_measurement_base'] = $q->user_measurement_base; $data['user_measurement_base'] = $q->user_measurement_base;
} }
if($this->input->post('user_date_format')) { if ($this->input->post('user_date_format')) {
$data['user_date_format'] = $this->input->post('user_date_format', true); $data['user_date_format'] = $this->input->post('user_date_format', true);
} else { } else {
$data['user_date_format'] = $q->user_date_format; $data['user_date_format'] = $q->user_date_format;
} }
if($this->input->post('language')) { if ($this->input->post('language')) {
$data['language'] = $this->input->post('language', true); $data['language'] = $this->input->post('language', true);
} else { } else {
$data['language'] = $q->language; $data['language'] = $q->language;
} }
if($this->input->post('user_stylesheet')) { if ($this->input->post('user_stylesheet')) {
$data['user_stylesheet'] = $this->input->post('user_stylesheet', true); $data['user_stylesheet'] = $this->input->post('user_stylesheet', true);
} else { } else {
$data['user_stylesheet'] = $q->user_stylesheet; $data['user_stylesheet'] = $q->user_stylesheet;
} }
if($this->input->post('user_qth_lookup')) { if ($this->input->post('user_qth_lookup')) {
$data['user_qth_lookup'] = $this->input->post('user_qth_lookup', true); $data['user_qth_lookup'] = $this->input->post('user_qth_lookup', true);
} else { } else {
$data['user_qth_lookup'] = $q->user_qth_lookup; $data['user_qth_lookup'] = $q->user_qth_lookup;
} }
if($this->input->post('user_sota_lookup')) { if ($this->input->post('user_sota_lookup')) {
$data['user_sota_lookup'] = $this->input->post('user_sota_lookup', true); $data['user_sota_lookup'] = $this->input->post('user_sota_lookup', true);
} else { } else {
$data['user_sota_lookup'] = $q->user_sota_lookup; $data['user_sota_lookup'] = $q->user_sota_lookup;
} }
if($this->input->post('user_wwff_lookup')) { if ($this->input->post('user_wwff_lookup')) {
$data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup', true); $data['user_wwff_lookup'] = $this->input->post('user_wwff_lookup', true);
} else { } else {
$data['user_wwff_lookup'] = $q->user_wwff_lookup; $data['user_wwff_lookup'] = $q->user_wwff_lookup;
} }
if($this->input->post('user_pota_lookup')) { if ($this->input->post('user_pota_lookup')) {
$data['user_pota_lookup'] = $this->input->post('user_pota_lookup', true); $data['user_pota_lookup'] = $this->input->post('user_pota_lookup', true);
} else { } else {
$data['user_pota_lookup'] = $q->user_pota_lookup; $data['user_pota_lookup'] = $q->user_pota_lookup;
} }
if($this->input->post('user_show_notes')) { if ($this->input->post('user_show_notes')) {
$data['user_show_notes'] = $this->input->post('user_show_notes', true); $data['user_show_notes'] = $this->input->post('user_show_notes', true);
} else { } else {
$data['user_show_notes'] = $q->user_show_notes; $data['user_show_notes'] = $q->user_show_notes;
} }
if($this->input->post('user_qso_end_times')) { if ($this->input->post('user_qso_end_times')) {
$data['user_qso_end_times'] = $this->input->post('user_qso_end_times', true); $data['user_qso_end_times'] = $this->input->post('user_qso_end_times', true);
} else { } else {
$data['user_qso_end_times'] = $q->user_qso_end_times; $data['user_qso_end_times'] = $q->user_qso_end_times;
} }
if($this->input->post('user_quicklog')) { if ($this->input->post('user_quicklog')) {
$data['user_quicklog'] = $this->input->post('user_quicklog', true); $data['user_quicklog'] = $this->input->post('user_quicklog', true);
} else { } else {
$data['user_quicklog'] = $q->user_quicklog; $data['user_quicklog'] = $q->user_quicklog;
} }
if($this->input->post('user_quicklog_enter')) { if ($this->input->post('user_quicklog_enter')) {
$data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter', true); $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter', true);
} else { } else {
$data['user_quicklog_enter'] = $q->user_quicklog_enter; $data['user_quicklog_enter'] = $q->user_quicklog_enter;
} }
if($this->input->post('user_show_profile_image')) { if ($this->input->post('user_show_profile_image')) {
$data['user_show_profile_image'] = $this->input->post('user_show_profile_image', false); $data['user_show_profile_image'] = $this->input->post('user_show_profile_image', false);
} else { } else {
$data['user_show_profile_image'] = $q->user_show_profile_image; $data['user_show_profile_image'] = $q->user_show_profile_image;
} }
if($this->input->post('user_previous_qsl_type')) { if ($this->input->post('user_previous_qsl_type')) {
$data['user_previous_qsl_type'] = $this->input->post('user_previous_qsl_type', false); $data['user_previous_qsl_type'] = $this->input->post('user_previous_qsl_type', false);
} else { } else {
$data['user_previous_qsl_type'] = $q->user_previous_qsl_type; $data['user_previous_qsl_type'] = $q->user_previous_qsl_type;
} }
if($this->input->post('user_amsat_status_upload')) { if ($this->input->post('user_amsat_status_upload')) {
$data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload', false); $data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload', false);
} else { } else {
$data['user_amsat_status_upload'] = $q->user_amsat_status_upload; $data['user_amsat_status_upload'] = $q->user_amsat_status_upload;
} }
if($this->input->post('user_mastodon_url')) { if ($this->input->post('user_mastodon_url')) {
$data['user_mastodon_url'] = $this->input->post('user_mastodon_url', false); $data['user_mastodon_url'] = $this->input->post('user_mastodon_url', false);
} else { } else {
$data['user_mastodon_url'] = $q->user_mastodon_url; $data['user_mastodon_url'] = $q->user_mastodon_url;
} }
if($this->input->post('user_default_band')) { if ($this->input->post('user_default_band')) {
$data['user_default_band'] = $this->input->post('user_default_band', false); $data['user_default_band'] = $this->input->post('user_default_band', false);
} else { } else {
$data['user_default_band'] = $q->user_default_band; $data['user_default_band'] = $q->user_default_band;
} }
if($this->input->post('user_default_confirmation')) { if ($this->input->post('user_default_confirmation')) {
$data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '').($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''); $data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '') . ($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '') . ($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '') . ($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : '');
} else { } else {
$data['user_default_confirmation'] = $q->user_default_confirmation; $data['user_default_confirmation'] = $q->user_default_confirmation;
} }
if($this->input->post('user_column1')) { if ($this->input->post('user_column1')) {
$data['user_column1'] = $this->input->post('user_column1', true); $data['user_column1'] = $this->input->post('user_column1', true);
} else { } else {
$data['user_column1'] = $q->user_column1; $data['user_column1'] = $q->user_column1;
} }
if($this->input->post('user_column2')) { if ($this->input->post('user_column2')) {
$data['user_column2'] = $this->input->post('user_column2', true); $data['user_column2'] = $this->input->post('user_column2', true);
} else { } else {
$data['user_column2'] = $q->user_column2; $data['user_column2'] = $q->user_column2;
} }
if($this->input->post('user_column3')) { if ($this->input->post('user_column3')) {
$data['user_column3'] = $this->input->post('user_column3', true); $data['user_column3'] = $this->input->post('user_column3', true);
} else { } else {
$data['user_column3'] = $q->user_column3; $data['user_column3'] = $q->user_column3;
} }
if($this->input->post('user_column4')) { if ($this->input->post('user_column4')) {
$data['user_column4'] = $this->input->post('user_column4', true); $data['user_column4'] = $this->input->post('user_column4', true);
} else { } else {
$data['user_column4'] = $q->user_column4; $data['user_column4'] = $q->user_column4;
} }
if($this->input->post('user_column5')) { if ($this->input->post('user_column5')) {
$data['user_column5'] = $this->input->post('user_column5', true); $data['user_column5'] = $this->input->post('user_column5', true);
} else { } else {
$data['user_column5'] = $q->user_column5; $data['user_column5'] = $q->user_column5;
} }
if($this->input->post('user_winkey')) { if ($this->input->post('user_winkey')) {
$data['user_winkey'] = $this->input->post('user_winkey', true); $data['user_winkey'] = $this->input->post('user_winkey', true);
} else { } else {
$data['user_winkey'] = $q->winkey; $data['user_winkey'] = $q->winkey;
@ -553,21 +574,21 @@ class User extends CI_Controller {
$this->load->model('user_options_model'); $this->load->model('user_options_model');
$hamsat_user_object = $this->user_options_model->get_options('hamsat')->result(); $hamsat_user_object = $this->user_options_model->get_options('hamsat')->result();
if($this->input->post('user_hamsat_key', true)) { if ($this->input->post('user_hamsat_key', true)) {
$data['user_hamsat_key'] = $this->input->post('user_hamsat_key', true); $data['user_hamsat_key'] = $this->input->post('user_hamsat_key', true);
} else { } else {
// get $q->hamsat_key if its set if not null // get $q->hamsat_key if its set if not null
if(isset($hamsat_user_object[0]->option_value)) { if (isset($hamsat_user_object[0]->option_value)) {
$data['user_hamsat_key'] = $hamsat_user_object[0]->option_value; $data['user_hamsat_key'] = $hamsat_user_object[0]->option_value;
} else { } else {
$data['user_hamsat_key'] = ""; $data['user_hamsat_key'] = "";
} }
} }
if($this->input->post('user_hamsat_workable_only')) { if ($this->input->post('user_hamsat_workable_only')) {
$data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only', false); $data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only', false);
} else { } else {
if(isset($hamsat_user_object[1]->option_value)) { if (isset($hamsat_user_object[1]->option_value)) {
$data['user_hamsat_workable_only'] = $hamsat_user_object[1]->option_value; $data['user_hamsat_workable_only'] = $hamsat_user_object[1]->option_value;
} else { } else {
$data['user_hamsat_workable_only'] = ""; $data['user_hamsat_workable_only'] = "";
@ -591,7 +612,7 @@ class User extends CI_Controller {
$option_value = $item->option_value; $option_value = $item->option_value;
if ($option_name == 'dashboard_upcoming_dx_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_upcoming_dx_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_upcoming_dx_card'] = true; $data['dashboard_upcoming_dx_card'] = true;
} else { } else {
$data['dashboard_upcoming_dx_card'] = false; $data['dashboard_upcoming_dx_card'] = false;
@ -599,7 +620,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_qslcards_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_qslcards_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_qslcard_card'] = true; $data['dashboard_qslcard_card'] = true;
} else { } else {
$data['dashboard_qslcard_card'] = false; $data['dashboard_qslcard_card'] = false;
@ -607,7 +628,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_eqslcards_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_eqslcards_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_eqslcard_card'] = true; $data['dashboard_eqslcard_card'] = true;
} else { } else {
$data['dashboard_eqslcard_card'] = false; $data['dashboard_eqslcard_card'] = false;
@ -615,7 +636,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_lotw_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_lotw_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_lotw_card'] = true; $data['dashboard_lotw_card'] = true;
} else { } else {
$data['dashboard_lotw_card'] = false; $data['dashboard_lotw_card'] = false;
@ -623,7 +644,7 @@ class User extends CI_Controller {
} }
if ($option_name == 'dashboard_vuccgrids_card' && $option_key == 'enabled') { if ($option_name == 'dashboard_vuccgrids_card' && $option_key == 'enabled') {
if($item->option_value == 'true') { if ($item->option_value == 'true') {
$data['dashboard_vuccgrids_card'] = true; $data['dashboard_vuccgrids_card'] = true;
} else { } else {
$data['dashboard_vuccgrids_card'] = false; $data['dashboard_vuccgrids_card'] = false;
@ -634,19 +655,19 @@ class User extends CI_Controller {
// [MAP Custom] GET user options // // [MAP Custom] GET user options //
$this->load->model('user_options_model'); $this->load->model('user_options_model');
$options_object = $this->user_options_model->get_options('map_custom')->result(); $options_object = $this->user_options_model->get_options('map_custom')->result();
if (count($options_object)>0) { if (count($options_object) > 0) {
foreach ($options_object as $row) { foreach ($options_object as $row) {
if ($row->option_name=='icon') { if ($row->option_name == 'icon') {
$option_value = json_decode($row->option_value,true); $option_value = json_decode($row->option_value, true);
foreach ($option_value as $ktype => $vtype) { foreach ($option_value as $ktype => $vtype) {
if($this->input->post('user_map_'.$row->option_key.'_icon')) { if ($this->input->post('user_map_' . $row->option_key . '_icon')) {
$data['user_map_'.$row->option_key.'_'.$ktype] = $this->input->post('user_map_'.$row->option_key.'_'.$ktype, true); $data['user_map_' . $row->option_key . '_' . $ktype] = $this->input->post('user_map_' . $row->option_key . '_' . $ktype, true);
} else { } else {
$data['user_map_'.$row->option_key.'_'.$ktype] = $vtype; $data['user_map_' . $row->option_key . '_' . $ktype] = $vtype;
} }
} }
} else { } else {
$data['user_map_'.$row->option_name.'_'.$row->option_key] = $row->option_value; $data['user_map_' . $row->option_name . '_' . $row->option_key] = $row->option_value;
} }
} }
} else { } else {
@ -659,22 +680,23 @@ class User extends CI_Controller {
$data['user_map_gridsquare_show'] = "0"; $data['user_map_gridsquare_show'] = "0";
} }
$data['map_icon_select'] = array( $data['map_icon_select'] = array(
'station'=>array('0', 'fas fa-home', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle' ), 'station' => array('0', 'fas fa-home', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle'),
'qso'=>array('fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle' ), 'qso' => array('fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle'),
'qsoconfirm'=>array('0', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle', 'fas fa-check-circle' )); 'qsoconfirm' => array('0', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle', 'fas fa-check-circle')
);
$this->load->view('interface_assets/header', $data); $this->load->view('interface_assets/header', $data);
$this->load->view('user/edit', $data); $this->load->view('user/edit', $data);
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} else { } else {
unset($data); unset($data);
switch($this->user_model->edit($this->input->post())) { switch ($this->user_model->edit($this->input->post())) {
// Check for errors // Check for errors
case EUSERNAMEEXISTS: case EUSERNAMEEXISTS:
$data['username_error'] = 'Username <b>'.$this->input->post('user_name', true).'</b> already in use!'; $data['username_error'] = 'Username <b>' . $this->input->post('user_name', true) . '</b> already in use!';
break; break;
case EEMAILEXISTS: case EEMAILEXISTS:
$data['email_error'] = 'E-mail address <b>'.$this->input->post('user_email', true).'</b> already in use!'; $data['email_error'] = 'E-mail address <b>' . $this->input->post('user_email', true) . '</b> already in use!';
break; break;
case EPASSWORDINVALID: case EPASSWORDINVALID:
$data['password_error'] = 'Invalid password!'; $data['password_error'] = 'Invalid password!';
@ -682,17 +704,17 @@ class User extends CI_Controller {
// All okay, return to user screen // All okay, return to user screen
case OK: case OK:
if ($this->session->userdata('user_id') == $this->uri->segment(3)) { // Editing own User? Set cookie! if ($this->session->userdata('user_id') == $this->uri->segment(3)) { // Editing own User? Set cookie!
$cookie= array( $cookie = array(
'name' => 'language', 'name' => 'language',
'value' => $this->input->post('language', true), 'value' => $this->input->post('language', true),
'expire' => time()+1000, 'expire' => time() + 1000,
'secure' => FALSE 'secure' => FALSE
); );
$this->input->set_cookie($cookie); $this->input->set_cookie($cookie);
} }
if($this->session->userdata('user_id') == $this->input->post('id', true)) { if ($this->session->userdata('user_id') == $this->input->post('id', true)) {
if (isset($_POST['user_dashboard_enable_dxpedition_card'])) { if (isset($_POST['user_dashboard_enable_dxpedition_card'])) {
$this->user_options_model->set_option('dashboard', 'dashboard_upcoming_dx_card', array('enabled' => 'true')); $this->user_options_model->set_option('dashboard', 'dashboard_upcoming_dx_card', array('enabled' => 'true'));
} else { } else {
@ -724,27 +746,27 @@ class User extends CI_Controller {
} }
// [MAP Custom] ADD to user options // // [MAP Custom] ADD to user options //
$array_icon = array('station','qso','qsoconfirm'); $array_icon = array('station', 'qso', 'qsoconfirm');
foreach ($array_icon as $icon) { foreach ($array_icon as $icon) {
$data_options['user_map_'.$icon.'_icon'] = xss_clean($this->input->post('user_map_'.$icon.'_icon', true)); $data_options['user_map_' . $icon . '_icon'] = xss_clean($this->input->post('user_map_' . $icon . '_icon', true));
$data_options['user_map_'.$icon.'_color'] = xss_clean($this->input->post('user_map_'.$icon.'_color', true)); $data_options['user_map_' . $icon . '_color'] = xss_clean($this->input->post('user_map_' . $icon . '_color', true));
} }
$this->load->model('user_options_model'); $this->load->model('user_options_model');
if (!empty($data_options['user_map_qso_icon'])) { if (!empty($data_options['user_map_qso_icon'])) {
foreach ($array_icon as $icon) { foreach ($array_icon as $icon) {
$json = json_encode(array('icon'=>$data_options['user_map_'.$icon.'_icon'], 'color'=>$data_options['user_map_'.$icon.'_color'])); $json = json_encode(array('icon' => $data_options['user_map_' . $icon . '_icon'], 'color' => $data_options['user_map_' . $icon . '_color']));
$this->user_options_model->set_option('map_custom','icon',array($icon=>$json)); $this->user_options_model->set_option('map_custom', 'icon', array($icon => $json));
} }
$this->user_options_model->set_option('map_custom','gridsquare',array('show'=>xss_clean($this->input->post('user_map_gridsquare_show', true)))); $this->user_options_model->set_option('map_custom', 'gridsquare', array('show' => xss_clean($this->input->post('user_map_gridsquare_show', true))));
} else { } else {
$this->user_options_model->del_option('map_custom','icon'); $this->user_options_model->del_option('map_custom', 'icon');
$this->user_options_model->del_option('map_custom','gridsquare'); $this->user_options_model->del_option('map_custom', 'gridsquare');
} }
$this->session->set_flashdata('success', lang('account_user').' '.$this->input->post('user_name', true).' '.lang('account_word_edited')); $this->session->set_flashdata('success', lang('account_user') . ' ' . $this->input->post('user_name', true) . ' ' . lang('account_word_edited'));
redirect('user/edit/'.$this->uri->segment(3)); redirect('user/edit/' . $this->uri->segment(3));
} else { } else {
$this->session->set_flashdata('success', lang('account_user').' '.$this->input->post('user_name', true).' '.lang('account_word_edited')); $this->session->set_flashdata('success', lang('account_user') . ' ' . $this->input->post('user_name', true) . ' ' . lang('account_word_edited'));
redirect('user'); redirect('user');
} }
return; return;
@ -777,7 +799,7 @@ class User extends CI_Controller {
$data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload'); $data['user_amsat_status_upload'] = $this->input->post('user_amsat_status_upload');
$data['user_mastodon_url'] = $this->input->post('user_mastodon_url'); $data['user_mastodon_url'] = $this->input->post('user_mastodon_url');
$data['user_default_band'] = $this->input->post('user_default_band'); $data['user_default_band'] = $this->input->post('user_default_band');
$data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '').($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '').($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '').($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : ''); $data['user_default_confirmation'] = ($this->input->post('user_default_confirmation_qsl') !== null ? 'Q' : '') . ($this->input->post('user_default_confirmation_lotw') !== null ? 'L' : '') . ($this->input->post('user_default_confirmation_eqsl') !== null ? 'E' : '') . ($this->input->post('user_default_confirmation_qrz') !== null ? 'Z' : '');
$data['user_qso_end_times'] = $this->input->post('user_qso_end_times'); $data['user_qso_end_times'] = $this->input->post('user_qso_end_times');
$data['user_quicklog'] = $this->input->post('user_quicklog'); $data['user_quicklog'] = $this->input->post('user_quicklog');
$data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter'); $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter');
@ -793,9 +815,13 @@ class User extends CI_Controller {
} }
} }
function profile() { function profile()
{
$this->load->model('user_model'); $this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } if (!$this->user_model->authorize(2)) {
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
redirect('dashboard');
}
$query = $this->user_model->get_by_id($this->session->userdata('user_id')); $query = $this->user_model->get_by_id($this->session->userdata('user_id'));
$q = $query->row(); $q = $query->row();
$data['page_title'] = "Profile"; $data['page_title'] = "Profile";
@ -827,9 +853,13 @@ class User extends CI_Controller {
* *
* @param int $id The ID of the user to delete. * @param int $id The ID of the user to delete.
*/ */
function delete_new($id) { function delete_new($id)
{
$this->load->model('user_model'); $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'); } if (!$this->user_model->authorize(99)) {
$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)); $query = $this->user_model->get_by_id($this->uri->segment(3));
// call $this->user_model->delete and if no errors return true // call $this->user_model->delete and if no errors return true
@ -840,12 +870,15 @@ class User extends CI_Controller {
// request responds with a 500 status code and empty content // request responds with a 500 status code and empty content
$this->output->set_status_header(500); $this->output->set_status_header(500);
} }
} }
function delete() { function delete()
{
$this->load->model('user_model'); $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'); } if (!$this->user_model->authorize(99)) {
$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)); $query = $this->user_model->get_by_id($this->uri->segment(3));
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -854,17 +887,13 @@ class User extends CI_Controller {
$data = $query->row(); $data = $query->row();
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == FALSE) {
{
$this->load->view('interface_assets/header', $data); $this->load->view('interface_assets/header', $data);
$this->load->view('user/delete'); $this->load->view('user/delete');
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} } else {
else if ($this->user_model->delete($data->user_id)) {
{
if($this->user_model->delete($data->user_id))
{
$this->session->set_flashdata('notice', 'User deleted'); $this->session->set_flashdata('notice', 'User deleted');
redirect('user'); redirect('user');
} else { } else {
@ -874,7 +903,8 @@ class User extends CI_Controller {
} }
} }
function login() { function login()
{
// Check our version and run any migrations // Check our version and run any migrations
$this->load->library('Migration'); $this->load->library('Migration');
$this->load->library('encryption'); $this->load->library('encryption');
@ -892,14 +922,14 @@ class User extends CI_Controller {
$data['user'] = $query->row(); $data['user'] = $query->row();
// Read the cookie remeber_me and log the user in // Read the cookie remeber_me and log the user in
if($this->input->cookie(config_item('cookie_prefix').'remember_me')) { if ($this->input->cookie(config_item('cookie_prefix') . 'remember_me')) {
try { try {
$encrypted_string = $this->input->cookie(config_item('cookie_prefix').'remember_me'); $encrypted_string = $this->input->cookie(config_item('cookie_prefix') . 'remember_me');
$decrypted_string = $this->encryption->decrypt($encrypted_string); $decrypted_string = $this->encryption->decrypt($encrypted_string);
$this->user_model->update_session($decrypted_string); $this->user_model->update_session($decrypted_string);
$this->user_model->set_last_login($decrypted_string); $this->user_model->set_last_login($decrypted_string);
log_message('debug', '[User ID: '.$decrypted_string.'] Remember Me Login Successful'); log_message('debug', '[User ID: ' . $decrypted_string . '] Remember Me Login Successful');
redirect('dashboard'); redirect('dashboard');
} catch (Exception $e) { } catch (Exception $e) {
@ -915,27 +945,26 @@ class User extends CI_Controller {
$this->load->view('interface_assets/mini_header', $data); $this->load->view('interface_assets/mini_header', $data);
$this->load->view('user/login'); $this->load->view('user/login');
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} else { } else {
if($this->user_model->login() == 1) { if ($this->user_model->login() == 1) {
$this->session->set_flashdata('notice', 'User logged in'); $this->session->set_flashdata('notice', 'User logged in');
$this->user_model->update_session($data['user']->user_id); $this->user_model->update_session($data['user']->user_id);
$this->user_model->set_last_login($data['user']->user_id); $this->user_model->set_last_login($data['user']->user_id);
$cookie= array( $cookie = array(
'name' => 'language', 'name' => 'language',
'value' => $data['user']->language, 'value' => $data['user']->language,
'expire' => time()+1000, 'expire' => time() + 1000,
'secure' => FALSE 'secure' => FALSE
); );
$this->input->set_cookie($cookie); $this->input->set_cookie($cookie);
// Create a remember me cookie // Create a remember me cookie
if($this->input->post('remember_me') == '1') { if ($this->input->post('remember_me') == '1') {
$encrypted_string = $this->encryption->encrypt($data['user']->user_id); $encrypted_string = $this->encryption->encrypt($data['user']->user_id);
$cookie= array( $cookie = array(
'name' => 'remember_me', 'name' => 'remember_me',
'value' => $encrypted_string, 'value' => $encrypted_string,
'expire' => '1209600', 'expire' => '1209600',
@ -951,7 +980,8 @@ class User extends CI_Controller {
} }
} }
function logout() { function logout()
{
$this->load->model('user_model'); $this->load->model('user_model');
$user_name = $this->session->userdata('user_name'); $user_name = $this->session->userdata('user_name');
@ -961,7 +991,7 @@ class User extends CI_Controller {
$this->user_model->clear_session(); $this->user_model->clear_session();
$this->session->set_flashdata('notice', 'User '.$user_name.' logged out.'); $this->session->set_flashdata('notice', 'User ' . $user_name . ' logged out.');
redirect('dashboard'); redirect('dashboard');
} }
@ -971,7 +1001,8 @@ class User extends CI_Controller {
* Allows users to input an email address and a password will be sent to that address. * Allows users to input an email address and a password will be sent to that address.
* *
*/ */
function forgot_password() { function forgot_password()
{
$this->load->helper(array('form', 'url')); $this->load->helper(array('form', 'url'));
@ -979,21 +1010,18 @@ class User extends CI_Controller {
$this->form_validation->set_rules('email', 'Email', 'required'); $this->form_validation->set_rules('email', 'Email', 'required');
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == FALSE) {
{
$data['page_title'] = "Forgot Password"; $data['page_title'] = "Forgot Password";
$this->load->view('interface_assets/mini_header', $data); $this->load->view('interface_assets/mini_header', $data);
$this->load->view('user/forgot_password'); $this->load->view('user/forgot_password');
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} } else {
else
{
// Check email address exists // Check email address exists
$this->load->model('user_model'); $this->load->model('user_model');
$check_email = $this->user_model->check_email_address($this->input->post('email', true)); $check_email = $this->user_model->check_email_address($this->input->post('email', true));
if($check_email == TRUE) { if ($check_email == TRUE) {
// Generate password reset code 50 characters long // Generate password reset code 50 characters long
$this->load->helper('string'); $this->load->helper('string');
$reset_code = random_string('alnum', 50); $reset_code = random_string('alnum', 50);
@ -1005,8 +1033,8 @@ class User extends CI_Controller {
$this->data['reset_code'] = $reset_code; $this->data['reset_code'] = $reset_code;
$this->load->library('email'); $this->load->library('email');
if($this->optionslib->get_option('emailProtocol') == "smtp") { if ($this->optionslib->get_option('emailProtocol') == "smtp") {
$config = Array( $config = array(
'protocol' => $this->optionslib->get_option('emailProtocol'), 'protocol' => $this->optionslib->get_option('emailProtocol'),
'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'), 'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'),
'smtp_host' => $this->optionslib->get_option('smtpHost'), 'smtp_host' => $this->optionslib->get_option('smtpHost'),
@ -1028,8 +1056,7 @@ class User extends CI_Controller {
$this->email->subject('Cloudlog Account Password Reset'); $this->email->subject('Cloudlog Account Password Reset');
$this->email->message($message); $this->email->message($message);
if (! $this->email->send()) if (!$this->email->send()) {
{
// Redirect to login page with message // Redirect to login page with message
$this->session->set_flashdata('warning', 'Email settings are incorrect.'); $this->session->set_flashdata('warning', 'Email settings are incorrect.');
redirect('user/login'); redirect('user/login');
@ -1047,10 +1074,14 @@ class User extends CI_Controller {
} }
// Send an E-Mail to the user. Function is similar to forgot_password() // Send an E-Mail to the user. Function is similar to forgot_password()
function admin_send_passwort_reset() { function admin_send_passwort_reset()
{
$this->load->model('user_model'); $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'); } if (!$this->user_model->authorize(99)) {
$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)); $query = $this->user_model->get_by_id($this->uri->segment(3));
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -1059,19 +1090,16 @@ class User extends CI_Controller {
$data = $query->row(); $data = $query->row();
if ($this->form_validation->run() != FALSE) if ($this->form_validation->run() != FALSE) {
{
$this->session->set_flashdata('notice', 'Something went wrong! User has no user_id.'); $this->session->set_flashdata('notice', 'Something went wrong! User has no user_id.');
redirect('user'); redirect('user');
} } else {
else
{
// Check email address exists // Check email address exists
$this->load->model('user_model'); $this->load->model('user_model');
$check_email = $this->user_model->check_email_address($data->user_email); $check_email = $this->user_model->check_email_address($data->user_email);
if($check_email == TRUE) { if ($check_email == TRUE) {
// Generate password reset code 50 characters long // Generate password reset code 50 characters long
$this->load->helper('string'); $this->load->helper('string');
$reset_code = random_string('alnum', 50); $reset_code = random_string('alnum', 50);
@ -1085,8 +1113,8 @@ class User extends CI_Controller {
$this->data['user_name'] = $data->user_name; $this->data['user_name'] = $data->user_name;
$this->load->library('email'); $this->load->library('email');
if($this->optionslib->get_option('emailProtocol') == "smtp") { if ($this->optionslib->get_option('emailProtocol') == "smtp") {
$config = Array( $config = array(
'protocol' => $this->optionslib->get_option('emailProtocol'), 'protocol' => $this->optionslib->get_option('emailProtocol'),
'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'), 'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'),
'smtp_host' => $this->optionslib->get_option('smtpHost'), 'smtp_host' => $this->optionslib->get_option('smtpHost'),
@ -1107,8 +1135,7 @@ class User extends CI_Controller {
$this->email->subject('Cloudlog Account Password Reset'); $this->email->subject('Cloudlog Account Password Reset');
$this->email->message($message); $this->email->message($message);
if (! $this->email->send()) if (!$this->email->send()) {
{
// Redirect to user page with message // Redirect to user page with message
$this->session->set_flashdata('danger', lang('admin_email_settings_incorrect')); $this->session->set_flashdata('danger', lang('admin_email_settings_incorrect'));
redirect('user'); redirect('user');
@ -1128,7 +1155,7 @@ class User extends CI_Controller {
function reset_password($reset_code = NULL) function reset_password($reset_code = NULL)
{ {
$data['reset_code'] = $reset_code; $data['reset_code'] = $reset_code;
if($reset_code != NULL) { if ($reset_code != NULL) {
$this->load->helper(array('form', 'url')); $this->load->helper(array('form', 'url'));
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -1136,15 +1163,12 @@ class User extends CI_Controller {
$this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required|matches[password]'); $this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required|matches[password]');
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == FALSE) {
{
$data['page_title'] = "Reset Password"; $data['page_title'] = "Reset Password";
$this->load->view('interface_assets/mini_header', $data); $this->load->view('interface_assets/mini_header', $data);
$this->load->view('user/reset_password'); $this->load->view('user/reset_password');
$this->load->view('interface_assets/footer'); $this->load->view('interface_assets/footer');
} } else {
else
{
// Lets reset the password! // Lets reset the password!
$this->load->model('user_model'); $this->load->model('user_model');
@ -1157,7 +1181,8 @@ class User extends CI_Controller {
} }
} }
function check_locator($grid) { function check_locator($grid)
{
$grid = $this->input->post('user_locator'); $grid = $this->input->post('user_locator');
// Allow empty locator // Allow empty locator
if (preg_match('/^$/', $grid)) return true; if (preg_match('/^$/', $grid)) return true;
@ -1174,7 +1199,7 @@ class User extends CI_Controller {
// Allow 8-digit locator // Allow 8-digit locator
else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}[0-9]{2}$/', $grid)) return true; else if (preg_match('/^[A-Ra-r]{2}[0-9]{2}[A-Za-z]{2}[0-9]{2}$/', $grid)) return true;
else { else {
$this->form_validation->set_message('check_locator', 'Please check value for grid locator ('.strtoupper($grid).').'); $this->form_validation->set_message('check_locator', 'Please check value for grid locator (' . strtoupper($grid) . ').');
return false; return false;
} }
} }