#!/usr/bin/perl
use Time::Local;
$options{data_directory} = ".";
require "plans_config.pl";
require "plans_lib.pl";

use Time::Local;
use IO::Socket;

print <<p1;
  This utility adjusts the times for Plans events.
  Timezone offsets for calendars are *not* changed.  Only event times.

  Loading event data...
p1


# uncomment these lines if you need to point this utility at xml files other than in the default location.
#$options{events_file} = "events.xml";
#$options{calendars_file} = "calendars.xml";

&load_calendars();
&load_events("all");

print " Enter the id for which calendar to adjust (or \"all\" to adjust all calendars):\n";
my $adjust_cal_ids = <STDIN>;
chomp $adjust_cal_ids;


print " Shift events how many hours? (i.e. 1, 6, -8, 4.5):\n";
my $adjust_hours = <STDIN>;


foreach $event_id (keys %events) {
  my %event = %{$events{$event_id}};
  if ($event_id eq "") {next;}
	if ($event{all_day_event} eq "1") {next;}  # don't adjust all-day events
  
  if ($event{cal_ids}[0] != $adjust_cal_ids && $adjust_cal_ids ne "all") {next;}
  
  print "updating event $event{id}, calendar $event{cal_ids}[0]\n";

  $events{$event_id}{start} += 3600*$adjust_hours;
  $events{$event_id}{end} += 3600*$adjust_hours;
}

&update_event($event_id);

print $debug_info;
# done already?!
