Merge remote-tracking branch 'calcms/master'
* event.cgi -> broadcast.cgi * upload-audio-recordings.cgi: remove, duplicate to audio-recordings.cgi * audiorecordings.pm: connect locally to detect permissions
This commit is contained in:
@@ -31,7 +31,6 @@ sub get($$) {
|
|||||||
if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $conditions = [];
|
my $conditions = [];
|
||||||
my $bind_values = [];
|
my $bind_values = [];
|
||||||
|
|
||||||
@@ -93,12 +92,45 @@ sub get($$) {
|
|||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub update_active($$) {
|
||||||
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
|
return undef unless defined $entry->{project_id};
|
||||||
|
return undef unless defined $entry->{studio_id};
|
||||||
|
return undef unless defined $entry->{event_id};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id} ];
|
||||||
|
my $query = qq{
|
||||||
|
update calcms_audio_recordings
|
||||||
|
set active=0
|
||||||
|
where project_id=? and studio_id=? and event_id=? and active=1
|
||||||
|
};
|
||||||
|
db::put( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
|
$query = qq{
|
||||||
|
select max(id) id from calcms_audio_recordings
|
||||||
|
where project_id=? and studio_id=? and event_id=?
|
||||||
|
};
|
||||||
|
my $entries = db::get( $dbh, $query, $bind_values );
|
||||||
|
my $max = $entries->[0];
|
||||||
|
return undef unless defined $max->{id};
|
||||||
|
|
||||||
|
$query = qq{
|
||||||
|
update calcms_audio_recordings
|
||||||
|
set active=1
|
||||||
|
where id=?
|
||||||
|
};
|
||||||
|
return db::put( $dbh, $query, [$max->{id}] );
|
||||||
|
}
|
||||||
|
|
||||||
# update playout entry if differs to old values
|
# update playout entry if differs to old values
|
||||||
sub update($$$) {
|
sub update($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
my $bind_values = [
|
my $bind_values = [
|
||||||
$entry->{path}, $entry->{size},
|
$entry->{path}, $entry->{size},
|
||||||
$entry->{created_by}, $entry->{created_at},
|
$entry->{created_by}, $entry->{created_at},
|
||||||
@@ -124,19 +156,20 @@ sub update($$$) {
|
|||||||
push @$bind_values, $entry->{id};
|
push @$bind_values, $entry->{id};
|
||||||
}
|
}
|
||||||
my $result = db::put( $dbh, $query, $bind_values );
|
my $result = db::put( $dbh, $query, $bind_values );
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
# insert playout entry
|
# insert playout entry
|
||||||
sub insert ($$$) {
|
sub insert ($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
return undef unless defined $entry->{project_id};
|
||||||
return undef unless defined $entry->{studio_id};
|
return undef unless defined $entry->{studio_id};
|
||||||
return undef unless defined $entry->{event_id};
|
return undef unless defined $entry->{event_id};
|
||||||
return undef unless defined $entry->{path};
|
return undef unless defined $entry->{path};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
$entry = {
|
$entry = {
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
@@ -153,19 +186,20 @@ sub insert ($$$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
|
my $result = db::insert( $dbh, 'calcms_audio_recordings', $entry );
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
# delete playout entry
|
# delete playout entry
|
||||||
sub delete ($$$) {
|
sub delete ($$) {
|
||||||
my ($config, $dbh, $entry) = @_;
|
my ($config, $entry) = @_;
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
return undef unless defined $entry->{project_id};
|
||||||
return undef unless defined $entry->{studio_id};
|
return undef unless defined $entry->{studio_id};
|
||||||
return undef unless defined $entry->{event_id};
|
return undef unless defined $entry->{event_id};
|
||||||
return undef unless defined $entry->{path};
|
return undef unless defined $entry->{path};
|
||||||
|
|
||||||
|
my $dbh = db::connect($config);
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
delete
|
delete
|
||||||
from calcms_audio_recordings
|
from calcms_audio_recordings
|
||||||
@@ -174,41 +208,10 @@ sub delete ($$$) {
|
|||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ];
|
||||||
my $result = db::put( $dbh, $query, $bind_values );
|
my $result = db::put( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
update_active($config, $dbh, $entry);
|
update_active($config, $entry);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update_active($$$) {
|
|
||||||
my ($config, $dbh, $entry) = @_;
|
|
||||||
|
|
||||||
return undef unless defined $entry->{project_id};
|
|
||||||
return undef unless defined $entry->{studio_id};
|
|
||||||
return undef unless defined $entry->{event_id};
|
|
||||||
|
|
||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id} ];
|
|
||||||
my $query = qq{
|
|
||||||
update calcms_audio_recordings
|
|
||||||
set active=0
|
|
||||||
where project_id=? and studio_id=? and event_id=? and active=1
|
|
||||||
};
|
|
||||||
db::put( $dbh, $query, $bind_values );
|
|
||||||
|
|
||||||
$query = qq{
|
|
||||||
select max(id) id from calcms_audio_recordings
|
|
||||||
where project_id=? and studio_id=? and event_id=?
|
|
||||||
};
|
|
||||||
my $entries = db::get( $dbh, $query, $bind_values );
|
|
||||||
my $max = $entries->[0];
|
|
||||||
return undef unless defined $max->{id};
|
|
||||||
|
|
||||||
$query = qq{
|
|
||||||
update calcms_audio_recordings
|
|
||||||
set active=1
|
|
||||||
where id=?
|
|
||||||
};
|
|
||||||
return db::put( $dbh, $query, [$max->{id}] );
|
|
||||||
}
|
|
||||||
|
|
||||||
sub error($) {
|
sub error($) {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
|
|||||||
@@ -209,7 +209,6 @@ sub deleteRecording {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
|
|
||||||
my $audioRecordings = audio_recordings::get(
|
my $audioRecordings = audio_recordings::get(
|
||||||
@@ -245,7 +244,7 @@ sub deleteRecording {
|
|||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
$audioRecordings = audio_recordings::delete(
|
$audioRecordings = audio_recordings::delete(
|
||||||
$config, $dbh,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
studio_id => $params->{studio_id},
|
studio_id => $params->{studio_id},
|
||||||
@@ -410,8 +409,6 @@ sub updateDatabase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#connect
|
#connect
|
||||||
my $dbh = db::connect($config);
|
|
||||||
|
|
||||||
my $entries = audio_recordings::get(
|
my $entries = audio_recordings::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
@@ -424,7 +421,7 @@ sub updateDatabase {
|
|||||||
|
|
||||||
if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) {
|
if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) {
|
||||||
print STDERR "update\n";
|
print STDERR "update\n";
|
||||||
audio_recordings::update( $config, $dbh, $entry );
|
audio_recordings::update( $config, $entry );
|
||||||
my $entry = $entries->[0];
|
my $entry = $entries->[0];
|
||||||
$params->{id} = $entry->{id};
|
$params->{id} = $entry->{id};
|
||||||
} else {
|
} else {
|
||||||
@@ -436,7 +433,7 @@ sub updateDatabase {
|
|||||||
$entry->{rmsRight} = 0.0;
|
$entry->{rmsRight} = 0.0;
|
||||||
$entry->{audioDuration} = 0.0;
|
$entry->{audioDuration} = 0.0;
|
||||||
$entry->{modified_at} = time();
|
$entry->{modified_at} = time();
|
||||||
$entry->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
$entry->{id} = audio_recordings::insert( $config, $entry );
|
||||||
$params->{id} = $entry->{id};
|
$params->{id} = $entry->{id};
|
||||||
}
|
}
|
||||||
call_hooks($config, $entry, $params);
|
call_hooks($config, $entry, $params);
|
||||||
@@ -448,7 +445,6 @@ sub updateDatabase {
|
|||||||
sub call_hooks {
|
sub call_hooks {
|
||||||
my ($config, $entry, $params) = @_;
|
my ($config, $entry, $params) = @_;
|
||||||
print STDERR Dumper($config->{"audio-upload-hooks"});
|
print STDERR Dumper($config->{"audio-upload-hooks"});
|
||||||
my $dbh = db::connect($config);
|
|
||||||
|
|
||||||
$entry = audio_recordings::get(
|
$entry = audio_recordings::get(
|
||||||
$config, {
|
$config, {
|
||||||
@@ -468,7 +464,7 @@ sub call_hooks {
|
|||||||
$entry->{$key} = $value;
|
$entry->{$key} = $value;
|
||||||
die "invalid column $key for table calcms_audio_recordings"
|
die "invalid column $key for table calcms_audio_recordings"
|
||||||
unless exists audio_recordings::get_columns($config)->{$key};
|
unless exists audio_recordings::get_columns($config)->{$key};
|
||||||
audio_recordings::update( $config, $dbh, $entry );
|
audio_recordings::update( $config, $entry );
|
||||||
} elsif ($line =~ m/^calcms_events\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
} elsif ($line =~ m/^calcms_events\.([a-zA-Z0-9_-]+)\s*=\s*(\S+)/) {
|
||||||
my ($key, $value) = ($1, $2);
|
my ($key, $value) = ($1, $2);
|
||||||
die "invalid column $key for calcms_events\n"
|
die "invalid column $key for calcms_events\n"
|
||||||
|
|||||||
@@ -767,14 +767,14 @@ sub download {
|
|||||||
if ( $datetime =~ /(\d\d\d\d\-\d\d\-\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
if ( $datetime =~ /(\d\d\d\d\-\d\d\-\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
||||||
$datetime = $1 . '\ ' . $2 . '_' . $3;
|
$datetime = $1 . '\ ' . $2 . '_' . $3;
|
||||||
} else {
|
} else {
|
||||||
print STDERR "event.cgi::download no valid datetime found $datetime\n";
|
print STDERR "broadcast.cgi::download no valid datetime found $datetime\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $archive_dir = $config->{locations}->{local_archive_dir};
|
my $archive_dir = $config->{locations}->{local_archive_dir};
|
||||||
my $archive_url = $config->{locations}->{local_archive_url};
|
my $archive_url = $config->{locations}->{local_archive_url};
|
||||||
print STDERR "archive_dir: " . $archive_dir . "\n";
|
print STDERR "archive_dir: " . $archive_dir . "\n";
|
||||||
print STDERR "archive_url: " . $archive_url . "\n";
|
print STDERR "archive_url: " . $archive_url . "\n";
|
||||||
print STDERR "event.cgi::download look for : $archive_dir/$datetime*.mp3\n";
|
print STDERR "broadcast.cgi::download look for : $archive_dir/$datetime*.mp3\n";
|
||||||
my @files = glob( $archive_dir . '/' . $datetime . '*.mp3' );
|
my @files = glob( $archive_dir . '/' . $datetime . '*.mp3' );
|
||||||
|
|
||||||
if ( @files > 0 ) {
|
if ( @files > 0 ) {
|
||||||
@@ -814,12 +814,12 @@ sub download_audio {
|
|||||||
if ( $datetime =~ /(\d\d\d\d\-\d\d\-\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
if ( $datetime =~ /(\d\d\d\d\-\d\d\-\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
||||||
$datetime = $1 . '\ ' . $2 . '_' . $3;
|
$datetime = $1 . '\ ' . $2 . '_' . $3;
|
||||||
} else {
|
} else {
|
||||||
print STDERR "event.cgi::download no valid datetime found $datetime\n";
|
print STDERR "broadcast.cgi::download no valid datetime found $datetime\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $archive_dir = $config->{locations}->{local_archive_dir};
|
my $archive_dir = $config->{locations}->{local_archive_dir};
|
||||||
print STDERR "archive_dir: " . $archive_dir . "\n";
|
print STDERR "archive_dir: " . $archive_dir . "\n";
|
||||||
print STDERR "event.cgi::download look for : $archive_dir/$datetime*.mp3\n";
|
print STDERR "broadcast.cgi::download look for : $archive_dir/$datetime*.mp3\n";
|
||||||
my @files = glob( $archive_dir . '/' . $datetime . '*.mp3' );
|
my @files = glob( $archive_dir . '/' . $datetime . '*.mp3' );
|
||||||
if ( @files > 0 ) {
|
if ( @files > 0 ) {
|
||||||
my $file = $files[0];
|
my $file = $files[0];
|
||||||
@@ -800,7 +800,7 @@ function handleEvent(id, event){
|
|||||||
if (series_id <0) return;
|
if (series_id <0) return;
|
||||||
if (event_id <0) return;
|
if (event_id <0) return;
|
||||||
|
|
||||||
var url="event.cgi?action=edit&project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&event_id="+event_id;
|
var url="broadcast.cgi?action=edit&project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&event_id="+event_id;
|
||||||
if(event.which==1){
|
if(event.which==1){
|
||||||
load(url);
|
load(url);
|
||||||
}
|
}
|
||||||
@@ -840,7 +840,7 @@ function handleSchedule(id, start_date, event){
|
|||||||
|
|
||||||
if(event.which==1){
|
if(event.which==1){
|
||||||
//left click: create event from schedule
|
//left click: create event from schedule
|
||||||
var url="event.cgi?action=show_new_event_from_schedule&project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&start_date="+start_date;
|
var url="broadcast.cgi?action=show_new_event_from_schedule&project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&start_date="+start_date;
|
||||||
load(url);
|
load(url);
|
||||||
}
|
}
|
||||||
if(event.which==3){
|
if(event.which==3){
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ function copyFromEvent(resultSelector){
|
|||||||
|
|
||||||
function loadEvent(projectId,studioId,seriesId,eventId, callback){
|
function loadEvent(projectId,studioId,seriesId,eventId, callback){
|
||||||
|
|
||||||
var url="event.cgi";
|
var url="broadcast.cgi";
|
||||||
url+="?project_id="+projectId;
|
url+="?project_id="+projectId;
|
||||||
url+="&studio_id="+studioId;
|
url+="&studio_id="+studioId;
|
||||||
url+="&series_id="+seriesId;
|
url+="&series_id="+seriesId;
|
||||||
@@ -192,7 +192,7 @@ function changeSeries(seriesId){
|
|||||||
$.post(
|
$.post(
|
||||||
url,
|
url,
|
||||||
function(data){
|
function(data){
|
||||||
var url='event.cgi?';
|
var url='broadcast.cgi?';
|
||||||
url += '&project_id='+projectId;
|
url += '&project_id='+projectId;
|
||||||
url += '&studio_id='+studioId;
|
url += '&studio_id='+studioId;
|
||||||
url += '&series_id='+newSeriesId;
|
url += '&series_id='+newSeriesId;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ function edit_event(event_id, series_id, studio_id, project_id, hide_series){
|
|||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
elem.addClass('active');
|
elem.addClass('active');
|
||||||
var url="event.cgi?project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&event_id="+event_id+"&action=edit";
|
var url="broadcast.cgi?project_id="+project_id+"&studio_id="+studio_id+"&series_id="+series_id+"&event_id="+event_id+"&action=edit";
|
||||||
if ((hide_series!=null) && (hide_series!=''))url+='&hide_series=1';
|
if ((hide_series!=null) && (hide_series!=''))url+='&hide_series=1';
|
||||||
load(url);
|
load(url);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -842,7 +842,7 @@ sub reassign_event {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $url =
|
my $url =
|
||||||
'event.cgi?project_id='
|
'broadcast.cgi?project_id='
|
||||||
. $project_id
|
. $project_id
|
||||||
. '&studio_id='
|
. '&studio_id='
|
||||||
. $studio_id
|
. $studio_id
|
||||||
@@ -1378,7 +1378,7 @@ sub rebuild_episodes {
|
|||||||
|
|
||||||
for my $event (@$events) {
|
for my $event (@$events) {
|
||||||
print qq{<tr class="$event->{class}" onclick="window.location.href=\$(this).attr('href');"}
|
print qq{<tr class="$event->{class}" onclick="window.location.href=\$(this).attr('href');"}
|
||||||
. qq{ href="event.cgi?action=edit&project_id=$event->{project_id}&studio_id=$event->{studio_id}&series_id=$series_id&event_id=$event->{id}"\n}
|
. qq{ href="broadcast.cgi?action=edit&project_id=$event->{project_id}&studio_id=$event->{studio_id}&series_id=$series_id&event_id=$event->{id}"\n}
|
||||||
. qq{>}
|
. qq{>}
|
||||||
. join( "", map { "<td>" . ( $event->{$_} // '-' ) . "</td>" } @cols )
|
. join( "", map { "<td>" . ( $event->{$_} // '-' ) . "</td>" } @cols )
|
||||||
. "</tr>\n";
|
. "</tr>\n";
|
||||||
|
|||||||
@@ -220,7 +220,7 @@
|
|||||||
<!-- edit event -->
|
<!-- edit event -->
|
||||||
<div id="edit_event" class="panel">
|
<div id="edit_event" class="panel">
|
||||||
<form id="event_<TMPL_VAR event_id>" method="post"
|
<form id="event_<TMPL_VAR event_id>" method="post"
|
||||||
action="event.cgi?project_id=<TMPL_VAR .project_id>&studio_id=<TMPL_VAR .studio_id>&series_id=<TMPL_VAR .series_id><TMPL_UNLESS new_event>&event_id=<TMPL_VAR .event_id></TMPL_UNLESS>"
|
action="broadcast.cgi?project_id=<TMPL_VAR .project_id>&studio_id=<TMPL_VAR .studio_id>&series_id=<TMPL_VAR .series_id><TMPL_UNLESS new_event>&event_id=<TMPL_VAR .event_id></TMPL_UNLESS>"
|
||||||
>
|
>
|
||||||
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
||||||
<input type="hidden" name="studio_id" value="<TMPL_VAR .studio_id>">
|
<input type="hidden" name="studio_id" value="<TMPL_VAR .studio_id>">
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
</TMPL_IF>
|
</TMPL_IF>
|
||||||
|
|
||||||
<TMPL_IF .allow.create_event>
|
<TMPL_IF .allow.create_event>
|
||||||
<form action="event.cgi"
|
<form action="broadcast.cgi"
|
||||||
style="float:left"
|
style="float:left"
|
||||||
>
|
>
|
||||||
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
</TMPL_IF>
|
</TMPL_IF>
|
||||||
|
|
||||||
<TMPL_IF .allow.create_event>
|
<TMPL_IF .allow.create_event>
|
||||||
<form action="event.cgi"
|
<form action="broadcast.cgi"
|
||||||
style="float:left"
|
style="float:left"
|
||||||
>
|
>
|
||||||
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
<input type="hidden" name="project_id" value="<TMPL_VAR .project_id>">
|
||||||
|
|||||||
@@ -1,314 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
|
|
||||||
use strict;
|
|
||||||
use warnings;
|
|
||||||
no warnings 'redefine';
|
|
||||||
|
|
||||||
use Data::Dumper;
|
|
||||||
use CGI::Simple();
|
|
||||||
use ModPerl::Util ();
|
|
||||||
use Date::Calc();
|
|
||||||
use Time::Local();
|
|
||||||
use File::Temp();
|
|
||||||
use File::Copy();
|
|
||||||
|
|
||||||
use config();
|
|
||||||
use log();
|
|
||||||
use entry();
|
|
||||||
use localization();
|
|
||||||
use auth();
|
|
||||||
use uac();
|
|
||||||
use studios();
|
|
||||||
use series();
|
|
||||||
use template();
|
|
||||||
use audio_recordings();
|
|
||||||
use events();
|
|
||||||
use audio();
|
|
||||||
use time();
|
|
||||||
|
|
||||||
#$|=1;
|
|
||||||
binmode STDOUT, ":utf8";
|
|
||||||
|
|
||||||
my $useCgi = 0;
|
|
||||||
|
|
||||||
our $config = config::get('../config/config.cgi');
|
|
||||||
my $base_dir = $config->{locations}->{base_dir};
|
|
||||||
|
|
||||||
my $tempDir = '/var/tmp';
|
|
||||||
my $uploadLimit = 400_000_000;
|
|
||||||
|
|
||||||
my %params = ();
|
|
||||||
my $error = '';
|
|
||||||
my $cgi = undef;
|
|
||||||
my $fh = undef;
|
|
||||||
|
|
||||||
#### simple CGI
|
|
||||||
$CGI::Simple::POST_MAX = $uploadLimit;
|
|
||||||
$CGI::Simple::DISABLE_UPLOADS = 0;
|
|
||||||
|
|
||||||
$cgi = CGI::Simple->new;
|
|
||||||
my $filename = $cgi->param('upload');
|
|
||||||
$fh = $cgi->upload($filename);
|
|
||||||
$error = $cgi->cgi_error() || '';
|
|
||||||
%params = $cgi->Vars();
|
|
||||||
|
|
||||||
my $params = \%params;
|
|
||||||
binmode $fh if defined $fh;
|
|
||||||
|
|
||||||
#print "Content-type:text/html; charset=UTF-8;\n\n";
|
|
||||||
my ( $user, $expires ) = auth::get_user( $config, $params, $cgi );
|
|
||||||
exit if ( !defined $user ) || ( $user eq '' );
|
|
||||||
|
|
||||||
my $user_presets = uac::get_user_presets(
|
|
||||||
$config,
|
|
||||||
{
|
|
||||||
user => $user,
|
|
||||||
project_id => $params->{project_id},
|
|
||||||
studio_id => $params->{studio_id}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$params->{default_studio_id} = $user_presets->{studio_id};
|
|
||||||
$params = uac::setDefaultStudio( $params, $user_presets );
|
|
||||||
$params = uac::setDefaultProject( $params, $user_presets );
|
|
||||||
|
|
||||||
my $request = {
|
|
||||||
url => $ENV{QUERY_STRING} || '',
|
|
||||||
params => {
|
|
||||||
original => $params,
|
|
||||||
checked => check_params( $config, $params ),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
$request = uac::prepare_request( $request, $user_presets );
|
|
||||||
|
|
||||||
$params = $request->{params}->{checked};
|
|
||||||
|
|
||||||
my $headerParams = uac::set_template_permissions( $request->{permissions}, $params );
|
|
||||||
$headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } );
|
|
||||||
|
|
||||||
exit unless uac::check( $config, $params, $user_presets ) == 1;
|
|
||||||
print q{Content-type: text/plain; char-set:utf-8;\n\n};
|
|
||||||
|
|
||||||
uploadRecording( $config, $request );
|
|
||||||
exit;
|
|
||||||
|
|
||||||
sub uploadRecording {
|
|
||||||
my $config = shift;
|
|
||||||
my $request = shift;
|
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
|
||||||
my $permissions = $request->{permissions};
|
|
||||||
|
|
||||||
unless ( $permissions->{upload_audio_recordings} == 1 ) {
|
|
||||||
uac::permissions_denied('upload_audio_recordings');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_id' ) {
|
|
||||||
unless ( defined $params->{$attr} ) {
|
|
||||||
uac::print_error( "missing " . $attr . " to upload productions" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( defined $fh ) {
|
|
||||||
print STDERR "upload\n";
|
|
||||||
|
|
||||||
events::set_upload_status($config, {event_id=>$params->{event_id}, upload_status=>'uploading' });
|
|
||||||
|
|
||||||
my $fileInfo = uploadFile( $config, $fh, $params->{event_id}, $user, $params->{upload} );
|
|
||||||
$params->{error} .= $fileInfo->{error} if defined $fileInfo->{error};
|
|
||||||
$params->{path} = $fileInfo->{path};
|
|
||||||
$params->{size} = $fileInfo->{size};
|
|
||||||
|
|
||||||
if ($params->{error} eq ''){
|
|
||||||
events::set_upload_status($config, {event_id=>$params->{event_id}, upload_status=>'uploaded' });
|
|
||||||
$params = updateDatabase( $config, $params, $user );
|
|
||||||
}else{
|
|
||||||
events::set_upload_status($config, {event_id=>$params->{event_id}, upload_status=>'upload failed' });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
print STDERR "could not get file handle\n";
|
|
||||||
$params->{error} .= 'Could not get file handle';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $params->{error} ne '' ) {
|
|
||||||
if ( $params->{error} =~ /limit/ ) {
|
|
||||||
$params->{error} .=
|
|
||||||
"audio file size is limited to "
|
|
||||||
. int( $uploadLimit / 1000000 ) . " MB!"
|
|
||||||
. "Please make it smaller and try again!";
|
|
||||||
} else {
|
|
||||||
$params->{error} .= "Error:'$error'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub uploadFile {
|
|
||||||
my $config = $_[0];
|
|
||||||
my $fh = $_[1];
|
|
||||||
my $eventId = $_[2];
|
|
||||||
my $user = $_[3] || '';
|
|
||||||
my $filename = $_[4] || '';
|
|
||||||
|
|
||||||
# check target directory
|
|
||||||
my $targetDir = $config->{locations}->{local_audio_recordings_dir};
|
|
||||||
return { error => "could not find local_audio_recordings_dir" } unless defined $targetDir;
|
|
||||||
return { error => "local_audio_recordings_dir does not exist" } unless -e $targetDir;
|
|
||||||
|
|
||||||
# save file to disk
|
|
||||||
my $userName = $user;
|
|
||||||
$userName =~ s/[^a-zA-Z0-9\.\-\_]//g;
|
|
||||||
|
|
||||||
my $time = time::time_to_datetime();
|
|
||||||
$time =~ s/\:/\-/g;
|
|
||||||
$time =~ s/\s/\_/g;
|
|
||||||
$time =~ s/[^a-zA-Z0-9\.\-\_]//g;
|
|
||||||
|
|
||||||
$filename =~ s/\.(mp3)$//g;
|
|
||||||
$filename = join( '-', ( $time, 'id' . $eventId, $userName, $filename ) ) . '.mp3';
|
|
||||||
$filename =~ s/[^a-zA-Z0-9\.\-\_]//g;
|
|
||||||
|
|
||||||
my $tempFile = $targetDir . '/' . $filename . '.tmp';
|
|
||||||
|
|
||||||
my $start = time();
|
|
||||||
open DAT, '>', $tempFile
|
|
||||||
or return { error => 'could not save upload. ' . $! . " " . $tempFile };
|
|
||||||
binmode DAT;
|
|
||||||
my $size = 0;
|
|
||||||
my $data = '';
|
|
||||||
$time = time();
|
|
||||||
while ( my $bytesRead = $fh->read( $data, 65000 ) ) {
|
|
||||||
print DAT $data;
|
|
||||||
$size += $bytesRead;
|
|
||||||
$data = '';
|
|
||||||
if ( time() - $start >= 1){
|
|
||||||
print "$size\n";
|
|
||||||
$start = $time;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close DAT;
|
|
||||||
File::Copy::move($tempFile, $targetDir . '/' . $filename);
|
|
||||||
|
|
||||||
return {
|
|
||||||
dir => $targetDir,
|
|
||||||
path => $filename,
|
|
||||||
size => $size,
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sub updateDatabase {
|
|
||||||
my $config = shift;
|
|
||||||
my $params = shift;
|
|
||||||
my $user = shift;
|
|
||||||
|
|
||||||
my $eventDuration = getEventDuration( $config, $params->{event_id} );
|
|
||||||
|
|
||||||
my $entry = {
|
|
||||||
project_id => $params->{project_id},
|
|
||||||
studio_id => $params->{studio_id},
|
|
||||||
event_id => $params->{event_id},
|
|
||||||
path => $params->{path},
|
|
||||||
size => $params->{size},
|
|
||||||
created_by => $user,
|
|
||||||
eventDuration => $eventDuration
|
|
||||||
};
|
|
||||||
|
|
||||||
#connect
|
|
||||||
$config->{access}->{write} = 1;
|
|
||||||
my $dbh = db::connect($config);
|
|
||||||
|
|
||||||
my $entries = audio_recordings::get(
|
|
||||||
$config,
|
|
||||||
{
|
|
||||||
project_id => $entry->{project_id},
|
|
||||||
studio_id => $entry->{studio_id},
|
|
||||||
event_id => $entry->{event_id},
|
|
||||||
path => $entry->{path}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) {
|
|
||||||
print STDERR "update\n";
|
|
||||||
audio_recordings::update( $config, $dbh, $entry );
|
|
||||||
my $entry = $entries->[0];
|
|
||||||
$params->{id} = $entry->{id};
|
|
||||||
} else {
|
|
||||||
print STDERR "insert\n";
|
|
||||||
$entry->{created_by} = $user;
|
|
||||||
$entry->{processed} = 0;
|
|
||||||
$entry->{mastered} = 0;
|
|
||||||
$entry->{rmsLeft} = 0.0;
|
|
||||||
$entry->{rmsRight} = 0.0;
|
|
||||||
$entry->{audioDuration} = 0.0;
|
|
||||||
$entry->{modified_at} = time();
|
|
||||||
$params->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
|
||||||
}
|
|
||||||
$config->{access}->{write} = 0;
|
|
||||||
$params->{action_result} = 'done!';
|
|
||||||
|
|
||||||
return $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# return event duration in seconds
|
|
||||||
sub getEventDuration {
|
|
||||||
my $config = shift;
|
|
||||||
my $eventId = shift;
|
|
||||||
|
|
||||||
if ( $eventId < 1 ) {
|
|
||||||
print STDERR "invalid eventId $eventId\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $request = {
|
|
||||||
params => {
|
|
||||||
checked => events::check_params(
|
|
||||||
$config,
|
|
||||||
{
|
|
||||||
event_id => $eventId,
|
|
||||||
template => 'no',
|
|
||||||
limit => 1,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
config => $config
|
|
||||||
};
|
|
||||||
$request->{params}->{checked}->{published} = 'all';
|
|
||||||
my $events = events::get( $config, $request );
|
|
||||||
if ( scalar @$events == 0 ) {
|
|
||||||
print STDERR "getEventDuration: no event found with event_id=$eventId\n";
|
|
||||||
}
|
|
||||||
my $event = $events->[0];
|
|
||||||
my $duration =
|
|
||||||
time::get_duration_seconds( $event->{start}, $event->{end}, $config->{date}->{time_zone} );
|
|
||||||
return $duration;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub check_params {
|
|
||||||
my $config = shift;
|
|
||||||
my $params = shift;
|
|
||||||
|
|
||||||
my $checked = {};
|
|
||||||
$checked->{error} = '';
|
|
||||||
$checked->{template} = template::check( $config, $params->{template}, 'upload-audio-recordings2' );
|
|
||||||
|
|
||||||
entry::set_numbers( $checked, $params, [
|
|
||||||
'project_id', 'studio_id', 'default_studio_id', 'series_id', 'event_id', 'id']);
|
|
||||||
|
|
||||||
if ( defined $checked->{studio_id} ) {
|
|
||||||
$checked->{default_studio_id} = $checked->{studio_id};
|
|
||||||
} else {
|
|
||||||
$checked->{studio_id} = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$checked->{action} = entry::element_of( $params->{action}, ['upload', 'delete'] );
|
|
||||||
|
|
||||||
entry::set_strings( $checked, $params, [ 'name', 'description', 'path' ]);
|
|
||||||
|
|
||||||
$checked->{upload} = $params->{upload};
|
|
||||||
return $checked;
|
|
||||||
}
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user