[Custom CSS Theme Support] Added user interface for add/edit/delete theme

pull/1127/head
Andreas 2021-08-09 14:29:53 +02:00
rodzic 5995b169c6
commit d24eeafcdf
7 zmienionych plików z 353 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,89 @@
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
This controller will contain features for contesting
*/
class Themes extends CI_Controller {
function __construct()
{
parent::__construct();
$this->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);
}
}

Wyświetl plik

@ -0,0 +1,56 @@
<?php
class Themes_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
// FUNCTION: array getThemes()
// Returns a list of themes
function getThemes() {
$result = $this->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);
}
}

Wyświetl plik

@ -2025,6 +2025,71 @@ function deleteQsl(id) {
<script src="<?php echo base_url() ;?>assets/js/sections/contestingnames.js"></script>
<?php } ?>
<?php if ($this->uri->segment(1) == "themes") { ?>
<script>
function deleteTheme(id, name) {
BootstrapDialog.confirm({
title: 'DANGER',
message: 'Warning! Are you sure you want to delete the following theme: ' + name + '?' ,
type: BootstrapDialog.TYPE_DANGER,
closable: true,
draggable: true,
btnOKClass: 'btn-danger',
callback: function(result) {
if(result) {
$.ajax({
url: base_url + 'index.php/themes/delete',
type: 'post',
data: {'id': id
},
success: function(data) {
$(".theme_" + id).parent("tr:first").remove(); // removes mode from table
}
});
}
}
});
}
function addThemeDialog() {
$.ajax({
url: base_url + 'index.php/themes/add',
type: 'post',
success: function(html) {
BootstrapDialog.show({
title: 'Create Theme',
size: BootstrapDialog.SIZE_WIDE,
cssClass: 'create-theme-dialog',
nl2br: false,
message: html,
buttons: [{
label: 'Close',
action: function (dialogItself) {
dialogItself.close();
}
}]
});
}
});
}
function addTheme(form) {
if (form.name.value != '') {
$.ajax({
url: base_url + 'index.php/themes/add',
type: 'post',
data: {
'name': form.name.value,
'foldername': form.foldername.value,
},
success: function(html) {
location.reload();
}
});
}
}
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "qslprint") { ?>
<script>
function deleteFromQslQueue(id) {

Wyświetl plik

@ -140,6 +140,10 @@
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('themes');?>" title="Manage Themes"><i class="fas fa-cog"></i> Themes</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="<?php echo site_url('backup');?>" title="Backup Cloudlog content"><i class="fas fa-save"></i> Backup</a>
<div class="dropdown-divider"></div>

Wyświetl plik

@ -0,0 +1,38 @@
<div class="container" id="create_mode">
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<?php if($this->session->flashdata('notice')) { ?>
<div id="message" >
<?php echo $this->session->flashdata('notice'); ?>
</div>
<?php } ?>
<?php $this->load->helper('form'); ?>
<?php echo validation_errors(); ?>
<form method="post" name="create_profile">
<div class="form-group">
<label for="nameInput">Theme Name</label>
<input type="text" class="form-control" name="name" id="nameInput" aria-describedby="nameInputHelp" required>
<small id="nameInputHelp" class="form-text text-muted">This is the name that is used to display the theme in the theme list.</small>
</div>
<div class="form-group">
<label for="foldernameInput">Folder Name</label>
<input type="text" class="form-control" name="foldername" id="foldernameInput" aria-describedby="foldernameInputHelp">
<small id="foldernameInputHelp" class="form-text text-muted">This is the name of the folder where your CSS-files are placed under assets/css.</small>
</div>
<button onclick="addTheme(this.form);" class="btn btn-primary"><i class="fas fa-plus-square"></i> Add theme</button>
</form>
</div>

Wyświetl plik

@ -0,0 +1,50 @@
<div class="container">
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<div class="card">
<div class="card-header">
<?php echo $page_title; ?>
</div>
<div class="card-body">
<h5 class="card-title"></h5>
<p class="card-text"></p>
<?php if($this->session->flashdata('notice')) { ?>
<div id="message" >
<?php echo $this->session->flashdata('notice'); ?>
</div>
<?php } ?>
<?php $this->load->helper('form'); ?>
<?php echo validation_errors(); ?>
<form method="post" action="<?php echo site_url('themes/edit/'); ?><?php echo $theme->id; ?>" name="edit_theme">
<div class="form-group">
<label for="themenameInput">Theme Name</label>
<input type="text" class="form-control" name="name" id="nameInput" aria-describedby="themenameInputHelp" value="<?php if(set_value('name') != "") { echo set_value('name'); } else { echo $theme->name; } ?>" required>
<small id="themenameInputHelp" class="form-text text-muted">This is the name that is used to display the theme in the theme list.</small>
</div>
<div class="form-group">
<label for="foldernameInput">Folder Name</label>
<input type="text" class="form-control" name="foldername" id="foldernameInput" aria-describedby="foldernameInputHelp" value="<?php if(set_value('foldername') != "") { echo set_value('foldername'); } else { echo $theme->foldername; } ?>">
<small id="foldernameInputHelp" class="form-text text-muted">This is the name of the folder where your CSS-files are placed under assets/css.</small>
</div>
<button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-plus-square"></i> Update Theme</button>
</form>
</div>
</div>
<br>
</div>

Wyświetl plik

@ -0,0 +1,51 @@
<div class="container">
<br>
<?php if($this->session->flashdata('message')) { ?>
<!-- Display Message -->
<div class="alert-message error">
<p><?php echo $this->session->flashdata('message'); ?></p>
</div>
<?php } ?>
<h2><?php echo $page_title; ?></h2>
<div class="card">
<div class="card-header">
Themes list
</div>
<div class="card-body">
<p class="card-text">
Using the theme list, you can control which Themes are shown in the account settings. Deleting a theme here, does not delete the css theme folder.
</p>
<div class="table-responsive">
<table style="width:100%" class="contesttable table table-sm table-striped">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Foldername</th>
<th scope="col"></th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php foreach ($themes as $theme) { ?>
<tr>
<td><?php echo $theme->name;?></td>
<td><?php echo $theme->foldername;?></td>
<td>
<a href="<?php echo site_url('themes/edit')."/".$theme->id; ?>" class="btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i> Edit</a>
</td>
<td class='theme_<?php echo $theme->id ?>'>
<a href="javascript:deleteTheme('<?php echo $theme->id; ?>', '<?php echo $theme->name; ?>');" class="btn btn-danger btn-sm" ><i class="fas fa-trash-alt"></i> Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
<table>
</div>
<br/>
<p><button onclick="addThemeDialog();" class="btn btn-primary btn-sm"><i class="fas fa-plus"></i> Add a Theme</button></p>
</div>
</div>