Add timezone setting to personal settings page

This commit is contained in:
Bart Visscher 2011-08-30 09:28:25 +02:00
parent c769f961ab
commit a469d15bc8
5 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,26 @@
<?php
// Init owncloud
require_once('../../../lib/base.php');
$l=new OC_L10N('calendar');
// We send json data
header( "Content-Type: application/jsonrequest" );
// Check if we are a user
if( !OC_User::isLoggedIn()){
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Authentication error") )));
exit();
}
// Get data
if( isset( $_POST['timezone'] ) ){
$timezone=$_POST['timezone'];
OC_Preferences::setValue( OC_User::getUser(), 'calendar', 'timezone', $timezone );
echo json_encode( array( "status" => "success", "data" => array( "message" => $l->t("Timezone changed") )));
}else{
echo json_encode( array( "status" => "error", "data" => array( "message" => $l->t("Invalid request") )));
}
?>

View File

@ -16,3 +16,5 @@ OC_App::addNavigationEntry( array(
'href' => OC_Helper::linkTo( 'calendar', 'index.php' ),
'icon' => OC_Helper::imagePath( 'calendar', 'icon.png' ),
'name' => $l->t('Calendar')));
OC_App::registerPersonal('calendar', 'settings');

View File

@ -0,0 +1,15 @@
$(document).ready(function(){
$("#timezone").change( function(){
// Serialize the data
var post = $( "#timezone" ).serialize();
// Ajax foo
$.post( oc_webroot + '/apps/calendar/ajax/settimezone.php', post, function(data){
if( data.status == "success" ){
}
else{
$('#timezoneerror').html( data.data.message );
}
});
return false;
});
});

View File

@ -0,0 +1,10 @@
<?php
$tmpl = new OC_Template( 'calendar', 'settings');
$timezone=OC_Preferences::getValue(OC_User::getUser(),'calendar','timezone','');
$tmpl->assign('timezone',$timezone);
$tmpl->assign('timezones',DateTimeZone::listIdentifiers());
OC_Util::addScript('calendar','settings');
return $tmpl->fetchPage();

View File

@ -0,0 +1,19 @@
<form id="calendar">
<fieldset class="personalblock">
<label for="timezone"><strong><?php echo $l->t('Timezone');?></strong></label>
<select id="timezone" name="timezone">
<?php foreach($_['timezones'] as $timezone):
if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $timezone ) ):
$ex=explode('/', $timezone, 2);//obtain continent,city
if ($continent!=$ex[0]):
if ($continent!="") echo '</optgroup>';
echo '<optgroup label="'.$ex[0].'">';
endif;
$city=$ex[1];
$continent=$ex[0];
echo '<option value="'.$timezone.'"'.($_['timezone'] == $timezone?' selected="selected"':'').'>'.$city.'</option>';
endif;
endforeach;?>
</select><span id="timezoneerror"></span>
</fieldset>
</form>