cloudlog/application/controllers/Themes.php
Peter Goodhall f5e3aac0d0 Cast IDs to int; use query builder
Normalize incoming ID parameters to integers and replace concatenated/raw SQL with CodeIgniter query builder. Controllers (Contesting.php, Themes.php) now cast $id to (int) instead of using xss_clean; models (Contesting_model.php, Themes_model.php) cast $id and use $this->db->where()/get()/select() to build queries. This improves type safety and reduces risk of injection while using more idiomatic CI DB APIs.
2026-06-24 22:08:30 +01:00

89 lines
2.1 KiB
PHP

<?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 = (int) $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);
}
}