diff --git a/application/controllers/user.php b/application/controllers/user.php index abe7eb63..59ce6879 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -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 '.$this->input->post('user_name').' 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'); } diff --git a/application/models/user_model.php b/application/models/user_model.php index 29d940f3..339f430c 100644 --- a/application/models/user_model.php +++ b/application/models/user_model.php @@ -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) { diff --git a/application/views/user/add.php b/application/views/user/add.php index dc891e22..2f5116fc 100644 --- a/application/views/user/add.php +++ b/application/views/user/add.php @@ -5,7 +5,11 @@ session->flashdata('notice'); ?> +load->helper('form'); + +?>