summaryrefslogtreecommitdiff
path: root/index.cgi
blob: b3e0a0745cceb37582f52e94739bb938a40cf069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/perl -w

$template_file = "/home/ivan/radio.haze.st/template.html";

use CGI;
use HTML::Table;
use Text::Template;

%type2color = (
  'upcoming'    => '999966',
  'live'        => 'ffffcc',
  'rebroadcast' => 'ffcc99',
);

%shows = (
  'high_jinx' => {
    'name'  => 'High Jinx',
    'day'   => 'sunday',
    'start' => '19',
    'len'   => '3',
    'type'  => 'upcoming',
    'startdate' => 'May 6th',
  },
  'high_jinx_rebroadcast' => {
    'name'  => 'High Jinx',
    'day'   => 'monday',
    'start' => '13',
    'len'   => '3',
    'type'  => 'upcoming',
    'startdate' => 'May 7th',
  },
  'dub_monday' => {
    'name'  => 'Dub Monday',
    'day'   => 'monday',
    'start' => '19.5',
    'len'   => '2',
    'url'   => 'http://www.voyager.org/sets',
    'type'  => 'live',
  },
  'dub_monday_rebroadcast' => {
    'name'  => 'Dub Monday',
    'day'   => 'tuesday',
    'start' => '13',
    'len'   => '2',
    'url'   => 'http://www.voyager.org/sets',
    'type'  => 'rebroadcast',
  },
  'organized_chaos' => {
    #'name'  => 'Organized<BR>Chaos',
    'name'  => 'Organized Chaos',
    'day'   => 'wednesday',
    'start' => '20',
    'len'   => '3',
    'url'   => 'http://www.angelfire.com/rant/burf/oc.html',
    'type'  => 'live',
  },
  'organized_chaos_rebroadcast' => {
    #'name'  => 'Organized<BR>Chaos',
    'name'  => 'Organized Chaos',
    'day'   => 'thursday',
    'start' => '13',
    'len'   => '3',
    'url'   => 'http://www.angelfire.com/rant/burf/oc.html',
    'type'  => 'rebroadcast',
  },
  'echo_communication_system' => {
    #'name'  => 'Echo<BR>Communication<BR>System',
    #'name'  => 'Echo Communication System',
    'name'  => 'Echo Communication System',
    'day'   => 'thursday',
    'start' => '20',
    'len'   => '3',
    'url'   => 'http://www.theoverworld.com/echo/',
    'type'  => 'live',
  },
  'echo_communication_system__rebroadcast' => {
    #'name'  => 'Echo<BR>Communication<BR>System',
    #'name'  => 'Echo Communication System',
    'name'  => 'Echo Communication System',
    'day'   => 'friday',
    'start' => '13',
    'len'   => '3',
    'url'   => 'http://www.theoverworld.com/echo/',
    'type'  => 'rebroadcast',
  },
  'sub_bass_sessions' => {
    'name'  => 'Sub-Bass Sessions',
    'day'   => 'tuesday',
    'start' => '20',
    'len'   => '2',
    'type'  => 'live',
  },
  'sub_bass_sessions_rebroadcast' => {
    'name'  => 'Sub-Bass Sessions',
    'day'   => 'wednesday',
    'start' => '13',
    'len'   => '2',
    'type'  => 'rebroadcast',
  },
);

@times = qw( midnight 1am 2am 3am 4am 5am 6am 7am 8am 9am 10am 11am noon 1pm
             2pm 3pm 4pm 5pm 6pm 7pm 8pm 9pm 10pm 11pm );
$increment = 0.5;
$showstart = 12;

$cgi = new CGI;
if ( defined($cgi->param('showstart'))
     && $cgi->param('showstart') =~ /^(\d+)$/ ) {
  die unless $1 < 24;
  $showstart = $1;
}

@showtimes = @times[$showstart..23];

$template = new Text::Template ( TYPE => 'FILE', SOURCE => $template_file )
  or die "Can't create template for $template_file: $Text::Template::ERROR";

my $text = $template->fill_in()
  or die "Can't fill in template for $template_file: $Text::Template::ERROR";

print $cgi->header, $text;

# subroutines for the template

