Squashed commit of the following: commit 29e5f5118a1c3f8deb623e5948c3b7602241792d Merge: 566b390de0a04cbeAuthor: phl0 <github@florian-wolters.de> Date: Mon Apr 24 23:28:31 2023 +0200 Merge remote-tracking branch 'upstream/dev' into removeRedundantDxccNames commit 566b390d8b0322b32f4438994354ce902010c0d4 Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 23:18:28 2023 +0200 Refactor reassign function to use DXCC name from dxcc_entities commit 2e50b34c1bdb9bb087e0e0d16f13c340c15588fb Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 22:05:12 2023 +0200 Use DXCC name from DXCC entities upon import commit d2b1d895818777747db593848b855819f53ffe6d Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 21:18:53 2023 +0200 Add DB migration script commit 0ecf4b8d9cf0253c1f818a252f7ae83722254544 Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 18:16:55 2023 +0200 Fix export function for requests QSLs commit 51d2c5c6175a8e8c69b9edd57d6f1e95c4a03600 Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 17:53:50 2023 +0200 Fix webadif/qrz upload commit 45039a6b1284d1a23f610fc70a39ef25ce720cab Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 17:32:40 2023 +0200 Fix lotw_export function commit 1306225d027cacbe70e510fd0fc5d3ca5040c35e Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 17:21:37 2023 +0200 Fix SIG export function commit 082798a80d8bb446500dcbadfa4912c510e4a458 Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 17:01:42 2023 +0200 Fix SAT export functions commit 2f035afaa3d3c74ca811c96c66f7bf9726b31a78 Merge: 87555f20d6139439Author: phl0 <github@florian-wolters.de> Date: Mon Apr 24 16:52:43 2023 +0200 Merge remote-tracking branch 'upstream/dev' into removeRedundantDxccNames commit 87555f201817fb963be117ab193d42bc03889972 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 23:54:14 2023 +0200 Use DXCC entity name from dxcc_entities in ADIF export commit e2fd1c5eb9b7e3257ed016814719bc7f9b913587 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 23:36:16 2023 +0200 Make logbooks use DXCC name from entities table commit 463057523dacbc34a545f0d9f720f2c29c9883a7 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 23:01:58 2023 +0200 Use DXCC name from separate table in QSO view commit 62b8f7aed8c1dca426b055eb7af6360106fc022b Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 18:21:57 2023 +0200 Add table join to station profile lookup commit 0afe155f46f1fcd227446166b215a98729494dc8 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 18:13:35 2023 +0200 Remove country name from edit functions commit ecb3689a0a73f0cc9c5ca7eba5dec7df5f9fbcd1 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 18:07:58 2023 +0200 Remove station_country parameter commit 22c350a585a3ff95d1d0b1f49dbe8ca310bdaf85 Author: phl0 <github@florian-wolters.de> Date: Thu Apr 20 17:59:24 2023 +0200 Use DXCC name from dxcc_entitites table
312 行
7.9 KiB
PHP
312 行
7.9 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
class Logbooks_model extends CI_Model {
|
|
|
|
function show_all() {
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
return $this->db->get('station_logbooks');
|
|
}
|
|
|
|
function CountAllStationLogbooks() {
|
|
// count all logbooks
|
|
$this->db->where('user_id =', NULL);
|
|
$query = $this->db->get('station_logbooks');
|
|
return $query->num_rows();
|
|
}
|
|
|
|
function add() {
|
|
// Create data array with field values
|
|
$data = array(
|
|
'user_id' => $this->session->userdata('user_id'),
|
|
'logbook_name' => xss_clean($this->input->post('stationLogbook_Name', true)),
|
|
);
|
|
|
|
// Insert Records
|
|
$this->db->insert('station_logbooks', $data);
|
|
$logbook_id = $this->db->insert_id();
|
|
|
|
// check if user has no active logbook yet
|
|
if ($this->session->userdata('active_station_logbook') === null) {
|
|
// set logbook active
|
|
$this->set_logbook_active($logbook_id);
|
|
|
|
// update user session data
|
|
$CI =& get_instance();
|
|
$CI->load->model('user_model');
|
|
$CI->user_model->update_session($this->session->userdata('user_id'));
|
|
}
|
|
}
|
|
|
|
function CreateDefaultLogbook() {
|
|
// Get the first USER ID from user table in the database
|
|
$id = $this->db->get("users")->row()->user_id;
|
|
|
|
$data = array(
|
|
'user_id' => $id,
|
|
'logbook_name' => "Default Logbook",
|
|
);
|
|
|
|
$this->db->insert('station_logbooks', $data);
|
|
$logbook_id = $this->db->insert_id();
|
|
|
|
$this->set_logbook_active($logbook_id, $id);
|
|
}
|
|
|
|
function delete($id) {
|
|
// Clean ID
|
|
$clean_id = $this->security->xss_clean($id);
|
|
|
|
// do not delete active logbook
|
|
if ($this->session->userdata('active_station_logbook') === $clean_id) {
|
|
return;
|
|
}
|
|
|
|
// Delete logbook
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', $id);
|
|
$this->db->delete('station_logbooks');
|
|
}
|
|
|
|
function edit() {
|
|
$data = array(
|
|
'logbook_name' => xss_clean($this->input->post('station_logbook_name', true)),
|
|
);
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', xss_clean($this->input->post('logbook_id', true)));
|
|
$this->db->update('station_logbooks', $data);
|
|
}
|
|
|
|
function set_logbook_active($id, $user_id = null) {
|
|
// Clean input
|
|
$cleanId = xss_clean($id);
|
|
|
|
// check if user_id is set
|
|
if ($user_id === null) {
|
|
$user_id = $this->session->userdata('user_id');
|
|
} else {
|
|
$user_id = xss_clean($user_id);
|
|
}
|
|
|
|
// be sure that logbook belongs to user
|
|
if (!$this->check_logbook_is_accessible($cleanId)) {
|
|
return;
|
|
}
|
|
|
|
$data = array(
|
|
'active_station_logbook' => $cleanId,
|
|
);
|
|
|
|
$this->db->where('user_id', $user_id);
|
|
$this->db->update('users', $data);
|
|
}
|
|
|
|
function logbook($id) {
|
|
// Clean ID
|
|
$clean_id = $this->security->xss_clean($id);
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', $clean_id);
|
|
return $this->db->get('station_logbooks');
|
|
}
|
|
|
|
function find_name($id) {
|
|
// Clean ID
|
|
$clean_id = $this->security->xss_clean($id);
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', $clean_id);
|
|
$query = $this->db->get('station_logbooks');
|
|
if ($query->num_rows() > 0){
|
|
foreach ($query->result() as $row)
|
|
{
|
|
return $row->logbook_name;
|
|
}
|
|
}
|
|
else{
|
|
return "n/a";
|
|
}
|
|
}
|
|
|
|
// Creates relationship between a logbook and a station location
|
|
function create_logbook_location_link($logbook_id, $location_id) {
|
|
// Clean ID
|
|
$clean_logbook_id = $this->security->xss_clean($logbook_id);
|
|
$clean_location_id = $this->security->xss_clean($location_id);
|
|
|
|
// be sure that logbook belongs to user
|
|
if (!$this->check_logbook_is_accessible($clean_logbook_id)) {
|
|
return;
|
|
}
|
|
|
|
// be sure that station belongs to user
|
|
$CI =& get_instance();
|
|
$CI->load->model('Stations');
|
|
if (!$CI->Stations->check_station_is_accessible($clean_location_id)) {
|
|
return;
|
|
}
|
|
|
|
// Create data array with field values
|
|
$data = array(
|
|
'station_logbook_id' => $clean_logbook_id,
|
|
'station_location_id' => $clean_location_id,
|
|
);
|
|
|
|
// Insert Record
|
|
$this->db->insert('station_logbooks_relationship', $data);
|
|
}
|
|
|
|
function relationship_exists($logbook_id, $location_id) {
|
|
$this->db->where('station_logbook_id', $logbook_id);
|
|
$this->db->where('station_location_id', $location_id);
|
|
$query = $this->db->get('station_logbooks_relationship');
|
|
|
|
if ($query->num_rows() > 0){
|
|
return true;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function public_slug_exists($slug) {
|
|
$this->db->where('public_slug', $this->security->xss_clean($slug));
|
|
$query = $this->db->get('station_logbooks');
|
|
|
|
if ($query->num_rows() > 0){
|
|
return true;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function public_slug_exists_logbook_id($slug) {
|
|
$this->db->where('public_slug', $this->security->xss_clean($slug));
|
|
$query = $this->db->get('station_logbooks');
|
|
|
|
if ($query->num_rows() > 0){
|
|
foreach ($query->result() as $row)
|
|
{
|
|
return $row->logbook_id;
|
|
}
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function is_public_slug_available($slug) {
|
|
// Clean public_slug
|
|
$clean_slug = $this->security->xss_clean($slug);
|
|
$this->db->where('public_slug', $clean_slug);
|
|
$query = $this->db->get('station_logbooks');
|
|
|
|
if ($query->num_rows() > 0){
|
|
return false;
|
|
}
|
|
else{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function save_public_slug($public_slug, $logbook_id) {
|
|
$data = array(
|
|
'public_slug' => xss_clean($public_slug),
|
|
);
|
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', xss_clean($logbook_id));
|
|
$this->db->update('station_logbooks', $data);
|
|
}
|
|
|
|
function remove_public_slug($logbook_id) {
|
|
|
|
$this->db->set('public_slug', null);
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', xss_clean($logbook_id));
|
|
$this->db->update('station_logbooks');
|
|
}
|
|
|
|
function list_logbook_relationships($logbook_id) {
|
|
|
|
$relationships_array = array();
|
|
|
|
$this->db->where('station_logbook_id', $logbook_id);
|
|
$query = $this->db->get('station_logbooks_relationship');
|
|
|
|
if ($query->num_rows() > 0){
|
|
foreach ($query->result() as $row)
|
|
{
|
|
array_push($relationships_array, $row->station_location_id);
|
|
}
|
|
|
|
return $relationships_array;
|
|
}
|
|
else{
|
|
return array();
|
|
}
|
|
}
|
|
|
|
function list_logbooks_linked($logbook_id) {
|
|
|
|
$relationships_array = array();
|
|
|
|
$this->db->where('station_logbook_id', $logbook_id);
|
|
$query = $this->db->get('station_logbooks_relationship');
|
|
|
|
|
|
if ($query->num_rows() > 0){
|
|
foreach ($query->result() as $row)
|
|
{
|
|
array_push($relationships_array, $row->station_location_id);
|
|
}
|
|
|
|
$this->db->select('station_profile.*, dxcc_entities.name as station_country');
|
|
$this->db->where_in('station_id', $relationships_array);
|
|
$this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left');
|
|
$query = $this->db->get('station_profile');
|
|
|
|
return $query;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function delete_relationship($logbook_id, $station_id) {
|
|
// Clean ID
|
|
$clean_logbook_id = $this->security->xss_clean($logbook_id);
|
|
$clean_station_id = $this->security->xss_clean($station_id);
|
|
|
|
// be sure that logbook belongs to user
|
|
if (!$this->check_logbook_is_accessible($clean_logbook_id)) {
|
|
return;
|
|
}
|
|
|
|
// be sure that station belongs to user
|
|
$CI =& get_instance();
|
|
$CI->load->model('Stations');
|
|
if (!$CI->Stations->check_station_is_accessible($clean_station_id)) {
|
|
return;
|
|
}
|
|
|
|
// Delete relationship
|
|
$this->db->where('station_logbook_id', $clean_logbook_id);
|
|
$this->db->where('station_location_id', $clean_station_id);
|
|
$this->db->delete('station_logbooks_relationship');
|
|
}
|
|
|
|
public function check_logbook_is_accessible($id) {
|
|
// check if logbook belongs to user
|
|
$this->db->select('logbook_id');
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
|
$this->db->where('logbook_id', $id);
|
|
$query = $this->db->get('station_logbooks');
|
|
if ($query->num_rows() == 1) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
?>
|