From a512a984aaf24e4b576a20966595078e037acdad Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Mon, 9 Aug 2021 13:13:41 +0200
Subject: [PATCH 1/4] [Custom CSS Theme Support] Added support for fetching
list of themes from database.
---
application/controllers/User.php | 6 ++++++
application/models/User_model.php | 8 ++++++++
application/views/user/add.php | 15 +++++++++------
application/views/user/edit.php | 15 +++++++++------
4 files changed, 32 insertions(+), 12 deletions(-)
diff --git a/application/controllers/User.php b/application/controllers/User.php
index 976ea38e..97059f73 100644
--- a/application/controllers/User.php
+++ b/application/controllers/User.php
@@ -42,6 +42,9 @@ class User extends CI_Controller {
$this->form_validation->set_rules('user_locator', 'Locator', 'required');
$this->form_validation->set_rules('user_timezone', 'Timezone', 'required');
+ // Get themes list
+ $data['themes'] = $this->user_model->getThemes();
+
// Get timezones
$data['timezones'] = $this->user_model->timezones();
@@ -158,6 +161,9 @@ class User extends CI_Controller {
$this->form_validation->set_rules('user_locator', 'Locator', 'required|xss_clean');
$this->form_validation->set_rules('user_timezone', 'Timezone', 'required');
+ // Get themes list
+ $data['themes'] = $this->user_model->getThemes();
+
// Get timezones
$data['timezones'] = $this->user_model->timezones();
diff --git a/application/models/User_model.php b/application/models/User_model.php
index ab368d51..ece9bc8c 100644
--- a/application/models/User_model.php
+++ b/application/models/User_model.php
@@ -370,6 +370,14 @@ class User_Model extends CI_Model {
return $ts;
}
+ // FUNCTION: array getThemes()
+ // Returns a list of themes
+ function getThemes() {
+ $result = $this->db->query('SELECT * FROM themes order by name');
+
+ return $result->result();
+ }
+
// FUNCTION: bool _auth($password, $hash)
// Checks a password against the stored hash
private function _auth($password, $hash) {
diff --git a/application/views/user/add.php b/application/views/user/add.php
index 7157053f..f6b9f09b 100644
--- a/application/views/user/add.php
+++ b/application/views/user/add.php
@@ -111,12 +111,15 @@
diff --git a/application/views/user/edit.php b/application/views/user/edit.php
index 3b879e71..20f7c379 100644
--- a/application/views/user/edit.php
+++ b/application/views/user/edit.php
@@ -94,12 +94,15 @@
From 5995b169c62c2bbdaa224bdbd5ff73e34b42ae45 Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Mon, 9 Aug 2021 13:26:04 +0200
Subject: [PATCH 2/4] [Custom CSS Theme Support] Added migration script for
creating the theme table
---
application/config/migration.php | 2 +-
application/migrations/071_theme_table.php | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
create mode 100644 application/migrations/071_theme_table.php
diff --git a/application/config/migration.php b/application/config/migration.php
index 5b216f92..227bc690 100644
--- a/application/config/migration.php
+++ b/application/config/migration.php
@@ -21,7 +21,7 @@ $config['migration_enabled'] = TRUE;
| be upgraded / downgraded to.
|
*/
-$config['migration_version'] = 70;
+$config['migration_version'] = 71;
/*
|--------------------------------------------------------------------------
diff --git a/application/migrations/071_theme_table.php b/application/migrations/071_theme_table.php
new file mode 100644
index 00000000..9bcf6ce8
--- /dev/null
+++ b/application/migrations/071_theme_table.php
@@ -0,0 +1,21 @@
+db->query("create table themes (id integer not null auto_increment, name varchar(256) not null, foldername varchar(256) not null, primary key (id)) ENGINE=myisam DEFAULT CHARSET=utf8;");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Blue','blue');");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Cosmo','cosmo');");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Cyborg (Dark)','cyborg');");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Darkly (Dark)','darkly');");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Default','default');");
+ $this->db->query("INSERT INTO themes (name, foldername) values ('Superhero (Dark)','superhero');");
+ }
+
+ public function down(){
+ $this->db->query("");
+
+ }
+}
From d24eeafcdf5271773bf9b59a0b16138c3215fe59 Mon Sep 17 00:00:00 2001
From: Andreas <6977712+AndreasK79@users.noreply.github.com>
Date: Mon, 9 Aug 2021 14:29:53 +0200
Subject: [PATCH 3/4] [Custom CSS Theme Support] Added user interface for
add/edit/delete theme
---
application/controllers/Themes.php | 89 +++++++++++++++++++
application/models/Themes_model.php | 56 ++++++++++++
application/views/interface_assets/footer.php | 65 ++++++++++++++
application/views/interface_assets/header.php | 4 +
application/views/themes/add.php | 38 ++++++++
application/views/themes/edit.php | 50 +++++++++++
application/views/themes/index.php | 51 +++++++++++
7 files changed, 353 insertions(+)
create mode 100644 application/controllers/Themes.php
create mode 100644 application/models/Themes_model.php
create mode 100644 application/views/themes/add.php
create mode 100644 application/views/themes/edit.php
create mode 100644 application/views/themes/index.php
diff --git a/application/controllers/Themes.php b/application/controllers/Themes.php
new file mode 100644
index 00000000..2420e689
--- /dev/null
+++ b/application/controllers/Themes.php
@@ -0,0 +1,89 @@
+lang->load('contesting');
+
+ $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'); }
+ }
+
+ public function index()
+ {
+ $this->load->model('Themes_model');
+
+ $data['themes'] = $this->Themes_model->getThemes();
+
+ // Render Page
+ $data['page_title'] = "Themes";
+ $this->load->view('interface_assets/header', $data);
+ $this->load->view('themes/index.php');
+ $this->load->view('interface_assets/footer');
+ }
+
+ public function add()
+ {
+ $this->load->model('Themes_model');
+ $this->load->library('form_validation');
+
+ $this->form_validation->set_rules('name', 'Theme Name', 'required');
+ $this->form_validation->set_rules('foldername', 'Folder Name', 'required');
+
+ if ($this->form_validation->run() == FALSE)
+ {
+ $data['page_title'] = "Create Theme";
+ $this->load->view('themes/add', $data);
+ }
+ else
+ {
+ $this->Themes_model->add();
+ }
+ }
+
+ public function edit($id)
+ {
+ $this->load->library('form_validation');
+
+ $this->load->model('Themes_model');
+
+ $item_id_clean = $this->security->xss_clean($id);
+
+ $data['theme'] = $this->Themes_model->theme($item_id_clean);
+
+ $data['page_title'] = "Edit Theme";
+
+ $this->form_validation->set_rules('name', 'Theme Name', 'required');
+ $this->form_validation->set_rules('foldername', 'Folder Name', 'required');
+
+ if ($this->form_validation->run() == FALSE)
+ {
+ $this->load->view('interface_assets/header', $data);
+ $this->load->view('themes/edit');
+ $this->load->view('interface_assets/footer');
+ }
+ else
+ {
+ $this->Themes_model->edit($item_id_clean);
+
+ $data['notice'] = "Theme ".$this->security->xss_clean($this->input->post('name', true))." Updated";
+
+ redirect('themes');
+ }
+ }
+
+ public function delete() {
+ $id = $this->input->post('id');
+ $this->load->model('Themes_model');
+ $this->Themes_model->delete($id);
+ }
+}
diff --git a/application/models/Themes_model.php b/application/models/Themes_model.php
new file mode 100644
index 00000000..8f34435c
--- /dev/null
+++ b/application/models/Themes_model.php
@@ -0,0 +1,56 @@
+db->query('SELECT * FROM themes order by name');
+
+ return $result->result();
+ }
+
+ function delete($id) {
+ // Clean ID
+ $clean_id = $this->security->xss_clean($id);
+
+ // Delete Theme
+ $this->db->delete('themes', array('id' => $clean_id));
+ }
+
+ function add() {
+ $data = array(
+ 'name' => xss_clean($this->input->post('name', true)),
+ 'foldername' => xss_clean($this->input->post('foldername', true)),
+ );
+
+ $this->db->insert('themes', $data);
+ }
+
+
+ function theme($id) {
+ // Clean ID
+ $clean_id = $this->security->xss_clean($id);
+
+ $sql = "SELECT * FROM themes where id =" . $clean_id;
+
+ $data = $this->db->query($sql);
+
+ return ($data->row());
+ }
+
+ function edit($id) {
+ $data = array(
+ 'name' => xss_clean($this->input->post('name', true)),
+ 'foldername' => xss_clean($this->input->post('foldername', true)),
+ );
+
+ $this->db->where('id', $id);
+ $this->db->update('themes', $data);
+ }
+}
diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php
index c8195c33..d6a6e15d 100644
--- a/application/views/interface_assets/footer.php
+++ b/application/views/interface_assets/footer.php
@@ -2025,6 +2025,71 @@ function deleteQsl(id) {
+uri->segment(1) == "themes") { ?>
+
+
uri->segment(1) == "qslprint") { ?>