Subversion Repositories ORC

Rev

Rev 2 | Rev 29 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/usr/bin/perl
2
 
3
use strict;
8 - 4
use cPanelUserConfig;
2 - 5
use Data::ICal;
6
use Data::ICal::Entry::Event;
7
use Date::ICal;
8
use DateTime;
9
use Date::Calc qw(Add_Delta_DHMS);
10
use Time::HiRes;
11
 
12
use CGI qw(:standard);
13
use DBI;
14
use scanFunctions;
15
 
16
 
17
my %games = ();
18
my @shifts = ();
19
 
20
my $query = new CGI;
21
my $RCid = $query->param('RCid');
22
if (!$RCid) { $RCid = '0'; }
23
 
24
my @stamp = localtime();
25
my $dstamp = sprintf("%d%02d%02dT%02d%02d%02dZ",
26
        $stamp[5] + 1900,
27
        $stamp[4] + 1,
28
        $stamp[3],
29
        $stamp[2],
30
        $stamp[1],
31
        $stamp[0]);
32
 
33
my $tz = DateTime::TimeZone->new(name => 'America/Los_Angeles');
34
 
35
my $dbh = getDBConnection();
36
my $sth = $dbh->prepare("select * from (select id, date, dayofweek, track, time, role, teams from v_shift where RCid = ? union select id, date, dayofweek, track , time, 'Track Lead' as role, '' as teams from v_lead_shift where assignee_id = ?) temp order by date, time");
37
$sth->execute($RCid, $RCid);
38
while (my $s = $sth->fetchrow_hashref) {
39
	$s->{role} =~ s/\-\d$//;
40
	push @shifts, $s;
41
}
42
 
43
my $calendar = Data::ICal->new();
44
my $count = 0;
45
 
46
for my $S (@shifts) {
47
	my ($startyear, $startmonth, $startday) = split /\-/, $S->{date};
48
	my ($endyear, $endmonth, $endday) = ($startyear, $startmonth, $startday);
49
	my ($stime, $etime) = split / \- /, $S->{time};
50
	my ($starthour, $startmin) = split /:/, $stime;
51
	my ($endhour, $endmin) = split /:/, $etime;
52
 
53
	my $event = Data::ICal::Entry::Event->new();
54
 
55
	my @tm = localtime();
56
  my $uid = sprintf("%d%02d%02d%02d%02d%02d%s%02d\@rollercon.com",
57
                    $tm[5] + 1900, $tm[4] + 1, $tm[3], $tm[2],
58
                    $tm[1], $tm[0], scalar(Time::HiRes::gettimeofday()), $count);
59
 
60
	$event->add_properties(
61
            uid => $uid,
62
            summary => "ORC: $S->{role} on $S->{track} - $S->{teams}",
63
            description => "" ,
64
            categories => "RollerCon Officiating;RollerCon Schedule",
65
            location => "Track $S->{track}",
66
            dtstamp => $dstamp,
67
            dtstart => Date::ICal->new(
68
                            year => $startyear,
69
                            month => $startmonth,
70
                            day => $startday,
71
                            hour => $starthour,
72
                            min => $startmin,
73
                            sec => 0,
74
                            offset => "-0700")->ical,
75
            dtend => Date::ICal->new(
76
                            year => $endyear,
77
                            month => $endmonth,
78
                            day => $endday,
79
                            hour => $endhour,
80
                            min => $endmin,
81
                            sec => 0,
82
                            offset => "-0700")->ical,
83
            );
84
 
85
    $calendar->add_entry($event);
86
    $count++;
87
}
88
 
89
$calendar->add_properties(
90
#        calscale => 'GREGORIAN',
91
#        method => 'PUBLISH',
92
        'X-WR-CALNAME' => 'RollerCon Officiating Schedule'
93
        );
94
 
95
print header('Content-type: text/calendar; charset=utf-8');
96
#print header('Content-Disposition: attachment; filename=export_ics.pl.ics');
97
print $calendar->as_string;