From 12a357fe17b08b8b3f8a8a20474eef70f2c44c23 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Thu, 11 Aug 2011 14:23:30 +0200 Subject: [PATCH] Make settings page working --- application/controllers/admin/users.php | 75 +------------------------ application/controllers/settings.php | 28 ++++++--- application/views/user/settings.php | 51 ++++++++++++----- assets/css/style.css | 7 ++- 4 files changed, 64 insertions(+), 97 deletions(-) diff --git a/application/controllers/admin/users.php b/application/controllers/admin/users.php index 2f63c9f..65d12ee 100644 --- a/application/controllers/admin/users.php +++ b/application/controllers/admin/users.php @@ -15,6 +15,7 @@ class Users extends CI_Controller { parent::__construct(); $this->load->library('form_validation'); $this->load->model('user'); + $this->load->config('form_validation'); } /** @@ -29,49 +30,6 @@ class Users extends CI_Controller { * Allows admins to create a new user. */ public function create() { - $config = array( - array( - 'field' => 'username', - 'label' => _('Username'), - 'rules' => 'trim|required|min_length[4]|max_length[20]|unique[users.username]', - ), - array( - 'field' => 'password', - 'label' => _('Password'), - 'rules' => 'required|min_length[6]|matches[password_confirm]', - ), - array( - 'field' => 'password_confirm', - 'label' => _('Confirm password'), - ), - array( - 'field' => 'firstname', - 'label' => _('First name'), - 'rules' => 'trim|required|max_length[50]', - ), - array( - 'field' => 'lastname', - 'label' => _('Last name'), - 'rules' => 'trim|required|max_length[50]', - ), - array( - 'field' => 'email', - 'label' => _('Email address'), - 'rules' => 'trim|required|valid_email', - ), - array( - 'field' => 'institution', - 'label' => _('Institution'), - 'rules' => 'trim|max_length[100]', - ), - array( - 'field' => 'phone', - 'label' => _('Phone number'), - 'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]', - ) - ); - $this->form_validation->set_rules($config); - if ($this->form_validation->run() === true) { $username = $this->input->post('username'); @@ -103,36 +61,7 @@ class Users extends CI_Controller { show_404(); } - $config = array( - array( - 'field' => 'firstname', - 'label' => _('First name'), - 'rules' => 'trim|required|max_length[50]', - ), - array( - 'field' => 'lastname', - 'label' => _('Last name'), - 'rules' => 'trim|required|max_length[50]', - ), - array( - 'field' => 'email', - 'label' => _('Email address'), - 'rules' => 'trim|required|valid_email', - ), - array( - 'field' => 'institution', - 'label' => _('Institution'), - 'rules' => 'trim|max_length[100]', - ), - array( - 'field' => 'phone', - 'label' => _('Phone number'), - 'rules' => 'trim|regex_match[/^\+\d{2,4}\s\d{2,4}\s\d{3,10}+$/i]', - ) - ); - $this->form_validation->set_rules($config); - - if ($this->form_validation->run() === true) { + if ($this->form_validation->run('users/edit') === true) { $data = array( 'email' => $this->input->post('email'), 'firstname' => $this->input->post('firstname'), diff --git a/application/controllers/settings.php b/application/controllers/settings.php index d694efa..8c8f65b 100644 --- a/application/controllers/settings.php +++ b/application/controllers/settings.php @@ -33,20 +33,30 @@ class Settings extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('program'); + $this->load->library('form_validation'); } /** * Show a list of all available programs. */ public function index() { - $profile = $this->user->profile(); - $profile_fields = array( - array('firstname', _('First name'), 'text'), - array('lastname', _('Last name'), 'text'), - array('intitution', _('Institution'), 'text'), - ); - $tpl['profile'] = $profile; - $tpl['profile_fields'] = $profile_fields; - $this->load->view('user/settings', $tpl); + $user = $this->access->getCurrentUser(); + + if ($this->form_validation->run() === true) { + $data = array( + 'email' => $this->input->post('email'), + 'firstname' => $this->input->post('firstname'), + 'lastname' => $this->input->post('lastname'), + 'institution' => $this->input->post('institution'), + 'phone' => $this->input->post('phone') + ); + + if ($this->user->update($user['id'], $data)) { + $this->messages->add(_("Settings saved successfully"), 'success'); + redirect('settings', 303); + } + } + + $this->load->view('user/settings', $user); } } diff --git a/application/views/user/settings.php b/application/views/user/settings.php index 3914891..ce2a767 100644 --- a/application/views/user/settings.php +++ b/application/views/user/settings.php @@ -1,7 +1,7 @@ load->view('header');?>
-
+

@@ -13,27 +13,45 @@
    -
  • - +
    - + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + +
    + + +
    +
  • +
  • + +
    + +
  • -
    -
  • - -
    - -
    -

  • @@ -41,6 +59,11 @@
+
+

+ +

+
diff --git a/assets/css/style.css b/assets/css/style.css index 99d1102..78e5df6 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -470,11 +470,16 @@ html ul.tabs li.active, html ul.tabs li.active a:hover { /*--Makes sure that th } .tab_container { + margin: 0 0 20px; + padding: 15px 15px 0 15px; border: 1px solid #e8e8e8; border-top: none; overflow: hidden; background: #fff; } .tab_content { - padding: 20px; + padding: 0; +} +.tab_buttons { + padding: 0; }