diff --git a/lib/calcms/aggregator.pm b/lib/calcms/aggregator.pm index c45d2e5..e61b421 100644 --- a/lib/calcms/aggregator.pm +++ b/lib/calcms/aggregator.pm @@ -1,18 +1,18 @@ package aggregator; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use events(); use comments(); use calendar(); use project(); -use cache(); use base 'Exporter'; -our @EXPORT_OK = qw(get_cache configure_cache put_cache get_list check_params); +our @EXPORT_OK = qw(get_cache configure_cache put_cache get_list check_params); -sub get_list { +sub get_list($$) { my $config = shift; my $request = shift; @@ -54,8 +54,6 @@ sub get_list { my @used_projects = reverse sort { $used_projects->{$a} <=> $used_projects->{$b} } ( keys %$used_projects ); my $most_used_project = $used_projects[0]; - #use Data::Dumper;print STDERR Dumper(\@used_projects); - return { day => $results->[0]->{day}, start_datetime => $results->[0]->{start_datetime}, @@ -70,7 +68,7 @@ sub get_list { }; } -sub get_menu { +sub get_menu($$$$) { my $config = shift; my $request = shift; my $date = shift; @@ -86,7 +84,7 @@ sub get_menu { $request->{params}->{checked} = events::check_params( $config, $request->{params}->{original} ); $results = events::get( $config, $request ); } else { - $request->{params}->{checked}->{template} = template::check($config, 'event_menu.html'); + $request->{params}->{checked}->{template} = template::check( $config, 'event_menu.html' ); } #events menu @@ -96,7 +94,7 @@ sub get_menu { return { content => $output }; } -sub get_calendar { +sub get_calendar($$$) { my $config = shift; my $request = shift; my $date = shift; @@ -122,7 +120,7 @@ sub get_calendar { return { content => $content }; } -sub get_newest_comments { +sub get_newest_comments($$) { my $config = shift; my $request = shift; @@ -146,49 +144,7 @@ sub get_newest_comments { return { content => $content }; } -sub get_cache { - my $config = shift; - my $request = shift; - - my $params = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; - - if ( $config->{cache}->{use_cache} == 1 ) { - configure_cache($config); - my $cache = cache::load( $config, $params ); - return $cache; - } - return {}; -} - -sub configure_cache { - my $config = shift; - - cache::init(); - my $controllers = $config->{controllers}; - - my $date_pattern = cache::get_date_pattern(); - - # cache::add_map('' ,'programm/index.html'); - cache::add_map( 'date=today', 'programm/' . $controllers->{events} . '/today.html' ); - cache::add_map( 'date=' . $date_pattern, 'programm/' . $controllers->{events} . '/$1-$2-$3.html' ); - cache::add_map( 'from_date=' . $date_pattern . '&till_date=' . $date_pattern, - 'programm/' . $controllers->{events} . '/$1-$2-$3_$4-$5-$6.html' ); - cache::add_map( 'event_id=(\d+)', 'programm/' . $controllers->{event} . '/$1.html' ); -} - -sub put_cache { - my $config = shift; - my $request = shift; - my $cache = shift; - - #write to cache - if ( $config->{cache}->{use_cache} == 1 ) { - cache::save($cache); - } -} - -sub check_params { +sub check_params($$) { my $config = shift; my $params = shift; @@ -200,14 +156,8 @@ sub check_params { #filter for date my $date = time::check_date( $params->{date} ); - #print STDERR $date."\n"; - if ( $date eq '' ) { - $date = time::time_to_date( time() ); - } - # - if ( $date eq 'today' ) { - $date = time::get_event_date($config); - } + $date = time::time_to_date( time() ) if $date eq ''; + $date = time::get_event_date($config) if $date eq 'today'; # $date =$config->{date}->{start_date} if ($date lt $config->{date}->{start_date}); # $date =$config->{date}->{end_date} if ($date gt $config->{date}->{end_date}); @@ -279,8 +229,6 @@ sub check_params { from_date => $from_date, till_date => $till_date, event_id => $event_id, - - # project => $project, debug => $debug, }; } diff --git a/lib/calcms/audio_recordings.pm b/lib/calcms/audio_recordings.pm index dc341e9..67b3f5e 100644 --- a/lib/calcms/audio_recordings.pm +++ b/lib/calcms/audio_recordings.pm @@ -1,13 +1,14 @@ package audio_recordings; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use db(); use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get); +our @EXPORT_OK = qw(get_columns get); # columns: # id, project_id, studio_id, event_id @@ -17,7 +18,7 @@ our @EXPORT_OK = qw(get_columns get); sub debug; -sub get_columns { +sub get_columns($) { my $config = shift; my $dbh = db::connect($config); @@ -30,7 +31,7 @@ sub get_columns { } # get playout entries -sub get { +sub get($$) { my $config = shift; my $condition = shift; @@ -38,7 +39,8 @@ sub get { 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 ); + $date_range_include = 1 + if ( defined $condition->{date_range_include} ) && ( $condition->{date_range_include} == 1 ); my $dbh = db::connect($config); @@ -105,7 +107,7 @@ sub get { } # update playout entry if differs to old values -sub update { +sub update($$$) { my $config = shift; my $dbh = shift; my $entry = shift; @@ -144,7 +146,7 @@ sub update { } # insert playout entry -sub insert { +sub insert ($$$) { my $config = shift; my $dbh = shift; my $entry = shift; @@ -177,7 +179,7 @@ sub insert { } # delete playout entry -sub delete { +sub delete ($$$) { my $config = shift; my $dbh = shift; my $entry = shift; @@ -196,7 +198,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/auth.pm b/lib/calcms/auth.pm index cb9c889..a2cc7bc 100644 --- a/lib/calcms/auth.pm +++ b/lib/calcms/auth.pm @@ -1,7 +1,8 @@ package auth; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use CGI::Simple(); use CGI::Session qw(-ip-match); @@ -22,7 +23,7 @@ my $debug = 0; sub debug; #TODO: remove CGI -sub get_user { +sub get_user($$$) { my $config = shift; my $params = shift; my $cgi = shift; @@ -61,7 +62,7 @@ sub get_user { return $session->{user}, $session->{expires}; } -sub crypt_password { +sub crypt_password($) { my $password = shift; my $ppr = Authen::Passphrase::BlowfishCrypt->new( @@ -75,7 +76,7 @@ sub crypt_password { }; } -sub login { +sub login($$$) { my $config = shift; my $user = shift; my $password = shift; @@ -98,8 +99,9 @@ sub login { } #TODO: remove cgi -sub logout { - my $cgi = shift; +sub logout($) { + my $cgi = shift; + my $session_id = read_cookie(); debug("logout") if $debug; unless ( delete_session($session_id) ) { @@ -115,7 +117,7 @@ sub logout { } #read and write data from browser, http://perldoc.perl.org/CGI/Cookie.html -sub create_cookie { +sub create_cookie($$) { my $session_id = shift; my $timeout = shift; @@ -131,7 +133,7 @@ sub create_cookie { return 1; } -sub read_cookie { +sub read_cookie() { debug("read_cookie") if $debug; my %cookie = CGI::Cookie->fetch; debug( "cookies: " . Dumper( \%cookie ) ) if $debug; @@ -144,7 +146,7 @@ sub read_cookie { } #TODO: remove CGI -sub delete_cookie { +sub delete_cookie($) { my $cgi = shift; debug("delete_cookie") if $debug; @@ -157,9 +159,9 @@ sub delete_cookie { return 1; } -#read and write server-side session data +# read and write server-side session data # expiration is in seconds -sub create_session { +sub create_session ($$$) { my $user = shift; my $password = shift; my $expiration = shift; @@ -174,7 +176,7 @@ sub create_session { return $session->id(); } -sub read_session { +sub read_session($) { my $session_id = shift; debug("read_session") if $debug; @@ -194,7 +196,7 @@ sub read_session { }; } -sub delete_session { +sub delete_session($) { my $session_id = shift; debug("delete_session") if $debug; @@ -205,7 +207,7 @@ sub delete_session { } #check user authentication -sub authenticate { +sub authenticate($$$) { my $config = shift; my $user = shift; my $password = shift; @@ -237,7 +239,7 @@ sub authenticate { # timeout in seconds my $timeout = $users->[0]->{session_timeout} || 120; - $timeout = 60 if $timeout < 60; + $timeout = 60 if $timeout < 60; return { timeout => $timeout, @@ -245,7 +247,7 @@ sub authenticate { }; } -sub show_login_form { +sub show_login_form ($$) { my $user = shift || ''; my $uri = $ENV{HTTP_REFERER} || ''; my $message = shift || ''; @@ -359,7 +361,7 @@ sub show_login_form { return undef; } -sub debug { +sub debug ($) { my $message = shift; print STDERR "$message\n" if $debug > 0; return; diff --git a/lib/calcms/cache.pm b/lib/calcms/cache.pm deleted file mode 100644 index ffa0a73..0000000 --- a/lib/calcms/cache.pm +++ /dev/null @@ -1,183 +0,0 @@ -package cache; - -use warnings "all"; -use strict; - -use config(); -use time(); -use log(); -use markup(); - -use base 'Exporter'; -our @EXPORT_OK = qw(init add_map get_map get_map_keys load save get_filename escape_regexp escape_regexp_line); - -my $cache_map = {}; -my $cache_map_keys = []; -my $header_printed = 0; - -my $date_pattern = '(\d{4})\-(\d{2})\-(\d{2})'; -my $datetime_pattern = '(\d{4})\-(\d{2})\-(\d{2})[T\+](\d{2})\:(\d{2})(\:\d{2})?'; - -sub init { - $cache_map = {}; - $cache_map_keys = []; - $header_printed = 0; -} - -sub get_date_pattern(){ - return $date_pattern; -} - -sub get_datetime_pattern(){ - return $datetime_pattern; -} - -sub add_map { - my $key = $_[0]; - my $value = $_[1]; - - $key = '^' . $key . '$'; - push @$cache_map_keys, $key; - $cache_map->{$key} = $value; -} - -sub get_map { - return $cache_map; -} - -sub get_map_keys { - return $cache_map_keys; -} - -#get cache from params -sub load { - my $params = shift; - - my $filename = get_filename($params); - - my $result = { filename => $filename }; - - if ( defined $filename ) { - my @file_info = stat($filename); - my $modified = $file_info[9] || ''; - if ( $modified ne '' ) { - - #file exists - my @now = localtime( time() ); - my @modified = localtime($modified); - if ( $now[2] == $modified[2] ) { - - #file is elder than a hour - my $content = log::load_file($filename); - if ( defined $content ) { - $result->{content} = $content; - $result->{action} = 'read'; - return $result; - } - } - } - } - - $result->{action} = 'save'; - return $result; -} - -#get filename from params -sub get_filename { - my $config = shift; - my $params = shift; - - # my $url=$ENV{REQUEST_URI}; - my $url = $ENV{QUERY_STRING} || ''; - if ( $url ne '' ) { - $url =~ s/(^|\&)update\=\d//gi; - $url =~ s/(^|\&)debug\=.*//gi; - $url =~ s/\?\&/\?/g; - $url =~ s/\&{2,99}/\&/g; - $url =~ s/\&$//g; - $url =~ s/^\/\//\//g; - } - foreach my $pattern (@$cache_map_keys) { - - my $filename = $url; - if ( $filename =~ /$pattern/ ) { - my $m1 = $1; - my $m2 = $2; - my $m3 = $3; - my $m4 = $4; - my $m5 = $5; - my $m6 = $6; - my $m7 = $7; - my $m8 = $8; - - # my $m9=$9; - - my $result = $cache_map->{$pattern}; - - $filename =~ s/$pattern/$result/; - $filename =~ s/\$1/$m1/ if ( defined $m1 ); - $filename =~ s/\$2/$m2/ if ( defined $m2 ); - $filename =~ s/\$3/$m3/ if ( defined $m3 ); - $filename =~ s/\$4/$m4/ if ( defined $m4 ); - $filename =~ s/\$5/$m5/ if ( defined $m5 ); - $filename =~ s/\$6/$m6/ if ( defined $m6 ); - $filename =~ s/\$7/$m7/ if ( defined $m7 ); - $filename =~ s/\$8/$m8/ if ( defined $m8 ); - - # $filename=~s/\$9/$m9/ if (defined $m9); - $filename = $config->{cache}->{cache_dir} . $filename; - return $filename; - } - } - return undef; -} - -#deprecated: set file from params -sub set { - my $params = shift; - my $content = shift; - - my $filename = get_filename($params); - my $cache = { - filename => $filename, - content => $content - }; - - # print $filename.":file\n"; - - if ( defined $filename ) { - cache::save($cache); - } -} - -sub save { - my $cache = shift; - - return if $cache->{action} ne 'save'; - return if ( !defined $cache->{filename} ) || ( $cache->{filename} eq '' ); - - log::save_file( $cache->{filename}, $cache->{content} ); - chmod 0664, $cache->{filename}; -} - -sub escape_regexp { - my $reg_exp = shift; - $reg_exp =~ s/([\^\$\\(\)\[\]\{\}\|\/\*\+\.\-\&\:])/\\$1/gi; - return $reg_exp; -} - -sub escape_regexp_line { - my $reg_exp = shift; - $reg_exp =~ s/([\^\$\\(\)\[\]\{\}\|\/\*\+\.\-\&\:])/\\$1/gi; - return '^' . $reg_exp . '$'; -} - -sub configure { - my $file_name = shift; - - cache::init(); - cache::add_map( '', $file_name ); -} - -#do not delete last line! -1; diff --git a/lib/calcms/calendar.pm b/lib/calcms/calendar.pm index e6a4212..9a89b85 100644 --- a/lib/calcms/calendar.pm +++ b/lib/calcms/calendar.pm @@ -1,22 +1,22 @@ package calendar; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use Date::Calc(); use template(); -use cache(); use events(); use base 'Exporter'; our @EXPORT_OK = qw(init get_cached_or_render get render get_calendar_weeks configure_cache); -sub init { +sub init() { } -sub get_cached_or_render { +sub get_cached_or_render($$$) { # my $output = $_[0] my $config = $_[1]; @@ -25,30 +25,12 @@ sub get_cached_or_render { my $parms = $request->{params}->{checked}; my $debug = $config->{system}->{debug}; - my $cache = {}; - if ( $config->{cache}->{use_cache} == 1 ) { - calendar::configure_cache($config); - $cache = cache::load( $config, $parms ); - if ( defined $cache->{content} ) { - $_[0] = $cache->{content}; - return; - } - } - my $calendar = calendar::get( $config, $request ); calendar::render( $_[0], $config, $request, $calendar ); - - #write to cache - if ( $config->{cache}->{use_cache} == 1 ) { - - #todo:put out reference only - $cache->{content} = $_[0]; - cache::save($cache); - } } -sub get { +sub get($$) { my $config = shift; my $request = shift; @@ -156,7 +138,7 @@ sub get { $start_year = $1; $start_month = $2; } - my $monthNames=time::getMonthNamesShort($language); + my $monthNames = time::getMonthNamesShort($language); my $start_month_name = $monthNames->[ $start_month - 1 ]; if ( $params->{month_only} eq '1' ) { @@ -208,7 +190,8 @@ sub get { my $weekday = 0; my $day_result = undef; - ( $week_of_year, $woy_year ) = Date::Calc::Week_of_Year( $year, $month, $day ) unless defined $week_of_year; + ( $week_of_year, $woy_year ) = Date::Calc::Week_of_Year( $year, $month, $day ) + unless defined $week_of_year; $day_result = { date => $date, @@ -299,7 +282,7 @@ sub get { } -sub render { +sub render($$$$) { # my $out = $_[0]; my $config = $_[1]; @@ -314,12 +297,13 @@ sub render { $template_parameters->{base_url} = $config->{locations}->{base_url}; $template_parameters->{cache_base_url} = $config->{cache}->{base_url}; $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} ); template::process( $config, $_[0], $parms->{template}, $template_parameters ); } -sub get_calendar_weeks { +sub get_calendar_weeks($$$) { my $config = shift; my $start = shift; my $end = shift; @@ -349,7 +333,7 @@ sub get_calendar_weeks { return $years; } -sub getWeeksOfMonth { +sub getWeeksOfMonth($$) { my $thisYear = shift; my $thisMonth = shift; my $thisDay = 1; @@ -439,22 +423,7 @@ sub getWeeksOfMonth { return \@weeks; } -sub configure_cache { - my $config = shift; - my $debug = $config->{system}->{debug}; - - cache::init(); - - my $date_pattern = cache::get_date_pattern(); - my $controllers = $config->{controllers}; - - cache::add_map( '', $controllers->{calendar} . '/cal.html' ); - cache::add_map( 'date=' . $date_pattern, $controllers->{calendar} . '/$1-$2.html' ); - cache::add_map( 'from_date=' . $date_pattern . '&till_date=' . $date_pattern, $controllers->{calendar} . '/$1-$2_$5-$6.html' ); - -} - -sub check_params { +sub check_params($$) { my $config = shift; my $params = shift; diff --git a/lib/calcms/comments.pm b/lib/calcms/comments.pm index 11f3153..2396abf 100644 --- a/lib/calcms/comments.pm +++ b/lib/calcms/comments.pm @@ -1,7 +1,8 @@ package comments; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use db(); @@ -12,13 +13,12 @@ use time(); use base 'Exporter'; our @EXPORT_OK = - qw(init get_cached_or_render get modify_results render configure_cache get_query get_by_event get_level get_events check insert set_lock_status set_news_status lock update_comment_count sort) - ; + qw(init get_cached_or_render get modify_results render configure_cache get_query get_by_event get_level get_events check insert set_lock_status set_news_status lock update_comment_count sort); -sub init { +sub init() { } -sub get_cached_or_render { +sub get_cached_or_render($$$;$) { # my $response=$_[0]; my $config = $_[1]; @@ -33,7 +33,6 @@ sub get_cached_or_render { my $comment = $request->{params}->{checked}; my $filename = ''; - my $cache = {}; my $results = comments::get( $config, $request ); @@ -54,15 +53,8 @@ sub get_cached_or_render { comments::modify_results( $results, $config, $request ); - #print STDERR Dumper($results); $results = comments::sort( $config, $results ) if ( $comment->{type} eq 'tree' ); - #print STDERR Dumper($results); - # if ($comment->{sort_order}eq'desc'){ - # my @results= reverse(@$results); - # $results=\@results; - # } - if ( ( $params->{show_max} ne '' ) && ( $params->{limit} ne '' ) && ( $params->{show_max} < $params->{limit} ) ) @@ -81,7 +73,7 @@ sub get_cached_or_render { } -sub get { +sub get($$) { my $config = shift; my $request = shift; @@ -99,7 +91,7 @@ sub get { return $results; } -sub get_query { +sub get_query($$$) { my $dbh = shift; my $config = shift; my $request = shift; @@ -150,8 +142,9 @@ sub get_query { } my $dbcols = [ - 'id', 'event_start', 'event_id', 'content', 'ip', 'author', 'email', 'lock_status', - 'created_at', 'title', 'parent_id', 'level', 'news_status', 'project' + 'id', 'event_start', 'event_id', 'content', 'ip', 'author', + 'email', 'lock_status', 'created_at', 'title', 'parent_id', 'level', + 'news_status', 'project' ]; my $cols = join( ', ', map { 'c.' . $_ } @$dbcols ); my $query = qq{ @@ -168,7 +161,7 @@ sub get_query { return ( \$query, $bind_values ); } -sub modify_results { +sub modify_results($$$) { my $results = $_[0]; my $config = $_[1]; my $request = $_[2]; @@ -204,11 +197,12 @@ sub modify_results { $result->{content} = markup::html_to_plain( $result->{html_content} ); $result->{short_content} = markup::html_to_plain( $result->{short_content} ); - $result->{excerpt} = "lass dich ueberraschen" if ( defined $result->{excerpt} ) && ( $result->{excerpt} eq '' ); - $result->{excerpt} = markup::html_to_plain( $result->{excerpt} ); - $result->{title} = markup::html_to_plain( $result->{title} ); - $result->{series_name} = markup::html_to_plain( $result->{series_name} ); - $result->{program} = markup::html_to_plain( $result->{program} ); + $result->{excerpt} = "lass dich ueberraschen" + if ( defined $result->{excerpt} ) && ( $result->{excerpt} eq '' ); + $result->{excerpt} = markup::html_to_plain( $result->{excerpt} ); + $result->{title} = markup::html_to_plain( $result->{title} ); + $result->{series_name} = markup::html_to_plain( $result->{series_name} ); + $result->{program} = markup::html_to_plain( $result->{program} ); if ( defined $result->{created_at} ) { $result->{created_at} =~ s/ /T/gi; @@ -224,7 +218,7 @@ sub modify_results { return $results; } -sub render { +sub render($$$$) { # my $response =$_[0]; my $config = $_[1]; @@ -244,14 +238,15 @@ sub render { $template_parameters->{event_id} = $params->{event_id}; $template_parameters->{event_start} = $params->{event_start}; - $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->{controllers} = $config->{controllers}; + $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->{controllers} = $config->{controllers}; template::process( $config, $_[0], $params->{template}, $template_parameters ); } #check if comment exists already -sub check { +sub check ($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -268,8 +263,10 @@ sub check { and ip=? and content=? }; - my $bind_values = - [ $comment->{event_start}, $comment->{event_id}, $comment->{parent_id}, $comment->{author}, $comment->{ip}, $comment->{content} ]; + my $bind_values = [ + $comment->{event_start}, $comment->{event_id}, $comment->{parent_id}, + $comment->{author}, $comment->{ip}, $comment->{content} + ]; my $comments = db::get( $dbh, $query, $bind_values ); @@ -279,7 +276,7 @@ sub check { } #used for insert -sub get_level { +sub get_level($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -314,7 +311,7 @@ sub get_level { return 0; } -sub get_by_event { +sub get_by_event($$$) { my $dbh = shift; my $config = shift; my $request = $_[0]; @@ -359,7 +356,7 @@ sub get_by_event { return $comments; } -sub get_by_time { +sub get_by_time($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -398,7 +395,7 @@ sub get_by_time { return $comments; } -sub get_events { +sub get_events($$$$) { my $dbh = shift; my $config = shift; my $request = shift; @@ -465,7 +462,7 @@ sub get_events { return \@sorted_events; } -sub insert { +sub insert ($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -488,7 +485,7 @@ sub insert { return $comment_id; } -sub set_lock_status { +sub set_lock_status ($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -516,7 +513,7 @@ sub set_lock_status { } } -sub set_news_status { +sub set_news_status($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -532,7 +529,7 @@ sub set_news_status { db::put( $dbh, $query, $bind_values ); } -sub update_comment_count { +sub update_comment_count ($$$) { my $dbh = shift; my $config = shift; my $comment = shift; @@ -557,8 +554,26 @@ sub update_comment_count { db::put( $dbh, $query, $bind_values ); } +sub sort_childs { + my $node = shift; + my $nodes = shift; + my $sorted_nodes = shift; + + #push node into list of sorted nodes + push @{$sorted_nodes}, $node; + + #return if node is leaf + return $sorted_nodes unless ( defined $node->{childs} ); + + #process child nodes + for my $child ( @{ $node->{childs} } ) { + $sorted_nodes = sort_childs( $child, $nodes, $sorted_nodes ); + } + return $sorted_nodes; +} + #precondition: results are presorted by creation date (by sql) -sub sort { +sub sort($$) { my $config = shift; my $results = shift; @@ -589,44 +604,15 @@ sub sort { return $sorted_nodes; } -sub sort_childs { - my $node = shift; - my $nodes = shift; - my $sorted_nodes = shift; - - #push node into list of sorted nodes - push @{$sorted_nodes}, $node; - - #return if node is leaf - return $sorted_nodes unless ( defined $node->{childs} ); - - #process child nodes - for my $child ( @{ $node->{childs} } ) { - $sorted_nodes = sort_childs( $child, $nodes, $sorted_nodes ); - } - return $sorted_nodes; -} - -sub configure_cache { - my $config = shift; - - cache::init(); - my $controllers = $config->{controllers}; - - cache::add_map( 'template=comments_newest&limit=3&type=list', $controllers->{comments} . '/neueste.html' ); - cache::add_map( 'template=comments_atom.xml&limit=20', $controllers->{comments} . '/feed.xml' ); - cache::add_map( 'template=comments.html&event_id=(\d+)&event_start=' . cache::get_datetime_pattern(), - $controllers->{comments} . '/$1_$2-$3-$4_$5-$6.html' ); -} - -sub check_params { - my $config = shift; - my $params = shift; - +sub check_params ($$) { + my $config = shift; + my $params = shift; my $comment = {}; $comment->{event_start} = ''; - if ( ( defined $params->{event_start} ) && ( $params->{event_start} =~ /(\d\d\d\d\-\d\d\-\d\d[T ]\d\d\:\d\d)(\:\d\d)?/ ) ) { + if ( ( defined $params->{event_start} ) + && ( $params->{event_start} =~ /(\d\d\d\d\-\d\d\-\d\d[T ]\d\d\:\d\d)(\:\d\d)?/ ) ) + { $comment->{event_start} = $1; } @@ -665,9 +651,10 @@ sub check_params { $comment->{debug} = $1; } - log::error( $config, 'missing parameter a' ) if ( defined $params->{limit} ) && ( $comment->{limit} eq '' ); - log::error( $config, 'missing parameter b' ) if ( defined $params->{event_id} ) && ( $comment->{event_id} eq '' ); - log::error( $config, 'missing parameter c' ) if ( defined $params->{event_start} ) && ( $comment->{event_start} eq '' ); + log::error( $config, 'missing parameter a' ) if ( defined $params->{limit} ) && ( $comment->{limit} eq '' ); + log::error( $config, 'missing parameter b' ) if ( defined $params->{event_id} ) && ( $comment->{event_id} eq '' ); + log::error( $config, 'missing parameter c' ) + if ( defined $params->{event_start} ) && ( $comment->{event_start} eq '' ); my $delta_days = 1; if ( $comment->{event_start} ne '' ) { @@ -690,3 +677,4 @@ sub check_params { #do not delete last line! 1; + diff --git a/lib/calcms/config.pm b/lib/calcms/config.pm index 56bdcfb..5a8b942 100644 --- a/lib/calcms/config.pm +++ b/lib/calcms/config.pm @@ -1,7 +1,8 @@ package config; -use warnings; use strict; +use warnings; +no warnings 'redefine'; use FindBin(); use Config::General(); @@ -11,13 +12,13 @@ our @EXPORT_OK = qw(get set); my $config = undef; -sub set { +sub set($) { my $value = shift; $config = $value; return; } -sub get { +sub get($) { my $filename = shift; return $config if ( defined $config ) && ( $config->{cache}->{cache_config} == 1 ); diff --git a/lib/calcms/creole_wiki.pm b/lib/calcms/creole_wiki.pm index f17fa89..72d590c 100644 --- a/lib/calcms/creole_wiki.pm +++ b/lib/calcms/creole_wiki.pm @@ -1,7 +1,8 @@ package creole_wiki; -use warnings; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use markup(); @@ -10,7 +11,7 @@ use base 'Exporter'; our @EXPORT_OK = qw(extractEventFromWikiText removeMeta eventToWikiText extractMeta removeMeta metaToWiki); #convert creole wiki text to event -sub extractEventFromWikiText { +sub extractEventFromWikiText($;$) { my $params = shift; my $event = shift; $event = {} unless ( defined $event ); @@ -134,7 +135,7 @@ sub extractEventFromWikiText { return $event; } -sub eventToWikiText { +sub eventToWikiText($$) { my $event = shift; my $local_media_url = $event->{local_media_url} || ''; @@ -195,7 +196,7 @@ sub eventToWikiText { } #extrace meta tags from comment text -sub extractMeta { +sub extractMeta ($$){ my $comments = shift; my $meta = shift; @@ -236,7 +237,7 @@ sub extractMeta { } #remove meta tags from comment text -sub removeMeta { +sub removeMeta($) { my $comments = shift || ''; my $result = ''; diff --git a/lib/calcms/db.pm b/lib/calcms/db.pm index c8a2713..81184e3 100644 --- a/lib/calcms/db.pm +++ b/lib/calcms/db.pm @@ -1,7 +1,8 @@ package db; -use warnings 'all'; use strict; +use warnings; +no warnings 'redefine'; use DBD::mysql(); use Data::Dumper; @@ -26,7 +27,7 @@ our $read = 1; our $write = 1; # connect to database -sub connect { +sub connect($;$) { my $options = shift; my $request = shift; @@ -62,7 +63,7 @@ sub connect { return $dbh; } -sub disconnect { +sub disconnect ($){ my $request = shift; my $dbh = $request->{connection}; $dbh->disconnect; @@ -71,7 +72,7 @@ sub disconnect { } # get all database entries of an sql query (as list of hashs) -sub get { +sub get($$;$) { my $dbh = shift; my $sql = shift; my $bind_values = shift; @@ -105,7 +106,7 @@ sub get { } # get list of table columns -sub get_columns { +sub get_columns($$) { my $dbh = shift; my $table = shift; @@ -115,7 +116,7 @@ sub get_columns { } # get hash with table columns as keys -sub get_columns_hash { +sub get_columns_hash($$) { my $dbh = shift; my $table = shift; @@ -128,7 +129,7 @@ sub get_columns_hash { } #returns last inserted id -sub insert { +sub insert ($$$){ my $dbh = shift; my $tablename = shift; my $entry = shift; @@ -151,7 +152,7 @@ sub insert { } # execute a modifying database command (update,insert,...) -sub put { +sub put($$$) { my $dbh = shift; my $sql = shift; my $bind_values = shift; @@ -177,7 +178,7 @@ sub put { return undef; } -sub quote { +sub quote($$) { my $dbh = shift; my $sql = shift; @@ -186,7 +187,7 @@ sub quote { } #subtract hours, deprecated(!) -sub shift_date_by_hours { +sub shift_date_by_hours($$$) { my $dbh = shift; my $date = shift; my $offset = shift; @@ -198,7 +199,7 @@ sub shift_date_by_hours { } #add minutes, deprecated(!) -sub shift_datetime_by_minutes { +sub shift_datetime_by_minutes($$$) { my $dbh = shift; my $datetime = shift; my $offset = shift; @@ -210,7 +211,7 @@ sub shift_datetime_by_minutes { } # get next free id of a database table -sub next_id { +sub next_id ($$){ my $dbh = shift; my $table = shift; @@ -224,7 +225,7 @@ sub next_id { } # get max id from table -sub get_max_id { +sub get_max_id($$) { my $dbh = shift; my $table = shift; diff --git a/lib/calcms/eventOps.pm b/lib/calcms/eventOps.pm index 122b2b0..c260167 100644 --- a/lib/calcms/eventOps.pm +++ b/lib/calcms/eventOps.pm @@ -1,6 +1,8 @@ package eventOps; -use warnings "all"; + use strict; +use warnings; +no warnings 'redefine'; use uac(); use events(); @@ -21,7 +23,7 @@ our @EXPORT_OK = qw( ); # functions: to be separated -sub setAttributesFromSeriesTemplate { +sub setAttributesFromSeriesTemplate($$$) { my $config = shift; my $params = shift; my $event = shift; @@ -54,7 +56,7 @@ sub setAttributesFromSeriesTemplate { return $serie; } -sub setAttributesFromSchedule { +sub setAttributesFromSchedule ($$$){ my $config = shift; my $params = shift; my $event = shift; @@ -87,7 +89,7 @@ sub setAttributesFromSchedule { return $event; } -sub setAttributesFromOtherEvent { +sub setAttributesFromOtherEvent ($$$){ my $config = shift; my $params = shift; my $event = shift; @@ -119,7 +121,7 @@ sub setAttributesFromOtherEvent { return $event; } -sub setAttributesForCurrentTime { +sub setAttributesForCurrentTime ($$){ my $serie = shift; my $event = shift; @@ -138,14 +140,14 @@ sub setAttributesForCurrentTime { } # get recurrence base id -sub getRecurrenceBaseId { +sub getRecurrenceBaseId ($){ my $event = shift; return $event->{recurrence} if ( defined $event->{recurrence} ) && ( $event->{recurrence} ne '' ) && ( $event->{recurrence} ne '0' ); return $event->{event_id}; } # get a new event for given series -sub getNewEvent { +sub getNewEvent($$$) { my $config = shift; my $params = shift; my $action = shift; @@ -205,7 +207,7 @@ sub getNewEvent { } # add user, action -sub createEvent { +sub createEvent($$$) { my $request = shift; my $event = shift; my $action = shift; diff --git a/lib/calcms/event_history.pm b/lib/calcms/event_history.pm index 309b571..6d1a100 100644 --- a/lib/calcms/event_history.pm +++ b/lib/calcms/event_history.pm @@ -1,7 +1,8 @@ package event_history; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; @@ -10,7 +11,7 @@ our @EXPORT_OK = qw(get_columns get get_by_id insert insert_by_event_id delete sub debug; -sub get_columns { +sub get_columns ($){ my $config = shift; my $dbh = db::connect($config); @@ -22,7 +23,7 @@ sub get_columns { return $columns; } -sub get { +sub get ($$){ my $config = shift; my $condition = shift; @@ -85,7 +86,7 @@ sub get { return $changes; } -sub get_by_id { +sub get_by_id($$) { my $config = shift; my $id = shift; @@ -102,7 +103,7 @@ sub get_by_id { return $studios->[0]; } -sub insert { +sub insert($$) { my $config = shift; my $entry = shift; @@ -124,7 +125,7 @@ sub insert { } # insert event -sub insert_by_event_id { +sub insert_by_event_id ($$){ my $config = shift; my $options = shift; @@ -157,7 +158,7 @@ sub insert_by_event_id { event_history::insert( $config, $event ); } -sub delete { +sub delete ($$){ my $config = shift; my $entry = shift; @@ -165,7 +166,7 @@ sub delete { db::put( $dbh, 'delete from calcms_event_history where event_id=?', [ $entry->{id} ] ); } -sub error { +sub error ($){ my $msg = shift; print "ERROR: $msg
\n"; } diff --git a/lib/calcms/events.pm b/lib/calcms/events.pm index 6e0390f..ece6d42 100644 --- a/lib/calcms/events.pm +++ b/lib/calcms/events.pm @@ -1,7 +1,8 @@ package events; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use DBI(); @@ -10,7 +11,7 @@ use template(); use config(); use time(); use db(); -use cache(); + use markup(); use log(); use project(); @@ -37,7 +38,7 @@ our @EXPORT_OK = qw( sub init { } -sub get_cached_or_render { +sub get_cached_or_render($$$) { # my $response=$_[0]; my $config = $_[1]; @@ -46,31 +47,13 @@ sub get_cached_or_render { my $params = $request->{params}->{checked}; my $debug = $config->{system}->{debug}; - my $cache = {}; - if ( $config->{cache}->{use_cache} == 1 ) { - events::configure_cache($config); - $cache = cache::load( $config, $params ); - if ( defined $cache->{content} ) { - $_[0] = $cache->{content}; - return; - } - } - my $results = events::get( $config, $request ); events::render( $_[0], $config, $request, $results ); - #write to cache - if ( $config->{cache}->{use_cache} == 1 ) { - - #todo:put out reference only - $cache->{content} = $_[0]; - cache::save($cache); - } - return $_[0]; } -sub get { +sub get($$) { my $config = shift; my $request = shift; @@ -92,7 +75,7 @@ sub get { return $results; } -sub modify_results { +sub modify_results ($$$$) { my $dbh = shift; my $config = shift; my $request = shift; @@ -242,14 +225,14 @@ sub modify_results { $result->{one_comment} = 1 if ( $result->{comment_count} == 1 ); $result->{no_comment} = 1 if ( $result->{comment_count} == 0 ); - #fix image url - #$params->{exclude_event_images}=0 unless defined $params->{exclude_event_images}; - #if ($params->{exclude_event_images}==1){ - # if ( (defined $config->{permissions}->{hide_event_images}) && ($config->{permissions}->{hide_event_images} eq '1') ){ - # $result->{image} = $result->{series_image}; - # $result->{image_label} = $result->{series_image_label}; - # } - #} +#fix image url +#$params->{exclude_event_images}=0 unless defined $params->{exclude_event_images}; +#if ($params->{exclude_event_images}==1){ +# if ( (defined $config->{permissions}->{hide_event_images}) && ($config->{permissions}->{hide_event_images} eq '1') ){ +# $result->{image} = $result->{series_image}; +# $result->{image_label} = $result->{series_image_label}; +# } +#} if ( defined $result->{image} ) { my $url = $config->{locations}->{local_media_url} || ''; @@ -504,7 +487,8 @@ sub calc_dates { if ( ( defined $params->{template} ) && ( $params->{template} =~ /(\.xml)/ ) ) { - $result->{start_datetime_utc} = time::datetime_to_utc_datetime( $result->{start_datetime}, $config->{date}->{time_zone} ); + $result->{start_datetime_utc} = + time::datetime_to_utc_datetime( $result->{start_datetime}, $config->{date}->{time_zone} ); } $result->{end_datetime} = $result->{end}; @@ -521,7 +505,8 @@ sub calc_dates { if ( ( defined $params->{template} ) && ( $params->{template} =~ /(\.xml)/ ) ) { - $result->{end_datetime_utc} = time::datetime_to_utc_datetime( $result->{end_datetime}, $config->{date}->{time_zone} ); + $result->{end_datetime_utc} = + time::datetime_to_utc_datetime( $result->{end_datetime}, $config->{date}->{time_zone} ); } if ( ( defined $previous_result ) @@ -550,15 +535,15 @@ sub calc_dates { if ( defined $result->{weekday} ) { my $language = $config->{date}->{language} || 'en'; - my $weekdayIndex = time::getWeekdayIndex($result->{weekday}) || 0; - - $result->{weekday_name} = time::getWeekdayNames($language)->[$weekdayIndex]; + my $weekdayIndex = time::getWeekdayIndex( $result->{weekday} ) || 0; + + $result->{weekday_name} = time::getWeekdayNames($language)->[$weekdayIndex]; $result->{weekday_short_name} = time::getWeekdayNamesShort($language)->[$weekdayIndex]; } return $result; } -sub add_recordings { +sub add_recordings($$$$) { my $dbh = shift; my $config = shift; my $request = shift; @@ -606,7 +591,7 @@ sub add_recordings { return $events; } -sub getDateQueryConditions { +sub getDateQueryConditions ($$$) { my $config = shift; my $params = shift; my $bind_values = shift; @@ -770,7 +755,7 @@ sub getDateQueryConditions { } # if recordings is set in params, recordings date and path will be included -sub get_query { +sub get_query($$$) { my $dbh = shift; my $config = shift; my $request = shift; @@ -1130,7 +1115,7 @@ sub get_query { return ( \$query, $bind_values ); } -sub render { +sub render($$$$;$) { # my $response = $_[0]; my $config = $_[1]; @@ -1220,7 +1205,8 @@ sub render { $template_parameters->{controllers} = $config->{controllers}; $template_parameters->{hide_event_images} = 1 - if ( defined $config->{permissions}->{hide_event_images} ) && ( $config->{permissions}->{hide_event_images} == 1 ); + if ( defined $config->{permissions}->{hide_event_images} ) + && ( $config->{permissions}->{hide_event_images} == 1 ); # use Data::Dumper;print STDERR Dumper($template_parameters)."\n"; template::process( $config, $_[0], $params->{template}, $template_parameters ); @@ -1228,7 +1214,7 @@ sub render { return $_[0]; } -sub get_running_event_id { +sub get_running_event_id($) { my $dbh = shift; my $query = qq{ @@ -1255,7 +1241,7 @@ sub get_running_event_id { } # add filters to query -sub setDefaultEventConditions { +sub setDefaultEventConditions ($$$$) { my $config = shift; my $conditions = $_[0]; my $bind_values = $_[1]; @@ -1293,7 +1279,7 @@ sub setDefaultEventConditions { } # for local use only or add support for exclude_projects and exclude_locations -sub getEventById { +sub getEventById ($$$$) { my $dbh = shift; my $config = shift; my $event_id = shift; @@ -1320,7 +1306,7 @@ sub getEventById { return $events; } -sub get_next_event_of_series { +sub get_next_event_of_series ($$$) { my $dbh = shift; my $config = shift; my $options = shift; @@ -1360,7 +1346,7 @@ sub get_next_event_of_series { return $events->[0]->{id}; } -sub get_previous_event_of_series { +sub get_previous_event_of_series($$$) { my $dbh = shift; my $config = shift; my $options = shift; @@ -1398,7 +1384,7 @@ sub get_previous_event_of_series { } # used by calendar -sub get_by_date_range { +sub get_by_date_range ($$$$$) { my $dbh = shift; my $config = shift; my $start_date = shift; @@ -1423,7 +1409,8 @@ sub get_by_date_range { $conditions = join( ' and ', @$conditions ); my $select = qq{distinct date(start) 'start_date'}; - $select = qq{distinct date(DATE_SUB(start, INTERVAL $day_starting_hour HOUR)) 'start_date'} if defined $day_starting_hour; + $select = qq{distinct date(DATE_SUB(start, INTERVAL $day_starting_hour HOUR)) 'start_date'} + if defined $day_starting_hour; my $query = qq{ select $select @@ -1438,7 +1425,7 @@ sub get_by_date_range { return $events; } -sub get_by_image { +sub get_by_image ($$$) { my $dbh = shift; my $config = shift; my $filename = shift; @@ -1462,7 +1449,7 @@ sub get_by_image { } # deleting an event is currently disabled -sub delete { +sub delete ($$$) { return; my $request = shift; my $config = shift; @@ -1487,51 +1474,7 @@ sub delete { } -#TODO: add location to cache map -sub configure_cache { - my $config = shift; - my $debug = $config->{system}->{debug}; - - my $date_pattern = cache::get_date_pattern(); - my $controllers = $config->{controllers}; - - cache::init(); - cache::add_map( '', 'index.html' ); - - my $name = ''; - my $extension = ''; - my $templates = $config->{templates}->{events}; - - for my $template (@$templates) { - if ( $template =~ /^(.+)\.([^\.]+)$/ ) { - $name = $1; - $extension = $2; - } - cache::add_map( 'template=' . $template, $controllers->{events} . '/' . $name . '.' . $extension ); - cache::add_map( 'template=' . $template . '&date=today', $controllers->{events} . '/' . $template . '_today.' . $extension ); - cache::add_map( 'template=' . $template . '&date=' . $date_pattern, - $controllers->{events} . '/' . $name . '_date_$1-$2-$3.' . $extension ); - cache::add_map( 'template=' . $template . '&time=now', $controllers->{events} . '/' . $template . '_now.html' ); - cache::add_map( 'template=' . $template . '&time=now&limit=(\d+)', - $controllers->{events} . '/' . $name . '_now_limit_$1.' . $extension ); - cache::add_map( - 'template=' . $template . '&from_date=' . $date_pattern . '&till_date=' . $date_pattern, - $controllers->{events} . '/' . $name . '_from_$1-$2-$3_till_$4_$5_$6.' . $extension - ); - cache::add_map( - 'template=' . $template . '&from_date=' . $date_pattern . '&till_date=' . $date_pattern . '&weekday=(\d)', - $controllers->{events} . '/' . $template . '_from_$1-$2-$3_till_$4_$5_$6_weekday_$7.' . $extension - ); - cache::add_map( - 'template=' . $template . '&from_date=' . $date_pattern . '&till_date=' . $date_pattern . '&limit=(\d)', - $controllers->{events} . '/' . $template . '_from_$1-$2-$3_till_$4_$5_$6_limit_$7.' . $extension - ); - cache::add_map( 'template=' . $template . '&weekday=(\d)', $controllers->{events} . '/' . $name . '_weekday_$1.' . $extension ); - cache::add_map( 'template=' . $template . '&event_id=(\d+)', $controllers->{event} . '/' . $name . '_page_$1.' . $extension ); - } -} - -sub get_duration { +sub get_duration ($$) { my $config = shift; my $event = shift; my $timezone = $config->{date}->{time_zone}; @@ -1548,7 +1491,7 @@ sub get_duration { return $duration / 60; } -sub check_params { +sub check_params ($$) { my $config = shift; my $params = shift; @@ -1679,7 +1622,8 @@ sub check_params { $exclude_projects = 1 if ( defined $params->{exclude_projects} ) && ( $params->{exclude_projects} eq '1' ); my $exclude_event_images = 0; - $exclude_event_images = 1 if ( defined $params->{exclude_event_images} ) && ( $params->{exclude_event_images} eq '1' ); + $exclude_event_images = 1 + if ( defined $params->{exclude_event_images} ) && ( $params->{exclude_event_images} eq '1' ); #show future events by default my $archive = 'future'; @@ -1826,7 +1770,7 @@ sub check_params { return $checked; } -sub get_keys { +sub get_keys($) { my $event = shift; my $program = $event->{program} || ''; diff --git a/lib/calcms/images.pm b/lib/calcms/images.pm index 18b9f2a..4c97ea5 100644 --- a/lib/calcms/images.pm +++ b/lib/calcms/images.pm @@ -1,7 +1,8 @@ package images; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use config(); use template(); @@ -12,74 +13,77 @@ our @EXPORT_OK = qw(get insert update insert_or_update delete delete_files); #column 'created_at' will be set at insert #column 'modified_at' will be set by default (do not update) -my $sql_columns = - [ 'filename', 'name', 'description', 'created_by', 'modified_by', 'modified_at', 'studio_id', 'project_id', 'public', 'licence' ]; +my $sql_columns = [ + 'filename', 'name', 'description', 'created_by', 'modified_by', 'modified_at', + 'studio_id', 'project_id', 'public', 'licence' +]; -sub get { - my $config = shift; - my $options = shift; +sub get($$) { + my $config = shift; + my $options = shift; - my @cond = (); - my $bind_values = []; - if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) { - push @cond, 'project_id = ?'; - push @$bind_values, $options->{project_id}; - } - if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) { - push @cond, 'studio_id = ?'; - push @$bind_values, $options->{studio_id}; - } - if ( ( defined $options->{filename} ) && ( $options->{filename} ne '' ) ) { - push @cond, 'filename = ?'; - push @$bind_values, $options->{filename}; - } - if ( ( defined $options->{from} ) && ( $options->{from} ne '' ) ) { - push @cond, 'date(created_at) >= ?'; - push @$bind_values, $options->{from}; - } - if ( ( defined $options->{till} ) && ( $options->{till} ne '' ) ) { - push @cond, 'date(created_at) <= ?'; - push @$bind_values, $options->{till}; - } - if ( ( defined $options->{created_by} ) && ( $options->{created_by} ne '' ) ) { - push @cond, 'created_by = ?'; - push @$bind_values, $options->{created_by}; - } - if ( ( defined $options->{modified_by} ) && ( $options->{modified_by} ne '' ) ) { - push @cond, 'modified_by = ?'; - push @$bind_values, $options->{modified_by}; - } - if ( ( defined $options->{licence} ) && ( $options->{licence} ne '' ) ) { - push @cond, 'licence = ?'; - push @$bind_values, $options->{licence}; - } - if ( ( defined $options->{public} ) && ( $options->{public} ne '' ) ) { - push @cond, 'public = ?'; - push @$bind_values, $options->{public}; - } + my @cond = (); + my $bind_values = []; + if ( ( defined $options->{project_id} ) && ( $options->{project_id} ne '' ) ) { + push @cond, 'project_id = ?'; + push @$bind_values, $options->{project_id}; + } + if ( ( defined $options->{studio_id} ) && ( $options->{studio_id} ne '' ) ) { + push @cond, 'studio_id = ?'; + push @$bind_values, $options->{studio_id}; + } + if ( ( defined $options->{filename} ) && ( $options->{filename} ne '' ) ) { + push @cond, 'filename = ?'; + push @$bind_values, $options->{filename}; + } + if ( ( defined $options->{from} ) && ( $options->{from} ne '' ) ) { + push @cond, 'date(created_at) >= ?'; + push @$bind_values, $options->{from}; + } + if ( ( defined $options->{till} ) && ( $options->{till} ne '' ) ) { + push @cond, 'date(created_at) <= ?'; + push @$bind_values, $options->{till}; + } + if ( ( defined $options->{created_by} ) && ( $options->{created_by} ne '' ) ) { + push @cond, 'created_by = ?'; + push @$bind_values, $options->{created_by}; + } + if ( ( defined $options->{modified_by} ) && ( $options->{modified_by} ne '' ) ) { + push @cond, 'modified_by = ?'; + push @$bind_values, $options->{modified_by}; + } + if ( ( defined $options->{licence} ) && ( $options->{licence} ne '' ) ) { + push @cond, 'licence = ?'; + push @$bind_values, $options->{licence}; + } + if ( ( defined $options->{public} ) && ( $options->{public} ne '' ) ) { + push @cond, 'public = ?'; + push @$bind_values, $options->{public}; + } - if ( ( defined $options->{search} ) && ( $options->{search} ne '' ) ) { - push @cond, '(filename like ?' . ' or name like ?' . ' or description like ?' . ' or created_by like ?' . ')'; - my $search = '%' . $options->{search} . '%'; - push @$bind_values, $search; - push @$bind_values, $search; - push @$bind_values, $search; - push @$bind_values, $search; + if ( ( defined $options->{search} ) && ( $options->{search} ne '' ) ) { + push @cond, + '(filename like ?' . ' or name like ?' . ' or description like ?' . ' or created_by like ?' . ')'; + my $search = '%' . $options->{search} . '%'; + push @$bind_values, $search; + push @$bind_values, $search; + push @$bind_values, $search; + push @$bind_values, $search; - # push @$bind_values,$search; - } + # push @$bind_values,$search; + } - my $where = ''; - if ( @cond > 0 ) { - $where = 'where ' . join( ' and ', @cond ); - } + my $where = ''; + if ( @cond > 0 ) { + $where = 'where ' . join( ' and ', @cond ); + } - my $limit = ''; - if ( ( defined $options->{limit} ) && ( $options->{limit} =~ /(\d+)/ ) ) { - $limit = ' limit ' . $1; - } + my $limit = ''; + if ( ( defined $options->{limit} ) && ( $options->{limit} =~ /(\d+)/ ) ) { + $limit = ' limit ' . $1; + } - my $query = qq{ + my $query = qq{ select * from calcms_images $where @@ -87,445 +91,453 @@ sub get { $limit }; - #print STDERR Dumper($query).Dumper($bind_values); + #print STDERR Dumper($query).Dumper($bind_values); - my $dbh = db::connect($config); - my $results = db::get( $dbh, $query, $bind_values ); + my $dbh = db::connect($config); + my $results = db::get( $dbh, $query, $bind_values ); - #print STDERR @$results."\n"; - return $results; + #print STDERR @$results."\n"; + return $results; } -sub insert_or_update { - my $dbh = shift; - my $image = shift; +sub insert_or_update($$) { + my $dbh = shift; + my $image = shift; - $image->{name} = 'new' if $image->{name} eq ''; - my $entry = get_by_filename( $dbh, $image->{filename} ); - if ( defined $entry ) { - update( $dbh, $image ); - } else { - insert( $dbh, $image ); - } + $image->{name} = 'new' if $image->{name} eq ''; + my $entry = get_by_filename( $dbh, $image->{filename} ); + if ( defined $entry ) { + update( $dbh, $image ); + } else { + insert( $dbh, $image ); + } } -sub insert { - my $dbh = shift; - my $image = shift; +sub insert ($$) { + my $dbh = shift; + my $image = shift; - my @sql_columns = @$sql_columns; + my @sql_columns = @$sql_columns; - #set created at timestamp - push @sql_columns, 'created_at'; - $image->{created_at} = time::time_to_datetime(); + #set created at timestamp + push @sql_columns, 'created_at'; + $image->{created_at} = time::time_to_datetime(); - unless ( defined $image->{created_by} ) { - print STDERR "missing created_by at image::insert\n"; - return undef; - } - unless ( defined $image->{studio_id} ) { - print STDERR "missing studio_id at image::insert\n"; - return undef; - } - unless ( defined $image->{project_id} ) { - print STDERR "missing project_id at image::insert\n"; - return undef; - } + unless ( defined $image->{created_by} ) { + print STDERR "missing created_by at image::insert\n"; + return undef; + } + unless ( defined $image->{studio_id} ) { + print STDERR "missing studio_id at image::insert\n"; + return undef; + } + unless ( defined $image->{project_id} ) { + print STDERR "missing project_id at image::insert\n"; + return undef; + } - for my $attr ('public') { - $image->{$attr} = 0 unless ( defined $image->{$attr} ) && ( $image->{$attr} eq '1' ); - } + for my $attr ('public') { + $image->{$attr} = 0 unless ( defined $image->{$attr} ) && ( $image->{$attr} eq '1' ); + } - my $query = q{ + my $query = q{ insert into calcms_images( } . join( ',', @sql_columns ) . qq{ ) values( } . join( ', ', ( map { '?' } @sql_columns ) ) . q{ ) }; - my @bind_values = map { $image->{$_} } @sql_columns; + my @bind_values = map { $image->{$_} } @sql_columns; - #print STDERR Dumper($query).Dumper(\@bind_values); - my $result = db::put( $dbh, $query, \@bind_values ); + #print STDERR Dumper($query).Dumper(\@bind_values); + my $result = db::put( $dbh, $query, \@bind_values ); - images::setSeriesLabels( $dbh, $image ); - images::setEventLabels( $dbh, $image ); + images::setSeriesLabels( $dbh, $image ); + images::setEventLabels( $dbh, $image ); - return $result; + return $result; } -sub update { - my $dbh = shift; - my $image = shift; +sub update($$) { + my $dbh = shift; + my $image = shift; - unless ( defined $image->{studio_id} ) { - print STDERR "missing studio_id at images::update\n"; - return undef; - } - unless ( defined $image->{project_id} ) { - print STDERR "missing project_id at image::update\n"; - return undef; - } - unless ( defined $image->{filename} ) { - print STDERR "missing filename at image::update\n"; - return undef; - } + unless ( defined $image->{studio_id} ) { + print STDERR "missing studio_id at images::update\n"; + return undef; + } + unless ( defined $image->{project_id} ) { + print STDERR "missing project_id at image::update\n"; + return undef; + } + unless ( defined $image->{filename} ) { + print STDERR "missing filename at image::update\n"; + return undef; + } - $image->{modified_at} = time::time_to_datetime(); + $image->{modified_at} = time::time_to_datetime(); - for my $attr ('public') { - $image->{$attr} = 0 unless ( defined $image->{$attr} ) && ( $image->{$attr} eq '1' ); - } + for my $attr ('public') { + $image->{$attr} = 0 unless ( defined $image->{$attr} ) && ( $image->{$attr} eq '1' ); + } - my @set = (); - my $bind_values = []; - for my $column (@$sql_columns) { - if ( defined $image->{$column} ) { - push @set, $column . ' = ?'; - push @$bind_values, $image->{$column}; - } - } + my @set = (); + my $bind_values = []; + for my $column (@$sql_columns) { + if ( defined $image->{$column} ) { + push @set, $column . ' = ?'; + push @$bind_values, $image->{$column}; + } + } - #conditions - my $conditions = ['filename=?']; - push @$bind_values, $image->{filename}; + #conditions + my $conditions = ['filename=?']; + push @$bind_values, $image->{filename}; - push @$conditions, 'project_id=?'; - push @$bind_values, $image->{project_id} || 0; + push @$conditions, 'project_id=?'; + push @$bind_values, $image->{project_id} || 0; - push @$conditions, 'studio_id=?'; - push @$bind_values, $image->{studio_id} || 0; + push @$conditions, 'studio_id=?'; + push @$bind_values, $image->{studio_id} || 0; - return if ( @set == 0 ); + return if ( @set == 0 ); - my $set = join( ",", @set ); - $conditions = join( ' and ', @$conditions ); - my $query = qq{ + my $set = join( ",", @set ); + $conditions = join( ' and ', @$conditions ); + my $query = qq{ update calcms_images set $set where $conditions }; - #print STDERR Dumper($query) . Dumper($bind_values); - my $result = db::put( $dbh, $query, $bind_values ); - images::setSeriesLabels( $dbh, $image ); - images::setEventLabels( $dbh, $image ); + #print STDERR Dumper($query) . Dumper($bind_values); + my $result = db::put( $dbh, $query, $bind_values ); - return $result; + images::setSeriesLabels( $dbh, $image ); + images::setEventLabels( $dbh, $image ); + + return $result; } -sub delete { - my $dbh = shift; - my $image = shift; +sub delete($$) { + my $dbh = shift; + my $image = shift; - unless ( defined $image->{project_id} ) { - print STDERR "missing project_id at images::delete\n"; - return undef; - } - unless ( defined $image->{studio_id} ) { - print STDERR "missing studio_id at images::delete\n"; - return undef; - } - unless ( defined $image->{filename} ) { - print STDERR "missing filename at images::delete\n"; - return undef; - } + unless ( defined $image->{project_id} ) { + print STDERR "missing project_id at images::delete\n"; + return undef; + } + unless ( defined $image->{studio_id} ) { + print STDERR "missing studio_id at images::delete\n"; + return undef; + } + unless ( defined $image->{filename} ) { + print STDERR "missing filename at images::delete\n"; + return undef; + } - my $project_id = $image->{project_id}; - my $studio_id = $image->{studio_id}; - my $filename = $image->{filename}; + my $project_id = $image->{project_id}; + my $studio_id = $image->{studio_id}; + my $filename = $image->{filename}; - my $conditions = ['filename=?']; - my $bind_values = [$filename]; + my $conditions = ['filename=?']; + my $bind_values = [$filename]; - push @$conditions, 'project_id=?'; - push @$bind_values, $studio_id; + push @$conditions, 'project_id=?'; + push @$bind_values, $studio_id; - push @$conditions, 'studio_id=?'; - push @$bind_values, $project_id; + push @$conditions, 'studio_id=?'; + push @$bind_values, $project_id; - $conditions = join( ' and ', @$conditions ); - my $query = qq{ + $conditions = join( ' and ', @$conditions ); + my $query = qq{ delete from calcms_images where $conditions }; - #print STDERR Dumper($query).Dumper($bind_values); - return db::put( $dbh, $query, $bind_values ); + #print STDERR Dumper($query).Dumper($bind_values); + return db::put( $dbh, $query, $bind_values ); } # deactivated -sub delete_files { - my $config = $_[0]; - my $local_media_dir = $_[1]; - my $filename = $_[2]; - my $action_result = $_[3]; - my $errors = $_[4]; +sub delete_files($$$$$) { + my $config = $_[0]; + my $local_media_dir = $_[1]; + my $filename = $_[2]; + my $action_result = $_[3]; + my $errors = $_[4]; - return undef; + return undef; - print log::error( $config, 'missing permissions on writing into local media dir' ) unless ( -w $local_media_dir ); + print log::error( $config, 'missing permissions on writing into local media dir' ) unless ( -w $local_media_dir ); - if ( $filename =~ /[^a-zA-Z0-9\.\_\-]/ ) { - log::error( $config, "invalid filename: '$filename'" ); - return; - } - if ( $filename =~ /\.\./ || $filename =~ /^\// || $filename =~ /\// ) { - log::error( $config, "invalid filename: '$filename'" ); - return; - } + if ( $filename =~ /[^a-zA-Z0-9\.\_\-]/ ) { + log::error( $config, "invalid filename: '$filename'" ); + return; + } + if ( $filename =~ /\.\./ || $filename =~ /^\// || $filename =~ /\// ) { + log::error( $config, "invalid filename: '$filename'" ); + return; + } - log::error( $config, 'missing permissions on writing into local_media_dir/images/' ) unless ( -w $local_media_dir . 'images/' ); - log::error( $config, 'missing permissions on writing into local_media_dir/thumbs/' ) unless ( -w $local_media_dir . 'thumbs/' ); - log::error( $config, 'missing permissions on writing into local_media_dir/icons/' ) unless ( -w $local_media_dir . 'icons/' ); + log::error( $config, 'missing permissions on writing into local_media_dir/images/' ) + unless ( -w $local_media_dir . 'images/' ); + log::error( $config, 'missing permissions on writing into local_media_dir/thumbs/' ) + unless ( -w $local_media_dir . 'thumbs/' ); + log::error( $config, 'missing permissions on writing into local_media_dir/icons/' ) + unless ( -w $local_media_dir . 'icons/' ); - my $path = $local_media_dir . '/upload/' . $filename; + my $path = $local_media_dir . '/upload/' . $filename; - #delete_file($path,"Upload $filename",$action_result,$errors); + #delete_file($path,"Upload $filename",$action_result,$errors); - $path = $local_media_dir . '/images/' . $filename; - delete_file( $path, "Image $filename", $action_result, $errors ); + $path = $local_media_dir . '/images/' . $filename; + delete_file( $path, "Image $filename", $action_result, $errors ); - $path = $local_media_dir . '/thumbs/' . $filename; - delete_file( $path, "Thumb $filename", $action_result, $errors ); + $path = $local_media_dir . '/thumbs/' . $filename; + delete_file( $path, "Thumb $filename", $action_result, $errors ); - $path = $local_media_dir . '/icons/' . $filename; - delete_file( $path, "Icon $filename", $action_result, $errors ); + $path = $local_media_dir . '/icons/' . $filename; + delete_file( $path, "Icon $filename", $action_result, $errors ); } # deactivated -sub delete_file { - my $path = $_[0]; - my $type = $_[1]; - my $action_result = $_[2]; - my $errors = $_[3]; +sub delete_file ($$$$) { + my $path = $_[0]; + my $type = $_[1]; + my $action_result = $_[2]; + my $errors = $_[3]; - return undef; + return undef; - unless ( -e $path ) { - $errors .= qq{Error: File does not exist!
}; - return; - } + unless ( -e $path ) { + $errors .= qq{Error: File does not exist!
}; + return; + } - unless ( -w $path ) { - $errors .= qq{Error: Cannot write $type
}; - return; - } + unless ( -w $path ) { + $errors .= qq{Error: Cannot write $type
}; + return; + } - unlink($path); - if ( $? == 0 ) { - $action_result .= qq{$type deleted
}; - } else { - $errors .= qq{Error on deleting $type
}; - } + unlink($path); + if ( $? == 0 ) { + $action_result .= qq{$type deleted
}; + } else { + $errors .= qq{Error on deleting $type
}; + } } sub getPath { - my $config = shift; - my $options = shift; + my $config = shift; + my $options = shift; - my $dir = $config->{locations}->{local_media_dir}; - return undef unless defined $dir; - return undef unless -e $dir; + my $dir = $config->{locations}->{local_media_dir}; + return undef unless defined $dir; + return undef unless -e $dir; - my $filename = $options->{filename}; - return undef unless defined $filename; - $filename =~ s/^.*\///g; + my $filename = $options->{filename}; + return undef unless defined $filename; + $filename =~ s/^.*\///g; - my $type = 'thumbs'; - $type = $options->{type} if ( defined $options->{type} ) && ( $options->{type} =~ /^(images|thumbs|icons)$/ ); + my $type = 'thumbs'; + $type = $options->{type} if ( defined $options->{type} ) && ( $options->{type} =~ /^(images|thumbs|icons)$/ ); - my $path = $dir . '/' . $type . '/' . $filename; - $path =~ s/\/+/\//g; - return $path; + my $path = $dir . '/' . $type . '/' . $filename; + $path =~ s/\/+/\//g; + return $path; } -sub getInternalPath { - my $config = shift; - my $options = shift; +sub getInternalPath ($$) { + my $config = shift; + my $options = shift; - my $dir = $config->{locations}->{local_media_dir}; - return undef unless defined $dir; - return undef unless -e $dir; + my $dir = $config->{locations}->{local_media_dir}; + return undef unless defined $dir; + return undef unless -e $dir; - my $filename = $options->{filename}; - return undef unless defined $filename; - $filename =~ s/^.*\///g; + my $filename = $options->{filename}; + return undef unless defined $filename; + $filename =~ s/^.*\///g; - my $type = 'thumbs'; - $type = $options->{type} if ( defined $options->{type} ) && ( $options->{type} =~ /^(images|thumbs|icons)$/ ); + my $type = 'thumbs'; + $type = $options->{type} if ( defined $options->{type} ) && ( $options->{type} =~ /^(images|thumbs|icons)$/ ); - my $path = $dir . '/internal/' . $type . '/' . $filename; - $path =~ s/\/+/\//g; - return $path; + my $path = $dir . '/internal/' . $type . '/' . $filename; + $path =~ s/\/+/\//g; + return $path; } -sub normalizeName { - my $name = shift; - return undef unless defined $name; - $name =~ s/.*\///g; - return $name; +sub normalizeName (;$) { + my $name = shift; + return undef unless defined $name; + $name =~ s/.*\///g; + return $name; } -sub readFile { - my $path = shift; - my $content = ''; +sub readFile($) { + my $path = shift; + my $content = ''; - print STDERR "read '$path'\n"; - return { error => "source '$path' does not exist" } unless -e $path; - return { error => "cannot read source '$path'" } unless -r $path; + print STDERR "read '$path'\n"; + return { error => "source '$path' does not exist" } unless -e $path; + return { error => "cannot read source '$path'" } unless -r $path; - open my $file, '< :raw', $path or return { error => 'could not open image file. ' . $! . " $path" }; - binmode $file; - $content = join( "", <$file> ); - close $file; - return { content => $content }; + open my $file, '< :raw', $path or return { error => 'could not open image file. ' . $! . " $path" }; + binmode $file; + $content = join( "", <$file> ); + close $file; + return { content => $content }; } -sub writeFile { - my $path = shift; - my $content = shift; +sub writeFile ($$) { + my $path = shift; + my $content = shift; - print STDERR "save '$path'\n"; - open my $fh, '> :raw', $path or return { error => 'could not save image. ' . $! . " $path" }; - binmode $fh; - print $fh $content; - close $fh; - return {}; + print STDERR "save '$path'\n"; + open my $fh, '> :raw', $path or return { error => 'could not save image. ' . $! . " $path" }; + binmode $fh; + print $fh $content; + close $fh; + return {}; } -sub deleteFile { - my $path = shift; - return { error => "source '$path' does not exist" } unless -e $path; +sub deleteFile($) { + my $path = shift; + return { error => "source '$path' does not exist" } unless -e $path; - #unlink $path; - return {}; + #unlink $path; + return {}; } -sub copyFile { - my $source = shift; - my $target = shift; - my $errors = shift; +sub copyFile ($$$) { + my $source = shift; + my $target = shift; + my $errors = shift; - my $read = images::readFile($source); - return $read if defined $read->{error}; + my $read = images::readFile($source); + return $read if defined $read->{error}; - my $write = images::writeFile( $target, $read->{content} ); - return $write; + my $write = images::writeFile( $target, $read->{content} ); + return $write; } -sub publish { - my $config = shift; - my $filename = shift; +sub publish($$) { + my $config = shift; + my $filename = shift; - print STDERR "publish\n"; - return undef unless defined $config; - return undef unless defined $filename; - my $errors = []; - for my $type ( 'images', 'thumbs', 'icons' ) { - my $source = getInternalPath( $config, { filename => $filename, type => $type } ); - my $target = getPath( $config, { filename => $filename, type => $type } ); - my $result = copyFile( $source, $target, $errors ); - if ( defined $result->{error} ) { - push @$errors, $result->{error}; - print STDERR "error on copy '$source' to '$target': $result->{error}\n"; - } - } - return $errors; + print STDERR "publish\n"; + return undef unless defined $config; + return undef unless defined $filename; + my $errors = []; + for my $type ( 'images', 'thumbs', 'icons' ) { + my $source = getInternalPath( $config, { filename => $filename, type => $type } ); + my $target = getPath( $config, { filename => $filename, type => $type } ); + my $result = copyFile( $source, $target, $errors ); + if ( defined $result->{error} ) { + push @$errors, $result->{error}; + print STDERR "error on copy '$source' to '$target': $result->{error}\n"; + } + } + return $errors; } -sub depublish { - my $config = shift; - my $filename = shift; +sub depublish ($$) { + my $config = shift; + my $filename = shift; - print STDERR "depublish\n"; - return undef unless defined $config; - return undef unless defined $filename; - my $errors = []; - for my $type ( 'images', 'thumbs', 'icons' ) { - my $path = getPath( $config, { filename => $filename, type => $type } ); - next unless defined $path; - print STDERR "remove '$path'\n"; - unlink $path; + print STDERR "depublish\n"; + return undef unless defined $config; + return undef unless defined $filename; + my $errors = []; + for my $type ( 'images', 'thumbs', 'icons' ) { + my $path = getPath( $config, { filename => $filename, type => $type } ); + next unless defined $path; + print STDERR "remove '$path'\n"; + unlink $path; - #push @$errors, $result->{error} if defined $result->{error}; - } - return $errors; + #push @$errors, $result->{error} if defined $result->{error}; + } + return $errors; } -sub checkLicence { - my $config = shift; - my $result = shift; +sub checkLicence ($$) { + my $config = shift; + my $result = shift; - print STDERR "depublish\n"; - return undef unless defined $config; - return undef unless defined $result; + print STDERR "depublish\n"; + return undef unless defined $config; + return undef unless defined $result; - return if $result->{licence} =~ /\S/; - if ( ( defined $result->{public} ) && ( $result->{public} eq '1' ) ) { - depublish( $config, $result->{filename} ); - $result->{public} = 0; - } + return if $result->{licence} =~ /\S/; + if ( ( defined $result->{public} ) && ( $result->{public} eq '1' ) ) { + depublish( $config, $result->{filename} ); + $result->{public} = 0; + } } -sub setEventLabels { - my $dbh = shift; - my $image = shift; +sub setEventLabels($$) { + my $dbh = shift; + my $image = shift; - unless ( defined $image->{project_id} ) { - print STDERR "missing project_id at images::setEventLabels\n"; - return undef; - } - unless ( defined $image->{studio_id} ) { - print STDERR "missing studio_id at images::setEventLabels\n"; - return undef; - } - unless ( defined $image->{filename} ) { - print STDERR "missing filename at images::setEventLabels\n"; - return undef; - } + unless ( defined $image->{project_id} ) { + print STDERR "missing project_id at images::setEventLabels\n"; + return undef; + } + unless ( defined $image->{studio_id} ) { + print STDERR "missing studio_id at images::setEventLabels\n"; + return undef; + } + unless ( defined $image->{filename} ) { + print STDERR "missing filename at images::setEventLabels\n"; + return undef; + } - my $query = qq{ + my $query = qq{ update calcms_events set image_label=? where image=? }; - my $bind_values = [ $image->{licence}, $image->{filename} ]; - #print STDERR Dumper($query) . Dumper($bind_values); + my $bind_values = [ $image->{licence}, $image->{filename} ]; - my $results = db::put( $dbh, $query, $bind_values ); - #print STDERR Dumper($results) . " changes\n"; - return $results; + #print STDERR Dumper($query) . Dumper($bind_values); + + my $results = db::put( $dbh, $query, $bind_values ); + + #print STDERR Dumper($results) . " changes\n"; + return $results; } -sub setSeriesLabels { - my $dbh = shift; - my $image = shift; +sub setSeriesLabels($$) { + my $dbh = shift; + my $image = shift; - unless ( defined $image->{project_id} ) { - print STDERR "missing project_id at images::setSeriesLabels\n"; - return undef; - } - unless ( defined $image->{studio_id} ) { - print STDERR "missing studio_id at images::setSeriesLabels\n"; - return undef; - } - unless ( defined $image->{filename} ) { - print STDERR "missing filename at images::setSeriesLabels\n"; - return undef; - } + unless ( defined $image->{project_id} ) { + print STDERR "missing project_id at images::setSeriesLabels\n"; + return undef; + } + unless ( defined $image->{studio_id} ) { + print STDERR "missing studio_id at images::setSeriesLabels\n"; + return undef; + } + unless ( defined $image->{filename} ) { + print STDERR "missing filename at images::setSeriesLabels\n"; + return undef; + } - my $query = qq{ + my $query = qq{ update calcms_events set series_image_label=? where series_image=? }; - my $bind_values = [ $image->{licence}, $image->{filename} ]; - #print STDERR Dumper($query) . Dumper($bind_values); + my $bind_values = [ $image->{licence}, $image->{filename} ]; - my $results = db::put( $dbh, $query, $bind_values ); - #print STDERR Dumper($results) . " changes\n"; - return $results; + #print STDERR Dumper($query) . Dumper($bind_values); + + my $results = db::put( $dbh, $query, $bind_values ); + + #print STDERR Dumper($results) . " changes\n"; + return $results; } #do not delete last line! diff --git a/lib/calcms/localization.pm b/lib/calcms/localization.pm index e2d1dff..6481b12 100644 --- a/lib/calcms/localization.pm +++ b/lib/calcms/localization.pm @@ -1,14 +1,15 @@ package localization; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use uac(); use user_settings(); use base 'Exporter'; -our @EXPORT_OK = qw(get getJavascript); +our @EXPORT_OK = qw(get getJavascript); sub debug; @@ -17,100 +18,100 @@ sub debug; # language : get for selected language # user : get from user settings # loc : add to existing localization, optional -sub get { - my $config = shift; - my $options = shift; +sub get($$) { + my $config = shift; + my $options = shift; - #print STDERR Dumper($options); + #print STDERR Dumper($options); - #get pot file - unless ( defined $options->{file} ) { - print STDERR "missing po file\n"; - return $options->{loc} || {}; - } + #get pot file + unless ( defined $options->{file} ) { + print STDERR "missing po file\n"; + return $options->{loc} || {}; + } - my $language = undef; + my $language = undef; - #get language from options - $language = $options->{language} if ( defined $options->{language} ); + #get language from options + $language = $options->{language} if ( defined $options->{language} ); - #get language from user - if ( ( !( defined $language ) ) && ( defined $options->{user} ) ) { - my $user_settings = user_settings::get( $config, { user => $options->{user} } ); - $language = $user_settings->{language}; - } - $language = 'en' unless defined $language; - $language = 'en' unless $language eq 'de'; + #get language from user + if ( ( !( defined $language ) ) && ( defined $options->{user} ) ) { + my $user_settings = user_settings::get( $config, { user => $options->{user} } ); + $language = $user_settings->{language}; + } + $language = 'en' unless defined $language; + $language = 'en' unless $language eq 'de'; - my $loc = {}; - $loc = $options->{loc} if defined $options->{loc}; + my $loc = {}; + $loc = $options->{loc} if defined $options->{loc}; - my $files = $options->{file}; - $files =~ s/[^a-zA-Z\,\_\-]//g; + my $files = $options->{file}; + $files =~ s/[^a-zA-Z\,\_\-]//g; - #get all comma separated po files - for my $file ( split /\,/, $files ) { + #get all comma separated po files + for my $file ( split /\,/, $files ) { - #read default language - #my $po_file=$config->{locations}->{admin_pot_dir}.'/en/'.$file.'.po'; - #$loc=read_po_file($po_file, $loc); + #read default language + #my $po_file=$config->{locations}->{admin_pot_dir}.'/en/'.$file.'.po'; + #$loc=read_po_file($po_file, $loc); - #read selected language - #if($language ne 'en'){ - my $po_file = $config->{locations}->{admin_pot_dir} . '/' . $language . '/' . $file . '.po'; - $loc = read_po_file( $po_file, $loc ); + #read selected language + #if($language ne 'en'){ + my $po_file = $config->{locations}->{admin_pot_dir} . '/' . $language . '/' . $file . '.po'; + $loc = read_po_file( $po_file, $loc ); - #} - } - return $loc; + #} + } + return $loc; } -sub read_po_file { - my $po_file = shift; - my $loc = shift; +sub read_po_file($$) { + my $po_file = shift; + my $loc = shift; - unless ( -e $po_file ) { - print STDERR "po file $po_file does not exist\n"; - return $loc; - } - unless ( -r $po_file ) { - print STDERR "cannot read po file $po_file\n"; - return $loc; - } + unless ( -e $po_file ) { + print STDERR "po file $po_file does not exist\n"; + return $loc; + } + unless ( -r $po_file ) { + print STDERR "cannot read po file $po_file\n"; + return $loc; + } - my $key = ''; - open my $file, '<:encoding(UTF-8)', $po_file; - return $loc unless defined $file; - while (<$file>) { - my $line = $_; + my $key = ''; + open my $file, '<:encoding(UTF-8)', $po_file; + return $loc unless defined $file; + while (<$file>) { + my $line = $_; - #print STDERR $line; - if ( $line =~ /^msgid\s*\"(.*)\"\s*$/ ) { - $key = $1; - $key =~ s/\'//g; - $key =~ s/\"//g; - } - if ( $line =~ /^msgstr\s*\"(.*)\"\s*$/ ) { - my $val = $1; - $val =~ s/\'//g; - $val =~ s/\"//g; - $loc->{$key} = $val; - } - } - close $file; - return $loc; + #print STDERR $line; + if ( $line =~ /^msgid\s*\"(.*)\"\s*$/ ) { + $key = $1; + $key =~ s/\'//g; + $key =~ s/\"//g; + } + if ( $line =~ /^msgstr\s*\"(.*)\"\s*$/ ) { + my $val = $1; + $val =~ s/\'//g; + $val =~ s/\"//g; + $loc->{$key} = $val; + } + } + close $file; + return $loc; } -sub getJavascript { - my $loc = shift; +sub getJavascript ($){ + my $loc = shift; - my $out = '\n"; - return $out; + my $out = '\n"; + return $out; } 1; diff --git a/lib/calcms/log.pm b/lib/calcms/log.pm index fa3cf81..84d35ed 100644 --- a/lib/calcms/log.pm +++ b/lib/calcms/log.pm @@ -1,7 +1,8 @@ package log; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use base 'Exporter'; our @EXPORT_OK = qw(error load_file save_file append_file); @@ -9,7 +10,7 @@ our @EXPORT_OK = qw(error load_file save_file append_file); use config(); #TODO: check if config is given -sub error { +sub error($$) { my $config = $_[0]; my $message = "Error: $_[1]\n"; @@ -22,8 +23,8 @@ sub error { #do not call template::check to avoid deep recursion! if ( $config->{system}->{debug} ) { - template::process($config, - 'print', + template::process( + $config, 'print', 'templates/default.html', { static_files_url => $config->{locations}->{static_files_url}, @@ -35,20 +36,20 @@ sub error { die(); } -sub load_file { +sub load_file($) { my $filename = shift; my $content = ''; if ( -e $filename ) { my $FILE = undef; - open ($FILE, "<:utf8", $filename) || warn "cant read file '$filename'"; + open( $FILE, "<:utf8", $filename ) || warn "cant read file '$filename'"; $content = join "", (<$FILE>); close $FILE; return $content; } } -sub save_file { +sub save_file($$) { my $filename = shift; my $content = shift; @@ -69,7 +70,7 @@ sub save_file { } -sub append_file { +sub append_file($$) { my $filename = shift; my $content = shift; @@ -86,4 +87,4 @@ sub append_file { } #do not delete last line! -1; \ No newline at end of file +1; diff --git a/lib/calcms/mail.pm b/lib/calcms/mail.pm index b5c72f4..8fb4309 100644 --- a/lib/calcms/mail.pm +++ b/lib/calcms/mail.pm @@ -1,23 +1,25 @@ package mail; -use warnings; + use strict; +use warnings; +no warnings 'redefine'; use MIME::Lite(); -sub send { - my $mail = shift; +sub send($) { + my $mail = shift; - my $msg = MIME::Lite->new( - 'From' => $mail->{'From'}, - 'To' => $mail->{'To'}, - 'Cc' => $mail->{'Cc'}, - 'Reply-To' => $mail->{'Reply-To'}, - 'Subject' => $mail->{'Subject'}, - 'Data' => $mail->{'Data'}, - ); + my $msg = MIME::Lite->new( + 'From' => $mail->{'From'}, + 'To' => $mail->{'To'}, + 'Cc' => $mail->{'Cc'}, + 'Reply-To' => $mail->{'Reply-To'}, + 'Subject' => $mail->{'Subject'}, + 'Data' => $mail->{'Data'}, + ); - $msg->print( \*STDERR ); - $msg->send; + $msg->print( \*STDERR ); + $msg->send; } # do not delete next line diff --git a/lib/calcms/markup.pm b/lib/calcms/markup.pm index e912d9e..1d98c15 100644 --- a/lib/calcms/markup.pm +++ b/lib/calcms/markup.pm @@ -1,7 +1,9 @@ package markup; -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; + use Data::Dumper; use Text::WikiCreole(); use HTML::Parse(); @@ -15,493 +17,493 @@ use base 'Exporter'; our @EXPORT_OK = qw(fix_line_ends html_to_creole creole_to_html creole_to_plain plain_to_ical ical_to_plain ical_to_xml html_to_plain fix_utf8 uri_encode compress base26); -sub fix_line_ends { - my $s = shift; - $s =~ s/\r?\n|\r/\n/g; - return $s; +sub fix_line_ends ($) { + my $s = shift; + $s =~ s/\r?\n|\r/\n/g; + return $s; } # convert 1..26 to a..z, 27 to aa, inspired by ConvertAA -sub base26 { - my $num = shift; - return '' if $num <= 0; +sub base26($) { + my $num = shift; + return '' if $num <= 0; - my $s = ""; - while ($num) { - $s = chr( --$num % 26 + ord "a" ) . $s; - $num = int $num / 26; - } + my $s = ""; + while ($num) { + $s = chr( --$num % 26 + ord "a" ) . $s; + $num = int $num / 26; + } - return $s; + return $s; } -sub html_to_creole { - my $s = shift; +sub html_to_creole($) { + my $s = shift; - #remove elements - # $s=~s/[\r\f\n]+/\n/gi; - # $s=~s/<\/p.*?>//gi; - # $s=~s/<\/br.*?>//gi; - $s =~ s/\<\!\-\-[\s\S]*?\-\-\>//gi; - $s =~ s/.*?<\/script.*?>//gi; + #remove elements + # $s=~s/[\r\f\n]+/\n/gi; + # $s=~s/<\/p.*?>//gi; + # $s=~s/<\/br.*?>//gi; + $s =~ s/\<\!\-\-[\s\S]*?\-\-\>//gi; + $s =~ s/.*?<\/script.*?>//gi; - # $s=~s/<\/?span.*?>//gi; - # $s=~s/<\/?font.*?>//gi; - # $s=~s/<\/?meta.*?>//gi; - # $s=~s/<\/?title.*?>//gi; - # $s=~s/<\/?style.*?>//gi; - # $s=~s/<\/?col.*?>//gi; - # $s=~s/<\/?thead.*?>//gi; - # $s=~s/<\/?tbody.*?>//gi; - $s =~ s/<\/?form.*?>//gi; - $s =~ s/<\/?select.*?>//gi; - $s =~ s/<\/?option.*?//gi; - $s =~ s/<\/?input.*?>//gi; + # $s=~s/<\/?span.*?>//gi; + # $s=~s/<\/?font.*?>//gi; + # $s=~s/<\/?meta.*?>//gi; + # $s=~s/<\/?title.*?>//gi; + # $s=~s/<\/?style.*?>//gi; + # $s=~s/<\/?col.*?>//gi; + # $s=~s/<\/?thead.*?>//gi; + # $s=~s/<\/?tbody.*?>//gi; + $s =~ s/<\/?form.*?>//gi; + $s =~ s/<\/?select.*?>//gi; + $s =~ s/<\/?option.*?//gi; + $s =~ s/<\/?input.*?>//gi; - # $s=~s/<\/?button.*?>//gi; - # $s=~s/<\/?textarea.*?>//gi; - $s =~ s/<\/?script.*?>//gi; + # $s=~s/<\/?button.*?>//gi; + # $s=~s/<\/?textarea.*?>//gi; + $s =~ s/<\/?script.*?>//gi; - #table elements - # $s=~s/\s*<\/?td.*?>//gi; - # $s=~s/\s*<\/?th.*?>//gi; + #table elements + # $s=~s/\s*<\/?td.*?>//gi; + # $s=~s/\s*<\/?th.*?>//gi; - #remove line breaks - $s =~ s/[\r\n]+/ /gi; + #remove line breaks + $s =~ s/[\r\n]+/ /gi; - #formats - $s =~ s//{{$1\|}}/gi; - $s =~ s//{{$2\|$1}}/gi; - $s =~ s/]*?title="(.*?)".*?>/{{$1\|$2}}/gi; - $s =~ s/]*?src="(.*?)".*?>/{{$2\|$1}}/gi; - $s =~ s/<\/?img.*?>//gi; + #formats + $s =~ s//{{$1\|}}/gi; + $s =~ s//{{$2\|$1}}/gi; + $s =~ s/]*?title="(.*?)".*?>/{{$1\|$2}}/gi; + $s =~ s/]*?src="(.*?)".*?>/{{$2\|$1}}/gi; + $s =~ s/<\/?img.*?>//gi; - #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 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/(.*?)<\/i>/\/\/$1\/\//gi; - $s =~ s/<\/?i.*?>//gi; - $s =~ s/(.*?)<\/b>/\*\*$1\*\*/gi; + $s =~ s/(.*?)<\/i>/\/\/$1\/\//gi; + $s =~ s/<\/?i.*?>//gi; + $s =~ s/(.*?)<\/b>/\*\*$1\*\*/gi; - # $s=~s/<\/?b.*?>//gi; + # $s=~s/<\/?b.*?>//gi; - $s =~ s/(.*?)<\/strong>/\*\*$1\*\*/gi; - $s =~ s/(.*?)<\/em>/\/\/$1\/\//gi; - $s =~ s/((\W+|\w+)*?)<\/blockquote>/{{{$1}}}/gi; + $s =~ s/(.*?)<\/strong>/\*\*$1\*\*/gi; + $s =~ s/(.*?)<\/em>/\/\/$1\/\//gi; + $s =~ s/((\W+|\w+)*?)<\/blockquote>/{{{$1}}}/gi; - # $s=~s/((\W+|\w+)*?)<\/a>/\[\[$1\|$2\]\]$3/gi; - $s =~ s/(.*?)(\s*)<\/a>/\[\[$1\|$2\]\]$3/gi; - $s =~ s///gi; + # $s=~s/((\W+|\w+)*?)<\/a>/\[\[$1\|$2\]\]$3/gi; + $s =~ s/(.*?)(\s*)<\/a>/\[\[$1\|$2\]\]$3/gi; + $s =~ s///gi; - #replace line breaks from links - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + #replace line breaks from links + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - # print STDERR Dumper($s) if ($s=~//== /gi; - $s =~ s/\s*/=== /gi; - $s =~ s/\s*/==== /gi; - $s =~ s/\s*/===== /gi; + #line elements, increase head line level to avoid breaking single = chars + $s =~ s/\s*/== /gi; + $s =~ s/\s*/=== /gi; + $s =~ s/\s*/==== /gi; + $s =~ s/\s*/===== /gi; - # $s=~s/\s*<\/h\d.*?>/\n/gi; + # $s=~s/\s*<\/h\d.*?>/\n/gi; - # $s=~s//\\\\
/gi; - # $s=~s/\s*//gi; - # $s=~s/\s*<\/div>/\n/gi; + # $s=~s//\\\\
/gi; + # $s=~s/\s*//gi; + # $s=~s/\s*<\/div>/\n/gi; - # $s=~s//\n/gi; - # $s=~s/<\/table>/\n/gi; - # $s=~s/\s*//gi; - # $s=~s/\s*<\/tr>//gi; + # $s=~s//\n/gi; + # $s=~s/<\/table>/\n/gi; + # $s=~s/\s*//gi; + # $s=~s/\s*<\/tr>//gi; - # $s=~s/\s*/\n/gi; - # $s=~s/\s*<\/ol>/\n/gi; - # $s=~s/\s*/\n/gi; - # $s=~s/\s*<\/ul>/\n/gi; - # $s=~s/\s*/\n\* /gi; - # $s=~s/\s*<\/li>//gi; + # $s=~s/\s*/\n/gi; + # $s=~s/\s*<\/ol>/\n/gi; + # $s=~s/\s*/\n/gi; + # $s=~s/\s*<\/ul>/\n/gi; + # $s=~s/\s*/\n\* /gi; + # $s=~s/\s*<\/li>//gi; - # $s=~s/\s*\s*/\n\n/gi; - # $s=~s/\s*\s*/\n /gi; + # $s=~s/\s*\s*/\n\n/gi; + # $s=~s/\s*\s*/\n /gi; - my $tree = HTML::Parse::parse_html( '' . $s . '' ); - my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 ); - $s = $formatter->format($tree); + my $tree = HTML::Parse::parse_html( '' . $s . '' ); + my $formatter = HTML::FormatText->new( leftmargin => 0, rightmargin => 2000 ); + $s = $formatter->format($tree); - #use Data::Dumper; print "asd:"; - $s =~ s/\".Dumper($s);print ""; + $s =~ s/\//gi; + # $s=~s/<\/a>//gi; - return $s; + return $s; } -sub creole_to_html { - my $s = $_[0] || ''; +sub creole_to_html ($) { + my $s = $_[0] || ''; - #$s=~s/\n\#\n/\n/g; - #fix_line_ends($s); - $s =~ s/(.*?)(\s*)<\/a>/\[\[$1\|$2\]\]$3/gi; - $s =~ s///gi; + #$s=~s/\n\#\n/\n/g; + #fix_line_ends($s); + $s =~ s/(.*?)(\s*)<\/a>/\[\[$1\|$2\]\]$3/gi; + $s =~ s///gi; - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; - $s =~ s/^\s+//g; - $s =~ s/\s+$//g; + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + $s =~ s/(\[\[[^\]\n]*?)\n([^\]]*?\]\])/$1$2/g; + $s =~ s/^\s+//g; + $s =~ s/\s+$//g; - $s = Text::WikiCreole::creole_parse($s) || ''; + $s = Text::WikiCreole::creole_parse($s) || ''; - # $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; + # $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/\$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/\\s*

    |<$elem>|g; - $s =~ 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*||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/gi; + 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 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/\n//gi; ## $_[0]=~s/\&amp;/\&/gi; ## $_[0]=~s/\&amp;/+/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/&(?!(#[0-9]+|#x[0-9a-fA-F]+|\w+);)/&/g; + $text =~ s/&($entities);/$entity{$1}/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 { - - + +
    } . $params->{loc}->{label_name} . qq{
    } . $params->{loc}->{label_title} . qq{
    } + . $params->{loc}->{label_name} . qq{
    } + . $params->{loc}->{label_title} . qq{
    - +
    @@ -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 { - + }; @@ -1678,7 +1716,8 @@ sub getCalendar { my $previous = ''; my $next = ''; if ( $range eq 'month' ) { - $previous = time::get_datetime( $from_date, $config->{date}->{time_zone} )->subtract( months => 1 )->set_day(1)->date(); + $previous = + time::get_datetime( $from_date, $config->{date}->{time_zone} )->subtract( months => 1 )->set_day(1)->date(); $next = time::get_datetime( $from_date, $config->{date}->{time_zone} )->add( months => 1 )->set_day(1)->date(); } else { $previous = time::get_datetime( $from_date, $config->{date}->{time_zone} )->subtract( days => $range )->date(); @@ -1741,7 +1780,8 @@ sub getTillDate { if ( $params->{range} eq 'month' ) { #get last day of month - return time::get_datetime( $date, $config->{date}->{time_zone} )->set_day(1)->add( months => 1 )->subtract( days => 1 )->date(); + return time::get_datetime( $date, $config->{date}->{time_zone} )->set_day(1)->add( months => 1 ) + ->subtract( days => 1 )->date(); } #add range to date @@ -1810,7 +1850,7 @@ sub check_params { my $checked = {}; my $template = ''; - $checked->{template} = template::check($config, $params->{template}, 'series' ); + $checked->{template} = template::check( $config, $params->{template}, 'series' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { @@ -1821,7 +1861,10 @@ sub check_params { #numeric values $checked->{part} = 0; $checked->{list} = 0; - for my $param ( 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'part', 'list', 'day_start' ) + for my $param ( + 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', + 'event_id', 'part', 'list', 'day_start' + ) { if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) { $checked->{$param} = $params->{$param}; diff --git a/website/agenda/planung/comment.cgi b/website/agenda/planung/comment.cgi index 56e5459..0ec88a9 100755 --- a/website/agenda/planung/comment.cgi +++ b/website/agenda/planung/comment.cgi @@ -1,7 +1,8 @@ #! /usr/bin/perl -w -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use URI::Escape(); use Encode(); @@ -71,7 +72,7 @@ if ( ( params::isJson() ) || ( defined $params->{action} ) ) { } unless (params::isJson); } -return unless defined uac::check( $config, $params, $user_presets ); +return unless uac::check( $config, $params, $user_presets ) == 1; if ( defined $params->{action} ) { if ( $params->{action} eq 'get_json' ) { @@ -155,7 +156,8 @@ sub showComments { $template_parameters->{projects} = project::get_with_dates($config); $template_parameters->{controllers} = $config->{controllers}; $template_parameters->{allow} = $permissions; - $template_parameters->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'comment' } ); + $template_parameters->{loc} = + localization::get( $config, { user => $params->{presets}->{user}, file => 'comment' } ); #fill and output template template::process( $config, 'print', $params->{template}, $template_parameters ); @@ -252,7 +254,8 @@ sub check_params { #template my $template = ''; if ( defined $checked->{action} ) { - $template = template::check( $config, $params->{template}, 'edit_comment' ) if $checked->{action} eq 'showComment'; + $template = template::check( $config, $params->{template}, 'edit_comment' ) + if $checked->{action} eq 'showComment'; } else { $template = template::check( $config, $params->{template}, 'comments' ); } diff --git a/website/agenda/planung/create_events.cgi b/website/agenda/planung/create_events.cgi index 9f898ad..6150ce9 100755 --- a/website/agenda/planung/create_events.cgi +++ b/website/agenda/planung/create_events.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 params(); diff --git a/website/agenda/planung/css/comment_manager.css b/website/agenda/planung/css/comment_manager.css deleted file mode 100644 index c630bf3..0000000 --- a/website/agenda/planung/css/comment_manager.css +++ /dev/null @@ -1,125 +0,0 @@ - td,th,input { - line-height:100%; - ffont-size:10px; - } - td,th{ - display:table-cell; - font-weight:normal; - } - - td.level0, td.level1, td.level2, td.level3, td.level4, td.level5{ - opacity:0.8; - border:0; - } - - td.host{ - color:gray; - } - - td.level0{ - padding-left:0px; - } - td.level1{ - padding-left:20px; - } - td.level2{ - padding-left:40px; - } - td.level3{ - padding-left:60px; - } - td.level4{ - padding-left:80px; - } - td.level5{ - padding-left:100px; - } - - img.level0{ - margin-left:0px; - } - img.level1{ - margin-left:20px; - } - img.level2{ - margin-left:40px; - } - img.level3{ - margin-left:60px; - } - img.level4{ - margin-left:80px; - } - img.level5{ - margin-left:100px; - } - - tr{ - vertical-align:middle; - } - - tr.show{ - color:#030; - text-decoration:none; - } - - #content tr.show td{ - padding-top:0px; - padding-bottom:0px; - } - - tr.blocked{ - color:#a33; - text-decoration:break-through; - } - - td.content.unread{ - font-weight:bold; - } - - td.content.received{ - font-weight:normal; - } - - - table.event_comments{ - width:800px; - } - - table.event_comments td{ - padding:3px; - background-color:#ccc; - } - - .event th{ - text-align:left; - opacity:0.8; - } - .event td{ - padding:3px; - border-right:1px solid #fff; - } - - .event button{ - text-align:right; - opacity:0.8; - } - - .event_start{ - width:200px; - text-align:center; - } - - .event_title{ - width:400px; - } - - .event_show_comments{ - height:2em; - } - - .event_excerpt{ - opacity:0.8; - } - - diff --git a/website/agenda/planung/event.cgi b/website/agenda/planung/event.cgi index e753519..69a2e28 100755 --- a/website/agenda/planung/event.cgi +++ b/website/agenda/planung/event.cgi @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use strict; use warnings; @@ -75,7 +75,7 @@ unless ( params::isJson() ) { $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); } -return unless defined uac::check( $config, $params, $user_presets ); +return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -296,7 +296,8 @@ sub show_event { $params->{event_edited} = 1 if ( ( $params->{action} eq 'save' ) && ( !( defined $params->{error} ) ) ); $params->{event_edited} = 1 if ( $params->{action} eq 'delete' ); $params->{event_edited} = 1 if ( ( $params->{action} eq 'create_event' ) && ( !( defined $params->{error} ) ) ); - $params->{event_edited} = 1 if ( ( $params->{action} eq 'create_event_from_schedule' ) && ( !( defined $params->{error} ) ) ); + $params->{event_edited} = 1 + if ( ( $params->{action} eq 'create_event_from_schedule' ) && ( !( defined $params->{error} ) ) ); $params->{user} = $params->{presets}->{user}; # remove all edit permissions if event is over for more than 2 weeks @@ -782,7 +783,10 @@ sub check_params { $checked->{debug} = $debug; #numeric values - for my $param ( 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'source_event_id', 'episode' ) + for my $param ( + 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', + 'event_id', 'source_event_id', 'episode' + ) { if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) { $checked->{$param} = $params->{$param}; @@ -820,8 +824,9 @@ sub check_params { #strings for my $param ( - 'series_name', 'title', 'excerpt', 'content', 'topic', 'program', 'category', 'image', - 'series_image', 'user_content', 'user_title', 'user_excerpt', 'podcast_url', 'archive_url', 'setImage' + 'series_name', 'title', 'excerpt', 'content', 'topic', 'program', + 'category', 'image', 'series_image', 'user_content', 'user_title', 'user_excerpt', + 'podcast_url', 'archive_url', 'setImage' ) { if ( defined $params->{$param} ) { @@ -844,7 +849,8 @@ sub check_params { $checked->{action} = ''; if ( defined $params->{action} ) { if ( $params->{action} =~ - /^(save|delete|download|show_new_event|show_new_event_from_schedule|create_event|create_event_from_schedule|get_json)$/ ) +/^(save|delete|download|show_new_event|show_new_event_from_schedule|create_event|create_event_from_schedule|get_json)$/ + ) { $checked->{action} = $params->{action}; } diff --git a/website/agenda/planung/event_history.cgi b/website/agenda/planung/event_history.cgi index 2f38016..8906514 100755 --- a/website/agenda/planung/event_history.cgi +++ b/website/agenda/planung/event_history.cgi @@ -1,12 +1,15 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use URI::Escape(); use Data::Dumper; use MIME::Base64(); -use Text::Diff::FormattedHTML(); + +#use Text::Diff::FormattedHTML(); +use Text::Diff::Unified::XS; use params(); use config(); @@ -23,7 +26,7 @@ use events(); use series_events(); use localization(); -binmode STDOUT, ":utf8"; +#binmode STDOUT, ":utf8"; my $r = shift; ( my $cgi, my $params, my $error ) = params::get($r); @@ -61,7 +64,10 @@ return unless uac::check( $config, $params, $user_presets ) == 1; print q{ - + + + + }; $config->{access}->{write} = 0; @@ -167,14 +173,59 @@ sub compare { return; } + print ''; + print ''; + + #log::save_file('/tmp/diff-a.txt', $t1); + #log::save_file('/tmp/diff-b.txt', $t2); + #my $diff=`/usr/bin/diff /tmp/diff-a.txt /tmp/diff-b.txt`; + + my $diff = diff( \$t1, \$t2 ); + + #$diff=~s/\&/\&/g; + #$diff=~s/\/\>/g; + #$diff=~s/\"/\"/g; + #$diff=~s/\'/\'/g; + $diff =~ s/\'/\\\'/g; + + #$diff=~s/\n/\'+\'/g; + $diff = join( qq{\\n' + '}, split( /\r?\n/, $diff ) ); + + #
    $diff
    + print qq! +
    + + + + !; + + #print ''; + #print ""; #print '
    ';
         #my $diff=diff_strings( { vertical => 1 }, $t1, $t2);
    -    my $diff = diff_strings( {}, $t1, $t2 );
    +    #my $diff = Text::Diff::FormattedHTML::diff_strings( {}, $t1, $t2 );
     
         #print Text::Diff::diff(\$t1, \$t2, { STYLE => "Table" });
         #print Text::Diff::diff($v1, $v2, { STYLE => "Table" });
    -    print $diff;
    +    #print $diff;
     
         #print '
    '; } @@ -208,7 +259,9 @@ sub check_params { $checked->{debug} = $debug; #numeric values - for my $param ( 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'v1', 'v2' ) { + for + my $param ( 'id', 'project_id', 'studio_id', 'default_studio_id', 'user_id', 'series_id', 'event_id', 'v1', 'v2' ) + { if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\d+$/ ) ) { $checked->{$param} = $params->{$param}; } diff --git a/website/agenda/planung/help.cgi b/website/agenda/planung/help.cgi index 19cb4fb..cd819d7 100755 --- a/website/agenda/planung/help.cgi +++ b/website/agenda/planung/help.cgi @@ -1,7 +1,8 @@ # !/usr/bin/perl -w -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; use Data::Dumper; use URI::Escape(); diff --git a/website/agenda/planung/image.cgi b/website/agenda/planung/image.cgi index 97b9132..aa51a88 100755 --- a/website/agenda/planung/image.cgi +++ b/website/agenda/planung/image.cgi @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#!/usr/bin/perl use strict; use warnings; @@ -62,13 +62,13 @@ $params = $request->{params}->{checked}; my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -if ($params->{search}){ -template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); -}else{ -template::process( $config, 'print', template::check( $config, 'ajax_header.html' ), $headerParams ); +if ( $params->{search} ) { + template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); +} else { + template::process( $config, 'print', template::check( $config, 'ajax_header.html' ), $headerParams ); } -return unless defined uac::check( $config, $params, $user_presets ); +return unless uac::check( $config, $params, $user_presets ) == 1; my $local_media_dir = $config->{locations}->{local_media_dir}; my $local_media_url = $config->{locations}->{local_media_url}; @@ -220,10 +220,10 @@ sub show_image { 'projects' => project::get_with_dates($config), 'project_id' => $params->{project_id}, 'studio_id' => $params->{studio_id}, - 'series_id' => $params->{series_id}, - 'event_id' => $params->{event_id}, - 'pid' => $params->{pid}, - 'target' => $params->{target}, + 'series_id' => $params->{series_id}, + 'event_id' => $params->{event_id}, + 'pid' => $params->{pid}, + 'target' => $params->{target}, 'filename' => $params->{filename} }; @@ -340,6 +340,7 @@ sub delete_image { my $result = images::delete( $dbh, $image ); return; + #my $action_result = ''; #my $errors = ''; #$result = images::delete_files( $config, $local_media_dir, $params->{delete_image}, $action_result, $errors ); @@ -393,9 +394,13 @@ sub modify_results { #reduce for my $permission ( 'update_image', 'delete_image' ) { - if ( ( defined $permissions->{ $permission . '_others' } ) && ( $permissions->{ $permission . '_others' } eq '1' ) ) { + if ( ( defined $permissions->{ $permission . '_others' } ) + && ( $permissions->{ $permission . '_others' } eq '1' ) ) + { $result->{$permission} = 1; - } elsif ( ( defined $permissions->{ $permission . '_own' } ) && ( $permissions->{ $permission . '_own' } eq '1' ) ) { + } elsif ( ( defined $permissions->{ $permission . '_own' } ) + && ( $permissions->{ $permission . '_own' } eq '1' ) ) + { next if ( $user eq '' ); $result->{$permission} = 1 if ( $user eq $result->{created_by} ); } diff --git a/website/agenda/planung/imageUpload.cgi b/website/agenda/planung/imageUpload.cgi index 2fa6a9e..61d51d7 100755 --- a/website/agenda/planung/imageUpload.cgi +++ b/website/agenda/planung/imageUpload.cgi @@ -1,7 +1,9 @@ -#! /usr/bin/perl +#!/usr/bin/perl -use warnings "all"; use strict; +use warnings; +no warnings 'redefine'; + use Data::Dumper; use Apache2::Request; @@ -43,14 +45,15 @@ my $error = ''; #get image from multiform before anything else if ( defined $r ) { + #$cgi = new CGI(); - + #Apache2::Request my $apr = Apache2::Request->new( $r, POST_MAX => $upload_limit, TEMP_DIR => $tmp_dir ); $params = { studio_id => $apr->param('studio_id'), - project_id => $apr->param('project_id'), + project_id => $apr->param('project_id'), }; #copy params to hash @@ -108,7 +111,7 @@ my $request = { $request = uac::prepare_request( $request, $user_presets ); $params = $request->{params}->{checked}; -return unless defined uac::check( $config, $params, $user_presets ); +return unless uac::check( $config, $params, $user_presets ) == 1; my $permissions = $request->{permissions}; @@ -122,7 +125,10 @@ if ( $permissions->{create_image} ne '1' ) { my $file_info = undef; if ( $error ne '' ) { if ( $error =~ /limit/ ) { - $params->{error} .= "Image size is limited to " . int( $upload_limit / 1000000 ) . " MB!" . "Please make it smaller and try again!"; + $params->{error} .= + "Image size is limited to " + . int( $upload_limit / 1000000 ) . " MB!" + . "Please make it smaller and try again!"; } else { $params->{error} .= "Error:'$error'"; } @@ -132,7 +138,7 @@ if ( $error ne '' ) { $params = update_database( $config, $params, $file_info, $user ) if $params->{error} eq ''; } -print STDERR "upload error: $params->{error}\n" if $params->{error} ; +print STDERR "upload error: $params->{error}\n" if $params->{error}; my $out = ''; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'image' } ); template::process( $config, 'print', $params->{template}, $params ); @@ -145,7 +151,6 @@ $params->{filename} ||= ''; $params->{image_id} ||= ''; $params->{name} ||= ''; - sub upload_file { my $config = shift; my $cgi = shift; @@ -215,11 +220,14 @@ sub update_database { $config->{access}->{write} = 1; my $dbh = db::connect($config); - my $entries = images::get( $config, { - filename => $image->{filename}, - project_id => $image->{project_id} , - studio_id => $image->{studio_id} - } ); + my $entries = images::get( + $config, + { + filename => $image->{filename}, + project_id => $image->{project_id}, + studio_id => $image->{studio_id} + } + ); if ( ( defined $entries ) && ( scalar(@$entries) > 0 ) ) { print STDERR "update image\n"; images::update( $dbh, $image ); @@ -300,10 +308,11 @@ sub process_image { my $md5_filename = shift; my $content = shift; - my $upload_path = images::getInternalPath( $config, { type => 'upload', filename => $md5_filename . '.' . $extension } ); - my $thumb_path = images::getInternalPath( $config, { type => 'thumbs', filename => $md5_filename . '.jpg' } ); - my $icon_path = images::getInternalPath( $config, { type => 'icons', filename => $md5_filename . '.jpg' } ); - my $image_path = images::getInternalPath( $config, { type => 'images', filename => $md5_filename . '.jpg' } ); + my $upload_path = + images::getInternalPath( $config, { type => 'upload', filename => $md5_filename . '.' . $extension } ); + my $thumb_path = images::getInternalPath( $config, { type => 'thumbs', filename => $md5_filename . '.jpg' } ); + my $icon_path = images::getInternalPath( $config, { type => 'icons', filename => $md5_filename . '.jpg' } ); + my $image_path = images::getInternalPath( $config, { type => 'images', filename => $md5_filename . '.jpg' } ); #copy file to upload space my $result = images::writeFile( $upload_path, $content ); @@ -397,4 +406,3 @@ sub check_params { return $checked; } - diff --git a/website/agenda/planung/js/jquery-ui.js b/website/agenda/planung/js/jquery-ui.js deleted file mode 100644 index 487c214..0000000 --- a/website/agenda/planung/js/jquery-ui.js +++ /dev/null @@ -1,16617 +0,0 @@ -/*! jQuery UI - v1.11.4 - 2016-01-24 -* http://jqueryui.com -* Includes: core.js, widget.js, mouse.js, position.js, draggable.js, droppable.js, resizable.js, selectable.js, sortable.js, accordion.js, autocomplete.js, button.js, datepicker.js, dialog.js, menu.js, progressbar.js, selectmenu.js, slider.js, spinner.js, tabs.js, tooltip.js, effect.js, effect-blind.js, effect-bounce.js, effect-clip.js, effect-drop.js, effect-explode.js, effect-fade.js, effect-fold.js, effect-highlight.js, effect-puff.js, effect-pulsate.js, effect-scale.js, effect-shake.js, effect-size.js, effect-slide.js, effect-transfer.js -* Copyright jQuery Foundation and other contributors; Licensed MIT */ - -(function( factory ) { - if ( typeof define === "function" && define.amd ) { - - // AMD. Register as an anonymous module. - define([ "jquery" ], factory ); - } else { - - // Browser globals - factory( jQuery ); - } -}(function( $ ) { -/*! - * jQuery UI Core 1.11.4 - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/category/ui-core/ - */ - - -// $.ui might exist from components with no dependencies, e.g., $.ui.position -$.ui = $.ui || {}; - -$.extend( $.ui, { - version: "1.11.4", - - keyCode: { - BACKSPACE: 8, - COMMA: 188, - DELETE: 46, - DOWN: 40, - END: 35, - ENTER: 13, - ESCAPE: 27, - HOME: 36, - LEFT: 37, - PAGE_DOWN: 34, - PAGE_UP: 33, - PERIOD: 190, - RIGHT: 39, - SPACE: 32, - TAB: 9, - UP: 38 - } -}); - -// plugins -$.fn.extend({ - scrollParent: function( includeHidden ) { - var position = this.css( "position" ), - excludeStaticParent = position === "absolute", - overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/, - scrollParent = this.parents().filter( function() { - var parent = $( this ); - if ( excludeStaticParent && parent.css( "position" ) === "static" ) { - return false; - } - return overflowRegex.test( parent.css( "overflow" ) + parent.css( "overflow-y" ) + parent.css( "overflow-x" ) ); - }).eq( 0 ); - - return position === "fixed" || !scrollParent.length ? $( this[ 0 ].ownerDocument || document ) : scrollParent; - }, - - uniqueId: (function() { - var uuid = 0; - - return function() { - return this.each(function() { - if ( !this.id ) { - this.id = "ui-id-" + ( ++uuid ); - } - }); - }; - })(), - - removeUniqueId: function() { - return this.each(function() { - if ( /^ui-id-\d+$/.test( this.id ) ) { - $( this ).removeAttr( "id" ); - } - }); - } -}); - -// selectors -function focusable( element, isTabIndexNotNaN ) { - var map, mapName, img, - nodeName = element.nodeName.toLowerCase(); - if ( "area" === nodeName ) { - map = element.parentNode; - mapName = map.name; - if ( !element.href || !mapName || map.nodeName.toLowerCase() !== "map" ) { - return false; - } - img = $( "img[usemap='#" + mapName + "']" )[ 0 ]; - return !!img && visible( img ); - } - return ( /^(input|select|textarea|button|object)$/.test( nodeName ) ? - !element.disabled : - "a" === nodeName ? - element.href || isTabIndexNotNaN : - isTabIndexNotNaN) && - // the element and all of its ancestors must be visible - visible( element ); -} - -function visible( element ) { - return $.expr.filters.visible( element ) && - !$( element ).parents().addBack().filter(function() { - return $.css( this, "visibility" ) === "hidden"; - }).length; -} - -$.extend( $.expr[ ":" ], { - data: $.expr.createPseudo ? - $.expr.createPseudo(function( dataName ) { - return function( elem ) { - return !!$.data( elem, dataName ); - }; - }) : - // support: jQuery <1.8 - function( elem, i, match ) { - return !!$.data( elem, match[ 3 ] ); - }, - - focusable: function( element ) { - return focusable( element, !isNaN( $.attr( element, "tabindex" ) ) ); - }, - - tabbable: function( element ) { - var tabIndex = $.attr( element, "tabindex" ), - isTabIndexNaN = isNaN( tabIndex ); - return ( isTabIndexNaN || tabIndex >= 0 ) && focusable( element, !isTabIndexNaN ); - } -}); - -// support: jQuery <1.8 -if ( !$( "" ).outerWidth( 1 ).jquery ) { - $.each( [ "Width", "Height" ], function( i, name ) { - var side = name === "Width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ], - type = name.toLowerCase(), - orig = { - innerWidth: $.fn.innerWidth, - innerHeight: $.fn.innerHeight, - outerWidth: $.fn.outerWidth, - outerHeight: $.fn.outerHeight - }; - - function reduce( elem, size, border, margin ) { - $.each( side, function() { - size -= parseFloat( $.css( elem, "padding" + this ) ) || 0; - if ( border ) { - size -= parseFloat( $.css( elem, "border" + this + "Width" ) ) || 0; - } - if ( margin ) { - size -= parseFloat( $.css( elem, "margin" + this ) ) || 0; - } - }); - return size; - } - - $.fn[ "inner" + name ] = function( size ) { - if ( size === undefined ) { - return orig[ "inner" + name ].call( this ); - } - - return this.each(function() { - $( this ).css( type, reduce( this, size ) + "px" ); - }); - }; - - $.fn[ "outer" + name] = function( size, margin ) { - if ( typeof size !== "number" ) { - return orig[ "outer" + name ].call( this, size ); - } - - return this.each(function() { - $( this).css( type, reduce( this, size, true, margin ) + "px" ); - }); - }; - }); -} - -// support: jQuery <1.8 -if ( !$.fn.addBack ) { - $.fn.addBack = function( selector ) { - return this.add( selector == null ? - this.prevObject : this.prevObject.filter( selector ) - ); - }; -} - -// support: jQuery 1.6.1, 1.6.2 (http://bugs.jquery.com/ticket/9413) -if ( $( "" ).data( "a-b", "a" ).removeData( "a-b" ).data( "a-b" ) ) { - $.fn.removeData = (function( removeData ) { - return function( key ) { - if ( arguments.length ) { - return removeData.call( this, $.camelCase( key ) ); - } else { - return removeData.call( this ); - } - }; - })( $.fn.removeData ); -} - -// deprecated -$.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ); - -$.fn.extend({ - focus: (function( orig ) { - return function( delay, fn ) { - return typeof delay === "number" ? - this.each(function() { - var elem = this; - setTimeout(function() { - $( elem ).focus(); - if ( fn ) { - fn.call( elem ); - } - }, delay ); - }) : - orig.apply( this, arguments ); - }; - })( $.fn.focus ), - - disableSelection: (function() { - var eventType = "onselectstart" in document.createElement( "div" ) ? - "selectstart" : - "mousedown"; - - return function() { - return this.bind( eventType + ".ui-disableSelection", function( event ) { - event.preventDefault(); - }); - }; - })(), - - enableSelection: function() { - return this.unbind( ".ui-disableSelection" ); - }, - - zIndex: function( zIndex ) { - if ( zIndex !== undefined ) { - return this.css( "zIndex", zIndex ); - } - - if ( this.length ) { - var elem = $( this[ 0 ] ), position, value; - while ( elem.length && elem[ 0 ] !== document ) { - // Ignore z-index if position is set to a value where z-index is ignored by the browser - // This makes behavior of this function consistent across browsers - // WebKit always returns auto if the element is positioned - position = elem.css( "position" ); - if ( position === "absolute" || position === "relative" || position === "fixed" ) { - // IE returns 0 when zIndex is not specified - // other browsers return a string - // we ignore the case of nested elements with an explicit value of 0 - //
    - value = parseInt( elem.css( "zIndex" ), 10 ); - if ( !isNaN( value ) && value !== 0 ) { - return value; - } - } - elem = elem.parent(); - } - } - - return 0; - } -}); - -// $.ui.plugin is deprecated. Use $.widget() extensions instead. -$.ui.plugin = { - add: function( module, option, set ) { - var i, - proto = $.ui[ module ].prototype; - for ( i in set ) { - proto.plugins[ i ] = proto.plugins[ i ] || []; - proto.plugins[ i ].push( [ option, set[ i ] ] ); - } - }, - call: function( instance, name, args, allowDisconnected ) { - var i, - set = instance.plugins[ name ]; - - if ( !set ) { - return; - } - - if ( !allowDisconnected && ( !instance.element[ 0 ].parentNode || instance.element[ 0 ].parentNode.nodeType === 11 ) ) { - return; - } - - for ( i = 0; i < set.length; i++ ) { - if ( instance.options[ set[ i ][ 0 ] ] ) { - set[ i ][ 1 ].apply( instance.element, args ); - } - } - } -}; - - -/*! - * jQuery UI Widget 1.11.4 - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/jQuery.widget/ - */ - - -var widget_uuid = 0, - widget_slice = Array.prototype.slice; - -$.cleanData = (function( orig ) { - return function( elems ) { - var events, elem, i; - for ( i = 0; (elem = elems[i]) != null; i++ ) { - try { - - // Only trigger remove when necessary to save time - events = $._data( elem, "events" ); - if ( events && events.remove ) { - $( elem ).triggerHandler( "remove" ); - } - - // http://bugs.jquery.com/ticket/8235 - } catch ( e ) {} - } - orig( elems ); - }; -})( $.cleanData ); - -$.widget = function( name, base, prototype ) { - var fullName, existingConstructor, constructor, basePrototype, - // proxiedPrototype allows the provided prototype to remain unmodified - // so that it can be used as a mixin for multiple widgets (#8876) - proxiedPrototype = {}, - namespace = name.split( "." )[ 0 ]; - - name = name.split( "." )[ 1 ]; - fullName = namespace + "-" + name; - - if ( !prototype ) { - prototype = base; - base = $.Widget; - } - - // create selector for plugin - $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) { - return !!$.data( elem, fullName ); - }; - - $[ namespace ] = $[ namespace ] || {}; - existingConstructor = $[ namespace ][ name ]; - constructor = $[ namespace ][ name ] = function( options, element ) { - // allow instantiation without "new" keyword - if ( !this._createWidget ) { - return new constructor( options, element ); - } - - // allow instantiation without initializing for simple inheritance - // must use "new" keyword (the code above always passes args) - if ( arguments.length ) { - this._createWidget( options, element ); - } - }; - // extend with the existing constructor to carry over any static properties - $.extend( constructor, existingConstructor, { - version: prototype.version, - // copy the object used to create the prototype in case we need to - // redefine the widget later - _proto: $.extend( {}, prototype ), - // track widgets that inherit from this widget in case this widget is - // redefined after a widget inherits from it - _childConstructors: [] - }); - - basePrototype = new base(); - // we need to make the options hash a property directly on the new instance - // otherwise we'll modify the options hash on the prototype that we're - // inheriting from - basePrototype.options = $.widget.extend( {}, basePrototype.options ); - $.each( prototype, function( prop, value ) { - if ( !$.isFunction( value ) ) { - proxiedPrototype[ prop ] = value; - return; - } - proxiedPrototype[ prop ] = (function() { - var _super = function() { - return base.prototype[ prop ].apply( this, arguments ); - }, - _superApply = function( args ) { - return base.prototype[ prop ].apply( this, args ); - }; - return function() { - var __super = this._super, - __superApply = this._superApply, - returnValue; - - this._super = _super; - this._superApply = _superApply; - - returnValue = value.apply( this, arguments ); - - this._super = __super; - this._superApply = __superApply; - - return returnValue; - }; - })(); - }); - constructor.prototype = $.widget.extend( basePrototype, { - // TODO: remove support for widgetEventPrefix - // always use the name + a colon as the prefix, e.g., draggable:start - // don't prefix for widgets that aren't DOM-based - widgetEventPrefix: existingConstructor ? (basePrototype.widgetEventPrefix || name) : name - }, proxiedPrototype, { - constructor: constructor, - namespace: namespace, - widgetName: name, - widgetFullName: fullName - }); - - // If this widget is being redefined then we need to find all widgets that - // are inheriting from it and redefine all of them so that they inherit from - // the new version of this widget. We're essentially trying to replace one - // level in the prototype chain. - if ( existingConstructor ) { - $.each( existingConstructor._childConstructors, function( i, child ) { - var childPrototype = child.prototype; - - // redefine the child widget using the same prototype that was - // originally used, but inherit from the new version of the base - $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto ); - }); - // remove the list of existing child constructors from the old constructor - // so the old child constructors can be garbage collected - delete existingConstructor._childConstructors; - } else { - base._childConstructors.push( constructor ); - } - - $.widget.bridge( name, constructor ); - - return constructor; -}; - -$.widget.extend = function( target ) { - var input = widget_slice.call( arguments, 1 ), - inputIndex = 0, - inputLength = input.length, - key, - value; - for ( ; inputIndex < inputLength; inputIndex++ ) { - for ( key in input[ inputIndex ] ) { - value = input[ inputIndex ][ key ]; - if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { - // Clone objects - if ( $.isPlainObject( value ) ) { - target[ key ] = $.isPlainObject( target[ key ] ) ? - $.widget.extend( {}, target[ key ], value ) : - // Don't extend strings, arrays, etc. with objects - $.widget.extend( {}, value ); - // Copy everything else by reference - } else { - target[ key ] = value; - } - } - } - } - return target; -}; - -$.widget.bridge = function( name, object ) { - var fullName = object.prototype.widgetFullName || name; - $.fn[ name ] = function( options ) { - var isMethodCall = typeof options === "string", - args = widget_slice.call( arguments, 1 ), - returnValue = this; - - if ( isMethodCall ) { - this.each(function() { - var methodValue, - instance = $.data( this, fullName ); - if ( options === "instance" ) { - returnValue = instance; - return false; - } - if ( !instance ) { - return $.error( "cannot call methods on " + name + " prior to initialization; " + - "attempted to call method '" + options + "'" ); - } - if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) { - return $.error( "no such method '" + options + "' for " + name + " widget instance" ); - } - methodValue = instance[ options ].apply( instance, args ); - if ( methodValue !== instance && methodValue !== undefined ) { - returnValue = methodValue && methodValue.jquery ? - returnValue.pushStack( methodValue.get() ) : - methodValue; - return false; - } - }); - } else { - - // Allow multiple hashes to be passed on init - if ( args.length ) { - options = $.widget.extend.apply( null, [ options ].concat(args) ); - } - - this.each(function() { - var instance = $.data( this, fullName ); - if ( instance ) { - instance.option( options || {} ); - if ( instance._init ) { - instance._init(); - } - } else { - $.data( this, fullName, new object( options, this ) ); - } - }); - } - - return returnValue; - }; -}; - -$.Widget = function( /* options, element */ ) {}; -$.Widget._childConstructors = []; - -$.Widget.prototype = { - widgetName: "widget", - widgetEventPrefix: "", - defaultElement: "
    ", - options: { - disabled: false, - - // callbacks - create: null - }, - _createWidget: function( options, element ) { - element = $( element || this.defaultElement || this )[ 0 ]; - this.element = $( element ); - this.uuid = widget_uuid++; - this.eventNamespace = "." + this.widgetName + this.uuid; - - this.bindings = $(); - this.hoverable = $(); - this.focusable = $(); - - if ( element !== this ) { - $.data( element, this.widgetFullName, this ); - this._on( true, this.element, { - remove: function( event ) { - if ( event.target === element ) { - this.destroy(); - } - } - }); - this.document = $( element.style ? - // element within the document - element.ownerDocument : - // element is window or document - element.document || element ); - this.window = $( this.document[0].defaultView || this.document[0].parentWindow ); - } - - this.options = $.widget.extend( {}, - this.options, - this._getCreateOptions(), - options ); - - this._create(); - this._trigger( "create", null, this._getCreateEventData() ); - this._init(); - }, - _getCreateOptions: $.noop, - _getCreateEventData: $.noop, - _create: $.noop, - _init: $.noop, - - destroy: function() { - this._destroy(); - // we can probably remove the unbind calls in 2.0 - // all event bindings should go through this._on() - this.element - .unbind( this.eventNamespace ) - .removeData( this.widgetFullName ) - // support: jquery <1.6.3 - // http://bugs.jquery.com/ticket/9413 - .removeData( $.camelCase( this.widgetFullName ) ); - this.widget() - .unbind( this.eventNamespace ) - .removeAttr( "aria-disabled" ) - .removeClass( - this.widgetFullName + "-disabled " + - "ui-state-disabled" ); - - // clean up events and states - this.bindings.unbind( this.eventNamespace ); - this.hoverable.removeClass( "ui-state-hover" ); - this.focusable.removeClass( "ui-state-focus" ); - }, - _destroy: $.noop, - - widget: function() { - return this.element; - }, - - option: function( key, value ) { - var options = key, - parts, - curOption, - i; - - if ( arguments.length === 0 ) { - // don't return a reference to the internal hash - return $.widget.extend( {}, this.options ); - } - - if ( typeof key === "string" ) { - // handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } } - options = {}; - parts = key.split( "." ); - key = parts.shift(); - if ( parts.length ) { - curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] ); - for ( i = 0; i < parts.length - 1; i++ ) { - curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {}; - curOption = curOption[ parts[ i ] ]; - } - key = parts.pop(); - if ( arguments.length === 1 ) { - return curOption[ key ] === undefined ? null : curOption[ key ]; - } - curOption[ key ] = value; - } else { - if ( arguments.length === 1 ) { - return this.options[ key ] === undefined ? null : this.options[ key ]; - } - options[ key ] = value; - } - } - - this._setOptions( options ); - - return this; - }, - _setOptions: function( options ) { - var key; - - for ( key in options ) { - this._setOption( key, options[ key ] ); - } - - return this; - }, - _setOption: function( key, value ) { - this.options[ key ] = value; - - if ( key === "disabled" ) { - this.widget() - .toggleClass( this.widgetFullName + "-disabled", !!value ); - - // If the widget is becoming disabled, then nothing is interactive - if ( value ) { - this.hoverable.removeClass( "ui-state-hover" ); - this.focusable.removeClass( "ui-state-focus" ); - } - } - - return this; - }, - - enable: function() { - return this._setOptions({ disabled: false }); - }, - disable: function() { - return this._setOptions({ disabled: true }); - }, - - _on: function( suppressDisabledCheck, element, handlers ) { - var delegateElement, - instance = this; - - // no suppressDisabledCheck flag, shuffle arguments - if ( typeof suppressDisabledCheck !== "boolean" ) { - handlers = element; - element = suppressDisabledCheck; - suppressDisabledCheck = false; - } - - // no element argument, shuffle and use this.element - if ( !handlers ) { - handlers = element; - element = this.element; - delegateElement = this.widget(); - } else { - element = delegateElement = $( element ); - this.bindings = this.bindings.add( element ); - } - - $.each( handlers, function( event, handler ) { - function handlerProxy() { - // allow widgets to customize the disabled handling - // - disabled as an array instead of boolean - // - disabled class as method for disabling individual parts - if ( !suppressDisabledCheck && - ( instance.options.disabled === true || - $( this ).hasClass( "ui-state-disabled" ) ) ) { - return; - } - return ( typeof handler === "string" ? instance[ handler ] : handler ) - .apply( instance, arguments ); - } - - // copy the guid so direct unbinding works - if ( typeof handler !== "string" ) { - handlerProxy.guid = handler.guid = - handler.guid || handlerProxy.guid || $.guid++; - } - - var match = event.match( /^([\w:-]*)\s*(.*)$/ ), - eventName = match[1] + instance.eventNamespace, - selector = match[2]; - if ( selector ) { - delegateElement.delegate( selector, eventName, handlerProxy ); - } else { - element.bind( eventName, handlerProxy ); - } - }); - }, - - _off: function( element, eventName ) { - eventName = (eventName || "").split( " " ).join( this.eventNamespace + " " ) + - this.eventNamespace; - element.unbind( eventName ).undelegate( eventName ); - - // Clear the stack to avoid memory leaks (#10056) - this.bindings = $( this.bindings.not( element ).get() ); - this.focusable = $( this.focusable.not( element ).get() ); - this.hoverable = $( this.hoverable.not( element ).get() ); - }, - - _delay: function( handler, delay ) { - function handlerProxy() { - return ( typeof handler === "string" ? instance[ handler ] : handler ) - .apply( instance, arguments ); - } - var instance = this; - return setTimeout( handlerProxy, delay || 0 ); - }, - - _hoverable: function( element ) { - this.hoverable = this.hoverable.add( element ); - this._on( element, { - mouseenter: function( event ) { - $( event.currentTarget ).addClass( "ui-state-hover" ); - }, - mouseleave: function( event ) { - $( event.currentTarget ).removeClass( "ui-state-hover" ); - } - }); - }, - - _focusable: function( element ) { - this.focusable = this.focusable.add( element ); - this._on( element, { - focusin: function( event ) { - $( event.currentTarget ).addClass( "ui-state-focus" ); - }, - focusout: function( event ) { - $( event.currentTarget ).removeClass( "ui-state-focus" ); - } - }); - }, - - _trigger: function( type, event, data ) { - var prop, orig, - callback = this.options[ type ]; - - data = data || {}; - event = $.Event( event ); - event.type = ( type === this.widgetEventPrefix ? - type : - this.widgetEventPrefix + type ).toLowerCase(); - // the original event may come from any element - // so we need to reset the target on the new event - event.target = this.element[ 0 ]; - - // copy original event properties over to the new event - orig = event.originalEvent; - if ( orig ) { - for ( prop in orig ) { - if ( !( prop in event ) ) { - event[ prop ] = orig[ prop ]; - } - } - } - - this.element.trigger( event, data ); - return !( $.isFunction( callback ) && - callback.apply( this.element[0], [ event ].concat( data ) ) === false || - event.isDefaultPrevented() ); - } -}; - -$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { - $.Widget.prototype[ "_" + method ] = function( element, options, callback ) { - if ( typeof options === "string" ) { - options = { effect: options }; - } - var hasOptions, - effectName = !options ? - method : - options === true || typeof options === "number" ? - defaultEffect : - options.effect || defaultEffect; - options = options || {}; - if ( typeof options === "number" ) { - options = { duration: options }; - } - hasOptions = !$.isEmptyObject( options ); - options.complete = callback; - if ( options.delay ) { - element.delay( options.delay ); - } - if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) { - element[ method ]( options ); - } else if ( effectName !== method && element[ effectName ] ) { - element[ effectName ]( options.duration, options.easing, callback ); - } else { - element.queue(function( next ) { - $( this )[ method ](); - if ( callback ) { - callback.call( element[ 0 ] ); - } - next(); - }); - } - }; -}); - -var widget = $.widget; - - -/*! - * jQuery UI Mouse 1.11.4 - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/mouse/ - */ - - -var mouseHandled = false; -$( document ).mouseup( function() { - mouseHandled = false; -}); - -var mouse = $.widget("ui.mouse", { - version: "1.11.4", - options: { - cancel: "input,textarea,button,select,option", - distance: 1, - delay: 0 - }, - _mouseInit: function() { - var that = this; - - this.element - .bind("mousedown." + this.widgetName, function(event) { - return that._mouseDown(event); - }) - .bind("click." + this.widgetName, function(event) { - if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) { - $.removeData(event.target, that.widgetName + ".preventClickEvent"); - event.stopImmediatePropagation(); - return false; - } - }); - - this.started = false; - }, - - // TODO: make sure destroying one instance of mouse doesn't mess with - // other instances of mouse - _mouseDestroy: function() { - this.element.unbind("." + this.widgetName); - if ( this._mouseMoveDelegate ) { - this.document - .unbind("mousemove." + this.widgetName, this._mouseMoveDelegate) - .unbind("mouseup." + this.widgetName, this._mouseUpDelegate); - } - }, - - _mouseDown: function(event) { - // don't let more than one widget handle mouseStart - if ( mouseHandled ) { - return; - } - - this._mouseMoved = false; - - // we may have missed mouseup (out of window) - (this._mouseStarted && this._mouseUp(event)); - - this._mouseDownEvent = event; - - var that = this, - btnIsLeft = (event.which === 1), - // event.target.nodeName works around a bug in IE 8 with - // disabled inputs (#7620) - elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false); - if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) { - return true; - } - - this.mouseDelayMet = !this.options.delay; - if (!this.mouseDelayMet) { - this._mouseDelayTimer = setTimeout(function() { - that.mouseDelayMet = true; - }, this.options.delay); - } - - if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { - this._mouseStarted = (this._mouseStart(event) !== false); - if (!this._mouseStarted) { - event.preventDefault(); - return true; - } - } - - // Click event may never have fired (Gecko & Opera) - if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) { - $.removeData(event.target, this.widgetName + ".preventClickEvent"); - } - - // these delegates are required to keep context - this._mouseMoveDelegate = function(event) { - return that._mouseMove(event); - }; - this._mouseUpDelegate = function(event) { - return that._mouseUp(event); - }; - - this.document - .bind( "mousemove." + this.widgetName, this._mouseMoveDelegate ) - .bind( "mouseup." + this.widgetName, this._mouseUpDelegate ); - - event.preventDefault(); - - mouseHandled = true; - return true; - }, - - _mouseMove: function(event) { - // Only check for mouseups outside the document if you've moved inside the document - // at least once. This prevents the firing of mouseup in the case of IE<9, which will - // fire a mousemove event if content is placed under the cursor. See #7778 - // Support: IE <9 - if ( this._mouseMoved ) { - // IE mouseup check - mouseup happened when mouse was out of window - if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) { - return this._mouseUp(event); - - // Iframe mouseup check - mouseup occurred in another document - } else if ( !event.which ) { - return this._mouseUp( event ); - } - } - - if ( event.which || event.button ) { - this._mouseMoved = true; - } - - if (this._mouseStarted) { - this._mouseDrag(event); - return event.preventDefault(); - } - - if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) { - this._mouseStarted = - (this._mouseStart(this._mouseDownEvent, event) !== false); - (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event)); - } - - return !this._mouseStarted; - }, - - _mouseUp: function(event) { - this.document - .unbind( "mousemove." + this.widgetName, this._mouseMoveDelegate ) - .unbind( "mouseup." + this.widgetName, this._mouseUpDelegate ); - - if (this._mouseStarted) { - this._mouseStarted = false; - - if (event.target === this._mouseDownEvent.target) { - $.data(event.target, this.widgetName + ".preventClickEvent", true); - } - - this._mouseStop(event); - } - - mouseHandled = false; - return false; - }, - - _mouseDistanceMet: function(event) { - return (Math.max( - Math.abs(this._mouseDownEvent.pageX - event.pageX), - Math.abs(this._mouseDownEvent.pageY - event.pageY) - ) >= this.options.distance - ); - }, - - _mouseDelayMet: function(/* event */) { - return this.mouseDelayMet; - }, - - // These are placeholder methods, to be overriden by extending plugin - _mouseStart: function(/* event */) {}, - _mouseDrag: function(/* event */) {}, - _mouseStop: function(/* event */) {}, - _mouseCapture: function(/* event */) { return true; } -}); - - -/*! - * jQuery UI Position 1.11.4 - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/position/ - */ - -(function() { - -$.ui = $.ui || {}; - -var cachedScrollbarWidth, supportsOffsetFractions, - max = Math.max, - abs = Math.abs, - round = Math.round, - rhorizontal = /left|center|right/, - rvertical = /top|center|bottom/, - roffset = /[\+\-]\d+(\.[\d]+)?%?/, - rposition = /^\w+/, - rpercent = /%$/, - _position = $.fn.position; - -function getOffsets( offsets, width, height ) { - return [ - parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ), - parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 ) - ]; -} - -function parseCss( element, property ) { - return parseInt( $.css( element, property ), 10 ) || 0; -} - -function getDimensions( elem ) { - var raw = elem[0]; - if ( raw.nodeType === 9 ) { - return { - width: elem.width(), - height: elem.height(), - offset: { top: 0, left: 0 } - }; - } - if ( $.isWindow( raw ) ) { - return { - width: elem.width(), - height: elem.height(), - offset: { top: elem.scrollTop(), left: elem.scrollLeft() } - }; - } - if ( raw.preventDefault ) { - return { - width: 0, - height: 0, - offset: { top: raw.pageY, left: raw.pageX } - }; - } - return { - width: elem.outerWidth(), - height: elem.outerHeight(), - offset: elem.offset() - }; -} - -$.position = { - scrollbarWidth: function() { - if ( cachedScrollbarWidth !== undefined ) { - return cachedScrollbarWidth; - } - var w1, w2, - div = $( "
    " ), - innerDiv = div.children()[0]; - - $( "body" ).append( div ); - w1 = innerDiv.offsetWidth; - div.css( "overflow", "scroll" ); - - w2 = innerDiv.offsetWidth; - - if ( w1 === w2 ) { - w2 = div[0].clientWidth; - } - - div.remove(); - - return (cachedScrollbarWidth = w1 - w2); - }, - getScrollInfo: function( within ) { - var overflowX = within.isWindow || within.isDocument ? "" : - within.element.css( "overflow-x" ), - overflowY = within.isWindow || within.isDocument ? "" : - within.element.css( "overflow-y" ), - hasOverflowX = overflowX === "scroll" || - ( overflowX === "auto" && within.width < within.element[0].scrollWidth ), - hasOverflowY = overflowY === "scroll" || - ( overflowY === "auto" && within.height < within.element[0].scrollHeight ); - return { - width: hasOverflowY ? $.position.scrollbarWidth() : 0, - height: hasOverflowX ? $.position.scrollbarWidth() : 0 - }; - }, - getWithinInfo: function( element ) { - var withinElement = $( element || window ), - isWindow = $.isWindow( withinElement[0] ), - isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9; - return { - element: withinElement, - isWindow: isWindow, - isDocument: isDocument, - offset: withinElement.offset() || { left: 0, top: 0 }, - scrollLeft: withinElement.scrollLeft(), - scrollTop: withinElement.scrollTop(), - - // support: jQuery 1.6.x - // jQuery 1.6 doesn't support .outerWidth/Height() on documents or windows - width: isWindow || isDocument ? withinElement.width() : withinElement.outerWidth(), - height: isWindow || isDocument ? withinElement.height() : withinElement.outerHeight() - }; - } -}; - -$.fn.position = function( options ) { - if ( !options || !options.of ) { - return _position.apply( this, arguments ); - } - - // make a copy, we don't want to modify arguments - options = $.extend( {}, options ); - - var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions, - target = $( options.of ), - within = $.position.getWithinInfo( options.within ), - scrollInfo = $.position.getScrollInfo( within ), - collision = ( options.collision || "flip" ).split( " " ), - offsets = {}; - - dimensions = getDimensions( target ); - if ( target[0].preventDefault ) { - // force left top to allow flipping - options.at = "left top"; - } - targetWidth = dimensions.width; - targetHeight = dimensions.height; - targetOffset = dimensions.offset; - // clone to reuse original targetOffset later - basePosition = $.extend( {}, targetOffset ); - - // force my and at to have valid horizontal and vertical positions - // if a value is missing or invalid, it will be converted to center - $.each( [ "my", "at" ], function() { - var pos = ( options[ this ] || "" ).split( " " ), - horizontalOffset, - verticalOffset; - - if ( pos.length === 1) { - pos = rhorizontal.test( pos[ 0 ] ) ? - pos.concat( [ "center" ] ) : - rvertical.test( pos[ 0 ] ) ? - [ "center" ].concat( pos ) : - [ "center", "center" ]; - } - pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center"; - pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center"; - - // calculate offsets - horizontalOffset = roffset.exec( pos[ 0 ] ); - verticalOffset = roffset.exec( pos[ 1 ] ); - offsets[ this ] = [ - horizontalOffset ? horizontalOffset[ 0 ] : 0, - verticalOffset ? verticalOffset[ 0 ] : 0 - ]; - - // reduce to just the positions without the offsets - options[ this ] = [ - rposition.exec( pos[ 0 ] )[ 0 ], - rposition.exec( pos[ 1 ] )[ 0 ] - ]; - }); - - // normalize collision option - if ( collision.length === 1 ) { - collision[ 1 ] = collision[ 0 ]; - } - - if ( options.at[ 0 ] === "right" ) { - basePosition.left += targetWidth; - } else if ( options.at[ 0 ] === "center" ) { - basePosition.left += targetWidth / 2; - } - - if ( options.at[ 1 ] === "bottom" ) { - basePosition.top += targetHeight; - } else if ( options.at[ 1 ] === "center" ) { - basePosition.top += targetHeight / 2; - } - - atOffset = getOffsets( offsets.at, targetWidth, targetHeight ); - basePosition.left += atOffset[ 0 ]; - basePosition.top += atOffset[ 1 ]; - - return this.each(function() { - var collisionPosition, using, - elem = $( this ), - elemWidth = elem.outerWidth(), - elemHeight = elem.outerHeight(), - marginLeft = parseCss( this, "marginLeft" ), - marginTop = parseCss( this, "marginTop" ), - collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width, - collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height, - position = $.extend( {}, basePosition ), - myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() ); - - if ( options.my[ 0 ] === "right" ) { - position.left -= elemWidth; - } else if ( options.my[ 0 ] === "center" ) { - position.left -= elemWidth / 2; - } - - if ( options.my[ 1 ] === "bottom" ) { - position.top -= elemHeight; - } else if ( options.my[ 1 ] === "center" ) { - position.top -= elemHeight / 2; - } - - position.left += myOffset[ 0 ]; - position.top += myOffset[ 1 ]; - - // if the browser doesn't support fractions, then round for consistent results - if ( !supportsOffsetFractions ) { - position.left = round( position.left ); - position.top = round( position.top ); - } - - collisionPosition = { - marginLeft: marginLeft, - marginTop: marginTop - }; - - $.each( [ "left", "top" ], function( i, dir ) { - if ( $.ui.position[ collision[ i ] ] ) { - $.ui.position[ collision[ i ] ][ dir ]( position, { - targetWidth: targetWidth, - targetHeight: targetHeight, - elemWidth: elemWidth, - elemHeight: elemHeight, - collisionPosition: collisionPosition, - collisionWidth: collisionWidth, - collisionHeight: collisionHeight, - offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ], - my: options.my, - at: options.at, - within: within, - elem: elem - }); - } - }); - - if ( options.using ) { - // adds feedback as second argument to using callback, if present - using = function( props ) { - var left = targetOffset.left - position.left, - right = left + targetWidth - elemWidth, - top = targetOffset.top - position.top, - bottom = top + targetHeight - elemHeight, - feedback = { - target: { - element: target, - left: targetOffset.left, - top: targetOffset.top, - width: targetWidth, - height: targetHeight - }, - element: { - element: elem, - left: position.left, - top: position.top, - width: elemWidth, - height: elemHeight - }, - horizontal: right < 0 ? "left" : left > 0 ? "right" : "center", - vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle" - }; - if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) { - feedback.horizontal = "center"; - } - if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) { - feedback.vertical = "middle"; - } - if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) { - feedback.important = "horizontal"; - } else { - feedback.important = "vertical"; - } - options.using.call( this, props, feedback ); - }; - } - - elem.offset( $.extend( position, { using: using } ) ); - }); -}; - -$.ui.position = { - fit: { - left: function( position, data ) { - var within = data.within, - withinOffset = within.isWindow ? within.scrollLeft : within.offset.left, - outerWidth = within.width, - collisionPosLeft = position.left - data.collisionPosition.marginLeft, - overLeft = withinOffset - collisionPosLeft, - overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset, - newOverRight; - - // element is wider than within - if ( data.collisionWidth > outerWidth ) { - // element is initially over the left side of within - if ( overLeft > 0 && overRight <= 0 ) { - newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset; - position.left += overLeft - newOverRight; - // element is initially over right side of within - } else if ( overRight > 0 && overLeft <= 0 ) { - position.left = withinOffset; - // element is initially over both left and right sides of within - } else { - if ( overLeft > overRight ) { - position.left = withinOffset + outerWidth - data.collisionWidth; - } else { - position.left = withinOffset; - } - } - // too far left -> align with left edge - } else if ( overLeft > 0 ) { - position.left += overLeft; - // too far right -> align with right edge - } else if ( overRight > 0 ) { - position.left -= overRight; - // adjust based on position and margin - } else { - position.left = max( position.left - collisionPosLeft, position.left ); - } - }, - top: function( position, data ) { - var within = data.within, - withinOffset = within.isWindow ? within.scrollTop : within.offset.top, - outerHeight = data.within.height, - collisionPosTop = position.top - data.collisionPosition.marginTop, - overTop = withinOffset - collisionPosTop, - overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset, - newOverBottom; - - // element is taller than within - if ( data.collisionHeight > outerHeight ) { - // element is initially over the top of within - if ( overTop > 0 && overBottom <= 0 ) { - newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset; - position.top += overTop - newOverBottom; - // element is initially over bottom of within - } else if ( overBottom > 0 && overTop <= 0 ) { - position.top = withinOffset; - // element is initially over both top and bottom of within - } else { - if ( overTop > overBottom ) { - position.top = withinOffset + outerHeight - data.collisionHeight; - } else { - position.top = withinOffset; - } - } - // too far up -> align with top - } else if ( overTop > 0 ) { - position.top += overTop; - // too far down -> align with bottom edge - } else if ( overBottom > 0 ) { - position.top -= overBottom; - // adjust based on position and margin - } else { - position.top = max( position.top - collisionPosTop, position.top ); - } - } - }, - flip: { - left: function( position, data ) { - var within = data.within, - withinOffset = within.offset.left + within.scrollLeft, - outerWidth = within.width, - offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left, - collisionPosLeft = position.left - data.collisionPosition.marginLeft, - overLeft = collisionPosLeft - offsetLeft, - overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft, - myOffset = data.my[ 0 ] === "left" ? - -data.elemWidth : - data.my[ 0 ] === "right" ? - data.elemWidth : - 0, - atOffset = data.at[ 0 ] === "left" ? - data.targetWidth : - data.at[ 0 ] === "right" ? - -data.targetWidth : - 0, - offset = -2 * data.offset[ 0 ], - newOverRight, - newOverLeft; - - if ( overLeft < 0 ) { - newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset; - if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) { - position.left += myOffset + atOffset + offset; - } - } else if ( overRight > 0 ) { - newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft; - if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) { - position.left += myOffset + atOffset + offset; - } - } - }, - top: function( position, data ) { - var within = data.within, - withinOffset = within.offset.top + within.scrollTop, - outerHeight = within.height, - offsetTop = within.isWindow ? within.scrollTop : within.offset.top, - collisionPosTop = position.top - data.collisionPosition.marginTop, - overTop = collisionPosTop - offsetTop, - overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop, - top = data.my[ 1 ] === "top", - myOffset = top ? - -data.elemHeight : - data.my[ 1 ] === "bottom" ? - data.elemHeight : - 0, - atOffset = data.at[ 1 ] === "top" ? - data.targetHeight : - data.at[ 1 ] === "bottom" ? - -data.targetHeight : - 0, - offset = -2 * data.offset[ 1 ], - newOverTop, - newOverBottom; - if ( overTop < 0 ) { - newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset; - if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) { - position.top += myOffset + atOffset + offset; - } - } else if ( overBottom > 0 ) { - newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop; - if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) { - position.top += myOffset + atOffset + offset; - } - } - } - }, - flipfit: { - left: function() { - $.ui.position.flip.left.apply( this, arguments ); - $.ui.position.fit.left.apply( this, arguments ); - }, - top: function() { - $.ui.position.flip.top.apply( this, arguments ); - $.ui.position.fit.top.apply( this, arguments ); - } - } -}; - -// fraction support test -(function() { - var testElement, testElementParent, testElementStyle, offsetLeft, i, - body = document.getElementsByTagName( "body" )[ 0 ], - div = document.createElement( "div" ); - - //Create a "fake body" for testing based on method used in jQuery.support - testElement = document.createElement( body ? "div" : "body" ); - testElementStyle = { - visibility: "hidden", - width: 0, - height: 0, - border: 0, - margin: 0, - background: "none" - }; - if ( body ) { - $.extend( testElementStyle, { - position: "absolute", - left: "-1000px", - top: "-1000px" - }); - } - for ( i in testElementStyle ) { - testElement.style[ i ] = testElementStyle[ i ]; - } - testElement.appendChild( div ); - testElementParent = body || document.documentElement; - testElementParent.insertBefore( testElement, testElementParent.firstChild ); - - div.style.cssText = "position: absolute; left: 10.7432222px;"; - - offsetLeft = $( div ).offset().left; - supportsOffsetFractions = offsetLeft > 10 && offsetLeft < 11; - - testElement.innerHTML = ""; - testElementParent.removeChild( testElement ); -})(); - -})(); - -var position = $.ui.position; - - -/*! - * jQuery UI Draggable 1.11.4 - * http://jqueryui.com - * - * Copyright jQuery Foundation and other contributors - * Released under the MIT license. - * http://jquery.org/license - * - * http://api.jqueryui.com/draggable/ - */ - - -$.widget("ui.draggable", $.ui.mouse, { - version: "1.11.4", - widgetEventPrefix: "drag", - options: { - addClasses: true, - appendTo: "parent", - axis: false, - connectToSortable: false, - containment: false, - cursor: "auto", - cursorAt: false, - grid: false, - handle: false, - helper: "original", - iframeFix: false, - opacity: false, - refreshPositions: false, - revert: false, - revertDuration: 500, - scope: "default", - scroll: true, - scrollSensitivity: 20, - scrollSpeed: 20, - snap: false, - snapMode: "both", - snapTolerance: 20, - stack: false, - zIndex: false, - - // callbacks - drag: null, - start: null, - stop: null - }, - _create: function() { - - if ( this.options.helper === "original" ) { - this._setPositionRelative(); - } - if (this.options.addClasses){ - this.element.addClass("ui-draggable"); - } - if (this.options.disabled){ - this.element.addClass("ui-draggable-disabled"); - } - this._setHandleClassName(); - - this._mouseInit(); - }, - - _setOption: function( key, value ) { - this._super( key, value ); - if ( key === "handle" ) { - this._removeHandleClassName(); - this._setHandleClassName(); - } - }, - - _destroy: function() { - if ( ( this.helper || this.element ).is( ".ui-draggable-dragging" ) ) { - this.destroyOnClear = true; - return; - } - this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" ); - this._removeHandleClassName(); - this._mouseDestroy(); - }, - - _mouseCapture: function(event) { - var o = this.options; - - this._blurActiveElement( event ); - - // among others, prevent a drag on a resizable-handle - if (this.helper || o.disabled || $(event.target).closest(".ui-resizable-handle").length > 0) { - return false; - } - - //Quit if we're not on a valid handle - this.handle = this._getHandle(event); - if (!this.handle) { - return false; - } - - this._blockFrames( o.iframeFix === true ? "iframe" : o.iframeFix ); - - return true; - - }, - - _blockFrames: function( selector ) { - this.iframeBlocks = this.document.find( selector ).map(function() { - var iframe = $( this ); - - return $( "
    " ) - .css( "position", "absolute" ) - .appendTo( iframe.parent() ) - .outerWidth( iframe.outerWidth() ) - .outerHeight( iframe.outerHeight() ) - .offset( iframe.offset() )[ 0 ]; - }); - }, - - _unblockFrames: function() { - if ( this.iframeBlocks ) { - this.iframeBlocks.remove(); - delete this.iframeBlocks; - } - }, - - _blurActiveElement: function( event ) { - var document = this.document[ 0 ]; - - // Only need to blur if the event occurred on the draggable itself, see #10527 - if ( !this.handleElement.is( event.target ) ) { - return; - } - - // support: IE9 - // IE9 throws an "Unspecified error" accessing document.activeElement from an