From 43f8b0fbf90cfd37e68d7637daac3e3a1b47bcd1 Mon Sep 17 00:00:00 2001 From: Franzz Date: Fri, 17 Apr 2020 11:00:11 +0200 Subject: [PATCH] Add Timezone to user data --- files/db/update_v9_to_v10.sql | 6 ++++ inc/media.php | 2 +- inc/spot.php | 53 ++++++++++++++++++----------------- inc/user.php | 6 ++-- languages/en.lang | 1 + languages/fr.lang | 1 + masks/project.html | 2 +- readme.md | 3 +- 8 files changed, 42 insertions(+), 32 deletions(-) create mode 100644 files/db/update_v9_to_v10.sql diff --git a/files/db/update_v9_to_v10.sql b/files/db/update_v9_to_v10.sql new file mode 100644 index 0000000..f21c504 --- /dev/null +++ b/files/db/update_v9_to_v10.sql @@ -0,0 +1,6 @@ +ALTER TABLE users ADD COLUMN timezone char(64) AFTER language; +ALTER TABLE users MODIFY COLUMN email VARCHAR(320) NOT NULL; +ALTER TABLE users ADD COLUMN frequency VARCHAR(1) NOT NULL AFTER active; +UPDATE users SET timezone = 'Europe/Paris', frequency = 'P'; + +ALTER TABLE projects MODIFY COLUMN timezone char(64); diff --git a/inc/media.php b/inc/media.php index 65d476d..66bea25 100644 --- a/inc/media.php +++ b/inc/media.php @@ -114,7 +114,7 @@ class Media extends PhpObject { $asDbInfo = array( Db::getId(Project::PROJ_TABLE) => $this->oProject->getProjectId(), 'filename' => $sMediaName, - 'taken_on' => ($asMediaInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asMediaInfo['taken_ts']):0, //Site Time (Settings::TIMEZONE) + 'taken_on' => ($asMediaInfo['taken_ts'] > 0)?date(Db::TIMESTAMP_FORMAT, $asMediaInfo['taken_ts']):0, //Site Time 'posted_on' => date(Db::TIMESTAMP_FORMAT, $asMediaInfo['file_ts']), //Site Time 'rotate' => $asMediaInfo['rotate'], 'type' => $asMediaInfo['type'] diff --git a/inc/spot.php b/inc/spot.php index 0756058..68b1f7d 100755 --- a/inc/spot.php +++ b/inc/spot.php @@ -80,38 +80,39 @@ class Spot extends Main Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to', 'timezone'), self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time'), Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'rotate', 'comment'), - User::USER_TABLE => array('name', 'email', 'language', 'active') + User::USER_TABLE => array('name', 'email', 'language', 'timezone', 'active', 'frequency') ), 'types' => array ( - 'ref_msg_id' => "INT", - 'type' => "VARCHAR(20)", - 'latitude' => "DECIMAL(7,5)", - 'longitude' => "DECIMAL(8,5)", - 'iso_time' => "VARCHAR(24)", - 'site_time' => "TIMESTAMP DEFAULT 0", //DEFAULT 0 removes auto-set to current time - 'unix_time' => "INT", - 'content' => "LONGTEXT", - 'battery_state' => "VARCHAR(10)", - 'ref_spot_id' => "VARCHAR(10)", - 'name' => "VARCHAR(100)", - 'codename' => "VARCHAR(100)", - 'model' => "VARCHAR(20)", - 'ref_feed_id' => "VARCHAR(40)", - 'description' => "VARCHAR(100)", - 'status' => "VARCHAR(10)", + 'active' => "BOOLEAN", 'active_from' => "TIMESTAMP DEFAULT 0", 'active_to' => "TIMESTAMP DEFAULT 0", - 'timezone' => "VARCHAR(100)", - 'last_update' => "TIMESTAMP DEFAULT 0", - 'filename' => "VARCHAR(100) NOT NULL", - 'taken_on' => "TIMESTAMP DEFAULT 0", - 'posted_on' => "TIMESTAMP DEFAULT 0", - 'rotate' => "SMALLINT", + 'battery_state' => "VARCHAR(10)", + 'codename' => "VARCHAR(100)", + 'content' => "LONGTEXT", 'comment' => "LONGTEXT", - 'email' => "VARCHAR(320)", + 'description' => "VARCHAR(100)", + 'email' => "VARCHAR(320) NOT NULL", + 'filename' => "VARCHAR(100) NOT NULL", + 'frequency' => "VARCHAR(1) NOT NULL", + 'iso_time' => "VARCHAR(24)", 'language' => "VARCHAR(2)", - 'active' => "BOOLEAN" + 'last_update' => "TIMESTAMP DEFAULT 0", + 'latitude' => "DECIMAL(7,5)", + 'longitude' => "DECIMAL(8,5)", + 'model' => "VARCHAR(20)", + 'name' => "VARCHAR(100)", + 'posted_on' => "TIMESTAMP DEFAULT 0", + 'ref_feed_id' => "VARCHAR(40)", + 'ref_msg_id' => "INT", + 'ref_spot_id' => "VARCHAR(10)", + 'rotate' => "SMALLINT", + 'site_time' => "TIMESTAMP DEFAULT 0", //DEFAULT 0 removes auto-set to current time + 'status' => "VARCHAR(10)", + 'taken_on' => "TIMESTAMP DEFAULT 0", + 'timezone' => "CHAR(64)", //see mysql.time_zone_name + 'type' => "VARCHAR(20)", + 'unix_time' => "INT" ), 'constraints' => array ( @@ -248,7 +249,7 @@ class Spot extends Main } public function subscribe($sEmail) { - $asResult = $this->oUser->addUser($sEmail, $this->oLang->getLanguage()); + $asResult = $this->oUser->addUser($sEmail, $this->oLang->getLanguage(), date_default_timezone_get()); $asUserInfo = $this->oUser->getUserInfo(); //Send Confirmation Email diff --git a/inc/user.php b/inc/user.php index 752d6d9..e49c002 100644 --- a/inc/user.php +++ b/inc/user.php @@ -22,7 +22,7 @@ class User extends PhpObject { parent::__construct(__CLASS__, Settings::DEBUG); $this->oDb = &$oDb; $this->iUserId = 0; - $this->asUserInfo = array(Db::getId(self::USER_TABLE)=>0, 'name'=>'', 'email'=>'', 'language'=>'', 'active'=>'0'); + $this->asUserInfo = array(Db::getId(self::USER_TABLE)=>0, 'name'=>'', 'email'=>'', 'language'=>'', 'timezone'=>'', 'active'=>'0'); $this->checkUserCookie(); } @@ -30,7 +30,7 @@ class User extends PhpObject { return $this->asUserInfo['language']; } - public function addUser($sEmail, $sLang) { + public function addUser($sEmail, $sLang, $sTimezone) { $bSuccess = false; $sDesc = ''; $sEmail = trim($sEmail); @@ -45,7 +45,7 @@ class User extends PhpObject { } else { //Add/Reactivate user - $iUserId = $this->oDb->insertUpdateRow(self::USER_TABLE, array('email'=>$sEmail, 'language'=>$sLang, 'active'=>'1'), array('email')); + $iUserId = $this->oDb->insertUpdateRow(self::USER_TABLE, array('email'=>$sEmail, 'language'=>$sLang, 'timezone'=>$sTimezone, 'active'=>'1'), array('email')); if($iUserId==0) $sDesc = 'lang:error_commit_db'; else { $sDesc = 'lang:nl_subscribed'; diff --git a/languages/en.lang b/languages/en.lang index b41c7ca..b4c0ce5 100644 --- a/languages/en.lang +++ b/languages/en.lang @@ -70,6 +70,7 @@ unit_hour = h newsletter = Keep in touch! nl_email_placeholder= my@email.com +nl_invalid_email = It doesn't look like an email nl_subscribed_desc = You're all set. We'll send you updates as soon as we get them nl_unsubscribed_desc= Write down your email address and we'll send you François' position as soon as we get it :) nl_email_exists = This email is already subscribed. You can unsubscribe by clicking on the button above. diff --git a/languages/fr.lang b/languages/fr.lang index 0a9d645..b65fa0e 100644 --- a/languages/fr.lang +++ b/languages/fr.lang @@ -70,6 +70,7 @@ unit_hour = h newsletter = Rester en contact nl_email_placeholder= mon@email.com +nl_invalid_email = Ceci ne ressemble pas à une adresse email nl_subscribed_desc = C'est tout bon. On t'enverra les nouvelles posititions dès qu'on les reçoit nl_unsubscribed_desc= Ajoute ton adresse email et on t'enverra la nouvelle position de François dès qu'on la reçoit :) nl_email_exists = Cette adresse email est déjà enregistrée. Vous pouvez vous désinscrire en cliquant sur le bouton ci-dessus. diff --git a/masks/project.html b/masks/project.html index 3ff9ee1..8622b13 100644 --- a/masks/project.html +++ b/masks/project.html @@ -270,7 +270,7 @@ function initSettings(){ var sAction = $(this).prop('name'); var sEmail = $('#email').val(); var regexEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; - if(!regexEmail.test(sEmail)) settingsFeedback('error', 'this is not an email'); + if(!regexEmail.test(sEmail)) settingsFeedback('error', oSpot.lang('nl_invalid_email')); else { oSpot.get( sAction, diff --git a/readme.md b/readme.md index bc0516b..005f245 100644 --- a/readme.md +++ b/readme.md @@ -15,4 +15,5 @@ * Fix lightbox portrait mode: push text under * Subscribe to message feed * Add mail frequency slider -* Add Timezone to user table \ No newline at end of file +* Add Timezone to user table +* Replace Project Time Zone with browser Time Zone when uploading media? \ No newline at end of file