[Options] Adds new Save & Update funcs to OptionsLib, Creates /options with the abilty to change the theme globally

pull/753/head
Peter Goodhall 2020-12-13 16:55:10 +00:00
rodzic b2d7565e63
commit a012d73df2
8 zmienionych plików z 225 dodań i 2 usunięć

Wyświetl plik

@ -20,8 +20,50 @@ class Options extends CI_Controller {
//echo $this->config->item('option_theme');
echo $this->optionslib->get_option('theme');
//echo $this->optionslib->get_option('theme');
$data['page_title'] = "Cloudlog Options";
$this->load->view('interface_assets/header', $data);
$this->load->view('options/index');
$this->load->view('interface_assets/footer');
}
function appearance() {
$data['page_title'] = "Cloudlog Options";
$data['sub_heading'] = "Appearance";
$this->load->view('interface_assets/header', $data);
$this->load->view('options/appearance');
$this->load->view('interface_assets/footer');
}
function appearance_save() {
$data['page_title'] = "Cloudlog Options";
$data['sub_heading'] = "Appearance";
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('theme', 'theme', 'required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('interface_assets/header', $data);
$this->load->view('options/appearance');
$this->load->view('interface_assets/footer');
}
else
{
$theme_update_status = $this->optionslib->update('theme', $this->input->post('theme'));
if($theme_update_status == TRUE) {
$this->session->set_flashdata('success', 'Theme changed to '.$this->input->post('theme'));
}
redirect('/options/appearance');
}
}
}

Wyświetl plik

@ -52,6 +52,37 @@ class OptionsLib {
return $options_result;
}
// Function to save new option to options table
function save($option_name, $option_value, $autoload) {
// Make Codeigniter functions available to library
$CI =& get_instance();
//Load the options model
$CI->load->model('options_model');
// call library function to save update
$result = $CI->options_model->save($option_name, $option_value, $autoload);
// return True or False on whether its completed.
return $result;
}
// Function to update options within the options table
function update($option_name, $option_value) {
// Make Codeigniter functions available to library
$CI =& get_instance();
//Load the options model
$CI->load->model('options_model');
// call library function to save update
$result = $CI->options_model->update($option_name, $option_value);
// return True or False on whether its completed.
return $result;
}
// This returns the global theme or the theme stored in the logged in users session data.
function get_theme() {
// Make Codeigniter functions available to library

Wyświetl plik

@ -28,6 +28,67 @@ class Options_model extends CI_Model {
return $row->option_value;
}
/*
*
* Saves an option to the database
*
* Parameters
* - option_name: name of the option with no spaces
* - option_value: the value of the option name
* - autoload: this is whether it needs to be loaded every page load set to yes or no
*/
function save($option_name, $option_value, $autoload) {
$this->db->where('option_name', $option_name);
$query = $this->db->get('options');
if($query->num_rows() > 0) {
// Update the Entry
return FALSE;
} else {
$data = array(
'option_name' => $option_name,
'option_value' => $option_value,
'autoload' => $autoload,
);
// Save to database
$this->db->insert('options', $data);
return TRUE;
}
}
/*
*
* Saves an update to option
*
* Parameters
* - option_name: name of the option with no spaces
* - option_value: the value of the option name
*/
function update($option_name, $option_value) {
$this->db->where('option_name', $option_name);
$query = $this->db->get('options');
if($query->num_rows() > 0) {
// Update the Entry
$data = array(
'option_name' => $option_name,
'option_value' => $option_value,
);
$this->db->where('option_name', $option_name);
$this->db->update('options', $data);
return TRUE;
} else {
// Save to database
$this->db->insert('options', $data);
return FALSE;
}
}
}
?>

Wyświetl plik

@ -125,7 +125,11 @@
<a class="dropdown-item" href="<?php echo site_url('user');?>" title="Manage user accounts"><i class="fas fa-user"></i> User Accounts</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('options');?>" title="Manage global options"><i class="fas fa-cog"></i> Global Options</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('api/help');?>" title="Manage API keys"><i class="fas fa-key"></i> API</a>
<div class="dropdown-divider"></div>

Wyświetl plik

@ -0,0 +1,58 @@
<div class="container settings">
<div class="row">
<!-- Nav Start -->
<?php $this->load->view('options/sidebar') ?>
<!-- Nav End -->
<!-- Content -->
<div class="col-md-9">
<div class="card">
<div class="card-header"><h2><?php echo $page_title; ?> - <?php echo $sub_heading; ?></h2></div>
<div class="card-body">
<?php if($this->session->flashdata('success')) { ?>
<!-- Display Success Message -->
<div class="alert alert-success">
<?php echo $this->session->flashdata('success'); ?>
</div>
<?php } ?>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<?php echo $this->session->flashdata('message'); ?>
</div>
<?php } ?>
<?php if(validation_errors()) { ?>
<div class="alert alert-danger">
<a class="close" data-dismiss="alert">x</a>
<?php echo validation_errors(); ?>
</div>
<?php } ?>
<?php echo form_open('options/appearance_save'); ?>
<!-- Form options for selecting global theme choice -->
<div class="form-group">
<label for="themeSelect">Theme</label>
<select class="custom-select" id="themeSelect" name="theme" aria-describedby="themeHelp" required>
<option value='default' <?php if($this->optionslib->get_option('theme') == "default") { echo "selected=\"selected\""; } ?>>Default</option>
<option value='blue' <?php if($this->optionslib->get_option('theme')== "blue") { echo "selected=\"selected\""; } ?>>Blue</option>
<option value='cosmo' <?php if($this->optionslib->get_option('theme') == "cosmo") { echo "selected=\"selected\""; } ?>>Cosmo</option>
<option value='cyborg' <?php if($this->optionslib->get_option('theme') == "cyborg") { echo "selected=\"selected\""; } ?>>Cyborg (Dark)</option>
<option value='darkly' <?php if($this->optionslib->get_option('theme') == "darkly") { echo "selected=\"selected\""; } ?>> Darkly (Dark)</option>
<option value='superhero' <?php if($this->optionslib->get_option('theme') == "superhero") { echo "selected=\"selected\""; } ?>>Superhero (Dark)</option>
</select>
<small id="themeHelp" class="form-text text-muted">Global Theme Choice, this is used when users arent logged in.</small>
</div>
<!-- Save the Form -->
<input class="btn btn-primary" type="submit" value="Save" />
</form>
</div>
</div>
</div>
</div>
</div>

Wyświetl plik

@ -0,0 +1,20 @@
<div class="container settings">
<div class="row">
<!-- Nav Start -->
<?php $this->load->view('options/sidebar') ?>
<!-- Nav End -->
<!-- Content -->
<div class="col-md-9">
<div class="card">
<div class="card-header"><h2 class="card-title"><?php echo $page_title; ?></h2></div>
<div class="card-body">
<p>Cloudlog Options are global settings used for all users of the installation, which are overriddden if theres a setting on a user level.</p>
</div>
</div>
</div>
</div>
</div>

Wyświetl plik

@ -0,0 +1,7 @@
<div class="col-md-3">
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item"><a class="nav-link" href="<?php echo site_url('options/appearance'); ?>">Appearance</a></li>
</ul>
</div>
</div>