2021-08-12 19:17:18 +00:00
|
|
|
<?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');
|
|
|
|
}
|
2021-08-12 19:36:01 +00:00
|
|
|
|
2022-10-09 15:46:37 +00:00
|
|
|
function CountAllStationLogbooks() {
|
|
|
|
// count all logbooks
|
2022-10-11 16:10:44 +00:00
|
|
|
$this->db->where('user_id =', NULL);
|
2022-10-11 15:54:32 +00:00
|
|
|
$query = $this->db->get('station_logbooks');
|
|
|
|
return $query->num_rows();
|
2022-10-09 15:46:37 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 16:14:57 +00:00
|
|
|
function add() {
|
2021-08-12 19:36:01 +00:00
|
|
|
// 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
|
2021-12-04 16:14:57 +00:00
|
|
|
$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'));
|
|
|
|
}
|
2021-08-12 19:36:01 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 15:46:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
function delete($id) {
|
2021-08-12 19:36:01 +00:00
|
|
|
// Clean ID
|
|
|
|
$clean_id = $this->security->xss_clean($id);
|
|
|
|
|
2021-12-04 16:14:57 +00:00
|
|
|
// do not delete active logbook
|
|
|
|
if ($this->session->userdata('active_station_logbook') === $clean_id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete logbook
|
2021-10-31 08:56:45 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2021-08-12 19:36:01 +00:00
|
|
|
$this->db->where('logbook_id', $id);
|
|
|
|
$this->db->delete('station_logbooks');
|
|
|
|
}
|
2021-08-12 20:10:43 +00:00
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
function edit() {
|
2021-08-12 20:10:43 +00:00
|
|
|
$data = array(
|
|
|
|
'logbook_name' => xss_clean($this->input->post('station_logbook_name', true)),
|
|
|
|
);
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2021-08-12 20:10:43 +00:00
|
|
|
$this->db->where('logbook_id', xss_clean($this->input->post('logbook_id', true)));
|
|
|
|
$this->db->update('station_logbooks', $data);
|
|
|
|
}
|
|
|
|
|
2022-10-09 15:46:37 +00:00
|
|
|
function set_logbook_active($id, $user_id = null) {
|
2021-10-31 08:56:45 +00:00
|
|
|
// Clean input
|
|
|
|
$cleanId = xss_clean($id);
|
|
|
|
|
2022-10-09 15:46:37 +00:00
|
|
|
// check if user_id is set
|
|
|
|
if ($user_id === null) {
|
|
|
|
$user_id = $this->session->userdata('user_id');
|
|
|
|
} else {
|
|
|
|
$user_id = xss_clean($user_id);
|
|
|
|
}
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
// be sure that logbook belongs to user
|
2021-10-31 09:17:14 +00:00
|
|
|
if (!$this->check_logbook_is_accessible($cleanId)) {
|
2021-10-31 08:56:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-07 17:07:48 +00:00
|
|
|
$data = array(
|
2021-10-31 08:56:45 +00:00
|
|
|
'active_station_logbook' => $cleanId,
|
2021-09-07 17:07:48 +00:00
|
|
|
);
|
|
|
|
|
2022-10-09 15:46:37 +00:00
|
|
|
$this->db->where('user_id', $user_id);
|
2021-09-07 17:07:48 +00:00
|
|
|
$this->db->update('users', $data);
|
|
|
|
}
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
function logbook($id) {
|
2021-08-12 20:10:43 +00:00
|
|
|
// Clean ID
|
|
|
|
$clean_id = $this->security->xss_clean($id);
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
$this->db->where('user_id', $this->session->userdata('user_id'));
|
2021-08-12 20:10:43 +00:00
|
|
|
$this->db->where('logbook_id', $clean_id);
|
|
|
|
return $this->db->get('station_logbooks');
|
|
|
|
}
|
2021-09-07 16:42:35 +00:00
|
|
|
|
2022-05-02 10:38:55 +00:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
2021-09-07 16:42:35 +00:00
|
|
|
|
|
|
|
// Creates relationship between a logbook and a station location
|
|
|
|
function create_logbook_location_link($logbook_id, $location_id) {
|
2021-10-31 08:56:45 +00:00
|
|
|
// 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
|
2021-10-31 09:17:14 +00:00
|
|
|
if (!$this->check_logbook_is_accessible($clean_logbook_id)) {
|
2021-10-31 08:56:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// be sure that station belongs to user
|
2021-10-31 09:17:14 +00:00
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('Stations');
|
|
|
|
if (!$CI->Stations->check_station_is_accessible($clean_location_id)) {
|
2021-10-31 08:56:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-09-07 16:42:35 +00:00
|
|
|
// Create data array with field values
|
|
|
|
$data = array(
|
2021-10-31 08:56:45 +00:00
|
|
|
'station_logbook_id' => $clean_logbook_id,
|
|
|
|
'station_location_id' => $clean_location_id,
|
2021-09-07 16:42:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-24 14:26:03 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2022-02-09 22:29:29 +00:00
|
|
|
|
|
|
|
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');
|
2022-02-09 22:51:46 +00:00
|
|
|
|
2022-02-09 22:29:29 +00:00
|
|
|
if ($query->num_rows() > 0){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-10 15:11:40 +00:00
|
|
|
function save_public_search($public_search, $logbook_id) {
|
|
|
|
$data = array(
|
|
|
|
'public_search' => xss_clean($public_search),
|
|
|
|
);
|
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2022-02-09 22:51:46 +00:00
|
|
|
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));
|
2022-10-15 18:50:20 +00:00
|
|
|
$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');
|
2022-02-09 22:51:46 +00:00
|
|
|
}
|
|
|
|
|
2021-09-07 16:42:35 +00:00
|
|
|
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{
|
2022-07-02 21:40:04 +00:00
|
|
|
return array();
|
2021-09-07 16:42:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-12 14:19:39 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2023-04-27 07:47:09 +00:00
|
|
|
$this->db->select('station_profile.*, dxcc_entities.name as station_country, dxcc_entities.end as end');
|
2021-10-12 14:19:39 +00:00
|
|
|
$this->db->where_in('station_id', $relationships_array);
|
2023-04-27 07:47:09 +00:00
|
|
|
$this->db->join('dxcc_entities','station_profile.station_dxcc = dxcc_entities.adif','left outer');
|
2021-10-12 14:19:39 +00:00
|
|
|
$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);
|
|
|
|
|
2021-10-31 08:56:45 +00:00
|
|
|
// be sure that logbook belongs to user
|
2021-10-31 09:17:14 +00:00
|
|
|
if (!$this->check_logbook_is_accessible($clean_logbook_id)) {
|
2021-10-31 08:56:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// be sure that station belongs to user
|
2021-10-31 09:17:14 +00:00
|
|
|
$CI =& get_instance();
|
|
|
|
$CI->load->model('Stations');
|
|
|
|
if (!$CI->Stations->check_station_is_accessible($clean_station_id)) {
|
2021-10-31 08:56:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-31 09:17:14 +00:00
|
|
|
// Delete relationship
|
2021-10-12 14:19:39 +00:00
|
|
|
$this->db->where('station_logbook_id', $clean_logbook_id);
|
|
|
|
$this->db->where('station_location_id', $clean_station_id);
|
|
|
|
$this->db->delete('station_logbooks_relationship');
|
|
|
|
}
|
2021-10-31 09:17:14 +00:00
|
|
|
|
|
|
|
public function check_logbook_is_accessible($id) {
|
2021-11-14 16:50:11 +00:00
|
|
|
// check if logbook belongs to user
|
|
|
|
$this->db->select('logbook_id');
|
2021-10-31 09:17:14 +00:00
|
|
|
$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;
|
|
|
|
}
|
2023-04-27 19:08:09 +00:00
|
|
|
|
|
|
|
public function find_active_station_logbook_from_userid($userid) {
|
|
|
|
$this->db->select('active_station_logbook');
|
|
|
|
$this->db->where('user_id', $userid);
|
|
|
|
$query = $this->db->get('users');
|
|
|
|
if ($query->num_rows() > 0){
|
|
|
|
foreach ($query->result() as $row)
|
|
|
|
{
|
|
|
|
return $row->active_station_logbook;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2023-07-10 15:11:40 +00:00
|
|
|
|
|
|
|
function public_search_enabled($logbook_id) {
|
|
|
|
$this->db->select('public_search');
|
|
|
|
$this->db->where('logbook_id', $logbook_id);
|
|
|
|
|
|
|
|
$query = $this->db->get('station_logbooks');
|
|
|
|
|
|
|
|
return $query->result_array()[0]['public_search'];
|
|
|
|
}
|
2021-08-12 19:17:18 +00:00
|
|
|
}
|
2022-05-02 10:38:55 +00:00
|
|
|
?>
|