Implement global settings
This commit is contained in:
@@ -109,7 +109,7 @@ $autoload['language'] = array();
|
||||
|
|
||||
*/
|
||||
|
||||
$autoload['model'] = array('user', 'project', 'share');
|
||||
$autoload['model'] = array('user', 'project', 'share', 'setting');
|
||||
|
||||
|
||||
/* End of file autoload.php */
|
||||
|
||||
@@ -84,6 +84,24 @@ $config['auth/settings'] = array(
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Rules for global settingsa.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
$config['settings/index'] = array(
|
||||
array(
|
||||
'field' => 'offline',
|
||||
'label' => _('Offline mode'),
|
||||
'rules' => 'required|integer',
|
||||
),
|
||||
array(
|
||||
'field' => 'offline_message',
|
||||
'label' => _('Offline message'),
|
||||
'rules' => 'trim',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Rules for creating users.
|
||||
*
|
||||
|
||||
57
application/controllers/admin/settings.php
Normal file
57
application/controllers/admin/settings.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (c) 2011 Karsten Heiken, Eike Foken
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
require_once APPPATH . 'core/Admin_Controller.php';
|
||||
|
||||
/**
|
||||
* Global settings.
|
||||
*
|
||||
* @author Eike Foken <kontakt@eikefoken.de>
|
||||
*/
|
||||
class Settings extends Admin_Controller {
|
||||
|
||||
/**
|
||||
* Calls the parent constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->load->library('form_validation');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function index() {
|
||||
if ($this->form_validation->run() === true) {
|
||||
$data = array(
|
||||
'offline' => $this->input->post('offline'),
|
||||
'offline_message' => $this->input->post('offline_message'),
|
||||
);
|
||||
$this->setting->update($data);
|
||||
}
|
||||
|
||||
$this->load->view('admin/settings/edit');
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file users.php */
|
||||
/* Location: ./application/constrollers/admin/users.php */
|
||||
91
application/models/setting.php
Normal file
91
application/models/setting.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php defined('BASEPATH') || exit('No direct script access allowed');
|
||||
/*
|
||||
* Copyright (c) 2011 Karsten Heiken, Eike Foken
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Model for settings.
|
||||
*
|
||||
* @todo Use magic methods
|
||||
* @author Eike Foken <kontakt@eikefoken.de>
|
||||
*/
|
||||
class Setting extends CI_Model {
|
||||
|
||||
/**
|
||||
* Calls the parent constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
*/
|
||||
public function set($name, $value) {
|
||||
$this->db->where('name', $name)->update('settings', array('value' => $value));
|
||||
|
||||
if ($this->db->where('name', $name)->count_all_results('settings') == 0) {
|
||||
$this->create(array('name' => $name, 'value' => $value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function get($name) {
|
||||
return $this->db->get_where('settings', array('name' => $name))->row()->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new settings entry.
|
||||
*
|
||||
* @param array $data
|
||||
* @return boolean Returns TRUE on success.
|
||||
*/
|
||||
public function create($data = array()) {
|
||||
do { // generate unique hash
|
||||
$data['id'] = random_hash();
|
||||
} while ($this->db->where('id', $data['id'])->from('settings')->count_all_results() > 0);
|
||||
|
||||
$this->db->insert('settings', $data);
|
||||
|
||||
return $this->db->affected_rows() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all settings.
|
||||
*
|
||||
* @param array $data
|
||||
* @return boolean Returns TRUE on success.
|
||||
*/
|
||||
public function update($data = array()) {
|
||||
foreach ($data as $name => $value) {
|
||||
$this->set($name, $value);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* End of file setting.php */
|
||||
/* Location: ./application/models/setting.php */
|
||||
35
application/views/admin/settings/edit.php
Normal file
35
application/views/admin/settings/edit.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php $this->load->view('header');?>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<div class="title">
|
||||
<h2><?=_('Global settings')?></h2>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<form name="settings" method="post" action="<?=site_url('admin/settings')?>">
|
||||
<ul>
|
||||
<li>
|
||||
<?=form_label(_('Offline mode?'), 'offline');?>
|
||||
<div>
|
||||
<?=form_yesno('offline', set_value('offline', $this->setting->get('offline')), 'id="offline" class="drop"');?>
|
||||
<?=form_error('offline');?>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<?=form_label(_('Offline message'), 'offline_message');?><br />
|
||||
<label class="note"><?=_('This message is shown if the page is in offline mode.');?></label>
|
||||
<div>
|
||||
<textarea name="offline_message" id="offline_message" rows="6" cols="60" class="textarea"><?=set_value('offline_message', $this->setting->get('offline_message'));?></textarea>
|
||||
<?=form_error('offline_message');?>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p>
|
||||
<a href="javascript:void(0);" onclick="$('form[name=settings]').submit();" class="button save"><?=_('Save settings');?></a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $this->load->view('footer');?>
|
||||
10
application/views/admin/settings/index.html
Executable file
10
application/views/admin/settings/index.html
Executable file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -58,7 +58,8 @@
|
||||
<p>
|
||||
<a class="button left big" href="<?=site_url('admin/servers');?>"><strong><?=image_asset('icons-big/server.png');?></strong><br /><?=_('Manage servers');?>
|
||||
</a><a class="button middle big" href="<?=site_url('admin/programs');?>"><strong><?=image_asset('icons-big/application.png');?></strong><br /><?=_('Manage programs');?>
|
||||
</a><a class="button right big" href="<?=site_url('admin/users');?>"><strong><?=image_asset('icons-big/user.png');?></strong><br /><?=_('Manage users');?></a>
|
||||
</a><a class="button middle big" href="<?=site_url('admin/users');?>"><strong><?=image_asset('icons-big/user.png');?></strong><br /><?=_('Manage users');?>
|
||||
</a><a class="button right big" href="<?=site_url('admin/settings');?>"><strong><?=image_asset('icons-big/switch.png');?></strong><br /><?=_('Global settings');?></a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user