improvements to multi user support of stations/logbooks
- Set active logbooks checks if logbook belongs to user - Link station to logbook checks that station and logbook belong to user - Unlink station from logbook checks that station and logbook belong to user - Edit of logbook only shows stations of user - Set active station checks if station belongs to user - find_active and find_gridsquare of Stations model now check user
这个提交包含在:
父节点
10969f7572
当前提交
9ed56e7211
共有 3 个文件被更改,包括 97 次插入 和 32 次删除
|
|
@ -53,7 +53,7 @@ class Logbooks extends CI_Controller {
|
|||
{
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->load->model('logbooks_model');
|
||||
$this->load->model('logbooks_model');
|
||||
$this->load->model('stations');
|
||||
|
||||
$station_logbook_id = $this->security->xss_clean($id);
|
||||
|
|
@ -62,7 +62,7 @@ class Logbooks extends CI_Controller {
|
|||
$data['station_locations_array'] = $this->logbooks_model->list_logbook_relationships($station_logbook_id);
|
||||
|
||||
$data['station_logbook_details'] = $station_logbook_details_query->row();
|
||||
$data['station_locations_list'] = $this->stations->all();
|
||||
$data['station_locations_list'] = $this->stations->all_of_user();
|
||||
|
||||
$data['station_locations_linked'] = $this->logbooks_model->list_logbooks_linked($station_logbook_id);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,40 +26,51 @@ class Logbooks_model extends CI_Model {
|
|||
$this->db->insert('station_logbooks', $data);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
function delete($id) {
|
||||
// Clean ID
|
||||
$clean_id = $this->security->xss_clean($id);
|
||||
|
||||
// Delete QSOs
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('logbook_id', $id);
|
||||
$this->db->delete('station_logbooks');
|
||||
}
|
||||
|
||||
function edit() {
|
||||
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('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) {
|
||||
// Clean input
|
||||
$cleanId = xss_clean($id);
|
||||
|
||||
// be sure that logbook belongs to user
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('logbook_id', $cleanId);
|
||||
$query = $this->db->get('station_logbooks');
|
||||
if ($query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'active_station_logbook' => xss_clean($id),
|
||||
'active_station_logbook' => $cleanId,
|
||||
);
|
||||
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->update('users', $data);
|
||||
}
|
||||
|
||||
function logbook($id) {
|
||||
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('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('logbook_id', $clean_id);
|
||||
return $this->db->get('station_logbooks');
|
||||
}
|
||||
|
|
@ -67,10 +78,30 @@ class Logbooks_model extends CI_Model {
|
|||
|
||||
// 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
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('logbook_id', $clean_logbook_id);
|
||||
$query = $this->db->get('station_logbooks');
|
||||
if ($query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// be sure that station belongs to user
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_id', $clean_location_id);
|
||||
$query = $this->db->get('station_profile');
|
||||
if ($query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create data array with field values
|
||||
$data = array(
|
||||
'station_logbook_id' => $logbook_id,
|
||||
'station_location_id' => $location_id,
|
||||
'station_logbook_id' => $clean_logbook_id,
|
||||
'station_location_id' => $clean_location_id,
|
||||
);
|
||||
|
||||
// Insert Record
|
||||
|
|
@ -139,6 +170,22 @@ class Logbooks_model extends CI_Model {
|
|||
$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
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('logbook_id', $clean_logbook_id);
|
||||
$query = $this->db->get('station_logbooks');
|
||||
if ($query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// be sure that station belongs to user
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_id', $clean_station_id);
|
||||
$query = $this->db->get('station_profile');
|
||||
if ($query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Delete QSOs
|
||||
$this->db->where('station_logbook_id', $clean_logbook_id);
|
||||
$this->db->where('station_location_id', $clean_station_id);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@ class Stations extends CI_Model {
|
|||
return $this->db->get('station_profile');
|
||||
}
|
||||
|
||||
function all_of_user() {
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
return $this->db->get('station_profile');
|
||||
}
|
||||
|
||||
function profile($id) {
|
||||
// Clean ID
|
||||
$clean_id = $this->security->xss_clean($id);
|
||||
|
|
@ -129,54 +134,67 @@ class Stations extends CI_Model {
|
|||
}
|
||||
|
||||
function set_active($current, $new) {
|
||||
|
||||
// Clean inputs
|
||||
|
||||
$clean_current = $this->security->xss_clean($current);
|
||||
$clean_new = $this->security->xss_clean($new);
|
||||
|
||||
// Deselect current default
|
||||
// be sure that stations belong to user
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where_in('station_id', array($clean_current, $clean_new));
|
||||
$query = $this->db->get('station_profile');
|
||||
if ($clean_current == 0 && $query->num_rows() != 1) {
|
||||
return;
|
||||
}
|
||||
if ($clean_current != 0 && $query->num_rows() != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Deselect current default
|
||||
$current_default = array(
|
||||
'station_active' => null,
|
||||
'station_active' => null,
|
||||
);
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_id', $clean_current);
|
||||
$this->db->update('station_profile', $current_default);
|
||||
|
||||
|
||||
// Deselect current default
|
||||
$newdefault = array(
|
||||
'station_active' => 1,
|
||||
);
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_id', $clean_new);
|
||||
$this->db->update('station_profile', $newdefault);
|
||||
}
|
||||
}
|
||||
|
||||
public function find_active() {
|
||||
$this->db->where('station_active', 1);
|
||||
$query = $this->db->get('station_profile');
|
||||
|
||||
if($query->num_rows() >= 1) {
|
||||
foreach ($query->result() as $row)
|
||||
public function find_active() {
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_active', 1);
|
||||
$query = $this->db->get('station_profile');
|
||||
|
||||
if($query->num_rows() >= 1) {
|
||||
foreach ($query->result() as $row)
|
||||
{
|
||||
return $row->station_id;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
public function find_gridsquare() {
|
||||
$this->db->where('station_active', 1);
|
||||
$query = $this->db->get('station_profile');
|
||||
|
||||
if($query->num_rows() >= 1) {
|
||||
foreach ($query->result() as $row)
|
||||
$this->db->where('user_id', $this->session->userdata('user_id'));
|
||||
$this->db->where('station_active', 1);
|
||||
$query = $this->db->get('station_profile');
|
||||
|
||||
if($query->num_rows() >= 1) {
|
||||
foreach ($query->result() as $row)
|
||||
{
|
||||
return $row->station_gridsquare;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function reassign($id) {
|
||||
// Clean ID
|
||||
|
|
|
|||
正在加载…
在新工单中引用