212 lines
7.9 KiB
PHP
Executable File
212 lines
7.9 KiB
PHP
Executable File
<?php if (! defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Settings extends CI_Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
define("HOOSK_ADMIN", 1);
|
|
$this->load->helper(array('admincontrol', 'url', 'hoosk_admin', 'form'));
|
|
$this->load->library('session');
|
|
$this->load->model('Cmap_model');
|
|
define('LANG', $this->Cmap_model->getLang());
|
|
$this->lang->load('admin', LANG);
|
|
//Define what page we are on for nav
|
|
$this->data['current'] = $this->uri->segment(2);
|
|
define('SITE_NAME', $this->Cmap_model->getSiteName());
|
|
define('THEME', $this->Cmap_model->getTheme());
|
|
define('THEME_FOLDER', BASE_URL.'/theme/'.THEME);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$this->load->helper('directory');
|
|
$this->data['themesdir'] = directory_map($_SERVER["DOCUMENT_ROOT"].'/theme/', 1);
|
|
$this->data['langdir'] = directory_map(APPPATH.'/language/', 1);
|
|
|
|
$this->data['settings'] = $this->Cmap_model->getSettings();
|
|
$this->data['current'] = $this->uri->segment(2);
|
|
$this->data['header'] = $this->load->view('admin/header', $this->data, true);
|
|
$this->data['footer'] = $this->load->view('admin/footer', '', true);
|
|
$this->load->view('admin/settings', $this->data);
|
|
}
|
|
|
|
public function upload()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$attachment = $this->input->post('attachment');
|
|
$uploadedFile = $_FILES['attachment']['tmp_name']['file'];
|
|
|
|
$path = $_SERVER["DOCUMENT_ROOT"].'/images';
|
|
$url = BASE_URL.'/images';
|
|
|
|
// create an image name
|
|
$fileName = $attachment['name'];
|
|
|
|
// upload the image
|
|
move_uploaded_file($uploadedFile, $path.'/'.$fileName);
|
|
|
|
$this->output->set_output(
|
|
json_encode(array('file' => array(
|
|
'url' => $url . '/' . $fileName,
|
|
'filename' => $fileName
|
|
))),
|
|
200,
|
|
array('Content-Type' => 'application/json')
|
|
);
|
|
}
|
|
|
|
public function updateSettings()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$path_upload = $_SERVER["DOCUMENT_ROOT"] . '/uploads/';
|
|
$path_images = $_SERVER["DOCUMENT_ROOT"] . '/images/';
|
|
if ($this->input->post('siteLogo') != "") {
|
|
rename($path_upload . $this->input->post('siteLogo'), $path_images . $this->input->post('siteLogo'));
|
|
}
|
|
if ($this->input->post('siteFavicon') != "") {
|
|
rename($path_upload . $this->input->post('siteFavicon'), $path_images . $this->input->post('siteFavicon'));
|
|
}
|
|
$this->Cmap_model->updateSettings();
|
|
redirect(BASE_URL.'/admin/settings/default', 'refresh');
|
|
}
|
|
|
|
public function uploadLogo()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$config['upload_path'] = FCPATH. '/uploads/';
|
|
$config['allowed_types'] = 'gif|jpg|png';
|
|
|
|
$this->load->library('upload', $config);
|
|
foreach ($_FILES as $key => $value) {
|
|
if (! $this->upload->do_upload($key)) {
|
|
$error = array('error' => $this->upload->display_errors());
|
|
echo 0;
|
|
} else {
|
|
echo '"'.$this->upload->data('file_name').'"';
|
|
}
|
|
}
|
|
}
|
|
|
|
public function social()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$this->data['social'] = $this->Cmap_model->getSocial();
|
|
$this->data['current'] = $this->uri->segment(2);
|
|
$this->data['header'] = $this->load->view('admin/header', $this->data, true);
|
|
$this->data['footer'] = $this->load->view('admin/footer', '', true);
|
|
$this->load->view('admin/social', $this->data);
|
|
}
|
|
|
|
public function updateSocial()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$this->Cmap_model->updateSocial();
|
|
redirect(BASE_URL.'/admin/settings/social', 'refresh');
|
|
}
|
|
|
|
|
|
public function roles()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
$this->load->library('pagination');
|
|
$result_per_page =15; // the number of result per page
|
|
$config['base_url'] = BASE_URL. '/admin/settings/roles/';
|
|
$config['total_rows'] = $this->Cmap_model->countRoles();
|
|
$config['per_page'] = $result_per_page;
|
|
|
|
$this->pagination->initialize($config);
|
|
|
|
//Get users from database
|
|
$this->data['roles'] = $this->Cmap_model->getRoles($result_per_page, $this->uri->segment(4));
|
|
|
|
//Load the view
|
|
$this->data['header'] = $this->load->view('admin/header', $this->data, true);
|
|
$this->data['footer'] = $this->load->view('admin/footer', '', true);
|
|
$this->load->view('admin/roles', $this->data);
|
|
}
|
|
|
|
public function newRole()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
//Load the view
|
|
$this->data['header'] = $this->load->view('admin/header', $this->data, true);
|
|
$this->data['footer'] = $this->load->view('admin/footer', '', true);
|
|
$this->load->view('admin/role_new', $this->data);
|
|
}
|
|
|
|
public function addRole()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
//Load the form validation library
|
|
$this->load->library('form_validation');
|
|
//Set validation rules
|
|
$this->form_validation->set_rules('name', 'role name', 'trim|required|is_unique[cm_setting_roles.name]');
|
|
$this->form_validation->set_rules('slug', 'role slug', 'trim|required|is_unique[cm_setting_roles.slug]');
|
|
|
|
if($this->form_validation->run() == FALSE) {
|
|
//Validation failed
|
|
$this->newRole();
|
|
} else {
|
|
//Validation passed
|
|
//Add the user
|
|
$this->Cmap_model->createRole();
|
|
//Return to user list
|
|
redirect(BASE_URL.'/admin/settings/roles', 'refresh');
|
|
}
|
|
}
|
|
|
|
public function editRole()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
//Get user details from database
|
|
$this->data['users'] = $this->Cmap_model->getRole($this->uri->segment(5));
|
|
//Load the view
|
|
$this->data['header'] = $this->load->view('admin/header', $this->data, true);
|
|
$this->data['footer'] = $this->load->view('admin/footer', '', true);
|
|
$this->load->view('admin/role_edit', $this->data);
|
|
}
|
|
|
|
public function editedRole()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
//Load the form validation library
|
|
$this->load->library('form_validation');
|
|
//Set validation rules
|
|
$this->form_validation->set_rules('name', 'email address', 'trim|required|is_unique[cm_setting_roles.name.roleID.'.$this->uri->segment(5).']');
|
|
$this->form_validation->set_rules('slug', 'password', 'trim|required');
|
|
|
|
|
|
if($this->form_validation->run() == FALSE) {
|
|
//Validation failed
|
|
$this->editRole();
|
|
} else {
|
|
//Validation passed
|
|
//Update the user
|
|
$this->Cmap_model->updateRole($this->uri->segment(5));
|
|
//Return to user list
|
|
redirect(BASE_URL.'/admin/settings/roles', 'refresh');
|
|
}
|
|
}
|
|
|
|
public function deleteRole()
|
|
{
|
|
Admincontrol_helper::is_logged_in($this->session->userdata('userName'));
|
|
if($this->input->post('deleteid')):
|
|
$this->Cmap_model->removeRole($this->input->post('deleteid'));
|
|
redirect(BASE_URL.'/admin/settings/roles');
|
|
else:
|
|
$this->data['form']=$this->Cmap_model->getRole($this->uri->segment(5));
|
|
$this->load->view('admin/role_delete.php', $this->data );
|
|
endif;
|
|
}
|
|
|
|
function roleSearch()
|
|
{
|
|
$this->Cmap_model->roleSearch($this->input->post('term'));
|
|
}
|
|
}
|