Make settings page working

This commit is contained in:
Eike Foken
2011-08-11 14:23:30 +02:00
parent a3ee0f784c
commit 12a357fe17
4 changed files with 64 additions and 97 deletions

View File

@@ -15,6 +15,7 @@ class Users extends CI_Controller {
parent::__construct(); parent::__construct();
$this->load->library('form_validation'); $this->load->library('form_validation');
$this->load->model('user'); $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. * Allows admins to create a new user.
*/ */
public function create() { 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) { if ($this->form_validation->run() === true) {
$username = $this->input->post('username'); $username = $this->input->post('username');
@@ -103,36 +61,7 @@ class Users extends CI_Controller {
show_404(); show_404();
} }
$config = array( if ($this->form_validation->run('users/edit') === true) {
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) {
$data = array( $data = array(
'email' => $this->input->post('email'), 'email' => $this->input->post('email'),
'firstname' => $this->input->post('firstname'), 'firstname' => $this->input->post('firstname'),

View File

@@ -33,20 +33,30 @@ class Settings extends CI_Controller {
public function __construct() { public function __construct() {
parent::__construct(); parent::__construct();
$this->load->model('program'); $this->load->model('program');
$this->load->library('form_validation');
} }
/** /**
* Show a list of all available programs. * Show a list of all available programs.
*/ */
public function index() { public function index() {
$profile = $this->user->profile(); $user = $this->access->getCurrentUser();
$profile_fields = array(
array('firstname', _('First name'), 'text'), if ($this->form_validation->run() === true) {
array('lastname', _('Last name'), 'text'), $data = array(
array('intitution', _('Institution'), 'text'), 'email' => $this->input->post('email'),
); 'firstname' => $this->input->post('firstname'),
$tpl['profile'] = $profile; 'lastname' => $this->input->post('lastname'),
$tpl['profile_fields'] = $profile_fields; 'institution' => $this->input->post('institution'),
$this->load->view('user/settings', $tpl); '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);
} }
} }

View File

@@ -1,7 +1,7 @@
<?php $this->load->view('header');?> <?php $this->load->view('header');?>
<div id="content"> <div id="content">
<form action="#" method="post"> <form name="settings" action="<?=('settings');?>" method="post">
<div class="title"> <div class="title">
<h2><?=_('Settings');?></h2> <h2><?=_('Settings');?></h2>
</div> </div>
@@ -13,27 +13,45 @@
<div class="tab_container"> <div class="tab_container">
<div id="personal" class="tab_content"> <div id="personal" class="tab_content">
<ul> <ul>
<?php foreach($profile_fields as $field):?>
<li> <li>
<label><?=$field[1]?></label> <?=form_label(_('First name'), 'firstname');?>
<div> <div>
<input type="<?=$field[2]?>" name="<?=$field[0]?>" class="short text" /> <input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname', $firstname);?>" />
<?=form_error('firstname');?>
</div>
</li>
<li>
<?=form_label(_('Last name'), 'lastname');?>
<div>
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname', $lastname);?>" />
<?=form_error('lastname');?>
</div>
</li>
<li>
<?=form_label(_('Email address'), 'email');?>
<div>
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email', $email);?>" />
<?=form_error('email');?>
</div>
</li>
<li>
<?=form_label(_('Institution'), 'institution');?>
<div>
<input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution', $institution);?>" />
<?=form_error('institution');?>
</div>
</li>
<li>
<?=form_label(_('Phone number'), 'phone');?>
<div>
<input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone', $phone);?>" />
<?=form_error('phone');?>
</div> </div>
</li> </li>
<?php endforeach;?>
</ul> </ul>
</div> </div>
<div id="settings" class="tab_content"> <div id="settings" class="tab_content">
<ul> <ul>
<li>
<label><?=_('Language');?></label>
<div>
<select id="language_select" name="language_select" class="drop">
<option value="de">Deutsch</option>
<option value="en">Englisch</option>
</select>
</div>
</li>
<li> <li>
<input type="checkbox" id="projects_sortrecently" name="projects_sortrecently" value="1" class="checkbox"/> <input type="checkbox" id="projects_sortrecently" name="projects_sortrecently" value="1" class="checkbox"/>
<label for="projects_sortrecently"><?=_('Sort projects by date of the last access');?></label><br /> <label for="projects_sortrecently"><?=_('Sort projects by date of the last access');?></label><br />
@@ -41,6 +59,11 @@
</li> </li>
</ul> </ul>
</div> </div>
<div class="tab_buttons">
<p>
<a class="button save" href="javascript:void(0);" onclick="$('form[name=settings]').submit();"><?=_('Save');?></a>
</p>
</div>
</div> </div>
</form> </form>
</div> </div>

View File

@@ -470,11 +470,16 @@ html ul.tabs li.active, html ul.tabs li.active a:hover { /*--Makes sure that th
} }
.tab_container { .tab_container {
margin: 0 0 20px;
padding: 15px 15px 0 15px;
border: 1px solid #e8e8e8; border: 1px solid #e8e8e8;
border-top: none; border-top: none;
overflow: hidden; overflow: hidden;
background: #fff; background: #fff;
} }
.tab_content { .tab_content {
padding: 20px; padding: 0;
}
.tab_buttons {
padding: 0;
} }