%if ($debug) {
RC: <% $rc %>
MSG: <%$msg %>
RC2: <% $rc2 %>
MSG2: <%$msg2 %>
EVENT_NAME: <%$eventname%>
DEFAULT_PLAYLIST: <% $default[0]->{'PLAYLIST_NAME'} %>
DATA:
% foreach my $k (@data) {
<%$k%>
% }
DEFAULT DATA:
% foreach my $k (@data2) {
<%$k%>
% }
START_TIME:<%$current_event->{'START_TIME'}%>
DURATION: <%$current_event->{'DURATION'}%>
SUBMITTING EVENT:
PLAYLIST: <%$new_playlist %>
EVENTNAME: <%$new_name %>
DESCRIPTION: <%$new_description %>
%}
%#########################################
%# arguments passed to this page
%#########################################
<%args>
$stationname => ''
$eventname =>''
$mode => ''
$check => 1
#ON SUBMIT
$new_name =>''
$new_type =>''
$new_playlist =>''
$new_description =>''
$new_recurrence =>''
$new_day =>''
$new_start =>''
$new_end =>''
$new_timezone =>''
$debug =>0
%args>
%##############################################
%# initialization routine
%##############################################
<%init>
use LiveConf;
use LiveLib;
use LiveSched;
use CGI ':standard';
use CGI::Cookie;
use LivePlaylist;
use LiveACL;
use Broadcast;
my $ecast_server;
my $playlists_link;
my $station_title;
my @playlists;
my @default;
my @events;
my $current_event; ## pointer to an @event element (HASH)
my @data;
my $response;
my @data2;
my ($rc2, $msg2, $response2);
my $error_severity;
my $error_title;
my $error_message;
my $nodata;
my $nodefaultdata;
my $do_dup_check = 1;
## CLEANUP INPUT FOR DB INPUT
$new_description = &LiveLib::cleanup_data_field('desc', $new_description);
$new_name = &LiveLib::cleanup_data_field('desc', $new_name);
my $dbh = &LiveLib::open_database();
#
# Figure out who is logged in and which station she's editing.
#
my ($rc, $msg, $member_name, $stn, $session_key) = &LiveACL::get_member_and_station($dbh, 2, 'schedule_event');
if (!$stationname) {
$stationname = $stn;
}
if ($rc || !$member_name || !$stn || $stn ne $stationname) {
my $q = new CGI('');
print $q->redirect("/members/login.live?action=exp");
exit;
}
#
# Get broadcaster data
#
my $b_info = &Broadcast::init_broadcast_info($dbh, $stationname, 'STA|STR');
my %station = &Broadcast::get_broadcast_info($b_info, 'STA');
my %stream = &Broadcast::get_broadcast_info($b_info, 'STR');
$station_title = $station{'TITLE'};
my $pool = $stream{'ASSIGNED_SERVER_POOL'};
$ecast_server = $LIVECONF{"Easycast::server_$pool"};
#
# "manage playlists" link appearing twice on page
#
$playlists_link = "Manage playlists";
#
# Create or edit an event
#
if ($mode eq 'submitevent') {
#
# Calc the duration
#
my $new_duration = 0;
if ($new_end ne 'cont' ) { ## CONTINUOUS PLAY IS TAGGED WITH DURATION OF ZERO IN DB
$new_duration = $new_end - $new_start;
if ($new_duration < 0) {
$new_duration += 86400; ##ADD 24HRS IF IT GOES PAST MIDNIGHT
}
}
#
# This is to re-populate the form if errors
#
$current_event -> {'STATION_NAME'} = $stationname;
$current_event -> {'STATUS'} = 1;
$current_event -> {'START_TIME'} = $new_start;
$current_event -> {'TIME_ZONE'} = $new_timezone;
$current_event -> {'RECURRENCE'} = $new_recurrence;
$current_event -> {'DESCRIPTION'} = $new_description;
$current_event -> {'PRIORITY'} = '-1';
$current_event -> {'DURATION'} = $new_duration;
$current_event -> {'EVENT_NAME'} = $new_name;
$current_event -> {'EVENT_TYPE'} = $new_type;
$current_event -> {'PLAYLIST_NAME'} = $new_playlist;
$current_event -> {'RECURRENCE_INFO'} = $new_day;
#
# Check for conflicting existing record
#
my $record_exists = 0;
if ($check) {
$record_exists = &LiveSched::does_record_exist($dbh, $new_name, $stationname);
}
if (!$record_exists) {
($rc, $msg) = &LiveSched::set_broadcaster_event($stationname, $new_type, $new_name, $new_playlist, $new_description, $new_recurrence, $new_day, '-1', $new_timezone, $new_duration, $new_start);
}
else {
($rc, $msg) = (1, "An event with named $new_name already exists. Please choose a different name for your new event.");
}
if ($rc != 0) {
$error_severity = 'error';
$error_title = 'Error Submitting Scheduler Data';
$error_message = "There was an error submitting your data to the scheduler:
". CGI::unescape($msg);
}
else {
#
# Bounce to main scheduler page with success confirmation
#
my $q = new CGI;
print $q->redirect("/broadcast/scheduler/index.live?stationname=$stationname&edit=1&confirm=1");
exit;
}
}
elsif ($mode eq 'edit') {
$do_dup_check = 0;
#
# Get scheduler event data for broadcaster's edit mode
#
($rc, $msg, $response) = &LiveSched::get_broadcaster_events('NOHEADER', $stationname);
if ($response =~/Generic error/) {
$nodata = 1;
}
elsif($rc != 0) {
$error_severity = 'error';
$error_title = 'Error Getting Scheduler Data';
$error_message = "There was an error getting data from the scheduler. Please return to the Scheduler, and try again. ($msg)";
}
else {
$response=~ s/'/'/g;
@data = split(/<\/EVENT>/, $response); ## split up into individual events
pop @data;
my $count = 0;
### PARSE CONTENT OUT OF EACH DATA ELEMENT
foreach my $data_chunk (@data) {
my $station_name;
my $status;
my $start_time;
my $time_zone;
my $recurrence;
my $description;
my $priority;
my $duration;
my $event_name;
my $event_type;
my $playlist_name;
my $recurrence_info;
if ($data_chunk=~ /