From 000d34768b8516e4e5cdd5f660a8fa0a2fda7b05 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Tue, 27 Sep 2011 23:47:25 +0100 Subject: [PATCH] * Implemented user timezones (closes #48) * Added 'user_timezone' field to table 'users' * Added 'timezones' table --- application/controllers/user.php | 39 ++++++++++++++++++++-- application/models/user_model.php | 19 +++++++++-- application/views/user/add.php | 9 +++++ application/views/user/edit.php | 10 ++++++ sql/timezones.sql | 55 +++++++++++++++++++++++++++++++ 5 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 sql/timezones.sql 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'); + +?>
@@ -72,6 +76,11 @@ ".$locator_error.""; } ?> + + + Timezone + + diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 885cbb2b..70143620 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -1,7 +1,11 @@

Edit user

+load->helper('form'); + +?> uri->segment(3); ?>" name="users"> @@ -73,6 +77,12 @@ ".$locator_error.""; } else { ?> + + + + + +
Timezone
diff --git a/sql/timezones.sql b/sql/timezones.sql new file mode 100644 index 00000000..e8cdeed6 --- /dev/null +++ b/sql/timezones.sql @@ -0,0 +1,55 @@ +-- +-- Based on http://www.michaelapproved.com/articles/timezone-dropdown-select-list/ +-- +-- MySQL dump 10.13 Distrib 5.1.58, for debian-linux-gnu (i486) +-- +-- Host: localhost Database: hrdlog_m0vkg +-- ------------------------------------------------------ +-- Server version 5.1.58-1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `timezones` +-- + +DROP TABLE IF EXISTS `timezones`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `timezones` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `offset` decimal(3,1) NOT NULL, + `name` varchar(120) COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=151 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `timezones` +-- + +LOCK TABLES `timezones` WRITE; +/*!40000 ALTER TABLE `timezones` DISABLE KEYS */; +INSERT INTO `timezones` VALUES (1,'-12.0','(GMT-12:00)-International Date Line West'),(2,'-11.0','(GMT-11:00)-Midway Island, Samoa'),(3,'-10.0','(GMT-10:00)-Hawaii'),(4,'-9.0','(GMT-09:00)-Alaska'),(5,'-8.0','(GMT-08:00)-Pacific Time (US & Canada); Tijuana'),(6,'-7.0','(GMT-07:00)-Arizona'),(7,'-7.0','(GMT-07:00)-Chihuahua, La Paz, Mazatlan'),(8,'-7.0','(GMT-07:00)-Mountain Time (US & Canada)'),(9,'-6.0','(GMT-06:00)-Central America'),(10,'-6.0','(GMT-06:00)-Central Time (US & Canada)'),(11,'-6.0','(GMT-06:00)-Guadalajara, Mexico City, Monterrey'),(12,'-6.0','(GMT-06:00)-Saskatchewan'),(13,'-5.0','(GMT-05:00)-Bogota, Lima, Quito'),(14,'-5.0','(GMT-05:00)-Eastern Time (US & Canada)'),(15,'-5.0','(GMT-05:00)-Indiana (East)'),(16,'-4.0','(GMT-04:00)-Atlantic Time (Canada)'),(17,'-4.0','(GMT-04:00)-La Paz'),(18,'-4.0','(GMT-04:00)-Santiago'),(19,'-3.5','(GMT-03:30)-Newfoundland'),(20,'-3.0','(GMT-03:00)-Brasilia'),(21,'-3.0','(GMT-03:00)-Buenos Aires, Georgetown'),(22,'-3.0','(GMT-03:00)-Greenland'),(23,'-2.0','(GMT-02:00)-Mid-Atlantic'),(24,'-1.0','(GMT-01:00)-Azores'),(25,'-1.0','(GMT-01:00)-Cape Verde Is.'),(26,'0.0','(GMT)-Casablanca, Monrovia'),(0,'0.0','(GMT)-Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London'),(28,'1.0','(GMT+01:00)-Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna'),(29,'1.0','(GMT+01:00)-Belgrade, Bratislava, Budapest, Ljubljana, Prague'),(30,'1.0','(GMT+01:00)-Brussels, Copenhagen, Madrid, Paris'),(31,'1.0','(GMT+01:00)-Sarajevo, Skopje, Warsaw, Zagreb'),(32,'1.0','(GMT+01:00)-West Central Africa'),(33,'2.0','(GMT+02:00)-Athens, Beirut, Istanbul, Minsk'),(34,'2.0','(GMT+02:00)-Bucharest'),(35,'2.0','(GMT+02:00)-Cairo'),(36,'2.0','(GMT+02:00)-Harare, Pretoria'),(37,'2.0','(GMT+02:00)-Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius'),(38,'2.0','(GMT+02:00)-Jerusalem'),(39,'3.0','(GMT+03:00)-Baghdad'),(40,'3.0','(GMT+03:00)-Kuwait, Riyadh'),(41,'3.0','(GMT+03:00)-Moscow, St. Petersburg, Volgograd'),(42,'3.0','(GMT+03:00)-Nairobi'),(43,'3.5','(GMT+03:30)-Tehran'),(44,'4.0','(GMT+04:00)-Abu Dhabi, Muscat'),(45,'4.0','(GMT+04:00)-Baku, Tbilisi, Yerevan'),(46,'4.5','(GMT+04:30)-Kabul'),(47,'5.0','(GMT+05:00)-Ekaterinburg'),(48,'5.0','(GMT+05:00)-Islamabad, Karachi, Tashkent'),(49,'5.5','(GMT+05:30)-Chennai, Kolkata, Mumbai, New Delhi'),(50,'5.8','(GMT+05:45)-Kathmandu'),(51,'6.0','(GMT+06:00)-Almaty, Novosibirsk'),(52,'6.0','(GMT+06:00)-Astana, Dhaka'),(53,'6.0','(GMT+06:00)-Sri Jayawardenepura'),(54,'6.5','(GMT+06:30)-Rangoon'),(55,'7.0','(GMT+07:00)-Bangkok, Hanoi, Jakarta'),(56,'7.0','(GMT+07:00)-Krasnoyarsk'),(57,'8.0','(GMT+08:00)-Beijing, Chongqing, Hong Kong, Urumqi'),(58,'8.0','(GMT+08:00)-Irkutsk, Ulaan Bataar'),(59,'8.0','(GMT+08:00)-Kuala Lumpur, Singapore'),(60,'8.0','(GMT+08:00)-Perth'),(61,'8.0','(GMT+08:00)-Taipei'),(62,'9.0','(GMT+09:00)-Osaka, Sapporo, Tokyo'),(63,'9.0','(GMT+09:00)-Seoul'),(64,'9.0','(GMT+09:00)-Vakutsk'),(65,'9.5','(GMT+09:30)-Adelaide'),(66,'9.5','(GMT+09:30)-Darwin'),(67,'10.0','(GMT+10:00)-Brisbane'),(68,'10.0','(GMT+10:00)-Canberra, Melbourne, Sydney'),(69,'10.0','(GMT+10:00)-Guam, Port Moresby'),(70,'10.0','(GMT+10:00)-Hobart'),(71,'10.0','(GMT+10:00)-Vladivostok'),(72,'11.0','(GMT+11:00)-Magadan, Solomon Is., New Caledonia'),(73,'12.0','(GMT+12:00)-Auckland, Wellington'),(74,'12.0','(GMT+12:00)-Fiji, Kamchatka, Marshall Is.'),(75,'-12.0','(GMT-12:00)-International Date Line West'),(76,'-11.0','(GMT-11:00)-Midway Island, Samoa'),(77,'-10.0','(GMT-10:00)-Hawaii'),(78,'-9.0','(GMT-09:00)-Alaska'),(79,'-8.0','(GMT-08:00)-Pacific Time (US & Canada); Tijuana'),(80,'-7.0','(GMT-07:00)-Arizona'),(81,'-7.0','(GMT-07:00)-Chihuahua, La Paz, Mazatlan'),(82,'-7.0','(GMT-07:00)-Mountain Time (US & Canada)'),(83,'-6.0','(GMT-06:00)-Central America'),(84,'-6.0','(GMT-06:00)-Central Time (US & Canada)'),(85,'-6.0','(GMT-06:00)-Guadalajara, Mexico City, Monterrey'),(86,'-6.0','(GMT-06:00)-Saskatchewan'),(87,'-5.0','(GMT-05:00)-Bogota, Lima, Quito'),(88,'-5.0','(GMT-05:00)-Eastern Time (US & Canada)'),(89,'-5.0','(GMT-05:00)-Indiana (East)'),(90,'-4.0','(GMT-04:00)-Atlantic Time (Canada)'),(91,'-4.0','(GMT-04:00)-Caracas, La Paz'),(92,'-4.0','(GMT-04:00)-Santiago'),(93,'-3.5','(GMT-03:30)-Newfoundland'),(94,'-3.0','(GMT-03:00)-Brasilia'),(95,'-3.0','(GMT-03:00)-Buenos Aires, Georgetown'),(96,'-3.0','(GMT-03:00)-Greenland'),(97,'-2.0','(GMT-02:00)-Mid-Atlantic'),(98,'-1.0','(GMT-01:00)-Azores'),(99,'-1.0','(GMT-01:00)-Cape Verde Is.'),(100,'0.0','(GMT)-Casablanca, Monrovia'),(101,'0.0','(GMT)-Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London'),(102,'1.0','(GMT+01:00)-Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna'),(103,'1.0','(GMT+01:00)-Belgrade, Bratislava, Budapest, Ljubljana, Prague'),(104,'1.0','(GMT+01:00)-Brussels, Copenhagen, Madrid, Paris'),(105,'1.0','(GMT+01:00)-Sarajevo, Skopje, Warsaw, Zagreb'),(106,'1.0','(GMT+01:00)-West Central Africa'),(107,'2.0','(GMT+02:00)-Athens, Beirut, Istanbul, Minsk'),(108,'2.0','(GMT+02:00)-Bucharest'),(109,'2.0','(GMT+02:00)-Cairo'),(110,'2.0','(GMT+02:00)-Harare, Pretoria'),(111,'2.0','(GMT+02:00)-Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius'),(112,'2.0','(GMT+02:00)-Jerusalem'),(113,'3.0','(GMT+03:00)-Baghdad'),(114,'3.0','(GMT+03:00)-Kuwait, Riyadh'),(115,'3.0','(GMT+03:00)-Moscow, St. Petersburg, Volgograd'),(116,'3.0','(GMT+03:00)-Nairobi'),(117,'3.5','(GMT+03:30)-Tehran'),(118,'4.0','(GMT+04:00)-Abu Dhabi, Muscat'),(119,'4.0','(GMT+04:00)-Baku, Tbilisi, Yerevan'),(120,'4.5','(GMT+04:30)-Kabul'),(121,'5.0','(GMT+05:00)-Ekaterinburg'),(122,'5.0','(GMT+05:00)-Islamabad, Karachi, Tashkent'),(123,'5.5','(GMT+05:30)-Chennai, Kolkata, Mumbai, New Delhi'),(124,'5.8','(GMT+05:45)-Kathmandu'),(125,'6.0','(GMT+06:00)-Almaty, Novosibirsk'),(126,'6.0','(GMT+06:00)-Astana, Dhaka'),(127,'6.0','(GMT+06:00)-Sri Jayawardenepura'),(128,'6.5','(GMT+06:30)-Rangoon'),(129,'7.0','(GMT+07:00)-Bangkok, Hanoi, Jakarta'),(130,'7.0','(GMT+07:00)-Krasnoyarsk'),(131,'8.0','(GMT+08:00)-Beijing, Chongqing, Hong Kong, Urumqi'),(132,'8.0','(GMT+08:00)-Irkutsk, Ulaan Bataar'),(133,'8.0','(GMT+08:00)-Kuala Lumpur, Singapore'),(134,'8.0','(GMT+08:00)-Perth'),(135,'8.0','(GMT+08:00)-Taipei'),(136,'9.0','(GMT+09:00)-Osaka, Sapporo, Tokyo'),(137,'9.0','(GMT+09:00)-Seoul'),(138,'9.0','(GMT+09:00)-Vakutsk'),(139,'9.5','(GMT+09:30)-Adelaide'),(140,'9.5','(GMT+09:30)-Darwin'),(141,'10.0','(GMT+10:00)-Brisbane'),(142,'10.0','(GMT+10:00)-Canberra, Melbourne, Sydney'),(143,'10.0','(GMT+10:00)-Guam, Port Moresby'),(144,'10.0','(GMT+10:00)-Hobart'),(145,'10.0','(GMT+10:00)-Vladivostok'),(146,'11.0','(GMT+11:00)-Magadan, Solomon Is., New Caledonia'),(147,'12.0','(GMT+12:00)-Auckland, Wellington'),(148,'12.0','(GMT+12:00)-Fiji, Kamchatka, Marshall Is.'),(149,'13.0','(GMT+13:00)-Nuku\'alofa '),(150,'-4.5','(GMT-04:30)-Caracas'); +/*!40000 ALTER TABLE `timezones` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2011-09-27 23:44:46