From e6739d230eec61af1ee99c4c17b53195552fe809 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Mon, 2 Jan 2012 11:35:50 +0100 Subject: [PATCH] add function to detect always the timezone --- apps/calendar/ajax/gettimezonedetection.php | 11 +++++++++++ apps/calendar/ajax/guesstimezone.php | 13 +++++++++++-- apps/calendar/ajax/timezonedetection.php | 17 +++++++++++++++++ apps/calendar/index.php | 2 +- apps/calendar/js/geo.js | 2 +- apps/calendar/js/settings.js | 11 +++++++++++ apps/calendar/templates/settings.php | 2 +- 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 apps/calendar/ajax/gettimezonedetection.php create mode 100644 apps/calendar/ajax/timezonedetection.php diff --git a/apps/calendar/ajax/gettimezonedetection.php b/apps/calendar/ajax/gettimezonedetection.php new file mode 100644 index 00000000000..ae58370712d --- /dev/null +++ b/apps/calendar/ajax/gettimezonedetection.php @@ -0,0 +1,11 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +OC_JSON::success(array('detection' => OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection'))); \ No newline at end of file diff --git a/apps/calendar/ajax/guesstimezone.php b/apps/calendar/ajax/guesstimezone.php index 07aadc5cb12..41aea26985f 100755 --- a/apps/calendar/ajax/guesstimezone.php +++ b/apps/calendar/ajax/guesstimezone.php @@ -1,6 +1,6 @@ + * Copyright (c) 2011, 2012 Georg Ehrke * This file is licensed under the Affero General Public License version 3 or * later. * See the COPYING-README file. @@ -24,10 +24,19 @@ OC_JSON::checkAppEnabled('calendar'); $l = new OC_L10N('calendar'); $lat = $_GET['lat']; $long = $_GET['long']; +if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'position') == $lat . '-' . $long && OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone') != null){ + OC_JSON::success(); + exit; +} +OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'position', $lat . '-' . $long); $geolocation = file_get_contents('http://ws.geonames.org/timezone?lat=' . $lat . '&lng=' . $long); //Information are by Geonames (http://www.geonames.org) and licensed under the Creative Commons Attribution 3.0 License $geoxml = simplexml_load_string($geolocation); $geoarray = make_array_out_of_xml($geoxml); +if($geoarray['timezone']['timezoneId'] == OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone')){ + OC_JSON::success(); + exit; +} if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers())){ OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezone', $geoarray['timezone']['timezoneId']); $message = array('message'=> $l->t('New Timezone:') . $geoarray['timezone']['timezoneId']); @@ -36,4 +45,4 @@ if(in_array($geoarray['timezone']['timezoneId'], DateTimeZone::listIdentifiers() OC_JSON::error(); } -?> \ No newline at end of file +?> diff --git a/apps/calendar/ajax/timezonedetection.php b/apps/calendar/ajax/timezonedetection.php new file mode 100644 index 00000000000..77e4c4f6ebe --- /dev/null +++ b/apps/calendar/ajax/timezonedetection.php @@ -0,0 +1,17 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +require_once ("../../../lib/base.php"); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('calendar'); +if($_POST['timezonedetection'] == 'on'){ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'true'); +}else{ + OC_Preferences::setValue(OC_USER::getUser(), 'calendar', 'timezonedetection', 'false'); +} +OC_JSON::success(); + diff --git a/apps/calendar/index.php b/apps/calendar/index.php index 7561f987b21..a2042afddf1 100644 --- a/apps/calendar/index.php +++ b/apps/calendar/index.php @@ -32,7 +32,7 @@ if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'mont OC_Util::addScript('3rdparty/fullcalendar', 'fullcalendar'); OC_Util::addStyle('3rdparty/fullcalendar', 'fullcalendar'); -if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null){ +if(OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone") == null || OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezonedetection') == 'true'){ OC_UTIL::addScript('calendar', 'geo'); } OC_Util::addScript('calendar', 'calendar'); diff --git a/apps/calendar/js/geo.js b/apps/calendar/js/geo.js index 744d960b75f..ae6a971e938 100755 --- a/apps/calendar/js/geo.js +++ b/apps/calendar/js/geo.js @@ -8,7 +8,7 @@ if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { $.getJSON(OC.filePath('calendar', 'ajax', 'guesstimezone.php?lat=' + position.coords.latitude + '&long=' + position.coords.longitude + ''), function(data){ - if (data.status == 'success'){ + if (data.status == 'success' && typeof(data.message) != 'undefined'){ $('#notification').html(data.message); $('#notification').attr('title', 'CC BY 3.0 by Geonames.org'); $('#notification').slideDown(); diff --git a/apps/calendar/js/settings.js b/apps/calendar/js/settings.js index 6c00be06b39..613e2d030db 100644 --- a/apps/calendar/js/settings.js +++ b/apps/calendar/js/settings.js @@ -8,6 +8,12 @@ $(document).ready(function(){ }); return false; }); + $('#timezonedetection').change( function(){ + var post = $('#timezonedetection').serialize(); + $.post( OC.filePath('calendar', 'ajax', 'timezonedetection.php'), post, function(data){ + + }); + }); $("#timezone").chosen(); $("#firstdayofweek").change( function(){ var data = $("#firstdayofweek").serialize(); @@ -52,6 +58,11 @@ $(document).ready(function(){ $.getJSON(OC.filePath('calendar', 'ajax', 'duration.php'), function(jsondata, status) { $("#duration").val(jsondata.duration); }); + $.getJSON(OC.filePath('calendar', 'ajax', 'gettimezonedetection.php'), function(jsondata, status){ + if(jsondata.detection == 'true'){ + $('#timezonedetection').attr('checked', 'checked'); + } + }); $("#weekend").change( function(){ var data = $("#weekend").serialize(); $.post( OC.filePath('calendar', 'ajax', 'setdaysofweekend.php'), data, function(data){ diff --git a/apps/calendar/templates/settings.php b/apps/calendar/templates/settings.php index 56fb55d235c..fc8e0e061d9 100644 --- a/apps/calendar/templates/settings.php +++ b/apps/calendar/templates/settings.php @@ -27,7 +27,7 @@ $continent=$ex[0]; echo ''; endforeach;?> - +