From a012d73df2acb562ba3eeb5bc8f5336744b648cf Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Sun, 13 Dec 2020 16:55:10 +0000 Subject: [PATCH] [Options] Adds new Save & Update funcs to OptionsLib, Creates /options with the abilty to change the theme globally --- application/controllers/Options.php | 44 ++++++++++++- application/libraries/OptionsLib.php | 31 ++++++++++ application/models/Options_model.php | 61 +++++++++++++++++++ application/views/interface_assets/header.php | 6 +- application/views/options/appearance.php | 58 ++++++++++++++++++ application/views/options/index.php | 20 ++++++ application/views/options/sidebar.php | 7 +++ .../views/{Settings => settings}/index.php | 0 8 files changed, 225 insertions(+), 2 deletions(-) create mode 100644 application/views/options/appearance.php create mode 100644 application/views/options/index.php create mode 100644 application/views/options/sidebar.php rename application/views/{Settings => settings}/index.php (100%) diff --git a/application/controllers/Options.php b/application/controllers/Options.php index 2601f978f..38bfad9ef 100644 --- a/application/controllers/Options.php +++ b/application/controllers/Options.php @@ -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'); + } + } } \ No newline at end of file diff --git a/application/libraries/OptionsLib.php b/application/libraries/OptionsLib.php index 075af5cf8..62071c159 100644 --- a/application/libraries/OptionsLib.php +++ b/application/libraries/OptionsLib.php @@ -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 diff --git a/application/models/Options_model.php b/application/models/Options_model.php index e8b0e7688..717c0a783 100644 --- a/application/models/Options_model.php +++ b/application/models/Options_model.php @@ -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; + } + } + } ?> \ No newline at end of file diff --git a/application/views/interface_assets/header.php b/application/views/interface_assets/header.php index 39e608c76..7001f1e42 100644 --- a/application/views/interface_assets/header.php +++ b/application/views/interface_assets/header.php @@ -125,7 +125,11 @@ User Accounts - + + Global Options + + + API diff --git a/application/views/options/appearance.php b/application/views/options/appearance.php new file mode 100644 index 000000000..a61c1308e --- /dev/null +++ b/application/views/options/appearance.php @@ -0,0 +1,58 @@ +
+ +
+ + load->view('options/sidebar') ?> + + + +
+
+

-

+ +
+ session->flashdata('success')) { ?> + +
+ session->flashdata('success'); ?> +
+ + + session->flashdata('message')) { ?> + +
+ session->flashdata('message'); ?> +
+ + + +
+ x + +
+ + + + +
+ + + Global Theme Choice, this is used when users arent logged in. +
+ + + + +
+
+
+
+ +
\ No newline at end of file diff --git a/application/views/options/index.php b/application/views/options/index.php new file mode 100644 index 000000000..321b8a307 --- /dev/null +++ b/application/views/options/index.php @@ -0,0 +1,20 @@ +
+ +
+ + load->view('options/sidebar') ?> + + + +
+
+

+
+

Cloudlog Options are global settings used for all users of the installation, which are overriddden if theres a setting on a user level.

+
+
+ +
+
+ +
\ No newline at end of file diff --git a/application/views/options/sidebar.php b/application/views/options/sidebar.php new file mode 100644 index 000000000..0f185c99c --- /dev/null +++ b/application/views/options/sidebar.php @@ -0,0 +1,7 @@ +
+
+ +
+
\ No newline at end of file diff --git a/application/views/Settings/index.php b/application/views/settings/index.php similarity index 100% rename from application/views/Settings/index.php rename to application/views/settings/index.php