| 2 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
| 56 |
bgadell |
3 |
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
|
|
|
4 |
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
|
|
|
5 |
close STDERR;
|
|
|
6 |
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
|
|
|
7 |
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
|
|
|
8 |
|
| 2 |
- |
9 |
use strict;
|
| 8 |
- |
10 |
use cPanelUserConfig;
|
| 2 |
- |
11 |
use Data::ICal;
|
|
|
12 |
use Data::ICal::Entry::Event;
|
|
|
13 |
use Date::ICal;
|
|
|
14 |
use DateTime;
|
|
|
15 |
use Date::Calc qw(Add_Delta_DHMS);
|
|
|
16 |
use Time::HiRes;
|
|
|
17 |
|
|
|
18 |
use CGI qw(:standard);
|
|
|
19 |
use DBI;
|
| 29 |
- |
20 |
use tableViewer;
|
|
|
21 |
use WebDB;
|
| 2 |
- |
22 |
|
|
|
23 |
|
|
|
24 |
my %games = ();
|
|
|
25 |
my @shifts = ();
|
|
|
26 |
|
|
|
27 |
my $query = new CGI;
|
|
|
28 |
my $RCid = $query->param('RCid');
|
|
|
29 |
if (!$RCid) { $RCid = '0'; }
|
|
|
30 |
|
|
|
31 |
my @stamp = localtime();
|
|
|
32 |
my $dstamp = sprintf("%d%02d%02dT%02d%02d%02dZ",
|
|
|
33 |
$stamp[5] + 1900,
|
|
|
34 |
$stamp[4] + 1,
|
|
|
35 |
$stamp[3],
|
|
|
36 |
$stamp[2],
|
|
|
37 |
$stamp[1],
|
|
|
38 |
$stamp[0]);
|
|
|
39 |
|
|
|
40 |
my $tz = DateTime::TimeZone->new(name => 'America/Los_Angeles');
|
|
|
41 |
|
| 29 |
- |
42 |
my $dbh = WebDB::connect;
|
|
|
43 |
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");
|
|
|
44 |
$sth->execute($RCid, $RCid, $RCid);
|
| 2 |
- |
45 |
while (my $s = $sth->fetchrow_hashref) {
|
|
|
46 |
$s->{role} =~ s/\-\d$//;
|
|
|
47 |
push @shifts, $s;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
my $calendar = Data::ICal->new();
|
|
|
51 |
my $count = 0;
|
|
|
52 |
|
|
|
53 |
for my $S (@shifts) {
|
|
|
54 |
my ($startyear, $startmonth, $startday) = split /\-/, $S->{date};
|
|
|
55 |
my ($endyear, $endmonth, $endday) = ($startyear, $startmonth, $startday);
|
|
|
56 |
my ($stime, $etime) = split / \- /, $S->{time};
|
|
|
57 |
my ($starthour, $startmin) = split /:/, $stime;
|
|
|
58 |
my ($endhour, $endmin) = split /:/, $etime;
|
|
|
59 |
|
|
|
60 |
my $event = Data::ICal::Entry::Event->new();
|
|
|
61 |
|
|
|
62 |
my @tm = localtime();
|
|
|
63 |
my $uid = sprintf("%d%02d%02d%02d%02d%02d%s%02d\@rollercon.com",
|
|
|
64 |
$tm[5] + 1900, $tm[4] + 1, $tm[3], $tm[2],
|
|
|
65 |
$tm[1], $tm[0], scalar(Time::HiRes::gettimeofday()), $count);
|
|
|
66 |
|
|
|
67 |
$event->add_properties(
|
|
|
68 |
uid => $uid,
|
| 35 |
- |
69 |
summary => "vORC: $S->{role} on $S->{location} - $S->{teams}",
|
| 2 |
- |
70 |
description => "" ,
|
| 29 |
- |
71 |
categories => "RollerCon Officiating;RollerCon Schedule;RollerCon Volunteer",
|
|
|
72 |
location => "$S->{location}",
|
| 2 |
- |
73 |
dtstamp => $dstamp,
|
|
|
74 |
dtstart => Date::ICal->new(
|
|
|
75 |
year => $startyear,
|
|
|
76 |
month => $startmonth,
|
|
|
77 |
day => $startday,
|
|
|
78 |
hour => $starthour,
|
|
|
79 |
min => $startmin,
|
|
|
80 |
sec => 0,
|
|
|
81 |
offset => "-0700")->ical,
|
|
|
82 |
dtend => Date::ICal->new(
|
|
|
83 |
year => $endyear,
|
|
|
84 |
month => $endmonth,
|
|
|
85 |
day => $endday,
|
|
|
86 |
hour => $endhour,
|
|
|
87 |
min => $endmin,
|
|
|
88 |
sec => 0,
|
|
|
89 |
offset => "-0700")->ical,
|
|
|
90 |
);
|
|
|
91 |
|
|
|
92 |
$calendar->add_entry($event);
|
|
|
93 |
$count++;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
$calendar->add_properties(
|
|
|
97 |
# calscale => 'GREGORIAN',
|
|
|
98 |
# method => 'PUBLISH',
|
| 29 |
- |
99 |
'X-WR-CALNAME' => 'RollerCon Volunteer Schedule'
|
| 2 |
- |
100 |
);
|
|
|
101 |
|
|
|
102 |
print header('Content-type: text/calendar; charset=utf-8');
|
|
|
103 |
#print header('Content-Disposition: attachment; filename=export_ics.pl.ics');
|
|
|
104 |
print $calendar->as_string;
|