diff --git a/application/config/migration.php b/application/config/migration.php index 49ca7587..7fbf6167 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE; | be upgraded / downgraded to. | */ -$config['migration_version'] = 63; +$config['migration_version'] = 64; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index 9bf03a7a..9beb2d50 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -13,21 +13,21 @@ class QSO extends CI_Controller { { parent::__construct(); $this->lang->load('qso'); - + $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'); } } public function index() { - + $this->load->model('cat'); $this->load->model('stations'); $this->load->model('logbook_model'); $this->load->model('user_model'); $this->load->model('modes'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } - + $data['active_station_profile'] = $this->stations->find_active(); $data['notice'] = false; $data['stations'] = $this->stations->all(); @@ -36,7 +36,7 @@ class QSO extends CI_Controller { $data['dxcc'] = $this->logbook_model->fetchDxcc(); $data['iota'] = $this->logbook_model->fetchIota(); $data['modes'] = $this->modes->active(); - + $this->load->library('form_validation'); @@ -58,7 +58,7 @@ class QSO extends CI_Controller { // $this->logbook_model->add(); //change to create_qso function as add and create_qso duplicate functionality $this->logbook_model->create_qso(); - + // Store Basic QSO Info for reuse // Put data in an array first, then call set_userdata once. // This solves the problem of CI dumping out the session @@ -83,7 +83,7 @@ class QSO extends CI_Controller { 'transmit_power' => $this->input->post('transmit_power') ); // ]; - + setcookie("radio", $qso_data['radio'], time()+3600*24*99); setcookie("station_profile_id", $qso_data['station_profile_id'], time()+3600*24*99); @@ -93,13 +93,13 @@ class QSO extends CI_Controller { if($this->input->post('sat_name')) { $this->session->set_userdata('prop_mode', 'SAT'); } - + // Get last 5 qsos $data['query'] = $this->logbook_model->last_custom('5'); - + // Set Any Notice Messages $data['notice'] = "QSO Added"; - + // Load view to create another contact $data['page_title'] = "Add QSO"; @@ -116,15 +116,15 @@ class QSO extends CI_Controller { $this->load->model('logbook_model'); $this->logbook_model->create_qso(); } - + function edit() { - + $this->load->model('logbook_model'); $this->load->model('user_model'); $this->load->model('modes'); if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); } $query = $this->logbook_model->qso_info($this->uri->segment(3)); - + $this->load->library('form_validation'); $this->form_validation->set_rules('time_on', 'Start Date', 'required'); @@ -135,7 +135,7 @@ class QSO extends CI_Controller { $data['dxcc'] = $this->logbook_model->fetchDxcc(); $data['iota'] = $this->logbook_model->fetchIota(); $data['modes'] = $this->modes->all(); - + if ($this->form_validation->run() == FALSE) { $this->load->view('qso/edit', $data); @@ -180,7 +180,7 @@ class QSO extends CI_Controller { $this->logbook_model->edit(); } - + function qsl_rcvd($id, $method) { $this->load->model('logbook_model'); $this->load->model('user_model'); @@ -215,13 +215,13 @@ class QSO extends CI_Controller { echo json_encode(array('message' => 'OK')); } } - + /* Delete QSO */ function delete($id) { $this->load->model('logbook_model'); - + $this->logbook_model->delete($id); - + $this->session->set_flashdata('notice', 'QSO Deleted Successfully'); $data['message_title'] = "Deleted"; $data['message_contents'] = "QSO Deleted Successfully"; @@ -245,12 +245,12 @@ class QSO extends CI_Controller { echo json_encode(array('message' => 'OK')); return; } - - + + function band_to_freq($band, $mode) { - + $this->load->library('frequency'); - + echo $this->frequency->convent_band($band, $mode); } @@ -352,4 +352,29 @@ class QSO extends CI_Controller { header('Content-Type: application/json'); echo json_encode($json); } + + public function get_sota_info() { + $sota = xss_clean($this->input->post('sota')); + $url = 'https://api2.sota.org.uk/api/summits/' . $sota; + + // Let's use cURL instead of file_get_contents + // begin script + $ch = curl_init(); + + // basic curl options for all requests + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 0); + + // use the URL we built + curl_setopt($ch, CURLOPT_URL, $url); + + $input = curl_exec($ch); + $chi = curl_getinfo($ch); + + // Close cURL handle + curl_close($ch); + + header('Content-Type: application/json'); + echo $input; + } } diff --git a/application/controllers/User.php b/application/controllers/User.php index 13a4a883..cc4e68c7 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -20,7 +20,7 @@ class User extends CI_Controller { function add() { $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'); } - + $this->load->library('form_validation'); $this->form_validation->set_rules('user_name', 'Username', 'required'); @@ -55,6 +55,7 @@ class User extends CI_Controller { $data['user_timezone'] = $this->input->post('user_timezone'); $data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/add', $data); } else { $this->load->view('user/add', $data); @@ -63,7 +64,7 @@ class User extends CI_Controller { } else { - switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'), $this->input->post('user_timezone'), $this->input->post('user_measurement_base'), $this->input->post('user_date_format'), $this->input->post('user_stylesheet'))) { + switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'), $this->input->post('user_timezone'), $this->input->post('user_measurement_base'), $this->input->post('user_date_format'), $this->input->post('user_stylesheet'), $this->input->post('user_sota_lookup'))) { // Check for errors case EUSERNAMEEXISTS: $data['username_error'] = 'Username '.$this->input->post('user_name').' already in use!'; @@ -93,6 +94,7 @@ class User extends CI_Controller { $data['user_locator'] = $this->input->post('user_locator'); $data['user_measurement_base'] = $this->input->post('user_measurement_base'); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/add', $data); $this->load->view('interface_assets/footer'); } @@ -102,7 +104,7 @@ class User extends CI_Controller { $this->load->model('user_model'); if((!$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)); - + $this->load->library('form_validation'); $this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean'); @@ -206,7 +208,7 @@ class User extends CI_Controller { } else { $data['user_clublog_name'] = $q->user_clublog_name; } - + if($this->input->post('user_clublog_password')) { $data['user_clublog_password'] = $this->input->post('user_clublog_password', true); } else { @@ -218,13 +220,13 @@ class User extends CI_Controller { } else { $data['user_lotw_password'] = $q->user_lotw_password; } - + if($this->input->post('user_eqsl_name')) { $data['user_eqsl_name'] = $this->input->post('user_eqsl_name', true); } else { $data['user_eqsl_name'] = $q->user_eqsl_name; } - + if($this->input->post('user_eqsl_password')) { $data['user_eqsl_password'] = $this->input->post('user_eqsl_password', true); } else { @@ -248,7 +250,13 @@ class User extends CI_Controller { } else { $data['user_stylesheet'] = $q->user_stylesheet; } - + + if($this->input->post('user_sota_lookup')) { + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup', true); + } else { + $data['user_sota_lookup'] = $q->user_sota_lookup; + } + $this->load->view('user/edit', $data); $this->load->view('interface_assets/footer'); } @@ -290,6 +298,7 @@ class User extends CI_Controller { $data['user_locator'] = $this->input->post('user_locator', true); $data['user_timezone'] = $this->input->post('user_timezone', true); $data['user_stylesheet'] = $this->input->post('user_stylesheet'); + $data['user_sota_lookup'] = $this->input->post('user_sota_lookup'); $this->load->view('user/edit'); $this->load->view('interface_assets/footer'); } @@ -347,8 +356,8 @@ class User extends CI_Controller { function login() { // Check our version and run any migrations $this->load->library('Migration'); - $this->migration->current(); - + $this->migration->current(); + $this->load->model('user_model'); $query = $this->user_model->get($this->input->post('user_name', true)); diff --git a/application/migrations/064_add_user_sota_lookup.php b/application/migrations/064_add_user_sota_lookup.php new file mode 100644 index 00000000..5a050e22 --- /dev/null +++ b/application/migrations/064_add_user_sota_lookup.php @@ -0,0 +1,25 @@ +dbforge->add_column('users', $fields); + } + + public function down() + { + $this->dbforge->drop_column('users', 'user_sota_lookup'); + } +} diff --git a/application/models/User_model.php b/application/models/User_model.php index cb77e588..f27e2f4f 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -5,7 +5,7 @@ * This model implements user authentication and authorization * */ - + // Uses 'phpass' from http://www.openwall.com/phpass/ to implement password hashing // TODO migration away from this? @@ -28,7 +28,7 @@ class User_Model extends CI_Model { $this->db->where('user_name', $clean_username); $r = $this->db->get($this->config->item('auth_table')); return $r; - } + } // FUNCTION: object get_by_id($id) // Retrieve a user by user ID @@ -96,7 +96,7 @@ class User_Model extends CI_Model { // FUNCTION: bool add($username, $password, $email, $type) // Add a user - function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet) { + function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet, $user_sota_lookup) { // Check that the user isn't already used if(!$this->exists($username)) { $data = array( @@ -112,6 +112,7 @@ class User_Model extends CI_Model { 'user_measurement_base' => xss_clean($measurement), 'user_date_format' => xss_clean($user_date_format), 'user_stylesheet' => xss_clean($user_stylesheet), + 'user_sota_lookup' => xss_clean($user_sota_lookup), ); // Check the password is valid @@ -153,13 +154,14 @@ class User_Model extends CI_Model { 'user_measurement_base' => xss_clean($fields['user_measurement_base']), 'user_date_format' => xss_clean($fields['user_date_format']), 'user_stylesheet' => xss_clean($fields['user_stylesheet']), + 'user_sota_lookup' => xss_clean($fields['user_sota_lookup']), ); - + // Check to see if the user is allowed to change user levels if($this->session->userdata('user_type') == 99) { $data['user_type'] = $fields['user_type']; } - + // Check to see if username is used already if($this->exists($fields['user_name']) && $this->get($fields['user_name'])->row()->user_id != $fields['id']) { return EUSERNAMEEXISTS; @@ -168,7 +170,7 @@ class User_Model extends CI_Model { if($this->exists_by_email($fields['user_email']) && $this->get_by_email($fields['user_email'])->row()->user_id != $fields['id']) { return EEMAILEXISTS; } - + // Hash password if($fields['user_password'] != NULL) { @@ -187,12 +189,12 @@ class User_Model extends CI_Model { { $data['user_clublog_password'] = $fields['user_clublog_password']; } - + if($fields['user_eqsl_password'] != NULL) { $data['user_eqsl_password'] = $fields['user_eqsl_password']; } - + // Update the user $this->db->where('user_id', $fields['id']); $this->db->update($this->config->item('auth_table'), $data); @@ -202,7 +204,7 @@ class User_Model extends CI_Model { } } else { return EFORBIDDEN; - } + } } // FUNCTION: bool delete() @@ -234,15 +236,15 @@ class User_Model extends CI_Model { // Nothing is returned - it can be assumed that if this is called, the user's // login session *will* be cleared, no matter what state it is in function clear_session() { - + $this->session->sess_destroy(); } - + // FUNCTION: void update_session() // Updates a user's login session after they've logged in // TODO: This should return bool TRUE/FALSE or 0/1 function update_session($id) { - + $u = $this->get_by_id($id); $userdata = array( @@ -260,6 +262,7 @@ class User_Model extends CI_Model { 'user_measurement_base' => $u->row()->user_measurement_base, 'user_date_format' => $u->row()->user_date_format, 'user_stylesheet' => $u->row()->user_stylesheet, + 'user_sota_lookup' => $u->row()->user_sota_lookup, ); $this->session->set_userdata($userdata); @@ -362,7 +365,7 @@ class User_Model extends CI_Model { // Will return '0' in the event of problems with the // hashing function private function _hash($password) { - $hash = password_hash($password, PASSWORD_DEFAULT); + $hash = password_hash($password, PASSWORD_DEFAULT); if(strlen($hash) < 20) { return EPASSWORDINVALID; @@ -370,7 +373,7 @@ class User_Model extends CI_Model { return $hash; } } - + } ?> diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index b075c5dc..ba6f6817 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -319,201 +319,7 @@ $(document).on('keypress',function(e) { uri->segment(1) == "qso") { ?> - + - diff --git a/application/views/user/add.php b/application/views/user/add.php index a90f2714..428e6660 100644 --- a/application/views/user/add.php +++ b/application/views/user/add.php @@ -28,7 +28,7 @@