kopia lustrzana https://github.com/magicbug/Cloudlog
[Options] Greates OptionsLib library, sets default theme and others
This commit does a couple of things - Creates OptionsLib which stores the 'Options' within the CI config system prefixed with "options_" - Loads the OptionsLib automatically - Adds function to OptionsLib for selecting the active stylesheet. - Adds function to get an option_value that isn't automatically loaded.pull/753/head
rodzic
6e98adb755
commit
8dfaf47c79
|
@ -52,7 +52,7 @@ $autoload['packages'] = array(APPPATH.'third_party');
|
|||
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
|
||||
*/
|
||||
|
||||
$autoload['libraries'] = array('database', 'session', 'curl');
|
||||
$autoload['libraries'] = array('database', 'session', 'curl', 'OptionsLib');
|
||||
|
||||
|
||||
/*
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
Handles Displaying of information for station tools.
|
||||
*/
|
||||
|
||||
class Options extends CI_Controller {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->helper(array('form', 'url'));
|
||||
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
}
|
||||
|
||||
function index() {
|
||||
|
||||
|
||||
//echo $this->config->item('option_theme');
|
||||
|
||||
echo $this->optionslib->get_option('theme');
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/*
|
||||
Controls the interaction with the QRZ.com Subscription based XML API.
|
||||
*/
|
||||
|
||||
|
||||
class OptionsLib {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
// Make Codeigniter functions available to library
|
||||
$CI =& get_instance();
|
||||
|
||||
//Load the options model
|
||||
$CI->load->model('options_model');
|
||||
|
||||
// Store returned array of autoload options
|
||||
$options_result = $CI->options_model->get_autoloads();
|
||||
|
||||
// If results are greater than one
|
||||
if($options_result->num_rows() > 0) {
|
||||
// Loop through the array
|
||||
foreach ($options_result->result() as $item)
|
||||
{
|
||||
/*
|
||||
* Add option to the config system dynamicly option_name is prefixed by option_
|
||||
* you can then call $this->config->item('option_<option_name>') to get the item.
|
||||
*/
|
||||
|
||||
$CI->config->set_item('option_'.$item->option_name, $item->option_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This returns a options value based on its name
|
||||
function get_option($option_name) {
|
||||
// Make Codeigniter functions available to library
|
||||
$CI =& get_instance();
|
||||
|
||||
//Load the options model
|
||||
$CI->load->model('options_model');
|
||||
|
||||
// call library function to get options value
|
||||
$options_result = $CI->options_model->item($option_name);
|
||||
|
||||
// return option_value as a string
|
||||
return $options_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
|
||||
$CI =& get_instance();
|
||||
|
||||
// If session data for stylesheet is set return choice
|
||||
if($CI->session->userdata('user_stylesheet')) {
|
||||
return $CI->session->userdata('user_stylesheet');
|
||||
} else {
|
||||
// Return the global choice.
|
||||
return $CI->config->item('option_theme');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
Class: Options_model
|
||||
This model handles all database interactions for the options table
|
||||
used for global settings within cloudlog.
|
||||
*/
|
||||
|
||||
class Options_model extends CI_Model {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
// Returns all options that are autoload yes
|
||||
function get_autoloads() {
|
||||
$this->db->where('autoload', "yes");
|
||||
return $this->db->get('options');
|
||||
}
|
||||
|
||||
// Return option value for an option
|
||||
function item($option_name) {
|
||||
$this->db->where('option_name', $option_name);
|
||||
$query = $this->db->get('options');
|
||||
$row = $query->row();
|
||||
|
||||
return $row->option_value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -6,14 +6,10 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<?php if($this->session->userdata('user_stylesheet')) { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->session->userdata('user_stylesheet');?>/bootstrap.min.css">
|
||||
<?php if($this->optionslib->get_theme()) { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->optionslib->get_theme();?>/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/general.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->session->userdata('user_stylesheet');?>/overrides.css">
|
||||
<?php } else { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/default/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/general.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/default/overrides.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->optionslib->get_theme();?>/overrides.css">
|
||||
<?php } ?>
|
||||
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/fontawesome/css/all.css">
|
||||
|
|
|
@ -6,14 +6,10 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<?php if($this->session->userdata('user_stylesheet')) { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->session->userdata('user_stylesheet');?>/bootstrap.min.css">
|
||||
<?php if($this->optionslib->get_theme()) { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->optionslib->get_theme();?>/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/general.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->session->userdata('user_stylesheet');?>/overrides.css">
|
||||
<?php } else { ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/default/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/general.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/default/overrides.css">
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/css/<?php echo $this->optionslib->get_theme();?>/overrides.css">
|
||||
<?php } ?>
|
||||
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/fontawesome/css/all.css">
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue