[Welcome] Hide Creating Logbooks or claiming locations

Hide Creating Logbooks or claiming locations if they are already in the database
这个提交包含在:
Peter Goodhall 2022-10-09 16:46:37 +01:00
父节点 cb4008c082
当前提交 b4f1f63098
共有 4 个文件被更改,包括 71 次插入11 次删除

查看文件

@ -13,6 +13,13 @@ class Welcome extends CI_Controller {
{
$data['page_title'] = "Welcome to Cloudlog Version 2.0";
// load stations model
$this->load->model('stations');
$data['CountAllStationLocations'] = $this->stations->CountAllStationLocations();
echo $data['CountAllStationLocations'];
$this->load->model('logbooks_model');
$data['NumberOfStationLogbooks'] = $this->logbooks_model->CountAllStationLogbooks();
$this->load->view('interface_assets/header', $data);
$this->load->view('welcome/index');
$this->load->view('interface_assets/footer');
@ -30,4 +37,17 @@ class Welcome extends CI_Controller {
echo "Error Claiming Station Locations during Migration. See Logs for further information";
}
}
public function defaultlogbook() {
try {
// load model Stations and call function ClaimAllStationLocations
$this->load->model('logbooks_model');
$this->logbooks_model->CreateDefaultLogbook();
echo "Default Logbook Created";
} catch (Exception $e) {
log_message('error', 'Error Creating Default Logbook during Migration. '.$e->getMessage());
echo "Error Creating Default Logbook during Migration. See Logs for further information";
}
}
}

查看文件

@ -7,6 +7,11 @@ class Logbooks_model extends CI_Model {
return $this->db->get('station_logbooks');
}
function CountAllStationLogbooks() {
// count all logbooks
return $this->db->count_all('station_logbooks');
}
function add() {
// Create data array with field values
$data = array(
@ -30,6 +35,21 @@ class Logbooks_model extends CI_Model {
}
}
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);
@ -55,10 +75,17 @@ class Logbooks_model extends CI_Model {
$this->db->update('station_logbooks', $data);
}
function set_logbook_active($id) {
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;
@ -68,7 +95,7 @@ class Logbooks_model extends CI_Model {
'active_station_logbook' => $cleanId,
);
$this->db->where('user_id', $this->session->userdata('user_id'));
$this->db->where('user_id', $user_id);
$this->db->update('users', $data);
}

查看文件

@ -148,7 +148,7 @@ class Stations extends CI_Model {
// Get the first USER ID from user table in the database
$id = $this->db->get("users")->row()->user_id;
}
$data = array(
'user_id' => $id,
);
@ -156,6 +156,13 @@ class Stations extends CI_Model {
$this->db->update('station_profile', $data);
}
function CountAllStationLocations() {
// count all logbooks
// where user_id is not NULL
$this->db->where('user_id !=', NULL);
return $this->db->count_all('station_logbooks');
}
function set_active($current, $new) {
// Clean inputs
$clean_current = $this->security->xss_clean($current);

查看文件

@ -90,6 +90,7 @@
<br>
<?php if($CountAllStationLocations == 0) { ?>
<div class="card">
<div class="card-header">Assign ALL Station Locations to this username</div>
<div class="card-body">
@ -99,15 +100,20 @@
</div>
<br>
<div class="card">
<div class="card-header">Create Station Logbooks</div>
<div class="card-body">
<p class="card-text">Needs Text</p>
</div>
</div>
<?php } ?>
<br>
<?php if($NumberOfStationLogbooks == 0) { ?>
<div class="card">
<div class="card-header">Create Station Logbooks</div>
<div class="card-body">
<p class="card-text">All the views now in Cloudlog are based around Station Logbooks, you can create as many as you want and group Station Locations it makes tracking awards a lot easier.</p>
<p class="card-text">You don't have one at the moment and it can cause issues so press the button below and create a default logbook, you can change this later!</p>
<button type="button" class="btn btn-primary" hx-post="<?php echo site_url('welcome/defaultlogbook'); ?>">Create a default logbook.</button>
</div>
</div>
<br>
<?php } ?>
<div class="card">
<div class="card-header">Update Country Files</div>