diff --git a/application/config/autoload.php b/application/config/autoload.php index 3fadc5b..530b91b 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -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 */ diff --git a/application/config/form_validation.php b/application/config/form_validation.php index 82264ce..c02c222 100644 --- a/application/config/form_validation.php +++ b/application/config/form_validation.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. * diff --git a/application/controllers/admin/settings.php b/application/controllers/admin/settings.php new file mode 100644 index 0000000..87b5783 --- /dev/null +++ b/application/controllers/admin/settings.php @@ -0,0 +1,57 @@ + + */ +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 */ diff --git a/application/models/setting.php b/application/models/setting.php new file mode 100644 index 0000000..c5a4fd4 --- /dev/null +++ b/application/models/setting.php @@ -0,0 +1,91 @@ + + */ +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 */ diff --git a/application/views/admin/settings/edit.php b/application/views/admin/settings/edit.php new file mode 100644 index 0000000..e2dde31 --- /dev/null +++ b/application/views/admin/settings/edit.php @@ -0,0 +1,35 @@ +load->view('header');?> + +
+ +
+

+
+ +
+
+
    +
  • + +
    + setting->get('offline')), 'id="offline" class="drop"');?> + +
    +
  • +
  • +
    + +
    + + +
    +
  • +
+

+ +

+
+
+
+ +load->view('footer');?> diff --git a/application/views/admin/settings/index.html b/application/views/admin/settings/index.html new file mode 100755 index 0000000..c942a79 --- /dev/null +++ b/application/views/admin/settings/index.html @@ -0,0 +1,10 @@ + + + 403 Forbidden + + + +

Directory access is forbidden.

+ + + \ No newline at end of file diff --git a/application/views/dashboard.php b/application/views/dashboard.php index 1811001..b5edcb6 100644 --- a/application/views/dashboard.php +++ b/application/views/dashboard.php @@ -58,7 +58,8 @@



-

+
+