sub table {

  my $rows = 1 + scalar(@showtimes)*(1/$increment);
  #$rows += 10;
  my $table = new HTML::Table($rows+20,8+2);
#  $table->setBorder(0);
  $table->setCellSpacing('0');
  $table->setCellPadding('1');

  my $daycol=2;
  foreach my $day ( map "${_}day", qw( Sun Mon Tues Wednes Thurs Fri Satur ) ) {
    $table->setCell(1, $daycol, "<B>${day}</B>" );
    $table->setCellAlign(1, $daycol, 'CENTER');

    my @dayshows =
      sort { $shows{$a}{'start'} <=> $shows{$b}{'start'} }
      grep { lc($shows{$_}{day}) eq lc($day) } keys %shows;
    my $pshowrow = 2;
    foreach my $show ( @dayshows ) {

      my $text = "<B>$shows{$show}{name}</B>";
      $text = qq(<A HREF="$shows{$show}{url}">$text</A>)
        if exists $shows{$show}{url};
      if ( $shows{$show}{type} eq 'upcoming' ) {
        $text .= qq(<BR><FONT SIZE="-1">starts $shows{$show}{startdate}</FONT>);
        #$text .= '<BR><FONT SIZE="-1">starts&nbsp;May&nbsp;Xth</FONT>';
      }
      if ( $shows{$show}{type} eq 'live' ) {
        $text .= "<BR><B>LIVE</B> ";
      }
      if ( $shows{$show}{type} eq 'rebroadcast' ) {
        #$text .= "<BR><B>rebroadcast</B> ";
        $text .= qq(<BR><FONT SIZE="-1">rebroadcast</FONT> );
      }
      if ( $shows{$show}{type} =~ /^(live|rebroadcast)$/ ) {
        my $start = $shows{$show}{start};
        my $stext = $times[ $start ];
        $stext =~ s/([0-9])([ap]m)/$1:30$2/ if $start != int($start);
        my $end = $shows{$show}{start} + $shows{$show}{len};
        my $etext = $times[$end];
        $etext =~ s/([0-9])([ap]m)/$1:30$2/ if $end != int($end);
        #$text .= "<B>$stext-$etext</B>";
        $text .= qq(<FONT SIZE="-1">$stext-$etext</FONT>);
      }

      my $showrow = 2 + (1/$increment) * ( $shows{$show}{start} - $showstart);

      if ( $pshowrow < $showrow ) {
        #$table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>'. "($showrow/$pshowrow) ".($showrow-$pshowrow));
        $table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>');
        $table->setCellAlign($pshowrow, $daycol, 'CENTER');
        $table->setCellRowSpan( $pshowrow, $daycol, $showrow-$pshowrow );
        #$table->setCellRowSpan( $pshowrow, $daycol, 1 );
        $table->setCellBGColor( $pshowrow, $daycol, '89201b' );
      }
      $table->setCell($showrow, $daycol, $text );
      $table->setCellAlign($showrow, $daycol, 'CENTER');
      $table->setCellBGColor($showrow, $daycol,
                             $type2color{$shows{$show}{type}});
      my $span = $shows{$show}{len} * (1/$increment);
      $table->setCellRowSpan($showrow, $daycol, $span );

      $pshowrow=$showrow+$span;
    }

    if ( $pshowrow < $rows+1 ) {
      #$table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>'. "($rows+1/$pshowrow) ".($rows+1-$pshowrow));
      $table->setCell($pshowrow, $daycol, '<B>OFF THE AIR</B>');
      $table->setCellAlign($pshowrow, $daycol, 'CENTER');
      $table->setCellRowSpan( $pshowrow, $daycol, $rows+1-$pshowrow );
      #$table->setCellRowSpan( $pshowrow, $daycol, 2 );
      $table->setCellBGColor( $pshowrow, $daycol, '89201b' );
    }

    $daycol++;
  }

  my $timerow = 2;
  foreach my $time ( @showtimes ) {
    my $text = $time;
    $text = qq(<FONT SIZE="-1">$text</FONT>) if length($text) > 4;
    $table->setCell( $timerow, 1, "<B>$text</B>" );
    $table->setCellAlign( $timerow, 1, 'CENTER' );
    $table->setCellRowSpan( $timerow, 1, 1/$increment );
    #$table->setCell( $timerow+1, 1, "<B>$text:30</B>" );
#    $table->setCell( $timerow+1, 1, "&nbsp;" );
#    $table->setCellAlign( $timerow+1, 1, 'CENTER' );
    $timerow += 1/$increment;
  }

  local $^W=0;
  my $html = $table->getTable;
  $html =~ s/<! spanned cell\)>//g;
  return $html;
}