Skip to content

Commit

Permalink
[Main menu] Added user option to hide notes in the main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
magicbug authored Mar 21, 2021
2 parents fb679a6 + 31e8eb9 commit ea01142
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion application/config/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 65;
$config['migration_version'] = 66;

/*
|--------------------------------------------------------------------------
Expand Down
11 changes: 10 additions & 1 deletion application/controllers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function add() {
$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');
$data['user_show_notes'] = $this->input->post('user_show_notes');
$this->load->view('user/add', $data);
} else {
$this->load->view('user/add', $data);
Expand All @@ -64,7 +65,7 @@ function add() {
}
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'), $this->input->post('user_sota_lookup'))) {
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'), $this->input->post('user_show_notes'))) {
// Check for errors
case EUSERNAMEEXISTS:
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
Expand Down Expand Up @@ -95,6 +96,7 @@ function add() {
$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');
$data['user_show_notes'] = $this->input->post('user_show_notes');
$this->load->view('user/add', $data);
$this->load->view('interface_assets/footer');
}
Expand Down Expand Up @@ -257,6 +259,12 @@ function edit() {
$data['user_sota_lookup'] = $q->user_sota_lookup;
}

if($this->input->post('user_show_notes')) {
$data['user_show_notes'] = $this->input->post('user_show_notes', true);
} else {
$data['user_show_notes'] = $q->user_show_notes;
}

$this->load->view('user/edit', $data);
$this->load->view('interface_assets/footer');
}
Expand Down Expand Up @@ -299,6 +307,7 @@ function edit() {
$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');
$data['user_show_notes'] = $this->input->post('user_show_notes');
$this->load->view('user/edit');
$this->load->view('interface_assets/footer');
}
Expand Down
25 changes: 25 additions & 0 deletions application/migrations/066_add_user_hide_notes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

defined('BASEPATH') OR exit('No direct script access allowed');

/*
* This migration creates a table called options which will hold global options needed within cloudlog
* removing the need for lots of configuration files.
*/

class Migration_add_user_hide_notes extends CI_Migration {

public function up()
{
$fields = array(
'user_show_notes integer DEFAULT 1',
);

$this->dbforge->add_column('users', $fields);
}

public function down()
{
$this->dbforge->drop_column('users', 'user_show_notes');
}
}
5 changes: 4 additions & 1 deletion application/models/User_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function exists_by_email($email) {

// 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, $user_sota_lookup) {
function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone, $measurement, $user_date_format, $user_stylesheet, $user_sota_lookup, $user_show_notes) {
// Check that the user isn't already used
if(!$this->exists($username)) {
$data = array(
Expand All @@ -113,6 +113,7 @@ function add($username, $password, $email, $type, $firstname, $lastname, $callsi
'user_date_format' => xss_clean($user_date_format),
'user_stylesheet' => xss_clean($user_stylesheet),
'user_sota_lookup' => xss_clean($user_sota_lookup),
'user_show_notes' => xss_clean($user_show_notes),
);

// Check the password is valid
Expand Down Expand Up @@ -155,6 +156,7 @@ function edit($fields) {
'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']),
'user_show_notes' => xss_clean($fields['user_show_notes']),
);

// Check to see if the user is allowed to change user levels
Expand Down Expand Up @@ -263,6 +265,7 @@ function update_session($id) {
'user_date_format' => $u->row()->user_date_format,
'user_stylesheet' => $u->row()->user_stylesheet,
'user_sota_lookup' => $u->row()->user_sota_lookup,
'user_show_notes' => $u->row()->user_show_notes,
);

$this->session->set_userdata($userdata);
Expand Down
3 changes: 2 additions & 1 deletion application/views/interface_assets/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
</li>

<!-- Notes -->
<?php if ($this->session->userdata('user_show_notes') == 1) { ?>
<a class="nav-link" href="<?php echo site_url('notes');?>">Notes</a>

<?php } ?>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Analytics</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
Expand Down
8 changes: 8 additions & 0 deletions application/views/user/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
<div class="small form-text text-muted">If this is set, name and gridsquare is fetched from the API and filled in location and locator.</div></td>
</div>

<div class="form-group">
<label for="shownotes">Show notes in the main menu.</label>
<select class="custom-select" id="shownotes" name="user_show_notes">
<option value="0"><?php echo $this->lang->line('general_word_no'); ?></option>
<option value="1"><?php echo $this->lang->line('general_word_yes'); ?></option>
</select>
</div>

<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />
<button type="submit" class="btn btn-primary">Create Account</button>
</form>
Expand Down
22 changes: 22 additions & 0 deletions application/views/user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@
</div>

</div>
<br>
<div class="row">
<!-- Club Log -->
<div class="col-md">
<div class="card">
<div class="card-header">
Main menu
</div>
<div class="card-body">
<div class="form-group">
<label for="shownotes">Show notes in the main menu.</label>
<select class="custom-select" id="shownotes" name="user_show_notes">
<option value="1" <?php if ($user_show_notes == 1) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_yes'); ?></option>
<option value="0" <?php if ($user_show_notes == 0) { echo " selected =\"selected\""; } ?>><?php echo $this->lang->line('general_word_no'); ?></option>
</select>
</div>

</div>
</div>
</div>

</div>

<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />
<br>
Expand Down

0 comments on commit ea01142

Please sign in to comment.