Subversion Repositories ORC

Rev

Rev 29 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

use strict;
use cPanelUserConfig;
use Data::ICal;
use Data::ICal::Entry::Event;
use Date::ICal;
use DateTime;
use Date::Calc qw(Add_Delta_DHMS);
use Time::HiRes;

use CGI qw(:standard);
use DBI;
use tableViewer;
use WebDB;


my %games = ();
my @shifts = ();

my $query = new CGI;
my $RCid = $query->param('RCid');
if (!$RCid) { $RCid = '0'; }

my @stamp = localtime();
my $dstamp = sprintf("%d%02d%02dT%02d%02d%02dZ",
        $stamp[5] + 1900,
        $stamp[4] + 1,
        $stamp[3],
        $stamp[2],
        $stamp[1],
        $stamp[0]);

my $tz = DateTime::TimeZone->new(name => 'America/Los_Angeles');

my $dbh = WebDB::connect;
my $sth = $dbh->prepare("select * from (select id, date, dayofweek, track as 'location', time, role, teams from v_shift_officiating where RCid = ? union select id, date, dayofweek, track as 'location', time, role, teams from v_shift_announcer where RCid = ? union select id, date, dayofweek, location, time, role, '' as teams from v_shift where RCid = ?) temp order by date, time");
$sth->execute($RCid, $RCid, $RCid);
while (my $s = $sth->fetchrow_hashref) {
        $s->{role} =~ s/\-\d$//;
        push @shifts, $s;
}

my $calendar = Data::ICal->new();
my $count = 0;

for my $S (@shifts) {
        my ($startyear, $startmonth, $startday) = split /\-/, $S->{date};
        my ($endyear, $endmonth, $endday) = ($startyear, $startmonth, $startday);
        my ($stime, $etime) = split / \- /, $S->{time};
        my ($starthour, $startmin) = split /:/, $stime;
        my ($endhour, $endmin) = split /:/, $etime;
        
        my $event = Data::ICal::Entry::Event->new();
        
        my @tm = localtime();
  my $uid = sprintf("%d%02d%02d%02d%02d%02d%s%02d\@rollercon.com",
                    $tm[5] + 1900, $tm[4] + 1, $tm[3], $tm[2],
                    $tm[1], $tm[0], scalar(Time::HiRes::gettimeofday()), $count);
        
        $event->add_properties(
            uid => $uid,
            summary => "vORC: $S->{role} on $S->{location} - $S->{teams}",
            description => "" ,
            categories => "RollerCon Officiating;RollerCon Schedule;RollerCon Volunteer",
            location => "$S->{location}",
            dtstamp => $dstamp,
            dtstart => Date::ICal->new(
                            year => $startyear,
                            month => $startmonth,
                            day => $startday,
                            hour => $starthour,
                            min => $startmin,
                            sec => 0,
                            offset => "-0700")->ical,
            dtend => Date::ICal->new(
                            year => $endyear,
                            month => $endmonth,
                            day => $endday,
                            hour => $endhour,
                            min => $endmin,
                            sec => 0,
                            offset => "-0700")->ical,
            );

    $calendar->add_entry($event);
    $count++;
}

$calendar->add_properties(
#        calscale => 'GREGORIAN',
#        method => 'PUBLISH',
        'X-WR-CALNAME' => 'RollerCon Volunteer Schedule'
        );

print header('Content-type: text/calendar; charset=utf-8');
#print header('Content-Disposition: attachment; filename=export_ics.pl.ics');
print $calendar->as_string;