fix array length determining and cleanup
This commit is contained in:
@@ -1,48 +0,0 @@
|
|||||||
# UTF8DBI.pm re-implementation by Pavel Kudinov http://search.cpan.org/~kudinov/
|
|
||||||
# originally from: http://dysphoria.net/code/perl-utf8/
|
|
||||||
# And patched again by Andrew Forrest, Jan 2007
|
|
||||||
|
|
||||||
use DBI 1.21;
|
|
||||||
use utf8;
|
|
||||||
use Encode();
|
|
||||||
|
|
||||||
package UTF8DBI;
|
|
||||||
use base DBI;
|
|
||||||
|
|
||||||
sub _utf8_ {
|
|
||||||
if ( ref $_ eq 'ARRAY' ) { _utf8_() foreach @$_ }
|
|
||||||
elsif ( ref $_ eq 'HASH' ) { _utf8_() foreach values %$_ }
|
|
||||||
else {
|
|
||||||
Encode::_utf8_on($_);
|
|
||||||
if ( Encode::is_utf8($_) && !Encode::is_utf8( $_, 1 ) ) {
|
|
||||||
|
|
||||||
#$_ = '⁂malformed-UTF8‼' #die "Malformed utf8 string in database"
|
|
||||||
#print data_string_desc($_)."\n"
|
|
||||||
#data_string_desc(STRING);
|
|
||||||
#Encode::decode_utf8($_);
|
|
||||||
#;
|
|
||||||
#Encode::_utf8_off($_);
|
|
||||||
#Encode::decode_utf8($_);
|
|
||||||
#Encode::encode_utf8($_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$_;
|
|
||||||
}
|
|
||||||
|
|
||||||
package UTF8DBI::db;
|
|
||||||
use base DBI::db;
|
|
||||||
|
|
||||||
sub selectrow_arrayref { return UTF8DBI::_utf8_ for shift->SUPER::selectrow_arrayref(@_) }
|
|
||||||
sub selectrow_hashref { return UTF8DBI::_utf8_ for shift->SUPER::selectrow_hashref(@_) }
|
|
||||||
sub selectall_arrayref { return UTF8DBI::_utf8_ for shift->SUPER::selectall_arrayref(@_) }
|
|
||||||
sub selectall_hashref { return UTF8DBI::_utf8_ for shift->SUPER::selectall_hashref(@_) }
|
|
||||||
sub selectcol_arrayref { return UTF8DBI::_utf8_ for shift->SUPER::selectcol_arrayref(@_) }
|
|
||||||
|
|
||||||
sub selectrow_array { @{ shift->selectrow_arrayref(@_) } }
|
|
||||||
|
|
||||||
package UTF8DBI::st;
|
|
||||||
use base DBI::st;
|
|
||||||
|
|
||||||
sub fetch { return UTF8DBI::_utf8_ for shift->SUPER::fetch(@_) }
|
|
||||||
|
|
||||||
1;
|
|
||||||
@@ -115,9 +115,9 @@ sub get_calendar {
|
|||||||
|
|
||||||
#set query string for caching
|
#set query string for caching
|
||||||
my $options = [];
|
my $options = [];
|
||||||
push( @$options, 'date=' . $params->{date} ) if ( $params->{date} ne '' );
|
push @$options, 'date=' . $params->{date} if $params->{date} ne '';
|
||||||
push( @$options, 'from_date=' . $params->{from_date} ) if ( $params->{from_date} ne '' );
|
push @$options, 'from_date=' . $params->{from_date} if $params->{from_date} ne '';
|
||||||
push( @$options, 'till_date=' . $params->{till_date} ) if ( $params->{till_date} ne '' );
|
push @$options, 'till_date=' . $params->{till_date} if $params->{till_date} ne '';
|
||||||
$ENV{QUERY_STRING} = '' . join( "&", @$options );
|
$ENV{QUERY_STRING} = '' . join( "&", @$options );
|
||||||
|
|
||||||
my $content = '';
|
my $content = '';
|
||||||
@@ -270,10 +270,10 @@ sub check_params {
|
|||||||
#set query string for caching
|
#set query string for caching
|
||||||
if ( ( !exists $ENV{QUERY_STRING} ) || ( $ENV{QUERY_STRING} eq '' ) ) {
|
if ( ( !exists $ENV{QUERY_STRING} ) || ( $ENV{QUERY_STRING} eq '' ) ) {
|
||||||
my $options = [];
|
my $options = [];
|
||||||
push( @$options, 'date=' . $date ) if $date ne '';
|
push @$options, 'date=' . $date if $date ne '';
|
||||||
push( @$options, 'from_date=' . $from_date ) if $from_date ne '';
|
push @$options, 'from_date=' . $from_date if $from_date ne '';
|
||||||
push( @$options, 'till_date=' . $till_date ) if $till_date ne '';
|
push @$options, 'till_date=' . $till_date if $till_date ne '';
|
||||||
push( @$options, 'event_id=' . $event_id ) if $event_id ne '';
|
push @$options, 'event_id=' . $event_id if $event_id ne '';
|
||||||
$ENV{QUERY_STRING} = '' . join( "&", @$options );
|
$ENV{QUERY_STRING} = '' . join( "&", @$options );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ sub set {
|
|||||||
sub save {
|
sub save {
|
||||||
my $cache = shift;
|
my $cache = shift;
|
||||||
|
|
||||||
return if ( $cache->{action} ne 'save' );
|
return if $cache->{action} ne 'save';
|
||||||
return if ( ( !defined $cache->{filename} ) || ( $cache->{filename} eq '' ) );
|
return if ( !defined $cache->{filename} ) || ( $cache->{filename} eq '' );
|
||||||
|
|
||||||
log::save_file( $cache->{filename}, $cache->{content} );
|
log::save_file( $cache->{filename}, $cache->{content} );
|
||||||
chmod 0664, $cache->{filename};
|
chmod 0664, $cache->{filename};
|
||||||
|
|||||||
@@ -264,8 +264,8 @@ sub get {
|
|||||||
};
|
};
|
||||||
|
|
||||||
$week_result->{class} .= ' selected'
|
$week_result->{class} .= ' selected'
|
||||||
if ( ( ( defined $params->{from_date} ) && ( $start_date eq $params->{from_date} ) )
|
if ( ( defined $params->{from_date} ) && ( $start_date eq $params->{from_date} ) )
|
||||||
|| ( ( defined $params->{till_date} ) && ( $end_date eq $params->{till_date} ) ) );
|
|| ( ( defined $params->{till_date} ) && ( $end_date eq $params->{till_date} ) );
|
||||||
$week_result->{class} .= " week_$weekCounter";
|
$week_result->{class} .= " week_$weekCounter";
|
||||||
$week_result->{class} =~ s/^\s+//g;
|
$week_result->{class} =~ s/^\s+//g;
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -12,12 +12,7 @@ our $config = undef;
|
|||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my $filename = shift;
|
my $filename = shift;
|
||||||
|
|
||||||
#return config if known
|
|
||||||
#my $age=(-M $filename);
|
|
||||||
#return $config::config if ((defined $config::config) && ($age <= $config::modified_at));
|
|
||||||
|
|
||||||
#reload config if changed
|
|
||||||
my $configuration = new Config::General(
|
my $configuration = new Config::General(
|
||||||
-ConfigFile => $filename,
|
-ConfigFile => $filename,
|
||||||
-UTF8 => 1
|
-UTF8 => 1
|
||||||
@@ -25,8 +20,6 @@ sub get {
|
|||||||
$config::config = $configuration->{DefaultConfig}->{config};
|
$config::config = $configuration->{DefaultConfig}->{config};
|
||||||
$config::modified_at = $age;
|
$config::modified_at = $age;
|
||||||
|
|
||||||
#print STDERR "reload $filename\n";
|
|
||||||
|
|
||||||
return $config::config;
|
return $config::config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,258 +12,259 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
|
|
||||||
#convert creole wiki text to event
|
#convert creole wiki text to event
|
||||||
sub extractEventFromWikiText {
|
sub extractEventFromWikiText {
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
my $event = shift;
|
my $event = shift;
|
||||||
$event = {} unless ( defined $event );
|
$event = {} unless ( defined $event );
|
||||||
|
|
||||||
my $title = $params->{title} || '';
|
my $title = $params->{title} || '';
|
||||||
my $content = $params->{content} || '';
|
my $content = $params->{content} || '';
|
||||||
my $local_media_url = $params->{local_media_url} || '';
|
my $local_media_url = $params->{local_media_url} || '';
|
||||||
|
|
||||||
#split content into excerpt, content and comments
|
#split content into excerpt, content and comments
|
||||||
$content =~ s/\s*\,\s*/, /g;
|
$content =~ s/\s*\,\s*/, /g;
|
||||||
my @lines = split( /\s*\-{10,99}\s*/, $content );
|
my @lines = split( /\s*\-{10,99}\s*/, $content );
|
||||||
my $lines = \@lines;
|
my $lines = \@lines;
|
||||||
for my $line (@$lines) {
|
for my $line (@$lines) {
|
||||||
$line =~ s/^\s+|\s+$//g;
|
$line =~ s/^\s+|\s+$//g;
|
||||||
}
|
}
|
||||||
if ( @lines == 1 ) {
|
if ( @lines == 1 ) {
|
||||||
$event->{content} = shift @lines;
|
$event->{content} = shift @lines;
|
||||||
} elsif ( @lines == 2 ) {
|
} elsif ( @lines == 2 ) {
|
||||||
$event->{excerpt} = shift @lines;
|
$event->{excerpt} = shift @lines;
|
||||||
$event->{content} = shift @lines;
|
$event->{content} = shift @lines;
|
||||||
} else {
|
} else {
|
||||||
$event->{excerpt} = shift @lines;
|
$event->{excerpt} = shift @lines;
|
||||||
$event->{content} = shift @lines;
|
$event->{content} = shift @lines;
|
||||||
$event->{comments} = join( "--------------------\n", @lines );
|
$event->{comments} = join( "--------------------\n", @lines );
|
||||||
}
|
}
|
||||||
if ( defined $event->{excerpt} ) {
|
if ( defined $event->{excerpt} ) {
|
||||||
$event->{excerpt} = markup::html_to_plain( $event->{excerpt} );
|
$event->{excerpt} = markup::html_to_plain( $event->{excerpt} );
|
||||||
}
|
}
|
||||||
|
|
||||||
#extract program from title
|
#extract program from title
|
||||||
$event->{program} = '';
|
$event->{program} = '';
|
||||||
|
|
||||||
if ( $title =~ /^(.*?)\:/ ) {
|
if ( $title =~ /^(.*?)\:/ ) {
|
||||||
my $program = $1;
|
my $program = $1;
|
||||||
unless ( $program =~ /\s\-\s/ ) {
|
unless ( $program =~ /\s\-\s/ ) {
|
||||||
$event->{program} = $program;
|
$event->{program} = $program;
|
||||||
$event->{program} =~ s/^\s+|\s+$//g;
|
$event->{program} =~ s/^\s+|\s+$//g;
|
||||||
$event->{program} =~ s/\s+/ /g;
|
$event->{program} =~ s/\s+/ /g;
|
||||||
$title =~ s/^.*?\:\s+//gi;
|
$title =~ s/^.*?\:\s+//gi;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#extract series_name from title
|
#extract series_name from title
|
||||||
$event->{series_name} = '';
|
$event->{series_name} = '';
|
||||||
if ( $title =~ /^(.*?)\s+\-\s+/ ) {
|
if ( $title =~ /^(.*?)\s+\-\s+/ ) {
|
||||||
$event->{series_name} = $1;
|
$event->{series_name} = $1;
|
||||||
$event->{series_name} =~ s/^\s+|\s+$//g;
|
$event->{series_name} =~ s/^\s+|\s+$//g;
|
||||||
$event->{series_name} =~ s/\s+/ /g;
|
$event->{series_name} =~ s/\s+/ /g;
|
||||||
$title =~ s/^(.*?)\s+\-\s+//gi;
|
$title =~ s/^(.*?)\s+\-\s+//gi;
|
||||||
}
|
}
|
||||||
|
|
||||||
#extract categories from title
|
#extract categories from title
|
||||||
my @categories = ();
|
my @categories = ();
|
||||||
while ( $title =~ /\((.*?),(.*?)\)/ ) {
|
while ( $title =~ /\((.*?),(.*?)\)/ ) {
|
||||||
my $category = $1;
|
my $category = $1;
|
||||||
$category =~ s/\s+/ /g;
|
$category =~ s/\s+/ /g;
|
||||||
$category =~ s/^\s+|\s+$//g;
|
$category =~ s/^\s+|\s+$//g;
|
||||||
$category =~ s/\&/\+/g;
|
$category =~ s/\&/\+/g;
|
||||||
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
||||||
|
|
||||||
$category = '';
|
$category = '';
|
||||||
$category = $2 if ( defined $2 );
|
$category = $2 if ( defined $2 );
|
||||||
$category =~ s/\s+/ /g;
|
$category =~ s/\s+/ /g;
|
||||||
$category =~ s/^\s+|\s+$//g;
|
$category =~ s/^\s+|\s+$//g;
|
||||||
$category =~ s/\&/\+/g;
|
$category =~ s/\&/\+/g;
|
||||||
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
||||||
$title =~ s/\((.*?),(.*?)\)/\($2\)/;
|
$title =~ s/\((.*?),(.*?)\)/\($2\)/;
|
||||||
}
|
}
|
||||||
if ( $title =~ /\((.*?)\)/ ) {
|
if ( $title =~ /\((.*?)\)/ ) {
|
||||||
my $category = $1;
|
my $category = $1;
|
||||||
$category =~ s/\s+/ /g;
|
$category =~ s/\s+/ /g;
|
||||||
$category =~ s/^\s+|\s+$//g;
|
$category =~ s/^\s+|\s+$//g;
|
||||||
$category =~ s/\&/\+/g;
|
$category =~ s/\&/\+/g;
|
||||||
|
|
||||||
# print $category."\n";
|
# print $category."\n";
|
||||||
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
push @categories, $category if ( defined $category && $category =~ /\S/ );
|
||||||
$title =~ s/\((.*?)\)//;
|
$title =~ s/\((.*?)\)//;
|
||||||
}
|
}
|
||||||
$event->{categories} = \@categories if ( @categories > 0 );
|
$event->{categories} = \@categories if ( @categories > 0 );
|
||||||
$event->{title} = $title;
|
$event->{title} = $title;
|
||||||
$event->{title} =~ s/^\s+|\s+$//g;
|
$event->{title} =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
if ( defined $event->{content} ) {
|
if ( defined $event->{content} ) {
|
||||||
|
|
||||||
#extract podcast_url from content link 'podcast'
|
#extract podcast_url from content link 'podcast'
|
||||||
my $podcast_url = '';
|
my $podcast_url = '';
|
||||||
if ( $event->{content} =~ /\[\[\s*([^\|\]]+)\s*\|\s*podcast\s*\]\]/i ) {
|
if ( $event->{content} =~ /\[\[\s*([^\|\]]+)\s*\|\s*podcast\s*\]\]/i ) {
|
||||||
$podcast_url = $1;
|
$podcast_url = $1;
|
||||||
|
|
||||||
# $podcast_url=~s/\|.*//g;
|
# $podcast_url=~s/\|.*//g;
|
||||||
# print "found podcast:".$podcast_url."\n";
|
# print "found podcast:".$podcast_url."\n";
|
||||||
}
|
}
|
||||||
$event->{podcast_url} = $podcast_url;
|
$event->{podcast_url} = $podcast_url;
|
||||||
|
|
||||||
#extract media_url from content link 'download'
|
#extract media_url from content link 'download'
|
||||||
my $media_url = '';
|
my $media_url = '';
|
||||||
if ( $event->{content} =~ /\[\[\s*([^\|\]]+)\s*\|\s*(direct\s+)?download\s*\]\]/i ) {
|
if ( $event->{content} =~ /\[\[\s*([^\|\]]+)\s*\|\s*(direct\s+)?download\s*\]\]/i ) {
|
||||||
$media_url = $1;
|
$media_url = $1;
|
||||||
|
|
||||||
# $podcast_url=~s/\|.*//g;
|
# $podcast_url=~s/\|.*//g;
|
||||||
# print "found media:".$media_url."\n";
|
# print "found media:".$media_url."\n";
|
||||||
}
|
}
|
||||||
$event->{media_url} = $media_url;
|
$event->{media_url} = $media_url;
|
||||||
|
|
||||||
#replace "thumbs/xxx" link by link to local media URI
|
#replace "thumbs/xxx" link by link to local media URI
|
||||||
$event->{content} =~
|
$event->{content} =~
|
||||||
s/\{\{\s*thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}/\[\[$local_media_url\/images\/$1\|\{\{$local_media_url\/thumbs\/$1\|$2\}\}\]\]/g;
|
s/\{\{\s*thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}/\[\[$local_media_url\/images\/$1\|\{\{$local_media_url\/thumbs\/$1\|$2\}\}\]\]/g;
|
||||||
|
|
||||||
#extract image from content
|
#extract image from content
|
||||||
if ( $event->{content} =~ /\{\{(.*?)(\||\}\})/ ) {
|
if ( $event->{content} =~ /\{\{(.*?)(\||\}\})/ ) {
|
||||||
$event->{image} = $1;
|
$event->{image} = $1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#meta
|
#meta
|
||||||
if ( defined $event->{comments} ) {
|
if ( defined $event->{comments} ) {
|
||||||
my $meta = extractMeta( $event->{comments} );
|
my $meta = extractMeta( $event->{comments} );
|
||||||
$event->{meta} = $meta if ( @$meta > 0 );
|
$event->{meta} = $meta if scalar @$meta > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub eventToWikiText {
|
sub eventToWikiText {
|
||||||
my $event = shift;
|
my $event = shift;
|
||||||
my $local_media_url = $event->{local_media_url} || '';
|
my $local_media_url = $event->{local_media_url} || '';
|
||||||
|
|
||||||
$event->{program} =~ s/^\s+|\s+$//g;
|
$event->{program} =~ s/^\s+|\s+$//g;
|
||||||
$event->{series_name} =~ s/^\s+|\s+$//g;
|
$event->{series_name} =~ s/^\s+|\s+$//g;
|
||||||
$event->{title} =~ s/^\s+|\s+$//g;
|
$event->{title} =~ s/^\s+|\s+$//g;
|
||||||
$event->{excerpt} =~ s/^\s+|\s+$//g;
|
$event->{excerpt} =~ s/^\s+|\s+$//g;
|
||||||
$event->{content} =~ s/^\s+|\s+$//g;
|
$event->{content} =~ s/^\s+|\s+$//g;
|
||||||
$event->{comments} =~ s/^\s+|\s+$//g;
|
$event->{comments} =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
my $title = '';
|
my $title = '';
|
||||||
if ( $event->{program} ne '' ) {
|
if ( $event->{program} ne '' ) {
|
||||||
$title = $event->{program};
|
$title = $event->{program};
|
||||||
$title .= ': ' if ( ( $event->{series_name} ne '' ) || ( $event->{title} ne '' ) );
|
$title .= ': ' if ( $event->{series_name} ne '' ) || ( $event->{title} ne '' );
|
||||||
}
|
}
|
||||||
if ( $event->{series_name} ne '' ) {
|
if ( $event->{series_name} ne '' ) {
|
||||||
$title .= $event->{series_name};
|
$title .= $event->{series_name};
|
||||||
$title .= ' - ' if ( $event->{title} ne '' );
|
$title .= ' - ' if ( $event->{title} ne '' );
|
||||||
}
|
}
|
||||||
$title .= $event->{title};
|
$title .= $event->{title};
|
||||||
if ( $event->{categories} ) {
|
if ( $event->{categories} ) {
|
||||||
$title .= ' (' . join( ",", @{ $event->{categories} } ) . ')' if ( @{ $event->{categories} } > 0 );
|
my $categories = $event->{categories};
|
||||||
}
|
$title .= ' (' . join( ",", @$categories ) . ')' if ( scalar @$categories > 0 );
|
||||||
|
}
|
||||||
|
|
||||||
my $meta = extractMeta( $event->{comments}, $event->{meta} );
|
my $meta = extractMeta( $event->{comments}, $event->{meta} );
|
||||||
|
|
||||||
#use Data::Dumper;print "extracted meta".Dumper($meta);
|
#use Data::Dumper;print "extracted meta".Dumper($meta);
|
||||||
|
|
||||||
$event->{comments} = removeMeta( $event->{comments} );
|
$event->{comments} = removeMeta( $event->{comments} );
|
||||||
$event->{wiki_comments} = $event->{comments} . "\n\n" . metaToWiki($meta);
|
$event->{wiki_comments} = $event->{comments} . "\n\n" . metaToWiki($meta);
|
||||||
|
|
||||||
#use Data::Dumper;print "event content".Dumper($event->{content});
|
#use Data::Dumper;print "event content".Dumper($event->{content});
|
||||||
|
|
||||||
#rich content editors:
|
#rich content editors:
|
||||||
#$event->{wiki_content}=markup::html_to_creole($event->{content});
|
#$event->{wiki_content}=markup::html_to_creole($event->{content});
|
||||||
|
|
||||||
#markup editors
|
#markup editors
|
||||||
$event->{wiki_content} = $event->{content};
|
$event->{wiki_content} = $event->{content};
|
||||||
|
|
||||||
# [[http://localhost/agenda_files/media/images/Vl8X7YmaWrmm9RMN_OMywA.jpg|{{http://localhost/agenda_files/media/thumbs/Vl8X7YmaWrmm9RMN_OMywA.jpg|}}]]
|
# [[http://localhost/agenda_files/media/images/Vl8X7YmaWrmm9RMN_OMywA.jpg|{{http://localhost/agenda_files/media/thumbs/Vl8X7YmaWrmm9RMN_OMywA.jpg|}}]]
|
||||||
#replace "thumbs/xxx" link by link to local media URI
|
#replace "thumbs/xxx" link by link to local media URI
|
||||||
# while ($event->{wiki_content}=~/\[\[.*?\/+media\/+images\/+(.*?)\s*\|.*?\{\{.*?\/+media\/+thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}\]\]/){
|
# while ($event->{wiki_content}=~/\[\[.*?\/+media\/+images\/+(.*?)\s*\|.*?\{\{.*?\/+media\/+thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}\]\]/){
|
||||||
$event->{wiki_content} =~
|
$event->{wiki_content} =~
|
||||||
s/\[\[.*?\/+media\/+images\/+(.*?)\s*\|.*?\{\{.*?\/+media\/+thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}\]\]/\{\{thumbs\/$1\|$3\}\}/g;
|
s/\[\[.*?\/+media\/+images\/+(.*?)\s*\|.*?\{\{.*?\/+media\/+thumbs\/+(.*?)\s*\|\s*(.*?)\s*\}\}\]\]/\{\{thumbs\/$1\|$3\}\}/g;
|
||||||
|
|
||||||
# }
|
# }
|
||||||
|
|
||||||
my $wiki_content = join( "\n" . ( "-" x 20 ) . "\n", ( $event->{excerpt}, $event->{wiki_content} ) );
|
my $wiki_content = join( "\n" . ( "-" x 20 ) . "\n", ( $event->{excerpt}, $event->{wiki_content} ) );
|
||||||
$wiki_content .= "\n" . ( "-" x 20 ) . "\n" . $event->{wiki_comments} if ( $event->{wiki_comments} =~ /\S/ );
|
$wiki_content .= "\n" . ( "-" x 20 ) . "\n" . $event->{wiki_comments} if ( $event->{wiki_comments} =~ /\S/ );
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title => $title,
|
title => $title,
|
||||||
content => $event->{content},
|
content => $event->{content},
|
||||||
wiki_content => $wiki_content
|
wiki_content => $wiki_content
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#extrace meta tags from comment text
|
#extrace meta tags from comment text
|
||||||
sub extractMeta {
|
sub extractMeta {
|
||||||
my $comments = shift;
|
my $comments = shift;
|
||||||
my $meta = shift;
|
my $meta = shift;
|
||||||
|
|
||||||
$meta = [] unless ( defined $meta );
|
$meta = [] unless ( defined $meta );
|
||||||
|
|
||||||
#push meta tags into meta list
|
#push meta tags into meta list
|
||||||
if ( defined $comments ) {
|
if ( defined $comments ) {
|
||||||
|
|
||||||
#build index for meta already defined
|
#build index for meta already defined
|
||||||
my $meta_keys = {};
|
my $meta_keys = {};
|
||||||
for my $pair (@$meta) {
|
for my $pair (@$meta) {
|
||||||
$meta_keys->{ $pair->{name} . '=' . $pair->{value} } = 1;
|
$meta_keys->{ $pair->{name} . '=' . $pair->{value} } = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ( $comments =~ /\~\~META\:(.+?)\=(.+?)\~\~/g ) {
|
while ( $comments =~ /\~\~META\:(.+?)\=(.+?)\~\~/g ) {
|
||||||
my $name = $1;
|
my $name = $1;
|
||||||
my $value = $2;
|
my $value = $2;
|
||||||
|
|
||||||
#fix meta values
|
#fix meta values
|
||||||
$name = lc($name);
|
$name = lc($name);
|
||||||
$name =~ s/^\s+|\s+$//g;
|
$name =~ s/^\s+|\s+$//g;
|
||||||
$value =~ s/^\s+|\s+$//g;
|
$value =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
#insert into list, if not defined yet
|
#insert into list, if not defined yet
|
||||||
unless ( ( $name eq '' ) || ( $value eq '' ) || ( exists $meta_keys->{ $name . '=' . $value } ) ) {
|
unless ( ( $name eq '' ) || ( $value eq '' ) || ( exists $meta_keys->{ $name . '=' . $value } ) ) {
|
||||||
push @$meta,
|
push @$meta,
|
||||||
{
|
{
|
||||||
name => $name,
|
name => $name,
|
||||||
value => $value,
|
value => $value,
|
||||||
};
|
};
|
||||||
$meta_keys->{ $name . '=' . $value } = 1;
|
$meta_keys->{ $name . '=' . $value } = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# use Data::Dumper;print Dumper($meta);
|
# use Data::Dumper;print Dumper($meta);
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
#remove meta tags from comment text
|
#remove meta tags from comment text
|
||||||
sub removeMeta {
|
sub removeMeta {
|
||||||
my $comments = shift || '';
|
my $comments = shift || '';
|
||||||
|
|
||||||
my $result = '';
|
my $result = '';
|
||||||
for my $line ( split( /\n/, $comments ) ) {
|
for my $line ( split( /\n/, $comments ) ) {
|
||||||
$result .= $line unless ( $line =~ /\~\~META\:(.+?)\=(.+?)\~\~/g );
|
$result .= $line unless ( $line =~ /\~\~META\:(.+?)\=(.+?)\~\~/g );
|
||||||
}
|
}
|
||||||
|
|
||||||
#use Data::Dumper;print "removed metsas:".Dumper($result);
|
#use Data::Dumper;print "removed metsas:".Dumper($result);
|
||||||
$result =~ s/^\s+//g;
|
$result =~ s/^\s+//g;
|
||||||
$result =~ s/\s+$//g;
|
$result =~ s/\s+$//g;
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add meta tags to comment text
|
#add meta tags to comment text
|
||||||
sub metaToWiki {
|
sub metaToWiki {
|
||||||
my $meta = shift;
|
my $meta = shift;
|
||||||
|
|
||||||
my $result = '';
|
my $result = '';
|
||||||
for my $pair (@$meta) {
|
for my $pair (@$meta) {
|
||||||
|
|
||||||
# use Data::Dumper;print Dumper($pair);
|
# use Data::Dumper;print Dumper($pair);
|
||||||
$result .= '~~META:' . $pair->{name} . '=' . $pair->{value} . '~~' . "\n";
|
$result .= '~~META:' . $pair->{name} . '=' . $pair->{value} . '~~' . "\n";
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
#use Data::Dumper;print Dumper($meta);
|
#use Data::Dumper;print Dumper($meta);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ sub connect {
|
|||||||
my $options = shift;
|
my $options = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
return $request->{connection} if ( ( defined $request ) && ( defined $request->{connection} ) );
|
return $request->{connection} if ( defined $request ) && ( defined $request->{connection} );
|
||||||
|
|
||||||
my $access_options = $options->{access};
|
my $access_options = $options->{access};
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ sub setAttributesFromSeriesTemplate {
|
|||||||
series_id => $params->{series_id},
|
series_id => $params->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( @$series != 1 ) {
|
if ( scalar @$series != 1 ) {
|
||||||
uac::print_error("series not found");
|
uac::print_error("series not found");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ sub createEvent {
|
|||||||
series_id => $event->{series_id},
|
series_id => $event->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( @$series != 1 ) {
|
if ( scalar @$series != 1 ) {
|
||||||
uac::print_error("series not found");
|
uac::print_error("series not found");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ sub createEvent {
|
|||||||
uac::print_error("studio not found");
|
uac::print_error("studio not found");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
unless ( @$studios == 1 ) {
|
unless ( scalar @$studios == 1 ) {
|
||||||
uac::print_error("studio not found");
|
uac::print_error("studio not found");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,62 +13,62 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_event_history' );
|
my $cols = db::get_columns( $dbh, 'calcms_event_history' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
return undef unless defined $condition->{studio_id};
|
return undef unless defined $condition->{studio_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'series_id=?';
|
push @conditions, 'series_id=?';
|
||||||
push @bind_values, $condition->{series_id};
|
push @bind_values, $condition->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{event_id} ) && ( $condition->{event_id} ne '' ) ) {
|
if ( ( defined $condition->{event_id} ) && ( $condition->{event_id} ne '' ) ) {
|
||||||
push @conditions, 'event_id=?';
|
push @conditions, 'event_id=?';
|
||||||
push @bind_values, $condition->{event_id};
|
push @bind_values, $condition->{event_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{change_id} ) && ( $condition->{change_id} ne '' ) ) {
|
if ( ( defined $condition->{change_id} ) && ( $condition->{change_id} ne '' ) ) {
|
||||||
push @conditions, 'id=?';
|
push @conditions, 'id=?';
|
||||||
push @bind_values, $condition->{change_id};
|
push @bind_values, $condition->{change_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $limit = '';
|
my $limit = '';
|
||||||
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
||||||
$limit = 'limit ' . $condition->{limit};
|
$limit = 'limit ' . $condition->{limit};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_event_history
|
from calcms_event_history
|
||||||
$conditions
|
$conditions
|
||||||
@@ -76,102 +76,100 @@ sub get {
|
|||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
|
|
||||||
my $changes = db::get( $dbh, $query, \@bind_values );
|
my $changes = db::get( $dbh, $query, \@bind_values );
|
||||||
|
|
||||||
#print STDERR Dumper($changes);
|
for my $change (@$changes) {
|
||||||
|
$change->{change_id} = $change->{id};
|
||||||
for my $change (@$changes) {
|
delete $change->{id};
|
||||||
$change->{change_id} = $change->{id};
|
}
|
||||||
delete $change->{id};
|
return $changes;
|
||||||
}
|
|
||||||
return $changes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_by_id {
|
sub get_by_id {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $id = shift;
|
my $id = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_event_history
|
from calcms_event_history
|
||||||
where event_id=?
|
where event_id=?
|
||||||
};
|
};
|
||||||
|
|
||||||
my $studios = db::get( $dbh, $query, [$id] );
|
my $studios = db::get( $dbh, $query, [$id] );
|
||||||
return undef if ( @$studios != 1 );
|
return undef if ( @$studios != 1 );
|
||||||
return $studios->[0];
|
return $studios->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub insert {
|
sub insert {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
$entry->{modified_at} = time::time_to_datetime( time() );
|
$entry->{modified_at} = time::time_to_datetime( time() );
|
||||||
|
|
||||||
$entry->{event_id} = $entry->{id} if ( ( defined $entry->{id} ) && ( !( defined $entry->{event_id} ) ) );
|
$entry->{event_id} = $entry->{id} if ( defined $entry->{id} ) && ( !( defined $entry->{event_id} ) );
|
||||||
delete $entry->{id};
|
delete $entry->{id};
|
||||||
|
|
||||||
#TODO:filter for existing attributes
|
#TODO:filter for existing attributes
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
my $event = {};
|
my $event = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$event->{$column} = $entry->{$column} if defined $entry->{$column};
|
$event->{$column} = $entry->{$column} if defined $entry->{$column};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_event_history', $event );
|
my $id = db::insert( $dbh, 'calcms_event_history', $event );
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# insert event
|
# insert event
|
||||||
sub insert_by_event_id {
|
sub insert_by_event_id {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return undef unless defined $options->{project_id};
|
return undef unless defined $options->{project_id};
|
||||||
return undef unless defined $options->{studio_id};
|
return undef unless defined $options->{studio_id};
|
||||||
return undef unless defined $options->{series_id};
|
return undef unless defined $options->{series_id};
|
||||||
return undef unless defined $options->{event_id};
|
return undef unless defined $options->{event_id};
|
||||||
return undef unless defined $options->{user};
|
return undef unless defined $options->{user};
|
||||||
|
|
||||||
my $sql = q{
|
my $sql = q{
|
||||||
select * from calcms_events
|
select * from calcms_events
|
||||||
where id=?
|
where id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $options->{event_id} ];
|
my $bind_values = [ $options->{event_id} ];
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $results = db::get( $dbh, $sql, $bind_values );
|
my $results = db::get( $dbh, $sql, $bind_values );
|
||||||
if ( @$results != 1 ) {
|
if ( @$results != 1 ) {
|
||||||
print STDERR "cannot find event with event_id=$options->{event_id}";
|
print STDERR "cannot find event with event_id=$options->{event_id}";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# add to history
|
# add to history
|
||||||
my $event = $results->[0];
|
my $event = $results->[0];
|
||||||
$event->{project_id} = $options->{project_id};
|
$event->{project_id} = $options->{project_id};
|
||||||
$event->{studio_id} = $options->{studio_id};
|
$event->{studio_id} = $options->{studio_id};
|
||||||
$event->{series_id} = $options->{series_id};
|
$event->{series_id} = $options->{series_id};
|
||||||
$event->{event_id} = $options->{event_id};
|
$event->{event_id} = $options->{event_id};
|
||||||
$event->{user} = $options->{user};
|
$event->{user} = $options->{user};
|
||||||
$event->{deleted} = 1;
|
$event->{deleted} = 1;
|
||||||
event_history::insert( $config, $event );
|
event_history::insert( $config, $event );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
db::put( $dbh, 'delete from calcms_event_history where event_id=?', [ $entry->{id} ] );
|
db::put( $dbh, 'delete from calcms_event_history where event_id=?', [ $entry->{id} ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
2737
lib/calcms/events.pm
2737
lib/calcms/events.pm
File diff suppressed because it is too large
Load Diff
@@ -14,11 +14,7 @@ sub send {
|
|||||||
'Data' => $mail->{'Data'},
|
'Data' => $mail->{'Data'},
|
||||||
);
|
);
|
||||||
|
|
||||||
#print '<pre>';
|
|
||||||
$msg->print( \*STDERR );
|
$msg->print( \*STDERR );
|
||||||
|
|
||||||
#print '</pre>';
|
|
||||||
|
|
||||||
$msg->send;
|
$msg->send;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -145,9 +145,6 @@ sub sync {
|
|||||||
my $studio_id = $options->{studio_id};
|
my $studio_id = $options->{studio_id};
|
||||||
my $updates = $options->{events};
|
my $updates = $options->{events};
|
||||||
|
|
||||||
#print STDERR "sync\n";
|
|
||||||
#print STDERR Dumper($updates);
|
|
||||||
|
|
||||||
# get new entries by date
|
# get new entries by date
|
||||||
my $update_by_date = {};
|
my $update_by_date = {};
|
||||||
for my $entry (@$updates) {
|
for my $entry (@$updates) {
|
||||||
|
|||||||
@@ -30,46 +30,46 @@ sub debug;
|
|||||||
|
|
||||||
# get project columns
|
# get project columns
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_projects' );
|
my $cols = db::get_columns( $dbh, 'calcms_projects' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get projects
|
# get projects
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{name} ) && ( $condition->{name} ne '' ) ) {
|
if ( ( defined $condition->{name} ) && ( $condition->{name} ne '' ) ) {
|
||||||
push @conditions, 'name=?';
|
push @conditions, 'name=?';
|
||||||
push @bind_values, $condition->{name};
|
push @bind_values, $condition->{name};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $limit = '';
|
my $limit = '';
|
||||||
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
||||||
$limit = 'limit ' . $condition->{limit};
|
$limit = 'limit ' . $condition->{limit};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_projects
|
from calcms_projects
|
||||||
$conditions
|
$conditions
|
||||||
@@ -77,423 +77,423 @@ sub get {
|
|||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
|
|
||||||
my $projects = db::get( $dbh, $query, \@bind_values );
|
my $projects = db::get( $dbh, $query, \@bind_values );
|
||||||
return $projects;
|
return $projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
# requires at least project_id
|
# requires at least project_id
|
||||||
sub getImageById {
|
sub getImageById {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $conditions = shift;
|
my $conditions = shift;
|
||||||
|
|
||||||
return undef unless defined $conditions->{project_id};
|
return undef unless defined $conditions->{project_id};
|
||||||
my $projects = project::get( $config, $conditions );
|
my $projects = project::get( $config, $conditions );
|
||||||
return undef if scalar(@$projects) != 1;
|
return undef if scalar(@$projects) != 1;
|
||||||
return $projects->[0]->{image};
|
return $projects->[0]->{image};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_date_range {
|
sub get_date_range {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select min(start_date) start_date, max(end_date) end_date
|
select min(start_date) start_date, max(end_date) end_date
|
||||||
from calcms_projects
|
from calcms_projects
|
||||||
};
|
};
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $projects = db::get( $dbh, $query );
|
my $projects = db::get( $dbh, $query );
|
||||||
return $projects->[0];
|
return $projects->[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
# insert project
|
# insert project
|
||||||
sub insert {
|
sub insert {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
my $project = {};
|
my $project = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$project->{$column} = $entry->{$column} if defined $entry->{$column};
|
$project->{$column} = $entry->{$column} if defined $entry->{$column};
|
||||||
}
|
}
|
||||||
|
|
||||||
$project->{image} = images::normalizeName( $project->{image} ) if defined $project->{image};
|
$project->{image} = images::normalizeName( $project->{image} ) if defined $project->{image};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_projects', $project );
|
my $id = db::insert( $dbh, 'calcms_projects', $project );
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# update project
|
# update project
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $project = shift;
|
my $project = shift;
|
||||||
|
|
||||||
my $columns = project::get_columns($config);
|
my $columns = project::get_columns($config);
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$entry->{$column} = $project->{$column} if defined $project->{$column};
|
$entry->{$column} = $project->{$column} if defined $project->{$column};
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
||||||
|
|
||||||
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
||||||
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
||||||
push @bind_values, $entry->{project_id};
|
push @bind_values, $entry->{project_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
update calcms_projects
|
update calcms_projects
|
||||||
set $values
|
set $values
|
||||||
where project_id=?
|
where project_id=?
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
db::put( $dbh, $query, \@bind_values );
|
db::put( $dbh, $query, \@bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
# delete project
|
# delete project
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
db::put( $dbh, 'delete from calcms_projects where project_id=?', [ $entry->{project_id} ] );
|
db::put( $dbh, 'delete from calcms_projects where project_id=?', [ $entry->{project_id} ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
# get studios of a project
|
# get studios of a project
|
||||||
sub get_studios {
|
sub get_studios {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return undef unless defined $options->{project_id};
|
return undef unless defined $options->{project_id};
|
||||||
my $project_id = $options->{project_id};
|
my $project_id = $options->{project_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_studios
|
from calcms_project_studios
|
||||||
where project_id=?
|
where project_id=?
|
||||||
};
|
};
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $project_studios = db::get( $dbh, $query, [$project_id] );
|
my $project_studios = db::get( $dbh, $query, [$project_id] );
|
||||||
|
|
||||||
return $project_studios;
|
return $project_studios;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_studio_assignments {
|
sub get_studio_assignments {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) {
|
if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $options->{project_id};
|
push @bind_values, $options->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) {
|
if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $options->{studio_id};
|
push @bind_values, $options->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_studios
|
from calcms_project_studios
|
||||||
$conditions
|
$conditions
|
||||||
};
|
};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $results = db::get( $dbh, $query, \@bind_values );
|
my $results = db::get( $dbh, $query, \@bind_values );
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
# is studio assigned to project
|
# is studio assigned to project
|
||||||
sub is_studio_assigned {
|
sub is_studio_assigned {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return 0 unless defined $entry->{project_id};
|
return 0 unless defined $entry->{project_id};
|
||||||
return 0 unless defined $entry->{studio_id};
|
return 0 unless defined $entry->{studio_id};
|
||||||
|
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_studios
|
from calcms_project_studios
|
||||||
where project_id=? and studio_id=?
|
where project_id=? and studio_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $project_id, $studio_id ];
|
my $bind_values = [ $project_id, $studio_id ];
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $project_studios = db::get( $dbh, $query, $bind_values );
|
my $project_studios = db::get( $dbh, $query, $bind_values );
|
||||||
return 1 if @$project_studios == 1;
|
return 1 if scalar @$project_studios == 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# assign studio to project
|
# assign studio to project
|
||||||
sub assign_studio {
|
sub assign_studio {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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};
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
|
|
||||||
if ( is_studio_assigned($entry) ) {
|
if ( is_studio_assigned($entry) ) {
|
||||||
print STDERR "studio $entry->{studio_id} already assigned to project $entry->{project_id}\n";
|
print STDERR "studio $entry->{studio_id} already assigned to project $entry->{project_id}\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_project_studios', $entry );
|
my $id = db::insert( $dbh, 'calcms_project_studios', $entry );
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# unassign studio from project
|
# unassign studio from project
|
||||||
sub unassign_studio {
|
sub unassign_studio {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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};
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
|
|
||||||
my $sql = 'delete from calcms_project_studios where project_id=? and studio_id=?';
|
my $sql = 'delete from calcms_project_studios where project_id=? and studio_id=?';
|
||||||
my $bind_values = [ $project_id, $studio_id ];
|
my $bind_values = [ $project_id, $studio_id ];
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
return db::put( $dbh, $sql, $bind_values );
|
return db::put( $dbh, $sql, $bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
# get series by project and studio
|
# get series by project and studio
|
||||||
sub get_series {
|
sub get_series {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return undef unless defined $options->{project_id};
|
return undef unless defined $options->{project_id};
|
||||||
return undef unless defined $options->{studio_id};
|
return undef unless defined $options->{studio_id};
|
||||||
my $project_id = $options->{project_id};
|
my $project_id = $options->{project_id};
|
||||||
my $studio_id = $options->{studio_id};
|
my $studio_id = $options->{studio_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_series
|
from calcms_project_series
|
||||||
where project_id=? and studio_id=?
|
where project_id=? and studio_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $project_id, $studio_id ];
|
my $bind_values = [ $project_id, $studio_id ];
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $project_series = db::get( $dbh, $query, $bind_values );
|
my $project_series = db::get( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
return $project_series;
|
return $project_series;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_series_assignments {
|
sub get_series_assignments {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) {
|
if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $options->{project_id};
|
push @bind_values, $options->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) {
|
if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $options->{studio_id};
|
push @bind_values, $options->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $options->{series_id} ) && ( $options->{series_id} ne '' ) ) {
|
if ( ( defined $options->{series_id} ) && ( $options->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'series_id=?';
|
push @conditions, 'series_id=?';
|
||||||
push @bind_values, $options->{series_id};
|
push @bind_values, $options->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_series
|
from calcms_project_series
|
||||||
$conditions
|
$conditions
|
||||||
};
|
};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $results = db::get( $dbh, $query, \@bind_values );
|
my $results = db::get( $dbh, $query, \@bind_values );
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
# is series assigned to project and studio
|
# is series assigned to project and studio
|
||||||
sub is_series_assigned {
|
sub is_series_assigned {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return 0 unless defined $entry->{project_id};
|
return 0 unless defined $entry->{project_id};
|
||||||
return 0 unless defined $entry->{studio_id};
|
return 0 unless defined $entry->{studio_id};
|
||||||
return 0 unless defined $entry->{series_id};
|
return 0 unless defined $entry->{series_id};
|
||||||
|
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
my $series_id = $entry->{series_id};
|
my $series_id = $entry->{series_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_project_series
|
from calcms_project_series
|
||||||
where project_id=? and studio_id=? and series_id=?
|
where project_id=? and studio_id=? and series_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $project_id, $studio_id, $series_id ];
|
my $bind_values = [ $project_id, $studio_id, $series_id ];
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $project_series = db::get( $dbh, $query, $bind_values );
|
my $project_series = db::get( $dbh, $query, $bind_values );
|
||||||
return 1 if @$project_series == 1;
|
return 1 if scalar @$project_series == 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
# assign series to project and studio
|
# assign series to project and studio
|
||||||
sub assign_series {
|
sub assign_series {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{series_id};
|
return undef unless defined $entry->{series_id};
|
||||||
|
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
my $series_id = $entry->{series_id};
|
my $series_id = $entry->{series_id};
|
||||||
|
|
||||||
if ( is_series_assigned($entry) ) {
|
if ( is_series_assigned($entry) ) {
|
||||||
print STDERR "series $series_id already assigned to project $project_id and studio $studio_id\n";
|
print STDERR "series $series_id already assigned to project $project_id and studio $studio_id\n";
|
||||||
return return undef;
|
return return undef;
|
||||||
}
|
}
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_project_series', $entry );
|
my $id = db::insert( $dbh, 'calcms_project_series', $entry );
|
||||||
print STDERR "assigned series $series_id to project $project_id and studio $studio_id\n";
|
print STDERR "assigned series $series_id to project $project_id and studio $studio_id\n";
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# unassign series from project
|
# unassign series from project
|
||||||
# TODO: remove series _single_ if no event is assigned to
|
# TODO: remove series _single_ if no event is assigned to
|
||||||
sub unassign_series {
|
sub unassign_series {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{series_id};
|
return undef unless defined $entry->{series_id};
|
||||||
|
|
||||||
my $project_id = $entry->{project_id};
|
my $project_id = $entry->{project_id};
|
||||||
my $studio_id = $entry->{studio_id};
|
my $studio_id = $entry->{studio_id};
|
||||||
my $series_id = $entry->{series_id};
|
my $series_id = $entry->{series_id};
|
||||||
|
|
||||||
my $sql = 'delete from calcms_project_series where project_id=? and studio_id=? and series_id=?';
|
my $sql = 'delete from calcms_project_series where project_id=? and studio_id=? and series_id=?';
|
||||||
my $bind_values = [ $project_id, $studio_id, $series_id ];
|
my $bind_values = [ $project_id, $studio_id, $series_id ];
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
return db::put( $dbh, $sql, $bind_values );
|
return db::put( $dbh, $sql, $bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_with_dates {
|
sub get_with_dates {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my $language = $config->{date}->{language} || 'en';
|
my $language = $config->{date}->{language} || 'en';
|
||||||
my $projects = project::get( $config, {} );
|
my $projects = project::get( $config, {} );
|
||||||
|
|
||||||
foreach my $project ( reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects) ) {
|
foreach my $project ( reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects) ) {
|
||||||
$project->{months} = get_months( $config, $project, $language );
|
$project->{months} = get_months( $config, $project, $language );
|
||||||
$project->{user} = $ENV{REMOTE_USER};
|
$project->{user} = $ENV{REMOTE_USER};
|
||||||
$project->{current} = 1 if ( $project->{name} eq $config::config->{project} );
|
$project->{current} = 1 if ( $project->{name} eq $config::config->{project} );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $projects;
|
return $projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO: add config
|
#TODO: add config
|
||||||
sub get_sorted {
|
sub get_sorted {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $projects = project::get( $config, {} );
|
my $projects = project::get( $config, {} );
|
||||||
my @projects = reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects);
|
my @projects = reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects);
|
||||||
|
|
||||||
unshift @projects,
|
unshift @projects,
|
||||||
{
|
{
|
||||||
name => 'all',
|
name => 'all',
|
||||||
title => 'alle',
|
title => 'alle',
|
||||||
priority => '0',
|
priority => '0',
|
||||||
start_date => $projects[-1]->{start_date},
|
start_date => $projects[-1]->{start_date},
|
||||||
end_date => $projects[0]->{end_date},
|
end_date => $projects[0]->{end_date},
|
||||||
};
|
};
|
||||||
return \@projects;
|
return \@projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
# internal
|
# internal
|
||||||
sub get_months {
|
sub get_months {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $project = shift;
|
my $project = shift;
|
||||||
my $language = shift || $config->{date}->{language} || 'en';
|
my $language = shift || $config->{date}->{language} || 'en';
|
||||||
|
|
||||||
my $start = $project->{start_date};
|
my $start = $project->{start_date};
|
||||||
my $end = $project->{end_date};
|
my $end = $project->{end_date};
|
||||||
|
|
||||||
( my $start_year, my $start_month, my $start_day ) = split( /\-/, $start );
|
( my $start_year, my $start_month, my $start_day ) = split( /\-/, $start );
|
||||||
my $last_day = Date::Calc::Days_in_Month( $start_year, $start_month );
|
my $last_day = Date::Calc::Days_in_Month( $start_year, $start_month );
|
||||||
$start_day = 1 if ( $start_day < 1 );
|
$start_day = 1 if ( $start_day < 1 );
|
||||||
$start_day = $last_day if ( $start_day gt $last_day );
|
$start_day = $last_day if ( $start_day gt $last_day );
|
||||||
|
|
||||||
( my $end_year, my $end_month, my $end_day ) = split( /\-/, $end );
|
( my $end_year, my $end_month, my $end_day ) = split( /\-/, $end );
|
||||||
$last_day = Date::Calc::Days_in_Month( $end_year, $end_month );
|
$last_day = Date::Calc::Days_in_Month( $end_year, $end_month );
|
||||||
$end_day = 1 if ( $end_day < 1 );
|
$end_day = 1 if ( $end_day < 1 );
|
||||||
$end_day = $last_day if ( $end_day gt $last_day );
|
$end_day = $last_day if ( $end_day gt $last_day );
|
||||||
|
|
||||||
my @months = ();
|
my @months = ();
|
||||||
for my $year ( $start_year .. $end_year ) {
|
for my $year ( $start_year .. $end_year ) {
|
||||||
my $m1 = 1;
|
my $m1 = 1;
|
||||||
my $m2 = 12;
|
my $m2 = 12;
|
||||||
$m1 = $start_month if $year eq $start_year;
|
$m1 = $start_month if $year eq $start_year;
|
||||||
$m2 = $end_month if $year eq $end_year;
|
$m2 = $end_month if $year eq $end_year;
|
||||||
|
|
||||||
for my $month ( $m1 .. $m2 ) {
|
for my $month ( $m1 .. $m2 ) {
|
||||||
my $d1 = 1;
|
my $d1 = 1;
|
||||||
my $d2 = Date::Calc::Days_in_Month( $year, $month );
|
my $d2 = Date::Calc::Days_in_Month( $year, $month );
|
||||||
$d1 = $start_day if $month eq $start_month;
|
$d1 = $start_day if $month eq $start_month;
|
||||||
$d2 = $end_day if $month eq $end_month;
|
$d2 = $end_day if $month eq $end_month;
|
||||||
push @months,
|
push @months,
|
||||||
{
|
{
|
||||||
start => time::array_to_date( $year, $month, $d1 ),
|
start => time::array_to_date( $year, $month, $d1 ),
|
||||||
end => time::array_to_date( $year, $month, $d2 ),
|
end => time::array_to_date( $year, $month, $d2 ),
|
||||||
year => $year,
|
year => $year,
|
||||||
month => $month,
|
month => $month,
|
||||||
month_name => $time::names->{$language}->{months_abbr}->[ $month - 1 ],
|
month_name => $time::names->{$language}->{months_abbr}->[ $month - 1 ],
|
||||||
title => $project->{title},
|
title => $project->{title},
|
||||||
user => $ENV{REMOTE_USER}
|
user => $ENV{REMOTE_USER}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@months = reverse @months;
|
@months = reverse @months;
|
||||||
return \@months;
|
return \@months;
|
||||||
}
|
}
|
||||||
|
|
||||||
# check project_id
|
# check project_id
|
||||||
sub check {
|
sub check {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
return "missing project_id at checking project" unless defined $options->{project_id};
|
return "missing project_id at checking project" unless defined $options->{project_id};
|
||||||
return "Please select a project" if ( $options->{project_id} eq '-1' );
|
return "Please select a project" if ( $options->{project_id} eq '-1' );
|
||||||
return "Please select a project" if ( $options->{project_id} eq '' );
|
return "Please select a project" if ( $options->{project_id} eq '' );
|
||||||
my $projects = project::get( $config, { project_id => $options->{project_id} } );
|
my $projects = project::get( $config, { project_id => $options->{project_id} } );
|
||||||
return "Sorry. unknown project" unless defined $projects;
|
return "Sorry. unknown project" unless defined $projects;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
use warnings "all";
|
|
||||||
use strict;
|
|
||||||
|
|
||||||
package projects;
|
|
||||||
|
|
||||||
print STDERR "projects.pm is not used anymore!\n";
|
|
||||||
|
|
||||||
#do not delete last line!
|
|
||||||
1;
|
|
||||||
1710
lib/calcms/series.pm
1710
lib/calcms/series.pm
File diff suppressed because it is too large
Load Diff
@@ -22,72 +22,72 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_series_dates' );
|
my $cols = db::get_columns( $dbh, 'calcms_series_dates' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get all series_dates for studio_id and series_id within given time range
|
# get all series_dates for studio_id and series_id within given time range
|
||||||
# calculate start_date, end_date, weeday, day from start and end(datetime)
|
# calculate start_date, end_date, weeday, day from start and end(datetime)
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'series_id=?';
|
push @conditions, 'series_id=?';
|
||||||
push @bind_values, $condition->{series_id};
|
push @bind_values, $condition->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
||||||
push @conditions, 'start=?';
|
push @conditions, 'start=?';
|
||||||
push @bind_values, $condition->{start_at};
|
push @bind_values, $condition->{start_at};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
||||||
push @conditions, 'start_date>=?';
|
push @conditions, 'start_date>=?';
|
||||||
push @bind_values, $condition->{from};
|
push @bind_values, $condition->{from};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
||||||
push @conditions, 'end_date<?';
|
push @conditions, 'end_date<?';
|
||||||
push @bind_values, $condition->{till};
|
push @bind_values, $condition->{till};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
||||||
push @conditions, 'id=?';
|
push @conditions, 'id=?';
|
||||||
push @bind_values, $condition->{schedule_id};
|
push @bind_values, $condition->{schedule_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
||||||
push @conditions, 'exclude=?';
|
push @conditions, 'exclude=?';
|
||||||
push @bind_values, $condition->{exclude};
|
push @bind_values, $condition->{exclude};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select date(start) start_date
|
select date(start) start_date
|
||||||
,date(end) end_date
|
,date(end) end_date
|
||||||
,dayname(start) weekday
|
,dayname(start) weekday
|
||||||
@@ -105,129 +105,129 @@ sub get {
|
|||||||
order by start
|
order by start
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR $query."\n";
|
#print STDERR $query."\n";
|
||||||
#print STDERR Dumper(\@bind_values);
|
#print STDERR Dumper(\@bind_values);
|
||||||
|
|
||||||
my $entries = db::get( $dbh, $query, \@bind_values );
|
my $entries = db::get( $dbh, $query, \@bind_values );
|
||||||
for my $entry (@$entries) {
|
for my $entry (@$entries) {
|
||||||
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
#check if event is scheduled (on permission check)
|
#check if event is scheduled (on permission check)
|
||||||
sub is_event_scheduled {
|
sub is_event_scheduled {
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return 0 unless defined $options->{project_id};
|
return 0 unless defined $options->{project_id};
|
||||||
return 0 unless defined $options->{studio_id};
|
return 0 unless defined $options->{studio_id};
|
||||||
return 0 unless defined $options->{series_id};
|
return 0 unless defined $options->{series_id};
|
||||||
return 0 unless defined $options->{start_at};
|
return 0 unless defined $options->{start_at};
|
||||||
|
|
||||||
my $config = $request->{config};
|
my $config = $request->{config};
|
||||||
my $schedules = series_dates::get(
|
my $schedules = series_dates::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id},
|
studio_id => $options->{studio_id},
|
||||||
series_id => $options->{series_id},
|
series_id => $options->{series_id},
|
||||||
start_at => $options->{start_at}
|
start_at => $options->{start_at}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return 0 if ( @$schedules != 1 );
|
return 0 if scalar @$schedules != 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#get all series for given studio_id, time range and search
|
#get all series for given studio_id, time range and search
|
||||||
sub get_series {
|
sub get_series {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $date_range_include = 0;
|
my $date_range_include = 0;
|
||||||
$date_range_include = 1 if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
$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 = ();
|
||||||
|
|
||||||
push @conditions, 'd.series_id=s.id';
|
push @conditions, 'd.series_id=s.id';
|
||||||
|
|
||||||
# push @conditions, 'd.studio_id=s.studio_id';
|
# push @conditions, 'd.studio_id=s.studio_id';
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'd.project_id=?';
|
push @conditions, 'd.project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'd.studio_id=?';
|
push @conditions, 'd.studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'd.series_id=?';
|
push @conditions, 'd.series_id=?';
|
||||||
push @bind_values, $condition->{series_id};
|
push @bind_values, $condition->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
||||||
push @conditions, 'd.start=?';
|
push @conditions, 'd.start=?';
|
||||||
push @bind_values, $condition->{start_at};
|
push @bind_values, $condition->{start_at};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
||||||
if ( $date_range_include == 1 ) {
|
if ( $date_range_include == 1 ) {
|
||||||
push @conditions, 'd.end_date>=?';
|
push @conditions, 'd.end_date>=?';
|
||||||
push @bind_values, $condition->{from};
|
push @bind_values, $condition->{from};
|
||||||
} else {
|
} else {
|
||||||
push @conditions, 'd.start_date>=?';
|
push @conditions, 'd.start_date>=?';
|
||||||
push @bind_values, $condition->{from};
|
push @bind_values, $condition->{from};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
||||||
if ( $date_range_include == 1 ) {
|
if ( $date_range_include == 1 ) {
|
||||||
push @conditions, 'd.start_date<=?';
|
push @conditions, 'd.start_date<=?';
|
||||||
push @bind_values, $condition->{till};
|
push @bind_values, $condition->{till};
|
||||||
} else {
|
} else {
|
||||||
push @conditions, 'd.end_date<?';
|
push @conditions, 'd.end_date<?';
|
||||||
push @bind_values, $condition->{till};
|
push @bind_values, $condition->{till};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
||||||
push @conditions, 'd.id=?';
|
push @conditions, 'd.id=?';
|
||||||
push @bind_values, $condition->{schedule_id};
|
push @bind_values, $condition->{schedule_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
||||||
push @conditions, 'd.exclude=?';
|
push @conditions, 'd.exclude=?';
|
||||||
push @bind_values, $condition->{exclude};
|
push @bind_values, $condition->{exclude};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $search_cond = '';
|
my $search_cond = '';
|
||||||
if ( ( defined $condition->{search} ) && ( $condition->{search} ne '' ) ) {
|
if ( ( defined $condition->{search} ) && ( $condition->{search} ne '' ) ) {
|
||||||
my $search = lc $condition->{search};
|
my $search = lc $condition->{search};
|
||||||
$search =~ s/[^a-z0-9\_\.\-\:\!öäüßÖÄÜ \&]/%/;
|
$search =~ s/[^a-z0-9\_\.\-\:\!öäüßÖÄÜ \&]/%/;
|
||||||
$search =~ s/\%+/\%/;
|
$search =~ s/\%+/\%/;
|
||||||
$search =~ s/^[\%\s]+//;
|
$search =~ s/^[\%\s]+//;
|
||||||
$search =~ s/[\%\s]+$//;
|
$search =~ s/[\%\s]+$//;
|
||||||
if ( $search ne '' ) {
|
if ( $search ne '' ) {
|
||||||
$search = '%' . $search . '%';
|
$search = '%' . $search . '%';
|
||||||
my @attr = ( 's.title', 's.series_name', 's.excerpt', 's.category', 's.content' );
|
my @attr = ( 's.title', 's.series_name', 's.excerpt', 's.category', 's.content' );
|
||||||
push @conditions, "(" . join( " or ", map { 'lower(' . $_ . ') like ?' } @attr ) . ")";
|
push @conditions, "(" . join( " or ", map { 'lower(' . $_ . ') like ?' } @attr ) . ")";
|
||||||
for my $attr (@attr) {
|
for my $attr (@attr) {
|
||||||
push @bind_values, $search;
|
push @bind_values, $search;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select date(d.start) start_date
|
select date(d.start) start_date
|
||||||
,date(d.end) end_date
|
,date(d.end) end_date
|
||||||
,dayname(d.start) weekday
|
,dayname(d.start) weekday
|
||||||
@@ -248,333 +248,333 @@ sub get_series {
|
|||||||
order by start
|
order by start
|
||||||
};
|
};
|
||||||
|
|
||||||
my $entries = db::get( $dbh, $query, \@bind_values );
|
my $entries = db::get( $dbh, $query, \@bind_values );
|
||||||
|
|
||||||
for my $entry (@$entries) {
|
for my $entry (@$entries) {
|
||||||
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
# add series schedule
|
# add series schedule
|
||||||
$entries = series_dates::addSeriesScheduleAttributes( $config, $entries );
|
$entries = series_dates::addSeriesScheduleAttributes( $config, $entries );
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub addSeriesScheduleAttributes {
|
sub addSeriesScheduleAttributes {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entries = shift;
|
my $entries = shift;
|
||||||
|
|
||||||
my $scheduleIds = {};
|
my $scheduleIds = {};
|
||||||
|
|
||||||
# get series schedule ids used at entries
|
# get series schedule ids used at entries
|
||||||
for my $entry (@$entries) {
|
for my $entry (@$entries) {
|
||||||
$scheduleIds->{ $entry->{series_schedule_id} } = 1;
|
$scheduleIds->{ $entry->{series_schedule_id} } = 1;
|
||||||
}
|
}
|
||||||
my @scheduleIds = keys %$scheduleIds;
|
my @scheduleIds = keys %$scheduleIds;
|
||||||
return $entries if scalar(@scheduleIds) == 0;
|
return $entries if scalar(@scheduleIds) == 0;
|
||||||
|
|
||||||
# get schedules with schedule ids
|
# get schedules with schedule ids
|
||||||
my $schedules = series_schedule::get(
|
my $schedules = series_schedule::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
schedule_ids => \@scheduleIds
|
schedule_ids => \@scheduleIds
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
# get schedules by id
|
# get schedules by id
|
||||||
my $scheduleById = {};
|
my $scheduleById = {};
|
||||||
for my $schedule (@$schedules) {
|
for my $schedule (@$schedules) {
|
||||||
$scheduleById->{ $schedule->{schedule_id} } = $schedule;
|
$scheduleById->{ $schedule->{schedule_id} } = $schedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $entry (@$entries) {
|
for my $entry (@$entries) {
|
||||||
$entry->{frequency} = $scheduleById->{ $entry->{series_schedule_id} }->{frequency};
|
$entry->{frequency} = $scheduleById->{ $entry->{series_schedule_id} }->{frequency};
|
||||||
$entry->{period_type} = $scheduleById->{ $entry->{series_schedule_id} }->{period_type};
|
$entry->{period_type} = $scheduleById->{ $entry->{series_schedule_id} }->{period_type};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
#update series dates for all schedules of a series and studio_id
|
#update series dates for all schedules of a series and studio_id
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{series_id};
|
return undef unless defined $entry->{series_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
#delete all dates for series (by studio and series id)
|
#delete all dates for series (by studio and series id)
|
||||||
series_dates::delete( $config, $entry );
|
series_dates::delete( $config, $entry );
|
||||||
|
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
|
|
||||||
#get all schedules for series ordered by exclude, date
|
#get all schedules for series ordered by exclude, date
|
||||||
my $schedules = series_schedule::get(
|
my $schedules = series_schedule::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#add scheduled series dates and remove exluded dates
|
#add scheduled series dates and remove exluded dates
|
||||||
my $series_dates = {};
|
my $series_dates = {};
|
||||||
|
|
||||||
#TODO:set schedules exclude to 0 if not 1
|
#TODO:set schedules exclude to 0 if not 1
|
||||||
#insert all normal dates (not excludes)
|
#insert all normal dates (not excludes)
|
||||||
for my $schedule (@$schedules) {
|
for my $schedule (@$schedules) {
|
||||||
my $dates = get_schedule_dates( $schedule, { exclude => 0 } );
|
my $dates = get_schedule_dates( $schedule, { exclude => 0 } );
|
||||||
for my $date (@$dates) {
|
for my $date (@$dates) {
|
||||||
$date->{exclude} = 0;
|
$date->{exclude} = 0;
|
||||||
$series_dates->{ $date->{start} } = $date;
|
$series_dates->{ $date->{start} } = $date;
|
||||||
|
|
||||||
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#insert / overwrite all exlude dates
|
#insert / overwrite all exlude dates
|
||||||
for my $schedule (@$schedules) {
|
for my $schedule (@$schedules) {
|
||||||
my $dates = get_schedule_dates( $schedule, { exclude => 1 } );
|
my $dates = get_schedule_dates( $schedule, { exclude => 1 } );
|
||||||
for my $date (@$dates) {
|
for my $date (@$dates) {
|
||||||
$date->{exclude} = 1;
|
$date->{exclude} = 1;
|
||||||
$series_dates->{ $date->{start} } = $date;
|
$series_dates->{ $date->{start} } = $date;
|
||||||
|
|
||||||
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR Dumper($series_dates->{'2014-02-05 19:00:00'});
|
#print STDERR Dumper($series_dates->{'2014-02-05 19:00:00'});
|
||||||
|
|
||||||
my $request = { config => $config };
|
my $request = { config => $config };
|
||||||
|
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $j = 0;
|
my $j = 0;
|
||||||
for my $date ( keys %$series_dates ) {
|
for my $date ( keys %$series_dates ) {
|
||||||
my $series_date = $series_dates->{$date};
|
my $series_date = $series_dates->{$date};
|
||||||
|
|
||||||
#insert date
|
#insert date
|
||||||
my $entry = {
|
my $entry = {
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
series_schedule_id => $series_date->{series_schedule_id},
|
series_schedule_id => $series_date->{series_schedule_id},
|
||||||
start => $series_date->{start},
|
start => $series_date->{start},
|
||||||
end => $series_date->{end},
|
end => $series_date->{end},
|
||||||
exclude => $series_date->{exclude},
|
exclude => $series_date->{exclude},
|
||||||
};
|
};
|
||||||
if ( studio_timeslot_dates::can_studio_edit_events( $config, $entry ) == 1 ) { # by studio_id, start, end
|
if ( studio_timeslot_dates::can_studio_edit_events( $config, $entry ) == 1 ) { # by studio_id, start, end
|
||||||
$entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start );
|
$entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start );
|
||||||
$entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start );
|
$entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start );
|
||||||
db::insert( $dbh, 'calcms_series_dates', $entry );
|
db::insert( $dbh, 'calcms_series_dates', $entry );
|
||||||
|
|
||||||
#print STDERR "$entry->{start_date}\n";
|
#print STDERR "$entry->{start_date}\n";
|
||||||
$i++;
|
$i++;
|
||||||
} else {
|
} else {
|
||||||
$j++;
|
$j++;
|
||||||
|
|
||||||
#print STDERR Dumper($entry);
|
#print STDERR Dumper($entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR "$i series_dates updates\n";
|
#print STDERR "$i series_dates updates\n";
|
||||||
return $j . " dates out of studio times, " . $i;
|
return $j . " dates out of studio times, " . $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_schedule_dates {
|
sub get_schedule_dates {
|
||||||
my $schedule = shift;
|
my $schedule = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my $is_exclude = $options->{exclude} || 0;
|
my $is_exclude = $options->{exclude} || 0;
|
||||||
my $dates = [];
|
my $dates = [];
|
||||||
return $dates if ( ( $is_exclude eq '1' ) && ( $schedule->{exclude} ne '1' ) );
|
return $dates if ( $is_exclude eq '1' ) && ( $schedule->{exclude} ne '1' );
|
||||||
return $dates if ( ( $is_exclude eq '0' ) && ( $schedule->{exclude} eq '1' ) );
|
return $dates if ( $is_exclude eq '0' ) && ( $schedule->{exclude} eq '1' );
|
||||||
|
|
||||||
if ( $schedule->{period_type} eq 'single' ) {
|
if ( $schedule->{period_type} eq 'single' ) {
|
||||||
$dates = get_single_date( $schedule->{start}, $schedule->{duration} );
|
$dates = get_single_date( $schedule->{start}, $schedule->{duration} );
|
||||||
} elsif ( $schedule->{period_type} eq 'days' ) {
|
} elsif ( $schedule->{period_type} eq 'days' ) {
|
||||||
$dates = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{frequency} );
|
$dates = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{frequency} );
|
||||||
} elsif ( $schedule->{period_type} eq 'week_of_month' ) {
|
} elsif ( $schedule->{period_type} eq 'week_of_month' ) {
|
||||||
$dates = get_week_of_month_dates(
|
$dates = get_week_of_month_dates(
|
||||||
$schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{week_of_month},
|
$schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{week_of_month},
|
||||||
$schedule->{weekday}, $schedule->{month}, $schedule->{nextDay}
|
$schedule->{weekday}, $schedule->{month}, $schedule->{nextDay}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print STDERR "unknown schedule period_type\n";
|
print STDERR "unknown schedule period_type\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# set series schedule id
|
# set series schedule id
|
||||||
for my $date (@$dates) {
|
for my $date (@$dates) {
|
||||||
$date->{series_schedule_id} = $schedule->{schedule_id};
|
$date->{series_schedule_id} = $schedule->{schedule_id};
|
||||||
}
|
}
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_week_of_month_dates {
|
sub get_week_of_month_dates {
|
||||||
my $start = shift; # datetime string
|
my $start = shift; # datetime string
|
||||||
my $end = shift; # datetime string
|
my $end = shift; # datetime string
|
||||||
my $duration = shift; # in minutes
|
my $duration = shift; # in minutes
|
||||||
my $week = shift; # every nth week of month
|
my $week = shift; # every nth week of month
|
||||||
my $weekday = shift; # weekday [1..7]
|
my $weekday = shift; # weekday [1..7]
|
||||||
my $frequency = shift; # every 1st,2nd,3th time
|
my $frequency = shift; # every 1st,2nd,3th time
|
||||||
my $nextDay = shift; # add 24 hours to start, (for night hours at last weekday of month)
|
my $nextDay = shift; # add 24 hours to start, (for night hours at last weekday of month)
|
||||||
|
|
||||||
return undef if $start eq '';
|
return undef if $start eq '';
|
||||||
return undef if $end eq '';
|
return undef if $end eq '';
|
||||||
return undef if $duration eq '';
|
return undef if $duration eq '';
|
||||||
return undef if $week eq '';
|
return undef if $week eq '';
|
||||||
return undef if $weekday eq '';
|
return undef if $weekday eq '';
|
||||||
return undef if $frequency eq '';
|
return undef if $frequency eq '';
|
||||||
return undef if $frequency == 0;
|
return undef if $frequency == 0;
|
||||||
|
|
||||||
my $start_dates = time::get_nth_weekday_in_month( $start, $end, $week, $weekday );
|
my $start_dates = time::get_nth_weekday_in_month( $start, $end, $week, $weekday );
|
||||||
|
|
||||||
if ( ( defined $nextDay ) && ( $nextDay > 0 ) ) {
|
if ( ( defined $nextDay ) && ( $nextDay > 0 ) ) {
|
||||||
for ( my $i = 0 ; $i < @$start_dates ; $i++ ) {
|
for ( my $i = 0 ; $i < @$start_dates ; $i++ ) {
|
||||||
$start_dates->[$i] = time::add_hours_to_datetime( $start_dates->[$i], 24 );
|
$start_dates->[$i] = time::add_hours_to_datetime( $start_dates->[$i], 24 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $results = [];
|
my $results = [];
|
||||||
|
|
||||||
my $c = -1;
|
my $c = -1;
|
||||||
for my $start_datetime (@$start_dates) {
|
for my $start_datetime (@$start_dates) {
|
||||||
$c++;
|
$c++;
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
next unless @start >= 6;
|
next unless @start >= 6;
|
||||||
next if ( ( $c % $frequency ) != 0 );
|
next if ( $c % $frequency ) != 0;
|
||||||
|
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$start[0], $start[1], $start[2], # start date
|
$start[0], $start[1], $start[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
my $end_datetime = time::array_to_datetime( \@end_datetime );
|
my $end_datetime = time::array_to_datetime( \@end_datetime );
|
||||||
|
|
||||||
push @$results,
|
push @$results,
|
||||||
{
|
{
|
||||||
start => $start_datetime,
|
start => $start_datetime,
|
||||||
end => $end_datetime
|
end => $end_datetime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add duration to a single date
|
#add duration to a single date
|
||||||
sub get_single_date {
|
sub get_single_date {
|
||||||
my $start_datetime = shift;
|
my $start_datetime = shift;
|
||||||
my $duration = shift;
|
my $duration = shift;
|
||||||
|
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
return unless @start >= 6;
|
return unless @start >= 6;
|
||||||
|
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$start[0], $start[1], $start[2], # start date
|
$start[0], $start[1], $start[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
my $date = {
|
my $date = {
|
||||||
start => $start_datetime,
|
start => $start_datetime,
|
||||||
end => time::array_to_datetime( \@end_datetime )
|
end => time::array_to_datetime( \@end_datetime )
|
||||||
};
|
};
|
||||||
return [$date];
|
return [$date];
|
||||||
}
|
}
|
||||||
|
|
||||||
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
|
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
|
||||||
sub get_dates {
|
sub get_dates {
|
||||||
my $start_datetime = shift;
|
my $start_datetime = shift;
|
||||||
my $end_date = shift;
|
my $end_date = shift;
|
||||||
my $duration = shift; # in minutes
|
my $duration = shift; # in minutes
|
||||||
my $frequency = shift; # in days
|
my $frequency = shift; # in days
|
||||||
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
|
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
|
||||||
|
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
return unless @start >= 6;
|
return unless @start >= 6;
|
||||||
my @start_date = ( $start[0], $start[1], $start[2] );
|
my @start_date = ( $start[0], $start[1], $start[2] );
|
||||||
my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] );
|
my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] );
|
||||||
|
|
||||||
#print STDERR "$start_datetime,$end_date,$duration,$frequency\n";
|
#print STDERR "$start_datetime,$end_date,$duration,$frequency\n";
|
||||||
|
|
||||||
#return on single date
|
#return on single date
|
||||||
my $date = {};
|
my $date = {};
|
||||||
$date->{start} = sprintf( "%04d-%02d-%02d", @start_date ) . ' ' . $start_time;
|
$date->{start} = sprintf( "%04d-%02d-%02d", @start_date ) . ' ' . $start_time;
|
||||||
return undef if $duration eq '';
|
return undef if $duration eq '';
|
||||||
|
|
||||||
return undef if ( ( $frequency eq '' ) || ( $end_date eq '' ) );
|
return undef if ( $frequency eq '' ) || ( $end_date eq '' );
|
||||||
|
|
||||||
#continue on recurring date
|
#continue on recurring date
|
||||||
my @end = @{ time::datetime_to_array($end_date) };
|
my @end = @{ time::datetime_to_array($end_date) };
|
||||||
return unless @end >= 3;
|
return unless scalar @end >= 3;
|
||||||
my @end_date = ( $end[0], $end[1], $end[2] );
|
my @end_date = ( $end[0], $end[1], $end[2] );
|
||||||
|
|
||||||
my $today = time::time_to_date();
|
my $today = time::time_to_date();
|
||||||
my ( $year, $month, $day ) = split( /\-/, $today );
|
my ( $year, $month, $day ) = split( /\-/, $today );
|
||||||
|
|
||||||
my $dates = [];
|
my $dates = [];
|
||||||
return $dates if ( $end_date lt $today );
|
return $dates if $end_date lt $today;
|
||||||
return $dates if ( $frequency < 1 );
|
return $dates if $frequency < 1;
|
||||||
|
|
||||||
my $j = Date::Calc::Delta_Days( @start_date, @end_date );
|
my $j = Date::Calc::Delta_Days( @start_date, @end_date );
|
||||||
my $c = 0;
|
my $c = 0;
|
||||||
for ( my $i = 0 ; $i <= $j ; $i += $frequency ) {
|
for ( my $i = 0 ; $i <= $j ; $i += $frequency ) {
|
||||||
my @date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i );
|
my @date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i );
|
||||||
my $date = {};
|
my $date = {};
|
||||||
$date->{start} = sprintf( "%04d-%02d-%02d", @date ) . ' ' . $start_time;
|
$date->{start} = sprintf( "%04d-%02d-%02d", @date ) . ' ' . $start_time;
|
||||||
|
|
||||||
#if($date->{start} gt $today){
|
#if($date->{start} gt $today){
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$date[0], $date[1], $date[2], # start date
|
$date[0], $date[1], $date[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
$date->{end} = time::array_to_datetime( \@end_datetime );
|
$date->{end} = time::array_to_datetime( \@end_datetime );
|
||||||
push @$dates, $date;
|
push @$dates, $date;
|
||||||
|
|
||||||
#}
|
#}
|
||||||
last if ( $c > 200 );
|
last if ( $c > 200 );
|
||||||
$c++;
|
$c++;
|
||||||
}
|
}
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
#remove all series_dates for studio_id and series_id
|
#remove all series_dates for studio_id and series_id
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return unless defined $entry->{project_id};
|
return unless defined $entry->{project_id};
|
||||||
return unless defined $entry->{studio_id};
|
return unless defined $entry->{studio_id};
|
||||||
return unless defined $entry->{series_id};
|
return unless defined $entry->{series_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
delete
|
delete
|
||||||
from calcms_series_dates
|
from calcms_series_dates
|
||||||
where project_id=? and studio_id=? and series_id=?
|
where project_id=? and studio_id=? and series_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id} ];
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id} ];
|
||||||
|
|
||||||
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
||||||
db::put( $dbh, $query, $bind_values );
|
db::put( $dbh, $query, $bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
# get all series dates where no event has been created for
|
# get all series dates where no event has been created for
|
||||||
sub getDatesWithoutEvent {
|
sub getDatesWithoutEvent {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return unless defined $options->{project_id};
|
return unless defined $options->{project_id};
|
||||||
return unless defined $options->{studio_id};
|
return unless defined $options->{studio_id};
|
||||||
return unless defined $options->{from};
|
return unless defined $options->{from};
|
||||||
return unless defined $options->{till};
|
return unless defined $options->{till};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $query = q{
|
my $query = q{
|
||||||
SELECT sd.*
|
SELECT sd.*
|
||||||
FROM calcms_series_dates sd LEFT JOIN calcms_events e
|
FROM calcms_series_dates sd LEFT JOIN calcms_events e
|
||||||
on (sd.start = e.start)
|
on (sd.start = e.start)
|
||||||
@@ -587,15 +587,15 @@ sub getDatesWithoutEvent {
|
|||||||
order by sd.start
|
order by sd.start
|
||||||
};
|
};
|
||||||
|
|
||||||
my $bind_values = [ $options->{project_id}, $options->{studio_id}, $options->{from}, $options->{till} ];
|
my $bind_values = [ $options->{project_id}, $options->{studio_id}, $options->{from}, $options->{till} ];
|
||||||
my $entries = db::get( $dbh, $query, $bind_values );
|
my $entries = db::get( $dbh, $query, $bind_values );
|
||||||
return $entries;
|
return $entries;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -39,147 +39,147 @@ sub debug;
|
|||||||
# do not check for project,studio,series
|
# do not check for project,studio,series
|
||||||
# all changed columns are returned for history handling
|
# all changed columns are returned for history handling
|
||||||
sub save_content {
|
sub save_content {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
return undef unless ( defined $entry->{id} );
|
return undef unless ( defined $entry->{id} );
|
||||||
|
|
||||||
for my $attr ( keys %$entry ) {
|
for my $attr ( keys %$entry ) {
|
||||||
next unless defined $entry->{$attr};
|
next unless defined $entry->{$attr};
|
||||||
$entry->{$attr} =~ s/^\s+//g;
|
$entry->{$attr} =~ s/^\s+//g;
|
||||||
$entry->{$attr} =~ s/\s+$//g;
|
$entry->{$attr} =~ s/\s+$//g;
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $attr ( 'image', 'series_image' ) {
|
for my $attr ( 'image', 'series_image' ) {
|
||||||
$entry->{$attr} = images::normalizeName( $entry->{$attr} ) if defined $entry->{$attr};
|
$entry->{$attr} = images::normalizeName( $entry->{$attr} ) if defined $entry->{$attr};
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR Dumper(\$entry->{content});
|
#print STDERR Dumper(\$entry->{content});
|
||||||
for my $attr ( 'content', 'topic' ) {
|
for my $attr ( 'content', 'topic' ) {
|
||||||
if ( defined $entry->{$attr} ) {
|
if ( defined $entry->{$attr} ) {
|
||||||
$entry->{ 'html_' . $attr } = markup::creole_to_html( $entry->{$attr} );
|
$entry->{ 'html_' . $attr } = markup::creole_to_html( $entry->{$attr} );
|
||||||
|
|
||||||
#$entry->{'html_'.$attr}=~s/([^\>])\n+([^\<])/$1<br\/><br\/>$2/g;
|
#$entry->{'html_'.$attr}=~s/([^\>])\n+([^\<])/$1<br\/><br\/>$2/g;
|
||||||
#$entry->{'html_'.$attr}=~s/^\s*(<p>)?//g;
|
#$entry->{'html_'.$attr}=~s/^\s*(<p>)?//g;
|
||||||
#$entry->{'html_'.$attr}=~s/(<\/p>)?\s*$//g;
|
#$entry->{'html_'.$attr}=~s/(<\/p>)?\s*$//g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR Dumper(\$entry->{series_image});
|
#print STDERR Dumper(\$entry->{series_image});
|
||||||
#print STDERR "ok2\n";
|
#print STDERR "ok2\n";
|
||||||
#return;
|
#return;
|
||||||
$entry->{modified_at} = time::time_to_datetime( time() );
|
$entry->{modified_at} = time::time_to_datetime( time() );
|
||||||
|
|
||||||
#return;
|
#return;
|
||||||
#update only existing atributes
|
#update only existing atributes
|
||||||
|
|
||||||
#TODO: double check series_name (needed for reassignment but not for editing...)
|
#TODO: double check series_name (needed for reassignment but not for editing...)
|
||||||
my @keys = ();
|
my @keys = ();
|
||||||
for my $key (
|
for my $key (
|
||||||
'series_name', 'title', 'excerpt', 'content',
|
'series_name', 'title', 'excerpt', 'content',
|
||||||
'html_content', 'user_title', 'user_excerpt', 'topic',
|
'html_content', 'user_title', 'user_excerpt', 'topic',
|
||||||
'html_topic', 'episode', 'image', 'image_label',
|
'html_topic', 'episode', 'image', 'image_label',
|
||||||
'series_image', 'series_image_label', 'podcast_url', 'archive_url',
|
'series_image', 'series_image_label', 'podcast_url', 'archive_url',
|
||||||
'live', 'published', 'playout', 'archived',
|
'live', 'published', 'playout', 'archived',
|
||||||
'rerun', 'draft', 'disable_event_sync', 'modified_by'
|
'rerun', 'draft', 'disable_event_sync', 'modified_by'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
push @keys, $key if defined $entry->{$key};
|
push @keys, $key if defined $entry->{$key};
|
||||||
}
|
}
|
||||||
$entry->{episode} = undef if ( defined $entry->{episode} ) && ( $entry->{episode} eq '0' );
|
$entry->{episode} = undef if ( defined $entry->{episode} ) && ( $entry->{episode} eq '0' );
|
||||||
$entry->{published} = 0 if ( defined $entry->{draft} ) && ( $entry->{draft} eq '1' );
|
$entry->{published} = 0 if ( defined $entry->{draft} ) && ( $entry->{draft} eq '1' );
|
||||||
|
|
||||||
my $values = join( ",", map { $_ . '=?' } (@keys) );
|
my $values = join( ",", map { $_ . '=?' } (@keys) );
|
||||||
my @bind_values = map { $entry->{$_} } (@keys);
|
my @bind_values = map { $entry->{$_} } (@keys);
|
||||||
|
|
||||||
push @bind_values, $entry->{id};
|
push @bind_values, $entry->{id};
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
update calcms_events
|
update calcms_events
|
||||||
set $values
|
set $values
|
||||||
where id=?
|
where id=?
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR "update:".$query.Dumper(\@bind_values);
|
#print STDERR "update:".$query.Dumper(\@bind_values);
|
||||||
my $result = db::put( $dbh, $query, \@bind_values );
|
my $result = db::put( $dbh, $query, \@bind_values );
|
||||||
unless ( defined $result ) {
|
unless ( defined $result ) {
|
||||||
print STDERR "error on updating event\n";
|
print STDERR "error on updating event\n";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR "result=$result\n";
|
#print STDERR "result=$result\n";
|
||||||
#print STDERR "entr after update".Dumper($entry);
|
#print STDERR "entr after update".Dumper($entry);
|
||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
# save event time by id
|
# save event time by id
|
||||||
# do not check project, studio, series
|
# do not check project, studio, series
|
||||||
# for history handling all changed columns are returned
|
# for history handling all changed columns are returned
|
||||||
sub save_event_time {
|
sub save_event_time {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return undef unless ( defined $entry->{id} );
|
return undef unless ( defined $entry->{id} );
|
||||||
return undef unless ( defined $entry->{duration} );
|
return undef unless ( defined $entry->{duration} );
|
||||||
return undef unless ( defined $entry->{start_date} );
|
return undef unless ( defined $entry->{start_date} );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $event = {
|
my $event = {
|
||||||
id => $entry->{id},
|
id => $entry->{id},
|
||||||
start => $entry->{start_date},
|
start => $entry->{start_date},
|
||||||
end => time::add_minutes_to_datetime( $entry->{start_date}, $entry->{duration} )
|
end => time::add_minutes_to_datetime( $entry->{start_date}, $entry->{duration} )
|
||||||
};
|
};
|
||||||
|
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
my $event_hour = int( ( split( /[\-\:\sT]/, $event->{start} ) )[3] );
|
my $event_hour = int( ( split( /[\-\:\sT]/, $event->{start} ) )[3] );
|
||||||
|
|
||||||
my @update_columns = ();
|
my @update_columns = ();
|
||||||
my $bind_values = [];
|
my $bind_values = [];
|
||||||
push @update_columns, 'start=?';
|
push @update_columns, 'start=?';
|
||||||
push @$bind_values, $event->{start};
|
push @$bind_values, $event->{start};
|
||||||
|
|
||||||
push @update_columns, 'end=?';
|
push @update_columns, 'end=?';
|
||||||
push @$bind_values, $event->{end};
|
push @$bind_values, $event->{end};
|
||||||
|
|
||||||
# add start date
|
# add start date
|
||||||
my $start_date = time::add_hours_to_datetime( $event->{start}, -$day_start );
|
my $start_date = time::add_hours_to_datetime( $event->{start}, -$day_start );
|
||||||
push @update_columns, 'start_date=?';
|
push @update_columns, 'start_date=?';
|
||||||
push @$bind_values, $start_date;
|
push @$bind_values, $start_date;
|
||||||
$event->{start_date} = $start_date;
|
$event->{start_date} = $start_date;
|
||||||
|
|
||||||
# add end date
|
# add end date
|
||||||
my $end_date = time::add_hours_to_datetime( $event->{end}, -$day_start );
|
my $end_date = time::add_hours_to_datetime( $event->{end}, -$day_start );
|
||||||
push @update_columns, 'end_date=?';
|
push @update_columns, 'end_date=?';
|
||||||
push @$bind_values, $end_date;
|
push @$bind_values, $end_date;
|
||||||
$event->{end_date} = $end_date;
|
$event->{end_date} = $end_date;
|
||||||
|
|
||||||
my $update_columns = join( ",\n", @update_columns );
|
my $update_columns = join( ",\n", @update_columns );
|
||||||
my $update_sql = qq{
|
my $update_sql = qq{
|
||||||
update calcms_events
|
update calcms_events
|
||||||
set $update_columns
|
set $update_columns
|
||||||
where id=?
|
where id=?
|
||||||
};
|
};
|
||||||
push @$bind_values, $event->{id};
|
push @$bind_values, $event->{id};
|
||||||
|
|
||||||
#print STDERR $update_sql."\n".Dumper($bind_values)."\n";
|
#print STDERR $update_sql."\n".Dumper($bind_values)."\n";
|
||||||
db::put( $dbh, $update_sql, $bind_values );
|
db::put( $dbh, $update_sql, $bind_values );
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub set_playout_status {
|
sub set_playout_status {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{start};
|
return undef unless defined $entry->{start};
|
||||||
return undef unless defined $entry->{playout};
|
return undef unless defined $entry->{playout};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
# check if event is assigned to project and studio
|
# check if event is assigned to project and studio
|
||||||
my $sql = qq{
|
my $sql = qq{
|
||||||
select se.event_id event_id
|
select se.event_id event_id
|
||||||
from calcms_series_events se, calcms_events e
|
from calcms_series_events se, calcms_events e
|
||||||
where
|
where
|
||||||
@@ -188,82 +188,82 @@ sub set_playout_status {
|
|||||||
and se.project_id=?
|
and se.project_id=?
|
||||||
and se.studio_id=?
|
and se.studio_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{start}, $entry->{project_id}, $entry->{studio_id} ];
|
my $bind_values = [ $entry->{start}, $entry->{project_id}, $entry->{studio_id} ];
|
||||||
|
|
||||||
#print STDERR Dumper($sql).Dumper($bind_values);
|
#print STDERR Dumper($sql).Dumper($bind_values);
|
||||||
my $events = db::get( $dbh, $sql, $bind_values );
|
my $events = db::get( $dbh, $sql, $bind_values );
|
||||||
|
|
||||||
#print STDERR Dumper($events);
|
#print STDERR Dumper($events);
|
||||||
return undef if scalar(@$events) != 1;
|
return undef if scalar(@$events) != 1;
|
||||||
my $event_id = $events->[0]->{event_id};
|
my $event_id = $events->[0]->{event_id};
|
||||||
$sql = qq{
|
$sql = qq{
|
||||||
update calcms_events
|
update calcms_events
|
||||||
set playout=?
|
set playout=?
|
||||||
where id=?
|
where id=?
|
||||||
and start=?
|
and start=?
|
||||||
};
|
};
|
||||||
$bind_values = [ $entry->{playout}, $event_id, $entry->{start} ];
|
$bind_values = [ $entry->{playout}, $event_id, $entry->{start} ];
|
||||||
|
|
||||||
#print STDERR $sql."\n".Dumper($bind_values)."\n";
|
#print STDERR $sql."\n".Dumper($bind_values)."\n";
|
||||||
my $result = db::put( $dbh, $sql, $bind_values );
|
my $result = db::put( $dbh, $sql, $bind_values );
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
# is event assigned to project, studio and series?
|
# is event assigned to project, studio and series?
|
||||||
sub is_event_assigned {
|
sub is_event_assigned {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return 0 unless defined $entry->{project_id};
|
return 0 unless defined $entry->{project_id};
|
||||||
return 0 unless defined $entry->{studio_id};
|
return 0 unless defined $entry->{studio_id};
|
||||||
return 0 unless defined $entry->{series_id};
|
return 0 unless defined $entry->{series_id};
|
||||||
return 0 unless defined $entry->{event_id};
|
return 0 unless defined $entry->{event_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $sql = q{
|
my $sql = q{
|
||||||
select * from calcms_series_events
|
select * from calcms_series_events
|
||||||
where project_id=? and studio_id=? and series_id=? and event_id=?
|
where project_id=? and studio_id=? and series_id=? and event_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{event_id} ];
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{event_id} ];
|
||||||
my $results = db::get( $dbh, $sql, $bind_values );
|
my $results = db::get( $dbh, $sql, $bind_values );
|
||||||
|
|
||||||
return 1 if @$results >= 1;
|
return 1 if scalar @$results >= 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delete_event {
|
sub delete_event {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{series_id};
|
return undef unless defined $entry->{series_id};
|
||||||
return undef unless defined $entry->{event_id};
|
return undef unless defined $entry->{event_id};
|
||||||
return undef unless defined $entry->{user};
|
return undef unless defined $entry->{user};
|
||||||
|
|
||||||
#is event assigned to project, studio and series?
|
#is event assigned to project, studio and series?
|
||||||
unless ( is_event_assigned( $config, $entry ) == 1 ) {
|
unless ( is_event_assigned( $config, $entry ) == 1 ) {
|
||||||
print STDERR
|
print STDERR
|
||||||
"cannot delete event with project_id=$entry->{project_id}, studio_id=$entry->{studio_id}, series_id=$entry->{series_id}, event_id=$entry->{event_id}";
|
"cannot delete event with project_id=$entry->{project_id}, studio_id=$entry->{studio_id}, series_id=$entry->{series_id}, event_id=$entry->{event_id}";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_history::insert_by_event_id( $config, $entry );
|
event_history::insert_by_event_id( $config, $entry );
|
||||||
|
|
||||||
#delete the association
|
#delete the association
|
||||||
series::unassign_event( $config, $entry );
|
series::unassign_event( $config, $entry );
|
||||||
|
|
||||||
# delete the event
|
# delete the event
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $sql = q{
|
my $sql = q{
|
||||||
delete from calcms_events
|
delete from calcms_events
|
||||||
where id=?
|
where id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{event_id} ];
|
my $bind_values = [ $entry->{event_id} ];
|
||||||
db::put( $dbh, $sql, $bind_values );
|
db::put( $dbh, $sql, $bind_values );
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#check permissions
|
#check permissions
|
||||||
@@ -272,141 +272,141 @@ sub delete_event {
|
|||||||
# key check_for: user, studio, series, events, schedule
|
# key check_for: user, studio, series, events, schedule
|
||||||
# return error text or 1 if okay
|
# return error text or 1 if okay
|
||||||
sub check_permission {
|
sub check_permission {
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return "missing permission at check" unless defined $options->{permission};
|
return "missing permission at check" unless defined $options->{permission};
|
||||||
return "missing check_for at check" unless defined $options->{check_for};
|
return "missing check_for at check" unless defined $options->{check_for};
|
||||||
return "missing user at check" unless defined $request->{user};
|
return "missing user at check" unless defined $request->{user};
|
||||||
return "missing project_id at check" unless defined $options->{project_id};
|
return "missing project_id at check" unless defined $options->{project_id};
|
||||||
return "missing studio_id at check" unless defined $options->{studio_id};
|
return "missing studio_id at check" unless defined $options->{studio_id};
|
||||||
return "missing series_id at check" unless defined $options->{series_id};
|
return "missing series_id at check" unless defined $options->{series_id};
|
||||||
|
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
my $config = $request->{config};
|
my $config = $request->{config};
|
||||||
|
|
||||||
my $studio_check = studios::check( $config, $options );
|
my $studio_check = studios::check( $config, $options );
|
||||||
return $studio_check if ( $studio_check ne '1' );
|
return $studio_check if ( $studio_check ne '1' );
|
||||||
print STDERR "check studio ok\n";
|
print STDERR "check studio ok\n";
|
||||||
|
|
||||||
my $project_check = project::check( $config, $options );
|
my $project_check = project::check( $config, $options );
|
||||||
return $project_check if ( $project_check ne '1' );
|
return $project_check if ( $project_check ne '1' );
|
||||||
print STDERR "check project ok\n";
|
print STDERR "check project ok\n";
|
||||||
|
|
||||||
#check if permissions are set (like create_event)
|
#check if permissions are set (like create_event)
|
||||||
my $found = 0;
|
my $found = 0;
|
||||||
for my $permission ( split /\,/, $options->{permission} ) {
|
for my $permission ( split /\,/, $options->{permission} ) {
|
||||||
$found = 1 if ( ( defined $permissions->{$permission} ) && ( $permissions->{$permission} ) eq '1' );
|
$found = 1 if ( defined $permissions->{$permission} ) && ( $permissions->{$permission} ) eq '1' ;
|
||||||
}
|
}
|
||||||
return 'missing permission to ' . $options->{permission} if $found == 0;
|
return 'missing permission to ' . $options->{permission} if $found == 0;
|
||||||
delete $options->{permission};
|
delete $options->{permission};
|
||||||
|
|
||||||
#convert check list to hash
|
#convert check list to hash
|
||||||
my $check = {};
|
my $check = {};
|
||||||
for my $permission ( @{ $options->{check_for} } ) {
|
for my $permission ( @{ $options->{check_for} } ) {
|
||||||
$check->{$permission} = 1;
|
$check->{$permission} = 1;
|
||||||
}
|
}
|
||||||
delete $options->{check_for};
|
delete $options->{check_for};
|
||||||
|
|
||||||
# is project assigned to studio
|
# is project assigned to studio
|
||||||
return "studio is not assigned to project" unless project::is_studio_assigned( $config, $options ) == 1;
|
return "studio is not assigned to project" unless project::is_studio_assigned( $config, $options ) == 1;
|
||||||
|
|
||||||
#get studio names
|
#get studio names
|
||||||
my $studios = studios::get(
|
my $studios = studios::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id}
|
studio_id => $options->{studio_id}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return "unknown studio" unless defined $studios;
|
return "unknown studio" unless defined $studios;
|
||||||
return "unknown studio" unless ( @$studios == 1 );
|
return "unknown studio" unless scalar @$studios == 1;
|
||||||
my $studio = $studios->[0];
|
my $studio = $studios->[0];
|
||||||
my $studio_name = $studio->{name} || '';
|
my $studio_name = $studio->{name} || '';
|
||||||
|
|
||||||
#get series names
|
#get series names
|
||||||
my $series = series::get(
|
my $series = series::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id},
|
studio_id => $options->{studio_id},
|
||||||
series_id => $options->{series_id}
|
series_id => $options->{series_id}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
my $series_name = $series->[0]->{series_name} || '';
|
my $series_name = $series->[0]->{series_name} || '';
|
||||||
$series_name .= ' - ' . $series->[0]->{title} if $series->[0]->{series_name} ne '';
|
$series_name .= ' - ' . $series->[0]->{title} if $series->[0]->{series_name} ne '';
|
||||||
|
|
||||||
my $draft = 0;
|
my $draft = 0;
|
||||||
$draft = 1 if ( defined $options->{draft} ) && ( $options->{draft} == 1 );
|
$draft = 1 if ( defined $options->{draft} ) && ( $options->{draft} == 1 );
|
||||||
|
|
||||||
#check all items from checklist
|
#check all items from checklist
|
||||||
if ( ( defined $check->{user} ) && ( uac::is_user_assigned_to_studio( $request, $options ) == 0 ) ) {
|
if ( ( defined $check->{user} ) && ( uac::is_user_assigned_to_studio( $request, $options ) == 0 ) ) {
|
||||||
return "User '$request->{user}' is not assigned to studio $studio_name ($options->{studio_id})";
|
return "User '$request->{user}' is not assigned to studio $studio_name ($options->{studio_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $check->{studio} ) && ( project::is_series_assigned( $config, $options ) == 0 ) ) {
|
if ( ( defined $check->{studio} ) && ( project::is_series_assigned( $config, $options ) == 0 ) ) {
|
||||||
return "Series '$series_name' ($options->{series_id}) is not assigned to studio '$studio_name' ($options->{studio_id})";
|
return "Series '$series_name' ($options->{series_id}) is not assigned to studio '$studio_name' ($options->{studio_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
# check series and can user update events
|
# check series and can user update events
|
||||||
if ( ( defined $check->{series} ) && ( series::can_user_update_events( $request, $options ) == 0 ) ) {
|
if ( ( defined $check->{series} ) && ( series::can_user_update_events( $request, $options ) == 0 ) ) {
|
||||||
return "unknown series" unless defined $series;
|
return "unknown series" unless defined $series;
|
||||||
return "User $request->{user} cannot update events for series '$series_name' ($options->{series_id})";
|
return "User $request->{user} cannot update events for series '$series_name' ($options->{series_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
# check series and can user create events
|
# check series and can user create events
|
||||||
if ( ( defined $check->{create_events} ) && ( series::can_user_create_events( $request, $options ) == 0 ) ) {
|
if ( ( defined $check->{create_events} ) && ( series::can_user_create_events( $request, $options ) == 0 ) ) {
|
||||||
return "unknown series" unless defined $series;
|
return "unknown series" unless defined $series;
|
||||||
return "User $request->{user} cannot create events for series '$series_name' ($options->{series_id})";
|
return "User $request->{user} cannot create events for series '$series_name' ($options->{series_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( $draft == 0 )
|
if ( ( $draft == 0 )
|
||||||
&& ( defined $check->{studio_timeslots} )
|
&& ( defined $check->{studio_timeslots} )
|
||||||
&& ( studio_timeslot_dates::can_studio_edit_events( $config, $options ) == 0 ) )
|
&& ( studio_timeslot_dates::can_studio_edit_events( $config, $options ) == 0 ) )
|
||||||
{
|
{
|
||||||
return "requested time is not assigned to studio '$studio_name' ($options->{studio_id})";
|
return "requested time is not assigned to studio '$studio_name' ($options->{studio_id})";
|
||||||
}
|
}
|
||||||
|
|
||||||
#check if event is assigned to user,project,studio,series,location
|
#check if event is assigned to user,project,studio,series,location
|
||||||
if ( defined $check->{events} ) {
|
if ( defined $check->{events} ) {
|
||||||
return "missing event_id" unless defined $options->{event_id};
|
return "missing event_id" unless defined $options->{event_id};
|
||||||
my $result = series::is_event_assigned_to_user( $request, $options );
|
my $result = series::is_event_assigned_to_user( $request, $options );
|
||||||
return $result if $result ne '1';
|
return $result if $result ne '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
# prevent editing events that are over for more than 14 days
|
# prevent editing events that are over for more than 14 days
|
||||||
if ( ( $draft == 0 ) && ( defined $check->{event_age} ) ) {
|
if ( ( $draft == 0 ) && ( defined $check->{event_age} ) ) {
|
||||||
if (
|
if (
|
||||||
series::is_event_older_than_days(
|
series::is_event_older_than_days(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id},
|
studio_id => $options->{studio_id},
|
||||||
series_id => $options->{series_id},
|
series_id => $options->{series_id},
|
||||||
event_id => $options->{event_id},
|
event_id => $options->{event_id},
|
||||||
max_age => 14
|
max_age => 14
|
||||||
}
|
}
|
||||||
) == 1
|
) == 1
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return "show is over for more than 2 weeks"
|
return "show is over for more than 2 weeks"
|
||||||
unless ( ( defined $permissions->{update_event_after_week} )
|
unless ( ( defined $permissions->{update_event_after_week} )
|
||||||
&& ( $permissions->{update_event_after_week} eq '1' ) );
|
&& ( $permissions->{update_event_after_week} eq '1' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#check if schedule event exists for given date
|
#check if schedule event exists for given date
|
||||||
if ( ( $draft == 0 ) && ( defined $check->{schedule} ) ) {
|
if ( ( $draft == 0 ) && ( defined $check->{schedule} ) ) {
|
||||||
return "unknown series" unless defined $series;
|
return "unknown series" unless defined $series;
|
||||||
return "missing start_at at check_permission" unless defined $options->{start_date};
|
return "missing start_at at check_permission" unless defined $options->{start_date};
|
||||||
|
|
||||||
#TODO: check "is_event_scheduled" if start_at could be moved to start_date
|
#TODO: check "is_event_scheduled" if start_at could be moved to start_date
|
||||||
$options->{start_at} = $options->{start_date};
|
$options->{start_at} = $options->{start_date};
|
||||||
return "No event scheduled for series '$series_name' ($options->{series_id})"
|
return "No event scheduled for series '$series_name' ($options->{series_id})"
|
||||||
if ( series_dates::is_event_scheduled( $request, $options ) == 0 );
|
if ( series_dates::is_event_scheduled( $request, $options ) == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return '1';
|
return '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
#not handled, yet:
|
#not handled, yet:
|
||||||
@@ -415,126 +415,126 @@ sub check_permission {
|
|||||||
|
|
||||||
#insert event
|
#insert event
|
||||||
sub insert_event {
|
sub insert_event {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my $project_id = $options->{project_id};
|
my $project_id = $options->{project_id};
|
||||||
my $studio = $options->{studio};
|
my $studio = $options->{studio};
|
||||||
my $serie = $options->{serie};
|
my $serie = $options->{serie};
|
||||||
my $params = $options->{event};
|
my $params = $options->{event};
|
||||||
my $user = $options->{user};
|
my $user = $options->{user};
|
||||||
|
|
||||||
return 0 unless defined $studio;
|
return 0 unless defined $studio;
|
||||||
return 0 unless defined $serie;
|
return 0 unless defined $serie;
|
||||||
return 0 unless defined $params;
|
return 0 unless defined $params;
|
||||||
return 0 unless defined $user;
|
return 0 unless defined $user;
|
||||||
return 0 unless defined $studio->{location};
|
return 0 unless defined $studio->{location};
|
||||||
|
|
||||||
my $projects = project::get( $config, { project_id => $project_id } );
|
my $projects = project::get( $config, { project_id => $project_id } );
|
||||||
if ( @$projects == 0 ) {
|
if ( scalar @$projects == 0 ) {
|
||||||
print STDERR "project not found at insert event\n";
|
print STDERR "project not found at insert event\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
my $projectName = $projects->[0]->{name};
|
my $projectName = $projects->[0]->{name};
|
||||||
my $event = {
|
my $event = {
|
||||||
project => $projectName,
|
project => $projectName,
|
||||||
location => $studio->{location}, # location from studio
|
location => $studio->{location}, # location from studio
|
||||||
};
|
};
|
||||||
|
|
||||||
#print '<pre>';
|
#print '<pre>';
|
||||||
$event = series_events::add_event_dates( $config, $event, $params );
|
$event = series_events::add_event_dates( $config, $event, $params );
|
||||||
|
|
||||||
#get event content from series
|
#get event content from series
|
||||||
for my $attr ( 'program', 'series_name', 'title', 'excerpt', 'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url' ) {
|
for my $attr ( 'program', 'series_name', 'title', 'excerpt', 'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url' ) {
|
||||||
$event->{$attr} = $serie->{$attr} if defined $serie->{$attr};
|
$event->{$attr} = $serie->{$attr} if defined $serie->{$attr};
|
||||||
}
|
}
|
||||||
$event->{series_image} = $serie->{image} if defined $serie->{image};
|
$event->{series_image} = $serie->{image} if defined $serie->{image};
|
||||||
$event->{series_image_label} = $serie->{licence} if defined $serie->{licence};
|
$event->{series_image_label} = $serie->{licence} if defined $serie->{licence};
|
||||||
|
|
||||||
#overwrite series values from parameters
|
#overwrite series values from parameters
|
||||||
for my $attr (
|
for my $attr (
|
||||||
'program', 'series_name', 'title', 'user_title', 'excerpt', 'user_except',
|
'program', 'series_name', 'title', 'user_title', 'excerpt', 'user_except',
|
||||||
'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url'
|
'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url'
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$event->{$attr} = $params->{$attr} if defined $params->{$attr};
|
$event->{$attr} = $params->{$attr} if defined $params->{$attr};
|
||||||
}
|
}
|
||||||
$event->{'html_content'} = markup::creole_to_html( $event->{'content'} ) if defined $event->{'content'};
|
$event->{'html_content'} = markup::creole_to_html( $event->{'content'} ) if defined $event->{'content'};
|
||||||
$event->{'html_topic'} = markup::creole_to_html( $event->{'topic'} ) if defined $event->{'topic'};
|
$event->{'html_topic'} = markup::creole_to_html( $event->{'topic'} ) if defined $event->{'topic'};
|
||||||
|
|
||||||
#add event status
|
#add event status
|
||||||
for my $attr ( 'live', 'published', 'playout', 'archived', 'rerun', 'draft', 'disable_event_sync' ) {
|
for my $attr ( 'live', 'published', 'playout', 'archived', 'rerun', 'draft', 'disable_event_sync' ) {
|
||||||
$event->{$attr} = $params->{$attr} || 0;
|
$event->{$attr} = $params->{$attr} || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $serie->{has_single_events} eq '1' ) {
|
if ( $serie->{has_single_events} eq '1' ) {
|
||||||
delete $event->{series_name};
|
delete $event->{series_name};
|
||||||
delete $event->{episode};
|
delete $event->{episode};
|
||||||
}
|
}
|
||||||
|
|
||||||
$event->{modified_at} = time::time_to_datetime( time() );
|
$event->{modified_at} = time::time_to_datetime( time() );
|
||||||
$event->{created_at} = time::time_to_datetime( time() );
|
$event->{created_at} = time::time_to_datetime( time() );
|
||||||
$event->{modified_by} = $user;
|
$event->{modified_by} = $user;
|
||||||
|
|
||||||
#print STDERR Dumper($event);
|
#print STDERR Dumper($event);
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $event_id = db::insert( $dbh, 'calcms_events', $event );
|
my $event_id = db::insert( $dbh, 'calcms_events', $event );
|
||||||
|
|
||||||
#add to history
|
#add to history
|
||||||
$event->{project_id} = $project_id;
|
$event->{project_id} = $project_id;
|
||||||
$event->{studio_id} = $studio->{id};
|
$event->{studio_id} = $studio->{id};
|
||||||
$event->{series_id} = $serie->{series_id};
|
$event->{series_id} = $serie->{series_id};
|
||||||
$event->{event_id} = $event_id;
|
$event->{event_id} = $event_id;
|
||||||
event_history::insert( $config, $event );
|
event_history::insert( $config, $event );
|
||||||
return $event_id;
|
return $event_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
#set start, end, start-date, end_date to an event
|
#set start, end, start-date, end_date to an event
|
||||||
sub add_event_dates {
|
sub add_event_dates {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $event = shift;
|
my $event = shift;
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
|
|
||||||
#start and end datetime
|
#start and end datetime
|
||||||
$event->{start} = $params->{start_date};
|
$event->{start} = $params->{start_date};
|
||||||
$event->{end} = time::add_minutes_to_datetime( $params->{start_date}, $params->{duration} );
|
$event->{end} = time::add_minutes_to_datetime( $params->{start_date}, $params->{duration} );
|
||||||
|
|
||||||
#set program days
|
#set program days
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
$event->{start_date} = time::date_cond( time::add_hours_to_datetime( $event->{start}, -$day_start ) );
|
$event->{start_date} = time::date_cond( time::add_hours_to_datetime( $event->{start}, -$day_start ) );
|
||||||
$event->{end_date} = time::date_cond( time::add_hours_to_datetime( $event->{end}, -$day_start ) );
|
$event->{end_date} = time::date_cond( time::add_hours_to_datetime( $event->{end}, -$day_start ) );
|
||||||
return $event;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update_series_images {
|
sub update_series_images {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
return "missing project_id" unless defined $options->{project_id};
|
return "missing project_id" unless defined $options->{project_id};
|
||||||
return "missing studio_id" unless defined $options->{studio_id};
|
return "missing studio_id" unless defined $options->{studio_id};
|
||||||
return "missing series_id" unless defined $options->{series_id};
|
return "missing series_id" unless defined $options->{series_id};
|
||||||
return "missing series_image" unless defined $options->{series_image};
|
return "missing series_image" unless defined $options->{series_image};
|
||||||
|
|
||||||
#print "save $options->{series_image}\n";
|
#print "save $options->{series_image}\n";
|
||||||
|
|
||||||
my $events = series::get_events(
|
my $events = series::get_events(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id},
|
studio_id => $options->{studio_id},
|
||||||
series_id => $options->{series_id},
|
series_id => $options->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
for my $event (@$events) {
|
for my $event (@$events) {
|
||||||
$event->{series_image} = $options->{series_image};
|
$event->{series_image} = $options->{series_image};
|
||||||
series_events::save_content( $config, $event );
|
series_events::save_content( $config, $event );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use lib qw(/home/radio/calcms/calcms/);
|
|||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Apache::DBI();
|
use Apache::DBI();
|
||||||
|
|
||||||
#$Apache::DBI::DEBUG = 2;
|
#$Apache::DBI::DEBUG = 2;
|
||||||
|
|
||||||
use Time::Local();
|
use Time::Local();
|
||||||
|
|||||||
@@ -16,157 +16,157 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_studios' );
|
my $cols = db::get_columns( $dbh, 'calcms_studios' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift || {};
|
my $condition = shift || {};
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 's.id=?';
|
push @conditions, 's.id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{name} ) && ( $condition->{name} ne '' ) ) {
|
if ( ( defined $condition->{name} ) && ( $condition->{name} ne '' ) ) {
|
||||||
push @conditions, 's.name=?';
|
push @conditions, 's.name=?';
|
||||||
push @bind_values, $condition->{name};
|
push @bind_values, $condition->{name};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{location} ) && ( $condition->{location} ne '' ) ) {
|
if ( ( defined $condition->{location} ) && ( $condition->{location} ne '' ) ) {
|
||||||
push @conditions, 's.location=?';
|
push @conditions, 's.location=?';
|
||||||
push @bind_values, $condition->{location};
|
push @bind_values, $condition->{location};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $limit = '';
|
my $limit = '';
|
||||||
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
||||||
$limit = 'limit ' . $condition->{limit};
|
$limit = 'limit ' . $condition->{limit};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $query = '';
|
my $query = '';
|
||||||
unless ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
unless ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
$query = qq{
|
$query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_studios s
|
from calcms_studios s
|
||||||
$conditions
|
$conditions
|
||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
push @conditions, 's.id=ps.studio_id';
|
push @conditions, 's.id=ps.studio_id';
|
||||||
|
|
||||||
push @conditions, 'ps.project_id=?';
|
push @conditions, 'ps.project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
my $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
my $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
$query = qq{
|
$query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_studios s, calcms_project_studios ps
|
from calcms_studios s, calcms_project_studios ps
|
||||||
$conditions
|
$conditions
|
||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
my $studios = db::get( $dbh, $query, \@bind_values );
|
my $studios = db::get( $dbh, $query, \@bind_values );
|
||||||
return $studios;
|
return $studios;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getImageById {
|
sub getImageById {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $conditions = shift;
|
my $conditions = shift;
|
||||||
|
|
||||||
return undef unless defined $conditions->{project_id};
|
return undef unless defined $conditions->{project_id};
|
||||||
return undef unless defined $conditions->{studio_id};
|
return undef unless defined $conditions->{studio_id};
|
||||||
my $studios = studios::get( $config, $conditions );
|
my $studios = studios::get( $config, $conditions );
|
||||||
return undef if scalar(@$studios) != 1;
|
return undef if scalar(@$studios) != 1;
|
||||||
return $studios->[0]->{image};
|
return $studios->[0]->{image};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub insert {
|
sub insert {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
$entry->{created_at} = time::time_to_datetime( time() );
|
$entry->{created_at} = time::time_to_datetime( time() );
|
||||||
$entry->{modified_at} = time::time_to_datetime( time() );
|
$entry->{modified_at} = time::time_to_datetime( time() );
|
||||||
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_studios', $entry );
|
my $id = db::insert( $dbh, 'calcms_studios', $entry );
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $studio = shift;
|
my $studio = shift;
|
||||||
|
|
||||||
$studio->{modified_at} = time::time_to_datetime( time() );
|
$studio->{modified_at} = time::time_to_datetime( time() );
|
||||||
|
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$entry->{$column} = $studio->{$column} if defined $studio->{$column};
|
$entry->{$column} = $studio->{$column} if defined $studio->{$column};
|
||||||
}
|
}
|
||||||
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
$entry->{image} = images::normalizeName( $entry->{image} ) if defined $entry->{image};
|
||||||
|
|
||||||
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
||||||
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
||||||
push @bind_values, $entry->{id};
|
push @bind_values, $entry->{id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
update calcms_studios
|
update calcms_studios
|
||||||
set $values
|
set $values
|
||||||
where id=?
|
where id=?
|
||||||
};
|
};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
#print STDERR Dumper($query)." ".Dumper(\@bind_values);
|
#print STDERR Dumper($query)." ".Dumper(\@bind_values);
|
||||||
db::put( $dbh, $query, \@bind_values );
|
db::put( $dbh, $query, \@bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $studio = shift;
|
my $studio = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
db::put( $dbh, 'delete from calcms_studios where id=?', [ $studio->{id} ] );
|
db::put( $dbh, 'delete from calcms_studios where id=?', [ $studio->{id} ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO rename to check
|
#TODO rename to check
|
||||||
sub check_studio {
|
sub check_studio {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
return check( $config, $options );
|
return check( $config, $options );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check {
|
sub check {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
return "missing studio_id" unless defined $options->{studio_id};
|
return "missing studio_id" unless defined $options->{studio_id};
|
||||||
return "Please select a studio" if ( $options->{studio_id} eq '-1' );
|
return "Please select a studio" if ( $options->{studio_id} eq '-1' );
|
||||||
return "Please select a studio" if ( $options->{studio_id} eq '' );
|
return "Please select a studio" if ( $options->{studio_id} eq '' );
|
||||||
my $studios = studios::get( $config, { studio_id => $options->{studio_id} } );
|
my $studios = studios::get( $config, { studio_id => $options->{studio_id} } );
|
||||||
return "Sorry. unknown studio" unless defined $studios;
|
return "Sorry. unknown studio" unless defined $studios;
|
||||||
return "Sorry. unknown studio" unless @$studios == 1;
|
return "Sorry. unknown studio" unless scalar @$studios == 1;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -23,205 +23,205 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
|
|
||||||
sub process {
|
sub process {
|
||||||
|
|
||||||
# my $output=$_[0];
|
# my $output=$_[0];
|
||||||
my $filename = $_[1];
|
my $filename = $_[1];
|
||||||
my $params = $_[2];
|
my $params = $_[2];
|
||||||
|
|
||||||
my $config = $config::config;
|
my $config = $config::config;
|
||||||
for my $key ( keys %{ $config::config->{locations} } ) {
|
for my $key ( keys %{ $config::config->{locations} } ) {
|
||||||
$params->{$key} = $config::config->{locations}->{$key} if ( $key =~ /\_url$/ );
|
$params->{$key} = $config::config->{locations}->{$key} if ( $key =~ /\_url$/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
# add current project
|
# add current project
|
||||||
unless ( defined $params->{project_title} ) {
|
unless ( defined $params->{project_title} ) {
|
||||||
my $projects = project::get_with_dates( $config, { name => $config->{project} } );
|
my $projects = project::get_with_dates( $config, { name => $config->{project} } );
|
||||||
if ( @$projects == 1 ) {
|
if ( scalar @$projects == 1 ) {
|
||||||
my $project = $projects->[0];
|
my $project = $projects->[0];
|
||||||
foreach my $key ( keys %$project ) {
|
foreach my $key ( keys %$project ) {
|
||||||
$params->{ 'project_' . $key } = $project->{$key};
|
$params->{ 'project_' . $key } = $project->{$key};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$params->{user} = $ENV{REMOTE_USER} unless defined $params->{user};
|
$params->{user} = $ENV{REMOTE_USER} unless defined $params->{user};
|
||||||
|
|
||||||
my $user_permissions = roles::get_user_permissions();
|
my $user_permissions = roles::get_user_permissions();
|
||||||
for my $permission ( keys %$user_permissions ) {
|
for my $permission ( keys %$user_permissions ) {
|
||||||
$params->{$permission} = $user_permissions->{$permission} if ( $user_permissions->{$permission} eq '1' );
|
$params->{$permission} = $user_permissions->{$permission} if ( $user_permissions->{$permission} eq '1' );
|
||||||
}
|
}
|
||||||
|
|
||||||
$params->{jobs} = roles::get_user_jobs();
|
$params->{jobs} = roles::get_user_jobs();
|
||||||
if ( ( $filename =~ /json\-p/ ) || (params::isJson) ) {
|
if ( ( $filename =~ /json\-p/ ) || (params::isJson) ) {
|
||||||
my $header = "Content-type:application/json; charset=utf-8\n\n";
|
my $header = "Content-type:application/json; charset=utf-8\n\n";
|
||||||
my $json = JSON::to_json( $params, { pretty => 1 } );
|
my $json = JSON::to_json( $params, { pretty => 1 } );
|
||||||
|
|
||||||
# $json=$header.$params->{json_callback}.'['.$json.']';
|
# $json=$header.$params->{json_callback}.'['.$json.']';
|
||||||
$json = $header . $params->{json_callback} . $json;
|
$json = $header . $params->{json_callback} . $json;
|
||||||
if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) {
|
if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) {
|
||||||
print $json. "\n";
|
print $json. "\n";
|
||||||
} else {
|
} else {
|
||||||
$_[0] = $json . "\n";
|
$_[0] = $json . "\n";
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR $filename."\n";
|
#print STDERR $filename."\n";
|
||||||
log::error( $config, "cannot find template $filename " ) unless -e $filename;
|
log::error( $config, "cannot find template $filename " ) unless -e $filename;
|
||||||
log::error( $config, "cannot read template $filename " ) unless -r $filename;
|
log::error( $config, "cannot read template $filename " ) unless -r $filename;
|
||||||
|
|
||||||
my $default_escape = '0';
|
my $default_escape = '0';
|
||||||
$default_escape = 'JS' if ( $filename =~ /\.js$/ );
|
$default_escape = 'JS' if ( $filename =~ /\.js$/ );
|
||||||
$default_escape = 'JS' if ( $filename =~ /\.json$/ );
|
$default_escape = 'JS' if ( $filename =~ /\.json$/ );
|
||||||
$default_escape = 'HTML_ALL' if ( $filename =~ /\.html$/ );
|
$default_escape = 'HTML_ALL' if ( $filename =~ /\.html$/ );
|
||||||
|
|
||||||
my $html_template = undef;
|
my $html_template = undef;
|
||||||
|
|
||||||
unless ( $filename =~ /\.xml$/ ) {
|
unless ( $filename =~ /\.xml$/ ) {
|
||||||
$html_template = HTML::Template::Compiled->new(
|
$html_template = HTML::Template::Compiled->new(
|
||||||
filename => $filename,
|
filename => $filename,
|
||||||
die_on_bad_params => 0,
|
die_on_bad_params => 0,
|
||||||
case_sensitive => 0,
|
case_sensitive => 0,
|
||||||
loop_context_vars => 0,
|
loop_context_vars => 0,
|
||||||
global_vars => 0,
|
global_vars => 0,
|
||||||
tagstyle => '-asp -comment',
|
tagstyle => '-asp -comment',
|
||||||
default_escape => $default_escape,
|
default_escape => $default_escape,
|
||||||
cache => 0,
|
cache => 0,
|
||||||
utf8 => 1,
|
utf8 => 1,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$html_template = HTML::Template::Compiled->new(
|
$html_template = HTML::Template::Compiled->new(
|
||||||
filename => $filename,
|
filename => $filename,
|
||||||
die_on_bad_params => 0,
|
die_on_bad_params => 0,
|
||||||
case_sensitive => 1,
|
case_sensitive => 1,
|
||||||
loop_context_vars => 0,
|
loop_context_vars => 0,
|
||||||
global_vars => 0,
|
global_vars => 0,
|
||||||
tagstyle => '-asp -comment',
|
tagstyle => '-asp -comment',
|
||||||
default_escape => 'XML',
|
default_escape => 'XML',
|
||||||
plugin => [qw(HTML::Template::Compiled::Plugin::XMLEscape)],
|
plugin => [qw(HTML::Template::Compiled::Plugin::XMLEscape)],
|
||||||
utf8 => 1
|
utf8 => 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#$params=
|
#$params=
|
||||||
setRelativeUrls( $params, 0 ) unless ( defined $params->{extern} ) && ( $params->{extern} eq '1' );
|
setRelativeUrls( $params, 0 ) unless ( defined $params->{extern} ) && ( $params->{extern} eq '1' );
|
||||||
|
|
||||||
# HTML::Template::Compiled->preload($cache_dir);
|
# HTML::Template::Compiled->preload($cache_dir);
|
||||||
$html_template->param($params);
|
$html_template->param($params);
|
||||||
if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) {
|
if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) {
|
||||||
print $html_template->output;
|
print $html_template->output;
|
||||||
} else {
|
} else {
|
||||||
$_[0] = $html_template->output;
|
$_[0] = $html_template->output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# set relative urls in nested params structure
|
# set relative urls in nested params structure
|
||||||
sub setRelativeUrls {
|
sub setRelativeUrls {
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
my $depth = shift || 0;
|
my $depth = shift || 0;
|
||||||
|
|
||||||
#print STDERR "setRelativeUrls depth:$depth ".ref($params)."\n";
|
#print STDERR "setRelativeUrls depth:$depth ".ref($params)."\n";
|
||||||
|
|
||||||
return unless defined $params;
|
return unless defined $params;
|
||||||
|
|
||||||
if ( $depth > 10 ) {
|
if ( $depth > 10 ) {
|
||||||
print STDERR "prevent deep recursion in template::setRelativeUrls()\n";
|
print STDERR "prevent deep recursion in template::setRelativeUrls()\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# set recursive for hash
|
# set recursive for hash
|
||||||
if ( ref($params) eq 'HASH' ) {
|
if ( ref($params) eq 'HASH' ) {
|
||||||
for my $key ( keys %$params ) {
|
for my $key ( keys %$params ) {
|
||||||
|
|
||||||
#next unless ($key eq 'icon') || ($key eq 'thumb');
|
#next unless ($key eq 'icon') || ($key eq 'thumb');
|
||||||
my $val = $params->{$key};
|
my $val = $params->{$key};
|
||||||
next unless defined $val;
|
next unless defined $val;
|
||||||
if ( ref($val) eq '' ) {
|
if ( ref($val) eq '' ) {
|
||||||
|
|
||||||
# make link relative
|
# make link relative
|
||||||
$params->{$key} =~ s/^https?\:(\/\/[^\/]+)/$1/;
|
$params->{$key} =~ s/^https?\:(\/\/[^\/]+)/$1/;
|
||||||
} elsif ( ( ref($val) eq 'HASH' ) || ( ref($val) eq 'ARRAY' ) ) {
|
} elsif ( ( ref($val) eq 'HASH' ) || ( ref($val) eq 'ARRAY' ) ) {
|
||||||
setRelativeUrls( $params->{$key}, $depth + 1 );
|
setRelativeUrls( $params->{$key}, $depth + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
# set recursive for arrays
|
# set recursive for arrays
|
||||||
if ( ref($params) eq 'ARRAY' ) {
|
if ( ref($params) eq 'ARRAY' ) {
|
||||||
for my $i ( 0 .. @$params ) {
|
for my $i ( 0 .. @$params ) {
|
||||||
my $val = $params->[$i];
|
my $val = $params->[$i];
|
||||||
next unless defined $val;
|
next unless defined $val;
|
||||||
if ( ( ref($val) eq 'HASH' ) || ( ref($val) eq 'ARRAY' ) ) {
|
if ( ( ref($val) eq 'HASH' ) || ( ref($val) eq 'ARRAY' ) ) {
|
||||||
setRelativeUrls( $params->[$i], $depth + 1 );
|
setRelativeUrls( $params->[$i], $depth + 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
|
||||||
#requires read config
|
#requires read config
|
||||||
sub check {
|
sub check {
|
||||||
my $template = shift || '';
|
my $template = shift || '';
|
||||||
my $default = shift;
|
my $default = shift;
|
||||||
|
|
||||||
if ( $template =~ /json\-p/ ) {
|
if ( $template =~ /json\-p/ ) {
|
||||||
$template =~ s/[^a-zA-Z0-9\-\_\.]//g;
|
$template =~ s/[^a-zA-Z0-9\-\_\.]//g;
|
||||||
$template =~ s/\.{2,99}/\./g;
|
$template =~ s/\.{2,99}/\./g;
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $config = $config::config;
|
my $config = $config::config;
|
||||||
if ( $template eq '' ) {
|
if ( $template eq '' ) {
|
||||||
$template = $default;
|
$template = $default;
|
||||||
} else {
|
} else {
|
||||||
$template =~ s/^\.\///gi;
|
$template =~ s/^\.\///gi;
|
||||||
|
|
||||||
#template does use ';' in filename
|
#template does use ';' in filename
|
||||||
log::error( $config, 'invalid template!' ) if ( $template =~ /;/ );
|
log::error( $config, 'invalid template!' ) if ( $template =~ /;/ );
|
||||||
|
|
||||||
#template does use '..' in filename
|
#template does use '..' in filename
|
||||||
log::error( $config, 'invalid template!' ) if ( $template =~ /\.\./ );
|
log::error( $config, 'invalid template!' ) if ( $template =~ /\.\./ );
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR $config::config->{cache}->{compress}."<.compres default:$template\n";
|
#print STDERR $config::config->{cache}->{compress}."<.compres default:$template\n";
|
||||||
$template = ( split( /\//, $template ) )[-1];
|
$template = ( split( /\//, $template ) )[-1];
|
||||||
my $cwd = Cwd::getcwd();
|
my $cwd = Cwd::getcwd();
|
||||||
|
|
||||||
$template .= '.html' unless ( $template =~ /\./ );
|
$template .= '.html' unless ( $template =~ /\./ );
|
||||||
if ( ( $config::config->{cache}->{compress} eq '1' ) && ( -e $cwd . '/templates/compressed/' . $template ) ) {
|
if ( ( $config::config->{cache}->{compress} eq '1' ) && ( -e $cwd . '/templates/compressed/' . $template ) ) {
|
||||||
$template = $cwd . '/templates/compressed/' . $template;
|
$template = $cwd . '/templates/compressed/' . $template;
|
||||||
} elsif ( -e $cwd . '/templates/' . $template ) {
|
} elsif ( -e $cwd . '/templates/' . $template ) {
|
||||||
$template = $cwd . '/templates/' . $template;
|
$template = $cwd . '/templates/' . $template;
|
||||||
} else {
|
} else {
|
||||||
log::error( $config, "template not found: '$cwd/$template'" );
|
log::error( $config, "template not found: '$cwd/$template'" );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log::error( $config, "missing permission to read template '$template'" ) unless ( -r $template );
|
log::error( $config, "missing permission to read template '$template'" ) unless ( -r $template );
|
||||||
return $template;
|
return $template;
|
||||||
}
|
}
|
||||||
|
|
||||||
#deprecated (for old admin only)
|
#deprecated (for old admin only)
|
||||||
sub exit_on_missing_permission {
|
sub exit_on_missing_permission {
|
||||||
my $permission = shift;
|
my $permission = shift;
|
||||||
my $user_permissions = roles::get_user_permissions();
|
my $user_permissions = roles::get_user_permissions();
|
||||||
if ( $user_permissions->{$permission} ne '1' ) {
|
if ( $user_permissions->{$permission} ne '1' ) {
|
||||||
print STDERR "missing permission to $permission\n";
|
print STDERR "missing permission to $permission\n";
|
||||||
template::process( 'print', template::check('default.html'), { error => 'sorry, missing permission!' } );
|
template::process( 'print', template::check('default.html'), { error => 'sorry, missing permission!' } );
|
||||||
die();
|
die();
|
||||||
|
|
||||||
#exit;
|
#exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub clear_cache {
|
sub clear_cache {
|
||||||
HTML::Template::Compiled->clear_cache();
|
HTML::Template::Compiled->clear_cache();
|
||||||
|
|
||||||
# return;
|
# return;
|
||||||
# my $html_template = HTML::Template::Compiled->new();
|
# my $html_template = HTML::Template::Compiled->new();
|
||||||
# $html_template->clear_cache();
|
# $html_template->clear_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -32,584 +32,584 @@ our @EXPORT_OK = qw(
|
|||||||
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
||||||
|
|
||||||
our $names = {
|
our $names = {
|
||||||
'de' => {
|
'de' => {
|
||||||
months =>
|
months =>
|
||||||
[ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ],
|
[ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ],
|
||||||
months_abbr => [ 'Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ],
|
months_abbr => [ 'Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez' ],
|
||||||
weekdays => [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ],
|
weekdays => [ 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sonntag' ],
|
||||||
weekdays_abbr => [ 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
|
weekdays_abbr => [ 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So' ],
|
||||||
},
|
},
|
||||||
'en' => {
|
'en' => {
|
||||||
months =>
|
months =>
|
||||||
[ 'January', 'February', 'March', 'April', 'May', 'June', 'Jule', 'August', 'September', 'October', 'November', 'December' ],
|
[ 'January', 'February', 'March', 'April', 'May', 'June', 'Jule', 'August', 'September', 'October', 'November', 'December' ],
|
||||||
months_abbr => [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
|
months_abbr => [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ],
|
||||||
weekdays => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ],
|
weekdays => [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ],
|
||||||
weekdays_abbr => [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ],
|
weekdays_abbr => [ 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su' ],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
our $durations = [
|
our $durations = [
|
||||||
0, 5, 10, 15, 20, 30, 40, 45, 50, 60, 70, 75, 80, 90, 100, 105, 110, 115,
|
0, 5, 10, 15, 20, 30, 40, 45, 50, 60, 70, 75, 80, 90, 100, 105, 110, 115,
|
||||||
120, 135, 150, 165, 180, 195, 210, 225, 240, 300, 360, 420, 480, 540, 600, 660, 720, 1440
|
120, 135, 150, 165, 180, 195, 210, 225, 240, 300, 360, 420, 480, 540, 600, 660, 720, 1440
|
||||||
];
|
];
|
||||||
|
|
||||||
sub get_names {
|
sub get_names {
|
||||||
my $language = shift || 'en';
|
my $language = shift || 'en';
|
||||||
return $time::names->{$language};
|
return $time::names->{$language};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_all_names {
|
sub get_all_names {
|
||||||
return $time::names;
|
return $time::names;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_durations {
|
sub get_durations {
|
||||||
return $time::durations;
|
return $time::durations;
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO: build from datenames
|
#TODO: build from datenames
|
||||||
our $weekday_index = {
|
our $weekday_index = {
|
||||||
'0' => 0,
|
'0' => 0,
|
||||||
'1' => 1,
|
'1' => 1,
|
||||||
'2' => 2,
|
'2' => 2,
|
||||||
'3' => 3,
|
'3' => 3,
|
||||||
'4' => 4,
|
'4' => 4,
|
||||||
'5' => 5,
|
'5' => 5,
|
||||||
'6' => 6,
|
'6' => 6,
|
||||||
'Mo' => 0,
|
'Mo' => 0,
|
||||||
'Tu' => 1,
|
'Tu' => 1,
|
||||||
'Di' => 1,
|
'Di' => 1,
|
||||||
'We' => 2,
|
'We' => 2,
|
||||||
'Mi' => 2,
|
'Mi' => 2,
|
||||||
'Th' => 3,
|
'Th' => 3,
|
||||||
'Do' => 3,
|
'Do' => 3,
|
||||||
'Fr' => 4,
|
'Fr' => 4,
|
||||||
'Sa' => 5,
|
'Sa' => 5,
|
||||||
'Su' => 6,
|
'Su' => 6,
|
||||||
'So' => 6
|
'So' => 6
|
||||||
};
|
};
|
||||||
|
|
||||||
sub get_weekdays {
|
sub get_weekdays {
|
||||||
return {
|
return {
|
||||||
1 => 1,
|
1 => 1,
|
||||||
2 => 2,
|
2 => 2,
|
||||||
3 => 3,
|
3 => 3,
|
||||||
4 => 4,
|
4 => 4,
|
||||||
5 => 5,
|
5 => 5,
|
||||||
6 => 6,
|
6 => 6,
|
||||||
7 => 7,
|
7 => 7,
|
||||||
'Mo' => 1,
|
'Mo' => 1,
|
||||||
'Tu' => 2,
|
'Tu' => 2,
|
||||||
'Di' => 2,
|
'Di' => 2,
|
||||||
'We' => 3,
|
'We' => 3,
|
||||||
'Mi' => 3,
|
'Mi' => 3,
|
||||||
'Th' => 4,
|
'Th' => 4,
|
||||||
'Do' => 4,
|
'Do' => 4,
|
||||||
'Fr' => 5,
|
'Fr' => 5,
|
||||||
'Sa' => 6,
|
'Sa' => 6,
|
||||||
'Su' => 7,
|
'Su' => 7,
|
||||||
'So' => 7
|
'So' => 7
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#deprecated, for wordpress sync
|
#deprecated, for wordpress sync
|
||||||
sub format_datetime {
|
sub format_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
return $datetime if ( $datetime eq '' );
|
return $datetime if ( $datetime eq '' );
|
||||||
return add_hours_to_datetime( $datetime, 0 );
|
return add_hours_to_datetime( $datetime, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#deprecated
|
#deprecated
|
||||||
sub format_time {
|
sub format_time {
|
||||||
my $t = $_[0];
|
my $t = $_[0];
|
||||||
|
|
||||||
my $year = $t->[5] + 1900;
|
my $year = $t->[5] + 1900;
|
||||||
my $month = $t->[4] + 1;
|
my $month = $t->[4] + 1;
|
||||||
$month = '0' . $month if ( length($month) == 1 );
|
$month = '0' . $month if ( length($month) == 1 );
|
||||||
|
|
||||||
my $day = $t->[3];
|
my $day = $t->[3];
|
||||||
$day = '0' . $day if ( length($day) == 1 );
|
$day = '0' . $day if ( length($day) == 1 );
|
||||||
|
|
||||||
my $hour = $t->[2];
|
my $hour = $t->[2];
|
||||||
$hour = '0' . $hour if ( length($hour) == 1 );
|
$hour = '0' . $hour if ( length($hour) == 1 );
|
||||||
|
|
||||||
my $minute = $t->[1];
|
my $minute = $t->[1];
|
||||||
$minute = '0' . $minute if ( length($minute) == 1 );
|
$minute = '0' . $minute if ( length($minute) == 1 );
|
||||||
|
|
||||||
return [ $day, $month, $year, $hour, $minute ];
|
return [ $day, $month, $year, $hour, $minute ];
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert datetime to unix time
|
# convert datetime to unix time
|
||||||
sub datetime_to_time {
|
sub datetime_to_time {
|
||||||
my $datetime = $_[0];
|
my $datetime = $_[0];
|
||||||
|
|
||||||
# print $datetime."\n";
|
# print $datetime."\n";
|
||||||
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)[T\s](\d+)\:(\d+)(\:(\d+))?/ ) {
|
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)[T\s](\d+)\:(\d+)(\:(\d+))?/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2 - 1;
|
my $month = $2 - 1;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
my $hour = $4;
|
my $hour = $4;
|
||||||
my $minute = $5;
|
my $minute = $5;
|
||||||
my $second = $8 || 0;
|
my $second = $8 || 0;
|
||||||
return Time::Local::timelocal( $second, $minute, $hour, $day, $month, $year );
|
return Time::Local::timelocal( $second, $minute, $hour, $day, $month, $year );
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
print STDERR "datetime_to_time: no valid date time found! ($datetime )\n";
|
print STDERR "datetime_to_time: no valid date time found! ($datetime )\n";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#get rfc822 datetime string from datetime string
|
#get rfc822 datetime string from datetime string
|
||||||
sub datetime_to_rfc822 {
|
sub datetime_to_rfc822 {
|
||||||
my $datetime = $_[0];
|
my $datetime = $_[0];
|
||||||
my $time = datetime_to_time($datetime);
|
my $time = datetime_to_time($datetime);
|
||||||
return POSIX::strftime( "%a, %d %b %Y %H:%M:%S %z", localtime($time) );
|
return POSIX::strftime( "%a, %d %b %Y %H:%M:%S %z", localtime($time) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#get seconds from epoch
|
#get seconds from epoch
|
||||||
sub datetime_to_utc {
|
sub datetime_to_utc {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $time_zone = shift;
|
my $time_zone = shift;
|
||||||
$datetime = get_datetime( $datetime, $time_zone );
|
$datetime = get_datetime( $datetime, $time_zone );
|
||||||
return $datetime->epoch();
|
return $datetime->epoch();
|
||||||
}
|
}
|
||||||
|
|
||||||
# get full utc datetime including timezone offset
|
# get full utc datetime including timezone offset
|
||||||
sub datetime_to_utc_datetime {
|
sub datetime_to_utc_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $time_zone = shift;
|
my $time_zone = shift;
|
||||||
$datetime = get_datetime( $datetime, $time_zone );
|
$datetime = get_datetime( $datetime, $time_zone );
|
||||||
return $datetime->format_cldr("yyyy-MM-ddTHH:mm:ssZZZZZ");
|
return $datetime->format_cldr("yyyy-MM-ddTHH:mm:ssZZZZZ");
|
||||||
}
|
}
|
||||||
|
|
||||||
#add hours to datetime string
|
#add hours to datetime string
|
||||||
sub add_hours_to_datetime {
|
sub add_hours_to_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $hours = shift;
|
my $hours = shift;
|
||||||
$hours = 0 unless defined $hours;
|
$hours = 0 unless defined $hours;
|
||||||
return time_to_datetime( datetime_to_time($datetime) + ( 3600 * $hours ) );
|
return time_to_datetime( datetime_to_time($datetime) + ( 3600 * $hours ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#add minutes to datetime string
|
#add minutes to datetime string
|
||||||
sub add_minutes_to_datetime {
|
sub add_minutes_to_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $minutes = shift;
|
my $minutes = shift;
|
||||||
$minutes = 0 unless defined $minutes;
|
$minutes = 0 unless defined $minutes;
|
||||||
return time_to_datetime( datetime_to_time($datetime) + ( 60 * $minutes ) );
|
return time_to_datetime( datetime_to_time($datetime) + ( 60 * $minutes ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
#add days to datetime string
|
#add days to datetime string
|
||||||
sub add_days_to_datetime {
|
sub add_days_to_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $days = shift;
|
my $days = shift;
|
||||||
$days = 0 unless defined $days;
|
$days = 0 unless defined $days;
|
||||||
my $time = datetime_to_array($datetime);
|
my $time = datetime_to_array($datetime);
|
||||||
|
|
||||||
#print STDERR Dumper($time);
|
#print STDERR Dumper($time);
|
||||||
( $time->[0], $time->[1], $time->[2] ) = Date::Calc::Add_Delta_Days( $time->[0] + 0, $time->[1] + 0, $time->[2] + 0, $days );
|
( $time->[0], $time->[1], $time->[2] ) = Date::Calc::Add_Delta_Days( $time->[0] + 0, $time->[1] + 0, $time->[2] + 0, $days );
|
||||||
return array_to_datetime($time);
|
return array_to_datetime($time);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_days_to_date {
|
sub add_days_to_date {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $days = shift;
|
my $days = shift;
|
||||||
$days = 0 unless defined $days;
|
$days = 0 unless defined $days;
|
||||||
my $date = date_to_array($datetime);
|
my $date = date_to_array($datetime);
|
||||||
( $date->[0], $date->[1], $date->[2] ) = Date::Calc::Add_Delta_Days( $date->[0] + 0, $date->[1] + 0, $date->[2] + 0, $days );
|
( $date->[0], $date->[1], $date->[2] ) = Date::Calc::Add_Delta_Days( $date->[0] + 0, $date->[1] + 0, $date->[2] + 0, $days );
|
||||||
return array_to_date($date);
|
return array_to_date($date);
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert unix time to datetime format
|
# convert unix time to datetime format
|
||||||
sub time_to_datetime {
|
sub time_to_datetime {
|
||||||
my $time = shift;
|
my $time = shift;
|
||||||
$time = time() unless ( ( defined $time ) && ( $time ne '' ) );
|
$time = time() unless ( defined $time ) && ( $time ne '' );
|
||||||
my @t = localtime($time);
|
my @t = localtime($time);
|
||||||
return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0] );
|
return sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert unix time to date format
|
# convert unix time to date format
|
||||||
sub time_to_date {
|
sub time_to_date {
|
||||||
my $time = shift;
|
my $time = shift;
|
||||||
$time = time() unless ( ( defined $time ) && ( $time ne '' ) );
|
$time = time() unless ( defined $time ) && ( $time ne '' );
|
||||||
my @t = localtime($time);
|
my @t = localtime($time);
|
||||||
return sprintf( '%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3] );
|
return sprintf( '%04d-%02d-%02d', $t[5] + 1900, $t[4] + 1, $t[3] );
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert datetime to a array of date/time values
|
# convert datetime to a array of date/time values
|
||||||
sub datetime_to_array {
|
sub datetime_to_array {
|
||||||
my $datetime = $_[0] || '';
|
my $datetime = $_[0] || '';
|
||||||
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)([T\s]+(\d+)\:(\d+)(\:(\d+))?)?/ ) {
|
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)([T\s]+(\d+)\:(\d+)(\:(\d+))?)?/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
my $hour = $5 || '00';
|
my $hour = $5 || '00';
|
||||||
my $minute = $6 || '00';
|
my $minute = $6 || '00';
|
||||||
my $second = $8 || '00';
|
my $second = $8 || '00';
|
||||||
return [ $year, $month, $day, $hour, $minute, $second ];
|
return [ $year, $month, $day, $hour, $minute, $second ];
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert datetime to date
|
# convert datetime to date
|
||||||
sub datetime_to_date {
|
sub datetime_to_date {
|
||||||
my $datetime = $_[0] || '';
|
my $datetime = $_[0] || '';
|
||||||
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
return sprintf( "%04d-%02d-%02d", $year, $month, $day );
|
return sprintf( "%04d-%02d-%02d", $year, $month, $day );
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
#convert datetime array or single value to datetime string
|
#convert datetime array or single value to datetime string
|
||||||
sub array_to_datetime {
|
sub array_to_datetime {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
if ( ref($date) eq 'ARRAY' ) {
|
if ( ref($date) eq 'ARRAY' ) {
|
||||||
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date->[0], $date->[1], $date->[2], $date->[3], $date->[4], $date->[5] );
|
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date->[0], $date->[1], $date->[2], $date->[3], $date->[4], $date->[5] );
|
||||||
}
|
}
|
||||||
my $month = shift;
|
my $month = shift;
|
||||||
my $day = shift;
|
my $day = shift;
|
||||||
my $hour = shift || '0';
|
my $hour = shift || '0';
|
||||||
my $minute = shift || '0';
|
my $minute = shift || '0';
|
||||||
my $second = shift || '0';
|
my $second = shift || '0';
|
||||||
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date, $month, $day, $hour, $minute, $second );
|
return sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date, $month, $day, $hour, $minute, $second );
|
||||||
}
|
}
|
||||||
|
|
||||||
#convert date array or single values to date string
|
#convert date array or single values to date string
|
||||||
sub array_to_date {
|
sub array_to_date {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
if ( ref($date) eq 'ARRAY' ) {
|
if ( ref($date) eq 'ARRAY' ) {
|
||||||
return sprintf( "%04d-%02d-%02d", $date->[0], $date->[1], $date->[2] );
|
return sprintf( "%04d-%02d-%02d", $date->[0], $date->[1], $date->[2] );
|
||||||
}
|
}
|
||||||
my $month = shift;
|
my $month = shift;
|
||||||
my $day = shift;
|
my $day = shift;
|
||||||
return sprintf( "%04d-%02d-%02d", $date, $month, $day );
|
return sprintf( "%04d-%02d-%02d", $date, $month, $day );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub array_to_time {
|
sub array_to_time {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
if ( ref($date) eq 'ARRAY' ) {
|
if ( ref($date) eq 'ARRAY' ) {
|
||||||
return sprintf( "%02d:%02d:%02d", $date->[3], $date->[4], $date->[5] );
|
return sprintf( "%02d:%02d:%02d", $date->[3], $date->[4], $date->[5] );
|
||||||
}
|
}
|
||||||
my $minute = shift || 0;
|
my $minute = shift || 0;
|
||||||
my $second = shift || 0;
|
my $second = shift || 0;
|
||||||
return sprintf( "%02d:%02d:%02d", $date, $minute, $second );
|
return sprintf( "%02d:%02d:%02d", $date, $minute, $second );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub array_to_time_hm {
|
sub array_to_time_hm {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
if ( ref($date) eq 'ARRAY' ) {
|
if ( ref($date) eq 'ARRAY' ) {
|
||||||
return sprintf( "%02d:%02d", $date->[3], $date->[4] );
|
return sprintf( "%02d:%02d", $date->[3], $date->[4] );
|
||||||
}
|
}
|
||||||
my $minute = shift || 0;
|
my $minute = shift || 0;
|
||||||
return sprintf( "%02d:%02d", $date, $minute );
|
return sprintf( "%02d:%02d", $date, $minute );
|
||||||
}
|
}
|
||||||
|
|
||||||
# get number of days between two days
|
# get number of days between two days
|
||||||
sub days_between {
|
sub days_between {
|
||||||
my $today = $_[0];
|
my $today = $_[0];
|
||||||
my $date = $_[1];
|
my $date = $_[1];
|
||||||
my $delta_days = eval { Date::Calc::Delta_Days( $today->[0], $today->[1], $today->[2], $date->[0], $date->[1], $date->[2] ) };
|
my $delta_days = eval { Date::Calc::Delta_Days( $today->[0], $today->[1], $today->[2], $date->[0], $date->[1], $date->[2] ) };
|
||||||
return $delta_days;
|
return $delta_days;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub dayOfYear {
|
sub dayOfYear {
|
||||||
my $datetime = $_[0];
|
my $datetime = $_[0];
|
||||||
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
return Date::Calc::Day_of_Year( $year, $month, $day );
|
return Date::Calc::Day_of_Year( $year, $month, $day );
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get duration in minutes
|
# get duration in minutes
|
||||||
sub get_duration {
|
sub get_duration {
|
||||||
my $start = shift;
|
my $start = shift;
|
||||||
my $end = shift;
|
my $end = shift;
|
||||||
my $timezone = shift;
|
my $timezone = shift;
|
||||||
$start = time::get_datetime( $start, $timezone );
|
$start = time::get_datetime( $start, $timezone );
|
||||||
$end = time::get_datetime( $end, $timezone );
|
$end = time::get_datetime( $end, $timezone );
|
||||||
my $duration = $end->epoch() - $start->epoch();
|
my $duration = $end->epoch() - $start->epoch();
|
||||||
return $duration / 60;
|
return $duration / 60;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get duration in seconds
|
# get duration in seconds
|
||||||
sub get_duration_seconds {
|
sub get_duration_seconds {
|
||||||
my $start = shift;
|
my $start = shift;
|
||||||
my $end = shift;
|
my $end = shift;
|
||||||
my $timezone = shift || 'UTC';
|
my $timezone = shift || 'UTC';
|
||||||
|
|
||||||
unless ( defined $start ) {
|
unless ( defined $start ) {
|
||||||
print STDERR "time::get_duration_seconds(): start is missing\n";
|
print STDERR "time::get_duration_seconds(): start is missing\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
unless ( defined $end ) {
|
unless ( defined $end ) {
|
||||||
print STDERR "time::get_duration_seconds(): end is missing\n";
|
print STDERR "time::get_duration_seconds(): end is missing\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$start = time::get_datetime( $start, $timezone );
|
$start = time::get_datetime( $start, $timezone );
|
||||||
$end = time::get_datetime( $end, $timezone );
|
$end = time::get_datetime( $end, $timezone );
|
||||||
unless ( defined $start ) {
|
unless ( defined $start ) {
|
||||||
print STDERR "time::get_duration_seconds(): invalid start\n";
|
print STDERR "time::get_duration_seconds(): invalid start\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
unless ( defined $end ) {
|
unless ( defined $end ) {
|
||||||
print STDERR "time::get_duration_seconds(): invalid end\n";
|
print STDERR "time::get_duration_seconds(): invalid end\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
my $duration = $end->epoch() - $start->epoch();
|
my $duration = $end->epoch() - $start->epoch();
|
||||||
return $duration;
|
return $duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
# convert date string to a array of date values
|
# convert date string to a array of date values
|
||||||
sub date_to_array {
|
sub date_to_array {
|
||||||
my $datetime = $_[0];
|
my $datetime = $_[0];
|
||||||
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
return [ $year, $month, $day ];
|
return [ $year, $month, $day ];
|
||||||
}
|
}
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
# parse date string and return date string
|
# parse date string and return date string
|
||||||
# pass 'today', return '' on parse error
|
# pass 'today', return '' on parse error
|
||||||
sub date_cond {
|
sub date_cond {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
|
|
||||||
return '' if ( $date eq '' );
|
return '' if ( $date eq '' );
|
||||||
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
return sprintf( "%04d-%02d-%02d", $year, $month, $day );
|
return sprintf( "%04d-%02d-%02d", $year, $month, $day );
|
||||||
}
|
}
|
||||||
return 'today' if ( $date eq 'today' );
|
return 'today' if ( $date eq 'today' );
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
#parse time and return time string hh:mm:ss
|
#parse time and return time string hh:mm:ss
|
||||||
#return hh:00 if time is 'now'
|
#return hh:00 if time is 'now'
|
||||||
sub time_cond {
|
sub time_cond {
|
||||||
my $time = shift;
|
my $time = shift;
|
||||||
|
|
||||||
return '' if ( $time eq '' );
|
return '' if ( $time eq '' );
|
||||||
if ( $time =~ /(\d\d?)\:(\d\d?)(\:(\d\d))?/ ) {
|
if ( $time =~ /(\d\d?)\:(\d\d?)(\:(\d\d))?/ ) {
|
||||||
my $hour = $1;
|
my $hour = $1;
|
||||||
my $minute = $2;
|
my $minute = $2;
|
||||||
my $second = $4 || '00';
|
my $second = $4 || '00';
|
||||||
return sprintf( "%02d:%02d:%02d", $hour, $minute, $second );
|
return sprintf( "%02d:%02d:%02d", $hour, $minute, $second );
|
||||||
}
|
}
|
||||||
if ( $time eq 'now' ) {
|
if ( $time eq 'now' ) {
|
||||||
my $date = datetime_to_array( time_to_datetime( time() ) );
|
my $date = datetime_to_array( time_to_datetime( time() ) );
|
||||||
my $hour = $date->[3] - 2;
|
my $hour = $date->[3] - 2;
|
||||||
$hour = 0 if ( $hour < 0 );
|
$hour = 0 if ( $hour < 0 );
|
||||||
$time = sprintf( "%02d:00", $hour );
|
$time = sprintf( "%02d:00", $hour );
|
||||||
return $time;
|
return $time;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
#parse date and time string and return yyyy-mm-ddThh:mm:ss
|
#parse date and time string and return yyyy-mm-ddThh:mm:ss
|
||||||
sub datetime_cond {
|
sub datetime_cond {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
|
|
||||||
return '' if ( $datetime eq '' );
|
return '' if ( $datetime eq '' );
|
||||||
( my $date, my $time ) = split /[ T]/, $datetime;
|
( my $date, my $time ) = split /[ T]/, $datetime;
|
||||||
$date = time::date_cond($date);
|
$date = time::date_cond($date);
|
||||||
return '' if ( $date eq '' );
|
return '' if ( $date eq '' );
|
||||||
$time = time::time_cond($time);
|
$time = time::time_cond($time);
|
||||||
return '' if ( $time eq '' );
|
return '' if ( $time eq '' );
|
||||||
|
|
||||||
return $date . 'T' . $time;
|
return $date . 'T' . $time;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_date {
|
sub check_date {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
|
|
||||||
return "" if ( ( !defined $date ) || ( $date eq '' ) );
|
return "" if ( !defined $date ) || ( $date eq '' );
|
||||||
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
||||||
return $1 . '-' . $2 . '-' . $3;
|
return $1 . '-' . $2 . '-' . $3;
|
||||||
} elsif ( $date =~ /(\d\d?)\.(\d\d?)\.(\d\d\d\d)/ ) {
|
} elsif ( $date =~ /(\d\d?)\.(\d\d?)\.(\d\d\d\d)/ ) {
|
||||||
return $3 . '-' . $2 . '-' . $1;
|
return $3 . '-' . $2 . '-' . $1;
|
||||||
}
|
}
|
||||||
return $date if ( $date eq 'today' || $date eq 'tomorrow' || $date eq 'yesterday' );
|
return $date if ( $date eq 'today' || $date eq 'tomorrow' || $date eq 'yesterday' );
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
#error("no valid date format given!");
|
#error("no valid date format given!");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_time {
|
sub check_time {
|
||||||
my $time = shift;
|
my $time = shift;
|
||||||
return "" if ( ( !defined $time ) || ( $time eq '' ) );
|
return "" if ( !defined $time ) || ( $time eq '' );
|
||||||
return $time if ( ( $time eq 'now' ) || ( $time eq 'future' ) );
|
return $time if ( $time eq 'now' ) || ( $time eq 'future' );
|
||||||
if ( $time =~ /(\d\d?)\:(\d\d?)/ ) {
|
if ( $time =~ /(\d\d?)\:(\d\d?)/ ) {
|
||||||
return $1 . ':' . $2;
|
return $1 . ':' . $2;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_datetime {
|
sub check_datetime {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
|
|
||||||
return "" if ( ( !defined $date ) || ( $date eq '' ) );
|
return "" if ( !defined $date ) || ( $date eq '' );
|
||||||
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[T ](\d\d?)\:(\d\d?)/ ) {
|
if ( $date =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[T ](\d\d?)\:(\d\d?)/ ) {
|
||||||
return sprintf( "%04d-%02d-%02dT%02d:%02d", $1, $2, $3, $4, $5 );
|
return sprintf( "%04d-%02d-%02dT%02d:%02d", $1, $2, $3, $4, $5 );
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_year_month {
|
sub check_year_month {
|
||||||
my $date = shift;
|
my $date = shift;
|
||||||
return -1 unless ( defined $date );
|
return -1 unless ( defined $date );
|
||||||
return $date if ( $date eq '' );
|
return $date if ( $date eq '' );
|
||||||
if ( $date =~ /(\d\d\d\d)\-(\d\d?)/ ) {
|
if ( $date =~ /(\d\d\d\d)\-(\d\d?)/ ) {
|
||||||
return $1 . '-' . $2 . '-' . $3;
|
return $1 . '-' . $2 . '-' . $3;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO: remove config dependency
|
#TODO: remove config dependency
|
||||||
sub date_time_format {
|
sub date_time_format {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $language = shift || $config::config->{date}->{language} || 'en';
|
my $language = shift || $config::config->{date}->{language} || 'en';
|
||||||
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[\sT](\d\d?\:\d\d?)/ ) {
|
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[\sT](\d\d?\:\d\d?)/ ) {
|
||||||
my $time = $4;
|
my $time = $4;
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
|
|
||||||
$month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || '';
|
$month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || '';
|
||||||
return "$day. $month $year $time";
|
return "$day. $month $year $time";
|
||||||
}
|
}
|
||||||
return $datetime;
|
return $datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
#format datetime to date string
|
#format datetime to date string
|
||||||
#TODO: remove config dependency
|
#TODO: remove config dependency
|
||||||
sub date_format {
|
sub date_format {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $language = shift || $config::config->{date}->{language} || 'en';
|
my $language = shift || $config::config->{date}->{language} || 'en';
|
||||||
|
|
||||||
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) {
|
||||||
my $day = $3;
|
my $day = $3;
|
||||||
my $month = $2;
|
my $month = $2;
|
||||||
my $year = $1;
|
my $year = $1;
|
||||||
$month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || '';
|
$month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || '';
|
||||||
return "$day. $month $year";
|
return "$day. $month $year";
|
||||||
}
|
}
|
||||||
return $datetime;
|
return $datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
#format datetime to time string
|
#format datetime to time string
|
||||||
sub time_format {
|
sub time_format {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
if ( defined $datetime && $datetime =~ /(\d\d?\:\d\d?)/ ) {
|
if ( defined $datetime && $datetime =~ /(\d\d?\:\d\d?)/ ) {
|
||||||
return $1;
|
return $1;
|
||||||
}
|
}
|
||||||
return $datetime;
|
return $datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
#get offset from given time_zone
|
#get offset from given time_zone
|
||||||
sub utc_offset {
|
sub utc_offset {
|
||||||
my $time_zone = shift;
|
my $time_zone = shift;
|
||||||
|
|
||||||
$a = DateTime->now();
|
$a = DateTime->now();
|
||||||
$a->set_time_zone($time_zone);
|
$a->set_time_zone($time_zone);
|
||||||
return $a->strftime("%z");
|
return $a->strftime("%z");
|
||||||
}
|
}
|
||||||
|
|
||||||
#get weekday from (yyyy,mm,dd)
|
#get weekday from (yyyy,mm,dd)
|
||||||
sub weekday {
|
sub weekday {
|
||||||
my ( $year, $month, $day ) = @_;
|
my ( $year, $month, $day ) = @_;
|
||||||
my $time = Time::Local::timelocal( 0, 0, 0, $day, $month - 1, $year );
|
my $time = Time::Local::timelocal( 0, 0, 0, $day, $month - 1, $year );
|
||||||
return ( localtime($time) )[6];
|
return ( localtime($time) )[6];
|
||||||
}
|
}
|
||||||
|
|
||||||
#get current date, related to starting day_starting_hour
|
#get current date, related to starting day_starting_hour
|
||||||
#TODO: remove config dependency
|
#TODO: remove config dependency
|
||||||
sub get_event_date {
|
sub get_event_date {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
$config = $config::config unless defined $config;
|
$config = $config::config unless defined $config;
|
||||||
|
|
||||||
my $datetime = time::time_to_datetime( time() );
|
my $datetime = time::time_to_datetime( time() );
|
||||||
my $hour = ( time::datetime_to_array($datetime) )->[3];
|
my $hour = ( time::datetime_to_array($datetime) )->[3];
|
||||||
|
|
||||||
#print STDERR "datetime=$datetime hour=$hour\n";
|
#print STDERR "datetime=$datetime hour=$hour\n";
|
||||||
#today: between 0:00 and starting_hour show last day
|
#today: between 0:00 and starting_hour show last day
|
||||||
if ( $hour < $config->{date}->{day_starting_hour} ) {
|
if ( $hour < $config->{date}->{day_starting_hour} ) {
|
||||||
my $date = time::datetime_to_array( time::add_days_to_datetime( $datetime, -1 ) );
|
my $date = time::datetime_to_array( time::add_days_to_datetime( $datetime, -1 ) );
|
||||||
return join( '-', ( $date->[0], $date->[1], $date->[2] ) );
|
return join( '-', ( $date->[0], $date->[1], $date->[2] ) );
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
#today: between starting_hour and end of day show current day
|
#today: between starting_hour and end of day show current day
|
||||||
my $date = time::datetime_to_array( time::time_to_datetime( time() ) );
|
my $date = time::datetime_to_array( time::time_to_datetime( time() ) );
|
||||||
return join( '-', ( $date->[0], $date->[1], $date->[2] ) );
|
return join( '-', ( $date->[0], $date->[1], $date->[2] ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#get datetime object from datetime string
|
#get datetime object from datetime string
|
||||||
sub get_datetime {
|
sub get_datetime {
|
||||||
my $datetime = shift;
|
my $datetime = shift;
|
||||||
my $timezone = shift;
|
my $timezone = shift;
|
||||||
|
|
||||||
return unless defined $datetime;
|
return unless defined $datetime;
|
||||||
return if $datetime eq '';
|
return if $datetime eq '';
|
||||||
my @l = @{ time::datetime_to_array($datetime) };
|
my @l = @{ time::datetime_to_array($datetime) };
|
||||||
return undef if scalar(@l) == 0;
|
return undef if scalar(@l) == 0;
|
||||||
|
|
||||||
# catch invalid datees
|
# catch invalid datees
|
||||||
$datetime = undef;
|
$datetime = undef;
|
||||||
eval {
|
eval {
|
||||||
$datetime = DateTime->new(
|
$datetime = DateTime->new(
|
||||||
year => $l[0],
|
year => $l[0],
|
||||||
month => $l[1],
|
month => $l[1],
|
||||||
day => $l[2],
|
day => $l[2],
|
||||||
hour => $l[3],
|
hour => $l[3],
|
||||||
minute => $l[4],
|
minute => $l[4],
|
||||||
second => $l[5],
|
second => $l[5],
|
||||||
time_zone => $timezone
|
time_zone => $timezone
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
return undef unless defined $datetime;
|
return undef unless defined $datetime;
|
||||||
$datetime->set_locale('de_DE');
|
$datetime->set_locale('de_DE');
|
||||||
return $datetime;
|
return $datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
#get list of nth weekday in month from start to end
|
#get list of nth weekday in month from start to end
|
||||||
sub get_nth_weekday_in_month {
|
sub get_nth_weekday_in_month {
|
||||||
my $start = shift; # datetime string
|
my $start = shift; # datetime string
|
||||||
my $end = shift; # datetime string
|
my $end = shift; # datetime string
|
||||||
my $nth = shift; # every nth week of month
|
my $nth = shift; # every nth week of month
|
||||||
my $weekday = shift; # weekday [1..7,'Mo'-'Su','Mo'-'Fr']
|
my $weekday = shift; # weekday [1..7,'Mo'-'Su','Mo'-'Fr']
|
||||||
|
|
||||||
return [] unless defined $start;
|
return [] unless defined $start;
|
||||||
return [] unless defined $end;
|
return [] unless defined $end;
|
||||||
return [] unless defined $nth;
|
return [] unless defined $nth;
|
||||||
return [] unless defined $weekday;
|
return [] unless defined $weekday;
|
||||||
|
|
||||||
my $weekdays = time::get_weekdays();
|
my $weekdays = time::get_weekdays();
|
||||||
return [] unless defined $weekdays->{$weekday};
|
return [] unless defined $weekdays->{$weekday};
|
||||||
$weekday = $weekdays->{$weekday};
|
$weekday = $weekdays->{$weekday};
|
||||||
|
|
||||||
my $dates = [];
|
my $dates = [];
|
||||||
|
|
||||||
if ( $start =~ /(\d\d\d\d)-(\d\d)-(\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
if ( $start =~ /(\d\d\d\d)-(\d\d)-(\d\d)[ T](\d\d)\:(\d\d)/ ) {
|
||||||
my $hour = int($4);
|
my $hour = int($4);
|
||||||
my $min = int($5);
|
my $min = int($5);
|
||||||
my $sec = 0;
|
my $sec = 0;
|
||||||
my @date = Date::Manip::ParseRecur( "0:1*$nth:$weekday:$hour:$min:$sec", "", $start, $end );
|
my @date = Date::Manip::ParseRecur( "0:1*$nth:$weekday:$hour:$min:$sec", "", $start, $end );
|
||||||
for my $date (@date) {
|
for my $date (@date) {
|
||||||
if ( $date =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)\:(\d\d)\:(\d\d)/ ) {
|
if ( $date =~ /(\d\d\d\d)(\d\d)(\d\d)(\d\d)\:(\d\d)\:(\d\d)/ ) {
|
||||||
push @$dates, "$1-$2-$3 $4:$5:$6";
|
push @$dates, "$1-$2-$3 $4:$5:$6";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -14,218 +14,218 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
our $defaultColors = [
|
our $defaultColors = [
|
||||||
{
|
{
|
||||||
name => 'color_event',
|
name => 'color_event',
|
||||||
css => '#content .event',
|
css => '#content .event',
|
||||||
color => '#c5e1a5'
|
color => '#c5e1a5'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_draft',
|
name => 'color_draft',
|
||||||
css => '#content .draft',
|
css => '#content .draft',
|
||||||
color => '#eeeeee',
|
color => '#eeeeee',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_schedule',
|
name => 'color_schedule',
|
||||||
css => '#content .schedule',
|
css => '#content .schedule',
|
||||||
color => '#dde4e6',
|
color => '#dde4e6',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_published',
|
name => 'color_published',
|
||||||
css => '#content .event.published',
|
css => '#content .event.published',
|
||||||
color => '#a5d6a7',
|
color => '#a5d6a7',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_no_series',
|
name => 'color_no_series',
|
||||||
css => '#content .event.no_series',
|
css => '#content .event.no_series',
|
||||||
color => '#fff59d',
|
color => '#fff59d',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_marked',
|
name => 'color_marked',
|
||||||
css => '#content .event.marked',
|
css => '#content .event.marked',
|
||||||
color => '#81d4fa',
|
color => '#81d4fa',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_event_error',
|
name => 'color_event_error',
|
||||||
css => '#content.conflicts .event.error',
|
css => '#content.conflicts .event.error',
|
||||||
color => '#ffab91',
|
color => '#ffab91',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_schedule_error',
|
name => 'color_schedule_error',
|
||||||
css => '#content.conflicts .schedule.error',
|
css => '#content.conflicts .schedule.error',
|
||||||
color => '#ffcc80'
|
color => '#ffcc80'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_work',
|
name => 'color_work',
|
||||||
css => '#content .work',
|
css => '#content .work',
|
||||||
color => '#b39ddb'
|
color => '#b39ddb'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name => 'color_playout',
|
name => 'color_playout',
|
||||||
css => '#content .play',
|
css => '#content .play',
|
||||||
color => '#90caf9'
|
color => '#90caf9'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
sub getColors {
|
sub getColors {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $conditions = shift;
|
my $conditions = shift;
|
||||||
return unless defined $conditions->{user};
|
return unless defined $conditions->{user};
|
||||||
my $user = $conditions->{user};
|
my $user = $conditions->{user};
|
||||||
|
|
||||||
#get defaultColors
|
#get defaultColors
|
||||||
my $colors = [];
|
my $colors = [];
|
||||||
my $colorMap = {};
|
my $colorMap = {};
|
||||||
for my $defaultColor (@$defaultColors) {
|
for my $defaultColor (@$defaultColors) {
|
||||||
my $color = {
|
my $color = {
|
||||||
name => $defaultColor->{name},
|
name => $defaultColor->{name},
|
||||||
css => $defaultColor->{css},
|
css => $defaultColor->{css},
|
||||||
color => $defaultColor->{color},
|
color => $defaultColor->{color},
|
||||||
};
|
};
|
||||||
push @$colors, $color;
|
push @$colors, $color;
|
||||||
$colorMap->{ $color->{css} } = $color;
|
$colorMap->{ $color->{css} } = $color;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $settings = user_settings::get( $config, { user => $user } );
|
my $settings = user_settings::get( $config, { user => $user } );
|
||||||
$settings->{colors} |= '';
|
$settings->{colors} |= '';
|
||||||
|
|
||||||
#overwrite colors from user settings
|
#overwrite colors from user settings
|
||||||
for my $line ( split( /\n+/, $settings->{colors} ) ) {
|
for my $line ( split( /\n+/, $settings->{colors} ) ) {
|
||||||
my ( $key, $value ) = split( /\=/, $line );
|
my ( $key, $value ) = split( /\=/, $line );
|
||||||
$key =~ s/^\s+//;
|
$key =~ s/^\s+//;
|
||||||
$key =~ s/\s+$//;
|
$key =~ s/\s+$//;
|
||||||
$value =~ s/^\s+//;
|
$value =~ s/^\s+//;
|
||||||
$value =~ s/\s+$//;
|
$value =~ s/\s+$//;
|
||||||
$colorMap->{$key}->{color} = $value if ( ( $key ne '' ) && ( $value ne '' ) && ( defined $colorMap->{$key} ) );
|
$colorMap->{$key}->{color} = $value if ( $key ne '' ) && ( $value ne '' ) && ( defined $colorMap->{$key} ) ;
|
||||||
}
|
}
|
||||||
return $colors;
|
return $colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getColorCss {
|
sub getColorCss {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $conditions = shift;
|
my $conditions = shift;
|
||||||
return unless defined $conditions->{user};
|
return unless defined $conditions->{user};
|
||||||
|
|
||||||
my $shift = 20;
|
my $shift = 20;
|
||||||
my $limit = 220;
|
my $limit = 220;
|
||||||
|
|
||||||
my $colors = getColors( $config, $conditions );
|
my $colors = getColors( $config, $conditions );
|
||||||
my $style = "<style>\n";
|
my $style = "<style>\n";
|
||||||
for my $color (@$colors) {
|
for my $color (@$colors) {
|
||||||
$style .= $color->{css} . "{\n\tbackground-color:" . $color->{color} . ";\n}\n";
|
$style .= $color->{css} . "{\n\tbackground-color:" . $color->{color} . ";\n}\n";
|
||||||
my $c = $color->{color};
|
my $c = $color->{color};
|
||||||
if ( $c =~ /#([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])/ ) {
|
if ( $c =~ /#([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])/ ) {
|
||||||
my $r = hex($1);
|
my $r = hex($1);
|
||||||
my $g = hex($2);
|
my $g = hex($2);
|
||||||
my $b = hex($3);
|
my $b = hex($3);
|
||||||
if ( $r > $limit ) { $r -= $shift; }
|
if ( $r > $limit ) { $r -= $shift; }
|
||||||
else { $r += $shift; }
|
else { $r += $shift; }
|
||||||
if ( $g > $limit ) { $g -= $shift; }
|
if ( $g > $limit ) { $g -= $shift; }
|
||||||
else { $g += $shift; }
|
else { $g += $shift; }
|
||||||
if ( $b > $limit ) { $b -= $shift; }
|
if ( $b > $limit ) { $b -= $shift; }
|
||||||
else { $b += $shift; }
|
else { $b += $shift; }
|
||||||
$c = sprintf( "#%x%x%x", $r, $g, $b );
|
$c = sprintf( "#%x%x%x", $r, $g, $b );
|
||||||
$style .= $color->{css} . ":hover{\n\tbackground-color:" . $c . ";\n}\n";
|
$style .= $color->{css} . ":hover{\n\tbackground-color:" . $c . ";\n}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$style .= "</style>\n";
|
$style .= "</style>\n";
|
||||||
return $style;
|
return $style;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_user_settings' );
|
my $cols = db::get_columns( $dbh, 'calcms_user_settings' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
||||||
push @conditions, 'user=?';
|
push @conditions, 'user=?';
|
||||||
push @bind_values, $condition->{user};
|
push @bind_values, $condition->{user};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_user_settings
|
from calcms_user_settings
|
||||||
$conditions
|
$conditions
|
||||||
};
|
};
|
||||||
|
|
||||||
#print $query."\n";
|
#print $query."\n";
|
||||||
#print Dumper(\@bind_values);
|
#print Dumper(\@bind_values);
|
||||||
|
|
||||||
my $entries = db::get( $dbh, $query, \@bind_values );
|
my $entries = db::get( $dbh, $query, \@bind_values );
|
||||||
return $entries->[0] || undef;
|
return $entries->[0] || undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub insert {
|
sub insert {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return unless ( defined $entry->{user} );
|
return unless ( defined $entry->{user} );
|
||||||
return unless ( defined $entry->{colors} );
|
return unless ( defined $entry->{colors} );
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
return db::insert( $dbh, 'calcms_user_settings', $entry );
|
return db::insert( $dbh, 'calcms_user_settings', $entry );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return unless ( defined $entry->{user} );
|
return unless ( defined $entry->{user} );
|
||||||
return unless ( defined $entry->{colors} );
|
return unless ( defined $entry->{colors} );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
||||||
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
||||||
push @bind_values, $entry->{user};
|
push @bind_values, $entry->{user};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
update calcms_user_settings
|
update calcms_user_settings
|
||||||
set $values
|
set $values
|
||||||
where user=?
|
where user=?
|
||||||
};
|
};
|
||||||
db::put( $dbh, $query, \@bind_values );
|
db::put( $dbh, $query, \@bind_values );
|
||||||
print "done\n";
|
print "done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
return unless ( defined $entry->{user} );
|
return unless ( defined $entry->{user} );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
delete
|
delete
|
||||||
from calcms_user_settings
|
from calcms_user_settings
|
||||||
where user=?
|
where user=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{user} ];
|
my $bind_values = [ $entry->{user} ];
|
||||||
|
|
||||||
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
||||||
db::put( $dbh, $query, $bind_values );
|
db::put( $dbh, $query, $bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -13,55 +13,55 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_user_stats' );
|
my $cols = db::get_columns( $dbh, 'calcms_user_stats' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'series_id=?';
|
push @conditions, 'series_id=?';
|
||||||
push @bind_values, $condition->{series_id};
|
push @bind_values, $condition->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
||||||
push @conditions, 'user=?';
|
push @conditions, 'user=?';
|
||||||
push @bind_values, $condition->{user};
|
push @bind_values, $condition->{user};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $limit = '';
|
my $limit = '';
|
||||||
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
||||||
$limit = 'limit ' . $condition->{limit};
|
$limit = 'limit ' . $condition->{limit};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select *
|
select *
|
||||||
from calcms_user_stats
|
from calcms_user_stats
|
||||||
$conditions
|
$conditions
|
||||||
@@ -69,50 +69,50 @@ sub get {
|
|||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
|
|
||||||
my $results = db::get( $dbh, $query, \@bind_values );
|
my $results = db::get( $dbh, $query, \@bind_values );
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_stats {
|
sub get_stats {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my @conditions = ();
|
my @conditions = ();
|
||||||
my @bind_values = ();
|
my @bind_values = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) {
|
||||||
push @conditions, 'series_id=?';
|
push @conditions, 'series_id=?';
|
||||||
push @bind_values, $condition->{series_id};
|
push @bind_values, $condition->{series_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) {
|
||||||
push @conditions, 'user=?';
|
push @conditions, 'user=?';
|
||||||
push @bind_values, $condition->{user};
|
push @bind_values, $condition->{user};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $limit = '';
|
my $limit = '';
|
||||||
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) {
|
||||||
$limit = 'limit ' . $condition->{limit};
|
$limit = 'limit ' . $condition->{limit};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select user, project_id, studio_id,
|
select user, project_id, studio_id,
|
||||||
max(modified_at) modified_at,
|
max(modified_at) modified_at,
|
||||||
sum(create_events) create_events,
|
sum(create_events) create_events,
|
||||||
@@ -127,126 +127,126 @@ sub get_stats {
|
|||||||
$limit
|
$limit
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
|
|
||||||
my $results = db::get( $dbh, $query, \@bind_values );
|
my $results = db::get( $dbh, $query, \@bind_values );
|
||||||
for my $result (@$results) {
|
for my $result (@$results) {
|
||||||
$result->{score} = 0;
|
$result->{score} = 0;
|
||||||
for my $column ( 'create_events', 'update_events', 'delete_events', 'create_series', 'update_series', 'delete_series' ) {
|
for my $column ( 'create_events', 'update_events', 'delete_events', 'create_series', 'update_series', 'delete_series' ) {
|
||||||
$result->{score} += $result->{$column};
|
$result->{score} += $result->{$column};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
my @results = reverse sort { $a->{score} <=> $b->{score} } @$results;
|
my @results = reverse sort { $a->{score} <=> $b->{score} } @$results;
|
||||||
return \@results;
|
return \@results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub insert {
|
sub insert {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $stats = shift;
|
my $stats = shift;
|
||||||
|
|
||||||
return undef unless defined $stats->{project_id};
|
return undef unless defined $stats->{project_id};
|
||||||
return undef unless defined $stats->{studio_id};
|
return undef unless defined $stats->{studio_id};
|
||||||
return undef unless defined $stats->{series_id};
|
return undef unless defined $stats->{series_id};
|
||||||
return undef unless defined $stats->{user};
|
return undef unless defined $stats->{user};
|
||||||
|
|
||||||
#TODO:filter for existing attributes
|
#TODO:filter for existing attributes
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$entry->{$column} = $stats->{$column} if defined $stats->{$column};
|
$entry->{$column} = $stats->{$column} if defined $stats->{$column};
|
||||||
}
|
}
|
||||||
$entry->{modified_at} = time::time_to_datetime( time() );
|
$entry->{modified_at} = time::time_to_datetime( time() );
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $id = db::insert( $dbh, 'calcms_user_stats', $entry );
|
my $id = db::insert( $dbh, 'calcms_user_stats', $entry );
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
# update project
|
# update project
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $stats = shift;
|
my $stats = shift;
|
||||||
|
|
||||||
return undef unless defined $stats->{project_id};
|
return undef unless defined $stats->{project_id};
|
||||||
return undef unless defined $stats->{studio_id};
|
return undef unless defined $stats->{studio_id};
|
||||||
return undef unless defined $stats->{series_id};
|
return undef unless defined $stats->{series_id};
|
||||||
return undef unless defined $stats->{user};
|
return undef unless defined $stats->{user};
|
||||||
|
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $column ( keys %$columns ) {
|
for my $column ( keys %$columns ) {
|
||||||
$entry->{$column} = $stats->{$column} if defined $stats->{$column};
|
$entry->{$column} = $stats->{$column} if defined $stats->{$column};
|
||||||
}
|
}
|
||||||
$entry->{modified_at} = time::time_to_datetime( time() );
|
$entry->{modified_at} = time::time_to_datetime( time() );
|
||||||
|
|
||||||
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) );
|
||||||
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
my @bind_values = map { $entry->{$_} } ( keys %$entry );
|
||||||
push @bind_values, $entry->{user};
|
push @bind_values, $entry->{user};
|
||||||
push @bind_values, $entry->{project_id};
|
push @bind_values, $entry->{project_id};
|
||||||
push @bind_values, $entry->{studio_id};
|
push @bind_values, $entry->{studio_id};
|
||||||
push @bind_values, $entry->{series_id};
|
push @bind_values, $entry->{series_id};
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
update calcms_user_stats
|
update calcms_user_stats
|
||||||
set $values
|
set $values
|
||||||
where user=? and project_id=? and studio_id=? and series_id=?
|
where user=? and project_id=? and studio_id=? and series_id=?
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
return db::put( $dbh, $query, \@bind_values );
|
return db::put( $dbh, $query, \@bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub increase {
|
sub increase {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $usecase = shift;
|
my $usecase = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
#print STDERR Dumper($usecase)." ".Dumper($options);
|
#print STDERR Dumper($usecase)." ".Dumper($options);
|
||||||
|
|
||||||
return undef unless defined $usecase;
|
return undef unless defined $usecase;
|
||||||
return undef unless defined $options->{project_id};
|
return undef unless defined $options->{project_id};
|
||||||
return undef unless defined $options->{studio_id};
|
return undef unless defined $options->{studio_id};
|
||||||
return undef unless defined $options->{series_id};
|
return undef unless defined $options->{series_id};
|
||||||
return undef unless defined $options->{user};
|
return undef unless defined $options->{user};
|
||||||
|
|
||||||
#print STDERR "ok\n";
|
#print STDERR "ok\n";
|
||||||
|
|
||||||
my $columns = get_columns($config);
|
my $columns = get_columns($config);
|
||||||
|
|
||||||
#print STDERR "columns:".Dumper($columns);
|
#print STDERR "columns:".Dumper($columns);
|
||||||
return undef unless defined $columns->{$usecase};
|
return undef unless defined $columns->{$usecase};
|
||||||
|
|
||||||
my $entries = get( $config, $options );
|
my $entries = get( $config, $options );
|
||||||
|
|
||||||
#print STDERR "exist:".Dumper($columns);
|
#print STDERR "exist:".Dumper($columns);
|
||||||
|
|
||||||
if ( @$entries == 0 ) {
|
if ( scalar @$entries == 0 ) {
|
||||||
my $entry = {
|
my $entry = {
|
||||||
project_id => $options->{project_id},
|
project_id => $options->{project_id},
|
||||||
studio_id => $options->{studio_id},
|
studio_id => $options->{studio_id},
|
||||||
series_id => $options->{series_id},
|
series_id => $options->{series_id},
|
||||||
user => $options->{user},
|
user => $options->{user},
|
||||||
$usecase => 1,
|
$usecase => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR "user_stats::insert\n";
|
#print STDERR "user_stats::insert\n";
|
||||||
return insert( $config, $entry );
|
return insert( $config, $entry );
|
||||||
} elsif ( @$entries == 1 ) {
|
} elsif ( scalar @$entries == 1 ) {
|
||||||
my $entry = $entries->[0];
|
my $entry = $entries->[0];
|
||||||
$entry->{$usecase}++ if defined
|
$entry->{$usecase}++ if defined
|
||||||
|
|
||||||
#print STDERR "user_stats::update\n";
|
#print STDERR "user_stats::update\n";
|
||||||
return update( $config, $entry );
|
return update( $config, $entry );
|
||||||
} else {
|
} else {
|
||||||
print STDERR "user_stats: to few options given: $usecase," . Dumper($options) . "\n";
|
print STDERR "user_stats: to few options given: $usecase," . Dumper($options) . "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -22,80 +22,80 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
|
|||||||
sub debug;
|
sub debug;
|
||||||
|
|
||||||
sub get_columns {
|
sub get_columns {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $cols = db::get_columns( $dbh, 'calcms_work_dates' );
|
my $cols = db::get_columns( $dbh, 'calcms_work_dates' );
|
||||||
my $columns = {};
|
my $columns = {};
|
||||||
for my $col (@$cols) {
|
for my $col (@$cols) {
|
||||||
$columns->{$col} = 1;
|
$columns->{$col} = 1;
|
||||||
}
|
}
|
||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get all work_dates for studio_id and schedule_id within given time range
|
# get all work_dates for studio_id and schedule_id within given time range
|
||||||
# calculate start_date, end_date, weeday, day from start and end(datetime)
|
# calculate start_date, end_date, weeday, day from start and end(datetime)
|
||||||
sub get {
|
sub get {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $condition = shift;
|
my $condition = shift;
|
||||||
|
|
||||||
my $date_range_include = 0;
|
my $date_range_include = 0;
|
||||||
$date_range_include = 1 if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 );
|
$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 = ();
|
||||||
|
|
||||||
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) {
|
||||||
push @conditions, 'project_id=?';
|
push @conditions, 'project_id=?';
|
||||||
push @bind_values, $condition->{project_id};
|
push @bind_values, $condition->{project_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) {
|
||||||
push @conditions, 'studio_id=?';
|
push @conditions, 'studio_id=?';
|
||||||
push @bind_values, $condition->{studio_id};
|
push @bind_values, $condition->{studio_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) {
|
||||||
push @conditions, 'schedule_id=?';
|
push @conditions, 'schedule_id=?';
|
||||||
push @bind_values, $condition->{schedule_id};
|
push @bind_values, $condition->{schedule_id};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) {
|
||||||
push @conditions, 'start=?';
|
push @conditions, 'start=?';
|
||||||
push @bind_values, $condition->{start_at};
|
push @bind_values, $condition->{start_at};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) {
|
||||||
if ( $date_range_include == 1 ) {
|
if ( $date_range_include == 1 ) {
|
||||||
push @conditions, 'end_date>=?';
|
push @conditions, 'end_date>=?';
|
||||||
push @bind_values, $condition->{from};
|
push @bind_values, $condition->{from};
|
||||||
} else {
|
} else {
|
||||||
push @conditions, 'start_date>=?';
|
push @conditions, 'start_date>=?';
|
||||||
push @bind_values, $condition->{from};
|
push @bind_values, $condition->{from};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) {
|
||||||
if ( $date_range_include == 1 ) {
|
if ( $date_range_include == 1 ) {
|
||||||
push @conditions, 'start_date<=?';
|
push @conditions, 'start_date<=?';
|
||||||
push @bind_values, $condition->{till};
|
push @bind_values, $condition->{till};
|
||||||
} else {
|
} else {
|
||||||
push @conditions, 'end_date<=?';
|
push @conditions, 'end_date<=?';
|
||||||
push @bind_values, $condition->{till};
|
push @bind_values, $condition->{till};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) {
|
||||||
push @conditions, 'exclude=?';
|
push @conditions, 'exclude=?';
|
||||||
push @bind_values, $condition->{exclude};
|
push @bind_values, $condition->{exclude};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $conditions = '';
|
my $conditions = '';
|
||||||
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
$conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 );
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
select date(start) start_date
|
select date(start) start_date
|
||||||
,date(end) end_date
|
,date(end) end_date
|
||||||
,dayname(start) weekday
|
,dayname(start) weekday
|
||||||
@@ -114,281 +114,281 @@ sub get {
|
|||||||
order by start
|
order by start
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR $query."\n";
|
#print STDERR $query."\n";
|
||||||
#print STDERR Dumper(\@bind_values);
|
#print STDERR Dumper(\@bind_values);
|
||||||
|
|
||||||
my $entries = db::get( $dbh, $query, \@bind_values );
|
my $entries = db::get( $dbh, $query, \@bind_values );
|
||||||
for my $entry (@$entries) {
|
for my $entry (@$entries) {
|
||||||
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
$entry->{weekday} = substr( $entry->{weekday}, 0, 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
#update work dates for all schedules of a work and studio_id
|
#update work dates for all schedules of a work and studio_id
|
||||||
sub update {
|
sub update {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{schedule_id};
|
return undef unless defined $entry->{schedule_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
#delete all existing work dates (by project, studio and schedule id)
|
#delete all existing work dates (by project, studio and schedule id)
|
||||||
work_dates::delete( $config, $entry );
|
work_dates::delete( $config, $entry );
|
||||||
|
|
||||||
my $day_start = $config->{date}->{day_starting_hour};
|
my $day_start = $config->{date}->{day_starting_hour};
|
||||||
|
|
||||||
#get all schedules for schedule id ordered by exclude, date
|
#get all schedules for schedule id ordered by exclude, date
|
||||||
my $schedules = work_schedule::get(
|
my $schedules = work_schedule::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
schedule_id => $entry->{schedule_id},
|
schedule_id => $entry->{schedule_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#add scheduled work dates and remove exluded dates
|
#add scheduled work dates and remove exluded dates
|
||||||
my $work_dates = {};
|
my $work_dates = {};
|
||||||
|
|
||||||
#TODO:set schedules exclude to 0 if not 1
|
#TODO:set schedules exclude to 0 if not 1
|
||||||
#insert all normal dates (not excludes)
|
#insert all normal dates (not excludes)
|
||||||
for my $schedule (@$schedules) {
|
for my $schedule (@$schedules) {
|
||||||
my $dates = get_schedule_dates( $schedule, { exclude => 0 } );
|
my $dates = get_schedule_dates( $schedule, { exclude => 0 } );
|
||||||
for my $date (@$dates) {
|
for my $date (@$dates) {
|
||||||
$date->{exclude} = 0;
|
$date->{exclude} = 0;
|
||||||
$work_dates->{ $date->{start} } = $date;
|
$work_dates->{ $date->{start} } = $date;
|
||||||
|
|
||||||
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#insert / overwrite all exlude dates
|
#insert / overwrite all exlude dates
|
||||||
for my $schedule (@$schedules) {
|
for my $schedule (@$schedules) {
|
||||||
my $dates = get_schedule_dates( $schedule, { exclude => 1 } );
|
my $dates = get_schedule_dates( $schedule, { exclude => 1 } );
|
||||||
for my $date (@$dates) {
|
for my $date (@$dates) {
|
||||||
$date->{exclude} = 1;
|
$date->{exclude} = 1;
|
||||||
$work_dates->{ $date->{start} } = $date;
|
$work_dates->{ $date->{start} } = $date;
|
||||||
|
|
||||||
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
#print STDERR Dumper($date)."\n" if ($date->{start} eq'2014-02-05 19:00:00');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR Dumper($work_dates->{'2014-02-05 19:00:00'});
|
#print STDERR Dumper($work_dates->{'2014-02-05 19:00:00'});
|
||||||
|
|
||||||
my $request = { config => $config };
|
my $request = { config => $config };
|
||||||
|
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
my $j = 0;
|
my $j = 0;
|
||||||
for my $date ( keys %$work_dates ) {
|
for my $date ( keys %$work_dates ) {
|
||||||
my $work_date = $work_dates->{$date};
|
my $work_date = $work_dates->{$date};
|
||||||
|
|
||||||
#insert date
|
#insert date
|
||||||
my $entry = {
|
my $entry = {
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
schedule_id => $entry->{schedule_id},
|
schedule_id => $entry->{schedule_id},
|
||||||
title => $entry->{title},
|
title => $entry->{title},
|
||||||
type => $entry->{type},
|
type => $entry->{type},
|
||||||
schedule_id => $entry->{schedule_id},
|
schedule_id => $entry->{schedule_id},
|
||||||
start => $work_date->{start},
|
start => $work_date->{start},
|
||||||
end => $work_date->{end},
|
end => $work_date->{end},
|
||||||
exclude => $work_date->{exclude}
|
exclude => $work_date->{exclude}
|
||||||
};
|
};
|
||||||
if ( studio_timeslot_dates::can_studio_edit_events( $config, $entry ) == 1 ) { # by studio_id, start, end
|
if ( studio_timeslot_dates::can_studio_edit_events( $config, $entry ) == 1 ) { # by studio_id, start, end
|
||||||
$entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start );
|
$entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start );
|
||||||
$entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start );
|
$entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start );
|
||||||
db::insert( $dbh, 'calcms_work_dates', $entry );
|
db::insert( $dbh, 'calcms_work_dates', $entry );
|
||||||
|
|
||||||
#print STDERR "$entry->{start_date}\n";
|
#print STDERR "$entry->{start_date}\n";
|
||||||
$i++;
|
$i++;
|
||||||
} else {
|
} else {
|
||||||
$j++;
|
$j++;
|
||||||
|
|
||||||
#print STDERR Dumper($entry);
|
#print STDERR Dumper($entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#print STDERR "$i work_dates updates\n";
|
#print STDERR "$i work_dates updates\n";
|
||||||
return $j . " dates out of studio times, " . $i;
|
return $j . " dates out of studio times, " . $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_schedule_dates {
|
sub get_schedule_dates {
|
||||||
my $schedule = shift;
|
my $schedule = shift;
|
||||||
my $options = shift;
|
my $options = shift;
|
||||||
|
|
||||||
my $is_exclude = $options->{exclude} || 0;
|
my $is_exclude = $options->{exclude} || 0;
|
||||||
my $dates = [];
|
my $dates = [];
|
||||||
return $dates if ( ( $is_exclude eq '1' ) && ( $schedule->{exclude} ne '1' ) );
|
return $dates if ( $is_exclude eq '1' ) && ( $schedule->{exclude} ne '1' );
|
||||||
return $dates if ( ( $is_exclude eq '0' ) && ( $schedule->{exclude} eq '1' ) );
|
return $dates if ( $is_exclude eq '0' ) && ( $schedule->{exclude} eq '1' );
|
||||||
|
|
||||||
if ( $schedule->{period_type} eq 'single' ) {
|
if ( $schedule->{period_type} eq 'single' ) {
|
||||||
$dates = get_single_date( $schedule->{start}, $schedule->{duration} );
|
$dates = get_single_date( $schedule->{start}, $schedule->{duration} );
|
||||||
} elsif ( $schedule->{period_type} eq 'days' ) {
|
} elsif ( $schedule->{period_type} eq 'days' ) {
|
||||||
$dates = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{frequency} );
|
$dates = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{duration}, $schedule->{frequency} );
|
||||||
} elsif ( $schedule->{period_type} eq 'week_of_month' ) {
|
} elsif ( $schedule->{period_type} eq 'week_of_month' ) {
|
||||||
$dates = get_week_of_month_dates(
|
$dates = get_week_of_month_dates(
|
||||||
$schedule->{start}, $schedule->{end}, $schedule->{duration},
|
$schedule->{start}, $schedule->{end}, $schedule->{duration},
|
||||||
$schedule->{week_of_month}, $schedule->{weekday}, $schedule->{month}
|
$schedule->{week_of_month}, $schedule->{weekday}, $schedule->{month}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print STDERR "unknown schedule period_type\n";
|
print STDERR "unknown schedule period_type\n";
|
||||||
}
|
}
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_week_of_month_dates {
|
sub get_week_of_month_dates {
|
||||||
my $start = shift; # datetime string
|
my $start = shift; # datetime string
|
||||||
my $end = shift; # datetime string
|
my $end = shift; # datetime string
|
||||||
my $duration = shift; # in minutes
|
my $duration = shift; # in minutes
|
||||||
my $week = shift; # every nth week of month
|
my $week = shift; # every nth week of month
|
||||||
my $weekday = shift; # weekday [1..7]
|
my $weekday = shift; # weekday [1..7]
|
||||||
my $frequency = shift; # every 1st,2nd,3th time
|
my $frequency = shift; # every 1st,2nd,3th time
|
||||||
|
|
||||||
return undef if $start eq '';
|
return undef if $start eq '';
|
||||||
return undef if $end eq '';
|
return undef if $end eq '';
|
||||||
return undef if $duration eq '';
|
return undef if $duration eq '';
|
||||||
return undef if $week eq '';
|
return undef if $week eq '';
|
||||||
return undef if $weekday eq '';
|
return undef if $weekday eq '';
|
||||||
return undef if $frequency eq '';
|
return undef if $frequency eq '';
|
||||||
return undef if $frequency == 0;
|
return undef if $frequency == 0;
|
||||||
|
|
||||||
my $start_dates = time::get_nth_weekday_in_month( $start, $end, $week, $weekday );
|
my $start_dates = time::get_nth_weekday_in_month( $start, $end, $week, $weekday );
|
||||||
|
|
||||||
my $results = [];
|
my $results = [];
|
||||||
|
|
||||||
my $c = -1;
|
my $c = -1;
|
||||||
for my $start_datetime (@$start_dates) {
|
for my $start_datetime (@$start_dates) {
|
||||||
$c++;
|
$c++;
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
next unless @start >= 6;
|
next unless @start >= 6;
|
||||||
next if ( ( $c % $frequency ) != 0 );
|
next if ( $c % $frequency ) != 0;
|
||||||
|
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$start[0], $start[1], $start[2], # start date
|
$start[0], $start[1], $start[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
my $end_datetime = time::array_to_datetime( \@end_datetime );
|
my $end_datetime = time::array_to_datetime( \@end_datetime );
|
||||||
|
|
||||||
push @$results,
|
push @$results,
|
||||||
{
|
{
|
||||||
start => $start_datetime,
|
start => $start_datetime,
|
||||||
end => $end_datetime
|
end => $end_datetime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add duration to a single date
|
#add duration to a single date
|
||||||
sub get_single_date {
|
sub get_single_date {
|
||||||
my $start_datetime = shift;
|
my $start_datetime = shift;
|
||||||
my $duration = shift;
|
my $duration = shift;
|
||||||
|
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
return unless @start >= 6;
|
return unless @start >= 6;
|
||||||
|
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$start[0], $start[1], $start[2], # start date
|
$start[0], $start[1], $start[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
my $date = {
|
my $date = {
|
||||||
start => $start_datetime,
|
start => $start_datetime,
|
||||||
end => time::array_to_datetime( \@end_datetime )
|
end => time::array_to_datetime( \@end_datetime )
|
||||||
};
|
};
|
||||||
return [$date];
|
return [$date];
|
||||||
}
|
}
|
||||||
|
|
||||||
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
|
#calculate all dates between start_datetime and end_date with duration(minutes) and frequency(days)
|
||||||
sub get_dates {
|
sub get_dates {
|
||||||
my $start_datetime = shift;
|
my $start_datetime = shift;
|
||||||
my $end_date = shift;
|
my $end_date = shift;
|
||||||
my $duration = shift; # in minutes
|
my $duration = shift; # in minutes
|
||||||
my $frequency = shift; # in days
|
my $frequency = shift; # in days
|
||||||
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
|
#print "start_datetime:$start_datetime end_date:$end_date duration:$duration frequency:$frequency\n";
|
||||||
|
|
||||||
my @start = @{ time::datetime_to_array($start_datetime) };
|
my @start = @{ time::datetime_to_array($start_datetime) };
|
||||||
return unless @start >= 6;
|
return unless @start >= 6;
|
||||||
my @start_date = ( $start[0], $start[1], $start[2] );
|
my @start_date = ( $start[0], $start[1], $start[2] );
|
||||||
my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] );
|
my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] );
|
||||||
|
|
||||||
#print STDERR "$start_datetime,$end_date,$duration,$frequency\n";
|
#print STDERR "$start_datetime,$end_date,$duration,$frequency\n";
|
||||||
|
|
||||||
#return on single date
|
#return on single date
|
||||||
my $date = {};
|
my $date = {};
|
||||||
$date->{start} = sprintf( "%04d-%02d-%02d", @start_date ) . ' ' . $start_time;
|
$date->{start} = sprintf( "%04d-%02d-%02d", @start_date ) . ' ' . $start_time;
|
||||||
return undef if $duration eq '';
|
return undef if $duration eq '';
|
||||||
|
|
||||||
return undef if ( ( $frequency eq '' ) || ( $end_date eq '' ) );
|
return undef if ( $frequency eq '' ) || ( $end_date eq '' );
|
||||||
|
|
||||||
#continue on recurring date
|
#continue on recurring date
|
||||||
my @end = @{ time::datetime_to_array($end_date) };
|
my @end = @{ time::datetime_to_array($end_date) };
|
||||||
return unless @end >= 3;
|
return unless @end >= 3;
|
||||||
my @end_date = ( $end[0], $end[1], $end[2] );
|
my @end_date = ( $end[0], $end[1], $end[2] );
|
||||||
|
|
||||||
my $today = time::time_to_date();
|
my $today = time::time_to_date();
|
||||||
my ( $year, $month, $day ) = split( /\-/, $today );
|
my ( $year, $month, $day ) = split( /\-/, $today );
|
||||||
|
|
||||||
#do not show dates one month back
|
#do not show dates one month back
|
||||||
my $not_before = sprintf( "%04d-%02d-%02d", Date::Calc::Add_Delta_Days( $year, $month, $day, -30 ) );
|
my $not_before = sprintf( "%04d-%02d-%02d", Date::Calc::Add_Delta_Days( $year, $month, $day, -30 ) );
|
||||||
|
|
||||||
my $dates = [];
|
my $dates = [];
|
||||||
return $dates if ( $end_date lt $today );
|
return $dates if ( $end_date lt $today );
|
||||||
return $dates if ( $frequency < 1 );
|
return $dates if ( $frequency < 1 );
|
||||||
|
|
||||||
my $j = Date::Calc::Delta_Days( @start_date, @end_date );
|
my $j = Date::Calc::Delta_Days( @start_date, @end_date );
|
||||||
my $c = 0;
|
my $c = 0;
|
||||||
for ( my $i = 0 ; $i <= $j ; $i += $frequency ) {
|
for ( my $i = 0 ; $i <= $j ; $i += $frequency ) {
|
||||||
my @date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i );
|
my @date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i );
|
||||||
my $date = {};
|
my $date = {};
|
||||||
$date->{start} = sprintf( "%04d-%02d-%02d", @date ) . ' ' . $start_time;
|
$date->{start} = sprintf( "%04d-%02d-%02d", @date ) . ' ' . $start_time;
|
||||||
|
|
||||||
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
my @end_datetime = Date::Calc::Add_Delta_DHMS(
|
||||||
$date[0], $date[1], $date[2], # start date
|
$date[0], $date[1], $date[2], # start date
|
||||||
$start[3], $start[4], $start[5], # start time
|
$start[3], $start[4], $start[5], # start time
|
||||||
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
0, 0, $duration, 0 # delta days, hours, minutes, seconds
|
||||||
);
|
);
|
||||||
$date->{end} = time::array_to_datetime( \@end_datetime );
|
$date->{end} = time::array_to_datetime( \@end_datetime );
|
||||||
|
|
||||||
last if ( $c > 200 );
|
last if ( $c > 200 );
|
||||||
$c++;
|
$c++;
|
||||||
|
|
||||||
next if $date->{end} lt $not_before;
|
next if $date->{end} lt $not_before;
|
||||||
push @$dates, $date;
|
push @$dates, $date;
|
||||||
|
|
||||||
}
|
}
|
||||||
return $dates;
|
return $dates;
|
||||||
}
|
}
|
||||||
|
|
||||||
#remove all work_dates for studio_id and schedule_id
|
#remove all work_dates for studio_id and schedule_id
|
||||||
sub delete {
|
sub delete {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
|
|
||||||
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->{schedule_id};
|
return undef unless defined $entry->{schedule_id};
|
||||||
|
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $query = qq{
|
my $query = qq{
|
||||||
delete
|
delete
|
||||||
from calcms_work_dates
|
from calcms_work_dates
|
||||||
where project_id=? and studio_id=? and schedule_id=?
|
where project_id=? and studio_id=? and schedule_id=?
|
||||||
};
|
};
|
||||||
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{schedule_id} ];
|
my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{schedule_id} ];
|
||||||
|
|
||||||
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
#print '<pre>$query'.$query.Dumper($bind_values).'</pre>';
|
||||||
return db::put( $dbh, $query, $bind_values );
|
return db::put( $dbh, $query, $bind_values );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
my $msg = shift;
|
my $msg = shift;
|
||||||
print "ERROR: $msg<br/>\n";
|
print "ERROR: $msg<br/>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#do not delete last line!
|
#do not delete last line!
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use warnings "all";
|
use warnings "all";
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use URI::Escape();
|
use URI::Escape();
|
||||||
use Encode();
|
use Encode();
|
||||||
@@ -32,30 +31,30 @@ my $r = shift;
|
|||||||
my $config = config::get('../config/config.cgi');
|
my $config = config::get('../config/config.cgi');
|
||||||
my $debug = $config->{system}->{debug};
|
my $debug = $config->{system}->{debug};
|
||||||
my ( $user, $expires ) = auth::get_user( $cgi, $config );
|
my ( $user, $expires ) = auth::get_user( $cgi, $config );
|
||||||
return if ( ( !defined $user ) || ( $user eq '' ) );
|
return if ( !defined $user ) || ( $user eq '' );
|
||||||
|
|
||||||
#print STDERR $params->{project_id}."\n";
|
#print STDERR $params->{project_id}."\n";
|
||||||
my $user_presets = uac::get_user_presets(
|
my $user_presets = uac::get_user_presets(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
studio_id => $params->{studio_id},
|
studio_id => $params->{studio_id},
|
||||||
user => $user
|
user => $user
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$params->{default_studio_id} = $user_presets->{studio_id};
|
$params->{default_studio_id} = $user_presets->{studio_id};
|
||||||
$params->{studio_id} = $params->{default_studio_id}
|
$params->{studio_id} = $params->{default_studio_id}
|
||||||
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
if ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
|
||||||
$params->{project_id} = $user_presets->{project_id}
|
$params->{project_id} = $user_presets->{project_id}
|
||||||
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
if ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
|
||||||
|
|
||||||
#print STDERR $params->{project_id}."\n";
|
#print STDERR $params->{project_id}."\n";
|
||||||
my $request = {
|
my $request = {
|
||||||
url => $ENV{QUERY_STRING} || '',
|
url => $ENV{QUERY_STRING} || '',
|
||||||
params => {
|
params => {
|
||||||
original => $params,
|
original => $params,
|
||||||
checked => check_params($params),
|
checked => check_params($params),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
$request = uac::prepare_request( $request, $user_presets );
|
$request = uac::prepare_request( $request, $user_presets );
|
||||||
|
|
||||||
@@ -76,170 +75,170 @@ print q{
|
|||||||
|
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{scan_series_events} == 1 ) {
|
unless ( $permissions->{scan_series_events} == 1 ) {
|
||||||
uac::permissions_denied('scan_series_events');
|
uac::permissions_denied('scan_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
assign_series( $config, $request ) if ( $params->{action} eq 'assign_series' );
|
assign_series( $config, $request ) if $params->{action} eq 'assign_series';
|
||||||
}
|
}
|
||||||
show_events( $config, $request );
|
show_events( $config, $request );
|
||||||
|
|
||||||
sub show_events {
|
sub show_events {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{assign_series_events} == 1 ) {
|
unless ( $permissions->{assign_series_events} == 1 ) {
|
||||||
uac::permissions_denied('assign_series_events');
|
uac::permissions_denied('assign_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $projects = project::get( $config, { project_id => $params->{project_id} } );
|
my $projects = project::get( $config, { project_id => $params->{project_id} } );
|
||||||
my $project = $projects->[0];
|
my $project = $projects->[0];
|
||||||
return unless ( @$projects == 1 );
|
return unless scalar @$projects == 1 ;
|
||||||
|
|
||||||
my $studios = studios::get( $config, { project_id => $params->{project_id}, studio_id => $params->{studio_id} } );
|
my $studios = studios::get( $config, { project_id => $params->{project_id}, studio_id => $params->{studio_id} } );
|
||||||
my $studio = $studios->[0];
|
my $studio = $studios->[0];
|
||||||
return unless ( @$studios == 1 );
|
return unless scalar @$studios == 1 ;
|
||||||
|
|
||||||
my $project_name = $project->{name};
|
my $project_name = $project->{name};
|
||||||
my $studio_name = $studio->{location};
|
my $studio_name = $studio->{location};
|
||||||
|
|
||||||
#get series_names
|
#get series_names
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $query = q{
|
my $query = q{
|
||||||
select project_id, studio_id, series_id, series_name, title
|
select project_id, studio_id, series_id, series_name, title
|
||||||
from calcms_series s, calcms_project_series ps
|
from calcms_series s, calcms_project_series ps
|
||||||
where s.id=ps.series_id
|
where s.id=ps.series_id
|
||||||
order by series_name, title
|
order by series_name, title
|
||||||
};
|
};
|
||||||
my $results = db::get( $dbh, $query );
|
my $results = db::get( $dbh, $query );
|
||||||
|
|
||||||
# get projects by id
|
# get projects by id
|
||||||
my $projects_by_id = {};
|
my $projects_by_id = {};
|
||||||
$projects = project::get($config);
|
$projects = project::get($config);
|
||||||
for my $project (@$projects) {
|
for my $project (@$projects) {
|
||||||
$projects_by_id->{ $project->{project_id} } = $project;
|
$projects_by_id->{ $project->{project_id} } = $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get studios by id
|
# get studios by id
|
||||||
my $studios_by_id = {};
|
my $studios_by_id = {};
|
||||||
$studios = studios::get($config);
|
$studios = studios::get($config);
|
||||||
for my $studio (@$studios) {
|
for my $studio (@$studios) {
|
||||||
$studios_by_id->{ $studio->{id} } = $studio;
|
$studios_by_id->{ $studio->{id} } = $studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add project and studio name to series
|
#add project and studio name to series
|
||||||
for my $result (@$results) {
|
for my $result (@$results) {
|
||||||
$result->{project_name} = $projects_by_id->{ $result->{project_id} }->{name};
|
$result->{project_name} = $projects_by_id->{ $result->{project_id} }->{name};
|
||||||
$result->{studio_name} = $studios_by_id->{ $result->{studio_id} }->{location};
|
$result->{studio_name} = $studios_by_id->{ $result->{studio_id} }->{location};
|
||||||
$result->{series_name} = 'Einzelsendung' if $result->{series_name} eq '_single_';
|
$result->{series_name} = 'Einzelsendung' if $result->{series_name} eq '_single_';
|
||||||
}
|
}
|
||||||
$params->{series} = $results;
|
$params->{series} = $results;
|
||||||
|
|
||||||
#fill template
|
#fill template
|
||||||
$params->{project_name} = $project_name;
|
$params->{project_name} = $project_name;
|
||||||
$params->{studio_name} = $studio_name;
|
$params->{studio_name} = $studio_name;
|
||||||
|
|
||||||
template::process( 'print', $params->{template}, $params );
|
template::process( 'print', $params->{template}, $params );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub assign_series {
|
sub assign_series {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{assign_series_events} == 1 ) {
|
unless ( $permissions->{assign_series_events} == 1 ) {
|
||||||
uac::permissions_denied('assign_series_events');
|
uac::permissions_denied('assign_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $attr ( 'project_id', 'studio_id', 'series_id' ) {
|
for my $attr ( 'project_id', 'studio_id', 'series_id' ) {
|
||||||
if ( defined $params->{$attr} ) {
|
if ( defined $params->{$attr} ) {
|
||||||
$entry->{$attr} = $params->{$attr};
|
$entry->{$attr} = $params->{$attr};
|
||||||
} else {
|
} else {
|
||||||
uac::print_error( $attr . ' not given!' );
|
uac::print_error( $attr . ' not given!' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
|
|
||||||
#check if series is assigned to project/studio
|
#check if series is assigned to project/studio
|
||||||
my $series = series::get(
|
my $series = series::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#print Dumper($series);
|
#print Dumper($series);
|
||||||
if ( @$series == 0 ) {
|
if ( @$series == 0 ) {
|
||||||
|
|
||||||
# assign series to project/studio
|
# assign series to project/studio
|
||||||
project::assign_series(
|
project::assign_series(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#print "assign\n";
|
#print "assign\n";
|
||||||
} else {
|
} else {
|
||||||
print STDERR
|
print STDERR
|
||||||
"event $entry->{event_id} already assigned to project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}\n";
|
"event $entry->{event_id} already assigned to project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}\n";
|
||||||
|
|
||||||
#print "is schon\n";
|
#print "is schon\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
uac::print_info("event successfully assigned to series");
|
uac::print_info("event successfully assigned to series");
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_params {
|
sub check_params {
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
|
|
||||||
my $checked = {};
|
my $checked = {};
|
||||||
|
|
||||||
my $debug = $params->{debug} || '';
|
my $debug = $params->{debug} || '';
|
||||||
if ( $debug =~ /([a-z\_\,]+)/ ) {
|
if ( $debug =~ /([a-z\_\,]+)/ ) {
|
||||||
$debug = $1;
|
$debug = $1;
|
||||||
}
|
}
|
||||||
$checked->{debug} = $debug;
|
$checked->{debug} = $debug;
|
||||||
|
|
||||||
#actions and roles
|
#actions and roles
|
||||||
$checked->{action} = '';
|
$checked->{action} = '';
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
if ( $params->{action} =~ /^(assign_series)$/ ) {
|
if ( $params->{action} =~ /^(assign_series)$/ ) {
|
||||||
$checked->{action} = $params->{action};
|
$checked->{action} = $params->{action};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#numeric values
|
#numeric values
|
||||||
$checked->{exclude} = 0;
|
$checked->{exclude} = 0;
|
||||||
for my $param ( 'id', 'project_id', 'studio_id', 'series_id' ) {
|
for my $param ( 'id', 'project_id', 'studio_id', 'series_id' ) {
|
||||||
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
||||||
$checked->{$param} = $params->{$param};
|
$checked->{$param} = $params->{$param};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $checked->{studio_id} ) {
|
if ( defined $checked->{studio_id} ) {
|
||||||
$checked->{default_studio_id} = $checked->{studio_id};
|
$checked->{default_studio_id} = $checked->{studio_id};
|
||||||
} else {
|
} else {
|
||||||
$checked->{studio_id} = -1;
|
$checked->{studio_id} = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$checked->{template} = template::check( $params->{template}, 'assign_series' );
|
$checked->{template} = template::check( $params->{template}, 'assign_series' );
|
||||||
|
|
||||||
return $checked;
|
return $checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
__DATA__
|
__DATA__
|
||||||
|
|||||||
@@ -36,26 +36,26 @@ return if ( ( !defined $user ) || ( $user eq '' ) );
|
|||||||
|
|
||||||
#print STDERR $params->{project_id}."\n";
|
#print STDERR $params->{project_id}."\n";
|
||||||
my $user_presets = uac::get_user_presets(
|
my $user_presets = uac::get_user_presets(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
studio_id => $params->{studio_id},
|
studio_id => $params->{studio_id},
|
||||||
user => $user
|
user => $user
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$params->{default_studio_id} = $user_presets->{studio_id};
|
$params->{default_studio_id} = $user_presets->{studio_id};
|
||||||
$params->{studio_id} = $params->{default_studio_id}
|
$params->{studio_id} = $params->{default_studio_id}
|
||||||
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
if ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
|
||||||
$params->{project_id} = $user_presets->{project_id}
|
$params->{project_id} = $user_presets->{project_id}
|
||||||
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
if ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' );
|
||||||
|
|
||||||
#print STDERR $params->{project_id}."\n";
|
#print STDERR $params->{project_id}."\n";
|
||||||
my $request = {
|
my $request = {
|
||||||
url => $ENV{QUERY_STRING} || '',
|
url => $ENV{QUERY_STRING} || '',
|
||||||
params => {
|
params => {
|
||||||
original => $params,
|
original => $params,
|
||||||
checked => check_params($params),
|
checked => check_params($params),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
$request = uac::prepare_request( $request, $user_presets );
|
$request = uac::prepare_request( $request, $user_presets );
|
||||||
|
|
||||||
@@ -76,86 +76,86 @@ print q{
|
|||||||
|
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{scan_series_events} == 1 ) {
|
unless ( $permissions->{scan_series_events} == 1 ) {
|
||||||
uac::permissions_denied('scan_series_events');
|
uac::permissions_denied('scan_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
assign_events( $config, $request ) if ( $params->{action} eq 'assign_events' );
|
assign_events( $config, $request ) if ( $params->{action} eq 'assign_events' );
|
||||||
}
|
}
|
||||||
show_events( $config, $request );
|
show_events( $config, $request );
|
||||||
|
|
||||||
sub show_events {
|
sub show_events {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{assign_series_events} == 1 ) {
|
unless ( $permissions->{assign_series_events} == 1 ) {
|
||||||
uac::permissions_denied('assign_series_events');
|
uac::permissions_denied('assign_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $projects = project::get( $config, { project_id => $params->{project_id} } );
|
my $projects = project::get( $config, { project_id => $params->{project_id} } );
|
||||||
my $project = $projects->[0];
|
my $project = $projects->[0];
|
||||||
|
|
||||||
#print STDERR Dumper($project);
|
#print STDERR Dumper($project);
|
||||||
return unless ( @$projects == 1 );
|
return unless ( @$projects == 1 );
|
||||||
|
|
||||||
my $studios = studios::get( $config, { project_id => $params->{project_id}, studio_id => $params->{studio_id} } );
|
my $studios = studios::get( $config, { project_id => $params->{project_id}, studio_id => $params->{studio_id} } );
|
||||||
my $studio = $studios->[0];
|
my $studio = $studios->[0];
|
||||||
|
|
||||||
#print STDERR Dumper($studio);
|
#print STDERR Dumper($studio);
|
||||||
return unless ( @$studios == 1 );
|
return unless ( @$studios == 1 );
|
||||||
|
|
||||||
my $project_name = $project->{name};
|
my $project_name = $project->{name};
|
||||||
my $studio_name = $studio->{location};
|
my $studio_name = $studio->{location};
|
||||||
|
|
||||||
#get series_names
|
#get series_names
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
my $query = q{
|
my $query = q{
|
||||||
select project_id, studio_id, series_id, series_name, title
|
select project_id, studio_id, series_id, series_name, title
|
||||||
from calcms_series s, calcms_project_series ps
|
from calcms_series s, calcms_project_series ps
|
||||||
where s.id=ps.series_id
|
where s.id=ps.series_id
|
||||||
order by series_name, title
|
order by series_name, title
|
||||||
};
|
};
|
||||||
my $results = db::get( $dbh, $query );
|
my $results = db::get( $dbh, $query );
|
||||||
|
|
||||||
# get projects by id
|
# get projects by id
|
||||||
my $projects_by_id = {};
|
my $projects_by_id = {};
|
||||||
$projects = project::get($config);
|
$projects = project::get($config);
|
||||||
for my $project (@$projects) {
|
for my $project (@$projects) {
|
||||||
$projects_by_id->{ $project->{project_id} } = $project;
|
$projects_by_id->{ $project->{project_id} } = $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
# get studios by id
|
# get studios by id
|
||||||
my $studios_by_id = {};
|
my $studios_by_id = {};
|
||||||
$studios = studios::get($config);
|
$studios = studios::get($config);
|
||||||
for my $studio (@$studios) {
|
for my $studio (@$studios) {
|
||||||
$studios_by_id->{ $studio->{id} } = $studio;
|
$studios_by_id->{ $studio->{id} } = $studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
#add project and studio name to series
|
#add project and studio name to series
|
||||||
for my $result (@$results) {
|
for my $result (@$results) {
|
||||||
$result->{project_name} = $projects_by_id->{ $result->{project_id} }->{name};
|
$result->{project_name} = $projects_by_id->{ $result->{project_id} }->{name};
|
||||||
$result->{studio_name} = $studios_by_id->{ $result->{studio_id} }->{location};
|
$result->{studio_name} = $studios_by_id->{ $result->{studio_id} }->{location};
|
||||||
$result->{series_name} = 'Einzelsendung' if $result->{series_name} eq '_single_';
|
$result->{series_name} = 'Einzelsendung' if $result->{series_name} eq '_single_';
|
||||||
}
|
}
|
||||||
$params->{series} = $results;
|
$params->{series} = $results;
|
||||||
|
|
||||||
# get events not assigned to series
|
# get events not assigned to series
|
||||||
my $conditions = [];
|
my $conditions = [];
|
||||||
my $bind_values = [];
|
my $bind_values = [];
|
||||||
if ( $project_name ne '' ) {
|
if ( $project_name ne '' ) {
|
||||||
push @$conditions, 'e.project=?';
|
push @$conditions, 'e.project=?';
|
||||||
push @$bind_values, $project_name;
|
push @$bind_values, $project_name;
|
||||||
}
|
}
|
||||||
if ( $studio_name ne '' ) {
|
if ( $studio_name ne '' ) {
|
||||||
push @$conditions, 'e.location=?';
|
push @$conditions, 'e.location=?';
|
||||||
push @$bind_values, $studio_name;
|
push @$bind_values, $studio_name;
|
||||||
}
|
}
|
||||||
$conditions = ' and ' . join( ' and ', @$conditions ) if ( @$conditions > 0 );
|
$conditions = ' and ' . join( ' and ', @$conditions ) if scalar(@$conditions) > 0;
|
||||||
$query = qq{
|
$query = qq{
|
||||||
select e.id, program, project, location, start, series_name, title, episode, rerun
|
select e.id, program, project, location, start, series_name, title, episode, rerun
|
||||||
from calcms_events e left join calcms_series_events se on se.event_id =e.id
|
from calcms_events e left join calcms_series_events se on se.event_id =e.id
|
||||||
where se.event_id is null
|
where se.event_id is null
|
||||||
@@ -163,252 +163,252 @@ sub show_events {
|
|||||||
order by series_name,title,start
|
order by series_name,title,start
|
||||||
limit 1000
|
limit 1000
|
||||||
};
|
};
|
||||||
print '<pre>' . Dumper($query) . Dumper($bind_values) . '</pre>';
|
print '<pre>' . Dumper($query) . Dumper($bind_values) . '</pre>';
|
||||||
$results = db::get( $dbh, $query, $bind_values );
|
$results = db::get( $dbh, $query, $bind_values );
|
||||||
|
|
||||||
# detect title and episode
|
# detect title and episode
|
||||||
for my $result (@$results) {
|
for my $result (@$results) {
|
||||||
$result->{rerun} .= '';
|
$result->{rerun} .= '';
|
||||||
if ( $result->{title} =~ /\#(\d+)([a-z])?\s*$/ ) {
|
if ( $result->{title} =~ /\#(\d+)([a-z])?\s*$/ ) {
|
||||||
$result->{episode} = $1 unless defined $result->{episode};
|
$result->{episode} = $1 unless defined $result->{episode};
|
||||||
$result->{rerun} = $2 || '' unless ( $result->{rerun} =~ /\d/ );
|
$result->{rerun} = $2 || '' unless ( $result->{rerun} =~ /\d/ );
|
||||||
$result->{title} =~ s/\#\d+[a-z]?\s*$//;
|
$result->{title} =~ s/\#\d+[a-z]?\s*$//;
|
||||||
$result->{title} =~ s/\s+$//;
|
$result->{title} =~ s/\s+$//;
|
||||||
}
|
}
|
||||||
my $a = time::datetime_to_array( $result->{start} );
|
my $a = time::datetime_to_array( $result->{start} );
|
||||||
|
|
||||||
#print STDERR "($a->[0],$a->[1],$a->[2])\n";
|
#print STDERR "($a->[0],$a->[1],$a->[2])\n";
|
||||||
$result->{weekday} = time::weekday( $a->[0], $a->[1], $a->[2] );
|
$result->{weekday} = time::weekday( $a->[0], $a->[1], $a->[2] );
|
||||||
$result->{weekday} = $time::names->{de}->{weekdays_abbr}->[ $result->{weekday} - 1 ];
|
$result->{weekday} = $time::names->{de}->{weekdays_abbr}->[ $result->{weekday} - 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
#fill template
|
#fill template
|
||||||
$params->{unassigned_events} = $results;
|
$params->{unassigned_events} = $results;
|
||||||
$params->{sum_events} = @$results;
|
$params->{sum_events} = @$results;
|
||||||
$params->{project_name} = $project_name;
|
$params->{project_name} = $project_name;
|
||||||
$params->{studio_name} = $studio_name;
|
$params->{studio_name} = $studio_name;
|
||||||
|
|
||||||
template::process( 'print', $params->{template}, $params );
|
template::process( 'print', $params->{template}, $params );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub assign_events {
|
sub assign_events {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{assign_series_events} == 1 ) {
|
unless ( $permissions->{assign_series_events} == 1 ) {
|
||||||
uac::permissions_denied('assign_series_events');
|
uac::permissions_denied('assign_series_events');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $entry = {};
|
my $entry = {};
|
||||||
for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_ids' ) {
|
for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_ids' ) {
|
||||||
if ( defined $params->{$attr} ) {
|
if ( defined $params->{$attr} ) {
|
||||||
$entry->{$attr} = $params->{$attr};
|
$entry->{$attr} = $params->{$attr};
|
||||||
} else {
|
} else {
|
||||||
uac::print_error( $attr . ' not given!' );
|
uac::print_error( $attr . ' not given!' );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
for my $event_id ( split( /[\,\s]+/, $params->{event_ids} ) ) {
|
for my $event_id ( split( /[\,\s]+/, $params->{event_ids} ) ) {
|
||||||
next unless $event_id =~ /^\d+/;
|
next unless $event_id =~ /^\d+/;
|
||||||
$entry->{event_id} = $event_id;
|
$entry->{event_id} = $event_id;
|
||||||
|
|
||||||
#get and parse event
|
#get and parse event
|
||||||
my $request2 = {
|
my $request2 = {
|
||||||
params => {
|
params => {
|
||||||
checked => events::check_params(
|
checked => events::check_params(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
event_id => $entry->{event_id},
|
event_id => $entry->{event_id},
|
||||||
template => 'no',
|
template => 'no',
|
||||||
limit => 1,
|
limit => 1,
|
||||||
archive => 'all',
|
archive => 'all',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
config => $request->{config},
|
config => $request->{config},
|
||||||
permissions => $request->{permissions}
|
permissions => $request->{permissions}
|
||||||
};
|
};
|
||||||
$request2->{params}->{checked}->{published} = 'all';
|
$request2->{params}->{checked}->{published} = 'all';
|
||||||
my $events = events::get( $config, $request2 );
|
my $events = events::get( $config, $request2 );
|
||||||
my $event = $events->[0];
|
my $event = $events->[0];
|
||||||
unless ( defined $event ) {
|
unless ( defined $event ) {
|
||||||
print STDERR
|
print STDERR
|
||||||
"event not found for project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}, event $entry->{event_id}\n";
|
"event not found for project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}, event $entry->{event_id}\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
print STDERR "'" . $event->{event_id} . "' '" . $event->{series_name} . "' '" . $event->{title} . "' '" . $event->{episode} . "'\n";
|
print STDERR "'" . $event->{event_id} . "' '" . $event->{series_name} . "' '" . $event->{title} . "' '" . $event->{episode} . "'\n";
|
||||||
|
|
||||||
#next;
|
#next;
|
||||||
|
|
||||||
#check if series is assigned to project/studio
|
#check if series is assigned to project/studio
|
||||||
my $series = series::get(
|
my $series = series::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( @$series == 0 ) {
|
if ( scalar(@$series) == 0 ) {
|
||||||
|
|
||||||
# assign series to project/studio
|
# assign series to project/studio
|
||||||
project::assign_series(
|
project::assign_series(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
print STDERR
|
print STDERR
|
||||||
"event $entry->{event_id} already asigned to project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}\n";
|
"event $entry->{event_id} already asigned to project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
#get series
|
#get series
|
||||||
$series = series::get(
|
$series = series::get(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( @$series == 1 ) {
|
if ( scalar(@$series) == 1 ) {
|
||||||
my $serie = $series->[0];
|
my $serie = $series->[0];
|
||||||
|
|
||||||
#set event's series name to value from series
|
#set event's series name to value from series
|
||||||
my $series_name = $serie->{series_name} || '';
|
my $series_name = $serie->{series_name} || '';
|
||||||
if ( $series_name ne '' ) {
|
if ( $series_name ne '' ) {
|
||||||
|
|
||||||
# prepend series_name from event to title on adding to single_events series
|
# prepend series_name from event to title on adding to single_events series
|
||||||
my $title = $event->{title};
|
my $title = $event->{title};
|
||||||
if ( $serie->{has_single_events} eq '1' ) {
|
if ( $serie->{has_single_events} eq '1' ) {
|
||||||
$title = $event->{series_name} . ' - ' . $title if $event->{series_name} ne '';
|
$title = $event->{series_name} . ' - ' . $title if $event->{series_name} ne '';
|
||||||
}
|
}
|
||||||
|
|
||||||
# save event content
|
# save event content
|
||||||
series_events::save_content(
|
series_events::save_content(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
id => $entry->{event_id}, #TODO: id=> event_id
|
id => $entry->{event_id}, #TODO: id=> event_id
|
||||||
series_name => $series_name,
|
series_name => $series_name,
|
||||||
title => $title,
|
title => $title,
|
||||||
episode => $event->{episode},
|
episode => $event->{episode},
|
||||||
rerun => $event->{rerun},
|
rerun => $event->{rerun},
|
||||||
modified_by => $params->{presets}->{user},
|
modified_by => $params->{presets}->{user},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
# add to history
|
# add to history
|
||||||
$event->{project_id} = $entry->{project_id};
|
$event->{project_id} = $entry->{project_id};
|
||||||
$event->{studio_id} = $entry->{studio_id};
|
$event->{studio_id} = $entry->{studio_id};
|
||||||
$event->{series_id} = $entry->{series_id};
|
$event->{series_id} = $entry->{series_id};
|
||||||
$event->{event_id} = $entry->{event_id};
|
$event->{event_id} = $entry->{event_id};
|
||||||
$event->{series_name} = $series_name;
|
$event->{series_name} = $series_name;
|
||||||
$event->{title} = $title;
|
$event->{title} = $title;
|
||||||
$event->{user} = $params->{presets}->{user};
|
$event->{user} = $params->{presets}->{user};
|
||||||
event_history::insert( $config, $event );
|
event_history::insert( $config, $event );
|
||||||
|
|
||||||
# print STDERR "ok\n";
|
# print STDERR "ok\n";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print STDERR "no series title found for studio $entry->{studio_id} series $entry->{series_id}, event $entry->{event_id}\n";
|
print STDERR "no series title found for studio $entry->{studio_id} series $entry->{series_id}, event $entry->{event_id}\n";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
#assign event
|
#assign event
|
||||||
my $result = series::assign_event(
|
my $result = series::assign_event(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
project_id => $entry->{project_id},
|
project_id => $entry->{project_id},
|
||||||
studio_id => $entry->{studio_id},
|
studio_id => $entry->{studio_id},
|
||||||
series_id => $entry->{series_id},
|
series_id => $entry->{series_id},
|
||||||
event_id => $entry->{event_id},
|
event_id => $entry->{event_id},
|
||||||
manual => 1
|
manual => 1
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
unless ( defined $result ) {
|
unless ( defined $result ) {
|
||||||
uac::print_error("error on assigning event to series");
|
uac::print_error("error on assigning event to series");
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
uac::print_info("event successfully assigned to series");
|
uac::print_info("event successfully assigned to series");
|
||||||
|
|
||||||
#$params->{getBack}=1;
|
#$params->{getBack}=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_params {
|
sub check_params {
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
|
|
||||||
my $checked = {};
|
my $checked = {};
|
||||||
|
|
||||||
my $debug = $params->{debug} || '';
|
my $debug = $params->{debug} || '';
|
||||||
if ( $debug =~ /([a-z\_\,]+)/ ) {
|
if ( $debug =~ /([a-z\_\,]+)/ ) {
|
||||||
$debug = $1;
|
$debug = $1;
|
||||||
}
|
}
|
||||||
$checked->{debug} = $debug;
|
$checked->{debug} = $debug;
|
||||||
|
|
||||||
#actions and roles
|
#actions and roles
|
||||||
$checked->{action} = '';
|
$checked->{action} = '';
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
if ( $params->{action} =~ /^(assign_events)$/ ) {
|
if ( $params->{action} =~ /^(assign_events)$/ ) {
|
||||||
$checked->{action} = $params->{action};
|
$checked->{action} = $params->{action};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#numeric values
|
#numeric values
|
||||||
$checked->{exclude} = 0;
|
$checked->{exclude} = 0;
|
||||||
for my $param ( 'id', 'project_id', 'studio_id', 'series_id', 'event_id' ) {
|
for my $param ( 'id', 'project_id', 'studio_id', 'series_id', 'event_id' ) {
|
||||||
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
||||||
$checked->{$param} = $params->{$param};
|
$checked->{$param} = $params->{$param};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $param ('event_ids') {
|
for my $param ('event_ids') {
|
||||||
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[\d,]+$/ ) ) {
|
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^[\d,]+$/ ) ) {
|
||||||
$checked->{$param} = $params->{$param};
|
$checked->{$param} = $params->{$param};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined $checked->{studio_id} ) {
|
if ( defined $checked->{studio_id} ) {
|
||||||
$checked->{default_studio_id} = $checked->{studio_id};
|
$checked->{default_studio_id} = $checked->{studio_id};
|
||||||
} else {
|
} else {
|
||||||
$checked->{studio_id} = -1;
|
$checked->{studio_id} = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$checked->{template} = template::check( $params->{template}, 'assignments' );
|
$checked->{template} = template::check( $params->{template}, 'assignments' );
|
||||||
|
|
||||||
if ( ( defined $checked->{action} ) && ( $checked->{action} eq 'save_schedule' ) ) {
|
if ( ( defined $checked->{action} ) && ( $checked->{action} eq 'save_schedule' ) ) {
|
||||||
|
|
||||||
#set defaults
|
#set defaults
|
||||||
$checked->{create_events} = 0;
|
$checked->{create_events} = 0;
|
||||||
$checked->{publish_events} = 0;
|
$checked->{publish_events} = 0;
|
||||||
}
|
}
|
||||||
for my $param ( 'frequency', 'duration', 'default_duration', 'create_events', 'publish_events', 'live', 'count_episodes' ) {
|
for my $param ( 'frequency', 'duration', 'default_duration', 'create_events', 'publish_events', 'live', 'count_episodes' ) {
|
||||||
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /(\d+)/ ) ) {
|
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /(\d+)/ ) ) {
|
||||||
$checked->{$param} = $1;
|
$checked->{$param} = $1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#scalars
|
#scalars
|
||||||
for my $param ( 'search', 'from', 'till' ) {
|
for my $param ( 'search', 'from', 'till' ) {
|
||||||
if ( defined $params->{$param} ) {
|
if ( defined $params->{$param} ) {
|
||||||
$checked->{$param} = $params->{$param};
|
$checked->{$param} = $params->{$param};
|
||||||
$checked->{$param} =~ s/^\s+//g;
|
$checked->{$param} =~ s/^\s+//g;
|
||||||
$checked->{$param} =~ s/\s+$//g;
|
$checked->{$param} =~ s/\s+$//g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $checked;
|
return $checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
__DATA__
|
__DATA__
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use warnings;
|
|||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use CGI::Simple ();
|
use CGI::Simple ();
|
||||||
use ModPerl::Util ();
|
use ModPerl::Util ();
|
||||||
use Date::Calc();
|
use Date::Calc();
|
||||||
use Time::Local();
|
use Time::Local();
|
||||||
@@ -141,8 +141,9 @@ sub uploadRecording {
|
|||||||
#print STDERR Dumper($fh)."<br>";
|
#print STDERR Dumper($fh)."<br>";
|
||||||
my $fileInfo = uploadFile( $config, $fh, $params->{event_id}, $user, $params->{upload} );
|
my $fileInfo = uploadFile( $config, $fh, $params->{event_id}, $user, $params->{upload} );
|
||||||
$params->{error} .= $fileInfo->{error} if defined $fileInfo->{error};
|
$params->{error} .= $fileInfo->{error} if defined $fileInfo->{error};
|
||||||
$params->{path} = $fileInfo->{path};
|
$params->{path} = $fileInfo->{path};
|
||||||
$params->{size} = $fileInfo->{size};
|
$params->{size} = $fileInfo->{size};
|
||||||
|
|
||||||
#$params->{duration} = $fileInfo->{duration};
|
#$params->{duration} = $fileInfo->{duration};
|
||||||
$params = updateDatabase( $config, $params, $user ) if $params->{error} eq '';
|
$params = updateDatabase( $config, $params, $user ) if $params->{error} eq '';
|
||||||
} else {
|
} else {
|
||||||
@@ -292,18 +293,19 @@ sub showAudioRecordings {
|
|||||||
event_id => $params->{event_id},
|
event_id => $params->{event_id},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#print Dumper($audioRecordings);
|
#print Dumper($audioRecordings);
|
||||||
for my $recording (@$audioRecordings) {
|
for my $recording (@$audioRecordings) {
|
||||||
$recording->{size} =~ s/(\d)(\d\d\d)$/$1\.$2/g;
|
$recording->{size} =~ s/(\d)(\d\d\d)$/$1\.$2/g;
|
||||||
$recording->{size} =~ s/(\d)(\d\d\d\.\d\d\d)$/$1\.$2/g;
|
$recording->{size} =~ s/(\d)(\d\d\d\.\d\d\d)$/$1\.$2/g;
|
||||||
|
|
||||||
$recording->{processed} = $recording->{processed} ? 'yes' : 'no';
|
$recording->{processed} = $recording->{processed} ? 'yes' : 'no';
|
||||||
$recording->{mastered} = $recording->{mastered} ? 'yes' : 'no';
|
$recording->{mastered} = $recording->{mastered} ? 'yes' : 'no';
|
||||||
|
|
||||||
$recording->{eventDuration} = getDuration( $recording->{eventDuration} );
|
$recording->{eventDuration} = getDuration( $recording->{eventDuration} );
|
||||||
$recording->{audioDuration} = getDuration( $recording->{audioDuration} );
|
$recording->{audioDuration} = getDuration( $recording->{audioDuration} );
|
||||||
|
|
||||||
$recording->{rmsLeft} ||= '-';
|
$recording->{rmsLeft} ||= '-';
|
||||||
$recording->{rmsRight} ||= '-';
|
$recording->{rmsRight} ||= '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,19 +325,19 @@ sub showAudioRecordings {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub getDuration{
|
sub getDuration {
|
||||||
my $duration=shift;
|
my $duration = shift;
|
||||||
my $hour = int($duration / 3600);
|
my $hour = int( $duration / 3600 );
|
||||||
$duration -= $hour * 3600;
|
$duration -= $hour * 3600;
|
||||||
|
|
||||||
my $minutes = int($duration / 60);
|
my $minutes = int( $duration / 60 );
|
||||||
$duration -= $minutes * 60;
|
$duration -= $minutes * 60;
|
||||||
|
|
||||||
my $seconds = int($duration);
|
my $seconds = int($duration);
|
||||||
$duration -= $seconds;
|
$duration -= $seconds;
|
||||||
|
|
||||||
my $milli= int(100 * $duration);
|
my $milli = int( 100 * $duration );
|
||||||
return sprintf("%02d:%02d:%02d.%02d",$hour, $minutes, $seconds, $milli);
|
return sprintf( "%02d:%02d:%02d.%02d", $hour, $minutes, $seconds, $milli );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub uploadFile {
|
sub uploadFile {
|
||||||
@@ -391,7 +393,7 @@ sub updateDatabase {
|
|||||||
my $params = shift;
|
my $params = shift;
|
||||||
my $user = shift;
|
my $user = shift;
|
||||||
|
|
||||||
my $eventDuration = getEventDuration($config, $params->{event_id});
|
my $eventDuration = getEventDuration( $config, $params->{event_id} );
|
||||||
|
|
||||||
my $entry = {
|
my $entry = {
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
@@ -402,6 +404,7 @@ sub updateDatabase {
|
|||||||
created_by => $user,
|
created_by => $user,
|
||||||
eventDuration => $eventDuration
|
eventDuration => $eventDuration
|
||||||
};
|
};
|
||||||
|
|
||||||
#print STDERR "updateDatabase:" . Dumper($entry);
|
#print STDERR "updateDatabase:" . Dumper($entry);
|
||||||
|
|
||||||
#connect
|
#connect
|
||||||
@@ -425,14 +428,14 @@ sub updateDatabase {
|
|||||||
$params->{id} = $entry->{id};
|
$params->{id} = $entry->{id};
|
||||||
} else {
|
} else {
|
||||||
print STDERR "insert\n";
|
print STDERR "insert\n";
|
||||||
$entry->{created_by} = $user;
|
$entry->{created_by} = $user;
|
||||||
$entry->{processed} = 0;
|
$entry->{processed} = 0;
|
||||||
$entry->{mastered} = 0;
|
$entry->{mastered} = 0;
|
||||||
$entry->{rmsLeft} = 0.0;
|
$entry->{rmsLeft} = 0.0;
|
||||||
$entry->{rmsRight} = 0.0;
|
$entry->{rmsRight} = 0.0;
|
||||||
$entry->{audioDuration} = 0.0;
|
$entry->{audioDuration} = 0.0;
|
||||||
$entry->{modified_at} = time();
|
$entry->{modified_at} = time();
|
||||||
$params->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
$params->{id} = audio_recordings::insert( $config, $dbh, $entry );
|
||||||
}
|
}
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
$params->{action_result} = 'done!';
|
$params->{action_result} = 'done!';
|
||||||
@@ -504,15 +507,15 @@ sub checkFilename {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# return event duration in seconds
|
# return event duration in seconds
|
||||||
sub getEventDuration{
|
sub getEventDuration {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $eventId = shift;
|
my $eventId = shift;
|
||||||
|
|
||||||
|
if ( $eventId < 1 ) {
|
||||||
|
print STDERR "invalid eventId $eventId\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($eventId<1){
|
|
||||||
print STDERR "invalid eventId $eventId\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
my $request = {
|
my $request = {
|
||||||
params => {
|
params => {
|
||||||
checked => events::check_params(
|
checked => events::check_params(
|
||||||
@@ -524,16 +527,16 @@ sub getEventDuration{
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
config => $config
|
config => $config
|
||||||
};
|
};
|
||||||
$request->{params}->{checked}->{published}='all';
|
$request->{params}->{checked}->{published} = 'all';
|
||||||
my $events = events::get( $config, $request );
|
my $events = events::get( $config, $request );
|
||||||
if (scalar @$events == 0){
|
if ( scalar @$events == 0 ) {
|
||||||
print STDERR "getEventDuration: no event found with event_id=$eventId\n";
|
print STDERR "getEventDuration: no event found with event_id=$eventId\n";
|
||||||
}
|
}
|
||||||
my $event = $events->[0];
|
my $event = $events->[0];
|
||||||
my $duration = time::get_duration_seconds( $event->{start}, $event->{end}, $config->{date}->{time_zone} );
|
my $duration = time::get_duration_seconds( $event->{start}, $event->{end}, $config->{date}->{time_zone} );
|
||||||
return $duration;
|
return $duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_params {
|
sub check_params {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -35,12 +35,12 @@ my ( $user, $expires ) = auth::get_user( $cgi, $config );
|
|||||||
return if ( ( !defined $user ) || ( $user eq '' ) );
|
return if ( ( !defined $user ) || ( $user eq '' ) );
|
||||||
|
|
||||||
my $user_presets = uac::get_user_presets(
|
my $user_presets = uac::get_user_presets(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
user => $user,
|
user => $user,
|
||||||
project_id => $params->{project_id},
|
project_id => $params->{project_id},
|
||||||
studio_id => $params->{studio_id}
|
studio_id => $params->{studio_id}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
$params->{default_studio_id} = $user_presets->{studio_id};
|
$params->{default_studio_id} = $user_presets->{studio_id};
|
||||||
$params->{studio_id} = $params->{default_studio_id}
|
$params->{studio_id} = $params->{default_studio_id}
|
||||||
@@ -49,11 +49,11 @@ $params->{project_id} = $user_presets->{project_id}
|
|||||||
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
if ( ( !( defined $params->{action} ) ) || ( $params->{action} eq '' ) || ( $params->{action} eq 'login' ) );
|
||||||
|
|
||||||
my $request = {
|
my $request = {
|
||||||
url => $ENV{QUERY_STRING} || '',
|
url => $ENV{QUERY_STRING} || '',
|
||||||
params => {
|
params => {
|
||||||
original => $params,
|
original => $params,
|
||||||
checked => check_params($params),
|
checked => check_params($params),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#set user at params->presets->user
|
#set user at params->presets->user
|
||||||
@@ -64,261 +64,261 @@ $params = $request->{params}->{checked};
|
|||||||
#print Dumper($params);
|
#print Dumper($params);
|
||||||
#show header
|
#show header
|
||||||
if ( ( params::isJson() ) || ( defined $params->{action} ) ) {
|
if ( ( params::isJson() ) || ( defined $params->{action} ) ) {
|
||||||
print "Content-Type:text/html; charset=utf-8;\n\n";
|
print "Content-Type:text/html; charset=utf-8;\n\n";
|
||||||
} else {
|
} else {
|
||||||
my $headerParams = uac::set_template_permissions( $request->{permissions}, $params );
|
my $headerParams = uac::set_template_permissions( $request->{permissions}, $params );
|
||||||
$headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } );
|
$headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } );
|
||||||
template::process( 'print', template::check('default.html'), $headerParams );
|
template::process( 'print', template::check('default.html'), $headerParams );
|
||||||
print q{
|
print q{
|
||||||
<script src="js/datetime.js" type="text/javascript"></script>
|
<script src="js/datetime.js" type="text/javascript"></script>
|
||||||
} unless (params::isJson);
|
} unless (params::isJson);
|
||||||
}
|
}
|
||||||
return unless defined uac::check( $config, $params, $user_presets );
|
return unless defined uac::check( $config, $params, $user_presets );
|
||||||
|
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
if ( $params->{action} eq 'get_json' ) {
|
if ( $params->{action} eq 'get_json' ) {
|
||||||
getJson( $config, $request );
|
getJson( $config, $request );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( $params->{action} eq 'setLock' ) {
|
if ( $params->{action} eq 'setLock' ) {
|
||||||
setLock( $config, $request );
|
setLock( $config, $request );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( $params->{action} eq 'setRead' ) {
|
if ( $params->{action} eq 'setRead' ) {
|
||||||
setRead( $config, $request );
|
setRead( $config, $request );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
showComments( $config, $request );
|
showComments( $config, $request );
|
||||||
|
|
||||||
sub showComments {
|
sub showComments {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
unless ( $permissions->{read_comment} == 1 ) {
|
unless ( $permissions->{read_comment} == 1 ) {
|
||||||
uac::permissions_denied('read_comment');
|
uac::permissions_denied('read_comment');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $attr ( 'project_id', 'studio_id' ) {
|
for my $attr ( 'project_id', 'studio_id' ) {
|
||||||
unless ( defined $params->{$attr} ) {
|
unless ( defined $params->{$attr} ) {
|
||||||
uac::print_error( "missing " . $attr . " to show comment" );
|
uac::print_error( "missing " . $attr . " to show comment" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 0;
|
$config->{access}->{write} = 0;
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $comment = $params->{comment};
|
my $comment = $params->{comment};
|
||||||
my $template_parameters = {};
|
my $template_parameters = {};
|
||||||
|
|
||||||
#my $nodes={};
|
#my $nodes={};
|
||||||
#my $sorted_nodes=[];
|
#my $sorted_nodes=[];
|
||||||
|
|
||||||
my $results = [];
|
my $results = [];
|
||||||
if ( $params->{search} ne '' ) {
|
if ( $params->{search} ne '' ) {
|
||||||
$params->{comment}->{search} = $params->{search};
|
$params->{comment}->{search} = $params->{search};
|
||||||
$results = comments::get_by_event( $dbh, $config, $request );
|
$results = comments::get_by_event( $dbh, $config, $request );
|
||||||
} elsif ( $comment->{event_id} ne '' ) {
|
} elsif ( $comment->{event_id} ne '' ) {
|
||||||
$results = comments::get_by_event( $dbh, $config, $request );
|
$results = comments::get_by_event( $dbh, $config, $request );
|
||||||
} else {
|
} else {
|
||||||
$results = comments::get_by_time( $dbh, $config, $comment );
|
$results = comments::get_by_time( $dbh, $config, $comment );
|
||||||
}
|
}
|
||||||
|
|
||||||
my $events = [];
|
my $events = [];
|
||||||
my $comment_count = 0;
|
my $comment_count = 0;
|
||||||
if ( @$results > 0 ) {
|
if ( scalar(@$results) > 0 ) {
|
||||||
my $comments = modify_comments( $request, $results );
|
my $comments = modify_comments( $request, $results );
|
||||||
|
|
||||||
$comments = comments::sort( $config, $comments );
|
$comments = comments::sort( $config, $comments );
|
||||||
|
|
||||||
$events = comments::get_events( $dbh, $config, $request, $comments );
|
$events = comments::get_events( $dbh, $config, $request, $comments );
|
||||||
my $language = $config::config->{date}->{language} || 'en';
|
my $language = $config::config->{date}->{language} || 'en';
|
||||||
for my $event (@$events) {
|
for my $event (@$events) {
|
||||||
$event->{start} = time::date_time_format( $event->{start}, $language );
|
$event->{start} = time::date_time_format( $event->{start}, $language );
|
||||||
$comment_count += $event->{comment_count} if ( defined $event->{comment_count} );
|
$comment_count += $event->{comment_count} if ( defined $event->{comment_count} );
|
||||||
$event->{cache_base_url} = $config::config->{cache}->{base_url};
|
$event->{cache_base_url} = $config::config->{cache}->{base_url};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for my $param (%$comment) {
|
for my $param (%$comment) {
|
||||||
$template_parameters->{$param} = $comment->{$param};
|
$template_parameters->{$param} = $comment->{$param};
|
||||||
}
|
}
|
||||||
|
|
||||||
$template_parameters->{search} = markup::fix_utf8( $request->{params}->{original}->{search} );
|
$template_parameters->{search} = markup::fix_utf8( $request->{params}->{original}->{search} );
|
||||||
$template_parameters->{events} = $events;
|
$template_parameters->{events} = $events;
|
||||||
$template_parameters->{debug} = $config->{system}->{debug};
|
$template_parameters->{debug} = $config->{system}->{debug};
|
||||||
$template_parameters->{event_count} = @$events + 0;
|
$template_parameters->{event_count} = scalar(@$events);
|
||||||
$template_parameters->{comment_count} = $comment_count;
|
$template_parameters->{comment_count} = $comment_count;
|
||||||
$template_parameters->{is_empty} = 1 if ( @$events == 0 );
|
$template_parameters->{is_empty} = 1 if scalar @$events == 0;
|
||||||
$template_parameters->{projects} = project::get_with_dates($config);
|
$template_parameters->{projects} = project::get_with_dates($config);
|
||||||
$template_parameters->{controllers} = $config->{controllers};
|
$template_parameters->{controllers} = $config->{controllers};
|
||||||
$template_parameters->{allow} = $permissions;
|
$template_parameters->{allow} = $permissions;
|
||||||
$template_parameters->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'comment' } );
|
$template_parameters->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'comment' } );
|
||||||
|
|
||||||
#fill and output template
|
#fill and output template
|
||||||
template::process( 'print', $params->{template}, $template_parameters );
|
template::process( 'print', $params->{template}, $template_parameters );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub modify_comments {
|
sub modify_comments {
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
my $results = shift;
|
my $results = shift;
|
||||||
|
|
||||||
my $language = $config::config->{date}->{language} || 'en';
|
my $language = $config::config->{date}->{language} || 'en';
|
||||||
for my $result (@$results) {
|
for my $result (@$results) {
|
||||||
$result->{start_date_name} = time::date_format( $result->{created_at}, $language );
|
$result->{start_date_name} = time::date_format( $result->{created_at}, $language );
|
||||||
$result->{start_time_name} = time::time_format( $result->{created_at} );
|
$result->{start_time_name} = time::time_format( $result->{created_at} );
|
||||||
$result->{ $result->{lock_status} } = 1;
|
$result->{ $result->{lock_status} } = 1;
|
||||||
$result->{ $result->{news_status} } = 1;
|
$result->{ $result->{news_status} } = 1;
|
||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub setLock {
|
sub setLock {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
|
|
||||||
unless ( $permissions->{update_comment_status_lock} == 1 ) {
|
unless ( $permissions->{update_comment_status_lock} == 1 ) {
|
||||||
uac::permissions_denied('update_comment_status_lock');
|
uac::permissions_denied('update_comment_status_lock');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $comment = $params->{comment};
|
my $comment = $params->{comment};
|
||||||
$comment->{id} = $comment->{comment_id};
|
$comment->{id} = $comment->{comment_id};
|
||||||
if ( $comment->{id} eq '' ) {
|
if ( $comment->{id} eq '' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#todo change set_news_status to lock_status in comment module
|
#todo change set_news_status to lock_status in comment module
|
||||||
$comment->{set_lock_status} = $comment->{lockStatus};
|
$comment->{set_lock_status} = $comment->{lockStatus};
|
||||||
$comment->{set_lock_status} = 'blocked' unless $comment->{set_lock_status} eq 'show';
|
$comment->{set_lock_status} = 'blocked' unless $comment->{set_lock_status} eq 'show';
|
||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
print STDERR "setLock " . Dumper($comment);
|
print STDERR "setLock " . Dumper($comment);
|
||||||
comments::set_lock_status( $dbh, $config, $comment );
|
comments::set_lock_status( $dbh, $config, $comment );
|
||||||
print "done\n";
|
print "done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub setRead {
|
sub setRead {
|
||||||
my $config = shift;
|
my $config = shift;
|
||||||
my $request = shift;
|
my $request = shift;
|
||||||
|
|
||||||
my $params = $request->{params}->{checked};
|
my $params = $request->{params}->{checked};
|
||||||
my $permissions = $request->{permissions};
|
my $permissions = $request->{permissions};
|
||||||
|
|
||||||
unless ( $permissions->{update_comment_status_read} == 1 ) {
|
unless ( $permissions->{update_comment_status_read} == 1 ) {
|
||||||
uac::permissions_denied('update_comment_status_read');
|
uac::permissions_denied('update_comment_status_read');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$config->{access}->{write} = 1;
|
$config->{access}->{write} = 1;
|
||||||
my $dbh = db::connect($config);
|
my $dbh = db::connect($config);
|
||||||
|
|
||||||
my $comment = $params->{comment};
|
my $comment = $params->{comment};
|
||||||
$comment->{id} = $comment->{comment_id};
|
$comment->{id} = $comment->{comment_id};
|
||||||
if ( $comment->{id} eq '' ) {
|
if ( $comment->{id} eq '' ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#todo change set_news_status to read_status in comment module
|
#todo change set_news_status to read_status in comment module
|
||||||
$comment->{set_news_status} = $comment->{readStatus};
|
$comment->{set_news_status} = $comment->{readStatus};
|
||||||
$comment->{set_news_status} = 'received' unless $comment->{set_news_status} eq 'unread';
|
$comment->{set_news_status} = 'received' unless $comment->{set_news_status} eq 'unread';
|
||||||
|
|
||||||
print STDERR "setRead " . Dumper($comment);
|
print STDERR "setRead " . Dumper($comment);
|
||||||
comments::set_news_status( $dbh, $config, $comment );
|
comments::set_news_status( $dbh, $config, $comment );
|
||||||
print "done\n";
|
print "done\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_params {
|
sub check_params {
|
||||||
my $params = shift;
|
my $params = shift;
|
||||||
|
|
||||||
my $checked = {};
|
my $checked = {};
|
||||||
|
|
||||||
#actions
|
#actions
|
||||||
|
|
||||||
if ( defined $params->{action} ) {
|
if ( defined $params->{action} ) {
|
||||||
if ( $params->{action} =~ /^(setLock|setRead|showComment)$/ ) {
|
if ( $params->{action} =~ /^(setLock|setRead|showComment)$/ ) {
|
||||||
$checked->{action} = $params->{action};
|
$checked->{action} = $params->{action};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#template
|
#template
|
||||||
my $template = '';
|
my $template = '';
|
||||||
if ( defined $checked->{action} ) {
|
if ( defined $checked->{action} ) {
|
||||||
$template = template::check( $params->{template}, 'edit_comment' ) if $checked->{action} eq 'showComment';
|
$template = template::check( $params->{template}, 'edit_comment' ) if $checked->{action} eq 'showComment';
|
||||||
} else {
|
} else {
|
||||||
$template = template::check( $params->{template}, 'comments' );
|
$template = template::check( $params->{template}, 'comments' );
|
||||||
}
|
}
|
||||||
$checked->{template} = $template;
|
$checked->{template} = $template;
|
||||||
|
|
||||||
#numeric values
|
#numeric values
|
||||||
for my $param ( 'project_id', 'studio_id', 'default_studio_id' ) {
|
for my $param ( 'project_id', 'studio_id', 'default_studio_id' ) {
|
||||||
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) {
|
||||||
$checked->{$param} = $params->{$param};
|
$checked->{$param} = $params->{$param};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( defined $checked->{studio_id} ) {
|
if ( defined $checked->{studio_id} ) {
|
||||||
$checked->{default_studio_id} = $checked->{studio_id};
|
$checked->{default_studio_id} = $checked->{studio_id};
|
||||||
} else {
|
} else {
|
||||||
$checked->{studio_id} = -1;
|
$checked->{studio_id} = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $comment = {};
|
my $comment = {};
|
||||||
|
|
||||||
for my $key ('readStatus') {
|
for my $key ('readStatus') {
|
||||||
my $value = $params->{$key};
|
my $value = $params->{$key};
|
||||||
$comment->{$key} = $value if ( defined $value ) && ( $value =~ /^(received|unread)$/ );
|
$comment->{$key} = $value if ( defined $value ) && ( $value =~ /^(received|unread)$/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
for my $key ('lockStatus') {
|
for my $key ('lockStatus') {
|
||||||
my $value = $params->{$key};
|
my $value = $params->{$key};
|
||||||
$comment->{$key} = $value if ( defined $value ) && ( $value =~ /^(blocked|show)$/ );
|
$comment->{$key} = $value if ( defined $value ) && ( $value =~ /^(blocked|show)$/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
$comment->{event_start} = time::check_date( $params->{event_start} ) || '';
|
$comment->{event_start} = time::check_date( $params->{event_start} ) || '';
|
||||||
$comment->{from} = time::check_date( $params->{from} ) || '';
|
$comment->{from} = time::check_date( $params->{from} ) || '';
|
||||||
$comment->{till} = time::check_date( $params->{till} ) || '';
|
$comment->{till} = time::check_date( $params->{till} ) || '';
|
||||||
|
|
||||||
my $event_id = $params->{event_id} || '';
|
my $event_id = $params->{event_id} || '';
|
||||||
if ( $event_id =~ /^(\d+)$/ ) {
|
if ( $event_id =~ /^(\d+)$/ ) {
|
||||||
$comment->{event_id} = $1;
|
$comment->{event_id} = $1;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
# error('invalid event_id');
|
# error('invalid event_id');
|
||||||
}
|
}
|
||||||
$comment->{event_id} = '' unless defined $comment->{event_id};
|
$comment->{event_id} = '' unless defined $comment->{event_id};
|
||||||
|
|
||||||
my $id = $params->{comment_id} || '';
|
my $id = $params->{comment_id} || '';
|
||||||
if ( $id =~ /^(\d+)$/ ) {
|
if ( $id =~ /^(\d+)$/ ) {
|
||||||
$comment->{comment_id} = $1;
|
$comment->{comment_id} = $1;
|
||||||
}
|
}
|
||||||
$comment->{comment_id} = '' unless defined $comment->{comment_id};
|
$comment->{comment_id} = '' unless defined $comment->{comment_id};
|
||||||
|
|
||||||
my $age = $params->{age} || '';
|
my $age = $params->{age} || '';
|
||||||
if ( $age =~ /^(\d+)$/ ) {
|
if ( $age =~ /^(\d+)$/ ) {
|
||||||
$comment->{age} = $1;
|
$comment->{age} = $1;
|
||||||
}
|
}
|
||||||
$comment->{age} = '365' unless defined $comment->{age};
|
$comment->{age} = '365' unless defined $comment->{age};
|
||||||
|
|
||||||
my $search = $params->{search} || '';
|
my $search = $params->{search} || '';
|
||||||
if ( ( defined $search ) && ( $search ne '' ) ) {
|
if ( ( defined $search ) && ( $search ne '' ) ) {
|
||||||
$search = substr( $search, 0, 100 );
|
$search = substr( $search, 0, 100 );
|
||||||
$search =~ s/^\s+//gi;
|
$search =~ s/^\s+//gi;
|
||||||
$search =~ s/\s+$//gi;
|
$search =~ s/\s+$//gi;
|
||||||
$search =~ s/\-\-//gi;
|
$search =~ s/\-\-//gi;
|
||||||
$search =~ s/\;//gi;
|
$search =~ s/\;//gi;
|
||||||
$checked->{search} = $search if $search ne '';
|
$checked->{search} = $search if $search ne '';
|
||||||
}
|
}
|
||||||
$checked->{search} = '' unless defined $checked->{search};
|
$checked->{search} = '' unless defined $checked->{search};
|
||||||
$checked->{comment} = $comment;
|
$checked->{comment} = $comment;
|
||||||
|
|
||||||
return $checked;
|
return $checked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ sub getJson {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( @$series == 1 ) {
|
if ( scalar @$series == 1 ) {
|
||||||
my $serie = $series->[0];
|
my $serie = $series->[0];
|
||||||
$event->{has_single_events} = $serie->{has_single_events};
|
$event->{has_single_events} = $serie->{has_single_events};
|
||||||
if ( $event->{has_single_events} eq '1' ) {
|
if ( $event->{has_single_events} eq '1' ) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ return unless defined uac::check( $config, $params, $user_presets );
|
|||||||
my $local_media_dir = $config->{locations}->{local_media_dir};
|
my $local_media_dir = $config->{locations}->{local_media_dir};
|
||||||
my $local_media_url = $config->{locations}->{local_media_url};
|
my $local_media_url = $config->{locations}->{local_media_url};
|
||||||
|
|
||||||
log::error( $config, 'cannot locate media dir' . $local_media_dir ) unless -e $local_media_dir;
|
log::error( $config, 'cannot locate media dir ' . $local_media_dir ) unless -e $local_media_dir;
|
||||||
uac::permissions_denied('reading from local media dir') unless -r $local_media_dir;
|
uac::permissions_denied('reading from local media dir') unless -r $local_media_dir;
|
||||||
uac::permissions_denied('writing to local media dir') unless -w $local_media_dir;
|
uac::permissions_denied('writing to local media dir') unless -w $local_media_dir;
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ sub show_image {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#print STDERR Dumper($imagesByNames);
|
#print STDERR Dumper($imagesByNames);
|
||||||
$selectedImage = $imagesByNames->[0] if scalar(@$imagesByNames) > 0;
|
$selectedImage = $imagesByNames->[0] if scalar @$imagesByNames > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $finalResults = [];
|
my $finalResults = [];
|
||||||
|
|||||||
@@ -350,6 +350,7 @@ sub process_image {
|
|||||||
|
|
||||||
#$image->Normalize();
|
#$image->Normalize();
|
||||||
$image->Write( 'jpg:' . $image_path );
|
$image->Write( 'jpg:' . $image_path );
|
||||||
|
|
||||||
#write thumb
|
#write thumb
|
||||||
my $thumb = $image;
|
my $thumb = $image;
|
||||||
$thumb->Trim2Square;
|
$thumb->Trim2Square;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ sub save_project {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $projects = project::get( $config, { name => $entry->{name} } );
|
my $projects = project::get( $config, { name => $entry->{name} } );
|
||||||
if ( @$projects > 0 ) {
|
if ( scalar @$projects > 0 ) {
|
||||||
uac::print_error("project with name '$entry->{name}' already exists");
|
uac::print_error("project with name '$entry->{name}' already exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,12 +334,6 @@ sub show_roles {
|
|||||||
#add permission rows
|
#add permission rows
|
||||||
$columns = sort_columns($columns);
|
$columns = sort_columns($columns);
|
||||||
|
|
||||||
# print '<pre>';
|
|
||||||
# for my $key (@$columns){
|
|
||||||
# printf (" %-40s => '',\n", "'".$key."'");
|
|
||||||
# }
|
|
||||||
# print '</pre>';
|
|
||||||
|
|
||||||
for my $key (@$columns) {
|
for my $key (@$columns) {
|
||||||
next
|
next
|
||||||
if ( $key eq 'level'
|
if ( $key eq 'level'
|
||||||
|
|||||||
@@ -361,9 +361,6 @@ sub save_series {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
#print STDERR "done\n";
|
|
||||||
#my @series_ids=@$series_ids;
|
|
||||||
|
|
||||||
if ( $params->{action} eq 'create' ) {
|
if ( $params->{action} eq 'create' ) {
|
||||||
|
|
||||||
unless ( $permissions->{create_series} == 1 ) {
|
unless ( $permissions->{create_series} == 1 ) {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ use studios;
|
|||||||
use series;
|
use series;
|
||||||
use template;
|
use template;
|
||||||
use playout;
|
use playout;
|
||||||
|
|
||||||
binmode STDOUT, ":utf8";
|
binmode STDOUT, ":utf8";
|
||||||
|
|
||||||
my $r = shift;
|
my $r = shift;
|
||||||
|
|||||||
5
website/agenda/planung/showImage.cgi
Normal file → Executable file
5
website/agenda/planung/showImage.cgi
Normal file → Executable file
@@ -72,6 +72,11 @@ sub showImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $filename = images::getInternalPath( $config, $params );
|
my $filename = images::getInternalPath( $config, $params );
|
||||||
|
unless ( defined $filename ) {
|
||||||
|
uac::permissions_denied("could not find path");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
unless ( -e $filename ) {
|
unless ( -e $filename ) {
|
||||||
uac::permissions_denied("read $filename");
|
uac::permissions_denied("read $filename");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ sub delete_studio {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
unless ( @$studio_assignments == 0 ) {
|
unless ( scalar @$studio_assignments == 0 ) {
|
||||||
uac::print_info("Studio unassigned from project");
|
uac::print_info("Studio unassigned from project");
|
||||||
uac::print_warn("Studio is assigned to other projects, so it will not be deleted");
|
uac::print_warn("Studio is assigned to other projects, so it will not be deleted");
|
||||||
return undef;
|
return undef;
|
||||||
@@ -141,7 +141,7 @@ sub save_studio {
|
|||||||
studios::update( $config, $entry );
|
studios::update( $config, $entry );
|
||||||
} else {
|
} else {
|
||||||
my $studios = studios::get( $config, { name => $entry->{name} } );
|
my $studios = studios::get( $config, { name => $entry->{name} } );
|
||||||
if ( @$studios > 0 ) {
|
if ( scalar @$studios > 0 ) {
|
||||||
uac::print_error("studio with name '$entry->{name}' already exists");
|
uac::print_error("studio with name '$entry->{name}' already exists");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ sub save_studio {
|
|||||||
has_single_events => 1
|
has_single_events => 1
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if ( @$single_series == 0 ) {
|
if ( scalar @$single_series == 0 ) {
|
||||||
series::insert(
|
series::insert(
|
||||||
$config,
|
$config,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -51,10 +51,6 @@
|
|||||||
|
|
||||||
<div> <a href="user_settings.cgi?project_id=<TMPL_VAR project_id>&studio_id=<TMPL_VAR default_studio_id>"><TMPL_VAR .loc.profile></a> </div>
|
<div> <a href="user_settings.cgi?project_id=<TMPL_VAR project_id>&studio_id=<TMPL_VAR default_studio_id>"><TMPL_VAR .loc.profile></a> </div>
|
||||||
|
|
||||||
<TMPL_IF .allow.is_admin>
|
|
||||||
<div> <a href="error_log.cgi"><TMPL_VAR .loc.errors></a> </div>
|
|
||||||
</TMPL_IF>
|
|
||||||
|
|
||||||
<div> <a href="help.cgi?project_id=<TMPL_VAR project_id>&studio_id=<TMPL_VAR default_studio_id>"><TMPL_VAR .loc.help></a> </div>
|
<div> <a href="help.cgi?project_id=<TMPL_VAR project_id>&studio_id=<TMPL_VAR default_studio_id>"><TMPL_VAR .loc.help></a> </div>
|
||||||
|
|
||||||
<select id="studio_id" name="studio_id" onchange="set_studio($(this).val())">
|
<select id="studio_id" name="studio_id" onchange="set_studio($(this).val())">
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ my $dbh = db::connect($config);
|
|||||||
my $template_parameters = {};
|
my $template_parameters = {};
|
||||||
$template_parameters->{projects} = getProjects( $dbh, $config, $params );
|
$template_parameters->{projects} = getProjects( $dbh, $config, $params );
|
||||||
$template_parameters->{debug} = $config->{system}->{debug};
|
$template_parameters->{debug} = $config->{system}->{debug};
|
||||||
$template_parameters->{server_cache} = $config->{cache}->{server_cache} if ( $config->{cache}->{server_cache} );
|
$template_parameters->{server_cache} = $config->{cache}->{server_cache} if $config->{cache}->{server_cache} ;
|
||||||
$template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} if ( $config->{cache}->{use_client_cache} );
|
$template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} if $config->{cache}->{use_client_cache} ;
|
||||||
|
|
||||||
#output template
|
#output template
|
||||||
my $template = $params->{template};
|
my $template = $params->{template};
|
||||||
@@ -103,9 +103,9 @@ sub getProjects {
|
|||||||
$project->{js_name} =~ s/\_+/\_/g;
|
$project->{js_name} =~ s/\_+/\_/g;
|
||||||
|
|
||||||
#mark last series_name entry of all non empty projects
|
#mark last series_name entry of all non empty projects
|
||||||
if ( ( defined $series_names ) && ( @$series_names > 0 ) ) {
|
if ( ( defined $series_names ) && ( scalar @$series_names > 0 ) ) {
|
||||||
$series_names->[-1]->{last} = 1;
|
$series_names->[-1]->{last} = 1;
|
||||||
$prev_series_names->[-1]->{last} = 0 if ( ( defined $prev_series_names ) && ( @$prev_series_names > 0 ) );
|
$prev_series_names->[-1]->{last} = 0 if ( defined $prev_series_names ) && ( sclar @$prev_series_names > 0 ) ;
|
||||||
$prev_series_names = $series_names;
|
$prev_series_names = $series_names;
|
||||||
}
|
}
|
||||||
push @$results, $project;
|
push @$results, $project;
|
||||||
|
|||||||
Reference in New Issue
Block a user