* Implemented user timezones (closes #48)

* Added 'user_timezone' field to table 'users'
* Added 'timezones' table
pull/106/merge
Andy Smith 2011-09-27 23:47:25 +01:00
rodzic 5d2e890da0
commit 000d34768b
5 zmienionych plików z 127 dodań i 5 usunięć

Wyświetl plik

@ -29,6 +29,10 @@ class User extends CI_Controller {
$this->form_validation->set_rules('user_lastname', 'Last name', 'required');
$this->form_validation->set_rules('user_callsign', 'Callsign', 'required');
$this->form_validation->set_rules('user_locator', 'Locator', 'required');
$this->form_validation->set_rules('user_timezone', 'Timezone', 'required');
// Get timezones
$data['timezones'] = $this->user_model->timezones();
if ($this->form_validation->run() == FALSE)
{
@ -43,15 +47,16 @@ class User extends CI_Controller {
$data['user_lastname'] = $this->input->post('user_lastname');
$data['user_callsign'] = $this->input->post('user_callsign');
$data['user_locator'] = $this->input->post('user_locator');
$data['user_timezone'] = $this->input->post('user_timezone');
$this->load->view('user/add', $data);
} else {
$this->load->view('user/add');
$this->load->view('user/add', $data);
}
$this->load->view('layout/footer');
}
else
{
switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'))) {
switch($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'), $this->input->post('user_firstname'), $this->input->post('user_lastname'), $this->input->post('user_callsign'), $this->input->post('user_locator'), $this->input->post('user_timezone'))) {
// Check for errors
case EUSERNAMEEXISTS:
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
@ -95,7 +100,14 @@ class User extends CI_Controller {
{
$this->form_validation->set_rules('user_type', 'Type', 'required');
}
$this->form_validation->set_rules('user_firstname', 'First name', 'required');
$this->form_validation->set_rules('user_lastname', 'Last name', 'required');
$this->form_validation->set_rules('user_callsign', 'Callsign', 'required');
$this->form_validation->set_rules('user_locator', 'Locator', 'required');
$this->form_validation->set_rules('user_timezone', 'Timezone', 'required');
// Get timezones
$data['timezones'] = $this->user_model->timezones();
if ($this->form_validation->run() == FALSE)
{
@ -152,6 +164,24 @@ class User extends CI_Controller {
$data['user_lastname'] = $q->user_lastname;
}
if($this->input->post('user_callsign')) {
$data['user_callsign'] = $this->input->post('user_callsign');
} else {
$data['user_callsign'] = $q->user_callsign;
}
if($this->input->post('user_locator')) {
$data['user_locator'] = $this->input->post('user_locator');
} else {
$data['user_locator'] = $q->user_locator;
}
if($this->input->post('user_timezone')) {
$data['user_timezone'] = $this->input->post('user_timezone');
} else {
$data['user_timezone'] = $q->user_timezone;
}
$this->load->view('user/edit', $data);
$this->load->view('layout/footer');
}
@ -185,6 +215,11 @@ class User extends CI_Controller {
$data['user_email'] = $this->input->post('user_email');
$data['user_password'] = $this->input->post('user_password');
$data['user_type'] = $this->input->post('user_type');
$data['user_firstname'] = $this->input->post('user_firstname');
$data['user_lastname'] = $this->input->post('user_lastname');
$data['user_callsign'] = $this->input->post('user_callsign');
$data['user_locator'] = $this->input->post('user_locator');
$data['user_timezone'] = $this->input->post('user_timezone');
$this->load->view('user/edit', $data);
$this->load->view('layout/footer');
}

Wyświetl plik

@ -74,7 +74,7 @@ class User_Model extends CI_Model {
// FUNCTION: bool add($username, $password, $email, $type)
// Add a user
function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator) {
function add($username, $password, $email, $type, $firstname, $lastname, $callsign, $locator, $timezone) {
// Check that the user isn't already used
if(!$this->exists($username)) {
$data = array(
@ -85,7 +85,8 @@ class User_Model extends CI_Model {
'user_firstname' => $firstname,
'user_lastname' => $lastname,
'user_callsign' => $callsign,
'user_locator' => $locator
'user_locator' => $locator,
'user_timezone' => $timezone
);
// Check the password is valid
@ -119,7 +120,8 @@ class User_Model extends CI_Model {
'user_callsign' => $fields['user_callsign'],
'user_locator' => $fields['user_locator'],
'user_firstname' => $fields['user_firstname'],
'user_lastname' => $fields['user_lastname']
'user_lastname' => $fields['user_lastname'],
'user_timezone' => $fields['user_timezone']
);
// Check to see if the user is allowed to change user levels
@ -279,6 +281,17 @@ class User_Model extends CI_Model {
return $r;
}
// FUNCTION: array timezones()
// Returns a list of timezones
function timezones() {
$r = $this->db->query('SELECT id, name FROM timezones ORDER BY offset');
$ts = array();
foreach ($r->result_array() as $t) {
$ts[$t['id']] = $t['name'];
}
return $ts;
}
// FUNCTION: bool _auth($password, $hash)
// Checks a password against the stored hash
private function _auth($password, $hash) {

Wyświetl plik

@ -5,7 +5,11 @@
<?php echo $this->session->flashdata('notice'); ?>
</div>
<?php } ?>
<?php
$this->load->helper('form');
?>
<?php echo validation_errors(); ?>
<form method="post" action="<?php echo site_url('user/add'); ?>" name="users">
@ -72,6 +76,11 @@
<?php if(isset($locator_error)) { echo "<div class=\"small error\">".$locator_error."</div>"; } ?>
</td>
</tr>
<tr>
<td>Timezone</td>
<td><?php echo form_dropdown('user_timezone', $timezones, 0); ?></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />

Wyświetl plik

@ -1,7 +1,11 @@
<h2>Edit user</h2>
<div class="wrap_content user">
<?php echo validation_errors(); ?>
<?php
$this->load->helper('form');
?>
<form method="post" action="<?php echo site_url('user/edit')."/".$this->uri->segment(3); ?>" name="users">
<table>
<tr>
@ -73,6 +77,12 @@
<?php if(isset($locator_error)) { echo "<div class=\"small error\">".$locator_error."</div>"; } else { ?>
<?php } ?>
</tr>
<tr>
<td>Timezone</td>
<td><?php echo form_dropdown('user_timezone', $timezones, $user_timezone); ?></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />

55
sql/timezones.sql 100644

File diff suppressed because one or more lines are too long