/\n/gi; - # $s=~s/\{\{\{((\W+|\w+)+?)\}\}\}/
$1<\/blockquote>/g; - # $s=~s/\{\{(.+?)\|(.*?)\}\}//g; - # $s=~s/\[\[(.+?)\|(.*?)\]\]/$2<\/a>/g; - # $s=~s/([^\:])\/\/(.*?[^\:])\/\//$1$2<\/em> /g; - # $s=~s/\n=== (.*?)\n/
$1<\/h3>\n/g; - # $s=~s/\n== (.*?)\n/
$1<\/h2>\n/g; - #replace line breaks from images - $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; - $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; - $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; + # $s=~s/
/\n/gi; + # $s=~s/\{\{\{((\W+|\w+)+?)\}\}\}/
$1<\/blockquote>/g; + # $s=~s/\{\{(.+?)\|(.*?)\}\}//g; + # $s=~s/\[\[(.+?)\|(.*?)\]\]/$2<\/a>/g; + # $s=~s/([^\:])\/\/(.*?[^\:])\/\//$1$2<\/em> /g; + # $s=~s/\n=== (.*?)\n/
$1<\/h3>\n/g; + # $s=~s/\n== (.*?)\n/
$1<\/h2>\n/g; + #replace line breaks from images + $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; + $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; + $s =~ s/(\{\{[^\}\n]*?)\n([^\}\n]*?\}\})/$1$2/g; - #replace line breaks from links - # $s=~s/\n= (.*?)\n/
$1<\/h1>\n/g; - # $s=~s/\*\*(.*?)\*\*/$1<\/strong> /g; - # $s=~s/^== (.*?)\n/
$1<\/h2>\n/g; - # $s=~s/\n\* (.*?)([\r\n]+)/
$1<\/li>\n/g; - # $s=~s/\n\- (.*?)\n/ $1<\/lo>\n/g; - # $s=~s/\n\n/ /gi; - # $s=~s/\n+/
/gi; - # $s=~s/\\</g; + #replace line breaks from links + # $s=~s/\n= (.*?)\n/$1<\/h1>\n/g; + # $s=~s/\*\*(.*?)\*\*/$1<\/strong> /g; + # $s=~s/^== (.*?)\n/
$1<\/h2>\n/g; + # $s=~s/\n\* (.*?)([\r\n]+)/
$1<\/li>\n/g; + # $s=~s/\n\- (.*?)\n/ $1<\/lo>\n/g; + # $s=~s/\n\n/ /gi; + # $s=~s/\n+/
/gi; + # $s=~s/\\</g; - #remove whitespaces and break lines at start or end of elements - for my $elem ( 'p', 'li' ) { - $s =~ s|<$elem>\s*
|<$elem>|g; - $s =~ s|
\s*$elem>|$elem>|g; - } + #remove whitespaces and break lines at start or end of elements + for my $elem ( 'p', 'li' ) { + $s =~ s|<$elem>\s*
|<$elem>|g; + $s =~ s|
\s*$elem>|$elem>|g; + } - return $s; + return $s; } -sub creole_to_plain { - my $s = shift; +sub creole_to_plain($) { + my $s = shift; - $s =~ s/\/\n/gi; - $s =~ s/\{\{\{((\W+|\w+)+?)\}\}\}/
$1<\/blockquote>/g; - $s =~ s/\{\{(.+?)\|(.*?)\}\}//g; - $s =~ s/\[\[(.+?)\|(.*?)\]\]/$2/g; - $s =~ s/\/\/([^\/\/]*?)\/\//$1<\/em> /g; - $s =~ s/\n=== (.*?)\n/\n$1<\/h3>\n/g; - $s =~ s/\n== (.*?)\n/\n
$1<\/h2>\n/g; - $s =~ s/\*\*(.*?)\*\*/$1<\/strong> /g; - $s =~ s/^== (.*?)\n/
$1<\/h2>\n/g; - $s =~ s/\n\* (.*?)\n/\n
$1<\/li>\n/g; - $s =~ s/\n\* (.*?)\n/\n $1<\/li>\n/g; - $s =~ s/\n\- (.*?)\n/\n $1<\/lo>\n/g; - $s =~ s/\n\- (.*?)\n/\n $1<\/lo>\n/g; - $s =~ s/\n\n/\n /gi; - $s =~ s/\n/\n
/gi; - return $s; + $s =~ s/\/\n/gi; + $s =~ s/\{\{\{((\W+|\w+)+?)\}\}\}/
$1<\/blockquote>/g; + $s =~ s/\{\{(.+?)\|(.*?)\}\}//g; + $s =~ s/\[\[(.+?)\|(.*?)\]\]/$2/g; + $s =~ s/\/\/([^\/\/]*?)\/\//$1<\/em> /g; + $s =~ s/\n=== (.*?)\n/\n$1<\/h3>\n/g; + $s =~ s/\n== (.*?)\n/\n
$1<\/h2>\n/g; + $s =~ s/\*\*(.*?)\*\*/$1<\/strong> /g; + $s =~ s/^== (.*?)\n/
$1<\/h2>\n/g; + $s =~ s/\n\* (.*?)\n/\n
$1<\/li>\n/g; + $s =~ s/\n\* (.*?)\n/\n $1<\/li>\n/g; + $s =~ s/\n\- (.*?)\n/\n $1<\/lo>\n/g; + $s =~ s/\n\- (.*?)\n/\n $1<\/lo>\n/g; + $s =~ s/\n\n/\n /gi; + $s =~ s/\n/\n
' . $s . '' ); - my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 ); - $s = $formatter->format($tree); - return $s; +sub html_to_plain ($) { + my $s = shift; + return '' unless ( defined $s ); + my $tree = HTML::Parse::parse_html( '' . $s . '' ); + my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 ); + $s = $formatter->format($tree); + return $s; } -sub ical_to_plain { - return '' unless defined( $_[0] ); - $_[0] =~ s/\\n/\n/gi; - $_[0] =~ s/ /\t/gi; - $_[0] =~ s/\\\./\./gi; - $_[0] =~ s/\\\,/\,/gi; - $_[0] =~ s/\\\\/\\/gi; - return $_[0]; +sub ical_to_plain ($) { + return '' unless defined( $_[0] ); + $_[0] =~ s/\\n/\n/gi; + $_[0] =~ s/ /\t/gi; + $_[0] =~ s/\\\./\./gi; + $_[0] =~ s/\\\,/\,/gi; + $_[0] =~ s/\\\\/\\/gi; + return $_[0]; } -sub plain_to_ical { - return '' unless defined( $_[0] ); +sub plain_to_ical ($) { + return '' unless defined( $_[0] ); - #remove images + links - $_[0] =~ s/\[\[.+?\|(.+?)\]\]/$1/g; - $_[0] =~ s/\{\{.+?\}\}//g; - $_[0] =~ s/^\s+//g; - $_[0] =~ s/\\/\\\\/gi; - $_[0] =~ s/\,/\\\,/gi; + #remove images + links + $_[0] =~ s/\[\[.+?\|(.+?)\]\]/$1/g; + $_[0] =~ s/\{\{.+?\}\}//g; + $_[0] =~ s/^\s+//g; + $_[0] =~ s/\\/\\\\/gi; + $_[0] =~ s/\,/\\\,/gi; - # $_[0]=~s/\./\\\./gi; - $_[0] =~ s/[\r\n]/\\n/gi; - $_[0] =~ s/\t/ /gi; - return $_[0]; + # $_[0]=~s/\./\\\./gi; + $_[0] =~ s/[\r\n]/\\n/gi; + $_[0] =~ s/\t/ /gi; + return $_[0]; } -sub plain_to_xml { - return '' unless defined( $_[0] ); - $_[0] =~ s/\n\={1,6} (.*?)\s+/\n\[\[$1\]\]\n/gi; +sub plain_to_xml($) { + return '' unless defined( $_[0] ); + $_[0] =~ s/\n\={1,6} (.*?)\s+/\n\[\[$1\]\]\n/gi; - #remove images + links - $_[0] =~ s/\[\[.+?\|(.+?)\]\]/$1/g; - $_[0] =~ s/\{\{.+?\}\}//g; - return encode_xml_element( $_[0] ); + #remove images + links + $_[0] =~ s/\[\[.+?\|(.+?)\]\]/$1/g; + $_[0] =~ s/\{\{.+?\}\}//g; + return encode_xml_element( $_[0] ); - # $_[0]=~s/\ä/ä/gi; - # $_[0]=~s/\ö/ö/gi; - # $_[0]=~s/\ü/ü/gi; - # $_[0]=~s/\Ä/Ä/gi; - # $_[0]=~s/\Ö/Ö/gi; - # $_[0]=~s/\Ü/Ü/gi; - # $_[0]=~s/\ß/ß/gi; - # $_[0]=~s/\&/\&/gi; - # $_[0]=~s/\\</gi; - # $_[0]=~s/\>/\>/gi; - # $_[0]=~s/\"/\"/gi; + # $_[0]=~s/\ä/ä/gi; + # $_[0]=~s/\ö/ö/gi; + # $_[0]=~s/\ü/ü/gi; + # $_[0]=~s/\Ä/Ä/gi; + # $_[0]=~s/\Ö/Ö/gi; + # $_[0]=~s/\Ü/Ü/gi; + # $_[0]=~s/\ß/ß/gi; + # $_[0]=~s/\&/\&/gi; + # $_[0]=~s/\\</gi; + # $_[0]=~s/\>/\>/gi; + # $_[0]=~s/\"/\"/gi; ## $_[0]=~s/\n/
/gi; + return $s; } -sub html_to_plain { - my $s = shift; - return '' unless ( defined $s ); - my $tree = HTML::Parse::parse_html( '
/gi; ## $_[0]=~s/\&/\&/gi; ## $_[0]=~s/\&/+/gi; ## $_[0]=~s/\&/+/gi; ## $_[0]=~s/\&/+/gi; - # return $_[0]; + # return $_[0]; } -sub fix_utf8 { - $_[0] = Encode::decode( 'cp1252', $_[0] ); - return $_[0]; +sub fix_utf8($) { + $_[0] = Encode::decode( 'cp1252', $_[0] ); + return $_[0]; } -sub uri_encode { - $_[0] =~ s/([^a-zA-Z0-9_\.\-])/sprintf("%%%02lx",ord($1))/esg; - return $_[0]; +sub uri_encode ($) { + $_[0] =~ s/([^a-zA-Z0-9_\.\-])/sprintf("%%%02lx",ord($1))/esg; + return $_[0]; } -sub compress { - my $header = ''; +sub compress ($) { + my $header = ''; - if ( $_[0] =~ /(Content\-type\:[^\n]+[\n]+)/ ) { - $header = $1; - } else { + if ( $_[0] =~ /(Content\-type\:[^\n]+[\n]+)/ ) { + $header = $1; + } else { - #return; - } + #return; + } - my $start = index( $_[0], $header ); - return if ( $start < 0 ); + my $start = index( $_[0], $header ); + return if ( $start < 0 ); - my $header_length = length($header); - $header = substr( $_[0], 0, $start + $header_length ); + my $header_length = length($header); + $header = substr( $_[0], 0, $start + $header_length ); - # print $header."\n"; + # print $header."\n"; - my $content = substr( $_[0], $start + $header_length ); + my $content = substr( $_[0], $start + $header_length ); - # #remove multiple line breaks - $content =~ s/[\r\n]+[\s]*[\r\n]+/\n/g; + # #remove multiple line breaks + $content =~ s/[\r\n]+[\s]*[\r\n]+/\n/g; - #remove leading whitespaces - $content =~ s/[\r\n]+[\s]+/\n/g; + #remove leading whitespaces + $content =~ s/[\r\n]+[\s]+/\n/g; - #remove tailing whitespaces - $content =~ s/[\t ]*[\r\n]+/\n/g; + #remove tailing whitespaces + $content =~ s/[\t ]*[\r\n]+/\n/g; - #remove whitespaces inside tags - $content =~ s/([\n]\<[^\n]+)[\r\n]+/$1 /g; - $content =~ s/\"\s+\>/\"\>/g; + #remove whitespaces inside tags + $content =~ s/([\n]\<[^\n]+)[\r\n]+/$1 /g; + $content =~ s/\"\s+\>/\"\>/g; - #get closing tags closer - $content =~ s/[\r\n]+(\<[\/\!])/$1/g; - $content =~ s/(\>)[\r\n]+([^\<])/$1$2/g; + #get closing tags closer + $content =~ s/[\r\n]+(\<[\/\!])/$1/g; + $content =~ s/(\>)[\r\n]+([^\<])/$1$2/g; - #remove leading whitespaces - #$content=~s/[\r\n]+([\d\S])/$1/g; + #remove leading whitespaces + #$content=~s/[\r\n]+([\d\S])/$1/g; - #remove empty lines - $content =~ s/[\n\r]+/\n/g; + #remove empty lines + $content =~ s/[\n\r]+/\n/g; - #remove whitespaces between tags - $content =~ s/\>[\t ]+\<(^\/T)/\>\<$1/g; + #remove whitespaces between tags + $content =~ s/\>[\t ]+\<(^\/T)/\>\<$1/g; - #multiple whitespaces - $content =~ s/[\t ]+/ /g; + #multiple whitespaces + $content =~ s/[\t ]+/ /g; - #restore content-type line break - $_[0] = $header . $content; + #restore content-type line break + $_[0] = $header . $content; - #$_[0]=~s/HTTP_CONTENT_TYPE/\n\n/; - # return $_[0]; + #$_[0]=~s/HTTP_CONTENT_TYPE/\n\n/; + # return $_[0]; } #from XML::RSS.pm my %entity = ( - nbsp => " ", - iexcl => "¡", - cent => "¢", - pound => "£", - curren => "¤", - yen => "¥", - brvbar => "¦", - sect => "§", - uml => "¨", - copy => "©", - ordf => "ª", - laquo => "«", - not => "¬", - shy => "", - reg => "®", - macr => "¯", - deg => "°", - plusmn => "±", - sup2 => "²", - sup3 => "³", - acute => "´", - micro => "µ", - para => "¶", - middot => "·", - cedil => "¸", - sup1 => "¹", - ordm => "º", - raquo => "»", - frac14 => "¼", - frac12 => "½", - frac34 => "¾", - iquest => "¿", - Agrave => "À", - Aacute => "Á", - Acirc => "Â", - Atilde => "Ã", - Auml => "Ä", - Aring => "Å", - AElig => "Æ", - Ccedil => "Ç", - Egrave => "È", - Eacute => "É", - Ecirc => "Ê", - Euml => "Ë", - Igrave => "Ì", - Iacute => "Í", - Icirc => "Î", - Iuml => "Ï", - ETH => "Ð", - Ntilde => "Ñ", - Ograve => "Ò", - Oacute => "Ó", - Ocirc => "Ô", - Otilde => "Õ", - Ouml => "Ö", - times => "×", - Oslash => "Ø", - Ugrave => "Ù", - Uacute => "Ú", - Ucirc => "Û", - Uuml => "Ü", - Yacute => "Ý", - THORN => "Þ", - szlig => "ß", - agrave => "à", - aacute => "á", - acirc => "â", - atilde => "ã", - auml => "ä", - aring => "å", - aelig => "æ", - ccedil => "ç", - egrave => "è", - eacute => "é", - ecirc => "ê", - euml => "ë", - igrave => "ì", - iacute => "í", - icirc => "î", - iuml => "ï", - eth => "ð", - ntilde => "ñ", - ograve => "ò", - oacute => "ó", - ocirc => "ô", - otilde => "õ", - ouml => "ö", - divide => "÷", - oslash => "ø", - ugrave => "ù", - uacute => "ú", - ucirc => "û", - uuml => "ü", - yacute => "ý", - thorn => "þ", - yuml => "ÿ", + nbsp => " ", + iexcl => "¡", + cent => "¢", + pound => "£", + curren => "¤", + yen => "¥", + brvbar => "¦", + sect => "§", + uml => "¨", + copy => "©", + ordf => "ª", + laquo => "«", + not => "¬", + shy => "", + reg => "®", + macr => "¯", + deg => "°", + plusmn => "±", + sup2 => "²", + sup3 => "³", + acute => "´", + micro => "µ", + para => "¶", + middot => "·", + cedil => "¸", + sup1 => "¹", + ordm => "º", + raquo => "»", + frac14 => "¼", + frac12 => "½", + frac34 => "¾", + iquest => "¿", + Agrave => "À", + Aacute => "Á", + Acirc => "Â", + Atilde => "Ã", + Auml => "Ä", + Aring => "Å", + AElig => "Æ", + Ccedil => "Ç", + Egrave => "È", + Eacute => "É", + Ecirc => "Ê", + Euml => "Ë", + Igrave => "Ì", + Iacute => "Í", + Icirc => "Î", + Iuml => "Ï", + ETH => "Ð", + Ntilde => "Ñ", + Ograve => "Ò", + Oacute => "Ó", + Ocirc => "Ô", + Otilde => "Õ", + Ouml => "Ö", + times => "×", + Oslash => "Ø", + Ugrave => "Ù", + Uacute => "Ú", + Ucirc => "Û", + Uuml => "Ü", + Yacute => "Ý", + THORN => "Þ", + szlig => "ß", + agrave => "à", + aacute => "á", + acirc => "â", + atilde => "ã", + auml => "ä", + aring => "å", + aelig => "æ", + ccedil => "ç", + egrave => "è", + eacute => "é", + ecirc => "ê", + euml => "ë", + igrave => "ì", + iacute => "í", + icirc => "î", + iuml => "ï", + eth => "ð", + ntilde => "ñ", + ograve => "ò", + oacute => "ó", + ocirc => "ô", + otilde => "õ", + ouml => "ö", + divide => "÷", + oslash => "ø", + ugrave => "ù", + uacute => "ú", + ucirc => "û", + uuml => "ü", + yacute => "ý", + thorn => "þ", + yuml => "ÿ", ); my $entities = join( '|', keys %entity ); -sub encode_xml_element { - my $text = shift; +sub encode_xml_element($) { + my $text = shift; - my $encoded_text = ''; + my $encoded_text = ''; - while ( $text =~ s/(.*?)(\<\!\[CDATA\[.*?\]\]\>)//s ) { - $encoded_text .= encode_xml_element_text($1) . $2; - } - $encoded_text .= encode_xml_element_text($text); + while ( $text =~ s/(.*?)(\<\!\[CDATA\[.*?\]\]\>)//s ) { + $encoded_text .= encode_xml_element_text($1) . $2; + } + $encoded_text .= encode_xml_element_text($text); - return $encoded_text; + return $encoded_text; } -sub encode_xml_element_text { - my $text = shift; +sub encode_xml_element_text ($) { + my $text = shift; - $text =~ s/&(?!(#[0-9]+|#x[0-9a-fA-F]+|\w+);)/&/g; - $text =~ s/&($entities);/$entity{$1}/g; - $text =~ s/\\<\;/g; - $text =~ s/\>/\>\;/g; + $text =~ s/&(?!(#[0-9]+|#x[0-9a-fA-F]+|\w+);)/&/g; + $text =~ s/&($entities);/$entity{$1}/g; + $text =~ s/\\<\;/g; + $text =~ s/\>/\>\;/g; - return $text; + return $text; } -sub escapeHtml{ - my $s=shift; - return HTML::Entities::encode_entities($s,q{&<>"'}); +sub escapeHtml($) { + my $s = shift; + return HTML::Entities::encode_entities( $s, q{&<>"'} ); } #do not delete last line! diff --git a/lib/calcms/params.pm b/lib/calcms/params.pm index 83c75c5..6c1b12a 100644 --- a/lib/calcms/params.pm +++ b/lib/calcms/params.pm @@ -1,7 +1,8 @@ package params; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Apache2::Request(); @@ -12,11 +13,11 @@ our @EXPORT_OK = qw(get isJson); sub debug; my $isJson = 0; -sub isJson { +sub isJson () { return $isJson; } -sub get { +sub get ($) { my $r = shift; my $tmp_dir = '/var/tmp/'; @@ -50,18 +51,18 @@ sub get { $isJson = 1 if ( defined $params->{json} ) && ( $params->{json} eq '1' ); if ( defined $status ) { - $status = '' if $status eq 'Success' ; - $status = '' if $status eq 'Missing input data' ; - if ($status ne ''){ - $cgi=new CGI::Simple() unless defined $cgi; + $status = '' if $status eq 'Success'; + $status = '' if $status eq 'Missing input data'; + if ( $status ne '' ) { + $cgi = new CGI::Simple() unless defined $cgi; print $cgi->header . $status . "\n"; - } ; + } } return ( $cgi, $params, $status ); } -sub debug { +sub debug ($) { my $message = shift; } diff --git a/lib/calcms/password_requests.pm b/lib/calcms/password_requests.pm index 1a70a23..1060069 100644 --- a/lib/calcms/password_requests.pm +++ b/lib/calcms/password_requests.pm @@ -1,14 +1,15 @@ package password_requests; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Session::Token(); # table: calcms_password_requests use base 'Exporter'; -our @EXPORT_OK = qw(get insert delete get_columns); +our @EXPORT_OK = qw(get insert delete get_columns); use mail; use uac; @@ -17,235 +18,235 @@ use auth; sub debug; -sub get_columns { - my $config = shift; +sub get_columns ($) { + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_password_requests' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_password_requests' ); + my $columns = {}; + for my $col (@$cols) { + $columns->{$col} = 1; + } + return $columns; } -sub get { - my $config = shift; - my $condition = shift; +sub get ($$) { + my $config = shift; + my $condition = shift; - my $dbh = db::connect($config); + my $dbh = db::connect($config); - my @conditions = (); - my @bind_values = (); + my @conditions = (); + my @bind_values = (); - if ( defined $condition->{user} ) { - push @conditions, 'user=?'; - push @bind_values, $condition->{user}; - } + if ( defined $condition->{user} ) { + push @conditions, 'user=?'; + push @bind_values, $condition->{user}; + } - if ( defined $condition->{token} ) { - push @conditions, 'token=?'; - push @bind_values, $condition->{token}; - } + if ( defined $condition->{token} ) { + push @conditions, 'token=?'; + push @bind_values, $condition->{token}; + } - return undef if ( scalar @conditions ) == 0; + return undef if ( scalar @conditions ) == 0; - my $conditions = " where " . join( " and ", @conditions ); - my $query = qq{ + my $conditions = " where " . join( " and ", @conditions ); + my $query = qq{ select * from calcms_password_requests $conditions }; - #print $query."\n".Dumper(\@bind_values); + #print $query."\n".Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); - return $entries->[0] || undef; + my $entries = db::get( $dbh, $query, \@bind_values ); + return $entries->[0] || undef; } -sub update { - my $config = shift; - my $entry = shift; +sub update($$) { + my $config = shift; + my $entry = shift; - return unless defined $entry->{user}; + return unless defined $entry->{user}; - my $dbh = db::connect($config); - my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) ); - my @bind_values = map { $entry->{$_} } ( keys %$entry ); - push @bind_values, $entry->{token}; + my $dbh = db::connect($config); + my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) ); + my @bind_values = map { $entry->{$_} } ( keys %$entry ); + push @bind_values, $entry->{token}; - my $query = qq{ + my $query = qq{ update calcms_password_requests set $values where token=? }; - print STDERR $query . Dumper( \@bind_values ); - db::put( $dbh, $query, \@bind_values ); + print STDERR $query . Dumper( \@bind_values ); + db::put( $dbh, $query, \@bind_values ); } -sub insert { - my $config = shift; - my $entry = shift; +sub insert ($$) { + my $config = shift; + my $entry = shift; - return undef unless defined $entry->{user}; + return undef unless defined $entry->{user}; - my $dbh = db::connect($config); - print STDERR 'insert ' . Dumper($entry); - return db::insert( $dbh, 'calcms_password_requests', $entry ); + my $dbh = db::connect($config); + print STDERR 'insert ' . Dumper($entry); + return db::insert( $dbh, 'calcms_password_requests', $entry ); } -sub delete { - my $config = shift; - my $condition = shift; +sub delete ($$) { + my $config = shift; + my $condition = shift; - my @conditions = (); - my @bind_values = (); + my @conditions = (); + my @bind_values = (); - if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) { - push @conditions, 'user=?'; - push @bind_values, $condition->{user}; - } + if ( ( defined $condition->{user} ) && ( $condition->{user} ne '' ) ) { + push @conditions, 'user=?'; + push @bind_values, $condition->{user}; + } - if ( ( defined $condition->{token} ) && ( $condition->{token} ne '' ) ) { - push @conditions, 'token=?'; - push @bind_values, $condition->{token}; - } + if ( ( defined $condition->{token} ) && ( $condition->{token} ne '' ) ) { + push @conditions, 'token=?'; + push @bind_values, $condition->{token}; + } - return if ( scalar @conditions ) == 0; - my $conditions = " where " . join( " and ", @conditions ); + return if ( scalar @conditions ) == 0; + my $conditions = " where " . join( " and ", @conditions ); - my $dbh = db::connect($config); + my $dbh = db::connect($config); - my $query = qq{ + my $query = qq{ delete from calcms_password_requests $conditions }; - print STDERR "$query " . Dumper( \@bind_values ); - db::put( $dbh, $query, \@bind_values ); + print STDERR "$query " . Dumper( \@bind_values ); + db::put( $dbh, $query, \@bind_values ); } -sub sendToken { - my $config = shift; - my $entry = shift; +sub sendToken ($$) { + my $config = shift; + my $entry = shift; - return undef unless defined $entry->{user}; + return undef unless defined $entry->{user}; - my $user = uac::get_user( $config, $entry->{user} ); - return undef unless defined $user; + my $user = uac::get_user( $config, $entry->{user} ); + return undef unless defined $user; - # check age of existing entry - my $oldEntry = password_requests::get( $config, { user => $entry->{user} } ); - if ( defined $oldEntry ) { - my $createdAt = $oldEntry->{created_at}; - print STDERR Dumper($oldEntry); - print STDERR "createdAt=$createdAt\n"; - my $age = time() - time::datetime_to_time($createdAt); - if ( $age < 60 ) { - print STDERR "too many requests"; - return undef; - } - print STDERR "age=$age\n"; - } - password_requests::delete( $config, $entry ); + # check age of existing entry + my $oldEntry = password_requests::get( $config, { user => $entry->{user} } ); + if ( defined $oldEntry ) { + my $createdAt = $oldEntry->{created_at}; + print STDERR Dumper($oldEntry); + print STDERR "createdAt=$createdAt\n"; + my $age = time() - time::datetime_to_time($createdAt); + if ( $age < 60 ) { + print STDERR "too many requests"; + return undef; + } + print STDERR "age=$age\n"; + } + password_requests::delete( $config, $entry ); - $entry->{max_attempts} = 0; - $entry->{token} = Session::Token->new->get; + $entry->{max_attempts} = 0; + $entry->{token} = Session::Token->new->get; - my $baseUrl = $config->{locations}->{source_base_url} . $config->{locations}->{editor_base_url}; - my $url = $baseUrl . "/requestPassword.cgi?token=" . $entry->{token}; - my $content = "Hi,$user->{full_name}\n\n"; - $content .= "Someone just tried to reset your password for $baseUrl.\n\n"; - $content .= "If you like to set a new password, please follow the link below\n"; - $content .= $url . "\n\n"; - $content .= "If you do not like to set a new password, please ignore this mail.\n"; + my $baseUrl = $config->{locations}->{source_base_url} . $config->{locations}->{editor_base_url}; + my $url = $baseUrl . "/requestPassword.cgi?token=" . $entry->{token}; + my $content = "Hi,$user->{full_name}\n\n"; + $content .= "Someone just tried to reset your password for $baseUrl.\n\n"; + $content .= "If you like to set a new password, please follow the link below\n"; + $content .= $url . "\n\n"; + $content .= "If you do not like to set a new password, please ignore this mail.\n"; - mail::send( - { - "To" => $user->{email}, - "Subject" => "request to change password for $baseUrl", - "Data" => $content - } - ); + mail::send( + { + "To" => $user->{email}, + "Subject" => "request to change password for $baseUrl", + "Data" => $content + } + ); - password_requests::insert( $config, $entry ); + password_requests::insert( $config, $entry ); } -sub changePassword { - my $config = shift; - my $request = shift; - my $userName = shift; +sub changePassword ($$$) { + my $config = shift; + my $request = shift; + my $userName = shift; - my $params = $request->{params}->{checked}; - my $permissions = $request->{permissions}; + my $params = $request->{params}->{checked}; + my $permissions = $request->{permissions}; - unless ( ( defined $userName ) || ( $userName eq '' ) ) { - return { error => 'user not found' }; - } + unless ( ( defined $userName ) || ( $userName eq '' ) ) { + return { error => 'user not found' }; + } - my $user = uac::get_user( $config, $userName ); + my $user = uac::get_user( $config, $userName ); - unless ( ( defined $user ) && ( defined $user->{id} ) && ( $user->{id} ne '' ) ) { - return { error => 'user id not found' }; - } + unless ( ( defined $user ) && ( defined $user->{id} ) && ( $user->{id} ne '' ) ) { + return { error => 'user id not found' }; + } - unless ( password_requests::checkPassword( $params->{user_password} ) ) { - return { error => 'password does not meet requirements' }; - } + unless ( password_requests::checkPassword( $params->{user_password} ) ) { + return { error => 'password does not meet requirements' }; + } - if ( $params->{user_password} ne $params->{user_password2} ) { - return { error => 'entered passwords do not match' }; - } + if ( $params->{user_password} ne $params->{user_password2} ) { + return { error => 'entered passwords do not match' }; + } - #print STDERR "error at changing password:" . Dumper($errors); + #print STDERR "error at changing password:" . Dumper($errors); - my $crypt = auth::crypt_password( $params->{user_password} ); - $user = { id => $user->{id} }; - $user->{salt} = $crypt->{salt}; - $user->{pass} = $crypt->{crypt}; + my $crypt = auth::crypt_password( $params->{user_password} ); + $user = { id => $user->{id} }; + $user->{salt} = $crypt->{salt}; + $user->{pass} = $crypt->{crypt}; - #print ''.Dumper($user).''; - $config->{access}->{write} = 1; - print STDERR "update user" . Dumper($user); - my $result = uac::update_user( $config, $user ); - print STDERR "result:" . Dumper($result); - $config->{access}->{write} = 0; - return { success => "password changed for $userName" }; + #print ''.Dumper($user).''; + $config->{access}->{write} = 1; + print STDERR "update user" . Dumper($user); + my $result = uac::update_user( $config, $user ); + print STDERR "result:" . Dumper($result); + $config->{access}->{write} = 0; + return { success => "password changed for $userName" }; } -sub checkPassword { - my $password = shift; - unless ( defined $password || $password eq '' ) { - error("password is empty"); - return; - } - if ( length($password) < 8 ) { - error("password to short"); - return 0; - } - unless ( $password =~ /[a-z]/ ) { - error("password should contains at least one small character"); - return 0; - } - unless ( $password =~ /[A-Z]/ ) { - error("password should contains at least one big character"); - return 0; - } - unless ( $password =~ /[0-9]/ ) { - error("password should contains at least one number"); - return 0; - } - unless ( $password =~ /[^a-zA-Z0-9]/ ) { - error("password should contains at least one special character"); - return 0; - } - return 1; +sub checkPassword($) { + my $password = shift; + unless ( defined $password || $password eq '' ) { + error("password is empty"); + return; + } + if ( length($password) < 8 ) { + error("password to short"); + return 0; + } + unless ( $password =~ /[a-z]/ ) { + error("password should contains at least one small character"); + return 0; + } + unless ( $password =~ /[A-Z]/ ) { + error("password should contains at least one big character"); + return 0; + } + unless ( $password =~ /[0-9]/ ) { + error("password should contains at least one number"); + return 0; + } + unless ( $password =~ /[^a-zA-Z0-9]/ ) { + error("password should contains at least one special character"); + return 0; + } + return 1; } -sub error { - my $msg = shift; - print "ERROR: $msg
\n"; +sub error($) { + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/lib/calcms/playout.pm b/lib/calcms/playout.pm index 71023af..8164b1b 100644 --- a/lib/calcms/playout.pm +++ b/lib/calcms/playout.pm @@ -1,7 +1,8 @@ package playout; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc(); @@ -10,84 +11,85 @@ use time(); use series_events(); use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get sync); +our @EXPORT_OK = qw(get_columns get sync); sub debug; -sub get_columns { - my $config = shift; +sub get_columns ($) { + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_playout' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_playout' ); + my $columns = {}; + for my $col (@$cols) { + $columns->{$col} = 1; + } + return $columns; } # get playout entries -sub get { - my $config = shift; - my $condition = shift; +sub get($$) { + my $config = shift; + my $condition = shift; - return undef unless defined $condition->{studio_id}; + return undef unless defined $condition->{studio_id}; - my $date_range_include = 0; - $date_range_include = 1 if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 ); + my $date_range_include = 0; + $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 @bind_values = (); + my @conditions = (); + my @bind_values = (); - if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) { - push @conditions, 'project_id=?'; - push @bind_values, $condition->{project_id}; - } + if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) { + push @conditions, 'project_id=?'; + push @bind_values, $condition->{project_id}; + } - if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) { - push @conditions, 'studio_id=?'; - push @bind_values, $condition->{studio_id}; - } + if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) { + push @conditions, 'studio_id=?'; + push @bind_values, $condition->{studio_id}; + } - if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) { - push @conditions, 'start=?'; - push @bind_values, $condition->{start_at}; - } + if ( ( defined $condition->{start_at} ) && ( $condition->{start_at} ne '' ) ) { + push @conditions, 'start=?'; + push @bind_values, $condition->{start_at}; + } - if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) { - if ( $date_range_include == 1 ) { - push @conditions, 'end_date>=?'; - push @bind_values, $condition->{from}; - } else { - push @conditions, 'start_date>=?'; - push @bind_values, $condition->{from}; - } - } + if ( ( defined $condition->{from} ) && ( $condition->{from} ne '' ) ) { + if ( $date_range_include == 1 ) { + push @conditions, 'end_date>=?'; + push @bind_values, $condition->{from}; + } else { + push @conditions, 'start_date>=?'; + push @bind_values, $condition->{from}; + } + } - if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) { - if ( $date_range_include == 1 ) { - push @conditions, 'start_date<=?'; - push @bind_values, $condition->{till}; - } else { - push @conditions, 'end_date<=?'; - push @bind_values, $condition->{till}; - } - } + if ( ( defined $condition->{till} ) && ( $condition->{till} ne '' ) ) { + if ( $date_range_include == 1 ) { + push @conditions, 'start_date<=?'; + push @bind_values, $condition->{till}; + } else { + push @conditions, 'end_date<=?'; + push @bind_values, $condition->{till}; + } + } - my $limit = ''; - if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) { - $limit = 'limit ' . $condition->{limit}; - } + my $limit = ''; + if ( ( defined $condition->{limit} ) && ( $condition->{limit} ne '' ) ) { + $limit = 'limit ' . $condition->{limit}; + } - my $conditions = ''; - $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); + my $conditions = ''; + $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); - my $order = 'start'; - $order = $condition->{order} if ( defined $condition->{order} ) && ( $condition->{order} ne '' ); + my $order = 'start'; + $order = $condition->{order} if ( defined $condition->{order} ) && ( $condition->{order} ne '' ); - my $query = qq{ + my $query = qq{ select date(start) start_date ,date(end) end_date ,dayname(start) weekday @@ -120,39 +122,39 @@ sub get { $limit }; - #print STDERR Dumper($query).Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); - return $entries; + #print STDERR Dumper($query).Dumper(\@bind_values); + my $entries = db::get( $dbh, $query, \@bind_values ); + return $entries; } # update playout entries for a given date span # insert, update and delete entries -sub sync { - my $config = shift; - my $options = shift; +sub sync ($$) { + my $config = shift; + my $options = shift; - #print STDERR Dumper($config); - print STDERR "upload " . Dumper($options); - return undef unless defined $options->{project_id}; - return undef unless defined $options->{studio_id}; - return undef unless defined $options->{from}; - return undef unless defined $options->{till}; - return undef unless defined $options->{events}; + #print STDERR Dumper($config); + print STDERR "upload " . Dumper($options); + return undef unless defined $options->{project_id}; + return undef unless defined $options->{studio_id}; + return undef unless defined $options->{from}; + return undef unless defined $options->{till}; + return undef unless defined $options->{events}; - my $project_id = $options->{project_id}; - my $studio_id = $options->{studio_id}; - my $updates = $options->{events}; + my $project_id = $options->{project_id}; + my $studio_id = $options->{studio_id}; + my $updates = $options->{events}; - # get new entries by date - my $update_by_date = {}; - for my $entry (@$updates) { - $update_by_date->{ $entry->{start} } = $entry; - } + # get new entries by date + my $update_by_date = {}; + for my $entry (@$updates) { + $update_by_date->{ $entry->{start} } = $entry; + } - # get database entries - my $bind_values = [ $options->{project_id}, $options->{studio_id}, $options->{from}, $options->{till} ]; + # get database entries + my $bind_values = [ $options->{project_id}, $options->{studio_id}, $options->{from}, $options->{till} ]; - my $query = qq{ + my $query = qq{ select * from calcms_playout where project_id=? @@ -161,132 +163,135 @@ sub sync { and end <= ? order by start }; - print STDERR "from:$options->{from} till:$options->{till}\n"; - my $dbh = db::connect($config); - my $entries = db::get( $dbh, $query, $bind_values ); + print STDERR "from:$options->{from} till:$options->{till}\n"; + my $dbh = db::connect($config); + my $entries = db::get( $dbh, $query, $bind_values ); - #print STDERR "entries:".Dumper($entries); + #print STDERR "entries:".Dumper($entries); - # get database entries by date - my $entries_by_date = {}; - for my $entry (@$entries) { + # get database entries by date + my $entries_by_date = {}; + for my $entry (@$entries) { - # store entry by date - my $start = $entry->{start}; - $entries_by_date->{$start} = $entry; + # store entry by date + my $start = $entry->{start}; + $entries_by_date->{$start} = $entry; - # remove outdated entries - unless ( defined $update_by_date->{$start} ) { - print STDERR "delete:" . Dumper($entry); - playout::delete( $config, $dbh, $entry ); - my $result = series_events::set_playout_status( - $config, - { - project_id => $project_id, - studio_id => $studio_id, - start => $entry->{start}, - playout => 0, - } - ); - print STDERR "delete playout_status result=" . $result . "\n"; - next; - } + # remove outdated entries + unless ( defined $update_by_date->{$start} ) { + print STDERR "delete:" . Dumper($entry); + playout::delete( $config, $dbh, $entry ); + my $result = series_events::set_playout_status( + $config, + { + project_id => $project_id, + studio_id => $studio_id, + start => $entry->{start}, + playout => 0, + } + ); + print STDERR "delete playout_status result=" . $result . "\n"; + next; + } - # update existing entries - if ( defined $update_by_date->{$start} ) { - next if has_changed( $entry, $update_by_date->{$start} ) == 0; - print STDERR "update:" . Dumper($entry); - playout::update( $config, $dbh, $entry, $update_by_date->{$start} ); - my $result = series_events::set_playout_status( - $config, - { - project_id => $project_id, - studio_id => $studio_id, - start => $entry->{start}, - playout => 1, - } - ); - print STDERR "update playout_status result=" . $result . "\n"; - next; - } - } + # update existing entries + if ( defined $update_by_date->{$start} ) { + next if has_changed( $entry, $update_by_date->{$start} ) == 0; + print STDERR "update:" . Dumper($entry); + playout::update( $config, $dbh, $entry, $update_by_date->{$start} ); + my $result = series_events::set_playout_status( + $config, + { + project_id => $project_id, + studio_id => $studio_id, + start => $entry->{start}, + playout => 1, + } + ); + print STDERR "update playout_status result=" . $result . "\n"; + next; + } + } - # insert new entries - for my $entry (@$updates) { - my $start = $entry->{start}; - unless ( defined $entries_by_date->{$start} ) { - $entry->{project_id} = $project_id; - $entry->{studio_id} = $studio_id; - print STDERR "insert:" . Dumper($entry); - playout::insert( $config, $dbh, $entry ); - my $result = series_events::set_playout_status( - $config, - { - project_id => $project_id, - studio_id => $studio_id, - start => $entry->{start}, - playout => 1, - } - ); - print STDERR "insert playout_status result=" . $result . "\n"; - } - } - return 1; + # insert new entries + for my $entry (@$updates) { + my $start = $entry->{start}; + unless ( defined $entries_by_date->{$start} ) { + $entry->{project_id} = $project_id; + $entry->{studio_id} = $studio_id; + print STDERR "insert:" . Dumper($entry); + playout::insert( $config, $dbh, $entry ); + my $result = series_events::set_playout_status( + $config, + { + project_id => $project_id, + studio_id => $studio_id, + start => $entry->{start}, + playout => 1, + } + ); + print STDERR "insert playout_status result=" . $result . "\n"; + } + } + return 1; } -sub has_changed { - my $oldEntry = shift; - my $newEntry = shift; +sub has_changed ($$) { + my $oldEntry = shift; + my $newEntry = shift; - my $update = 0; - for my $key ( - 'duration', 'errors', 'file', 'channels', 'format', 'format_version', - 'format_profile', 'format_settings', 'stream_size', 'bitrate', 'bitrate_mode', 'sampling_rate', - 'writing_library', 'modified_at' - ) - { - return 1 if ( $oldEntry->{$key} || '' ) ne ( $newEntry->{$key} || '' ); - } - return 0; + my $update = 0; + for my $key ( + 'duration', 'errors', 'file', 'channels', + 'format', 'format_version', 'format_profile', 'format_settings', + 'stream_size', 'bitrate', 'bitrate_mode', 'sampling_rate', + 'writing_library', 'modified_at' + ) + { + return 1 if ( $oldEntry->{$key} || '' ) ne ( $newEntry->{$key} || '' ); + } + return 0; } # update playout entry if differs to old values -sub update { - my $config = shift; - my $dbh = shift; - my $oldEntry = shift; - my $newEntry = shift; +sub update ($$$$) { + my $config = shift; + my $dbh = shift; + my $oldEntry = shift; + my $newEntry = shift; - return if has_changed( $oldEntry, $newEntry ) == 0; + return if has_changed( $oldEntry, $newEntry ) == 0; - for my $key ( - 'duration', 'errors', 'file', 'channels', 'format', 'format_version', - 'format_profile', 'format_settings', 'stream_size', 'bitrate', 'bitrate_mode', 'sampling_rate', - 'writing_library', 'rms_left', 'rms_right', 'rms_image', 'replay_gain', 'modified_at' - ) - { - if ( ( $oldEntry->{$key} || '' ) ne ( $newEntry->{$key} || '' ) ) { - $oldEntry->{$key} = $newEntry->{$key}; - } - } + for my $key ( + 'duration', 'errors', 'file', 'channels', + 'format', 'format_version', 'format_profile', 'format_settings', + 'stream_size', 'bitrate', 'bitrate_mode', 'sampling_rate', + 'writing_library', 'rms_left', 'rms_right', 'rms_image', + 'replay_gain', 'modified_at' + ) + { + if ( ( $oldEntry->{$key} || '' ) ne ( $newEntry->{$key} || '' ) ) { + $oldEntry->{$key} = $newEntry->{$key}; + } + } - my $entry = $oldEntry; - print STDERR "update:" . Dumper($entry); + my $entry = $oldEntry; + print STDERR "update:" . Dumper($entry); - my $day_start = $config->{date}->{day_starting_hour}; - $entry->{end} = playout::getEnd( $entry->{start}, $entry->{duration} ); - $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); - $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); + my $day_start = $config->{date}->{day_starting_hour}; + $entry->{end} = playout::getEnd( $entry->{start}, $entry->{duration} ); + $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); + $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); - my $bind_values = [ - $entry->{end}, $entry->{duration}, $entry->{file}, $entry->{errors}, - $entry->{start_date}, $entry->{end_date}, $entry->{channels}, $entry->{'format'}, - $entry->{format_version}, $entry->{format_profile}, $entry->{format_settings}, $entry->{stream_size}, - $entry->{bitrate}, $entry->{bitrate_mode}, $entry->{sampling_rate}, $entry->{writing_library}, - $entry->{rms_left}, $entry->{rms_right}, $entry->{rms_image}, $entry->{replay_gain}, - $entry->{modified_at}, $entry->{project_id}, $entry->{studio_id}, $entry->{start} - ]; - my $query = qq{ + my $bind_values = [ + $entry->{end}, $entry->{duration}, $entry->{file}, $entry->{errors}, + $entry->{start_date}, $entry->{end_date}, $entry->{channels}, $entry->{'format'}, + $entry->{format_version}, $entry->{format_profile}, $entry->{format_settings}, $entry->{stream_size}, + $entry->{bitrate}, $entry->{bitrate_mode}, $entry->{sampling_rate}, $entry->{writing_library}, + $entry->{rms_left}, $entry->{rms_right}, $entry->{rms_image}, $entry->{replay_gain}, + $entry->{modified_at}, $entry->{project_id}, $entry->{studio_id}, $entry->{start} + ]; + my $query = qq{ update calcms_playout set end=?, duration=?, file=?, errors=?, start_date=?, end_date=?, @@ -296,100 +301,100 @@ sub update { replay_gain=?, modified_at=? where project_id=? and studio_id=? and start=? }; - return db::put( $dbh, $query, $bind_values ); + return db::put( $dbh, $query, $bind_values ); } # insert playout entry -sub insert { - my $config = shift; - my $dbh = shift; - my $entry = shift; +sub insert ($$$) { + my $config = shift; + my $dbh = shift; + my $entry = shift; - return undef unless defined $entry->{project_id}; - return undef unless defined $entry->{studio_id}; - return undef unless defined $entry->{start}; - return undef unless defined $entry->{duration}; - return undef unless defined $entry->{file}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{start}; + return undef unless defined $entry->{duration}; + return undef unless defined $entry->{file}; - my $day_start = $config->{date}->{day_starting_hour}; - $entry->{end} = playout::getEnd( $entry->{start}, $entry->{duration} ); - $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); - $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); + my $day_start = $config->{date}->{day_starting_hour}; + $entry->{end} = playout::getEnd( $entry->{start}, $entry->{duration} ); + $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); + $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); - return db::insert( - $dbh, - 'calcms_playout', - { - project_id => $entry->{project_id}, - studio_id => $entry->{studio_id}, - start => $entry->{start}, - end => $entry->{end}, - start_date => $entry->{start_date}, - end_date => $entry->{end_date}, - duration => $entry->{duration}, - rms_left => $entry->{rms_left}, - rms_right => $entry->{rms_right}, - rms_image => $entry->{rms_image}, - replay_gain => $entry->{replay_gain}, - file => $entry->{file}, - errors => $entry->{errors}, - channels => $entry->{channels}, - "format" => $entry->{"format"}, - format_version => $entry->{format_version}, - format_profile => $entry->{format_profile}, - format_settings => $entry->{format_settings}, - stream_size => $entry->{stream_size}, - bitrate => $entry->{bitrate}, - bitrate_mode => $entry->{bitrate_mode}, - sampling_rate => $entry->{sampling_rate}, - writing_library => $entry->{writing_library}, - modified_at => $entry->{modified_at} - } - ); + return db::insert( + $dbh, + 'calcms_playout', + { + project_id => $entry->{project_id}, + studio_id => $entry->{studio_id}, + start => $entry->{start}, + end => $entry->{end}, + start_date => $entry->{start_date}, + end_date => $entry->{end_date}, + duration => $entry->{duration}, + rms_left => $entry->{rms_left}, + rms_right => $entry->{rms_right}, + rms_image => $entry->{rms_image}, + replay_gain => $entry->{replay_gain}, + file => $entry->{file}, + errors => $entry->{errors}, + channels => $entry->{channels}, + "format" => $entry->{"format"}, + format_version => $entry->{format_version}, + format_profile => $entry->{format_profile}, + format_settings => $entry->{format_settings}, + stream_size => $entry->{stream_size}, + bitrate => $entry->{bitrate}, + bitrate_mode => $entry->{bitrate_mode}, + sampling_rate => $entry->{sampling_rate}, + writing_library => $entry->{writing_library}, + modified_at => $entry->{modified_at} + } + ); } # delete playout entry -sub delete { - my $config = shift; - my $dbh = shift; - my $entry = shift; +sub delete($$$) { + my $config = shift; + my $dbh = shift; + my $entry = shift; - return undef unless defined $entry->{project_id}; - return undef unless defined $entry->{studio_id}; - return undef unless defined $entry->{start}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{start}; - my $query = qq{ + my $query = qq{ delete from calcms_playout where project_id=? and studio_id=? and start=? }; - my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{start} ]; - return db::put( $dbh, $query, $bind_values ); + my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{start} ]; + return db::put( $dbh, $query, $bind_values ); } -sub getEnd { - my $start = shift; - my $duration = shift; +sub getEnd ($$) { + my $start = shift; + my $duration = shift; - # calculate end from start + duration - my @start = @{ time::datetime_to_array($start) }; - next unless @start >= 6; + # calculate end from start + duration + my @start = @{ time::datetime_to_array($start) }; + next unless @start >= 6; - #print STDERR Dumper(\@start); - my @end_datetime = Date::Calc::Add_Delta_DHMS( - $start[0], $start[1], $start[2], # start date - $start[3], $start[4], $start[5], # start time - 0, 0, 0, int($duration) # delta days, hours, minutes, seconds - ); + #print STDERR Dumper(\@start); + my @end_datetime = Date::Calc::Add_Delta_DHMS( + $start[0], $start[1], $start[2], # start date + $start[3], $start[4], $start[5], # start time + 0, 0, 0, int($duration) # delta days, hours, minutes, seconds + ); - #print STDERR Dumper(\@end_datetime); - return time::array_to_datetime( \@end_datetime ); + #print STDERR Dumper(\@end_datetime); + return time::array_to_datetime( \@end_datetime ); } -sub error { - my $msg = shift; - print "ERROR: $msg
\n"; +sub error($) { + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/lib/calcms/project.pm b/lib/calcms/project.pm index 4d58c3a..1592368 100644 --- a/lib/calcms/project.pm +++ b/lib/calcms/project.pm @@ -1,7 +1,8 @@ package project; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc; @@ -24,7 +25,7 @@ our @EXPORT_OK = qw( sub debug; # get project columns -sub get_columns { +sub get_columns ($) { my $config = shift; my $dbh = db::connect($config); @@ -37,7 +38,7 @@ sub get_columns { } # get projects -sub get { +sub get ($;$) { my $config = shift; my $condition = shift; @@ -79,7 +80,7 @@ sub get { } # requires at least project_id -sub getImageById { +sub getImageById($$) { my $config = shift; my $conditions = shift; @@ -89,9 +90,10 @@ sub getImageById { return $projects->[0]->{image}; } -sub get_date_range { +sub get_date_range($) { my $config = shift; - my $query = qq{ + + my $query = qq{ select min(start_date) start_date, max(end_date) end_date from calcms_projects }; @@ -102,7 +104,7 @@ sub get_date_range { } # insert project -sub insert { +sub insert($$) { my $config = shift; my $entry = shift; @@ -120,7 +122,7 @@ sub insert { } # update project -sub update { +sub update($$) { my $config = shift; my $project = shift; @@ -148,7 +150,7 @@ sub update { } # delete project -sub delete { +sub delete ($$) { my $config = shift; my $entry = shift; @@ -157,7 +159,7 @@ sub delete { } # get studios of a project -sub get_studios { +sub get_studios($$) { my $config = shift; my $options = shift; @@ -175,7 +177,7 @@ sub get_studios { return $project_studios; } -sub get_studio_assignments { +sub get_studio_assignments($$) { my $config = shift; my $options = shift; @@ -208,7 +210,7 @@ sub get_studio_assignments { } # is studio assigned to project -sub is_studio_assigned { +sub is_studio_assigned ($$) { my $config = shift; my $entry = shift; @@ -232,7 +234,7 @@ sub is_studio_assigned { } # assign studio to project -sub assign_studio { +sub assign_studio($$) { my $config = shift; my $entry = shift; @@ -241,7 +243,7 @@ sub assign_studio { my $project_id = $entry->{project_id}; my $studio_id = $entry->{studio_id}; - if ( is_studio_assigned($entry) ) { + if ( is_studio_assigned( $config, $entry ) ) { print STDERR "studio $entry->{studio_id} already assigned to project $entry->{project_id}\n"; return 1; } @@ -251,7 +253,7 @@ sub assign_studio { } # unassign studio from project -sub unassign_studio { +sub unassign_studio($$) { my $config = shift; my $entry = shift; @@ -267,7 +269,7 @@ sub unassign_studio { } # get series by project and studio -sub get_series { +sub get_series ($$) { my $config = shift; my $options = shift; @@ -288,7 +290,7 @@ sub get_series { return $project_series; } -sub get_series_assignments { +sub get_series_assignments ($$) { my $config = shift; my $options = shift; @@ -326,7 +328,7 @@ sub get_series_assignments { } # is series assigned to project and studio -sub is_series_assigned { +sub is_series_assigned ($$) { my $config = shift; my $entry = shift; @@ -352,7 +354,7 @@ sub is_series_assigned { } # assign series to project and studio -sub assign_series { +sub assign_series($$) { my $config = shift; my $entry = shift; @@ -364,7 +366,7 @@ sub assign_series { my $studio_id = $entry->{studio_id}; my $series_id = $entry->{series_id}; - if ( is_series_assigned($entry) ) { + if ( is_series_assigned( $config, $entry ) ) { print STDERR "series $series_id already assigned to project $project_id and studio $studio_id\n"; return return undef; } @@ -376,7 +378,7 @@ sub assign_series { # unassign series from project # TODO: remove series _single_ if no event is assigned to -sub unassign_series { +sub unassign_series ($$) { my $config = shift; my $entry = shift; @@ -394,7 +396,7 @@ sub unassign_series { return db::put( $dbh, $sql, $bind_values ); } -sub get_with_dates { +sub get_with_dates($;$) { my $config = shift; my $options = shift; @@ -411,7 +413,7 @@ sub get_with_dates { } #TODO: add config -sub get_sorted { +sub get_sorted($) { my $config = shift; my $projects = project::get( $config, {} ); my @projects = reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects); @@ -428,7 +430,7 @@ sub get_sorted { } # internal -sub get_months { +sub get_months ($$;$) { my $config = shift; my $project = shift; my $language = shift || $config->{date}->{language} || 'en'; @@ -476,7 +478,7 @@ sub get_months { } # check project_id -sub check { +sub check ($$) { my $config = shift; my $options = shift; return "missing project_id at checking project" unless defined $options->{project_id}; @@ -487,7 +489,7 @@ sub check { return 1; } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/roles.pm b/lib/calcms/roles.pm index 78ce2a5..aaf4f96 100644 --- a/lib/calcms/roles.pm +++ b/lib/calcms/roles.pm @@ -1,6 +1,8 @@ package roles; -use warnings; + use strict; +use warnings; +no warnings 'redefine'; use Apache2::Reload(); @@ -102,6 +104,7 @@ my $ROLES = { sub get_user($) { my $config = shift; + my $user = $ENV{REMOTE_USER}; my $users = $config->{users}; return $user if ( defined $users->{$user} ); @@ -110,6 +113,7 @@ sub get_user($) { sub get_user_permissions($) { my $config = shift; + my $user = $ENV{REMOTE_USER} || ''; my $roles = $roles::ROLES; return $roles->{nobody} unless $user =~ /\S/; @@ -121,8 +125,9 @@ sub get_user_permissions($) { return $roles->{nobody}; } -sub get_user_jobs { +sub get_user_jobs ($;$) { my $config = shift; + my $user = $ENV{REMOTE_USER} || ''; return [] unless ( $user =~ /\S/ ); my $result = []; @@ -138,12 +143,14 @@ sub get_user_jobs { sub get_jobs($) { my $config = shift; + return $config->{jobs}->{job}; } sub get_template_parameters($$) { my $config = shift; my $user_permissions = shift; + $user_permissions = roles::get_user_permissions($config) unless defined $user_permissions; my @user_permissions = (); for my $usecase ( keys %$user_permissions ) { diff --git a/lib/calcms/series.pm b/lib/calcms/series.pm index 6377cd5..f118960 100644 --- a/lib/calcms/series.pm +++ b/lib/calcms/series.pm @@ -1,7 +1,8 @@ package series; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; @@ -28,7 +29,7 @@ our @EXPORT_OK = qw( sub debug; # get series columns -sub get_columns { +sub get_columns ($) { my $config = shift; my $dbh = db::connect($config); @@ -41,7 +42,7 @@ sub get_columns { } # get series content -sub get { +sub get ($$) { my $config = shift; my $condition = shift; @@ -132,7 +133,7 @@ sub get { } # insert series -sub insert { +sub insert ($$) { my $config = shift; my $series = shift; @@ -174,7 +175,7 @@ sub insert { } # update series -sub update { +sub update ($$) { my $config = shift; my $series = shift; @@ -210,7 +211,7 @@ sub update { # delete series, its schedules and series dates # unassign its users and events -sub delete { +sub delete($$) { my $config = shift; my $series = shift; @@ -300,7 +301,7 @@ sub delete { } # get users directly assigned to project, studio, series (editors) -sub get_users { +sub get_users ($$) { my $config = shift; my $condition = shift; @@ -346,7 +347,7 @@ sub get_users { } # assign user to series -sub add_user { +sub add_user ($$) { my $config = shift; my $entry = shift; @@ -371,12 +372,13 @@ sub add_user { insert calcms_user_series set project_id=?, studio_id=?, series_id=?, user_id=?, modified_by=?, modified_at=now() }; - $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{user_id}, $entry->{user} ]; + $bind_values = + [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{user_id}, $entry->{user} ]; db::put( $dbh, $query, $bind_values ); } # remove user(s) from series. -sub remove_user { +sub remove_user ($$) { my $config = shift; my $condition = shift; @@ -420,7 +422,7 @@ sub remove_user { #search events by series_name and title (for events not assigned yet) #TODO: add location -sub search_events { +sub search_events ($$$) { my $config = shift; my $request = shift; my $options = shift; @@ -469,7 +471,7 @@ sub search_events { } #get events (only assigned ones) by project_id,studio_id,series_id, -sub get_events { +sub get_events ($$) { my $config = shift; my $options = shift; @@ -580,7 +582,7 @@ sub get_events { # load event given by studio_id, series_id and event_id # helper for gui - errors are written to gui output # return undef on error -sub get_event { +sub get_event ($$) { my $config = shift; my $options = shift; @@ -645,7 +647,7 @@ sub get_event { } # get name and title of series and age in days ('days_over') -sub get_event_age { +sub get_event_age($$) { my $config = shift; my $options = shift; @@ -702,7 +704,7 @@ sub get_event_age { } # is event older than max_age days -sub is_event_older_than_days { +sub is_event_older_than_days ($$) { my $config = shift; my $options = shift; @@ -736,7 +738,7 @@ sub is_event_older_than_days { return 0; } -sub get_next_episode { +sub get_next_episode($$) { my $config = shift; my $options = shift; @@ -778,7 +780,7 @@ sub get_next_episode { return $max + 1; } -sub get_images { +sub get_images ($$) { my $config = shift; my $options = shift; @@ -842,7 +844,7 @@ sub get_images { #assign event to series #TODO: manual assign needs to update automatic one -sub assign_event { +sub assign_event($$) { my $config = shift; my $entry = shift; @@ -879,14 +881,15 @@ sub assign_event { insert into calcms_series_events (project_id, studio_id, series_id, event_id, manual) values (?,?,?,?,?) }; - $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{event_id}, $entry->{manual} ]; + $bind_values = + [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{event_id}, $entry->{manual} ]; #print STDERR ''.$query.Dumper($bind_values).''; return db::put( $dbh, $query, $bind_values ); } #unassign event from series -sub unassign_event { +sub unassign_event($$) { my $config = shift; my $entry = shift; @@ -913,7 +916,7 @@ sub unassign_event { # put series id to given events (for legacy handling) # used by calendar # TODO: optionally add project_id and studio_id to conditions -sub add_series_ids_to_events { +sub add_series_ids_to_events ($$) { my $config = shift; my $events = shift; @@ -961,7 +964,7 @@ sub add_series_ids_to_events { # add event_ids to series and remove all event ids from series, not given event_ids # for scan only, used at series -sub set_event_ids { +sub set_event_ids ($$$$$) { my $config = shift; my $project_id = shift; my $studio_id = shift; @@ -1037,7 +1040,7 @@ sub set_event_ids { # check if user allowed to update series events # evaluate permissions and consider editors directly assigned to series -sub can_user_update_events { +sub can_user_update_events ($$) { my $request = shift; my $options = shift; @@ -1058,7 +1061,7 @@ sub can_user_update_events { # check if user allowed to create series events # evaluate permissions and consider editors directly assigned to series -sub can_user_create_events { +sub can_user_create_events ($$) { my $request = shift; my $options = shift; @@ -1077,7 +1080,7 @@ sub can_user_create_events { return is_series_assigned_to_user( $request, $options ); } -sub is_series_assigned_to_user { +sub is_series_assigned_to_user ($$) { my $request = shift; my $options = shift; @@ -1104,7 +1107,7 @@ sub is_series_assigned_to_user { # check if user is assigned to studio where location matchs to event # return 1 on success or error text -sub is_event_assigned_to_user { +sub is_event_assigned_to_user ($$) { my $request = shift; my $options = shift; @@ -1157,7 +1160,7 @@ sub is_event_assigned_to_user { # to find multiple recurrences this does not include the recurrence_count # use events::get_key to add the recurrence -sub get_event_key { +sub get_event_key ($) { my $event = shift; my $program = $event->{program} || ''; @@ -1176,7 +1179,7 @@ sub get_event_key { return $key; } -sub update_recurring_events { +sub update_recurring_events ($$) { my $config = shift; my $options = shift; @@ -1217,7 +1220,7 @@ sub update_recurring_events { next if $event->{recurrence} == 0; next if $event->{recurrence_count} == 0; print STDERR - "remove recurrence\t'$event->{event_id}'\t'$event->{start}'\t'$event->{rerun}'\t'$event->{recurrence}'\t'$event->{key}'\n"; +"remove recurrence\t'$event->{event_id}'\t'$event->{start}'\t'$event->{rerun}'\t'$event->{recurrence}'\t'$event->{key}'\n"; $event->{recurrence} = 0; $event->{recurrence_count} = 0; $event->{rerun} = 0; @@ -1253,7 +1256,7 @@ sub update_recurring_events { } } -sub update_recurring_event { +sub update_recurring_event($$) { my $config = shift; my $event = shift; @@ -1284,7 +1287,7 @@ sub update_recurring_event { db::put( $dbh, $update_sql, $bind_values ); } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/series_dates.pm b/lib/calcms/series_dates.pm index 0370708..c69b650 100644 --- a/lib/calcms/series_dates.pm +++ b/lib/calcms/series_dates.pm @@ -1,7 +1,8 @@ package series_dates; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc(); @@ -16,11 +17,11 @@ use series_schedule(); # columns: id, studio_id, series_id, start(datetime), end(datetime) # TODO: delete column schedule_id use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get insert update delete get_dates get_series); +our @EXPORT_OK = qw(get_columns get insert update delete get_dates get_series); sub debug; -sub get_columns { +sub get_columns ($) { my $config = shift; my $dbh = db::connect($config); @@ -34,7 +35,7 @@ sub get_columns { # 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) -sub get { +sub get ($;$) { my $config = shift; my $condition = shift; @@ -47,7 +48,6 @@ sub get { push @conditions, 'project_id=?'; push @bind_values, $condition->{project_id}; } - if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) { push @conditions, 'studio_id=?'; push @bind_values, $condition->{studio_id}; @@ -116,7 +116,7 @@ sub get { } #check if event is scheduled (on permission check) -sub is_event_scheduled { +sub is_event_scheduled($$) { my $request = shift; my $options = shift; @@ -140,12 +140,13 @@ sub is_event_scheduled { } #get all series for given studio_id, time range and search -sub get_series { +sub get_series($;$) { my $config = shift; my $condition = shift; 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); @@ -259,7 +260,7 @@ sub get_series { return $entries; } -sub addSeriesScheduleAttributes { +sub addSeriesScheduleAttributes ($$) { my $config = shift; my $entries = shift; @@ -295,7 +296,7 @@ sub addSeriesScheduleAttributes { } #update series dates for all schedules of a series and studio_id -sub update { +sub update($$) { my $config = shift; my $entry = shift; @@ -383,7 +384,7 @@ sub update { return $j . " dates out of studio times, " . $i; } -sub get_schedule_dates { +sub get_schedule_dates($$) { my $schedule = shift; my $options = shift; @@ -412,7 +413,7 @@ sub get_schedule_dates { return $dates; } -sub get_week_of_month_dates { +sub get_week_of_month_dates ($$$$$$$) { my $start = shift; # datetime string my $end = shift; # datetime string my $duration = shift; # in minutes @@ -463,7 +464,7 @@ sub get_week_of_month_dates { } #add duration to a single date -sub get_single_date { +sub get_single_date ($$) { my $start_datetime = shift; my $duration = shift; @@ -483,12 +484,12 @@ sub get_single_date { } #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 $end_date = shift; my $duration = shift; # in minutes 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) }; return unless @start >= 6; @@ -540,7 +541,7 @@ sub get_dates { } #remove all series_dates for studio_id and series_id -sub delete { +sub delete ($$) { my $config = shift; my $entry = shift; @@ -562,7 +563,7 @@ sub delete { } # get all series dates where no event has been created for -sub getDatesWithoutEvent { +sub getDatesWithoutEvent ($$) { my $config = shift; my $options = shift; @@ -592,7 +593,7 @@ sub getDatesWithoutEvent { } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/series_events.pm b/lib/calcms/series_events.pm index ddf5270..e912d60 100644 --- a/lib/calcms/series_events.pm +++ b/lib/calcms/series_events.pm @@ -1,7 +1,8 @@ package series_events; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc; @@ -36,7 +37,7 @@ sub debug; # update main fields of the event by id # do not check for project,studio,series # all changed columns are returned for history handling -sub save_content { +sub save_content($$) { my $config = shift; my $entry = shift; @@ -114,7 +115,7 @@ sub save_content { # save event time by id # do not check project, studio, series # for history handling all changed columns are returned -sub save_event_time { +sub save_event_time($$) { my $config = shift; my $entry = shift; @@ -165,7 +166,7 @@ sub save_event_time { return $event; } -sub set_playout_status { +sub set_playout_status ($$) { my $config = shift; my $entry = shift; @@ -208,7 +209,7 @@ sub set_playout_status { } # is event assigned to project, studio and series? -sub is_event_assigned { +sub is_event_assigned($$) { my $config = shift; my $entry = shift; @@ -230,7 +231,7 @@ sub is_event_assigned { return 0; } -sub delete_event { +sub delete_event ($$) { my $config = shift; my $entry = shift; @@ -269,7 +270,7 @@ sub delete_event { # key permission: permissions to be checked (one of) # key check_for: user, studio, series, events, schedule # return error text or 1 if okay -sub check_permission { +sub check_permission($$) { my $request = shift; my $options = shift; @@ -294,7 +295,7 @@ sub check_permission { #check if permissions are set (like create_event) my $found = 0; 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; delete $options->{permission}; @@ -343,7 +344,8 @@ sub check_permission { } 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 @@ -412,7 +414,7 @@ sub check_permission { # category, time_of_day, #insert event -sub insert_event { +sub insert_event ($$) { my $config = shift; my $options = shift; @@ -443,7 +445,11 @@ sub insert_event { $event = series_events::add_event_dates( $config, $event, $params ); #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->{series_image} = $serie->{image} if defined $serie->{image}; @@ -488,7 +494,7 @@ sub insert_event { } #set start, end, start-date, end_date to an event -sub add_event_dates { +sub add_event_dates($$$) { my $config = shift; my $event = shift; my $params = shift; @@ -504,7 +510,7 @@ sub add_event_dates { return $event; } -sub update_series_images { +sub update_series_images ($$) { my $config = shift; my $options = shift; @@ -530,7 +536,7 @@ sub update_series_images { } } -sub error { +sub error ($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/series_schedule.pm b/lib/calcms/series_schedule.pm index 2738570..7e83176 100644 --- a/lib/calcms/series_schedule.pm +++ b/lib/calcms/series_schedule.pm @@ -1,7 +1,9 @@ package series_schedule; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; + use Data::Dumper; use series_dates(); @@ -17,168 +19,168 @@ use series_dates(); # nextDay (add 24 hours to start) use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get insert update delete); +our @EXPORT_OK = qw(get_columns get insert update delete); sub debug; -sub get_columns { - my $config = shift; +sub get_columns ($) { + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_series_schedule' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_series_schedule' ); + my $columns = {}; + for my $col (@$cols) { + $columns->{$col} = 1; + } + return $columns; } #map schedule id to id -sub get { - my $config = shift; - my $condition = shift; +sub get($$) { + my $config = shift; + my $condition = shift; - my $dbh = db::connect($config); + my $dbh = db::connect($config); - my @conditions = (); - my @bind_values = (); + my @conditions = (); + my @bind_values = (); - if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) { - push @conditions, 'project_id=?'; - push @bind_values, $condition->{project_id}; - } - if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) { - push @conditions, 'studio_id=?'; - push @bind_values, $condition->{studio_id}; - } + if ( ( defined $condition->{project_id} ) && ( $condition->{project_id} ne '' ) ) { + push @conditions, 'project_id=?'; + push @bind_values, $condition->{project_id}; + } + if ( ( defined $condition->{studio_id} ) && ( $condition->{studio_id} ne '' ) ) { + push @conditions, 'studio_id=?'; + push @bind_values, $condition->{studio_id}; + } - if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) { - push @conditions, 'series_id=?'; - push @bind_values, $condition->{series_id}; - } + if ( ( defined $condition->{series_id} ) && ( $condition->{series_id} ne '' ) ) { + push @conditions, 'series_id=?'; + push @bind_values, $condition->{series_id}; + } - if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { - push @conditions, 'id=?'; - push @bind_values, $condition->{schedule_id}; - } + if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { + push @conditions, 'id=?'; + push @bind_values, $condition->{schedule_id}; + } - if ( ( defined $condition->{schedule_ids} ) && ( ref( $condition->{schedule_ids} ) eq 'ARRAY' ) ) { - my @scheduleIds = @{ $condition->{schedule_ids} }; - push @conditions, 'id in (' . ( join( ',', ( map { '?' } @scheduleIds ) ) ) . ')'; - for my $id (@scheduleIds) { - push @bind_values, $id; - } - } + if ( ( defined $condition->{schedule_ids} ) && ( ref( $condition->{schedule_ids} ) eq 'ARRAY' ) ) { + my @scheduleIds = @{ $condition->{schedule_ids} }; + push @conditions, 'id in (' . ( join( ',', ( map { '?' } @scheduleIds ) ) ) . ')'; + for my $id (@scheduleIds) { + push @bind_values, $id; + } + } - if ( ( defined $condition->{start} ) && ( $condition->{start} ne '' ) ) { - push @conditions, 'start=?'; - push @bind_values, $condition->{start}; - } + if ( ( defined $condition->{start} ) && ( $condition->{start} ne '' ) ) { + push @conditions, 'start=?'; + push @bind_values, $condition->{start}; + } - if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) { - push @conditions, 'exclude=?'; - push @bind_values, $condition->{exclude}; - } + if ( ( defined $condition->{exclude} ) && ( $condition->{exclude} ne '' ) ) { + push @conditions, 'exclude=?'; + push @bind_values, $condition->{exclude}; + } - if ( ( defined $condition->{period_type} ) && ( $condition->{period_type} ne '' ) ) { - push @conditions, 'period_type=?'; - push @bind_values, $condition->{period_type}; - } + if ( ( defined $condition->{period_type} ) && ( $condition->{period_type} ne '' ) ) { + push @conditions, 'period_type=?'; + push @bind_values, $condition->{period_type}; + } - my $conditions = ''; - $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); + my $conditions = ''; + $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); - my $query = qq{ + my $query = qq{ select * from calcms_series_schedule $conditions order by exclude, start }; - #print STDERR $query."\n".Dumper(\@bind_values); + #print STDERR $query."\n".Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); - for my $entry (@$entries) { - $entry->{schedule_id} = $entry->{id}; - delete $entry->{id}; - } + my $entries = db::get( $dbh, $query, \@bind_values ); + for my $entry (@$entries) { + $entry->{schedule_id} = $entry->{id}; + delete $entry->{id}; + } - #print STDERR Dumper($entries); - return $entries; + #print STDERR Dumper($entries); + return $entries; } -sub insert { - my $config = shift; - my $entry = shift; +sub insert($$) { + my $config = shift; + my $entry = shift; - return undef unless defined $entry->{project_id}; - return undef unless defined $entry->{studio_id}; - return undef unless defined $entry->{series_id}; - return undef unless defined $entry->{start}; - my $dbh = db::connect($config); - return db::insert( $dbh, 'calcms_series_schedule', $entry ); + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{series_id}; + return undef unless defined $entry->{start}; + my $dbh = db::connect($config); + return db::insert( $dbh, 'calcms_series_schedule', $entry ); } #schedule id to id -sub update { - my $config = shift; - my $entry = shift; +sub update($$) { + my $config = shift; + my $entry = shift; - return undef unless defined $entry->{project_id}; - return undef unless defined $entry->{studio_id}; - return undef unless defined $entry->{series_id}; - return undef unless defined $entry->{schedule_id}; - return undef unless defined $entry->{start}; - $entry->{nextDay} = 0 unless defined $entry->{nextDay}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{series_id}; + return undef unless defined $entry->{schedule_id}; + return undef unless defined $entry->{start}; + $entry->{nextDay} = 0 unless defined $entry->{nextDay}; - $entry->{id} = $entry->{schedule_id}; - delete $entry->{schedule_id}; + $entry->{id} = $entry->{schedule_id}; + delete $entry->{schedule_id}; - my $dbh = db::connect($config); - my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) ); - my @bind_values = map { $entry->{$_} } ( keys %$entry ); + my $dbh = db::connect($config); + my $values = join( ",", map { $_ . '=?' } ( keys %$entry ) ); + my @bind_values = map { $entry->{$_} } ( keys %$entry ); - push @bind_values, $entry->{project_id}; - push @bind_values, $entry->{studio_id}; - push @bind_values, $entry->{id}; + push @bind_values, $entry->{project_id}; + push @bind_values, $entry->{studio_id}; + push @bind_values, $entry->{id}; - my $query = qq{ + my $query = qq{ update calcms_series_schedule set $values where project_id=? and studio_id=? and id=? }; - #print STDERR Dumper($query).Dumper(\@bind_values); - db::put( $dbh, $query, \@bind_values ); - print "done\n"; + #print STDERR Dumper($query).Dumper(\@bind_values); + db::put( $dbh, $query, \@bind_values ); + print "done\n"; } #map schedule id to id -sub delete { - my $config = shift; - my $entry = shift; +sub delete($$) { + my $config = shift; + my $entry = shift; - return undef unless defined $entry->{project_id}; - return undef unless defined $entry->{studio_id}; - return undef unless defined $entry->{series_id}; - return undef unless defined $entry->{schedule_id}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{series_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 from calcms_series_schedule where project_id=? and studio_id=? and series_id=? and id=? }; - my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{schedule_id} ]; + my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{series_id}, $entry->{schedule_id} ]; - #print '$query'.$query.Dumper($bind_values).''; - db::put( $dbh, $query, $bind_values ); + #print '$query'.$query.Dumper($bind_values).''; + db::put( $dbh, $query, $bind_values ); } -sub error { - my $msg = shift; - print "ERROR: $msg
\n"; +sub error($) { + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/lib/calcms/startup.pl b/lib/calcms/startup.pl index 55a6121..85080c5 100644 --- a/lib/calcms/startup.pl +++ b/lib/calcms/startup.pl @@ -2,8 +2,6 @@ use lib qw(/home/radio/calcms/calcms/); use Data::Dumper; use Apache::DBI(); -#$Apache::DBI::DEBUG = 2; - use Time::Local(); use Date::Calc(); use Calendar::Simple qw(date_span); @@ -12,7 +10,6 @@ use config(); use log(); use time(); use db(); -use cache(); use template(); #do not delete last line! diff --git a/lib/calcms/studio_timeslot_dates.pm b/lib/calcms/studio_timeslot_dates.pm index 82b542d..bc60517 100644 --- a/lib/calcms/studio_timeslot_dates.pm +++ b/lib/calcms/studio_timeslot_dates.pm @@ -1,7 +1,8 @@ package studio_timeslot_dates; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc(); @@ -16,7 +17,7 @@ our @EXPORT_OK = qw(get_columns get insert update delete get_dates); sub debug; -sub get_columns { +sub get_columns ($){ my $config = shift; my $dbh = db::connect($config); @@ -30,7 +31,7 @@ sub get_columns { # get all studio_timeslot_dates for studio_id within given time range # calculate start_date, end_date, weeday, day from start and end(datetime) -sub get { +sub get ($$){ my $config = shift; my $condition = shift; diff --git a/lib/calcms/studio_timeslot_schedule.pm b/lib/calcms/studio_timeslot_schedule.pm index 9f45da7..26459ba 100644 --- a/lib/calcms/studio_timeslot_schedule.pm +++ b/lib/calcms/studio_timeslot_schedule.pm @@ -1,7 +1,8 @@ package studio_timeslot_schedule; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use studio_timeslot_dates(); @@ -14,7 +15,7 @@ our @EXPORT_OK = qw(get_columns get insert update delete); sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -27,7 +28,7 @@ sub get_columns { } #map schedule id to id -sub get { +sub get($$) { my $config = shift; my $condition = shift; @@ -70,7 +71,7 @@ sub get { return $entries; } -sub insert { +sub insert($$) { my $config = shift; my $entry = shift; @@ -85,7 +86,7 @@ sub insert { } #schedule id to id -sub update { +sub update($$) { my $config = shift; my $entry = shift; @@ -119,7 +120,7 @@ sub update { } #map schedule id to id -sub delete { +sub delete ($$){ my $config = shift; my $entry = shift; @@ -138,7 +139,7 @@ sub delete { db::put( $dbh, $query, $bind_values ); } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/studios.pm b/lib/calcms/studios.pm index 8cbe95d..0288da5 100644 --- a/lib/calcms/studios.pm +++ b/lib/calcms/studios.pm @@ -1,7 +1,8 @@ package studios; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use images(); @@ -11,7 +12,7 @@ our @EXPORT_OK = qw(get_columns get get_by_id insert update delete check check_s sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -22,8 +23,7 @@ sub get_columns { } return $columns; } - -sub get { +sub get($;$) { my $config = shift; my $condition = shift || {}; @@ -61,7 +61,7 @@ sub get { $limit }; } else { - push @conditions, 's.id=ps.studio_id'; + push @conditions, 's.id=ps.studio_id'; push @conditions, 'ps.project_id=?'; push @bind_values, $condition->{project_id}; @@ -80,7 +80,7 @@ sub get { return $studios; } -sub getImageById { +sub getImageById($$) { my $config = shift; my $conditions = shift; @@ -91,7 +91,7 @@ sub getImageById { return $studios->[0]->{image}; } -sub insert { +sub insert ($$) { my $config = shift; my $entry = shift; @@ -104,7 +104,7 @@ sub insert { return $id; } -sub update { +sub update ($$) { my $config = shift; my $studio = shift; @@ -133,7 +133,7 @@ sub update { db::put( $dbh, $query, \@bind_values ); } -sub delete { +sub delete ($$) { my $config = shift; my $studio = shift; @@ -142,13 +142,13 @@ sub delete { } #TODO rename to check -sub check_studio { +sub check_studio($$) { my $config = shift; my $options = shift; return check( $config, $options ); } -sub check { +sub check ($$) { my $config = shift; my $options = shift; return "missing studio_id" unless defined $options->{studio_id}; diff --git a/lib/calcms/tags.pm b/lib/calcms/tags.pm index 65aafb3..3252531 100644 --- a/lib/calcms/tags.pm +++ b/lib/calcms/tags.pm @@ -1,13 +1,14 @@ package tags; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use base 'Exporter'; our @EXPORT_OK = qw(get_tags); -sub get_tags { +sub get_tags($) { my $dbh = shift; my $query = qq{ select name, count(name) sum from calcms_tags diff --git a/lib/calcms/template.pm b/lib/calcms/template.pm index a84cea5..03eabe9 100644 --- a/lib/calcms/template.pm +++ b/lib/calcms/template.pm @@ -1,11 +1,13 @@ package template; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use HTML::Template::Compiled(); use HTML::Template::Compiled::Plugin::XMLEscape(); + #use HTML::Template::JIT(); use JSON(); use Cwd(); @@ -20,7 +22,7 @@ use base 'Exporter'; our @EXPORT_OK = qw(check process exit_on_missing_permission clear_cache); # TODO:config -sub process { +sub process($$$$) { my $config = $_[0]; # my $output=$_[1]; @@ -47,7 +49,8 @@ sub process { my $user_permissions = roles::get_user_permissions($config); 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($config); @@ -65,25 +68,28 @@ sub process { return; } - unless (-r $filename){ - log::error($config, qq{template "$filename" does not exist}) unless -e $filename; - log::error($config, qq{missing permissions to read "$filename"}); + unless ( -r $filename ) { + log::error( $config, qq{template "$filename" does not exist} ) unless -e $filename; + log::error( $config, qq{missing permissions to read "$filename"} ); } my $html_template = initTemplate($filename); - setRelativeUrls( $params, 0 ) unless ( defined $params->{extern} ) && ( $params->{extern} eq '1' ); + setRelativeUrls( $params, 0 ) + unless ( defined $params->{extern} ) && ( $params->{extern} eq '1' ); $html_template->param($params); my $output = $html_template->output(); - if ($filename=~/html/){ - my ($header, $content) = split(/\n\n/, $output, 2); - if ($content){ - #$content =~s/\s+/ /g; - $output = $header."\n\n".$content; - }else{ - #$output =~s/[ \t]+/ /g; - } - } + if ( $filename =~ /html/ ) { + my ( $header, $content ) = split( /\n\n/, $output, 2 ); + if ($content) { + + #$content =~s/\s+/ /g; + $output = $header . "\n\n" . $content; + } else { + + #$output =~s/[ \t]+/ /g; + } + } if ( ( defined $_[1] ) && ( $_[1] eq 'print' ) ) { print $output; @@ -92,8 +98,8 @@ sub process { } } -sub initTemplate{ - my $filename=shift; +sub initTemplate($) { + my $filename = shift; my $default_escape = 'none'; $default_escape = 'js' if ( $filename =~ /\.js$/ ); @@ -113,7 +119,7 @@ sub initTemplate{ utf8 => 1, plugin => [qw(HTML::Template::Compiled::Plugin::XMLEscape)], ); - } + } return HTML::Template::Compiled->new( filename => $filename, @@ -125,12 +131,15 @@ sub initTemplate{ default_escape => $default_escape, cache => 1, utf8 => 1, -#pre_chomp => 1, -#post_chomp => 1, + + #pre_chomp => 1, + #post_chomp => 1, ); } # set relative urls in nested params structure +sub setRelativeUrls; + sub setRelativeUrls { my $params = shift; my $depth = shift || 0; @@ -179,7 +188,7 @@ sub setRelativeUrls { #requires read config #TODO:add config -sub check { +sub check($;$$) { my $config = shift; my $template = shift || ''; my $default = shift; @@ -207,7 +216,9 @@ sub check { my $cwd = Cwd::getcwd(); $template .= '.html' unless ( $template =~ /\./ ); - if ( ( $config->{cache}->{compress} eq '1' ) && ( -e $cwd . '/templates/compressed/' . $template ) ) { + if ( ( $config->{cache}->{compress} eq '1' ) + && ( -e $cwd . '/templates/compressed/' . $template ) ) + { $template = $cwd . '/templates/compressed/' . $template; } elsif ( -e $cwd . '/templates/' . $template ) { $template = $cwd . '/templates/' . $template; @@ -216,29 +227,36 @@ sub check { } - 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; } #deprecated (for old admin only) -sub exit_on_missing_permission { - my $config = shift; - my $permission = shift; +sub exit_on_missing_permission($$) { + my $config = shift; + my $permission = shift; + my $user_permissions = roles::get_user_permissions($config); if ( $user_permissions->{$permission} ne '1' ) { print STDERR "missing permission to $permission\n"; - template::process( $config, 'print', template::check( $config, 'default.html' ), { error => 'sorry, missing permission!' } ); + template::process( + $config, 'print', + template::check( $config, 'default.html' ), + { error => 'sorry, missing permission!' } + ); die(); } } +#do not delete last line! +1; + +__END__ sub clear_cache { HTML::Template::Compiled->clear_cache(); - # return; - # my $html_template = HTML::Template::Compiled->new(); - # $html_template->clear_cache(); + # return; + # my $html_template = HTML::Template::Compiled->new(); + # $html_template->clear_cache(); } - -#do not delete last line! -1; diff --git a/lib/calcms/time.pm b/lib/calcms/time.pm index 512928d..1688f0a 100644 --- a/lib/calcms/time.pm +++ b/lib/calcms/time.pm @@ -1,7 +1,8 @@ package time; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use utf8; use Time::Local(); @@ -73,32 +74,32 @@ my $DURATIONS = [ 120, 135, 150, 165, 180, 195, 210, 225, 240, 300, 360, 420, 480, 540, 600, 660, 720, 1440 ]; -sub getDurations { +sub getDurations() { return $DURATIONS; } -sub getWeekdayNames { +sub getWeekdayNames(;$) { my $language = shift || 'en'; return $NAMES->{$language}->{weekdays}; } -sub getWeekdayNamesShort { +sub getWeekdayNamesShort(;$) { my $language = shift || 'en'; return $NAMES->{$language}->{weekdays_abbr}; } -sub getMonthNames { +sub getMonthNames(;$) { my $language = shift || 'en'; return $NAMES->{$language}->{months}; } -sub getMonthNamesShort { +sub getMonthNamesShort(;$) { my $language = shift || 'en'; return $NAMES->{$language}->{months_abbr}; } -sub getWeekdayIndex($) { +sub getWeekdayIndex(;$) { my $weekday = shift || ''; return $WEEKDAY_INDEX->{$weekday}; } @@ -128,14 +129,14 @@ sub getWeekdays { } #deprecated, for wordpress sync -sub format_datetime { +sub format_datetime(;$) { my $datetime = shift; return $datetime if ( $datetime eq '' ); return add_hours_to_datetime( $datetime, 0 ); } #deprecated -sub format_time { +sub format_time($) { my $t = $_[0]; my $year = $t->[5] + 1900; @@ -155,7 +156,7 @@ sub format_time { } # convert datetime to unix time -sub datetime_to_time { +sub datetime_to_time ($){ my $datetime = $_[0]; # print $datetime."\n"; @@ -167,7 +168,6 @@ sub datetime_to_time { my $minute = $5; my $second = $8 || 0; return Time::Local::timelocal( $second, $minute, $hour, $day, $month, $year ) || print STDERR "datetime_to_time: no valid date time found! ($datetime)\n"; - ; } else { print STDERR "datetime_to_time: no valid date time found! ($datetime)\n"; @@ -176,14 +176,14 @@ sub datetime_to_time { } #get rfc822 datetime string from datetime string -sub datetime_to_rfc822 { +sub datetime_to_rfc822($) { my $datetime = $_[0]; my $time = datetime_to_time($datetime); return POSIX::strftime( "%a, %d %b %Y %H:%M:%S %z", localtime($time) ); } #get seconds from epoch -sub datetime_to_utc { +sub datetime_to_utc($$) { my $datetime = shift; my $time_zone = shift; $datetime = get_datetime( $datetime, $time_zone ); @@ -191,7 +191,7 @@ sub datetime_to_utc { } # get full utc datetime including timezone offset -sub datetime_to_utc_datetime { +sub datetime_to_utc_datetime($$) { my $datetime = shift; my $time_zone = shift; $datetime = get_datetime( $datetime, $time_zone ); @@ -199,7 +199,7 @@ sub datetime_to_utc_datetime { } #add hours to datetime string -sub add_hours_to_datetime { +sub add_hours_to_datetime($;$) { my $datetime = shift; my $hours = shift; $hours = 0 unless defined $hours; @@ -207,7 +207,7 @@ sub add_hours_to_datetime { } #add minutes to datetime string -sub add_minutes_to_datetime { +sub add_minutes_to_datetime($;$) { my $datetime = shift; my $minutes = shift; $minutes = 0 unless defined $minutes; @@ -215,7 +215,7 @@ sub add_minutes_to_datetime { } #add days to datetime string -sub add_days_to_datetime { +sub add_days_to_datetime($;$) { my $datetime = shift; my $days = shift; $days = 0 unless defined $days; @@ -226,7 +226,7 @@ sub add_days_to_datetime { return array_to_datetime($time); } -sub add_days_to_date { +sub add_days_to_date($;$) { my $datetime = shift; my $days = shift; $days = 0 unless defined $days; @@ -236,7 +236,7 @@ sub add_days_to_date { } # convert unix time to datetime format -sub time_to_datetime { +sub time_to_datetime(;$) { my $time = shift; $time = time() unless ( defined $time ) && ( $time ne '' ); my @t = localtime($time); @@ -244,7 +244,7 @@ sub time_to_datetime { } # convert unix time to date format -sub time_to_date { +sub time_to_date(;$) { my $time = shift; $time = time() unless ( defined $time ) && ( $time ne '' ); my @t = localtime($time); @@ -252,7 +252,7 @@ sub time_to_date { } # convert datetime to a array of date/time values -sub datetime_to_array { +sub datetime_to_array(;$) { my $datetime = $_[0] || ''; if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)([T\s]+(\d+)\:(\d+)(\:(\d+))?)?/ ) { my $year = $1; @@ -267,7 +267,7 @@ sub datetime_to_array { } # convert datetime to date -sub datetime_to_date { +sub datetime_to_date(;$) { my $datetime = $_[0] || ''; if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) { my $year = $1; @@ -279,7 +279,7 @@ sub datetime_to_date { } #convert datetime array or single value to datetime string -sub array_to_datetime { +sub array_to_datetime(;$) { my $date = shift; 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] ); @@ -293,7 +293,7 @@ sub array_to_datetime { } #convert date array or single values to date string -sub array_to_date { +sub array_to_date($;$$) { my $date = shift; if ( ref($date) eq 'ARRAY' ) { return sprintf( "%04d-%02d-%02d", $date->[0], $date->[1], $date->[2] ); @@ -303,7 +303,7 @@ sub array_to_date { return sprintf( "%04d-%02d-%02d", $date, $month, $day ); } -sub array_to_time { +sub array_to_time(;$) { my $date = shift; if ( ref($date) eq 'ARRAY' ) { return sprintf( "%02d:%02d:%02d", $date->[3], $date->[4], $date->[5] ); @@ -313,7 +313,7 @@ sub array_to_time { return sprintf( "%02d:%02d:%02d", $date, $minute, $second ); } -sub array_to_time_hm { +sub array_to_time_hm(;$) { my $date = shift; if ( ref($date) eq 'ARRAY' ) { return sprintf( "%02d:%02d", $date->[3], $date->[4] ); @@ -323,14 +323,14 @@ sub array_to_time_hm { } # get number of days between two days -sub days_between { +sub days_between($$) { my $today = $_[0]; my $date = $_[1]; my $delta_days = eval { Date::Calc::Delta_Days( $today->[0], $today->[1], $today->[2], $date->[0], $date->[1], $date->[2] ) }; return $delta_days; } -sub dayOfYear { +sub dayOfYear($) { my $datetime = $_[0]; if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) { my $year = $1; @@ -342,7 +342,7 @@ sub dayOfYear { } # get duration in minutes -sub get_duration { +sub get_duration($$$) { my $start = shift; my $end = shift; my $timezone = shift; @@ -353,7 +353,7 @@ sub get_duration { } # get duration in seconds -sub get_duration_seconds { +sub get_duration_seconds($$;$) { my $start = shift; my $end = shift; my $timezone = shift || 'UTC'; @@ -382,7 +382,7 @@ sub get_duration_seconds { } # convert date string to a array of date values -sub date_to_array { +sub date_to_array($) { my $datetime = $_[0]; if ( $datetime =~ /(\d\d\d\d)\-(\d+)\-(\d+)/ ) { my $year = $1; @@ -395,7 +395,7 @@ sub date_to_array { # parse date string and return date string # pass 'today', return '' on parse error -sub date_cond { +sub date_cond($) { my $date = shift; return '' if ( $date eq '' ); @@ -411,7 +411,7 @@ sub date_cond { #parse time and return time string hh:mm:ss #return hh:00 if time is 'now' -sub time_cond { +sub time_cond($) { my $time = shift; return '' if ( $time eq '' ); @@ -432,7 +432,7 @@ sub time_cond { } #parse date and time string and return yyyy-mm-ddThh:mm:ss -sub datetime_cond { +sub datetime_cond($) { my $datetime = shift; return '' if ( $datetime eq '' ); @@ -445,7 +445,7 @@ sub datetime_cond { return $date . 'T' . $time; } -sub check_date { +sub check_date($) { my $date = shift; return "" if ( !defined $date ) || ( $date eq '' ); @@ -460,7 +460,7 @@ sub check_date { #error("no valid date format given!"); } -sub check_time { +sub check_time($) { my $time = shift; return "" if ( !defined $time ) || ( $time eq '' ); return $time if ( $time eq 'now' ) || ( $time eq 'future' ); @@ -470,7 +470,7 @@ sub check_time { return -1; } -sub check_datetime { +sub check_datetime($) { my $date = shift; return "" if ( !defined $date ) || ( $date eq '' ); @@ -480,7 +480,7 @@ sub check_datetime { return -1; } -sub check_year_month { +sub check_year_month($) { my $date = shift; return -1 unless ( defined $date ); return $date if ( $date eq '' ); @@ -491,7 +491,7 @@ sub check_year_month { } #TODO: remove config dependency -sub date_time_format { +sub date_time_format($$;$) { my $config = shift; my $datetime = shift; my $language = shift || $config->{date}->{language} || 'en'; @@ -509,7 +509,7 @@ sub date_time_format { #format datetime to date string #TODO: remove config dependency -sub date_format { +sub date_format($$;$) { my $config = shift; my $datetime = shift; my $language = shift || $config->{date}->{language} || 'en'; @@ -525,7 +525,7 @@ sub date_format { } #format datetime to time string -sub time_format { +sub time_format($) { my $datetime = shift; if ( defined $datetime && $datetime =~ /(\d\d?\:\d\d?)/ ) { return $1; @@ -534,7 +534,7 @@ sub time_format { } #get offset from given time_zone -sub utc_offset { +sub utc_offset($) { my $time_zone = shift; my $datetime = DateTime->now(); @@ -543,7 +543,7 @@ sub utc_offset { } #get weekday from (yyyy,mm,dd) -sub weekday { +sub weekday($$$) { my ( $year, $month, $day ) = @_; my $time = Time::Local::timelocal( 0, 0, 0, $day, $month - 1, $year ); return ( localtime($time) )[6]; @@ -551,7 +551,7 @@ sub weekday { #get current date, related to starting day_starting_hour #TODO: remove config dependency -sub get_event_date { +sub get_event_date($) { my $config = shift; my $datetime = time::time_to_datetime( time() ); @@ -571,7 +571,7 @@ sub get_event_date { } #get datetime object from datetime string -sub get_datetime { +sub get_datetime(;$$) { my $datetime = shift; my $timezone = shift; @@ -599,7 +599,7 @@ sub get_datetime { } #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 $end = shift; # datetime string my $nth = shift; # every nth week of month diff --git a/lib/calcms/uac.pm b/lib/calcms/uac.pm index 476f761..0c99153 100644 --- a/lib/calcms/uac.pm +++ b/lib/calcms/uac.pm @@ -1,6 +1,8 @@ package uac; -use warnings "all"; + use strict; +use warnings; +no warnings 'redefine'; use CGI::Session qw(-ip-match); use CGI::Cookie(); @@ -28,7 +30,7 @@ our @EXPORT_OK = qw( sub debug; # get user by name -sub get_user { +sub get_user($$) { my $config = shift; my $user = shift; @@ -49,7 +51,7 @@ sub get_user { } # get all users -sub get_users { +sub get_users($;$) { my $config = shift; my $condition = shift; @@ -82,7 +84,7 @@ sub get_users { # get all users of a given studio id # used at series (previously named get_studio_users) -sub get_users_by_studio { +sub get_users_by_studio ($$) { my $config = shift; my $condition = shift; @@ -117,7 +119,7 @@ sub get_users_by_studio { } # get projects a user is assigned by name -sub get_projects_by_user { +sub get_projects_by_user ($$) { my $config = shift; my $condition = shift; @@ -156,7 +158,7 @@ sub get_projects_by_user { # get all studios a user is assigned to by role # used at series (previously named get_user_studios) -sub get_studios_by_user { +sub get_studios_by_user ($$) { my $config = shift; my $condition = shift; @@ -192,7 +194,7 @@ sub get_studios_by_user { return $users; } -sub insert_user { +sub insert_user($$) { my $config = shift; my $entry = shift; @@ -203,7 +205,7 @@ sub insert_user { db::insert( $dbh, 'calcms_users', $entry ); } -sub update_user { +sub update_user($$) { my $config = shift; my $entry = shift; @@ -223,7 +225,7 @@ sub update_user { db::put( $dbh, $query, \@bind_values ); } -sub delete_user { +sub delete_user($$) { my $config = shift; my $id = shift; return unless ( defined $id && ( $id =~ /^\d+$/ ) ); @@ -238,7 +240,7 @@ sub delete_user { # get all roles used by all users of a studio # available conditions: project_id, studio_id -sub get_studio_roles { +sub get_studio_roles($$) { my $config = shift; my $condition = shift; @@ -273,7 +275,7 @@ sub get_studio_roles { } # get role columns (for external use only) -sub get_role_columns { +sub get_role_columns($) { my $config = shift; my $dbh = db::connect($config); my $columns = db::get_columns_hash( $dbh, 'calcms_roles' ); @@ -282,7 +284,7 @@ sub get_role_columns { # get roles # filter: studio_id project_id -sub get_roles { +sub get_roles($$) { my $config = shift; my $condition = shift; @@ -313,7 +315,7 @@ sub get_roles { } #insert role to database, set created_at and modified_at -sub insert_role { +sub insert_role ($$) { my $config = shift; my $entry = shift; @@ -330,7 +332,7 @@ sub insert_role { } #update role, set modified_at -sub update_role { +sub update_role($$) { my $config = shift; my $entry = shift; @@ -354,7 +356,7 @@ sub update_role { } # delete role from database -sub delete_role { +sub delete_role($$) { my $config = shift; my $id = shift; @@ -370,7 +372,7 @@ sub delete_role { # get all roles for given conditions: project_id, studio_id, user_id, name # includes global admin user role -sub get_user_roles { +sub get_user_roles($$) { my $config = shift; my $condition = shift; @@ -425,7 +427,7 @@ sub get_user_roles { } #return admin user roles for given conditions: project_id, studio_id, user, user_id -sub get_admin_user_roles { +sub get_admin_user_roles ($$) { my $config = shift; my $condition = shift; @@ -468,7 +470,7 @@ sub get_admin_user_roles { # read permissions for given conditions and add to user_permissions # return user_permissions # studio_id, user_id, name -sub get_user_permissions { +sub get_user_permissions ($$;$) { my $config = shift; my $conditions = shift; my $user_permissions = shift; @@ -478,8 +480,8 @@ sub get_user_permissions { my @user_roles = ( @$admin_roles, @$user_roles ); #set default permissions - $user_permissions = {} unless ( defined $user_permissions ); - $user_permissions->{is_admin} = 1 if ( scalar @$admin_roles > 0 ); + $user_permissions = {} unless defined $user_permissions; + $user_permissions->{is_admin} = 1 if scalar @$admin_roles > 0; my $max_level = 0; @@ -501,7 +503,8 @@ sub get_user_permissions { && ( $permission ne 'studio_id' ) && ( $permission ne 'project_id' ) ) { - $user_permissions->{$permission} = 1 if ( defined $user_role->{$permission} ) && ( $user_role->{$permission} ne '0' ); + $user_permissions->{$permission} = 1 + if ( defined $user_role->{$permission} ) && ( $user_role->{$permission} ne '0' ); } } } @@ -509,7 +512,7 @@ sub get_user_permissions { } #get user id by user name -sub get_user_id { +sub get_user_id ($$) { my $config = shift; my $user = shift; @@ -527,7 +530,7 @@ sub get_user_id { } #get role id by role name -sub get_role_id { +sub get_role_id ($$) { my $config = shift; my $role = shift; @@ -545,7 +548,7 @@ sub get_role_id { } # assign a role to an user (for a studio) -sub assign_user_role { +sub assign_user_role($$) { my $config = shift; my $options = shift; @@ -561,8 +564,9 @@ sub assign_user_role { from calcms_user_roles where project_id=? and studio_id=? and user_id=? and role_id=? }; - my $dbh = db::connect($config); - my $user_roles = db::get( $dbh, $query, [ $options->{project_id}, $options->{studio_id}, $options->{user_id}, $options->{role_id} ] ); + my $dbh = db::connect($config); + my $user_roles = db::get( $dbh, $query, + [ $options->{project_id}, $options->{studio_id}, $options->{user_id}, $options->{role_id} ] ); return undef if scalar @$user_roles > 0; #insert entry @@ -578,7 +582,7 @@ sub assign_user_role { } # unassign a user from a role of (for a studio) -sub remove_user_role { +sub remove_user_role($$) { my $config = shift; my $options = shift; @@ -603,7 +607,7 @@ sub remove_user_role { } #checks -sub is_user_assigned_to_studio { +sub is_user_assigned_to_studio ($$) { my $request = shift; my $options = shift; @@ -626,26 +630,26 @@ sub is_user_assigned_to_studio { # print errors at get_user_presets and check for project id and studio id # call after header is printed -sub check { +sub check($$$) { my $config = shift; my $params = shift; my $user_presets = shift; if ( defined $user_presets->{error} ) { uac::print_error( $user_presets->{error} ); - return undef; + return 0; } my $project_check = project::check( $config, { project_id => $params->{project_id} } ); if ( $project_check ne '1' ) { uac::print_error($project_check); - return undef; + return 0; } my $studio_check = studios::check( $config, { studio_id => $params->{studio_id} } ); if ( $studio_check ne '1' ) { uac::print_error($studio_check); - return undef; + return 0; } return 1; } @@ -653,7 +657,7 @@ sub check { # get user, projects and studios user is assigned to for selected values from params # set permissions for selected project and studio # return request -sub get_user_presets { +sub get_user_presets($$) { my $config = shift; my $options = shift; @@ -666,8 +670,8 @@ sub get_user_presets { $config->{access}->{write} = 0; my $user_settings = user_settings::get( $config, { user => $user } ); - $project_id = $user_settings->{project_id} if $project_id eq ''; - $studio_id = $user_settings->{studio_id} if $studio_id eq ''; + $project_id = $user_settings->{project_id} || '' if $project_id eq ''; + $studio_id = $user_settings->{studio_id} || '' if $studio_id eq ''; #get my $admin_roles = get_admin_user_roles( $config, { user => $user } ); @@ -732,7 +736,8 @@ sub get_user_presets { } } - my $permissions = uac::get_user_permissions( $config, { user => $user, project_id => $project_id, studio_id => $studio_id } ); + my $permissions = + uac::get_user_permissions( $config, { user => $user, project_id => $project_id, studio_id => $studio_id } ); #only admin is allowed to select all projects # if($permissions->{is_admin}==1){ @@ -780,7 +785,7 @@ sub get_user_presets { return $result; } -sub setDefaultProject { +sub setDefaultProject ($$) { my $params = shift; my $user_presets = shift; @@ -789,7 +794,7 @@ sub setDefaultProject { return $params; } -sub setDefaultStudio { +sub setDefaultStudio($$) { my $params = shift; my $user_presets = shift; @@ -799,7 +804,7 @@ sub setDefaultStudio { } #set user preset properties to request -sub prepare_request { +sub prepare_request ($$) { my $request = shift; my $user_presets = shift; @@ -815,7 +820,7 @@ sub prepare_request { } #TODO: shift to permissions sub entry -sub set_template_permissions { +sub set_template_permissions ($$) { my $permissions = shift; my $params = shift; @@ -826,25 +831,34 @@ sub set_template_permissions { } #print error message -sub permissions_denied { +sub permissions_denied($) { my $message = shift; $message =~ s/_/ /g; print 'Sorry! Missing permissions to ' . $message . '' . "\n"; print STDERR 'Sorry! Missing permissions to ' . $message . "\n"; } -sub print_info { - print '' . ' ' . $_[0] . '' . "\n"; +sub print_info($) { + print '' + . ' ' + . $_[0] + . '' . "\n"; } -sub print_warn { - print '' . ' ' . $_[0] . '' . "\n"; +sub print_warn($) { + print '' + . ' ' + . $_[0] + . '' . "\n"; } -sub print_error { +sub print_error ($) { my $message = shift; print STDERR "ERROR:" . $message . "\n"; - print '' . ' ' . $message . '' . "\n"; + print '' + . ' ' + . $message + . '' . "\n"; } #do not delete last line! diff --git a/lib/calcms/user_settings.pm b/lib/calcms/user_settings.pm index 67bdd43..5e71dca 100644 --- a/lib/calcms/user_settings.pm +++ b/lib/calcms/user_settings.pm @@ -1,7 +1,8 @@ package user_settings; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use series_dates(); @@ -9,7 +10,7 @@ use series_dates(); # table: calcms_user_settings # columns: user, colors use base 'Exporter'; -our @EXPORT_OK = qw(getColors getColorCss get insert update delete get_columns defaultColors); +our @EXPORT_OK = qw(getColors getColorCss get insert update delete get_columns defaultColors); sub debug; @@ -66,9 +67,10 @@ our $defaultColors = [ } ]; -sub getColors { +sub getColors($$) { my $config = shift; my $conditions = shift; + return unless defined $conditions->{user}; my $user = $conditions->{user}; @@ -95,12 +97,12 @@ sub getColors { $key =~ 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; } -sub getColorCss { +sub getColorCss ($$) { my $config = shift; my $conditions = shift; return unless defined $conditions->{user}; @@ -131,7 +133,7 @@ sub getColorCss { return $style; } -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -143,7 +145,7 @@ sub get_columns { return $columns; } -sub get { +sub get ($$) { my $config = shift; my $condition = shift; @@ -170,7 +172,7 @@ sub get { return $entries->[0] || undef; } -sub insert { +sub insert ($$) { my $config = shift; my $entry = shift; @@ -179,7 +181,7 @@ sub insert { return db::insert( $dbh, 'calcms_user_settings', $entry ); } -sub update { +sub update($$) { my $config = shift; my $entry = shift; @@ -195,12 +197,13 @@ sub update { set $values where user=? }; - #print STDERR Dumper($query).Dumper(\@bind_values); + + #print STDERR Dumper($query).Dumper(\@bind_values); db::put( $dbh, $query, \@bind_values ); print "done\n"; } -sub delete { +sub delete ($$) { my $config = shift; my $entry = shift; @@ -218,7 +221,7 @@ sub delete { db::put( $dbh, $query, $bind_values ); } -sub error { +sub error ($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/user_stats.pm b/lib/calcms/user_stats.pm index 6469417..0af00dd 100644 --- a/lib/calcms/user_stats.pm +++ b/lib/calcms/user_stats.pm @@ -1,15 +1,16 @@ package user_stats; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get update insert get_stats increase); +our @EXPORT_OK = qw(get_columns get update insert get_stats increase); sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -21,7 +22,7 @@ sub get_columns { return $columns; } -sub get { +sub get ($$) { my $config = shift; my $condition = shift; @@ -72,7 +73,7 @@ sub get { return $results; } -sub get_stats { +sub get_stats($$) { my $config = shift; my $condition = shift; @@ -129,7 +130,9 @@ sub get_stats { my $results = db::get( $dbh, $query, \@bind_values ); for my $result (@$results) { $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}; } } @@ -137,7 +140,7 @@ sub get_stats { return \@results; } -sub insert { +sub insert($$) { my $config = shift; my $stats = shift; @@ -160,7 +163,7 @@ sub insert { } # update project -sub update { +sub update ($$) { my $config = shift; my $stats = shift; @@ -194,7 +197,7 @@ sub update { return db::put( $dbh, $query, \@bind_values ); } -sub increase { +sub increase ($$$) { my $config = shift; my $usecase = shift; my $options = shift; @@ -241,7 +244,7 @@ sub increase { } -sub error { +sub error ($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/work_dates.pm b/lib/calcms/work_dates.pm index 42b7471..966ea45 100644 --- a/lib/calcms/work_dates.pm +++ b/lib/calcms/work_dates.pm @@ -1,7 +1,8 @@ package work_dates; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc(); @@ -16,11 +17,11 @@ use work_schedule(); # columns: id, studio_id, schedule_id, start(datetime), end(datetime) # TODO: delete column schedule_id use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get insert update delete get_dates); +our @EXPORT_OK = qw(get_columns get insert update delete get_dates); sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -34,12 +35,13 @@ sub get_columns { # 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) -sub get { +sub get ($$) { my $config = shift; my $condition = shift; 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); @@ -125,7 +127,7 @@ sub get { } #update work dates for all schedules of a work and studio_id -sub update { +sub update($$) { my $config = shift; my $entry = shift; @@ -215,7 +217,7 @@ sub update { return $j . " dates out of studio times, " . $i; } -sub get_schedule_dates { +sub get_schedule_dates($$) { my $schedule = shift; my $options = shift; @@ -239,7 +241,7 @@ sub get_schedule_dates { return $dates; } -sub get_week_of_month_dates { +sub get_week_of_month_dates($$$$$$) { my $start = shift; # datetime string my $end = shift; # datetime string my $duration = shift; # in minutes @@ -283,7 +285,7 @@ sub get_week_of_month_dates { } #add duration to a single date -sub get_single_date { +sub get_single_date($$) { my $start_datetime = shift; my $duration = shift; @@ -303,12 +305,12 @@ sub get_single_date { } #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 $end_date = shift; my $duration = shift; # in minutes 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) }; return unless @start >= 6; @@ -364,7 +366,7 @@ sub get_dates { } #remove all work_dates for studio_id and schedule_id -sub delete { +sub delete($$) { my $config = shift; my $entry = shift; @@ -385,7 +387,7 @@ sub delete { return db::put( $dbh, $query, $bind_values ); } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/work_schedule.pm b/lib/calcms/work_schedule.pm index 562bc8b..00508b7 100644 --- a/lib/calcms/work_schedule.pm +++ b/lib/calcms/work_schedule.pm @@ -1,7 +1,8 @@ package work_schedule; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use series_dates(); @@ -17,11 +18,11 @@ use series_dates(); # month use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get insert update delete); +our @EXPORT_OK = qw(get_columns get insert update delete); sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -34,7 +35,7 @@ sub get_columns { } #map schedule id to id -sub get { +sub get($$) { my $config = shift; my $condition = shift; @@ -89,7 +90,7 @@ sub get { return $entries; } -sub insert { +sub insert ($$) { my $config = shift; my $entry = shift; @@ -101,7 +102,7 @@ sub insert { } #schedule id to id -sub update { +sub update ($$) { my $config = shift; my $entry = shift; @@ -128,7 +129,7 @@ sub update { } #map schedule id to id -sub delete { +sub delete($$) { my $config = shift; my $entry = shift; @@ -149,7 +150,7 @@ sub delete { return db::put( $dbh, $query, $bind_values ); } -sub error { +sub error($) { my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/website/agenda/add_comment.cgi b/website/agenda/add_comment.cgi index 9f7e932..15dba18 100755 --- a/website/agenda/add_comment.cgi +++ b/website/agenda/add_comment.cgi @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use warnings; use strict; @@ -8,7 +8,6 @@ use params(); use config(); use db(); use markup(); -use cache(); use comments(); use template(); use log(); diff --git a/website/agenda/aggregate.cgi b/website/agenda/aggregate.cgi index 5ab017f..2c6642b 100755 --- a/website/agenda/aggregate.cgi +++ b/website/agenda/aggregate.cgi @@ -1,11 +1,8 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use warnings "all"; use strict; use utf8; - -#use CGI qw(header param Vars); - use config(); use params(); use db(); @@ -20,7 +17,7 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) { my $params = {}; my $r = shift; - #print STDERR ref($r)."\n"; + if ( ref($r) eq '' ) { for my $arg (@ARGV) { my ( $key, $value ) = split( /\=/, $arg, 2 ); @@ -56,22 +53,12 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) { $params = $request->{params}->{checked}; my $mem = 0; - - #get result from cache - my $cache = aggregator::get_cache( $config, $request ); - - if ( ( defined $cache->{content} ) && ( $cache->{content} ne '' ) ) { - my $content = $cache->{content}; - print $output_header; - print $content; - return; - } - my $content = load_file( $base_dir . './index.html' ); $content = $$content || ''; #replace HTML escaped calcms_title span by unescaped one - $content =~ s/\<\;span id\="\;calcms_title"\;\>\;[^\&]*\<\;\/span\>\;/\\<\/span\>/g; + $content =~ +s/\<\;span id\="\;calcms_title"\;\>\;[^\&]*\<\;\/span\>\;/\\<\/span\>/g; # print $content; @@ -130,7 +117,9 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) { $content =~ s/(<(div|span)\s+id="calcms_title".*?>).*?(<\/(div|span)>)/$list->{project_title}/g; my $values = []; - for my $value ( $list->{'series_name'}, $list->{'title'}, $list->{'location'}, 'Programm '. $list->{project_title} ) { + for my $value ( $list->{'series_name'}, + $list->{'title'}, $list->{'location'}, 'Programm ' . $list->{project_title} . ' | In Gedenken an AB✝' ) + { next unless defined $value; next if $value eq ''; push @$values, $value; @@ -156,14 +145,8 @@ if ( $0 =~ /aggregate.*?\.cgi$/ ) { print $output_header; print $content; - if ( $config->{cache}->{use_cache} eq '1' ) { - $cache->{content} = $content; - cache::save($cache); - } - # $config=undef; $content = undef; - $cache = undef; } sub load_file { diff --git a/website/agenda/cal.cgi b/website/agenda/cal.cgi index 7bbd657..37c83a4 100755 --- a/website/agenda/cal.cgi +++ b/website/agenda/cal.cgi @@ -1,8 +1,8 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -#use utf8; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use params(); @@ -16,23 +16,23 @@ my $r = shift; binmode STDOUT, ":encoding(UTF-8)"; if ( $0 =~ /cal.*?\.cgi$/ ) { - ( my $cgi, my $params, my $error ) = params::get($r); + ( my $cgi, my $params, my $error ) = params::get($r); - my $config = config::getFromScriptLocation(); - my $debug = $config->{system}->{debug}; + my $config = config::getFromScriptLocation(); + my $debug = $config->{system}->{debug}; - my $request = { - url => $ENV{QUERY_STRING}, - params => { - original => $params, - checked => calendar::check_params( $config, $params ), - }, - }; - $params = $request->{params}->{checked}; + my $request = { + url => $ENV{QUERY_STRING}, + params => { + original => $params, + checked => calendar::check_params( $config, $params ), + }, + }; + $params = $request->{params}->{checked}; - my $out = ''; - calendar::get_cached_or_render( $out, $config, $request ); - print $out. "\n"; + my $out = ''; + calendar::get_cached_or_render( $out, $config, $request ); + print $out. "\n"; } 1; diff --git a/website/agenda/category.cgi b/website/agenda/category.cgi index d97d7f5..47b6bea 100755 --- a/website/agenda/category.cgi +++ b/website/agenda/category.cgi @@ -1,13 +1,14 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use strict; use warnings; +no warnings 'redefine'; + use Data::Dumper; use params(); use db(); use markup(); -use cache(); use log(); use config(); use template(); @@ -19,7 +20,7 @@ my $r = shift; ( my $cgi, my $params, my $error ) = params::get($r); my $config = config::getFromScriptLocation(); -my $debug = $config->{system}->{debug}; +my $debug = $config->{system}->{debug}; my $request = { url => $ENV{QUERY_STRING}, @@ -30,16 +31,6 @@ my $request = { }; $params = $request->{params}->{checked}; -my $cache = {}; -if ( $config->{cache}->{use_cache} eq '1' ) { - cache::configure('categories.html'); - $cache = cache::load( $config, $params ); - if ( defined $cache->{content} ) { - print $cache->{content}; - return; - } -} - my $dbh = db::connect($config); my $template_parameters = {}; @@ -48,19 +39,14 @@ $template_parameters->{projects} = getProjects( $dbh, $config ); #$template_parameters->{categories} = get_categories($dbh,$params->{project}); $template_parameters->{debug} = $config->{system}->{debug}; $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} ); my $template = $params->{template}; my $out = ''; template::process( $config, $out, $params->{template}, $template_parameters ); print $out; -#write to cache -if ( $config->{cache}->{use_cache} eq '1' ) { - $cache->{content} = $out; - cache::save($cache); -} - sub getProjects { my $dbh = shift; my $config = shift; diff --git a/website/agenda/comments.cgi b/website/agenda/comments.cgi index 9de872b..ff19394 100755 --- a/website/agenda/comments.cgi +++ b/website/agenda/comments.cgi @@ -1,7 +1,8 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; @@ -11,7 +12,6 @@ use comments(); use db(); use markup(); use time(); -use cache(); use log(); my $r = shift; ( my $cgi, my $params, my $error ) = params::get($r); @@ -19,20 +19,20 @@ my $r = shift; binmode STDOUT, ":encoding(UTF-8)"; if ( $0 =~ /comments.*?\.cgi$/ ) { - my $config = config::get('config/config.cgi'); - my $debug = $config->{system}->{debug}; + my $config = config::get('config/config.cgi'); + my $debug = $config->{system}->{debug}; - my $request = { - url => $ENV{QUERY_STRING}, - params => { - original => $params, - checked => comments::check_params( $config, $params ), - }, - }; + my $request = { + url => $ENV{QUERY_STRING}, + params => { + original => $params, + checked => comments::check_params( $config, $params ), + }, + }; - my $output = ''; - comments::get_cached_or_render( $output, $config, $request, 'filter_locked' ); - print $output; + my $output = ''; + comments::get_cached_or_render( $output, $config, $request, 'filter_locked' ); + print $output; } #do not delete last line diff --git a/website/agenda/events.cgi b/website/agenda/events.cgi index 989cd00..cd0220f 100755 --- a/website/agenda/events.cgi +++ b/website/agenda/events.cgi @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use strict; use warnings; diff --git a/website/agenda/planung/assign_series.cgi b/website/agenda/planung/assign_series.cgi index ecd40ff..1422619 100755 --- a/website/agenda/planung/assign_series.cgi +++ b/website/agenda/planung/assign_series.cgi @@ -1,7 +1,9 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; + use Data::Dumper; use URI::Escape(); use Encode(); @@ -61,7 +63,7 @@ $params = $request->{params}->{checked}; #process header my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); +template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -95,11 +97,11 @@ sub show_events { my $projects = project::get( $config, { project_id => $params->{project_id} } ); my $project = $projects->[0]; - return unless scalar @$projects == 1 ; + return unless scalar @$projects == 1; my $studios = studios::get( $config, { project_id => $params->{project_id}, studio_id => $params->{studio_id} } ); my $studio = $studios->[0]; - return unless scalar @$studios == 1 ; + return unless scalar @$studios == 1; my $project_name = $project->{name}; my $studio_name = $studio->{location}; @@ -140,7 +142,7 @@ sub show_events { $params->{project_name} = $project_name; $params->{studio_name} = $studio_name; - template::process($config, 'print', $params->{template}, $params ); + template::process( $config, 'print', $params->{template}, $params ); } sub assign_series { @@ -235,7 +237,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check($config, $params->{template}, 'assign_series' ); + $checked->{template} = template::check( $config, $params->{template}, 'assign_series' ); return $checked; } diff --git a/website/agenda/planung/assignments.cgi b/website/agenda/planung/assignments.cgi index a73d7da..1598fd0 100755 --- a/website/agenda/planung/assignments.cgi +++ b/website/agenda/planung/assignments.cgi @@ -1,8 +1,8 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -use warnings "all"; use strict; -use Data::Dumper; +use warnings; +no warnings 'redefine'; use URI::Escape(); use Encode(); @@ -240,7 +240,11 @@ sub assign_events { "event not found for project $entry->{project_id}, studio $entry->{studio_id}, series $entry->{series_id}, event $entry->{event_id}\n"; 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; @@ -318,7 +322,8 @@ sub assign_events { # print STDERR "ok\n"; } } 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; } @@ -392,7 +397,9 @@ sub check_params { $checked->{create_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+)/ ) ) { $checked->{$param} = $1; } diff --git a/website/agenda/planung/audio_recordings.cgi b/website/agenda/planung/audio_recordings.cgi index b38b770..0288306 100755 --- a/website/agenda/planung/audio_recordings.cgi +++ b/website/agenda/planung/audio_recordings.cgi @@ -1,9 +1,8 @@ #!/usr/bin/perl -local $| = 0; - -use warnings; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use CGI::Simple (); @@ -59,12 +58,12 @@ my ( $user, $expires ) = auth::get_user( $config, $params, $cgi ); exit if ( !defined $user ) || ( $user eq '' ); my $user_presets = uac::get_user_presets( - $config, - { - user => $user, - project_id => $params->{project_id}, - studio_id => $params->{studio_id} - } + $config, + { + user => $user, + project_id => $params->{project_id}, + studio_id => $params->{studio_id} + } ); $params->{default_studio_id} = $user_presets->{studio_id}; @@ -72,11 +71,11 @@ $params = uac::setDefaultStudio( $params, $user_presets ); $params = uac::setDefaultProject( $params, $user_presets ); my $request = { - url => $ENV{QUERY_STRING} || '', - params => { - original => $params, - checked => check_params($config, $params), - }, + url => $ENV{QUERY_STRING} || '', + params => { + original => $params, + checked => check_params( $config, $params ), + }, }; $request = uac::prepare_request( $request, $user_presets ); @@ -85,9 +84,9 @@ $params = $request->{params}->{checked}; my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); +template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); -exit unless defined uac::check( $config, $params, $user_presets ); +exit unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -101,479 +100,481 @@ $params->{error} = $error || ''; #print STDERR Dumper($params); if ( $params->{action} eq 'upload' ) { - uploadRecording( $config, $request ); + uploadRecording( $config, $request ); } elsif ( $params->{action} eq 'delete' ) { - deleteRecording( $config, $request ); + deleteRecording( $config, $request ); } showAudioRecordings( $config, $request ); print STDERR "$0 ERROR: " . $params->{error} . "\n" if $params->{error} ne ''; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'event,comment' } ); -template::process($config, 'print', $params->{template}, $params ); +template::process( $config, 'print', $params->{template}, $params ); exit; sub uploadRecording { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $permissions = $request->{permissions}; + my $params = $request->{params}->{checked}; + my $permissions = $request->{permissions}; - unless ( $permissions->{upload_audio_recordings} == 1 ) { - uac::permissions_denied('upload_audio_recordings'); - return; - } + unless ( $permissions->{upload_audio_recordings} == 1 ) { + uac::permissions_denied('upload_audio_recordings'); + return; + } - for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_id' ) { - unless ( defined $params->{$attr} ) { - uac::print_error( "missing " . $attr . " to upload productions" ); - return; - } - } + for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_id' ) { + unless ( defined $params->{$attr} ) { + uac::print_error( "missing " . $attr . " to upload productions" ); + return; + } + } - if ( defined $fh ) { - print STDERR "upload\n"; + if ( defined $fh ) { + print STDERR "upload\n"; - #print STDERR Dumper($fh)."
"; - my $fileInfo = uploadFile( $config, $fh, $params->{event_id}, $user, $params->{upload} ); - $params->{error} .= $fileInfo->{error} if defined $fileInfo->{error}; - $params->{path} = $fileInfo->{path}; - $params->{size} = $fileInfo->{size}; + #print STDERR Dumper($fh)."
"; + my $fileInfo = uploadFile( $config, $fh, $params->{event_id}, $user, $params->{upload} ); + $params->{error} .= $fileInfo->{error} if defined $fileInfo->{error}; + $params->{path} = $fileInfo->{path}; + $params->{size} = $fileInfo->{size}; - #$params->{duration} = $fileInfo->{duration}; - $params = updateDatabase( $config, $params, $user ) if $params->{error} eq ''; - } else { - $params->{error} .= 'Could not get file handle'; - } + #$params->{duration} = $fileInfo->{duration}; + $params = updateDatabase( $config, $params, $user ) if $params->{error} eq ''; + } else { + $params->{error} .= 'Could not get file handle'; + } - if ( $params->{error} ne '' ) { - if ( $params->{error} =~ /limit/ ) { - $params->{error} .= - "audio file size is limited to " . int( $uploadLimit / 1000000 ) . " MB!" . "Please make it smaller and try again!"; - } else { - $params->{error} .= "Error:'$error'"; - } - } + if ( $params->{error} ne '' ) { + if ( $params->{error} =~ /limit/ ) { + $params->{error} .= + "audio file size is limited to " + . int( $uploadLimit / 1000000 ) . " MB!" + . "Please make it smaller and try again!"; + } else { + $params->{error} .= "Error:'$error'"; + } + } } # return 1 if file has been deleted sub deleteFile { - my $file = shift; - return 0 unless defined $file; + my $file = shift; + return 0 unless defined $file; - if ( -e $file ) { - if ( -w $file ) { - unlink $file; + if ( -e $file ) { + if ( -w $file ) { + unlink $file; - # check if file has been deleted - if ( -e $file ) { - uac::print_error("could not delete audio file '$file', $!\n"); - return 0; - } - } else { - uac::print_error("cannot delete audio file '$file', missing permissions\n"); - return 0; - } - } - return 1; + # check if file has been deleted + if ( -e $file ) { + uac::print_error("could not delete audio file '$file', $!\n"); + return 0; + } + } else { + uac::print_error("cannot delete audio file '$file', missing permissions\n"); + return 0; + } + } + return 1; } sub deleteRecording { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $permissions = $request->{permissions}; + my $params = $request->{params}->{checked}; + my $permissions = $request->{permissions}; - unless ( $permissions->{delete_audio_recordings} == 1 ) { - uac::permissions_denied('delete_audio_recordings'); - return; - } + unless ( $permissions->{delete_audio_recordings} == 1 ) { + uac::permissions_denied('delete_audio_recordings'); + return; + } - for my $attr ( - 'project_id', 'studio_id', + for my $attr ( + 'project_id', 'studio_id', - #'series_id', - 'event_id', 'path' - ) - { - unless ( defined $params->{$attr} ) { - uac::print_error( "missing " . $attr . " to delete production" ); - return; - } - } + #'series_id', + 'event_id', 'path' + ) + { + unless ( defined $params->{$attr} ) { + uac::print_error( "missing " . $attr . " to delete production" ); + return; + } + } - my $dbh = db::connect($config); - $config->{access}->{write} = 0; + my $dbh = db::connect($config); + $config->{access}->{write} = 0; - my $audioRecordings = audio_recordings::get( - $config, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - event_id => $params->{event_id}, - path => $params->{path} - } - ); + my $audioRecordings = audio_recordings::get( + $config, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + event_id => $params->{event_id}, + path => $params->{path} + } + ); - unless ( ( defined $audioRecordings ) && ( scalar @$audioRecordings > 0 ) ) { - uac::print_error("could not find audio file $params->{path} in database"); - return; - } + unless ( ( defined $audioRecordings ) && ( scalar @$audioRecordings > 0 ) ) { + uac::print_error("could not find audio file $params->{path} in database"); + return; + } - my $targetDir = $config->{locations}->{local_audio_recordings_dir}; - unless ( defined $targetDir ) { - uac::print_error("'local_audio_recordings_dir' is not configured."); - return; - } - unless ( -d $targetDir ) { - uac::print_error("audio dir '$targetDir' does not exist"); - return; - } + my $targetDir = $config->{locations}->{local_audio_recordings_dir}; + unless ( defined $targetDir ) { + uac::print_error("'local_audio_recordings_dir' is not configured."); + return; + } + unless ( -d $targetDir ) { + uac::print_error("audio dir '$targetDir' does not exist"); + return; + } - my $file = $targetDir . '/' . $params->{path}; - print STDERR "ERROR: cannot delete audio file '$file', file does not exist\n" unless -e $file; + my $file = $targetDir . '/' . $params->{path}; + print STDERR "ERROR: cannot delete audio file '$file', file does not exist\n" unless -e $file; - my $isDeleted = deleteFile($file); - return unless $isDeleted; + my $isDeleted = deleteFile($file); + return unless $isDeleted; - $config->{access}->{write} = 1; - $audioRecordings = audio_recordings::delete( - $config, $dbh, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - event_id => $params->{event_id}, - path => $params->{path}, - } - ); - $config->{access}->{write} = 0; + $config->{access}->{write} = 1; + $audioRecordings = audio_recordings::delete( + $config, $dbh, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + event_id => $params->{event_id}, + path => $params->{path}, + } + ); + $config->{access}->{write} = 0; } sub showAudioRecordings { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $permissions = $request->{permissions}; + my $params = $request->{params}->{checked}; + my $permissions = $request->{permissions}; - for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_id' ) { - unless ( defined $params->{$attr} ) { - uac::print_error( "missing " . $attr . " to show productions" ); - return; - } - } + for my $attr ( 'project_id', 'studio_id', 'series_id', 'event_id' ) { + unless ( defined $params->{$attr} ) { + uac::print_error( "missing " . $attr . " to show productions" ); + return; + } + } - my $event = series::get_event( - $config, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - series_id => $params->{series_id}, - event_id => $params->{event_id} - } - ); - unless ( defined $event ) { - uac::print_error("event not found"); - return; - } + my $event = series::get_event( + $config, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + series_id => $params->{series_id}, + event_id => $params->{event_id} + } + ); + unless ( defined $event ) { + uac::print_error("event not found"); + return; + } - #print ''.Dumper($event).''; + #print ''.Dumper($event).''; - my $audioRecordings = audio_recordings::get( - $config, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - event_id => $params->{event_id}, - } - ); + my $audioRecordings = audio_recordings::get( + $config, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + event_id => $params->{event_id}, + } + ); - #print Dumper($audioRecordings); - for my $recording (@$audioRecordings) { - $recording->{size} =~ s/(\d)(\d\d\d)$/$1\.$2/g; - $recording->{size} =~ s/(\d)(\d\d\d\.\d\d\d)$/$1\.$2/g; + #print Dumper($audioRecordings); + for my $recording (@$audioRecordings) { + $recording->{size} =~ s/(\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->{mastered} = $recording->{mastered} ? 'yes' : 'no'; + $recording->{processed} = $recording->{processed} ? 'yes' : 'no'; + $recording->{mastered} = $recording->{mastered} ? 'yes' : 'no'; - $recording->{eventDuration} = getDuration( $recording->{eventDuration} ); - $recording->{audioDuration} = getDuration( $recording->{audioDuration} ); + $recording->{eventDuration} = getDuration( $recording->{eventDuration} ); + $recording->{audioDuration} = getDuration( $recording->{audioDuration} ); - $recording->{rmsLeft} ||= '-'; - $recording->{rmsRight} ||= '-'; - } + $recording->{rmsLeft} ||= '-'; + $recording->{rmsRight} ||= '-'; + } - my $now = time(); - my $timeZone = $config->{date}->{time_zone}; - my $start = time::datetime_to_utc( $event->{start}, $timeZone ); - my $end = time::datetime_to_utc( $event->{end}, $timeZone ); - if ( $now > $end ) { - uac::print_error("upload is expired due to the show is over"); - $params->{isOver} = 1; - } - my $days = 24 * 60 * 60; - uac::print_warn("show is more than a week ahead") if ( $now + 7 * $days ) < $start; + my $now = time(); + my $timeZone = $config->{date}->{time_zone}; + my $start = time::datetime_to_utc( $event->{start}, $timeZone ); + my $end = time::datetime_to_utc( $event->{end}, $timeZone ); + if ( $now > $end ) { + uac::print_error("upload is expired due to the show is over"); + $params->{isOver} = 1; + } + my $days = 24 * 60 * 60; + uac::print_warn("show is more than a week ahead") if ( $now + 7 * $days ) < $start; - $params->{event} = $event; - $params->{audio_recordings} = $audioRecordings; + $params->{event} = $event; + $params->{audio_recordings} = $audioRecordings; } sub getDuration { - my $duration = shift; - my $hour = int( $duration / 3600 ); - $duration -= $hour * 3600; + my $duration = shift; + my $hour = int( $duration / 3600 ); + $duration -= $hour * 3600; - my $minutes = int( $duration / 60 ); - $duration -= $minutes * 60; + my $minutes = int( $duration / 60 ); + $duration -= $minutes * 60; - my $seconds = int($duration); - $duration -= $seconds; + my $seconds = int($duration); + $duration -= $seconds; - my $milli = int( 100 * $duration ); - return sprintf( "%02d:%02d:%02d.%02d", $hour, $minutes, $seconds, $milli ); + my $milli = int( 100 * $duration ); + return sprintf( "%02d:%02d:%02d.%02d", $hour, $minutes, $seconds, $milli ); } sub uploadFile { - my $config = $_[0]; - my $fh = $_[1]; - my $eventId = $_[2]; - my $user = $_[3] || ''; - my $filename = $_[4] || ''; + my $config = $_[0]; + my $fh = $_[1]; + my $eventId = $_[2]; + my $user = $_[3] || ''; + my $filename = $_[4] || ''; - # check target directory - my $targetDir = $config->{locations}->{local_audio_recordings_dir}; - return { error => "could not find local_audio_recordings_dir" } unless defined $targetDir; - return { error => "local_audio_recordings_dir does not exist" } unless -e $targetDir; + # check target directory + my $targetDir = $config->{locations}->{local_audio_recordings_dir}; + return { error => "could not find local_audio_recordings_dir" } unless defined $targetDir; + return { error => "local_audio_recordings_dir does not exist" } unless -e $targetDir; - # save file to disk - my $userName = $user; - $userName =~ s/[^a-zA-Z0-9\.\-\_]//g; + # save file to disk + my $userName = $user; + $userName =~ s/[^a-zA-Z0-9\.\-\_]//g; - my $time = time::time_to_datetime(); - $time =~ s/\:/\-/g; - $time =~ s/\s/\_/g; - $time =~ s/[^a-zA-Z0-9\.\-\_]//g; + my $time = time::time_to_datetime(); + $time =~ s/\:/\-/g; + $time =~ s/\s/\_/g; + $time =~ s/[^a-zA-Z0-9\.\-\_]//g; - $filename =~ s/\.(mp3)$//g; - $filename = join( '-', ( $time, 'id' . $eventId, $userName, $filename ) ) . '.mp3'; - $filename =~ s/[^a-zA-Z0-9\.\-\_]//g; + $filename =~ s/\.(mp3)$//g; + $filename = join( '-', ( $time, 'id' . $eventId, $userName, $filename ) ) . '.mp3'; + $filename =~ s/[^a-zA-Z0-9\.\-\_]//g; - my $tempFile = $targetDir . '/' . $filename; - print STDERR "tempFile=$tempFile\n"; + my $tempFile = $targetDir . '/' . $filename; + print STDERR "tempFile=$tempFile\n"; - my $start = time(); - open DAT, '>', $tempFile or return { error => 'could not save upload. ' . $! . " " . $tempFile }; - binmode DAT; - my $size = 0; - my $data = ''; - while ( my $bytesRead = $fh->read( $data, 65000 ) ) { - print DAT $data; - $size += $bytesRead; - $data = ''; - } - close DAT; + my $start = time(); + open DAT, '>', $tempFile or return { error => 'could not save upload. ' . $! . " " . $tempFile }; + binmode DAT; + my $size = 0; + my $data = ''; + while ( my $bytesRead = $fh->read( $data, 65000 ) ) { + print DAT $data; + $size += $bytesRead; + $data = ''; + } + close DAT; - return { - dir => $targetDir, - path => $filename, - size => $size, - }; + return { + dir => $targetDir, + path => $filename, + size => $size, + }; } sub updateDatabase { - my $config = shift; - my $params = shift; - my $user = shift; + my $config = shift; + my $params = shift; + my $user = shift; - my $eventDuration = getEventDuration( $config, $params->{event_id} ); + my $eventDuration = getEventDuration( $config, $params->{event_id} ); - my $entry = { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - event_id => $params->{event_id}, - path => $params->{path}, - size => $params->{size}, - created_by => $user, - eventDuration => $eventDuration - }; + my $entry = { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + event_id => $params->{event_id}, + path => $params->{path}, + size => $params->{size}, + created_by => $user, + eventDuration => $eventDuration + }; - #print STDERR "updateDatabase:" . Dumper($entry); + #print STDERR "updateDatabase:" . Dumper($entry); - #connect - $config->{access}->{write} = 1; - my $dbh = db::connect($config); + #connect + $config->{access}->{write} = 1; + my $dbh = db::connect($config); - my $entries = audio_recordings::get( - $config, - { - project_id => $entry->{project_id}, - studio_id => $entry->{studio_id}, - event_id => $entry->{event_id}, - path => $entry->{path} - } - ); + my $entries = audio_recordings::get( + $config, + { + project_id => $entry->{project_id}, + studio_id => $entry->{studio_id}, + event_id => $entry->{event_id}, + path => $entry->{path} + } + ); - if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) { - print STDERR "update\n"; - audio_recordings::update( $config, $dbh, $entry ); - my $entry = $entries->[0]; - $params->{id} = $entry->{id}; - } else { - print STDERR "insert\n"; - $entry->{created_by} = $user; - $entry->{processed} = 0; - $entry->{mastered} = 0; - $entry->{rmsLeft} = 0.0; - $entry->{rmsRight} = 0.0; - $entry->{audioDuration} = 0.0; - $entry->{modified_at} = time(); - $params->{id} = audio_recordings::insert( $config, $dbh, $entry ); - } - $config->{access}->{write} = 0; - $params->{action_result} = 'done!'; + if ( ( defined $entries ) && ( scalar @$entries > 0 ) ) { + print STDERR "update\n"; + audio_recordings::update( $config, $dbh, $entry ); + my $entry = $entries->[0]; + $params->{id} = $entry->{id}; + } else { + print STDERR "insert\n"; + $entry->{created_by} = $user; + $entry->{processed} = 0; + $entry->{mastered} = 0; + $entry->{rmsLeft} = 0.0; + $entry->{rmsRight} = 0.0; + $entry->{audioDuration} = 0.0; + $entry->{modified_at} = time(); + $params->{id} = audio_recordings::insert( $config, $dbh, $entry ); + } + $config->{access}->{write} = 0; + $params->{action_result} = 'done!'; - return $params; + return $params; } # return filename, filehandle and optionally error from upload sub getFilename { - my $cgi = shift; - my $upload = shift; + my $cgi = shift; + my $upload = shift; - if ( defined $upload ) { + if ( defined $upload ) { - # try apache2 module - my $filename = $upload->filename(); - return { - filename => $filename, - fh => $upload->fh(), - error => '' - }; + # try apache2 module + my $filename = $upload->filename(); + return { + filename => $filename, + fh => $upload->fh(), + error => '' + }; - } + } - #print STDERR "cgi:".Dumper($cgi); + #print STDERR "cgi:".Dumper($cgi); - # fallback to CGI module - my $file = $cgi->param("upload"); - return { error => "is no file" } if ( defined $file ) && ( $file =~ /\|/ ); + # fallback to CGI module + my $file = $cgi->param("upload"); + return { error => "is no file" } if ( defined $file ) && ( $file =~ /\|/ ); - #print STDERR "file:".Dumper($file); - my $fileInfo = $cgi->uploadInfo($file); + #print STDERR "file:".Dumper($file); + my $fileInfo = $cgi->uploadInfo($file); - #print STDERR "fileInfo:".Dumper($fileInfo); + #print STDERR "fileInfo:".Dumper($fileInfo); - if ( defined $fileInfo ) { - my $filename = $fileInfo->{'Content-Disposition'} || ''; - if ( $filename =~ /filename=\"(.*?)\"/ ) { - $filename = $1; - return { - filename => $filename, - fh => $file, - error => '' - }; + if ( defined $fileInfo ) { + my $filename = $fileInfo->{'Content-Disposition'} || ''; + if ( $filename =~ /filename=\"(.*?)\"/ ) { + $filename = $1; + return { + filename => $filename, + fh => $file, + error => '' + }; - } - } + } + } - #error - return { error => 'Could not detect file name!' }; + #error + return { error => 'Could not detect file name!' }; } # get extension and optionally error sub checkFilename { - my $filename = shift; + my $filename = shift; - my @validExtensions = ('mp3'); - if ( $filename =~ /\.([a-zA-Z]{3,5})$/ ) { - my $extension = lc $1; - unless ( grep( /$extension/, @validExtensions ) ) { - return { error => 'Following file formats are supported: ' . join( ",", @validExtensions ) . '!' }; - } - return { - extension => $extension, - error => '' - }; - } - return { error => 'Not matching file extension found! Supported are: ' . join( ",", @validExtensions ) . '!' }; + my @validExtensions = ('mp3'); + if ( $filename =~ /\.([a-zA-Z]{3,5})$/ ) { + my $extension = lc $1; + unless ( grep( /$extension/, @validExtensions ) ) { + return { error => 'Following file formats are supported: ' . join( ",", @validExtensions ) . '!' }; + } + return { + extension => $extension, + error => '' + }; + } + return { error => 'Not matching file extension found! Supported are: ' . join( ",", @validExtensions ) . '!' }; } # return event duration in seconds sub getEventDuration { - my $config = shift; - my $eventId = shift; + my $config = 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 = { - params => { - checked => events::check_params( - $config, - { - event_id => $eventId, - template => 'no', - limit => 1, - } - ) - }, - config => $config - }; - $request->{params}->{checked}->{published} = 'all'; - my $events = events::get( $config, $request ); - if ( scalar @$events == 0 ) { - print STDERR "getEventDuration: no event found with event_id=$eventId\n"; - } - my $event = $events->[0]; - my $duration = time::get_duration_seconds( $event->{start}, $event->{end}, $config->{date}->{time_zone} ); - return $duration; + my $request = { + params => { + checked => events::check_params( + $config, + { + event_id => $eventId, + template => 'no', + limit => 1, + } + ) + }, + config => $config + }; + $request->{params}->{checked}->{published} = 'all'; + my $events = events::get( $config, $request ); + if ( scalar @$events == 0 ) { + print STDERR "getEventDuration: no event found with event_id=$eventId\n"; + } + my $event = $events->[0]; + my $duration = time::get_duration_seconds( $event->{start}, $event->{end}, $config->{date}->{time_zone} ); + return $duration; } sub check_params { my $config = shift; - my $params = shift; + my $params = shift; - my $checked = {}; - $checked->{error} = ''; - $checked->{template} = template::check($config, $params->{template}, 'upload_audio_recordings' ); + my $checked = {}; + $checked->{error} = ''; + $checked->{template} = template::check( $config, $params->{template}, 'upload_audio_recordings' ); - #print Dumper($params); - #numeric values - for my $param ( 'project_id', 'studio_id', 'default_studio_id', 'series_id', 'event_id', 'id' ) { - if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) { - $checked->{$param} = $params->{$param}; - } - } + #print Dumper($params); + #numeric values + for my $param ( 'project_id', 'studio_id', 'default_studio_id', 'series_id', 'event_id', 'id' ) { + if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) { + $checked->{$param} = $params->{$param}; + } + } - if ( defined $checked->{studio_id} ) { - $checked->{default_studio_id} = $checked->{studio_id}; - } else { - $checked->{studio_id} = -1; - } + if ( defined $checked->{studio_id} ) { + $checked->{default_studio_id} = $checked->{studio_id}; + } else { + $checked->{studio_id} = -1; + } - #word - for my $param ( 'debug', 'name', 'description' ) { - if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) { - $checked->{$param} = $1; - } - } + #word + for my $param ( 'debug', 'name', 'description' ) { + if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) { + $checked->{$param} = $1; + } + } - # words - for my $attr ( 'action', 'path' ) { - if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\S+)/ ) ) { - $checked->{$attr} = $params->{$attr}; - } - } + # words + for my $attr ( 'action', 'path' ) { + if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\S+)/ ) ) { + $checked->{$attr} = $params->{$attr}; + } + } - $checked->{upload} = $params->{upload}; - return $checked; + $checked->{upload} = $params->{upload}; + return $checked; } diff --git a/website/agenda/planung/calendar.cgi b/website/agenda/planung/calendar.cgi index e0d3375..199770c 100755 --- a/website/agenda/planung/calendar.cgi +++ b/website/agenda/planung/calendar.cgi @@ -1,7 +1,8 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use URI::Escape(); @@ -92,7 +93,7 @@ if ( #process header my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); + template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); print q{ @@ -167,7 +168,7 @@ sub showCalendar { my $end_of_day = $cal_options->{end_of_day}; my $params = $request->{params}->{checked}; - my $permissions = $request->{permissions}; + my $permissions = $request->{permissions} || {}; unless ( $permissions->{read_series} == 1 ) { uac::permissions_denied('read_series'); return; @@ -233,7 +234,7 @@ sub showCalendar { if ( $params->{search} =~ /\S/ ) { if ( $params->{list} == 1 ) { - $options->{search} = $params->{search}; + $options->{search} = $params->{search}; delete $options->{from_date}; delete $options->{till_date}; delete $options->{date_range_include}; @@ -372,7 +373,9 @@ sub showCalendar { my $format = undef; if ( defined $date->{'format'} ) { $format = - ( $date->{'format'} || '' ) . " " . ( $date->{'format_version'} || '' ) . " " . ( $date->{'format_profile'} || '' ); + ( $date->{'format'} || '' ) . " " + . ( $date->{'format_version'} || '' ) . " " + . ( $date->{'format_profile'} || '' ); $format =~ s/MPEG Audio Version 1 Layer 3/MP3/g; $format .= ' ' . ( $date->{'format_settings'} || '' ) if defined $date->{'format_settings'}; $format .= '
'; @@ -383,20 +386,27 @@ sub showCalendar { $date->{series_id} = -1; $date->{event_id} = $id; $date->{title} = ''; - $date->{title} .= 'errors: ' . $date->{errors} . '
' if defined $date->{errors}; + $date->{title} .= 'errors: ' . $date->{errors} . '
' if defined $date->{errors}; $date->{title} .= formatDuration( $date->{duration} ) . "
" if defined $date->{duration}; $date->{title} .= formatLoudness( "L:", $date->{rms_left} ) . ', ' if defined $date->{rms_left}; $date->{title} .= formatLoudness( "R:", $date->{rms_right} ) . '
' if defined $date->{rms_right}; - $date->{title} .= formatBitrate( $date->{bitrate} ) . ' ' . $date->{bitrate_mode} . '
' if defined $date->{bitrate}; - $date->{title} .= 'replay gain ' . sprintf( "%.1f", $date->{replay_gain} ) . '
' if defined $date->{replay_gain}; - $date->{title} .= ( ( $date->{sampling_rate} || '0' ) / 1000 ) . ' kHz
' if defined $date->{sampling_rate}; + $date->{title} .= formatBitrate( $date->{bitrate} ) . ' ' . $date->{bitrate_mode} . '
' + if defined $date->{bitrate}; + $date->{title} .= 'replay gain ' . sprintf( "%.1f", $date->{replay_gain} ) . '
' + if defined $date->{replay_gain}; + $date->{title} .= ( ( $date->{sampling_rate} || '0' ) / 1000 ) . ' kHz
' + if defined $date->{sampling_rate}; $date->{title} .= ( $date->{channels} || '' ) . ' channels
' if defined $date->{channels}; - $date->{title} .= int( ( $date->{'stream_size'} || '0' ) / ( 1024 * 1024 ) ) . 'MB
' if defined $date->{'stream_size'}; + $date->{title} .= int( ( $date->{'stream_size'} || '0' ) / ( 1024 * 1024 ) ) . 'MB
' + if defined $date->{'stream_size'}; $date->{title} .= $format if defined $format; - $date->{title} .= 'library: ' . ( $date->{writing_library} || '' ) . '
' if defined $date->{'writing_library'}; - $date->{title} .= 'path: ' . ( $date->{file} || '' ) . '
' if defined $date->{file}; - $date->{title} .= 'updated_at: ' . ( $date->{updated_at} || '' ) . '
' if defined $date->{updated_at}; - $date->{title} .= 'modified_at: ' . ( $date->{modified_at} || '' ) . '
' if defined $date->{modified_at}; + $date->{title} .= 'library: ' . ( $date->{writing_library} || '' ) . '
' + if defined $date->{'writing_library'}; + $date->{title} .= 'path: ' . ( $date->{file} || '' ) . '
' if defined $date->{file}; + $date->{title} .= 'updated_at: ' . ( $date->{updated_at} || '' ) . '
' + if defined $date->{updated_at}; + $date->{title} .= 'modified_at: ' . ( $date->{modified_at} || '' ) . '
' + if defined $date->{modified_at}; #print STDERR Dumper($date) if $date->{file}=~/180503/; #$date->{title}.= 'rms_image: ' .($date->{rms_image}||'').'
' if defined $date->{rms_image}; @@ -540,7 +550,7 @@ sub formatLoudness { return '' if $value eq ''; #print STDERR "'$value'\n"; - $value = sprintf( "%d", $value+0.5 ); + $value = sprintf( "%d", $value + 0.5 ); my $class = 'ok'; $class = 'warn' if $value > -18.5; $class = 'error' if $value > -16.0; @@ -553,7 +563,7 @@ sub formatDuration { my $duration = shift; return '' unless defined $duration; return '' if $duration eq ''; - my $result = int( ( $duration +30.5 ) % 60)-30; + my $result = int( ( $duration + 30.5 ) % 60 ) - 30; my $class = "ok"; $class = "warn" if abs($result) > 1; $class = "error" if abs($result) > 2; @@ -720,10 +730,10 @@ sub showEventList { my $events_by_day = shift; my $language = $params->{language}; - my $rerunIcon=''; - my $liveIcon=''; - my $draftIcon=''; - my $archiveIcon=''; + my $rerunIcon = ''; + my $liveIcon = ''; + my $draftIcon = ''; + my $archiveIcon = ''; my $out = ''; $out = qq{ @@ -762,7 +772,12 @@ sub showEventList { $event->{studio_id} = $params->{studio_id}; $event->{series_id} = '-1' unless defined $event->{series_id}; $event->{event_id} = '-1' unless defined $event->{event_id}; - my $id = 'event_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{series_id} . '_' . $event->{event_id}; + my $id = + 'event_' + . $event->{project_id} . '_' + . $event->{studio_id} . '_' + . $event->{series_id} . '_' + . $event->{event_id}; my $class = 'event'; $class = $event->{class} if defined $event->{class}; @@ -795,20 +810,22 @@ sub showEventList { $class ||= ''; my $archived = $event->{archived} || '-'; - $archived = '-' if $archived eq '0'; + $archived = '-' if $archived eq '0'; $archived = $archiveIcon if $archived eq '1'; my $live = $event->{live} || '-'; - $live = '-' if $live eq '0'; + $live = '-' if $live eq '0'; $live = $liveIcon if $live eq '1'; my $rerun = $event->{rerun} || '-'; $rerun = " [" . markup::base26( $event->{recurrence_count} + 1 ) . "]" - if ( defined $event->{recurrence_count} ) && ( $event->{recurrence_count} ne '' ) && ( $event->{recurrence_count} > 0 ); + if ( defined $event->{recurrence_count} ) + && ( $event->{recurrence_count} ne '' ) + && ( $event->{recurrence_count} > 0 ); my $draft = $event->{draft} || '0'; - $draft = '-' if $draft eq '0'; + $draft = '-' if $draft eq '0'; $draft = $draftIcon if $draft eq '1'; my $title = $event->{title}; @@ -858,7 +875,8 @@ sub showEventList { $out .= q{}; } @@ -1115,13 +1133,14 @@ sub printTableBody { if ( ( defined $event->{title} ) && ( defined $event->{title} ne '' ) ) { $content .= $event->{title}; unless ( $event->{title} =~ /\#\d+/ ) { - $content .= ' #' . $event->{episode} if ( ( defined $event->{episode} ) && ( $event->{episode} ne '' ) ); + $content .= ' #' . $event->{episode} + if ( ( defined $event->{episode} ) && ( $event->{episode} ne '' ) ); } } $content = $event->{start} if $day eq '0'; $event->{project_id} = $project_id unless defined $event->{project_id}; $event->{studio_id} = $studio_id unless defined $event->{studio_id}; - $event->{content} = $content unless ( ( defined $event->{class} ) && ( $event->{class} eq 'time now' ) ); + $event->{content} = $content unless ( ( defined $event->{class} ) && ( $event->{class} eq 'time now' ) ); $event->{class} = 'event' if $day ne '0'; $event->{class} = 'grid' if ( ( defined $event->{grid} ) && ( $event->{grid} == 1 ) ); $event->{class} = 'schedule' if ( ( defined $event->{schedule} ) && ( $event->{schedule} == 1 ) ); @@ -1133,6 +1152,7 @@ sub printTableBody { $event->{content} .= formatDuration( $event->{duration} ) . ' ' if defined $event->{duration}; $event->{content} .= formatLoudness( 'L', $event->{rms_left} ) . ' ' if defined $event->{rms_left}; $event->{content} .= formatLoudness( 'R', $event->{rms_right} ) if defined $event->{rms_right}; + #$event->{content} .= formatBitrate( $event->{bitrate} ) if defined $event->{bitrate}; $event->{content} .= ''; } @@ -1173,7 +1193,10 @@ sub printSeries { my $out = ''; #add schedule entry for series - if ( ( defined $permissions->{update_schedule} ) && ( $permissions->{update_schedule} eq '1' ) && ( scalar(@$series) > 0 ) ) { + if ( ( defined $permissions->{update_schedule} ) + && ( $permissions->{update_schedule} eq '1' ) + && ( scalar(@$series) > 0 ) ) + { $out .= q{}; @@ -1183,7 +1206,8 @@ sub printSeries { $out .= q{}; } @@ -1349,11 +1373,14 @@ sub createSeries {-
@@ -1374,10 +1401,17 @@ sub print_event { $event->{series_id} = '-1' unless defined $event->{series_id}; $event->{event_id} = '-1' unless defined $event->{event_id}; - my $id = 'event_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{series_id} . '_' . $event->{event_id}; - $id = 'grid_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{series_id} if defined $event->{grid}; - $id = 'work_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{schedule_id} if defined $event->{work}; - $id = 'play_' . $event->{project_id} . '_' . $event->{studio_id} if defined $event->{play}; + my $id = + 'event_' + . $event->{project_id} . '_' + . $event->{studio_id} . '_' + . $event->{series_id} . '_' + . $event->{event_id}; + $id = 'grid_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{series_id} + if defined $event->{grid}; + $id = 'work_' . $event->{project_id} . '_' . $event->{studio_id} . '_' . $event->{schedule_id} + if defined $event->{work}; + $id = 'play_' . $event->{project_id} . '_' . $event->{studio_id} if defined $event->{play}; my $class = $event->{class} || ''; my $showIcons = 0; @@ -1400,7 +1434,7 @@ sub print_event { $ystart = int( $ystart * $yzoom ); $yend = int( $yend * $yzoom ); - my $height = $yend - $ystart +1; + my $height = $yend - $ystart + 1; if ( $ypos > 0 ) { $height = q{height:} . ($height) . 'px;'; @@ -1418,6 +1452,7 @@ sub print_event { my $attr = ''; if ( $class =~ /play/ ) { + #$event->{rms_image}=~s/\.png/.svg/; $attr .= ' rms="' . $event->{rms_image} . '"' if defined $event->{rms_image}; $attr .= ' start="' . $event->{start} . '"' if defined $event->{start}; @@ -1476,11 +1511,10 @@ sub calc_positions { my ( $start_hour, $start_min ) = getTime( $event->{start_time} ); my ( $end_hour, $end_min ) = getTime( $event->{end_time} ); - $start_hour += 24 if $start_hour < $start_of_day; - $end_hour += 24 if $end_hour < $start_of_day; - $end_hour += 24 if $start_hour > $end_hour; - $end_hour += 24 if ($start_hour == $end_hour) && ($start_min == $end_min); - + $start_hour += 24 if $start_hour < $start_of_day; + $end_hour += 24 if $end_hour < $start_of_day; + $end_hour += 24 if $start_hour > $end_hour; + $end_hour += 24 if ( $start_hour == $end_hour ) && ( $start_min == $end_min ); $event->{ystart} = $start_hour * 60 + $start_min; $event->{yend} = $end_hour * 60 + $end_min; @@ -1623,7 +1657,10 @@ sub printToolbar {- } . $params->{loc}->{label_name} . qq{ + } . $params->{loc}->{label_title} . qq{ + } + . $params->{loc}->{label_name} . qq{ } + . $params->{loc}->{label_title} . qq{ - +