From a6b656779b001cd5346dd116e48c531b2227a69a Mon Sep 17 00:00:00 2001 From: Milan Date: Sun, 2 Sep 2018 09:39:24 +0200 Subject: [PATCH] refactoring update package definition fix dependencies remove global variables --- lib/calcms/aggregator.pm | 424 ++++++----- lib/calcms/audio_recordings.pm | 219 +++--- lib/calcms/auth.pm | 369 +++++---- lib/calcms/cache.pm | 212 +++--- lib/calcms/calendar.pm | 786 ++++++++++---------- lib/calcms/comments.pm | 32 +- lib/calcms/config.pm | 36 +- lib/calcms/creole_wiki.pm | 9 +- lib/calcms/db.pm | 311 ++++---- lib/calcms/eventOps.pm | 4 +- lib/calcms/event_history.pm | 8 +- lib/calcms/events.pm | 37 +- lib/calcms/images.pm | 13 +- lib/calcms/localization.pm | 7 +- lib/calcms/log.pm | 131 ++-- lib/calcms/mail.pm | 2 + lib/calcms/markup.pm | 16 +- lib/calcms/params.pm | 6 +- lib/calcms/password_requests.pm | 4 +- lib/calcms/playout.pm | 8 +- lib/calcms/project.pm | 14 +- lib/calcms/roles.pm | 269 +++---- lib/calcms/series.pm | 4 +- lib/calcms/series_dates.pm | 5 +- lib/calcms/series_events.pm | 4 +- lib/calcms/series_schedule.pm | 5 +- lib/calcms/startup.pl | 1 - lib/calcms/studio_timeslot_dates.pm | 610 +++++++-------- lib/calcms/studio_timeslot_schedule.pm | 6 +- lib/calcms/studios.pm | 13 +- lib/calcms/tags.pm | 20 +- lib/calcms/template.pm | 51 +- lib/calcms/time.pm | 102 +-- lib/calcms/uac.pm | 12 +- lib/calcms/user_settings.pm | 6 +- lib/calcms/user_stats.pm | 7 +- lib/calcms/work_dates.pm | 5 +- lib/calcms/work_schedule.pm | 160 ++-- website/agenda/add_comment.cgi | 4 +- website/agenda/aggregate.cgi | 10 - website/agenda/category.cgi | 4 +- website/agenda/events.cgi | 1 - website/agenda/planung/assign_series.cgi | 7 +- website/agenda/planung/assignments.cgi | 11 +- website/agenda/planung/audio_recordings.cgi | 6 +- website/agenda/planung/calendar.cgi | 8 +- website/agenda/planung/comment.cgi | 23 +- website/agenda/planung/create_events.cgi | 8 +- website/agenda/planung/error_log.cgi | 84 --- website/agenda/planung/event.cgi | 14 +- website/agenda/planung/event_history.cgi | 6 +- website/agenda/planung/help.cgi | 2 +- website/agenda/planung/image.cgi | 6 +- website/agenda/planung/imageUpload.cgi | 4 +- website/agenda/planung/notify_events.cgi | 6 +- website/agenda/planung/playout.cgi | 4 +- website/agenda/planung/projects.cgi | 8 +- website/agenda/planung/requestPassword.cgi | 2 +- website/agenda/planung/roles.cgi | 4 +- website/agenda/planung/selectEvent.cgi | 4 +- website/agenda/planung/selectSeries.cgi | 4 +- website/agenda/planung/series.cgi | 10 +- website/agenda/planung/show-playout.cgi | 212 +++--- website/agenda/planung/studio_timeslots.cgi | 10 +- website/agenda/planung/studios.cgi | 8 +- website/agenda/planung/user_settings.cgi | 6 +- website/agenda/planung/user_stats.cgi | 6 +- website/agenda/planung/users.cgi | 10 +- website/agenda/planung/work_time.cgi | 6 +- website/agenda/series.cgi | 2 +- website/agenda/series_names.cgi | 4 +- 71 files changed, 2135 insertions(+), 2297 deletions(-) mode change 100644 => 100755 website/agenda/planung/calendar.cgi delete mode 100755 website/agenda/planung/error_log.cgi mode change 100644 => 100755 website/agenda/planung/playout.cgi mode change 100644 => 100755 website/agenda/planung/requestPassword.cgi diff --git a/lib/calcms/aggregator.pm b/lib/calcms/aggregator.pm index 90a4e55..c45d2e5 100644 --- a/lib/calcms/aggregator.pm +++ b/lib/calcms/aggregator.pm @@ -1,292 +1,288 @@ +package aggregator; + use warnings "all"; use strict; + use events(); use comments(); use calendar(); use project(); +use cache(); -package aggregator; - -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_cache configure_cache put_cache get_list check_params); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); - -#my $cgi=undef; sub get_list { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + my $params = $request->{params}->{checked}; + my $debug = $config->{system}->{debug}; - #customize prefiltered request parameters - $request->{params}->{original}->{date} = $request->{params}->{checked}->{date}; - if ( $params->{event_id} ne '' ) { - $request->{params}->{original}->{template} = 'event_details.html'; - } else { - $request->{params}->{original}->{template} = 'event_list.html'; - } - $request->{params}->{checked} = events::check_params( $config, $request->{params}->{original} ); - - my $content = ''; - my $results = events::get( $config, $request ); - events::render( $content, $config, $request, $results ); + #customize prefiltered request parameters + $request->{params}->{original}->{date} = $request->{params}->{checked}->{date}; + if ( $params->{event_id} ne '' ) { + $request->{params}->{original}->{template} = 'event_details.html'; + } else { + $request->{params}->{original}->{template} = 'event_list.html'; + } + $request->{params}->{checked} = events::check_params( $config, $request->{params}->{original} ); - # calendar::get_cached_or_render($content,$request); + my $content = ''; + my $results = events::get( $config, $request ); + events::render( $content, $config, $request, $results ); - #set url to embed as last loaded url in javascript - my $date = $params->{date} || ''; - $date = 'heute' if ( $params->{date} eq 'today' ); - $date = $results->[0]->{day} if ( $params->{event_id} ne '' ); - my $url = ''; + #set url to embed as last loaded url in javascript + my $date = $params->{date} || ''; + $date = 'heute' if ( $params->{date} eq 'today' ); + $date = $results->[0]->{day} if ( $params->{event_id} ne '' ); + my $url = ''; - #$config->{controllers}->{events}.'/'.$date.'/'; - if ( $params->{from_date} ne '' && $params->{till_date} ne '' ) { - $url = $config->{controllers}->{events} . '/' . $params->{from_date} . '/' . $params->{till_date}; - } else { - $url = $config->{controllers}->{events} . '/' . $params->{from_date} . '/' . $params->{till_date}; - } + #$config->{controllers}->{events}.'/'.$date.'/'; + if ( $params->{from_date} ne '' && $params->{till_date} ne '' ) { + $url = $config->{controllers}->{events} . '/' . $params->{from_date} . '/' . $params->{till_date}; + } else { + $url = $config->{controllers}->{events} . '/' . $params->{from_date} . '/' . $params->{till_date}; + } - #count most projects - my $used_projects = {}; - for my $result (@$results) { - my $project = $result->{project_title} || ''; - $used_projects->{$project}++; - } - my @used_projects = reverse sort { $used_projects->{$a} <=> $used_projects->{$b} } ( keys %$used_projects ); - my $most_used_project = $used_projects[0]; + #count most projects + my $used_projects = {}; + for my $result (@$results) { + my $project = $result->{project_title} || ''; + $used_projects->{$project}++; + } + 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); + #use Data::Dumper;print STDERR Dumper(\@used_projects); - return { - day => $results->[0]->{day}, - start_datetime => $results->[0]->{start_datetime}, - event_id => $results->[0]->{event_id}, - program => $results->[0]->{program}, - project_title => $most_used_project, - series_name => $results->[0]->{series_name}, - title => $results->[0]->{title}, - content => $content, - results => $results, - url => $url, - }; + return { + day => $results->[0]->{day}, + start_datetime => $results->[0]->{start_datetime}, + event_id => $results->[0]->{event_id}, + program => $results->[0]->{program}, + project_title => $most_used_project, + series_name => $results->[0]->{series_name}, + title => $results->[0]->{title}, + content => $content, + results => $results, + url => $url, + }; } sub get_menu { - my $config = shift; - my $request = shift; - my $date = shift; - my $results = shift; + my $config = shift; + my $request = shift; + my $date = shift; + my $results = shift; - my $params = $request->{params}->{checked}; + my $params = $request->{params}->{checked}; - #load details only on demand - if ( $params->{event_id} ne '' ) { - $request->{params}->{original}->{template} = 'event_menu.html'; - $request->{params}->{original}->{event_id} = undef; - $request->{params}->{original}->{date} = $date; - $request->{params}->{checked} = events::check_params( $config, $request->{params}->{original} ); - $results = events::get( $config, $request ); - } else { - $request->{params}->{checked}->{template} = template::check('event_menu.html'); - } + #load details only on demand + if ( $params->{event_id} ne '' ) { + $request->{params}->{original}->{template} = 'event_menu.html'; + $request->{params}->{original}->{event_id} = undef; + $request->{params}->{original}->{date} = $date; + $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'); + } - #events menu - my $output = ''; - events::render( $output, $config, $request, $results ); + #events menu + my $output = ''; + events::render( $output, $config, $request, $results ); - return { content => $output }; + return { content => $output }; } sub get_calendar { - my $config = shift; - my $request = shift; - my $date = shift; + my $config = shift; + my $request = shift; + my $date = shift; - my $params = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + my $params = $request->{params}->{checked}; + my $debug = $config->{system}->{debug}; - $request->{params}->{original}->{template} = 'calendar.html'; - $request->{params}->{original}->{date} = $date if ( defined $date ); - $request->{params}->{checked} = calendar::check_params( $config, $request->{params}->{original} ); - $params = $request->{params}->{checked}; + $request->{params}->{original}->{template} = 'calendar.html'; + $request->{params}->{original}->{date} = $date if ( defined $date ); + $request->{params}->{checked} = calendar::check_params( $config, $request->{params}->{original} ); + $params = $request->{params}->{checked}; - #set query string for caching - my $options = []; + #set query string for caching + my $options = []; push @$options, 'date=' . $params->{date} if $params->{date} ne ''; push @$options, 'from_date=' . $params->{from_date} if $params->{from_date} ne ''; push @$options, 'till_date=' . $params->{till_date} if $params->{till_date} ne ''; - $ENV{QUERY_STRING} = '' . join( "&", @$options ); + $ENV{QUERY_STRING} = '' . join( "&", @$options ); - my $content = ''; - calendar::get_cached_or_render( $content, $config, $request ); + my $content = ''; + calendar::get_cached_or_render( $content, $config, $request ); - return { content => $content }; + return { content => $content }; } sub get_newest_comments { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = { - template => 'comments_newest.html', - limit => 10, - type => 'list', - show_max => 3 - }; - $request = { - url => $ENV{QUERY_STRING}, - params => { - original => $params, - checked => comments::check_params( $config, $params ), - }, - config => $config, - connection => $request->{connection} - }; - my $content = ''; - comments::get_cached_or_render( $content, $config, $request ); - return { content => $content }; + my $params = { + template => 'comments_newest.html', + limit => 10, + type => 'list', + show_max => 3 + }; + $request = { + url => $ENV{QUERY_STRING}, + params => { + original => $params, + checked => comments::check_params( $config, $params ), + }, + config => $config, + connection => $request->{connection} + }; + my $content = ''; + comments::get_cached_or_render( $content, $config, $request ); + return { content => $content }; } sub get_cache { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + 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 {}; + if ( $config->{cache}->{use_cache} == 1 ) { + configure_cache($config); + my $cache = cache::load( $config, $params ); + return $cache; + } + return {}; } sub configure_cache { - my $config = shift; + my $config = shift; - cache::init(); - my $controllers = $config->{controllers}; + cache::init(); + my $controllers = $config->{controllers}; - my $date_pattern = $cache::date_pattern; + 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' ); + # 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; + my $config = shift; + my $request = shift; + my $cache = shift; - #write to cache - if ( $config->{cache}->{use_cache} == 1 ) { - cache::save($cache); - } + #write to cache + if ( $config->{cache}->{use_cache} == 1 ) { + cache::save($cache); + } } sub check_params { - my $config = shift; - my $params = shift; + my $config = shift; + my $params = shift; - #get start and stop from projects - my $range = project::get_date_range($config); - my $start_date = $range->{start_date}; - my $end_date = $range->{end_date}; + #get start and stop from projects + my $range = project::get_date_range($config); + my $start_date = $range->{start_date}; + my $end_date = $range->{end_date}; - #filter for date - my $date = time::check_date( $params->{date} ); + #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); - } + #print STDERR $date."\n"; + if ( $date eq '' ) { + $date = time::time_to_date( time() ); + } + # + if ( $date eq 'today' ) { + $date = time::get_event_date($config); + } - # $date =$config->{date}->{start_date} if ($date lt $config->{date}->{start_date}); - # $date =$config->{date}->{end_date} if ($date gt $config->{date}->{end_date}); - $date = $start_date if $date lt $start_date; - $date = $end_date if $date gt $end_date; + # $date =$config->{date}->{start_date} if ($date lt $config->{date}->{start_date}); + # $date =$config->{date}->{end_date} if ($date gt $config->{date}->{end_date}); + $date = $start_date if $date lt $start_date; + $date = $end_date if $date gt $end_date; - #filter for date - # my $date=time::check_date($params->{date}); - my $time = time::check_time( $params->{time} ); - if ( ( defined $params->{today} ) && ( $params->{today} eq '1' ) ) { - $date = time::time_to_date( time() ); - $params->{date} = $date; - } + #filter for date + # my $date=time::check_date($params->{date}); + my $time = time::check_time( $params->{time} ); + if ( ( defined $params->{today} ) && ( $params->{today} eq '1' ) ) { + $date = time::time_to_date( time() ); + $params->{date} = $date; + } - my $from_date = time::check_date( $params->{from_date} ); - my $till_date = time::check_date( $params->{till_date} ); + my $from_date = time::check_date( $params->{from_date} ); + my $till_date = time::check_date( $params->{till_date} ); - my $previous_series = $params->{previous_series} || ''; - if ( ($previous_series) && ( $previous_series =~ /(\d+)/ ) ) { - $params->{event_id} = events::get_previous_event_of_series( - undef, $config, - { - event_id => $1, - exclude_projects => 1, - exclude_locations => 1, - } - ); - } + my $previous_series = $params->{previous_series} || ''; + if ( ($previous_series) && ( $previous_series =~ /(\d+)/ ) ) { + $params->{event_id} = events::get_previous_event_of_series( + undef, $config, + { + event_id => $1, + exclude_projects => 1, + exclude_locations => 1, + } + ); + } - my $next_series = $params->{next_series} || ''; - if ( ($next_series) && ( $next_series =~ /(\d+)/ ) ) { - $params->{event_id} = events::get_next_event_of_series( - undef, $config, - { - event_id => $1, - exclude_projects => 1, - exclude_locations => 1, - } - ); - } + my $next_series = $params->{next_series} || ''; + if ( ($next_series) && ( $next_series =~ /(\d+)/ ) ) { + $params->{event_id} = events::get_next_event_of_series( + undef, $config, + { + event_id => $1, + exclude_projects => 1, + exclude_locations => 1, + } + ); + } - my $event_id = $params->{event_id} || ''; - unless ( $event_id eq '' ) { - if ( $event_id =~ /(\d+)/ ) { - $event_id = $1; - } else { - log::error( $config, "invalid event_id" ); - } - } + my $event_id = $params->{event_id} || ''; + unless ( $event_id eq '' ) { + if ( $event_id =~ /(\d+)/ ) { + $event_id = $1; + } else { + log::error( $config, "invalid event_id" ); + } + } - my $debug = $params->{debug} || ''; - if ( $debug =~ /([a-z\_\,]+)/ ) { - $debug = $1; - } + my $debug = $params->{debug} || ''; + if ( $debug =~ /([a-z\_\,]+)/ ) { + $debug = $1; + } - #set query string for caching - if ( ( !exists $ENV{QUERY_STRING} ) || ( $ENV{QUERY_STRING} eq '' ) ) { - my $options = []; + #set query string for caching + if ( ( !exists $ENV{QUERY_STRING} ) || ( $ENV{QUERY_STRING} eq '' ) ) { + my $options = []; push @$options, 'date=' . $date if $date ne ''; push @$options, 'from_date=' . $from_date if $from_date ne ''; push @$options, 'till_date=' . $till_date if $till_date ne ''; push @$options, 'event_id=' . $event_id if $event_id ne ''; - $ENV{QUERY_STRING} = '' . join( "&", @$options ); - } + $ENV{QUERY_STRING} = '' . join( "&", @$options ); + } - return { - date => $date, - time => $time, - from_date => $from_date, - till_date => $till_date, - event_id => $event_id, + return { + date => $date, + time => $time, + from_date => $from_date, + till_date => $till_date, + event_id => $event_id, - # project => $project, - debug => $debug, - }; + # project => $project, + debug => $debug, + }; } #do not delete last line! diff --git a/lib/calcms/audio_recordings.pm b/lib/calcms/audio_recordings.pm index 5b51cd9..dc341e9 100644 --- a/lib/calcms/audio_recordings.pm +++ b/lib/calcms/audio_recordings.pm @@ -1,5 +1,3 @@ -#!/bin/perl - package audio_recordings; use warnings "all"; @@ -8,11 +6,8 @@ use strict; use Data::Dumper; use db(); -require Exporter; - -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); # columns: # id, project_id, studio_id, event_id @@ -23,67 +18,67 @@ our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; sub get_columns { - my $config = shift; + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_audio_recordings' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_audio_recordings' ); + my $columns = {}; + for my $col (@$cols) { + $columns->{$col} = 1; + } + return $columns; } # get playout entries sub get { - my $config = shift; - my $condition = shift; + my $config = shift; + my $condition = shift; - return undef unless defined $condition->{project_id}; - return undef unless defined $condition->{studio_id}; + return undef unless defined $condition->{project_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->{id} ) && ( $condition->{id} ne '' ) ) { - push @$conditions, 'id=?'; - push @$bind_values, $condition->{id}; - } + if ( ( defined $condition->{id} ) && ( $condition->{id} ne '' ) ) { + push @$conditions, 'id=?'; + push @$bind_values, $condition->{id}; + } - 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->{event_id} ) && ( $condition->{event_id} ne '' ) ) { - push @$conditions, 'event_id=?'; - push @$bind_values, $condition->{event_id}; - } + if ( ( defined $condition->{event_id} ) && ( $condition->{event_id} ne '' ) ) { + push @$conditions, 'event_id=?'; + push @$bind_values, $condition->{event_id}; + } - if ( ( defined $condition->{path} ) && ( $condition->{path} ne '' ) ) { - push @$conditions, 'path=?'; - push @$bind_values, $condition->{path}; - } + if ( ( defined $condition->{path} ) && ( $condition->{path} ne '' ) ) { + push @$conditions, 'path=?'; + push @$bind_values, $condition->{path}; + } - 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 $whereClause = ''; - $whereClause = " where " . join( " and ", @$conditions ) if ( scalar @$conditions > 0 ); + my $whereClause = ''; + $whereClause = " where " . join( " and ", @$conditions ) if ( scalar @$conditions > 0 ); - my $query = qq{ + my $query = qq{ select id ,project_id ,studio_id @@ -104,32 +99,32 @@ sub get { order by created_at desc }; - #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 entry if differs to old values sub update { - my $config = shift; - my $dbh = shift; - my $entry = shift; + my $config = shift; + my $dbh = shift; + my $entry = shift; - #print STDERR "update:".Dumper($entry); + #print STDERR "update:".Dumper($entry); - my $day_start = $config->{date}->{day_starting_hour}; + my $day_start = $config->{date}->{day_starting_hour}; - my $bind_values = [ - $entry->{path}, $entry->{size}, - $entry->{created_by}, $entry->{created_at}, - $entry->{modified_at} || time::time_to_datetime( time() ), $entry->{processed}, - $entry->{mastered}, $entry->{eventDuration}, - $entry->{audioDuration}, $entry->{rmsLeft}, - $entry->{rmsRight}, $entry->{project_id}, - $entry->{studio_id}, $entry->{event_id} - ]; + my $bind_values = [ + $entry->{path}, $entry->{size}, + $entry->{created_by}, $entry->{created_at}, + $entry->{modified_at} || time::time_to_datetime( time() ), $entry->{processed}, + $entry->{mastered}, $entry->{eventDuration}, + $entry->{audioDuration}, $entry->{rmsLeft}, + $entry->{rmsRight}, $entry->{project_id}, + $entry->{studio_id}, $entry->{event_id} + ]; - my $query = qq{ + my $query = qq{ update calcms_audio_recordings set path=?, size=?, created_by=?, created_at=?, @@ -139,71 +134,71 @@ sub update { rmsLeft=?, rmsRight=? where project_id=? and studio_id=? and event_id=? }; - if ( defined $entry->{id} ) { - $query .= ' and id=?'; - push @$bind_values, $entry->{id}; - } + if ( defined $entry->{id} ) { + $query .= ' and id=?'; + push @$bind_values, $entry->{id}; + } - #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 ); } # insert playout entry sub insert { - my $config = shift; - my $dbh = shift; - my $entry = shift; + 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->{event_id}; - return undef unless defined $entry->{path}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{event_id}; + return undef unless defined $entry->{path}; - #print STDERR "insert into audio_recordings:".Dumper($entry); - return db::insert( - $dbh, - 'calcms_audio_recordings', - { - project_id => $entry->{project_id}, - studio_id => $entry->{studio_id}, - event_id => $entry->{event_id}, - path => $entry->{path}, - size => $entry->{size}, - created_by => $entry->{created_by}, - eventDuration => $entry->{eventDuration}, - audioDuration => $entry->{audioDuration}, - rmsLeft => $entry->{rmsLeft}, - rmsRight => $entry->{rmsRight}, - processed => $entry->{processed}, - mastered => $entry->{mastered} || '0', - } - ); + #print STDERR "insert into audio_recordings:".Dumper($entry); + return db::insert( + $dbh, + 'calcms_audio_recordings', + { + project_id => $entry->{project_id}, + studio_id => $entry->{studio_id}, + event_id => $entry->{event_id}, + path => $entry->{path}, + size => $entry->{size}, + created_by => $entry->{created_by}, + eventDuration => $entry->{eventDuration}, + audioDuration => $entry->{audioDuration}, + rmsLeft => $entry->{rmsLeft}, + rmsRight => $entry->{rmsRight}, + processed => $entry->{processed}, + mastered => $entry->{mastered} || '0', + } + ); } # delete playout entry sub delete { - my $config = shift; - my $dbh = shift; - my $entry = shift; + 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->{event_id}; - return undef unless defined $entry->{path}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{event_id}; + return undef unless defined $entry->{path}; - my $query = qq{ + my $query = qq{ delete from calcms_audio_recordings where project_id=? and studio_id=? and event_id=? and path=? }; - my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ]; - return db::put( $dbh, $query, $bind_values ); + my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{event_id}, $entry->{path} ]; + return db::put( $dbh, $query, $bind_values ); } sub error { - my $msg = shift; - print "ERROR: $msg
\n"; + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/lib/calcms/auth.pm b/lib/calcms/auth.pm index b6f19be..18af258 100644 --- a/lib/calcms/auth.pm +++ b/lib/calcms/auth.pm @@ -1,25 +1,20 @@ -#!/bin/perl +package auth; + +use warnings "all"; +use strict; use CGI; use CGI::Session qw(-ip-match); use CGI::Cookie(); #$CGI::Session::IP_MATCH=1; - -package auth; - -use warnings "all"; -use strict; - use Data::Dumper; use Authen::Passphrase::BlowfishCrypt(); + use time(); -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(get_user login logout crypt_password); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); - +use base 'Exporter'; +our @EXPORT_OK = qw(get_user login logout crypt_password); my $defaultExpiration = 60; my $tmp_dir = '/var/tmp/'; my $debug = 0; @@ -27,259 +22,258 @@ my $debug = 0; sub debug; sub get_user { - my $cgi = shift; - my $config = shift; + my $cgi = shift; + my $config = shift; - my %parms = $cgi->Vars(); - my $parms = \%parms; + my %parms = $cgi->Vars(); + my $parms = \%parms; - debug("get_user") if ($debug); + debug("get_user") if ($debug); - # login or logout on action - if ( defined $parms->{action} ) { - if ( $parms->{action} eq 'login' ) { - my $user = login( $cgi, $config, $parms->{user}, $parms->{password} ); - $cgi->delete( 'user', 'password', 'uri', 'action' ); - return $user; - } elsif ( $parms->{action} eq 'logout' ) { - logout($cgi); - $cgi->delete( 'user', 'password', 'uri', 'action' ); - return undef; - } - } + # login or logout on action + if ( defined $parms->{action} ) { + if ( $parms->{action} eq 'login' ) { + my $user = login( $cgi, $config, $parms->{user}, $parms->{password} ); + $cgi->delete( 'user', 'password', 'uri', 'action' ); + return $user; + } elsif ( $parms->{action} eq 'logout' ) { + logout($cgi); + $cgi->delete( 'user', 'password', 'uri', 'action' ); + return undef; + } + } - # read session id from cookie - my $session_id = read_cookie($cgi); + # read session id from cookie + my $session_id = read_cookie($cgi); - # login if no cookie found - return show_login_form( $parms->{user}, 'Please login' ) unless defined $session_id; + # login if no cookie found + return show_login_form( $parms->{user}, 'Please login' ) unless defined $session_id; - # read session - my $session = read_session($session_id); + # read session + my $session = read_session($session_id); - # login if user not found - return show_login_form( $parms->{user}, 'unknown User' ) unless defined $session; + # login if user not found + return show_login_form( $parms->{user}, 'unknown User' ) unless defined $session; - $parms->{user} = $session->{user}; - $parms->{expires} = $session->{expires}; - debug( $parms->{expires} ); - return $session->{user}, $session->{expires}; + $parms->{user} = $session->{user}; + $parms->{expires} = $session->{expires}; + debug( $parms->{expires} ); + return $session->{user}, $session->{expires}; } sub crypt_password { - my $password = shift; + my $password = shift; - my $ppr = Authen::Passphrase::BlowfishCrypt->new( - cost => 8, - salt_random => 1, - passphrase => $password - ); - return { - salt => $ppr->salt_base64, - crypt => $ppr->as_crypt - }; + my $ppr = Authen::Passphrase::BlowfishCrypt->new( + cost => 8, + salt_random => 1, + passphrase => $password + ); + return { + salt => $ppr->salt_base64, + crypt => $ppr->as_crypt + }; } sub login { - my $cgi = shift; - my $config = shift; - my $user = shift; - my $password = shift; - debug("login") if ($debug); + my $cgi = shift; + my $config = shift; + my $user = shift; + my $password = shift; + debug("login") if ($debug); - #print STDERR "login $user $password\n"; - my $result = authenticate( $config, $user, $password ); + #print STDERR "login $user $password\n"; + my $result = authenticate( $config, $user, $password ); - #print STDERR Dumper($result); + #print STDERR Dumper($result); - return show_login_form( $user, 'Could not authenticate you' ) unless defined $result; - return unless defined $result->{login} eq '1'; + return show_login_form( $user, 'Could not authenticate you' ) unless defined $result; + return unless defined $result->{login} eq '1'; - my $timeout = $result->{timeout} || $defaultExpiration; - $timeout = '+' . $timeout . 'm'; + my $timeout = $result->{timeout} || $defaultExpiration; + $timeout = '+' . $timeout . 'm'; - my $session_id = create_session( $user, $password, $timeout ); - return $user if ( create_cookie( $cgi, $session_id, $timeout ) ); - return undef; + my $session_id = create_session( $user, $password, $timeout ); + return $user if ( create_cookie( $cgi, $session_id, $timeout ) ); + return undef; } sub logout { - my $cgi = shift; - my $session_id = read_cookie($cgi); - debug("logout") if ($debug); - unless ( delete_session($session_id) ) { - return show_login_form( 'Cant delete session', 'logged out' ); - } - unless ( delete_cookie($cgi) ) { - return show_login_form( 'Cant remove cookie', 'logged out' ); - } - my $uri = $ENV{HTTP_REFERER} || ''; - $uri =~ s/action=logout//g; - print $cgi->redirect($uri); - - # return show_login_form('', 'logged out'); + my $cgi = shift; + my $session_id = read_cookie($cgi); + debug("logout") if ($debug); + unless ( delete_session($session_id) ) { + return show_login_form( 'Cant delete session', 'logged out' ); + } + unless ( delete_cookie($cgi) ) { + return show_login_form( 'Cant remove cookie', 'logged out' ); + } + my $uri = $ENV{HTTP_REFERER} || ''; + $uri =~ s/action=logout//g; + print $cgi->redirect($uri); + return; } #read and write data from browser, http://perldoc.perl.org/CGI/Cookie.html sub create_cookie { - my $cgi = shift; - my $session_id = shift; - my $timeout = shift; + my $cgi = shift; + my $session_id = shift; + my $timeout = shift; - #debug("create_cookie")if ($debug); + #debug("create_cookie")if ($debug); - my $cookie = CGI::Cookie->new( - -name => 'sessionID', - -value => $session_id, - -expires => $timeout, + my $cookie = CGI::Cookie->new( + -name => 'sessionID', + -value => $session_id, + -expires => $timeout, - # -domain => '.capricorn.com', - # -path => '/agenda/admin/', - -secure => 1 - ); - print "Set-Cookie: ", $cookie->as_string, "\n"; - print STDERR "#Set-Cookie: ", $cookie->as_string, "\n"; + # -domain => '.capricorn.com', + # -path => '/agenda/admin/', + -secure => 1 + ); + print "Set-Cookie: ", $cookie->as_string, "\n"; + print STDERR "#Set-Cookie: ", $cookie->as_string, "\n"; - # print $cgi->header( -cookie => $cookie ); - return 1; + # print $cgi->header( -cookie => $cookie ); + return 1; } sub read_cookie { - my $cgi = shift; + my $cgi = shift; - debug("read_cookie") if ($debug); - my %cookie = CGI::Cookie->fetch; - debug( "cookies: " . Dumper( \%cookie ) ) if ($debug); - my $cookie = $cookie{'sessionID'}; - debug( "cookie: " . $cookie ) if ($debug); - return undef unless ( defined $cookie ); - my $session_id = $cookie->value || undef; - debug( "sid: " . $session_id ) if ($debug); - return $session_id; + debug("read_cookie") if ($debug); + my %cookie = CGI::Cookie->fetch; + debug( "cookies: " . Dumper( \%cookie ) ) if ($debug); + my $cookie = $cookie{'sessionID'}; + debug( "cookie: " . $cookie ) if ($debug); + return undef unless defined $cookie ; + my $session_id = $cookie->value || undef; + debug( "sid: " . $session_id ) if ($debug); + return $session_id; - #return $cgi->cookie('sessionID') || undef; + #return $cgi->cookie('sessionID') || undef; } sub delete_cookie { - my $cgi = shift; + my $cgi = shift; - debug("delete_cookie") if ($debug); - my $cookie = $cgi->cookie( - -name => 'sessionID', - -value => '', - -expires => '+1s' - ); - print $cgi->header( -cookie => $cookie ); - return 1; + debug("delete_cookie") if ($debug); + my $cookie = $cgi->cookie( + -name => 'sessionID', + -value => '', + -expires => '+1s' + ); + print $cgi->header( -cookie => $cookie ); + return 1; } #read and write server-side session data sub create_session { - my $user = shift; - my $password = shift; - my $expiration = shift; + my $user = shift; + my $password = shift; + my $expiration = shift; - debug("create_session") if ($debug); - my $session = new CGI::Session( undef, undef, { Directory => $tmp_dir } ); - $session->expire($expiration); - $session->param( "user", $user ); - $session->param( "pid", $$ ); + debug("create_session") if ($debug); + my $session = CGI::Session->new( undef, undef, { Directory => $tmp_dir } ); + $session->expire($expiration); + $session->param( "user", $user ); + $session->param( "pid", $$ ); - # $session->param("password", $password); - return $session->id(); + # $session->param("password", $password); + return $session->id(); } sub read_session { - my $session_id = shift; + my $session_id = shift; - debug("read_session") if $debug; - return undef unless ( defined $session_id ); + debug("read_session") if $debug; + return undef unless ( defined $session_id ); - debug("read_session2") if $debug; - my $session = new CGI::Session( undef, $session_id, { Directory => $tmp_dir } ); - return undef unless defined $session; + debug("read_session2") if $debug; + my $session = CGI::Session->new( undef, $session_id, { Directory => $tmp_dir } ); + return undef unless defined $session; - debug("read_session3") if $debug; - my $user = $session->param("user") || undef; - return undef unless defined $user; - my $expires = time::time_to_datetime( $session->param("_SESSION_ATIME") + $session->param("_SESSION_ETIME") ); - return { - user => $user, - expires => $expires - }; + debug("read_session3") if $debug; + my $user = $session->param("user") || undef; + return undef unless defined $user; + my $expires = time::time_to_datetime( $session->param("_SESSION_ATIME") + $session->param("_SESSION_ETIME") ); + return { + user => $user, + expires => $expires + }; } sub delete_session { - my $session_id = shift; + my $session_id = shift; - debug("delete_session") if ($debug); - return undef unless ( defined $session_id ); - my $session = new CGI::Session( undef, $session_id, { Directory => $tmp_dir } ); - $session->delete(); - return 1; + debug("delete_session") if ($debug); + return undef unless ( defined $session_id ); + my $session = CGI::Session->new( undef, $session_id, { Directory => $tmp_dir } ); + $session->delete(); + return 1; } #check user authentication sub authenticate { - my $config = shift; - my $user = shift; - my $password = shift; + my $config = shift; + my $user = shift; + my $password = shift; - $config->{access}->{write} = 0; - my $dbh = db::connect($config); - my $query = qq{ + $config->{access}->{write} = 0; + my $dbh = db::connect($config); + my $query = qq{ select * from calcms_users where name=? }; - my $bind_values = [$user]; + my $bind_values = [$user]; - #print STDERR "query:".Dumper($query).Dumper($bind_values); + #print STDERR "query:".Dumper($query).Dumper($bind_values); - my $users = db::get( $dbh, $query, $bind_values ); + my $users = db::get( $dbh, $query, $bind_values ); - #print STDERR "result:".Dumper($users); + #print STDERR "result:".Dumper($users); - if ( scalar(@$users) != 1 ) { - print STDERR "auth: did not find user '$user'\n"; - return undef; - } + if ( scalar(@$users) != 1 ) { + print STDERR "auth: did not find user '$user'\n"; + return undef; + } - #print STDERR Dumper($users); + #print STDERR Dumper($users); - my $salt = $users->[0]->{salt}; - my $ppr = Authen::Passphrase::BlowfishCrypt->from_crypt( $users->[0]->{pass}, $users->[0]->{salt} ); + my $salt = $users->[0]->{salt}; + my $ppr = Authen::Passphrase::BlowfishCrypt->from_crypt( $users->[0]->{pass}, $users->[0]->{salt} ); - return undef unless $ppr->match($password); - if ( $users->[0]->{disabled} == 1 ) { - print STDERR "user '$user' is disabled\n"; - return undef; - } + return undef unless $ppr->match($password); + if ( $users->[0]->{disabled} == 1 ) { + print STDERR "user '$user' is disabled\n"; + return undef; + } - my $timeout = $users->[0]->{session_timeout} || 120; - $timeout = 10 if $timeout < 10; - $timeout = 12 * 60 if $timeout > 12 * 60; + my $timeout = $users->[0]->{session_timeout} || 120; + $timeout = 10 if $timeout < 10; + $timeout = 12 * 60 if $timeout > 12 * 60; - return { - timeout => $timeout, - login => 1 - }; + return { + timeout => $timeout, + login => 1 + }; } sub show_login_form { - my $user = shift || ''; - my $uri = $ENV{HTTP_REFERER} || ''; - my $message = shift || ''; - my $requestReset = ''; + my $user = shift || ''; + my $uri = $ENV{HTTP_REFERER} || ''; + my $message = shift || ''; + my $requestReset = ''; - if ( ( $user ne '' ) && ( $message ne '' ) ) { - $requestReset = qq{ + if ( ( $user ne '' ) && ( $message ne '' ) ) { + $requestReset = qq{ forgotten }; - } + } - debug("show_login_form") if ($debug); - print qq{Content-type:text/html + debug("show_login_form") if ($debug); + print qq{Content-type:text/html @@ -377,12 +371,13 @@ sub show_login_form { }; - return undef; + return undef; } sub debug { - my $message = shift; - print STDERR "$message\n" if $debug > 0; + my $message = shift; + print STDERR "$message\n" if $debug > 0; + return; } #do not delete last line! diff --git a/lib/calcms/cache.pm b/lib/calcms/cache.pm index 9a02869..ffa0a73 100644 --- a/lib/calcms/cache.pm +++ b/lib/calcms/cache.pm @@ -1,3 +1,5 @@ +package cache; + use warnings "all"; use strict; @@ -6,171 +8,175 @@ use time(); use log(); use markup(); -package cache; - -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(init add_map get_map get_map_keys load save get_filename escape_regexp escape_regexp_line); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); my $cache_map = {}; my $cache_map_keys = []; my $header_printed = 0; -our $date_pattern = '(\d{4})\-(\d{2})\-(\d{2})'; -our $datetime_pattern = '(\d{4})\-(\d{2})\-(\d{2})[T\+](\d{2})\:(\d{2})(\:\d{2})?'; +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; + $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]; + my $key = $_[0]; + my $value = $_[1]; - $key = '^' . $key . '$'; - push @$cache_map_keys, $key; - $cache_map->{$key} = $value; + $key = '^' . $key . '$'; + push @$cache_map_keys, $key; + $cache_map->{$key} = $value; } sub get_map { - return $cache_map; + return $cache_map; } sub get_map_keys { - return $cache_map_keys; + return $cache_map_keys; } #get cache from params sub load { - my $params = shift; + my $params = shift; - my $filename = get_filename($params); + my $filename = get_filename($params); - my $result = { filename => $filename }; + my $result = { filename => $filename }; - if ( defined $filename ) { - my @file_info = stat($filename); - my $modified = $file_info[9] || ''; - if ( $modified ne '' ) { + 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 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; - } - } - } - } + #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; + $result->{action} = 'save'; + return $result; } #get filename from params sub get_filename { - my $config = shift; - my $params = shift; + 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 $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 $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 $m9=$9; - my $result = $cache_map->{$pattern}; + 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/$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; + # $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 $params = shift; + my $content = shift; - my $filename = get_filename($params); - my $cache = { - filename => $filename, - content => $content - }; + my $filename = get_filename($params); + my $cache = { + filename => $filename, + content => $content + }; - # print $filename.":file\n"; + # print $filename.":file\n"; - if ( defined $filename ) { - cache::save($cache); - } + if ( defined $filename ) { + cache::save($cache); + } } sub save { - my $cache = shift; + 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}; + 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; + 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 . '$'; + my $reg_exp = shift; + $reg_exp =~ s/([\^\$\\(\)\[\]\{\}\|\/\*\+\.\-\&\:])/\\$1/gi; + return '^' . $reg_exp . '$'; } sub configure { - my $file_name = shift; + my $file_name = shift; - cache::init(); - cache::add_map( '', $file_name ); + cache::init(); + cache::add_map( '', $file_name ); } #do not delete last line! diff --git a/lib/calcms/calendar.pm b/lib/calcms/calendar.pm index 781801b..d5fcdb5 100644 --- a/lib/calcms/calendar.pm +++ b/lib/calcms/calendar.pm @@ -1,524 +1,514 @@ - -#use config(); -use template(); - -#use markup(); -use cache(); - -#use log(); -#use time(); -#use project(); -#use events(); - package calendar; + use warnings "all"; use strict; + use Data::Dumper; use Date::Calc(); -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(init get_cached_or_render get render get_calendar_weeks configure_cache); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); +use template(); +use cache(); -#my $debug=''; +use base 'Exporter'; +our @EXPORT_OK = qw(init get_cached_or_render get render get_calendar_weeks configure_cache); sub init { } sub get_cached_or_render { - # my $output = $_[0] - my $config = $_[1]; - my $request = $_[2]; + # my $output = $_[0] + my $config = $_[1]; + my $request = $_[2]; - my $parms = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + 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 $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 ); + my $calendar = calendar::get( $config, $request ); - calendar::render( $_[0], $config, $request, $calendar ); + calendar::render( $_[0], $config, $request, $calendar ); - #write to cache - if ( $config->{cache}->{use_cache} == 1 ) { + #write to cache + if ( $config->{cache}->{use_cache} == 1 ) { - #todo:put out reference only - $cache->{content} = $_[0]; - cache::save($cache); - } + #todo:put out reference only + $cache->{content} = $_[0]; + cache::save($cache); + } } sub get { - my $config = shift; - my $request = shift; + my $config = shift; + my $request = shift; - my $params = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + my $params = $request->{params}->{checked}; + my $debug = $config->{system}->{debug}; - my $language = $config->{date}->{language} || 'en'; + my $language = $config->{date}->{language} || 'en'; - my $date = $params->{date} || ''; - my $template = $params->{template} || ''; - my $from_time = $params->{from_time} || ''; - my $till_time = $params->{till_time} || ''; + my $date = $params->{date} || ''; + my $template = $params->{template} || ''; + my $from_time = $params->{from_time} || ''; + my $till_time = $params->{till_time} || ''; - my @today = localtime( time() ); - my $today = sprintf( '%04d-%02d-%02d', 1900 + $today[5], $today[4] + 1, $today[3] ); + my @today = localtime( time() ); + my $today = sprintf( '%04d-%02d-%02d', 1900 + $today[5], $today[4] + 1, $today[3] ); - my $weekday_names = $time::names->{$language}->{weekdays}; - my $weekday_short_names = $time::names->{$language}->{weekdays_abbr}; - my $week_label = {}; - my $c = 0; - for my $weekday (@$weekday_short_names) { - $week_label->{$weekday} = $weekday_names->[$c] || ''; - $c++; - } + my $weekday_names = time::getWeekdayNames($language); + my $weekday_short_names = time::getWeekdayNamesShort($language); + my $week_label = {}; + my $c = 0; + for my $weekday (@$weekday_short_names) { + $week_label->{$weekday} = $weekday_names->[$c] || ''; + $c++; + } - $template =~ s/\'//gi; - $from_time =~ s/\'//gi; - $till_time =~ s/\'//gi; + $template =~ s/\'//gi; + $from_time =~ s/\'//gi; + $till_time =~ s/\'//gi; - #put "clear all" filter into final results - my $day_result = {}; - my $clear_filter = $day_result; + #put "clear all" filter into final results + my $day_result = {}; + my $clear_filter = $day_result; - #put "week day" filter into final results - my $days = []; - $c = 0; - for my $weekday (@$weekday_short_names) { - my $day_result = { - label => $week_label->{$weekday}, - weekday => $c + 1, - weekday_parameter => 'weekday=' . $c, - weekday_short_name => $weekday_short_names->[$c] || '', - weekday_name => $weekday_names->[$c] || '', - description => qq{alle $week_label->{$weekday}-Termine anzeigen}, - }; - push @$days, $day_result; - $c++; - } + #put "week day" filter into final results + my $days = []; + $c = 0; + for my $weekday (@$weekday_short_names) { + my $day_result = { + label => $week_label->{$weekday}, + weekday => $c + 1, + weekday_parameter => 'weekday=' . $c, + weekday_short_name => $weekday_short_names->[$c] || '', + weekday_name => $weekday_names->[$c] || '', + description => qq{alle $week_label->{$weekday}-Termine anzeigen}, + }; + push @$days, $day_result; + $c++; + } - #weeks and days array - my $weekAndDayResults = []; + #weeks and days array + my $weekAndDayResults = []; - #weekday array - my $weekdayResults = $days; + #weekday array + my $weekdayResults = $days; - #week array - my $weekResults = []; + #week array + my $weekResults = []; - #info hash by timedate - my $dateInfo = {}; + #info hash by timedate + my $dateInfo = {}; - #generate content for each day in a week in a month in a year - #get today - my $start_date = ''; - my $end_date = ''; - if ( $date =~ /(\d{4})\-(\d{2})/ ) { - my $year = $1; - my $month = $2; - $start_date = "$year-$month-01"; - $end_date = "$year-$month-" . Date::Calc::Days_in_Month( $year, $month ); - } else { - $start_date = $params->{start_date}; - $end_date = $params->{end_date}; - } + #generate content for each day in a week in a month in a year + #get today + my $start_date = ''; + my $end_date = ''; + if ( $date =~ /(\d{4})\-(\d{2})/ ) { + my $year = $1; + my $month = $2; + $start_date = "$year-$month-01"; + $end_date = "$year-$month-" . Date::Calc::Days_in_Month( $year, $month ); + } else { + $start_date = $params->{start_date}; + $end_date = $params->{end_date}; + } - my $previous_month = $start_date; - if ( $previous_month =~ /(\d{4})\-(\d{2})/ ) { - my $year = $1; - my $month = $2 - 1; - $month = '0' . $month if ( length($month) < 2 ); - if ( $month lt '01' ) { - $year -= 1; - $month = '12'; - } - $previous_month = "$year-$month-01"; - $previous_month = $params->{start_date} if ( $previous_month lt $params->{start_date} ); - } + my $previous_month = $start_date; + if ( $previous_month =~ /(\d{4})\-(\d{2})/ ) { + my $year = $1; + my $month = $2 - 1; + $month = '0' . $month if ( length($month) < 2 ); + if ( $month lt '01' ) { + $year -= 1; + $month = '12'; + } + $previous_month = "$year-$month-01"; + $previous_month = $params->{start_date} if ( $previous_month lt $params->{start_date} ); + } - my $next_month = $end_date; - if ( $next_month =~ /(\d{4})\-(\d{2})/ ) { - my $year = $1; - my $month = $2 + 1; - $month = '0' . $month if ( length($month) < 2 ); - if ( $month gt '12' ) { - $year += 1; - $month = '01'; - } - $next_month = "$year-$month-01"; - $next_month = $params->{end_date} if ( $next_month gt $params->{end_date} ); - } + my $next_month = $end_date; + if ( $next_month =~ /(\d{4})\-(\d{2})/ ) { + my $year = $1; + my $month = $2 + 1; + $month = '0' . $month if ( length($month) < 2 ); + if ( $month gt '12' ) { + $year += 1; + $month = '01'; + } + $next_month = "$year-$month-01"; + $next_month = $params->{end_date} if ( $next_month gt $params->{end_date} ); + } - my $start_year = undef; - my $start_month = undef; - if ( $start_date =~ /(\d{4})\-(\d{2})/ ) { - $start_year = $1; - $start_month = $2; - } - my $start_month_name = $time::names->{$language}->{months_abbr}->[ $start_month - 1 ]; + my $start_year = undef; + my $start_month = undef; + if ( $start_date =~ /(\d{4})\-(\d{2})/ ) { + $start_year = $1; + $start_month = $2; + } + my $monthNames=time::getMonthNamesShort($language); + my $start_month_name = $monthNames->[ $start_month - 1 ]; - if ( $params->{month_only} eq '1' ) { - return { - next_month => $next_month, - previous_month => $previous_month, - start_year => $start_year, - start_month => $start_month, - start_month_name => $start_month_name - }; - } + if ( $params->{month_only} eq '1' ) { + return { + next_month => $next_month, + previous_month => $previous_month, + start_year => $start_year, + start_month => $start_month, + start_month_name => $start_month_name + }; + } - my $years = calendar::get_calendar_weeks( $config, $start_date, $end_date ); + my $years = calendar::get_calendar_weeks( $config, $start_date, $end_date ); - my $dbh = db::connect( $config, $request ); + my $dbh = db::connect( $config, $request ); - my $used_days = events::get_by_date_range( - $dbh, $config, - $start_date, - $end_date, - { - exclude_projects => 1, - exclude_locations => 1, - } - ); - my $used_day = {}; - for my $day (@$used_days) { - $used_day->{ $day->{start_date} } = 1; - } + my $used_days = events::get_by_date_range( + $dbh, $config, + $start_date, + $end_date, + { + exclude_projects => 1, + exclude_locations => 1, + } + ); + my $used_day = {}; + for my $day (@$used_days) { + $used_day->{ $day->{start_date} } = 1; + } - for my $year ( sort { $a <=> $b } keys %$years ) { - my $months = $years->{$year}; + for my $year ( sort { $a <=> $b } keys %$years ) { + my $months = $years->{$year}; - for my $month ( sort { $a <=> $b } keys %$months ) { - my $weeks = $months->{$month}; + for my $month ( sort { $a <=> $b } keys %$months ) { + my $weeks = $months->{$month}; - my $weekCounter = 1; - for my $week (@$weeks) { - my $dayResults = []; + my $weekCounter = 1; + for my $week (@$weeks) { + my $dayResults = []; - my $week_end = undef; - my $week_start = undef; + my $week_end = undef; + my $week_start = undef; - my $week_of_year = undef; - my $woy_year = undef; + my $week_of_year = undef; + my $woy_year = undef; - for my $date (@$week) { - my ( $year, $month, $day ) = split( /\-/, $date ); - my $weekday = 0; - my $day_result = undef; + for my $date (@$week) { + my ( $year, $month, $day ) = split( /\-/, $date ); + 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, - date_parameter => 'date=' . $date, - day => $day, - year => $year, - month => $month, - }; - $day_result->{time} = $from_time if defined $from_time; + $day_result = { + date => $date, + date_parameter => 'date=' . $date, + day => $day, + year => $year, + month => $month, + }; + $day_result->{time} = $from_time if defined $from_time; - $day_result->{class} .= ' calcms_today' if $date eq $today; - $day_result->{class} .= ' selected' if defined $used_day->{$date}; - $day_result->{class} .= " week_$weekCounter"; - $day_result->{class} .= " other_month" if ( $weekCounter < 2 ) && ( $day gt "15" ); - $day_result->{class} .= " other_month" if ( $weekCounter > 3 ) && ( $day lt "15" ); - $day_result->{class} =~ s/^\s+//g; + $day_result->{class} .= ' calcms_today' if $date eq $today; + $day_result->{class} .= ' selected' if defined $used_day->{$date}; + $day_result->{class} .= " week_$weekCounter"; + $day_result->{class} .= " other_month" if ( $weekCounter < 2 ) && ( $day gt "15" ); + $day_result->{class} .= " other_month" if ( $weekCounter > 3 ) && ( $day lt "15" ); + $day_result->{class} =~ s/^\s+//g; - $week_start = $day unless defined $week_start; - $week_end = $day; + $week_start = $day unless defined $week_start; + $week_end = $day; - $day_result->{weekday_name} = $weekday_names->[$weekday]; - $day_result->{weekday_short_name} = $weekday_short_names->[$weekday]; - $day_result->{weekday} = $weekday + 1; + $day_result->{weekday_name} = $weekday_names->[$weekday]; + $day_result->{weekday_short_name} = $weekday_short_names->[$weekday]; + $day_result->{weekday} = $weekday + 1; - $dateInfo->{ $day_result->{date} } = $day_result->{weekday} if defined $day_result->{date}; + $dateInfo->{ $day_result->{date} } = $day_result->{weekday} if defined $day_result->{date}; - push @$dayResults, $day_result; - $weekday++; + push @$dayResults, $day_result; + $weekday++; - } #end for days + } #end for days - #week filter - my $start_date = $week->[0]; - my $end_date = $week->[-1]; + #week filter + my $start_date = $week->[0]; + my $end_date = $week->[-1]; - my $week_result = { - from_date => $start_date, - till_date => $end_date, - week_start => $week_start, - week_end => $week_end, - week_month => sprintf( "%2d", $month ), - week_year => $year, - week_of_year => $week_of_year, - }; + my $week_result = { + from_date => $start_date, + till_date => $end_date, + week_start => $week_start, + week_end => $week_end, + week_month => sprintf( "%2d", $month ), + week_year => $year, + week_of_year => $week_of_year, + }; - $week_result->{class} .= ' selected' + $week_result->{class} .= ' selected' if ( ( defined $params->{from_date} ) && ( $start_date eq $params->{from_date} ) ) || ( ( defined $params->{till_date} ) && ( $end_date eq $params->{till_date} ) ); - $week_result->{class} .= " week_$weekCounter"; - $week_result->{class} =~ s/^\s+//g; + $week_result->{class} .= " week_$weekCounter"; + $week_result->{class} =~ s/^\s+//g; - push @$weekResults, $week_result; + push @$weekResults, $week_result; - push @$weekAndDayResults, - { - days => $dayResults, - week => [$week_result] - }; - $weekCounter++; + push @$weekAndDayResults, + { + days => $dayResults, + week => [$week_result] + }; + $weekCounter++; - } #end week + } #end week - } #end month + } #end month - } #end year + } #end year - for my $weekday (@$weekdayResults) { - $weekday->{start_date} = $start_date; - $weekday->{end_date} = $end_date; - } + for my $weekday (@$weekdayResults) { + $weekday->{start_date} = $start_date; + $weekday->{end_date} = $end_date; + } - return { - week_and_days => $weekAndDayResults, - weekdays => $weekdayResults, - weeks => $weekResults, - days => $dateInfo, - next_month => $next_month, - previous_month => $previous_month, - start_date => $start_date, - end_date => $end_date, - start_month_name => $start_month_name, - start_month => $start_month, - start_year => $start_year, - base_url => $config->{locations}->{base_url}, - cache_base_url => $config->{cache}->{base_url}, - controllers => $config->{controllers}, - }; + return { + week_and_days => $weekAndDayResults, + weekdays => $weekdayResults, + weeks => $weekResults, + days => $dateInfo, + next_month => $next_month, + previous_month => $previous_month, + start_date => $start_date, + end_date => $end_date, + start_month_name => $start_month_name, + start_month => $start_month, + start_year => $start_year, + base_url => $config->{locations}->{base_url}, + cache_base_url => $config->{cache}->{base_url}, + controllers => $config->{controllers}, + }; } sub render { - # my $out = $_[0]; - my $config = $_[1]; - my $request = $_[2]; - my $calendar = $_[3]; + # my $out = $_[0]; + my $config = $_[1]; + my $request = $_[2]; + my $calendar = $_[3]; - my $parms = $request->{params}->{checked}; - my $debug = $config->{system}->{debug}; + my $parms = $request->{params}->{checked}; + my $debug = $config->{system}->{debug}; - my $template_parameters = $calendar; - $template_parameters->{debug} = $config->{system}->{debug}; - $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} ); + my $template_parameters = $calendar; + $template_parameters->{debug} = $config->{system}->{debug}; + $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::process( $_[0], $parms->{template}, $template_parameters ); + template::process( $config, $_[0], $parms->{template}, $template_parameters ); } sub get_calendar_weeks { - my $config = shift; - my $start = shift; - my $end = shift; + my $config = shift; + my $start = shift; + my $end = shift; - my $debug = $config->{system}->{debug}; + my $debug = $config->{system}->{debug}; - $start = time::date_to_array($start); - $end = time::date_to_array($end); + $start = time::date_to_array($start); + $end = time::date_to_array($end); - my $start_year = int( $start->[0] ); - my $end_year = int( $end->[0] ); + my $start_year = int( $start->[0] ); + my $end_year = int( $end->[0] ); - my $start_month = int( $start->[1] ); - my $end_month = int( $end->[1] ); + my $start_month = int( $start->[1] ); + my $end_month = int( $end->[1] ); - my $years = {}; - for my $year ( $start_year .. $end_year ) { - my $months = {}; - for my $month ( $start_month .. $end_month ) { + my $years = {}; + for my $year ( $start_year .. $end_year ) { + my $months = {}; + for my $month ( $start_month .. $end_month ) { - #get week arrays of days of the month - my $weeks = getWeeksOfMonth( $year, $month ); - $months->{$month} = $weeks; - } - $years->{$year} = $months; - } - return $years; + #get week arrays of days of the month + my $weeks = getWeeksOfMonth( $year, $month ); + $months->{$month} = $weeks; + } + $years->{$year} = $months; + } + return $years; } sub getWeeksOfMonth { - my $thisYear = shift; - my $thisMonth = shift; - my $thisDay = 1; + my $thisYear = shift; + my $thisMonth = shift; + my $thisDay = 1; - # get weekday of 1st of month - my $thisMonthWeekday = Date::Calc::Day_of_Week( $thisYear, $thisMonth, 1 ); + # get weekday of 1st of month + my $thisMonthWeekday = Date::Calc::Day_of_Week( $thisYear, $thisMonth, 1 ); - # get next month date - my ( $nextYear, $nextMonth, $nextDay ) = Date::Calc::Add_Delta_YM( $thisYear, $thisMonth, $thisDay, 0, 1 ); + # get next month date + my ( $nextYear, $nextMonth, $nextDay ) = Date::Calc::Add_Delta_YM( $thisYear, $thisMonth, $thisDay, 0, 1 ); - # get weekday of 1st of next month - my $nextMonthWeekday = Date::Calc::Day_of_Week( $nextYear, $nextMonth, $nextDay ); - my ( $lastYear, $lastMonth, $lastDayOfMonth ) = Date::Calc::Add_Delta_Days( $nextYear, $nextMonth, $nextDay, -1 ); + # get weekday of 1st of next month + my $nextMonthWeekday = Date::Calc::Day_of_Week( $nextYear, $nextMonth, $nextDay ); + my ( $lastYear, $lastMonth, $lastDayOfMonth ) = Date::Calc::Add_Delta_Days( $nextYear, $nextMonth, $nextDay, -1 ); - # get date of 1st of row - my ( $week, $year ) = Date::Calc::Week_of_Year( $thisYear, $thisMonth, $thisDay ); - ( $year, my $month, my $day ) = Date::Calc::Monday_of_Week( $week, $year ); + # get date of 1st of row + my ( $week, $year ) = Date::Calc::Week_of_Year( $thisYear, $thisMonth, $thisDay ); + ( $year, my $month, my $day ) = Date::Calc::Monday_of_Week( $week, $year ); - my @weeks = (); - my $weekday = 1; + my @weeks = (); + my $weekday = 1; - { - # first week - my @days = (); - for $weekday ( 0 .. $thisMonthWeekday - 2 ) { - push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); - $day++; - } + { + # first week + my @days = (); + for $weekday ( 0 .. $thisMonthWeekday - 2 ) { + push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); + $day++; + } - # set current month - $month = $thisMonth; - $year = $thisYear; - $day = 1; - for $weekday ( $thisMonthWeekday .. 7 ) { - push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); - $day++; - } + # set current month + $month = $thisMonth; + $year = $thisYear; + $day = 1; + for $weekday ( $thisMonthWeekday .. 7 ) { + push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); + $day++; + } - # next week - push @weeks, \@days; - } + # next week + push @weeks, \@days; + } - # weeks until end of month - while ( scalar(@weeks) < 6 ) { - my @days = (); - $weekday = 1; - while ( $weekday <= 7 ) { - push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); - $day++; - $weekday++; - last if $day > $lastDayOfMonth; - } + # weeks until end of month + while ( scalar(@weeks) < 6 ) { + my @days = (); + $weekday = 1; + while ( $weekday <= 7 ) { + push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); + $day++; + $weekday++; + last if $day > $lastDayOfMonth; + } - if ( $day > $lastDayOfMonth ) { + if ( $day > $lastDayOfMonth ) { - # set next month - $month = $nextMonth; - $year = $nextYear; - $day = 1; + # set next month + $month = $nextMonth; + $year = $nextYear; + $day = 1; - if ( $nextMonthWeekday != 1 ) { + if ( $nextMonthWeekday != 1 ) { - # finish end week - if ( $weekday <= 7 ) { - while ( $weekday <= 7 ) { - push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); - $day++; - $weekday++; - } - } - } - push @weeks, \@days; - last; - } - push @weeks, \@days if $weeks[-1]->[-1] ne $days[-1]; - } + # finish end week + if ( $weekday <= 7 ) { + while ( $weekday <= 7 ) { + push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); + $day++; + $weekday++; + } + } + } + push @weeks, \@days; + last; + } + push @weeks, \@days if $weeks[-1]->[-1] ne $days[-1]; + } - #coming weeks - while ( scalar(@weeks) < 6 ) { - my @days = (); - for $weekday ( 1 .. 7 ) { - push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); - $day++; - } - push @weeks, \@days; - } - return \@weeks; + #coming weeks + while ( scalar(@weeks) < 6 ) { + my @days = (); + for $weekday ( 1 .. 7 ) { + push @days, sprintf( "%04d-%02d-%02d", $year, $month, $day ); + $day++; + } + push @weeks, \@days; + } + return \@weeks; } sub configure_cache { - my $config = shift; - my $debug = $config->{system}->{debug}; + my $config = shift; + my $debug = $config->{system}->{debug}; - cache::init(); + cache::init(); - my $date_pattern = $cache::date_pattern; - my $controllers = $config->{controllers}; + 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' ); + 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 { - my $config = shift; - my $params = shift; + my $config = shift; + my $params = shift; - #get start and stop from projects - my $range = project::get_date_range($config); - my $start_date = $range->{start_date}; - my $end_date = $range->{end_date}; + #get start and stop from projects + my $range = project::get_date_range($config); + my $start_date = $range->{start_date}; + my $end_date = $range->{end_date}; - #switch off limiting end date by project - my $open_end = 0; - if ( ( defined $params->{'open_end'} ) && ( $params->{'open_end'} =~ /(\d+)/ ) ) { - $open_end = $1; - $end_date = time::add_days_to_datetime( time::time_to_datetime(), 365 ); - } + #switch off limiting end date by project + my $open_end = 0; + if ( ( defined $params->{'open_end'} ) && ( $params->{'open_end'} =~ /(\d+)/ ) ) { + $open_end = $1; + $end_date = time::add_days_to_datetime( time::time_to_datetime(), 365 ); + } - my $month_only = $params->{month_only} || ''; + my $month_only = $params->{month_only} || ''; - #filter for date - my $date = time::check_date( $params->{date} ); + #filter for date + my $date = time::check_date( $params->{date} ); - $date = $start_date if ( $date lt $start_date ); - $date = $end_date if ( $date gt $end_date ); - log::error( $config, "no valid year-month format given!" ) if ( $date eq "-1" ); + $date = $start_date if ( $date lt $start_date ); + $date = $end_date if ( $date gt $end_date ); + log::error( $config, "no valid year-month format given!" ) if ( $date eq "-1" ); - my $time = time::check_time( $params->{time} ); - log::error( $config, "no valid time format given!" ) if ( $time eq "-1" ); + my $time = time::check_time( $params->{time} ); + log::error( $config, "no valid time format given!" ) if ( $time eq "-1" ); - my $from_date = time::check_date( $params->{from_date} ) || ''; - log::error( $config, "no valid date format given!" ) if ( defined $from_date && $from_date eq "-1" ); - $from_date = $start_date if ( $from_date lt $start_date ); - $from_date = $end_date if ( $from_date gt $end_date ); + my $from_date = time::check_date( $params->{from_date} ) || ''; + log::error( $config, "no valid date format given!" ) if ( defined $from_date && $from_date eq "-1" ); + $from_date = $start_date if ( $from_date lt $start_date ); + $from_date = $end_date if ( $from_date gt $end_date ); - my $till_date = time::check_date( $params->{till_date} || '' ); - log::error( $config, "no valid date format given!" ) if ( defined $till_date && $till_date eq "-1" ); - $till_date = $start_date if ( $till_date lt $start_date ); - $till_date = $end_date if ( $till_date gt $end_date ); + my $till_date = time::check_date( $params->{till_date} || '' ); + log::error( $config, "no valid date format given!" ) if ( defined $till_date && $till_date eq "-1" ); + $till_date = $start_date if ( $till_date lt $start_date ); + $till_date = $end_date if ( $till_date gt $end_date ); - my $template = template::check( $params->{template}, 'calendar.html' ); + my $template = template::check( $config, $params->{template}, 'calendar.html' ); - my $debug = $params->{debug}; - if ( ( defined $debug ) && ( $debug =~ /([a-z\_\,]+)/ ) ) { - $debug = $1; - } + my $debug = $params->{debug}; + if ( ( defined $debug ) && ( $debug =~ /([a-z\_\,]+)/ ) ) { + $debug = $1; + } - return { - template => $template, - date => $date, - from_date => $from_date, - till_date => $till_date, - debug => $debug, - month_only => $month_only, - open_end => $open_end, - start_date => $start_date, - end_date => $end_date - }; + return { + template => $template, + date => $date, + from_date => $from_date, + till_date => $till_date, + debug => $debug, + month_only => $month_only, + open_end => $open_end, + start_date => $start_date, + end_date => $end_date + }; } #do not delete last line! diff --git a/lib/calcms/comments.pm b/lib/calcms/comments.pm index 7cec0d6..11f3153 100644 --- a/lib/calcms/comments.pm +++ b/lib/calcms/comments.pm @@ -1,22 +1,19 @@ +package comments; + use warnings "all"; use strict; use Data::Dumper; + +use db(); use config(); +use markup(); use template(); use time(); -package comments; -use warnings "all"; -use strict; -use Data::Dumper; - -require Exporter; -our @ISA = qw(Exporter); - -#our @EXPORT = qw(all); +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); -our %EXPORT_TAGS = ( 'all' => [@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) + ; sub init { } @@ -188,7 +185,7 @@ sub modify_results { for my $result (@$results) { $result->{allow}->{new_comments} = 1 if ( $params->{allow}->{new_comments} ); - $result->{start_date_name} = time::date_format( $result->{created_at}, $language ); + $result->{start_date_name} = time::date_format( $config, $result->{created_at}, $language ); $result->{start_time_name} = time::time_format( $result->{created_at} ); my $comment_limit = 100; if ( length( $result->{content} ) > $comment_limit ) { @@ -250,7 +247,7 @@ sub render { $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( $_[0], $params->{template}, $template_parameters ); + template::process( $config, $_[0], $params->{template}, $template_parameters ); } #check if comment exists already @@ -614,14 +611,11 @@ sub configure_cache { my $config = shift; cache::init(); - - my $date_pattern = $cache::date_pattern; - my $datetime_pattern = $cache::datetime_pattern; - my $controllers = $config->{controllers}; + 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=' . $datetime_pattern, + cache::add_map( 'template=comments.html&event_id=(\d+)&event_start=' . cache::get_datetime_pattern(), $controllers->{comments} . '/$1_$2-$3-$4_$5-$6.html' ); } @@ -689,7 +683,7 @@ sub check_params { $comment->{allow}->{new_comments} = 1; } - $comment->{template} = template::check( $params->{template}, 'comments.html' ); + $comment->{template} = template::check( $config, $params->{template}, 'comments.html' ); return $comment; } diff --git a/lib/calcms/config.pm b/lib/calcms/config.pm index 6f3a865..e51b65b 100644 --- a/lib/calcms/config.pm +++ b/lib/calcms/config.pm @@ -1,26 +1,32 @@ package config; -require Exporter; -my @ISA = qw(Exporter); -my @EXPORT_OK = qw(get $config); -my %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); +use warnings; +use strict; use Config::General(); -our $modified_at = -999; -our $config = undef; +use base 'Exporter'; +our @EXPORT_OK = qw(get set); + +my $config = undef; + +sub set { + my $value = shift; + $config = $value; + return; +} sub get { - my $filename = shift; - - my $configuration = new Config::General( - -ConfigFile => $filename, - -UTF8 => 1 - ); - $config::config = $configuration->{DefaultConfig}->{config}; - $config::modified_at = $age; + my $filename = shift; - return $config::config; + return $config if defined $config;; + + my $configuration = Config::General->new( + -ConfigFile => $filename, + -UTF8 => 1 + ); + config::set( $configuration->{DefaultConfig}->{config} ); + return $config; } #do not delete last line diff --git a/lib/calcms/creole_wiki.pm b/lib/calcms/creole_wiki.pm index a235fd6..f17fa89 100644 --- a/lib/calcms/creole_wiki.pm +++ b/lib/calcms/creole_wiki.pm @@ -1,14 +1,13 @@ +package creole_wiki; + use warnings; use strict; + use Data::Dumper; use markup(); -package creole_wiki; - -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(extractEventFromWikiText removeMeta eventToWikiText extractMeta removeMeta metaToWiki); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); #convert creole wiki text to event sub extractEventFromWikiText { diff --git a/lib/calcms/db.pm b/lib/calcms/db.pm index ed07f4e..8f3a4bd 100644 --- a/lib/calcms/db.pm +++ b/lib/calcms/db.pm @@ -1,13 +1,12 @@ -use warnings "all"; +package db; + +use warnings 'all'; use strict; use DBD::mysql(); - -package db; use Data::Dumper; -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( connect disconnect get insert put @@ -17,7 +16,6 @@ our @EXPORT_OK = qw( $write $read ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); #debug settings our $debug_read = 0; @@ -29,251 +27,222 @@ our $write = 1; # connect to database sub connect { - my $options = shift; - my $request = shift; + my $options = shift; + my $request = shift; return $request->{connection} if ( defined $request ) && ( defined $request->{connection} ); - my $access_options = $options->{access}; + my $access_options = $options->{access}; - my $hostname = $access_options->{hostname}; - my $port = $access_options->{port}; - my $database = $access_options->{database}; - my $username = $access_options->{username}; - my $password = $access_options->{password}; + my $hostname = $access_options->{hostname}; + my $port = $access_options->{port}; + my $database = $access_options->{database}; + my $username = $access_options->{username}; + my $password = $access_options->{password}; - if ( ( defined $access_options->{write} ) && ( $access_options->{write} eq '1' ) ) { - $username = $access_options->{username_write}; - $password = $access_options->{password_write}; - } + if ( ( defined $access_options->{write} ) && ( $access_options->{write} eq '1' ) ) { + $username = $access_options->{username_write}; + $password = $access_options->{password_write}; + } - my $dbh = undef; - my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; + my $dbh = undef; + my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port"; - # if ($db::utf8dbi eq '1'){ - # use UTF8DBI; - # $dbh = UTF8DBI->connect( $dsn,$username,$password) || die "Database connection not made: $DBI::errstr"; # \nfor $dsn, $username - # }else{ - # use DBI; - $dbh = DBI->connect( $dsn, $username, $password, { mysql_enable_utf8 => 1 } ) - || die "could not connect to database: $DBI::errstr"; # \nfor $dsn, $username + $dbh = DBI->connect( $dsn, $username, $password, { mysql_enable_utf8 => 1 } ) + || die "could not connect to database: $DBI::errstr"; - # } - #print STDERR "db connect $username\n" if ($debug_read==1); - #print STDERR "db connect $username\n"; - $dbh->{RaiseError} = 1; + $dbh->{RaiseError} = 1; - $dbh->{'mysql_enable_utf8'} = 1; - put( $dbh, "set character set utf8" ); - put( $dbh, "set names utf8" ); - put( $dbh, "set time_zone='" . $options->{date}->{time_zone} . "'" ); + $dbh->{'mysql_enable_utf8'} = 1; + put( $dbh, "set character set utf8" ); + put( $dbh, "set names utf8" ); + put( $dbh, "set time_zone='" . $options->{date}->{time_zone} . "'" ); - $request->{connection} = $dbh; - return $dbh; + $request->{connection} = $dbh; + return $dbh; } sub disconnect { - my $request = shift; - my $dbh = $request->{connection}; - $dbh->disconnect; - delete $request->{connection}; + my $request = shift; + my $dbh = $request->{connection}; + $dbh->disconnect; + delete $request->{connection}; + return; } # get all database entries of an sql query (as list of hashs) sub get { - my $dbh = shift; - my $sql = shift; - my $bind_values = shift; + my $dbh = shift; + my $sql = shift; + my $bind_values = shift; - if ( $debug_read == 1 ) { - print STDERR $sql . "\n"; - print STDERR Dumper($bind_values) . "\n" if defined $bind_values; - } + if ( $debug_read == 1 ) { + print STDERR $sql . "\n"; + print STDERR Dumper($bind_values) . "\n" if defined $bind_values; + } - my $sth = $dbh->prepare($sql); - if ( ( defined $bind_values ) && ( ref($bind_values) eq 'ARRAY' ) ) { + my $sth = $dbh->prepare($sql); + if ( ( defined $bind_values ) && ( ref($bind_values) eq 'ARRAY' ) ) { - # print STDERR Dumper($bind_values)."\n"; - my $result = $sth->execute(@$bind_values); - unless ($result) { - print STDERR $sql . "\n"; - die "db: $DBI::errstr $sql" if ( $read == 1 ); - } - } else { - $sth->execute() || die "db: $DBI::errstr $sql" if ( $read == 1 ); - } + # print STDERR Dumper($bind_values)."\n"; + my $result = $sth->execute(@$bind_values); + unless ($result) { + print STDERR $sql . "\n"; + die "db: $DBI::errstr $sql" if ( $read == 1 ); + } + } else { + $sth->execute() || die "db: $DBI::errstr $sql" if ( $read == 1 ); + } - my @results = (); - while ( my $row = $sth->fetchrow_hashref ) { - my $result = {}; - foreach my $key ( keys %$row ) { - $result->{$key} = $row->{$key}; - } - push @results, $result; - } + my @results = (); + while ( my $row = $sth->fetchrow_hashref ) { + my $result = {}; + foreach my $key ( keys %$row ) { + $result->{$key} = $row->{$key}; + } + push @results, $result; + } - if ( $debug_read == 1 ) { - print STDERR Dumper( $results[0] ) . "\n" if ( @results == 1 ); - print STDERR @results . "\n" if ( @results != 1 ); - } + if ( $debug_read == 1 ) { + print STDERR Dumper( $results[0] ) . "\n" if ( @results == 1 ); + print STDERR @results . "\n" if ( @results != 1 ); + } - $sth->finish; - return \@results; + $sth->finish; + return \@results; } # get list of table columns sub get_columns { - my $dbh = shift; - my $table = shift; + my $dbh = shift; + my $table = shift; - my $columns = db::get( $dbh, 'select column_name from information_schema.columns where table_name=?', [$table] ); - my @result = map { $_->{column_name} } (@$columns); - return \@result; + my $columns = db::get( $dbh, 'select column_name from information_schema.columns where table_name=?', [$table] ); + my @result = map { $_->{column_name} } (@$columns); + return \@result; } # get hash with table columns as keys sub get_columns_hash { - my $dbh = shift; - my $table = shift; - - my $columns = db::get_columns( $dbh, $table ); - my $result = {}; - for my $column (@$columns) { - $result->{$column} = 1; - } - return $result; -} - -# insert an entry into database (select from where) -sub insert_old { - my $dbh = shift; - my $tablename = shift; - my $entry = shift; - my $do_not_quote = shift; - - my $keys = join( ",", map { $_ } ( keys %$entry ) ); - my $values = undef; - if ( defined $do_not_quote && $do_not_quote ne '' ) { - $values = join( "\n,", map { $entry->{$_} } ( keys %$entry ) ); - } else { - $values = join( "\n,", map { $dbh->quote( $entry->{$_} ) } ( keys %$entry ) ); - } - my $sql = "insert into $tablename \n ($keys) \n values ($values);\n"; - print STDERR $sql . "\n" if ( $debug_write == 1 ); - put( $dbh, $sql ); + my $dbh = shift; + my $table = shift; + my $columns = db::get_columns( $dbh, $table ); + my $result = {}; + for my $column (@$columns) { + $result->{$column} = 1; + } + return $result; } #returns last inserted id sub insert { - my $dbh = shift; - my $tablename = shift; - my $entry = shift; + my $dbh = shift; + my $tablename = shift; + my $entry = shift; - # my $do_not_quote=shift; + my $keys = join( ",", map { $_ } ( keys %$entry ) ); + my $values = join( ",", map { '?' } ( keys %$entry ) ); + my @bind_values = map { $entry->{$_} } ( keys %$entry ); - my $keys = join( ",", map { $_ } ( keys %$entry ) ); - my $values = join( ",", map { '?' } ( keys %$entry ) ); - my @bind_values = map { $entry->{$_} } ( keys %$entry ); + my $sql = "insert into $tablename \n ($keys) \n values ($values);\n"; - my $sql = "insert into $tablename \n ($keys) \n values ($values);\n"; + if ( $debug_write == 1 ) { + print STDERR $sql . "\n"; + print STDERR Dumper( \@bind_values ) . "\n" if (@bind_values); + } - if ( $debug_write == 1 ) { - print STDERR $sql . "\n"; - print STDERR Dumper( \@bind_values ) . "\n" if (@bind_values); - } - - put( $dbh, $sql, \@bind_values ); - my $result = get( $dbh, 'SELECT LAST_INSERT_ID() id;' ); - return $result->[0]->{id} if $result->[0]->{id} > 0; - return undef; + put( $dbh, $sql, \@bind_values ); + my $result = get( $dbh, 'SELECT LAST_INSERT_ID() id;' ); + return $result->[0]->{id} if $result->[0]->{id} > 0; + return undef; } # execute a modifying database command (update,insert,...) sub put { - my $dbh = shift; - my $sql = shift; - my $bind_values = shift; + my $dbh = shift; + my $sql = shift; + my $bind_values = shift; - if ( $debug_write == 1 ) { - print STDERR $sql . "\n"; - print STDERR Dumper($bind_values) . "\n" if defined $bind_values; - } + if ( $debug_write == 1 ) { + print STDERR $sql . "\n"; + print STDERR Dumper($bind_values) . "\n" if defined $bind_values; + } - my $sth = $dbh->prepare($sql); - if ( $write == 1 ) { - if ( ( defined $bind_values ) && ( ref($bind_values) eq 'ARRAY' ) ) { - $sth->execute(@$bind_values); - } else { - $sth->execute(); - } - } - $sth->finish; - print STDERR "1\n" if ( $debug_write == 1 ); + my $sth = $dbh->prepare($sql); + if ( $write == 1 ) { + if ( ( defined $bind_values ) && ( ref($bind_values) eq 'ARRAY' ) ) { + $sth->execute(@$bind_values); + } else { + $sth->execute(); + } + } + $sth->finish; + print STDERR "1\n" if ( $debug_write == 1 ); - my $result = get( $dbh, 'SELECT ROW_COUNT() changes;' ); - return $result->[0]->{changes} if $result->[0]->{changes} > 0; - return undef; + my $result = get( $dbh, 'SELECT ROW_COUNT() changes;' ); + return $result->[0]->{changes} if $result->[0]->{changes} > 0; + return undef; } sub quote { - my $dbh = shift; - my $sql = shift; + my $dbh = shift; + my $sql = shift; - $sql =~ s/\_/\\\_/g; - return $dbh->quote($sql); + $sql =~ s/\_/\\\_/g; + return $dbh->quote($sql); } #subtract hours, deprecated(!) sub shift_date_by_hours { - my $dbh = shift; - my $date = shift; - my $offset = shift; + my $dbh = shift; + my $date = shift; + my $offset = shift; - my $query = 'select date(? - INTERVAL ? HOUR) date'; - my $bind_values = [ $date, $offset ]; - my $results = db::get( $dbh, $query, $bind_values ); - return $results->[0]->{date}; + my $query = 'select date(? - INTERVAL ? HOUR) date'; + my $bind_values = [ $date, $offset ]; + my $results = db::get( $dbh, $query, $bind_values ); + return $results->[0]->{date}; } #add minutes, deprecated(!) sub shift_datetime_by_minutes { - my $dbh = shift; - my $datetime = shift; - my $offset = shift; + my $dbh = shift; + my $datetime = shift; + my $offset = shift; - my $query = "select ? + INTERVAL ? MINUTE date"; - my $bind_values = [ $datetime, $offset ]; - my $results = db::get( $dbh, $query, $bind_values ); - return $results->[0]->{date}; + my $query = "select ? + INTERVAL ? MINUTE date"; + my $bind_values = [ $datetime, $offset ]; + my $results = db::get( $dbh, $query, $bind_values ); + return $results->[0]->{date}; } # get next free id of a database table sub next_id { - my $dbh = shift; - my $table = shift; + my $dbh = shift; + my $table = shift; - my $query = qq{ + my $query = qq{ select max(id) id from $table where 1 }; - my $results = get( $dbh, $query ); - return $results->[0]->{id} + 1; + my $results = get( $dbh, $query ); + return $results->[0]->{id} + 1; } # get max id from table sub get_max_id { - my $dbh = shift; - my $table = shift; + my $dbh = shift; + my $table = shift; - my $query = qq{ + my $query = qq{ select max(id) id from $table where 1 }; - my $results = get( $dbh, $query ); - return $results->[0]->{id}; + my $results = get( $dbh, $query ); + return $results->[0]->{id}; } #do not delete last line! diff --git a/lib/calcms/eventOps.pm b/lib/calcms/eventOps.pm index aa42ddc..122b2b0 100644 --- a/lib/calcms/eventOps.pm +++ b/lib/calcms/eventOps.pm @@ -11,8 +11,7 @@ use studios(); use series_events(); use user_stats(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( setAttributesFromSeriesTemplate setAttributesFromSchedule @@ -20,7 +19,6 @@ our @EXPORT_OK = qw( setAttributesForCurrentTime getRecurrenceBaseId ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); # functions: to be separated sub setAttributesFromSeriesTemplate { diff --git a/lib/calcms/event_history.pm b/lib/calcms/event_history.pm index 3f4604a..309b571 100644 --- a/lib/calcms/event_history.pm +++ b/lib/calcms/event_history.pm @@ -1,14 +1,12 @@ -#!/bin/perl - package event_history; + use warnings "all"; use strict; + use Data::Dumper; -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get get_by_id insert insert_by_event_id delete); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/events.pm b/lib/calcms/events.pm index 26fdd04..39b1d5d 100644 --- a/lib/calcms/events.pm +++ b/lib/calcms/events.pm @@ -1,6 +1,9 @@ +package events; + use warnings "all"; use strict; +use Data::Dumper; use DBI(); use template(); @@ -10,14 +13,10 @@ use db(); use cache(); use markup(); use log(); +use project(); +use studios(); -package events; -use Data::Dumper; -use project; -use studios; - -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( init get_cached_or_render @@ -34,7 +33,6 @@ our @EXPORT_OK = qw( get_keys add_recordings ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub init { } @@ -535,9 +533,9 @@ sub calc_dates { } $result->{start_date_name} = - time::date_format( $result->{start_date}, $language ); + time::date_format( $config, $result->{start_date}, $language ); $result->{end_date_name} = - time::date_format( $result->{end_date}, $language ); + time::date_format( $config, $result->{end_date}, $language ); if ( $result->{start} =~ /(\d\d\:\d\d)\:\d\d/ ) { $result->{start_time_name} = $1; @@ -550,14 +548,12 @@ sub calc_dates { } if ( defined $result->{weekday} ) { - my $language = $config::config->{date}->{language} || 'en'; + my $language = $config->{date}->{language} || 'en'; - #my $weekdays=time::get_weekdays(); - my $weekday_index = $time::weekday_index->{ $result->{weekday} . '' } || 0; - $result->{weekday_name} = - $time::names->{$language}->{weekdays}->[$weekday_index]; - $result->{weekday_short_name} = - $time::names->{$language}->{weekdays_abbr}->[$weekday_index]; + my $weekdayIndex = time::getWeekdayIndex($result->{weekday}) || 0; + + $result->{weekday_name} = time::getWeekdayNames($language)->[$weekdayIndex]; + $result->{weekday_short_name} = time::getWeekdayNamesShort($language)->[$weekdayIndex]; } return $result; } @@ -1227,7 +1223,7 @@ sub render { if ( defined $config->{permissions}->{hide_event_images} ) && ( $config->{permissions}->{hide_event_images} == 1 ); # use Data::Dumper;print STDERR Dumper($template_parameters)."\n"; - template::process( $_[0], $params->{template}, $template_parameters ); + template::process( $config, $_[0], $params->{template}, $template_parameters ); return $_[0]; } @@ -1464,6 +1460,7 @@ sub get_by_image { return $events->[0]; } +# deleting an event is currently disabled sub delete { return; my $request = shift; @@ -1494,7 +1491,7 @@ sub configure_cache { my $config = shift; my $debug = $config->{system}->{debug}; - my $date_pattern = $cache::date_pattern; + my $date_pattern = cache::get_date_pattern(); my $controllers = $config->{controllers}; cache::init(); @@ -1728,7 +1725,7 @@ sub check_params { if ( ( defined $params->{template} ) && ( $params->{template} eq 'no' ) ) { $template = 'no'; } else { - $template = template::check( $params->{template}, 'event_list.html' ); + $template = template::check( $config, $params->{template}, 'event_list.html' ); } my $limit_config = $config->{permissions}->{result_limit} || 100; diff --git a/lib/calcms/images.pm b/lib/calcms/images.pm index 664442d..5346fe2 100644 --- a/lib/calcms/images.pm +++ b/lib/calcms/images.pm @@ -1,19 +1,14 @@ +package images; + use warnings "all"; use strict; + use config(); use template(); - -package images; -use warnings "all"; -use strict; use Data::Dumper; -require Exporter; -our @ISA = qw(Exporter); - -#our @EXPORT = qw(all); +use base 'Exporter'; our @EXPORT_OK = qw(get insert update insert_or_update delete delete_files); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); #column 'created_at' will be set at insert #column 'modified_at' will be set by default (do not update) diff --git a/lib/calcms/localization.pm b/lib/calcms/localization.pm index b79d029..e2d1dff 100644 --- a/lib/calcms/localization.pm +++ b/lib/calcms/localization.pm @@ -2,14 +2,13 @@ package localization; use warnings "all"; use strict; + use Data::Dumper; use uac(); use user_settings(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get getJavascript); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; @@ -81,6 +80,7 @@ sub read_po_file { my $key = ''; open my $file, '<:encoding(UTF-8)', $po_file; + return $loc unless defined $file; while (<$file>) { my $line = $_; @@ -97,6 +97,7 @@ sub read_po_file { $loc->{$key} = $val; } } + close $file; return $loc; } diff --git a/lib/calcms/log.pm b/lib/calcms/log.pm index 6881425..fa3cf81 100644 --- a/lib/calcms/log.pm +++ b/lib/calcms/log.pm @@ -1,92 +1,89 @@ -use warnings "all"; -use strict; -use template(); -use config(); - package log; +use warnings "all"; +use strict; + +use base 'Exporter'; +our @EXPORT_OK = qw(error load_file save_file append_file); + +use config(); + +#TODO: check if config is given sub error { - my $config = $_[0]; - my $message = "Error: $_[1]\n"; + my $config = $_[0]; + my $message = "Error: $_[1]\n"; - print STDERR $message; - unless ( defined $config ) { - print STDERR "missing config at log::error\n"; - die(); - } + print STDERR $message; + unless ( defined $config ) { + print STDERR "missing config at log::error\n"; + die(); + } - #do not call template::check to avoid deep recursion! - if ( $config::config->{system}->{debug} ) { + #do not call template::check to avoid deep recursion! + if ( $config->{system}->{debug} ) { - template::process( - 'print', - 'templates/default.html', - { - static_files_url => $config::config->{locations}->{static_files_url}, - error => $message - } - ); - } + template::process($config, + 'print', + 'templates/default.html', + { + static_files_url => $config->{locations}->{static_files_url}, + error => $message + } + ); + } - die(); + die(); } -#do not delete last line! -1; - sub load_file { - my $filename = $_[0]; + my $filename = shift; - # my $content=$_[1]; - - # binmode STDOUT, ":utf8"; - my $content = ''; - if ( -e $filename ) { - my $FILE = undef; - open $FILE, "<:utf8", $filename || warn "cant read file '$filename'"; - $content = join "", (<$FILE>); - close $FILE; - return $content; - } + my $content = ''; + if ( -e $filename ) { + my $FILE = undef; + open ($FILE, "<:utf8", $filename) || warn "cant read file '$filename'"; + $content = join "", (<$FILE>); + close $FILE; + return $content; + } } sub save_file { - my $filename = $_[0]; - my $content = $_[1]; + my $filename = shift; + my $content = shift; - #check if directory is writeable - if ( $filename =~ /^(.+?)\/[^\/]+$/ ) { - my $dir = $1; - unless ( -w $dir ) { - print STDERR `pwd;id -a;`; - print STDERR "log::save_file : cannot write to directory ($dir)\n"; - return; - } - } + #check if directory is writeable + if ( $filename =~ /^(.+?)\/[^\/]+$/ ) { + my $dir = $1; + unless ( -w $dir ) { + print STDERR "log::save_file : cannot write to directory ($dir)\n"; + return; + } + } - open my $FILE, ">:utf8", $filename || warn("cant write file '$filename'"); - if ( defined $FILE ) { - print $FILE $content . "\n"; - close $FILE; - } + open my $FILE, ">:utf8", $filename || warn("cant write file '$filename'"); + if ( defined $FILE ) { + print $FILE $content . "\n"; + close $FILE; + } } sub append_file { - my $filename = $_[0]; - my $content = $_[1]; + my $filename = shift; + my $content = shift; - unless ( ( defined $filename ) && ( $filename ne '' ) && ( -e $filename ) ) { - print STDERR "cannot append, file '$filename' does not exist\n"; - return; - } + unless ( ( defined $filename ) && ( $filename ne '' ) && ( -e $filename ) ) { + print STDERR "cannot append, file '$filename' does not exist\n"; + return; + } - if ( defined $content ) { - open my $FILE, ">>:utf8", $filename or warn("cant write file '$filename'"); - print $FILE $content . "\n"; - close $FILE; - } + return unless defined $content; + + open my $FILE, ">>:utf8", $filename or warn("cant write file '$filename'"); + print $FILE $content . "\n"; + close $FILE; } #do not delete last line! -return 1; +1; \ No newline at end of file diff --git a/lib/calcms/mail.pm b/lib/calcms/mail.pm index d89e278..b5c72f4 100644 --- a/lib/calcms/mail.pm +++ b/lib/calcms/mail.pm @@ -1,4 +1,6 @@ package mail; +use warnings; +use strict; use MIME::Lite(); diff --git a/lib/calcms/markup.pm b/lib/calcms/markup.pm index 59dc5cf..553205b 100644 --- a/lib/calcms/markup.pm +++ b/lib/calcms/markup.pm @@ -1,24 +1,18 @@ +package markup; + use warnings "all"; use strict; use Data::Dumper; use Text::WikiCreole(); - use HTML::Parse(); use HTML::FormatText(); +use Encode(); -use log; +use log(); -package markup; - -use Encode; - -require Exporter; -our @ISA = qw(Exporter); - -#our @EXPORT = qw(all); +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); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub fix_line_ends { my $s = shift; diff --git a/lib/calcms/params.pm b/lib/calcms/params.pm index bc296aa..b2ff79e 100644 --- a/lib/calcms/params.pm +++ b/lib/calcms/params.pm @@ -1,14 +1,14 @@ package params; + use warnings "all"; use strict; + use Data::Dumper; use CGI(); use Apache2::Request(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get isJson); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; my $isJson = 0; diff --git a/lib/calcms/password_requests.pm b/lib/calcms/password_requests.pm index ba0c15c..1a70a23 100644 --- a/lib/calcms/password_requests.pm +++ b/lib/calcms/password_requests.pm @@ -7,10 +7,8 @@ use Data::Dumper; use Session::Token(); # table: calcms_password_requests -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get insert delete get_columns); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); use mail; use uac; diff --git a/lib/calcms/playout.pm b/lib/calcms/playout.pm index d08dc5a..71023af 100644 --- a/lib/calcms/playout.pm +++ b/lib/calcms/playout.pm @@ -1,18 +1,16 @@ -#!/bin/perl - package playout; + use warnings "all"; use strict; + use Data::Dumper; use Date::Calc(); use db(); use time(); use series_events(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get sync); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/project.pm b/lib/calcms/project.pm index 4862dbe..4d58c3a 100644 --- a/lib/calcms/project.pm +++ b/lib/calcms/project.pm @@ -1,5 +1,3 @@ -#!/bin/perl - package project; use warnings "all"; @@ -13,8 +11,7 @@ use log(); use template(); use images(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( check get_columns get insert delete get_date_range get_studios assign_studio unassign_studio is_studio_assigned get_studio_assignments @@ -24,8 +21,6 @@ our @EXPORT_OK = qw( #TODO: globally replace get_studios by get_studio_assignments -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); - sub debug; # get project columns @@ -409,7 +404,7 @@ sub get_with_dates { foreach my $project ( reverse sort { $a->{end_date} cmp $b->{end_date} } (@$projects) ) { $project->{months} = get_months( $config, $project, $language ); $project->{user} = $ENV{REMOTE_USER}; - $project->{current} = 1 if ( $project->{name} eq $config::config->{project} ); + $project->{current} = 1 if ( $project->{name} eq $config->{project} ); } return $projects; @@ -451,7 +446,8 @@ sub get_months { $end_day = 1 if ( $end_day < 1 ); $end_day = $last_day if ( $end_day gt $last_day ); - my @months = (); + my $monthNamesShort = time::getMonthNamesShort($language); + my @months = (); for my $year ( $start_year .. $end_year ) { my $m1 = 1; my $m2 = 12; @@ -469,7 +465,7 @@ sub get_months { end => time::array_to_date( $year, $month, $d2 ), year => $year, month => $month, - month_name => $time::names->{$language}->{months_abbr}->[ $month - 1 ], + month_name => $monthNamesShort->[ $month - 1 ], title => $project->{title}, user => $ENV{REMOTE_USER} }; diff --git a/lib/calcms/roles.pm b/lib/calcms/roles.pm index 6a78471..78ce2a5 100644 --- a/lib/calcms/roles.pm +++ b/lib/calcms/roles.pm @@ -1,146 +1,155 @@ package roles; -use Apache2::Reload(); -require Exporter; -my @ISA = qw(Exporter); -my @EXPORT_OK = qw($roles get_user get_user_permissions get_template_parameters); -my %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); +use warnings; +use strict; -our $roles = { - 'admin' => { - access_events => 1, - access_images => 1, - access_comments => 1, - access_sync => 1, - access_system => 1, - read_event_all => 1, - create_event => 1, - delete_event => 1, - update_comment => 1, - create_image => 1, - read_image_own => 1, - read_image_all => 1, - update_image_own => 1, - update_image_all => 1, - delete_image_own => 1, - delete_image_all => 1, - sync_own => 1, - sync_all => 1, - sync_select_range => 1, - upload_playlist => 1, - }, - 'dev' => { - access_events => 1, - access_images => 1, - access_comments => 1, - access_sync => 1, - access_system => 0, - read_event_all => 1, - create_event => 1, - delete_event => 1, - update_comment => 1, - create_image => 1, - read_image_own => 1, - read_image_all => 1, - update_image_own => 1, - update_image_all => 1, - delete_image_own => 1, - delete_image_all => 1, - sync_own => 0, - sync_all => 1, - sync_select_range => 1, - upload_playlist => 1, - }, - 'editor' => { - access_events => 1, - access_images => 1, - access_comments => 1, - access_sync => 1, - access_system => 0, - read_event_all => 0, - create_event => 1, - delete_event => 0, - update_comment => 0, - create_image => 1, - read_image_own => 1, - read_image_all => 1, - update_image_own => 1, - update_image_all => 0, - delete_image_own => 1, - delete_image_all => 0, - sync_own => 1, - sync_all => 0, - sync_select_range => 0, - upload_playlist => 1, - }, - 'nobody' => { - access_events => 0, - access_images => 0, - access_comments => 0, - access_sync => 0, - access_system => 0, - read_event_all => 0, - create_event => 0, - delete_event => 0, - update_comment => 0, - create_image => 0, - read_image_own => 0, - read_image_all => 0, - update_image_own => 0, - update_image_all => 0, - delete_image_own => 0, - delete_image_all => 0, - sync_own => 0, - sync_all => 0, - sync_select_range => 0, - upload_playlist => 0, - } +use Apache2::Reload(); + +use config(); + +use base 'Exporter'; +my @EXPORT_OK = qw(get_user get_user_permissions get_template_parameters get_jobs); + +my $ROLES = { + 'admin' => { + access_events => 1, + access_images => 1, + access_comments => 1, + access_sync => 1, + access_system => 1, + read_event_all => 1, + create_event => 1, + delete_event => 1, + update_comment => 1, + create_image => 1, + read_image_own => 1, + read_image_all => 1, + update_image_own => 1, + update_image_all => 1, + delete_image_own => 1, + delete_image_all => 1, + sync_own => 1, + sync_all => 1, + sync_select_range => 1, + upload_playlist => 1, + }, + 'dev' => { + access_events => 1, + access_images => 1, + access_comments => 1, + access_sync => 1, + access_system => 0, + read_event_all => 1, + create_event => 1, + delete_event => 1, + update_comment => 1, + create_image => 1, + read_image_own => 1, + read_image_all => 1, + update_image_own => 1, + update_image_all => 1, + delete_image_own => 1, + delete_image_all => 1, + sync_own => 0, + sync_all => 1, + sync_select_range => 1, + upload_playlist => 1, + }, + 'editor' => { + access_events => 1, + access_images => 1, + access_comments => 1, + access_sync => 1, + access_system => 0, + read_event_all => 0, + create_event => 1, + delete_event => 0, + update_comment => 0, + create_image => 1, + read_image_own => 1, + read_image_all => 1, + update_image_own => 1, + update_image_all => 0, + delete_image_own => 1, + delete_image_all => 0, + sync_own => 1, + sync_all => 0, + sync_select_range => 0, + upload_playlist => 1, + }, + 'nobody' => { + access_events => 0, + access_images => 0, + access_comments => 0, + access_sync => 0, + access_system => 0, + read_event_all => 0, + create_event => 0, + delete_event => 0, + update_comment => 0, + create_image => 0, + read_image_own => 0, + read_image_all => 0, + update_image_own => 0, + update_image_all => 0, + delete_image_own => 0, + delete_image_all => 0, + sync_own => 0, + sync_all => 0, + sync_select_range => 0, + upload_playlist => 0, + } }; -sub get_user { - my $user = $ENV{REMOTE_USER}; - my $users = $config::config->{users}; - return $user if ( defined $users->{$user} ); - return 'nobody'; +sub get_user($) { + my $config = shift; + my $user = $ENV{REMOTE_USER}; + my $users = $config->{users}; + return $user if ( defined $users->{$user} ); + return 'nobody'; } -sub get_user_permissions { - my $user = $ENV{REMOTE_USER} || ''; - return $roles::roles->{nobody} unless ( $user =~ /\S/ ); - my $users = $config::config->{users}; - if ( defined $users->{$user} ) { - my $role = $users->{$user}; - if ( defined $roles::roles->{$role} ) { - return $roles::roles->{$role}; - } - } - return $roles::roles->{nobody}; +sub get_user_permissions($) { + my $config = shift; + my $user = $ENV{REMOTE_USER} || ''; + my $roles = $roles::ROLES; + return $roles->{nobody} unless $user =~ /\S/; + my $users = $config->{users}; + if ( defined $users->{$user} ) { + my $role = $users->{$user}; + return $roles->{$role} if defined $roles->{$role}; + } + return $roles->{nobody}; } sub get_user_jobs { - my $user = $ENV{REMOTE_USER} || ''; - return [] unless ( $user =~ /\S/ ); - my $result = []; - my $jobs = $config::config->{jobs}->{job}; + my $config = shift; + my $user = $ENV{REMOTE_USER} || ''; + return [] unless ( $user =~ /\S/ ); + my $result = []; + my $jobs = $config->{jobs}->{job}; - for my $job (@$jobs) { - for my $job_user ( split /\,/, $job->{users} ) { - push @$result, $job if ( $user eq $job_user ); - } - } - return $result; + for my $job (@$jobs) { + for my $job_user ( split /\,/, $job->{users} ) { + push @$result, $job if ( $user eq $job_user ); + } + } + return $result; } -sub get_jobs { - return $config::config->{jobs}->{job}; +sub get_jobs($) { + my $config = shift; + return $config->{jobs}->{job}; } -sub get_template_parameters { - my $user_permissions = shift; - $user_permissions = roles::get_user_permissions() unless ( defined $user_permissions ); - my @user_permissions = (); - for my $usecase ( keys %$user_permissions ) { - push @user_permissions, $usecase if ( $user_permissions->{$usecase} eq '1' ); - } - return \@user_permissions; +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 ) { + push @user_permissions, $usecase if $user_permissions->{$usecase} eq '1'; + } + return \@user_permissions; } +return 1; diff --git a/lib/calcms/series.pm b/lib/calcms/series.pm index 06b97f1..6377cd5 100644 --- a/lib/calcms/series.pm +++ b/lib/calcms/series.pm @@ -8,8 +8,7 @@ use Data::Dumper; use events(); use images(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( get_columns get insert update delete get_users add_user remove_user @@ -22,7 +21,6 @@ our @EXPORT_OK = qw( is_series_assigned_to_user is_event_assigned_to_user update_recurring_events update_recurring_event ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); #TODO: remove studio_id #TODO: get project_id, studio_id by join with project_series diff --git a/lib/calcms/series_dates.pm b/lib/calcms/series_dates.pm index dab893f..0370708 100644 --- a/lib/calcms/series_dates.pm +++ b/lib/calcms/series_dates.pm @@ -2,6 +2,7 @@ package series_dates; use warnings "all"; use strict; + use Data::Dumper; use Date::Calc(); use time(); @@ -14,10 +15,8 @@ use series_schedule(); # table: calcms_series_dates # columns: id, studio_id, series_id, start(datetime), end(datetime) # TODO: delete column schedule_id -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete get_dates get_series); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/series_events.pm b/lib/calcms/series_events.pm index 9e303fb..ddf5270 100644 --- a/lib/calcms/series_events.pm +++ b/lib/calcms/series_events.pm @@ -21,8 +21,7 @@ use images(); # check permissions, insert and update events related to series -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( check_permission save_content @@ -31,7 +30,6 @@ our @EXPORT_OK = qw( delete_event set_playout_status ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/series_schedule.pm b/lib/calcms/series_schedule.pm index ecea4ea..2738570 100644 --- a/lib/calcms/series_schedule.pm +++ b/lib/calcms/series_schedule.pm @@ -1,4 +1,5 @@ package series_schedule; + use warnings "all"; use strict; use Data::Dumper; @@ -15,10 +16,8 @@ use series_dates(); # month # nextDay (add 24 hours to start) -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/startup.pl b/lib/calcms/startup.pl index 8daa587..55a6121 100644 --- a/lib/calcms/startup.pl +++ b/lib/calcms/startup.pl @@ -2,7 +2,6 @@ use lib qw(/home/radio/calcms/calcms/); use Data::Dumper; use Apache::DBI(); - #$Apache::DBI::DEBUG = 2; use Time::Local(); diff --git a/lib/calcms/studio_timeslot_dates.pm b/lib/calcms/studio_timeslot_dates.pm index 1f4be4c..82b542d 100644 --- a/lib/calcms/studio_timeslot_dates.pm +++ b/lib/calcms/studio_timeslot_dates.pm @@ -1,6 +1,8 @@ package studio_timeslot_dates; + use warnings "all"; use strict; + use Data::Dumper; use Date::Calc(); use time(); @@ -9,90 +11,88 @@ use time(); # table: calcms_studio_timeslot_dates # columns: id, studio_id, start(datetime), end(datetime) # TODO: delete column schedule_id -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete get_dates); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; sub get_columns { - my $config = shift; + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_dates' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_studio_timeslot_dates' ); + my $columns = {}; + for my $col (@$cols) { + $columns->{$col} = 1; + } + return $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 { - my $config = shift; - my $condition = shift; + 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 ); + 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->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { - push @conditions, 'schedule_id=?'; - push @bind_values, $condition->{schedule_id}; - } + if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { + push @conditions, 'schedule_id=?'; + push @bind_values, $condition->{schedule_id}; + } - # from and till range from an event should beween start and end of the studio's permission - if ( ( defined $condition->{start} ) && ( $condition->{start} ne '' ) ) { - push @conditions, 'start<=?'; - push @bind_values, $condition->{start}; - } + # from and till range from an event should beween start and end of the studio's permission + if ( ( defined $condition->{start} ) && ( $condition->{start} ne '' ) ) { + push @conditions, 'start<=?'; + push @bind_values, $condition->{start}; + } - if ( ( defined $condition->{end} ) && ( $condition->{end} ne '' ) ) { - push @conditions, 'end>=?'; - push @bind_values, $condition->{end}; - } + if ( ( defined $condition->{end} ) && ( $condition->{end} ne '' ) ) { + push @conditions, 'end>=?'; + push @bind_values, $condition->{end}; + } - # check only a given date date range (without time) - 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}; - } - } + # check only a given date date range (without time) + 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 $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 date(start) start_date ,date(end) end_date ,dayname(start) start_weekday @@ -108,351 +108,351 @@ sub get { order by start }; - #print STDERR $query."\n"; - #print STDERR Dumper(\@bind_values); + #print STDERR $query."\n"; + #print STDERR Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); - for my $entry (@$entries) { - $entry->{start_weekday} = substr( $entry->{start_weekday}, 0, 2 ); - $entry->{end_weekday} = substr( $entry->{end_weekday}, 0, 2 ); - } + my $entries = db::get( $dbh, $query, \@bind_values ); + for my $entry (@$entries) { + $entry->{start_weekday} = substr( $entry->{start_weekday}, 0, 2 ); + $entry->{end_weekday} = substr( $entry->{end_weekday}, 0, 2 ); + } - #print STDERR Dumper($entries); - return $entries; + #print STDERR Dumper($entries); + return $entries; } #get all studio_timeslot_schedules for studio_id and update studio_timeslot_dates sub update { - my $config = shift; - my $entry = shift; + my $config = shift; + my $entry = shift; - return undef unless ( defined $entry->{schedule_id} ); + return undef unless ( defined $entry->{schedule_id} ); - my $dbh = db::connect($config); + my $dbh = db::connect($config); - #delete all dates for schedule id - studio_timeslot_dates::delete( $config, $entry ); + #delete all dates for schedule id + studio_timeslot_dates::delete( $config, $entry ); - my $day_start = $config->{date}->{day_starting_hour}; + my $day_start = $config->{date}->{day_starting_hour}; - #get the schedule with schedule id ordered by date - my $schedules = studio_timeslot_schedule::get( - $config, - { - schedule_id => $entry->{schedule_id} - } - ); + #get the schedule with schedule id ordered by date + my $schedules = studio_timeslot_schedule::get( + $config, + { + schedule_id => $entry->{schedule_id} + } + ); - #add scheduled dates - my $i = 0; - my $dates = {}; - for my $schedule (@$schedules) { + #add scheduled dates + my $i = 0; + my $dates = {}; + for my $schedule (@$schedules) { - #calculate dates from start to end_date - my $dateList = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{end_date}, $schedule->{frequency} ); + #calculate dates from start to end_date + my $dateList = get_dates( $schedule->{start}, $schedule->{end}, $schedule->{end_date}, $schedule->{frequency} ); - #print STDERR Dumper($dateList); - for my $date (@$dateList) { + #print STDERR Dumper($dateList); + for my $date (@$dateList) { - #set studio i from - $date->{project_id} = $schedule->{project_id}; - $date->{studio_id} = $schedule->{studio_id}; - $date->{schedule_id} = $schedule->{schedule_id}; - $dates->{ $date->{start} . $date->{studio_id} } = $date; - } - } + #set studio i from + $date->{project_id} = $schedule->{project_id}; + $date->{studio_id} = $schedule->{studio_id}; + $date->{schedule_id} = $schedule->{schedule_id}; + $dates->{ $date->{start} . $date->{studio_id} } = $date; + } + } - for my $date ( keys %$dates ) { - my $timeslot_date = $dates->{$date}; + for my $date ( keys %$dates ) { + my $timeslot_date = $dates->{$date}; - #insert date - my $entry = { - project_id => $timeslot_date->{project_id}, - studio_id => $timeslot_date->{studio_id}, - schedule_id => $timeslot_date->{schedule_id}, - start => $timeslot_date->{start}, - end => $timeslot_date->{end}, - }; - $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); - $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); - db::insert( $dbh, 'calcms_studio_timeslot_dates', $entry ); + #insert date + my $entry = { + project_id => $timeslot_date->{project_id}, + studio_id => $timeslot_date->{studio_id}, + schedule_id => $timeslot_date->{schedule_id}, + start => $timeslot_date->{start}, + end => $timeslot_date->{end}, + }; + $entry->{start_date} = time::add_hours_to_datetime( $entry->{start}, -$day_start ); + $entry->{end_date} = time::add_hours_to_datetime( $entry->{end}, -$day_start ); + db::insert( $dbh, 'calcms_studio_timeslot_dates', $entry ); - #print STDERR "$entry->{start_date}\n"; - $i++; - } + #print STDERR "$entry->{start_date}\n"; + $i++; + } - #print STDERR "$i studio_timeslot_dates updates\n"; - return $i; + #print STDERR "$i studio_timeslot_dates updates\n"; + return $i; } # calculate all start/end datetimes between start_date and stop_date with a frequency(days) # returns list of hashs with start and end sub get_dates { - my $start_datetime = shift; # start - my $end_datetime = shift; # start - my $stop_date = shift; # limit recurring events - my $frequency = shift; # in days + my $start_datetime = shift; # start + my $end_datetime = shift; # start + my $stop_date = shift; # limit recurring events + my $frequency = shift; # in days - my @start = @{ time::datetime_to_array($start_datetime) }; - return unless @start >= 6; - my @start_date = ( $start[0], $start[1], $start[2] ); - my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); - my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] ); + my @start = @{ time::datetime_to_array($start_datetime) }; + return unless @start >= 6; + my @start_date = ( $start[0], $start[1], $start[2] ); + my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); + my $start_time = sprintf( '%02d:%02d:%02d', $start[3], $start[4], $start[5] ); - my @end = @{ time::datetime_to_array($end_datetime) }; - return unless @end >= 6; - my @end_date = ( $end[0], $end[1], $end[2] ); - my $end_date = sprintf( "%04d-%02d-%02d", @end_date ); - my $end_time = sprintf( '%02d:%02d:%02d', $end[3], $end[4], $end[5] ); + my @end = @{ time::datetime_to_array($end_datetime) }; + return unless @end >= 6; + my @end_date = ( $end[0], $end[1], $end[2] ); + my $end_date = sprintf( "%04d-%02d-%02d", @end_date ); + my $end_time = sprintf( '%02d:%02d:%02d', $end[3], $end[4], $end[5] ); - my @stop = @{ time::date_to_array($stop_date) }; - return unless @end >= 3; - my @stop_date = ( $stop[0], $stop[1], $stop[2] ); - $stop_date = sprintf( "%04d-%02d-%02d", @stop_date ); + my @stop = @{ time::date_to_array($stop_date) }; + return unless @end >= 3; + my @stop_date = ( $stop[0], $stop[1], $stop[2] ); + $stop_date = sprintf( "%04d-%02d-%02d", @stop_date ); - my $date = {}; - $date->{start} = $start_date . ' ' . $start_time; - $date->{end} = $end_date . ' ' . $end_time; + my $date = {}; + $date->{start} = $start_date . ' ' . $start_time; + $date->{end} = $end_date . ' ' . $end_time; - my $dates = []; - return $dates if ( $date->{end} le $date->{start} ); + my $dates = []; + return $dates if ( $date->{end} le $date->{start} ); - return $dates if ( $stop_date lt $end_date ); + return $dates if ( $stop_date lt $end_date ); - my $j = Date::Calc::Delta_Days( @start_date, @stop_date ); - return $dates if $j < 0; + my $j = Date::Calc::Delta_Days( @start_date, @stop_date ); + return $dates if $j < 0; - # split full time events into single days - if ( $frequency < 1 ) { + # split full time events into single days + if ( $frequency < 1 ) { - #start day - my @next_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], 1 ); - my $next_date = sprintf( "%04d-%02d-%02d", @next_date ); - push @$dates, - { - start => $start_date . ' ' . $start_time, - end => $next_date . ' 00:00:00', - }; - my $c = 0; - for ( my $i = 1 ; $i < $j ; $i++ ) { - my @start_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i ); - my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); - my @next_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i + 1 ); - my $next_date = sprintf( "%04d-%02d-%02d", @next_date ); - push @$dates, - { - start => $start_date . ' 00:00:00', - end => $next_date . ' 00:00:00', - }; - last if ( $c > 1000 ); - $c++; - } + #start day + my @next_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], 1 ); + my $next_date = sprintf( "%04d-%02d-%02d", @next_date ); + push @$dates, + { + start => $start_date . ' ' . $start_time, + end => $next_date . ' 00:00:00', + }; + my $c = 0; + for ( my $i = 1 ; $i < $j ; $i++ ) { + my @start_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i ); + my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); + my @next_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i + 1 ); + my $next_date = sprintf( "%04d-%02d-%02d", @next_date ); + push @$dates, + { + start => $start_date . ' 00:00:00', + end => $next_date . ' 00:00:00', + }; + last if ( $c > 1000 ); + $c++; + } - #end day - push @$dates, - { - start => $end_date . ' 00:00:00', - end => $end_date . ' ' . $end_time, - } if ( $end_time ne '00:00:00' ); - return $dates; - } + #end day + push @$dates, + { + start => $end_date . ' 00:00:00', + end => $end_date . ' ' . $end_time, + } if ( $end_time ne '00:00:00' ); + return $dates; + } - # multiple time events - my $c = 0; - for ( my $i = 0 ; $i <= $j ; $i += $frequency ) { + # multiple time events + my $c = 0; + for ( my $i = 0 ; $i <= $j ; $i += $frequency ) { - #add frequency to start and end date - my @start_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i ); - my @end_date = Date::Calc::Add_Delta_Days( $end[0], $end[1], $end[2], $i ); + #add frequency to start and end date + my @start_date = Date::Calc::Add_Delta_Days( $start[0], $start[1], $start[2], $i ); + my @end_date = Date::Calc::Add_Delta_Days( $end[0], $end[1], $end[2], $i ); - #print STDERR Dumper(\@start_date); - #print STDERR Dumper(\@end_date); - my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); - my $end_date = sprintf( "%04d-%02d-%02d", @end_date ); - push @$dates, - { - start => $start_date . ' ' . $start_time, - end => $end_date . ' ' . $end_time, - }; - last if ( $c > 1000 ); - $c++; - } - return $dates; + #print STDERR Dumper(\@start_date); + #print STDERR Dumper(\@end_date); + my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); + my $end_date = sprintf( "%04d-%02d-%02d", @end_date ); + push @$dates, + { + start => $start_date . ' ' . $start_time, + end => $end_date . ' ' . $end_time, + }; + last if ( $c > 1000 ); + $c++; + } + return $dates; } #remove all studio_timeslot_dates for studio_id and schedule_id sub delete { - my $config = shift; - my $entry = shift; + my $config = shift; + my $entry = shift; - #print STDERR "delete:".Dumper($entry); - return unless ( defined $entry->{project_id} ); - return unless ( defined $entry->{studio_id} ); - return unless ( defined $entry->{schedule_id} ); + #print STDERR "delete:".Dumper($entry); + return unless ( defined $entry->{project_id} ); + return unless ( defined $entry->{studio_id} ); + return unless ( defined $entry->{schedule_id} ); - my $dbh = db::connect($config); + my $dbh = db::connect($config); - my $query = qq{ + my $query = qq{ delete from calcms_studio_timeslot_dates where schedule_id=? }; - my $bind_values = [ $entry->{schedule_id} ]; + my $bind_values = [ $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 ); } # time based filter to check if studio is assigned to an studio at a given time range # return 1 if there is a schedule date starting before start and ending after end sub can_studio_edit_events { - my $config = shift; - my $condition = shift; + my $config = shift; + my $condition = shift; - my @conditions = (); - my @bind_values = (); + my @conditions = (); + my @bind_values = (); - #print Dumper($condition); + #print Dumper($condition); - #return 0 unless defined $condition->{project_id}; - return 0 unless defined $condition->{studio_id}; - return 0 unless defined $condition->{start}; - return 0 unless defined $condition->{end}; + #return 0 unless defined $condition->{project_id}; + return 0 unless defined $condition->{studio_id}; + return 0 unless defined $condition->{start}; + return 0 unless defined $condition->{end}; - 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} ) && ( $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->{end} ) && ( $condition->{end} ne '' ) ) { - push @conditions, 'end>=?'; - push @bind_values, $condition->{end}; - } + if ( ( defined $condition->{end} ) && ( $condition->{end} ne '' ) ) { + push @conditions, 'end>=?'; + push @bind_values, $condition->{end}; + } - my $conditions = ''; - $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); + my $conditions = ''; + $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); - my $dbh = db::connect($config); - my $query = qq{ + my $dbh = db::connect($config); + my $query = qq{ select count(*) permission from calcms_studio_timeslot_dates $conditions }; - #print STDERR Dumper($query).Dumper(\@bind_values); + #print STDERR Dumper($query).Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); + my $entries = db::get( $dbh, $query, \@bind_values ); - #print STDERR Dumper($entries); - return 0 if scalar(@$entries) == 0; - return 1 if $entries->[0]->{permission} > 0; + #print STDERR Dumper($entries); + return 0 if scalar(@$entries) == 0; + return 1 if $entries->[0]->{permission} > 0; - if ( $entries->[0]->{permission} == 0 ) { - my $timeslot = getMergedDays( $config, $condition ); - return 0 unless defined $timeslot; - if ( ( $condition->{start} ge $timeslot->{start} ) - && ( $condition->{end} le $timeslot->{end} ) ) - { - #print STDERR "($condition->{start} ge $timeslot->{start}) ".($condition->{start} ge $timeslot->{start}); - #print STDERR "($condition->{end} le $timeslot->{end}) ".($condition->{end} le $timeslot->{end}); - return 1; - } - } - return 0; + if ( $entries->[0]->{permission} == 0 ) { + my $timeslot = getMergedDays( $config, $condition ); + return 0 unless defined $timeslot; + if ( ( $condition->{start} ge $timeslot->{start} ) + && ( $condition->{end} le $timeslot->{end} ) ) + { + #print STDERR "($condition->{start} ge $timeslot->{start}) ".($condition->{start} ge $timeslot->{start}); + #print STDERR "($condition->{end} le $timeslot->{end}) ".($condition->{end} le $timeslot->{end}); + return 1; + } + } + return 0; } # merge two subsequent days if first day ends at same time as next day starts # returns hashref with start and end of merged slot # returns undef if not slot could be found sub getMergedDays { - my $config = shift; - my $condition = shift; + my $config = shift; + my $condition = shift; - my @conditions = (); - my @bind_values = (); + my @conditions = (); + my @bind_values = (); - #print Dumper($condition); + #print Dumper($condition); - #return 0 unless defined $condition->{project_id}; - return 0 unless defined $condition->{studio_id}; - return 0 unless defined $condition->{start}; - return 0 unless defined $condition->{end}; + #return 0 unless defined $condition->{project_id}; + return 0 unless defined $condition->{studio_id}; + return 0 unless defined $condition->{start}; + return 0 unless defined $condition->{end}; - 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}; + } - # set start to next day at 00:00 - my $start = undef; - if ( $condition->{start} =~ /(\d\d\d\d\-\d\d\-\d\d)/ ) { - $start = $1 . ' 00:00'; - $start = time::add_days_to_datetime( $start, 1 ); - push @bind_values, $start; - } + # set start to next day at 00:00 + my $start = undef; + if ( $condition->{start} =~ /(\d\d\d\d\-\d\d\-\d\d)/ ) { + $start = $1 . ' 00:00'; + $start = time::add_days_to_datetime( $start, 1 ); + push @bind_values, $start; + } - # set end to end days at 00:00 - my $end = undef; - if ( $condition->{end} =~ /(\d\d\d\d\-\d\d\-\d\d)/ ) { - $end = $1 . ' 00:00'; - push @bind_values, $end; - } - return undef unless defined $start; - return undef unless defined $end; + # set end to end days at 00:00 + my $end = undef; + if ( $condition->{end} =~ /(\d\d\d\d\-\d\d\-\d\d)/ ) { + $end = $1 . ' 00:00'; + push @bind_values, $end; + } + return undef unless defined $start; + return undef unless defined $end; - push @conditions, '(start=? or end=?)'; + push @conditions, '(start=? or end=?)'; - my $conditions = ''; - $conditions = 'where ' . join( " and ", @conditions ) if ( @conditions > 0 ); + my $conditions = ''; + $conditions = 'where ' . join( " and ", @conditions ) if ( @conditions > 0 ); - # get all days starting on first day or ending at next day - my $dbh = db::connect($config); - my $query = qq{ + # get all days starting on first day or ending at next day + my $dbh = db::connect($config); + my $query = qq{ select start, end from calcms_studio_timeslot_dates $conditions order by start }; - # print STDERR Dumper($query).Dumper(\@bind_values); + # print STDERR Dumper($query).Dumper(\@bind_values); - my $entries = db::get( $dbh, $query, \@bind_values ); + my $entries = db::get( $dbh, $query, \@bind_values ); - # print STDERR Dumper($entries); + # print STDERR Dumper($entries); - if ( scalar(@$entries) == 2 ) { - if ( $entries->[0]->{end} eq $entries->[1]->{start} ) { - $entries = { - start => $entries->[0]->{start}, - end => $entries->[1]->{end} - }; + if ( scalar(@$entries) == 2 ) { + if ( $entries->[0]->{end} eq $entries->[1]->{start} ) { + $entries = { + start => $entries->[0]->{start}, + end => $entries->[1]->{end} + }; - # print STDERR "found".Dumper($entries)."\n"; - return $entries; - } - } + # print STDERR "found".Dumper($entries)."\n"; + return $entries; + } + } - return undef; + return undef; } sub error { - my $msg = shift; - print "ERROR: $msg
\n"; + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/lib/calcms/studio_timeslot_schedule.pm b/lib/calcms/studio_timeslot_schedule.pm index 8d64929..9f45da7 100644 --- a/lib/calcms/studio_timeslot_schedule.pm +++ b/lib/calcms/studio_timeslot_schedule.pm @@ -1,16 +1,16 @@ package studio_timeslot_schedule; + use warnings "all"; use strict; + use Data::Dumper; use studio_timeslot_dates(); # table: calcms_studio_timeslot_schedule # columns: id, project_id, studio_id, start(datetime), end(datetime), end_date(date), # frequency(days), duration(minutes), create_events(days), publish_events(days) -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/studios.pm b/lib/calcms/studios.pm index f9efaac..475ecee 100644 --- a/lib/calcms/studios.pm +++ b/lib/calcms/studios.pm @@ -1,17 +1,13 @@ -#!/bin/perl - package studios; + use warnings "all"; use strict; use Data::Dumper; - use images(); -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(get_columns get get_by_id insert update delete check check_studio); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); +use base 'Exporter'; +our @EXPORT_OK = qw(get_columns get get_by_id insert update delete check check_studio); sub debug; @@ -69,7 +65,8 @@ sub get { push @conditions, 'ps.project_id=?'; push @bind_values, $condition->{project_id}; - my $conditions = " where " . join( " and ", @conditions ) if ( @conditions > 0 ); + my $conditions = ''; + $condition .= " where " . join( " and ", @conditions ) if ( scalar @conditions > 0 ); $query = qq{ select * from calcms_studios s, calcms_project_studios ps diff --git a/lib/calcms/tags.pm b/lib/calcms/tags.pm index 28b8b56..65aafb3 100644 --- a/lib/calcms/tags.pm +++ b/lib/calcms/tags.pm @@ -1,23 +1,21 @@ +package tags; + use warnings "all"; use strict; use Data::Dumper; -package tags; +use base 'Exporter'; +our @EXPORT_OK = qw(get_tags); -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(get_tags); -our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] ); - -sub get_tags{ - my $dbh=shift; - my $query=qq{ +sub get_tags { + my $dbh = shift; + my $query = qq{ select name, count(name) sum from calcms_tags group by name order by sum desc }; - my $tags=db::get($dbh,$query); - return $tags; + my $tags = db::get( $dbh, $query ); + return $tags; } #do not delete last line! diff --git a/lib/calcms/template.pm b/lib/calcms/template.pm index 35d1061..af3a68b 100644 --- a/lib/calcms/template.pm +++ b/lib/calcms/template.pm @@ -1,7 +1,8 @@ +package template; + use warnings "all"; use strict; -package template; use Data::Dumper; use HTML::Template::Compiled(); use HTML::Template::Compiled::Plugin::XMLEscape(); @@ -14,22 +15,20 @@ use project(); use log(); use roles(); -require Exporter; -our @ISA = qw(Exporter); - -#our @EXPORT = qw(all); +use base 'Exporter'; our @EXPORT_OK = qw(check process exit_on_missing_permission clear_cache); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); +# TODO:config sub process { + my $config = $_[0]; - # my $output=$_[0]; - my $filename = $_[1]; - my $params = $_[2]; + # my $output=$_[1]; + my $filename = $_[2]; + my $params = $_[3]; - my $config = $config::config; - for my $key ( keys %{ $config::config->{locations} } ) { - $params->{$key} = $config::config->{locations}->{$key} if ( $key =~ /\_url$/ ); + #TODO: get config + for my $key ( keys %{ $config->{locations} } ) { + $params->{$key} = $config->{locations}->{$key} if ( $key =~ /\_url$/ ); } # add current project @@ -45,22 +44,22 @@ sub process { $params->{user} = $ENV{REMOTE_USER} unless defined $params->{user}; - my $user_permissions = roles::get_user_permissions(); + 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->{jobs} = roles::get_user_jobs(); + $params->{jobs} = roles::get_user_jobs($config); if ( ( $filename =~ /json\-p/ ) || (params::isJson) ) { my $header = "Content-type:application/json; charset=utf-8\n\n"; my $json = JSON::to_json( $params, { pretty => 1 } ); # $json=$header.$params->{json_callback}.'['.$json.']'; $json = $header . $params->{json_callback} . $json; - if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) { + if ( ( defined $_[1] ) && ( $_[1] eq 'print' ) ) { print $json. "\n"; } else { - $_[0] = $json . "\n"; + $_[1] = $json . "\n"; } return; } @@ -107,10 +106,10 @@ sub process { # HTML::Template::Compiled->preload($cache_dir); $html_template->param($params); - if ( ( defined $_[0] ) && ( $_[0] eq 'print' ) ) { + if ( ( defined $_[1] ) && ( $_[1] eq 'print' ) ) { print $html_template->output; } else { - $_[0] = $html_template->output; + $_[1] = $html_template->output; } } @@ -162,9 +161,11 @@ sub setRelativeUrls { } #requires read config +#TODO:add config sub check { + my $config = shift; my $template = shift || ''; - my $default = shift; + my $default = shift; if ( $template =~ /json\-p/ ) { $template =~ s/[^a-zA-Z0-9\-\_\.]//g; @@ -172,7 +173,6 @@ sub check { return $template; } - my $config = $config::config; if ( $template eq '' ) { $template = $default; } else { @@ -185,12 +185,12 @@ sub check { log::error( $config, 'invalid template!' ) if ( $template =~ /\.\./ ); } - #print STDERR $config::config->{cache}->{compress}."<.compres default:$template\n"; + #print STDERR $config->{cache}->{compress}."<.compres default:$template\n"; $template = ( split( /\//, $template ) )[-1]; my $cwd = Cwd::getcwd(); $template .= '.html' unless ( $template =~ /\./ ); - if ( ( $config::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; @@ -205,14 +205,13 @@ sub check { #deprecated (for old admin only) sub exit_on_missing_permission { + my $config = shift; my $permission = shift; - my $user_permissions = roles::get_user_permissions(); + my $user_permissions = roles::get_user_permissions($config); if ( $user_permissions->{$permission} ne '1' ) { print STDERR "missing permission to $permission\n"; - template::process( 'print', template::check('default.html'), { error => 'sorry, missing permission!' } ); + template::process( $config, 'print', template::check( $config, 'default.html' ), { error => 'sorry, missing permission!' } ); die(); - - #exit; } } diff --git a/lib/calcms/time.pm b/lib/calcms/time.pm index 04b8394..512928d 100644 --- a/lib/calcms/time.pm +++ b/lib/calcms/time.pm @@ -1,19 +1,19 @@ +package time; + use warnings "all"; use strict; +use utf8; + use Time::Local(); use DateTime(); use Date::Calc(); use Date::Manip(); use POSIX qw(strftime); +use Data::Dumper; use config(); -package time; -use Data::Dumper; -use utf8; - -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( format_datetime format_time date_format time_format @@ -25,13 +25,10 @@ our @EXPORT_OK = qw( date_cond time_cond check_date check_time check_datetime check_year_month datetime_to_rfc822 get_datetime datetime_to_utc datetime_to_utc_datetime get_duration get_duration_seconds - get_durations get_names get_all_names weekday_index - $names + getDurations getWeekdayIndex getWeekdayNames getWeekdayNamesShort getMonthNames getMonthNamesShort ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); - -our $names = { +my $NAMES = { 'de' => { months => [ 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember' ], @@ -48,26 +45,9 @@ our $names = { }, }; -our $durations = [ - 0, 5, 10, 15, 20, 30, 40, 45, 50, 60, 70, 75, 80, 90, 100, 105, 110, 115, - 120, 135, 150, 165, 180, 195, 210, 225, 240, 300, 360, 420, 480, 540, 600, 660, 720, 1440 -]; -sub get_names { - my $language = shift || 'en'; - return $time::names->{$language}; -} - -sub get_all_names { - return $time::names; -} - -sub get_durations { - return $time::durations; -} - -#TODO: build from datenames -our $weekday_index = { +# map starting with monday=0 +my $WEEKDAY_INDEX = { '0' => 0, '1' => 1, '2' => 2, @@ -88,7 +68,43 @@ our $weekday_index = { 'So' => 6 }; -sub get_weekdays { +my $DURATIONS = [ + 0, 5, 10, 15, 20, 30, 40, 45, 50, 60, 70, 75, 80, 90, 100, 105, 110, 115, + 120, 135, 150, 165, 180, 195, 210, 225, 240, 300, 360, 420, 480, 540, 600, 660, 720, 1440 +]; + +sub getDurations { + return $DURATIONS; +} + +sub getWeekdayNames { + my $language = shift || 'en'; + return $NAMES->{$language}->{weekdays}; +} + +sub getWeekdayNamesShort { + my $language = shift || 'en'; + return $NAMES->{$language}->{weekdays_abbr}; +} + +sub getMonthNames { + my $language = shift || 'en'; + return $NAMES->{$language}->{months}; +} + +sub getMonthNamesShort { + my $language = shift || 'en'; + return $NAMES->{$language}->{months_abbr}; +} + + +sub getWeekdayIndex($) { + my $weekday = shift || ''; + return $WEEKDAY_INDEX->{$weekday}; +} + +# map starting with monday=1 +sub getWeekdays { return { 1 => 1, 2 => 2, @@ -150,10 +166,11 @@ sub datetime_to_time { my $hour = $4; my $minute = $5; my $second = $8 || 0; - return Time::Local::timelocal( $second, $minute, $hour, $day, $month, $year ); + 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"; + print STDERR "datetime_to_time: no valid date time found! ($datetime)\n"; return -1; } } @@ -475,15 +492,16 @@ sub check_year_month { #TODO: remove config dependency sub date_time_format { + my $config = shift; my $datetime = shift; - my $language = shift || $config::config->{date}->{language} || 'en'; + my $language = shift || $config->{date}->{language} || 'en'; if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)[\sT](\d\d?\:\d\d?)/ ) { my $time = $4; my $day = $3; my $month = $2; my $year = $1; - $month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || ''; + $month = time::getMonthNamesShort($language)->[ $month - 1 ] || ''; return "$day. $month $year $time"; } return $datetime; @@ -492,14 +510,15 @@ sub date_time_format { #format datetime to date string #TODO: remove config dependency sub date_format { + my $config = shift; my $datetime = shift; - my $language = shift || $config::config->{date}->{language} || 'en'; + my $language = shift || $config->{date}->{language} || 'en'; if ( defined $datetime && $datetime =~ /(\d\d\d\d)\-(\d\d?)\-(\d\d?)/ ) { my $day = $3; my $month = $2; my $year = $1; - $month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || ''; + $month = time::getMonthNamesShort($language)->[ $month - 1 ] || ''; return "$day. $month $year"; } return $datetime; @@ -518,9 +537,9 @@ sub time_format { sub utc_offset { my $time_zone = shift; - $a = DateTime->now(); - $a->set_time_zone($time_zone); - return $a->strftime("%z"); + my $datetime = DateTime->now(); + $datetime->set_time_zone($time_zone); + return $datetime->strftime("%z"); } #get weekday from (yyyy,mm,dd) @@ -534,7 +553,6 @@ sub weekday { #TODO: remove config dependency sub get_event_date { my $config = shift; - $config = $config::config unless defined $config; my $datetime = time::time_to_datetime( time() ); my $hour = ( time::datetime_to_array($datetime) )->[3]; @@ -592,7 +610,7 @@ sub get_nth_weekday_in_month { return [] unless defined $nth; return [] unless defined $weekday; - my $weekdays = time::get_weekdays(); + my $weekdays = time::getWeekdays(); return [] unless defined $weekdays->{$weekday}; $weekday = $weekdays->{$weekday}; diff --git a/lib/calcms/uac.pm b/lib/calcms/uac.pm index f203092..741814d 100644 --- a/lib/calcms/uac.pm +++ b/lib/calcms/uac.pm @@ -1,10 +1,10 @@ -use CGI(); -use CGI::Session qw(-ip-match); -use CGI::Cookie(); - package uac; use warnings "all"; use strict; + +use CGI(); +use CGI::Session qw(-ip-match); +use CGI::Cookie(); use Data::Dumper; use auth(); use db(); @@ -12,8 +12,7 @@ use template(); use project(); use studios(); -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw( get_user get_users update_user insert_user delete_user get_roles insert_role update_role get_role_columns @@ -25,7 +24,6 @@ our @EXPORT_OK = qw( prepare_request set_template_permissions permission_denied ); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/user_settings.pm b/lib/calcms/user_settings.pm index 5b0aa68..964648f 100644 --- a/lib/calcms/user_settings.pm +++ b/lib/calcms/user_settings.pm @@ -1,15 +1,15 @@ package user_settings; + use warnings "all"; use strict; + use Data::Dumper; use series_dates(); # table: calcms_user_settings # columns: user, colors -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(getColors getColorCss get insert update delete get_columns defaultColors); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/user_stats.pm b/lib/calcms/user_stats.pm index 8aace0d..6469417 100644 --- a/lib/calcms/user_stats.pm +++ b/lib/calcms/user_stats.pm @@ -1,14 +1,11 @@ -#!/bin/perl - package user_stats; + use warnings "all"; use strict; use Data::Dumper; -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get update insert get_stats increase); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/work_dates.pm b/lib/calcms/work_dates.pm index 91e0132..42b7471 100644 --- a/lib/calcms/work_dates.pm +++ b/lib/calcms/work_dates.pm @@ -2,6 +2,7 @@ package work_dates; use warnings "all"; use strict; + use Data::Dumper; use Date::Calc(); use time(); @@ -14,10 +15,8 @@ use work_schedule(); # table: calcms_work_dates # columns: id, studio_id, schedule_id, start(datetime), end(datetime) # TODO: delete column schedule_id -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete get_dates); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; diff --git a/lib/calcms/work_schedule.pm b/lib/calcms/work_schedule.pm index b14d2ac..562bc8b 100644 --- a/lib/calcms/work_schedule.pm +++ b/lib/calcms/work_schedule.pm @@ -1,6 +1,8 @@ package work_schedule; + use warnings "all"; use strict; + use Data::Dumper; use series_dates(); @@ -14,144 +16,142 @@ use series_dates(); # week_of_month (1..5) # month -require Exporter; -our @ISA = qw(Exporter); +use base 'Exporter'; our @EXPORT_OK = qw(get_columns get insert update delete); -our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] ); sub debug; sub get_columns { - my $config = shift; + my $config = shift; - my $dbh = db::connect($config); - my $cols = db::get_columns( $dbh, 'calcms_work_schedule' ); - my $columns = {}; - for my $col (@$cols) { - $columns->{$col} = 1; - } - return $columns; + my $dbh = db::connect($config); + my $cols = db::get_columns( $dbh, 'calcms_work_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; + 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->{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->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { - push @conditions, 'schedule_id=?'; - push @bind_values, $condition->{schedule_id}; - } + if ( ( defined $condition->{schedule_id} ) && ( $condition->{schedule_id} ne '' ) ) { + push @conditions, 'schedule_id=?'; + push @bind_values, $condition->{schedule_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_work_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 ); - return $entries; + my $entries = db::get( $dbh, $query, \@bind_values ); + return $entries; } sub insert { - my $config = shift; - my $entry = shift; + 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->{start}; - my $dbh = db::connect($config); - return db::insert( $dbh, 'calcms_work_schedule', $entry ); + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_id}; + return undef unless defined $entry->{start}; + my $dbh = db::connect($config); + return db::insert( $dbh, 'calcms_work_schedule', $entry ); } #schedule id to id sub update { - my $config = shift; - my $entry = shift; + 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->{schedule_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->{schedule_id}; + return undef unless defined $entry->{start}; - 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->{schedule_id}; + push @bind_values, $entry->{project_id}; + push @bind_values, $entry->{studio_id}; + push @bind_values, $entry->{schedule_id}; - my $query = qq{ + my $query = qq{ update calcms_work_schedule set $values where project_id=? and studio_id=? and schedule_id=? }; - return db::put( $dbh, $query, \@bind_values ); - print "done\n"; + return db::put( $dbh, $query, \@bind_values ); + print "done\n"; } #map schedule id to id sub delete { - my $config = shift; - my $entry = shift; + 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->{schedule_id}; + return undef unless defined $entry->{project_id}; + return undef unless defined $entry->{studio_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_work_schedule where project_id=? and studio_id=? and schedule_id=? }; - my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{schedule_id} ]; + my $bind_values = [ $entry->{project_id}, $entry->{studio_id}, $entry->{schedule_id} ]; - #print '
$query'.$query.Dumper($bind_values).'
'; - return db::put( $dbh, $query, $bind_values ); + #print '
$query'.$query.Dumper($bind_values).'
'; + return db::put( $dbh, $query, $bind_values ); } sub error { - my $msg = shift; - print "ERROR: $msg
\n"; + my $msg = shift; + print "ERROR: $msg
\n"; } #do not delete last line! diff --git a/website/agenda/add_comment.cgi b/website/agenda/add_comment.cgi index d30760f..66ca5f3 100755 --- a/website/agenda/add_comment.cgi +++ b/website/agenda/add_comment.cgi @@ -26,8 +26,6 @@ my $r=shift; my $config = config::get('./config/config.cgi'); my $debug = $config->{system}->{debug}; -$cache::debug=$debug; - my $request={ url => $ENV{QUERY_STRING}, params => { @@ -174,7 +172,7 @@ sub check_params{ my $config=shift; my $params=shift; - my $template=template::check($params->{'template'}, 'comments.html'); + my $template = template::check($config, $params->{'template'}, 'comments.html' ); my $comment={}; diff --git a/website/agenda/aggregate.cgi b/website/agenda/aggregate.cgi index 9e55dac..993c1cf 100755 --- a/website/agenda/aggregate.cgi +++ b/website/agenda/aggregate.cgi @@ -3,15 +3,8 @@ use warnings "all"; use strict; -#use Data::Dumper; - -#use DBI; use CGI qw(header param Vars); -#use Time::Local qw(timelocal); -#use Benchmark; -#use Devel::Profiler; - use db(); use events(); use time(); @@ -20,9 +13,6 @@ use markup(); use log(); use config(); -#use params; -#my $r=shift; - if ( $0 =~ /aggregate.*?\.cgi$/ ) { binmode STDOUT, ":encoding(UTF-8)"; diff --git a/website/agenda/category.cgi b/website/agenda/category.cgi index 9f16fa6..18b64b5 100755 --- a/website/agenda/category.cgi +++ b/website/agenda/category.cgi @@ -56,7 +56,7 @@ $template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} my $template = $params->{template}; my $out = ''; -template::process( $out, $params->{template}, $template_parameters ); +template::process($config, $out, $params->{template}, $template_parameters ); print $out; #write to cache @@ -127,7 +127,7 @@ sub check_params { my $config = $_[0]; my $params = $_[1]; - my $template = template::check( $params->{template}, 'categories.html' ); + my $template = template::check($config, $params->{template}, 'categories.html' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/events.cgi b/website/agenda/events.cgi index d3d2eb9..ce48a22 100755 --- a/website/agenda/events.cgi +++ b/website/agenda/events.cgi @@ -23,7 +23,6 @@ binmode STDOUT, ":encoding(UTF-8)"; my $r = shift; ( my $cgi, my $params, my $error ) = params::get($r); - if ( $0 =~ /events.*?\.cgi$/ ) { #my $cgi=new CGI(); diff --git a/website/agenda/planung/assign_series.cgi b/website/agenda/planung/assign_series.cgi index 406b813..0b34f3c 100755 --- a/website/agenda/planung/assign_series.cgi +++ b/website/agenda/planung/assign_series.cgi @@ -63,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( 'print', template::check('default.html'), $headerParams ); +template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -142,7 +142,7 @@ sub show_events { $params->{project_name} = $project_name; $params->{studio_name} = $studio_name; - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub assign_series { @@ -201,6 +201,7 @@ sub assign_series { $config->{access}->{write} = 0; uac::print_info("event successfully assigned to series"); + return; } sub check_params { @@ -236,7 +237,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $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 73d8ccf..35e773c 100755 --- a/website/agenda/planung/assignments.cgi +++ b/website/agenda/planung/assignments.cgi @@ -1,4 +1,4 @@ -#! /usr/bin/perl -w +#! /usr/bin/perl -w use warnings "all"; use strict; @@ -64,7 +64,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( 'print', template::check('default.html'), $headerParams ); +template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -167,6 +167,7 @@ sub show_events { $results = db::get( $dbh, $query, $bind_values ); # detect title and episode + my $weekdayNamesShort = time::getWeekdayNamesShort('de'); for my $result (@$results) { $result->{rerun} .= ''; if ( $result->{title} =~ /\#(\d+)([a-z])?\s*$/ ) { @@ -179,7 +180,7 @@ sub show_events { #print STDERR "($a->[0],$a->[1],$a->[2])\n"; $result->{weekday} = time::weekday( $a->[0], $a->[1], $a->[2] ); - $result->{weekday} = $time::names->{de}->{weekdays_abbr}->[ $result->{weekday} - 1 ]; + $result->{weekday} = $weekdayNamesShort->[ $result->{weekday} - 1 ]; } #fill template @@ -188,7 +189,7 @@ sub show_events { $params->{project_name} = $project_name; $params->{studio_name} = $studio_name; - template::process( 'print', $params->{template}, $params ); + template::process( $config, 'print', $params->{template}, $params ); } sub assign_events { @@ -385,7 +386,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'assignments' ); + $checked->{template} = template::check( $config, $params->{template}, 'assignments' ); if ( ( defined $checked->{action} ) && ( $checked->{action} eq 'save_schedule' ) ) { diff --git a/website/agenda/planung/audio_recordings.cgi b/website/agenda/planung/audio_recordings.cgi index 5bdddd6..4b41825 100755 --- a/website/agenda/planung/audio_recordings.cgi +++ b/website/agenda/planung/audio_recordings.cgi @@ -87,7 +87,7 @@ $params = $request->{params}->{checked}; my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( 'print', template::check('default.html'), $headerParams ); +template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); exit unless defined uac::check( $config, $params, $user_presets ); @@ -112,7 +112,7 @@ 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( 'print', $params->{template}, $params ); +template::process($config, 'print', $params->{template}, $params ); exit; @@ -544,7 +544,7 @@ sub check_params { my $checked = {}; $checked->{error} = ''; - $checked->{template} = template::check( $params->{template}, 'upload_audio_recordings' ); + $checked->{template} = template::check($config, $params->{template}, 'upload_audio_recordings' ); #print Dumper($params); #numeric values diff --git a/website/agenda/planung/calendar.cgi b/website/agenda/planung/calendar.cgi old mode 100644 new mode 100755 index 131a2ab..5d8cdcc --- a/website/agenda/planung/calendar.cgi +++ b/website/agenda/planung/calendar.cgi @@ -98,7 +98,7 @@ if ( #process header my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( 'print', template::check('default.html'), $headerParams ); + template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); print q{ @@ -1682,14 +1682,14 @@ sub getCalendar { $next = time::get_datetime( $from_date, $config->{date}->{time_zone} )->add( days => $range )->date(); } my ( $year, $month, $day ) = split( /\-/, $from_date ); - $month = $time::names->{$language}->{months_abbr}->[ $month - 1 ] || ''; + my $monthName = time::getMonthNamesShort($language)->[ $month - 1 ] || ''; return { from_date => $from_date, till_date => $till_date, next_date => $next, previous_date => $previous, - month => $month, + month => $monthName, year => $year }; @@ -1807,7 +1807,7 @@ sub check_params { my $checked = {}; my $template = ''; - $checked->{template} = template::check( $params->{template}, 'series' ); + $checked->{template} = template::check($config, $params->{template}, 'series' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/planung/comment.cgi b/website/agenda/planung/comment.cgi index 730e176..573a9d7 100755 --- a/website/agenda/planung/comment.cgi +++ b/website/agenda/planung/comment.cgi @@ -32,7 +32,7 @@ my $r = shift; my $config = config::get('../config/config.cgi'); my $debug = $config->{system}->{debug}; my ( $user, $expires ) = auth::get_user( $cgi, $config ); -return if ( ( !defined $user ) || ( $user eq '' ) ); +return if ( !defined $user ) || ( $user eq '' ) ; my $user_presets = uac::get_user_presets( $config, @@ -68,7 +68,7 @@ if ( ( params::isJson() ) || ( defined $params->{action} ) ) { } else { my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( 'print', template::check('default.html'), $headerParams ); + template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); print q{ } unless (params::isJson); @@ -132,16 +132,16 @@ sub showComments { my $events = []; my $comment_count = 0; if ( scalar(@$results) > 0 ) { - my $comments = modify_comments( $request, $results ); + my $comments = modify_comments( $config, $request, $results ); $comments = comments::sort( $config, $comments ); $events = comments::get_events( $dbh, $config, $request, $comments ); - my $language = $config::config->{date}->{language} || 'en'; + my $language = $config->{date}->{language} || 'en'; for my $event (@$events) { - $event->{start} = time::date_time_format( $event->{start}, $language ); + $event->{start} = time::date_time_format($config, $event->{start}, $language ); $comment_count += $event->{comment_count} if ( defined $event->{comment_count} ); - $event->{cache_base_url} = $config::config->{cache}->{base_url}; + $event->{cache_base_url} = $config->{cache}->{base_url}; } } for my $param (%$comment) { @@ -160,16 +160,17 @@ sub showComments { $template_parameters->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'comment' } ); #fill and output template - template::process( 'print', $params->{template}, $template_parameters ); + template::process($config, 'print', $params->{template}, $template_parameters ); } sub modify_comments { + my $config = shift; my $request = shift; my $results = shift; - my $language = $config::config->{date}->{language} || 'en'; + my $language = $config->{date}->{language} || 'en'; for my $result (@$results) { - $result->{start_date_name} = time::date_format( $result->{created_at}, $language ); + $result->{start_date_name} = time::date_format($config, $result->{created_at}, $language ); $result->{start_time_name} = time::time_format( $result->{created_at} ); $result->{ $result->{lock_status} } = 1; $result->{ $result->{news_status} } = 1; @@ -252,9 +253,9 @@ sub check_params { #template my $template = ''; if ( defined $checked->{action} ) { - $template = template::check( $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( $params->{template}, 'comments' ); + $template = template::check($config, $params->{template}, 'comments' ); } $checked->{template} = $template; diff --git a/website/agenda/planung/create_events.cgi b/website/agenda/planung/create_events.cgi index 20f2abf..eece38c 100755 --- a/website/agenda/planung/create_events.cgi +++ b/website/agenda/planung/create_events.cgi @@ -58,7 +58,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( 'print', template::check('default.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -90,7 +90,7 @@ sub show_events { uac::permissions_denied('assign_series_events'); return; } - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } @@ -147,7 +147,7 @@ sub create_events { } $params->{created_events} = $events; $params->{created_total} = scalar(@$events); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub createEvent { @@ -210,7 +210,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'create_events' ); + $checked->{template} = template::check($config, $params->{template}, 'create_events' ); return $checked; } diff --git a/website/agenda/planung/error_log.cgi b/website/agenda/planung/error_log.cgi deleted file mode 100755 index b05fdd6..0000000 --- a/website/agenda/planung/error_log.cgi +++ /dev/null @@ -1,84 +0,0 @@ -#! /usr/bin/perl -I../lib - -use warnings "all"; -use strict; -use Data::Dumper; -use HTML::Template(); - -use config(); -use log(); -use template(); -use params(); -use config(); -use auth(); -use localization(); -use studios(); - -binmode STDOUT, ":utf8"; -my $r = shift; -( my $cgi, my $params, my $error ) = params::get($r); - -my $config = config::get('../config/config.cgi'); -my $debug = $config->{system}->{debug}; -my ( $user, $expires ) = auth::get_user( $cgi, $config ); -return if ( !defined $user ) || ( $user eq '' ); - -my $user_presets = uac::get_user_presets( $config, { user => $user, studio_id => $params->{studio_id} } ); -my $request = { - url => $ENV{QUERY_STRING} || '', - params => { - original => $params, - checked => $params - - # checked => check_params($params), - }, -}; -$request = uac::prepare_request( $request, $user_presets ); - -#process header -my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); -$headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( 'print', template::check('default.html'), $headerParams ); - -#filter -my $lines = $cgi->param('lines'); -$lines = 100 if $lines eq ''; - -my $filter = ''; -$filter = ' |grep -v "Use of uninitialized value in | grep -v redefined " ' if ( $cgi->param('warn') eq '1' ); - -#get file -my $file = $config->{system}->{log_file}; -if ( $cgi->param('log') eq 'app' ) { - $file = $config->{system}->{log_debug_file}; -} -if ( $cgi->param('log') eq 'mem' ) { - $file = $config->{system}->{log_debug_memory_file}; -} -if ( $cgi->param('log') eq 'job' ) { - $file = $config->{system}->{job_log}; -} - -#output header -my $out = ''; -template::process( 'print', 'templates/error_log.html', $params ); - -#get log -my $cmd = "tail -$lines " . $file . $filter; -print '
' . $cmd . '
'; - -my $log = `$cmd`; -$log = join( "\n", reverse( split( "\n", $log ) ) ); - -#replace -if ( $cgi->param('log') eq 'app' ) { - $log =~ s/\\n/
/gi; -} else { - $log =~ s/
                                   /gi;
-}
-
-#output content
-print $log;
-
diff --git a/website/agenda/planung/event.cgi b/website/agenda/planung/event.cgi
index 23fc537..7ffdca3 100755
--- a/website/agenda/planung/event.cgi
+++ b/website/agenda/planung/event.cgi
@@ -75,7 +75,7 @@ $params = $request->{params}->{checked};
 unless ( params::isJson() ) {
 	my $headerParams = uac::set_template_permissions( $request->{permissions}, $params );
 	$headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } );
-	template::process( 'print', template::check('default.html'), $headerParams );
+	template::process($config,  'print', template::check($config, 'default.html'), $headerParams );
 }
 return unless defined uac::check( $config, $params, $user_presets );
 
@@ -148,7 +148,7 @@ sub show_event {
 
 	#TODO: move to JS
 	my @durations = ();
-	for my $duration ( @{ time::get_durations() } ) {
+	for my $duration ( @{ time::getDurations() } ) {
 		my $entry = {
 			name  => sprintf( "%02d:%02d", $duration / 60, $duration % 60 ),
 			value => $duration
@@ -311,7 +311,7 @@ sub show_event {
 
 	#print STDERR Dumper($params);
 	$params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'event' } );
-	template::process( 'print', template::check('edit_event'), $params );
+	template::process($config,  'print', template::check($config, 'edit_event'), $params );
 }
 
 sub getJson {
@@ -394,7 +394,7 @@ sub getJson {
 	}
 
 	#print to_json($event);
-	template::process( 'print', 'json-p', $event );
+	template::process($config,  'print', 'json-p', $event );
 }
 
 #show new event from schedule
@@ -432,7 +432,7 @@ sub show_new_event {
 	#add duration selectbox
 	#TODO: move to javascript
 	my @durations = ();
-	for my $duration ( @{ time::get_durations() } ) {
+	for my $duration ( @{ time::getDurations() } ) {
 		my $entry = {
 			name  => sprintf( "%02d:%02d", $duration / 60, $duration % 60 ),
 			value => $duration
@@ -455,7 +455,7 @@ sub show_new_event {
 	}
 
 	$params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'event,comment' } );
-	template::process( 'print', template::check('edit_event'), $params );
+	template::process( $config, 'print', template::check($config, 'edit_event'), $params );
 
 	#print '
'.Dumper($params).'
'; } @@ -773,7 +773,7 @@ sub check_params { my $checked = {}; my $template = ''; - $checked->{template} = template::check( $params->{template}, 'series' ); + $checked->{template} = template::check($config, $params->{template}, 'series' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/planung/event_history.cgi b/website/agenda/planung/event_history.cgi index 934d4d8..da413ae 100755 --- a/website/agenda/planung/event_history.cgi +++ b/website/agenda/planung/event_history.cgi @@ -57,7 +57,7 @@ $params = $request->{params}->{checked}; #show header my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( 'print', template::check('default.html'), $headerParams ); +template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -113,7 +113,7 @@ sub show_history { #print STDERR Dumper($params); $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'event_history' } ); - template::process( 'print', template::check('event_history'), $params ); + template::process($config, 'print', template::check($config, 'event_history'), $params ); } #show existing event history @@ -200,7 +200,7 @@ sub check_params { my $checked = {}; my $template = ''; - $checked->{template} = template::check( $params->{template}, 'event_history' ); + $checked->{template} = template::check($config, $params->{template}, 'event_history' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/planung/help.cgi b/website/agenda/planung/help.cgi index 01ddfc0..a137986 100755 --- a/website/agenda/planung/help.cgi +++ b/website/agenda/planung/help.cgi @@ -56,7 +56,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( 'print', template::check('default.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; my $toc = $headerParams->{loc}->{toc}; diff --git a/website/agenda/planung/image.cgi b/website/agenda/planung/image.cgi index 26d7031..9068fc3 100755 --- a/website/agenda/planung/image.cgi +++ b/website/agenda/planung/image.cgi @@ -65,7 +65,7 @@ $params = $request->{params}->{checked}; #show header my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -template::process( 'print', template::check('ajax_header.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'ajax_header.html'), $headerParams ); return unless defined uac::check( $config, $params, $user_presets ); my $local_media_dir = $config->{locations}->{local_media_dir}; @@ -231,7 +231,7 @@ sub show_image { $template_params->{allow}->{update_image_own} || $template_params->{allow}->{seriesupdate_image_others}; $template_params->{allow}->{delete_image} = $template_params->{allow}->{delete_image_own} || $template_params->{allow}->{delete_image_others}; - template::process( 'print', $params->{template}, $template_params ); + template::process($config, 'print', $params->{template}, $template_params ); } sub print_js_error { @@ -408,7 +408,7 @@ sub modify_results { sub check_params { my $params = shift; - my $checked = { template => template::check( $params->{template}, 'image.html' ) }; + my $checked = { template => template::check($config, $params->{template}, 'image.html' ) }; #numeric values $checked->{limit} = 100; diff --git a/website/agenda/planung/imageUpload.cgi b/website/agenda/planung/imageUpload.cgi index b70870d..2db3cb9 100755 --- a/website/agenda/planung/imageUpload.cgi +++ b/website/agenda/planung/imageUpload.cgi @@ -142,7 +142,7 @@ if ( $error ne '' ) { } print STDERR $params->{error} . "\n" if defined $params->{error}; my $out = ''; -template::process( 'print', $params->{template}, $params ); +template::process( $config, 'print', $params->{template}, $params ); print $cgi->cgi_error() if defined $cgi; @@ -388,7 +388,7 @@ sub check_params { my $params = shift; my $checked = {}; - $checked->{template} = template::check( $params->{template}, 'imageUpload' ); + $checked->{template} = template::check($config, $params->{template}, 'imageUpload' ); #numeric values for my $param ( 'project_id', 'studio_id', 'default_studio_id' ) { diff --git a/website/agenda/planung/notify_events.cgi b/website/agenda/planung/notify_events.cgi index 8fb515e..036b147 100755 --- a/website/agenda/planung/notify_events.cgi +++ b/website/agenda/planung/notify_events.cgi @@ -63,7 +63,7 @@ $params = $request->{params}->{checked}; unless ( params::isJson() || ( $params->{template} =~ /\.txt/ ) ) { my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( 'print', template::check('default.html'), $headerParams ); + template::process( $config, 'print', template::check($config, 'default.html'), $headerParams ); } return unless uac::check( $config, $params, $user_presets ) == 1; @@ -122,7 +122,7 @@ sub show_events { } $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'notify_events' } ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } @@ -241,7 +241,7 @@ sub check_params { my $checked = {}; my $template = ''; - $checked->{template} = template::check( $params->{template}, 'notify_events' ); + $checked->{template} = template::check($config, $params->{template}, 'notify_events' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/planung/playout.cgi b/website/agenda/planung/playout.cgi old mode 100644 new mode 100755 index 142dd9d..8abe17e --- a/website/agenda/planung/playout.cgi +++ b/website/agenda/planung/playout.cgi @@ -70,7 +70,7 @@ $params = $request->{params}->{checked}; my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); -#template::process('print', template::check('default.html'), $headerParams); +#template::process($config, 'print', template::check($config, 'default.html'), $headerParams); return unless uac::check( $config, $params, $user_presets ) == 1; if ( defined $params->{action} ) { @@ -154,7 +154,7 @@ sub check_params { $checked->{studio_id} = -1; } - #$checked->{template}=template::check($params->{template},'playout'); + #$checked->{template}=template::check($config, $params->{template},'playout'); return $checked; } diff --git a/website/agenda/planung/projects.cgi b/website/agenda/planung/projects.cgi index d498c99..f516788 100755 --- a/website/agenda/planung/projects.cgi +++ b/website/agenda/planung/projects.cgi @@ -24,7 +24,7 @@ my $debug = $config->{system}->{debug}; my ( $user, $expires ) = auth::get_user( $cgi, $config ); return if ( $user eq '' ); -my $permissions = roles::get_user_permissions(); +my $permissions = roles::get_user_permissions($config); my $user_presets = uac::get_user_presets( $config, { @@ -53,7 +53,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( 'print', template::check('default.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -262,7 +262,7 @@ sub show_projects { $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'projects' } ); uac::set_template_permissions( $permissions, $params ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub check_params { @@ -272,7 +272,7 @@ sub check_params { #template my $template = ''; - $template = template::check( $params->{template}, 'projects' ); + $template = template::check($config, $params->{template}, 'projects' ); $checked->{template} = $template; #actions diff --git a/website/agenda/planung/requestPassword.cgi b/website/agenda/planung/requestPassword.cgi old mode 100644 new mode 100755 index c73a1ff..87c9893 --- a/website/agenda/planung/requestPassword.cgi +++ b/website/agenda/planung/requestPassword.cgi @@ -141,7 +141,7 @@ sub check_params { my $checked = {}; #my $template = ''; - #$checked->{template} = template::check( $params->{template}, 'requestPassword' ); + #$checked->{template} = template::check($config, $params->{template}, 'requestPassword' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) { diff --git a/website/agenda/planung/roles.cgi b/website/agenda/planung/roles.cgi index 89d8364..cd8543d 100755 --- a/website/agenda/planung/roles.cgi +++ b/website/agenda/planung/roles.cgi @@ -62,7 +62,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( 'print', template::check('roles.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'roles.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; if ( defined $params->{action} ) { @@ -431,7 +431,7 @@ sub check_params { #template my $template = ''; - $template = template::check( $params->{template}, 'roles.html' ); + $template = template::check($config, $params->{template}, 'roles.html' ); $checked->{template} = $template; #actions diff --git a/website/agenda/planung/selectEvent.cgi b/website/agenda/planung/selectEvent.cgi index 195c012..4f13a11 100755 --- a/website/agenda/planung/selectEvent.cgi +++ b/website/agenda/planung/selectEvent.cgi @@ -117,7 +117,7 @@ sub show_events { $params->{years} = $years; #print STDERR Dumper($params); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); return; } @@ -171,7 +171,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'selectEvent' ); + $checked->{template} = template::check($config, $params->{template}, 'selectEvent' ); return $checked; } diff --git a/website/agenda/planung/selectSeries.cgi b/website/agenda/planung/selectSeries.cgi index 86c0c03..704813d 100755 --- a/website/agenda/planung/selectSeries.cgi +++ b/website/agenda/planung/selectSeries.cgi @@ -104,7 +104,7 @@ sub show_series { $params->{studios} = $user_studios; $params->{series} = $series; - template::process( 'print', $params->{template}, $params ); + template::process( $config, 'print', $params->{template}, $params ); return; } @@ -148,7 +148,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'selectSeries' ); + $checked->{template} = template::check($config, $params->{template}, 'selectSeries' ); return $checked; } diff --git a/website/agenda/planung/series.cgi b/website/agenda/planung/series.cgi index 07c4684..5f749eb 100755 --- a/website/agenda/planung/series.cgi +++ b/website/agenda/planung/series.cgi @@ -66,7 +66,7 @@ $params = $request->{params}->{checked}; unless ( params::isJson() ) { my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( 'print', template::check('default.html'), $headerParams ); + template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); } return unless uac::check( $config, $params, $user_presets ) == 1; @@ -989,7 +989,7 @@ sub list_series { #print STDERR Dumper $params->{image}; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'all,series' } ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub show_series { @@ -1207,7 +1207,7 @@ sub show_series { #print STDERR '
'.Dumper($params).'
'; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'all,series' } ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub check_params { @@ -1252,9 +1252,9 @@ sub check_params { } if ( defined $checked->{series_id} ) { - $checked->{template} = template::check( $params->{template}, 'edit_series' ); + $checked->{template} = template::check($config, $params->{template}, 'edit_series' ); } else { - $checked->{template} = template::check( $params->{template}, 'series' ); + $checked->{template} = template::check($config, $params->{template}, 'series' ); } if ( ( defined $checked->{action} ) && ( $checked->{action} eq 'save_schedule' ) ) { diff --git a/website/agenda/planung/show-playout.cgi b/website/agenda/planung/show-playout.cgi index 2bfbaa8..141d373 100755 --- a/website/agenda/planung/show-playout.cgi +++ b/website/agenda/planung/show-playout.cgi @@ -30,12 +30,12 @@ return if ( ( !defined $user ) || ( $user eq '' ) ); #print STDERR $params->{project_id}."\n"; my $user_presets = uac::get_user_presets( - $config, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - user => $user - } + $config, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + user => $user + } ); $params->{default_studio_id} = $user_presets->{studio_id}; $params->{studio_id} = $params->{default_studio_id} @@ -45,20 +45,20 @@ $params->{project_id} = $user_presets->{project_id} #print STDERR $params->{project_id}."\n"; my $request = { - url => $ENV{QUERY_STRING} || '', - params => { - original => $params, - checked => check_params($params), - }, + url => $ENV{QUERY_STRING} || '', + params => { + original => $params, + checked => check_params($params), + }, }; $request = uac::prepare_request( $request, $user_presets ); $params = $request->{params}->{checked}; #process header unless ( params::isJson() ) { - my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); - $headerParams->{loc} = localization::get( $config, { user => $user, file => 'menu' } ); - template::process( 'print', template::check('default.html'), $headerParams ); + 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 ); } return unless uac::check( $config, $params, $user_presets ) == 1; @@ -75,127 +75,127 @@ showPlayout( $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( 'print', $params->{template}, $params ); +template::process($config, 'print', $params->{template}, $params ); exit; sub showPlayout { - 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' ) { - unless ( defined $params->{$attr} ) { - uac::print_error( "missing " . $attr . " to show playout" ); - return; - } - } + for my $attr ( 'project_id', 'studio_id' ) { + unless ( defined $params->{$attr} ) { + uac::print_error( "missing " . $attr . " to show playout" ); + return; + } + } - my $events = playout::get( - $config, - { - project_id => $params->{project_id}, - studio_id => $params->{studio_id}, - order => 'modified_at desc, start desc', - limit => 500 - } - ); + my $events = playout::get( + $config, + { + project_id => $params->{project_id}, + studio_id => $params->{studio_id}, + order => 'modified_at desc, start desc', + limit => 500 + } + ); - # print '
'.Dumper($events).'
'; - unless ( defined $events ) { - uac::print_error("not found"); - return; - } + # print '
'.Dumper($events).'
'; + unless ( defined $events ) { + uac::print_error("not found"); + return; + } - for my $event (@$events) { - $event->{stream_size} =~ s/(\d)(\d\d\d)$/$1\.$2/g; - $event->{stream_size} =~ s/(\d)(\d\d\d\.\d\d\d)$/$1\.$2/g; - $event->{duration} =~ s/(\d\.\d)(\d+)$/$1/g; - $event->{duration} =~ s/(\d)\.0/$1/g; - $event->{rms_left} = formatLoudness( $event->{rms_left} ); - $event->{rms_right} = formatLoudness( $event->{rms_right} ); - $event->{bitrate} = formatBitrate($event); - $event->{duration} = formatDuration($event); - } + for my $event (@$events) { + $event->{stream_size} =~ s/(\d)(\d\d\d)$/$1\.$2/g; + $event->{stream_size} =~ s/(\d)(\d\d\d\.\d\d\d)$/$1\.$2/g; + $event->{duration} =~ s/(\d\.\d)(\d+)$/$1/g; + $event->{duration} =~ s/(\d)\.0/$1/g; + $event->{rms_left} = formatLoudness( $event->{rms_left} ); + $event->{rms_right} = formatLoudness( $event->{rms_right} ); + $event->{bitrate} = formatBitrate($event); + $event->{duration} = formatDuration($event); + } - $params->{events} = $events; + $params->{events} = $events; - #print Dumper($events); + #print Dumper($events); } sub formatDuration { - my $event = $_[0]; - my $duration = $event->{duration}; - return '' unless defined $duration; - return '' if $duration eq ''; - my $result = int( ( $duration + 3600 ) * 10 ) % 600; - my $class = "ok"; - $class = "warn" if $result > 1; - $class = "error" if $result > 10; - return sprintf( qq{
%.01f
}, $class, $duration ); + my $event = $_[0]; + my $duration = $event->{duration}; + return '' unless defined $duration; + return '' if $duration eq ''; + my $result = int( ( $duration + 3600 ) * 10 ) % 600; + my $class = "ok"; + $class = "warn" if $result > 1; + $class = "error" if $result > 10; + return sprintf( qq{
%.01f
}, $class, $duration ); } sub formatBitrate { - my $event = $_[0]; - my $bitrate = $event->{bitrate}; - my $mode = $event->{bitrate_mode}; - if ( $bitrate ne '' ) { - if ( $bitrate >= 200 ) { - $bitrate = '
' . $bitrate . ' ' . $mode . '
'; - } elsif ( $bitrate < 190 ) { - $bitrate = '
' . $bitrate . ' ' . $mode . '
'; - } else { - $bitrate .= ' ' . $mode; - } - } - return $bitrate; + my $event = $_[0]; + my $bitrate = $event->{bitrate}; + my $mode = $event->{bitrate_mode}; + if ( $bitrate ne '' ) { + if ( $bitrate >= 200 ) { + $bitrate = '
' . $bitrate . ' ' . $mode . '
'; + } elsif ( $bitrate < 190 ) { + $bitrate = '
' . $bitrate . ' ' . $mode . '
'; + } else { + $bitrate .= ' ' . $mode; + } + } + return $bitrate; } sub formatLoudness { - my $value = shift; - return '' unless defined $value; - return '' if $value == 0; - return '' if $value eq ''; + my $value = shift; + return '' unless defined $value; + return '' if $value == 0; + return '' if $value eq ''; - $value = sprintf( "%.1f", $value ); - my $class = 'ok'; - $class = 'warn' if $value > -18.5; - $class = 'error' if $value > -16.0; - $class = 'warn' if $value < -24.0; - $class = 'error' if $value < -27.0; + $value = sprintf( "%.1f", $value ); + my $class = 'ok'; + $class = 'warn' if $value > -18.5; + $class = 'error' if $value > -16.0; + $class = 'warn' if $value < -24.0; + $class = 'error' if $value < -27.0; - return qq{
$value dB
}; + return qq{
$value dB
}; } sub check_params { - my $params = shift; + my $params = shift; - my $checked = {}; - $checked->{error} = ''; - $checked->{template} = template::check( $params->{template}, 'show_playout' ); + my $checked = {}; + $checked->{error} = ''; + $checked->{template} = template::check($config, $params->{template}, 'show_playout' ); - #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}; - } - } + #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') { - if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) { - $checked->{$param} = $1; - } - } + #word + for my $param ('debug') { + if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /^\s*(.+?)\s*$/ ) ) { + $checked->{$param} = $1; + } + } - return $checked; + return $checked; } diff --git a/website/agenda/planung/studio_timeslots.cgi b/website/agenda/planung/studio_timeslots.cgi index e2cbee1..9565924 100755 --- a/website/agenda/planung/studio_timeslots.cgi +++ b/website/agenda/planung/studio_timeslots.cgi @@ -64,7 +64,7 @@ if ( $action eq 'show_dates' ) { #print "Content-type:text/html\n\n"; } else { - template::process( 'print', template::check('default.html'), $headerParams ); + template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); } return unless uac::check( $config, $params, $user_presets ) == 1; @@ -259,7 +259,7 @@ sub showTimeslotSchedule { } #print '
'.Dumper($params).'
'; - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub showDates { @@ -350,8 +350,8 @@ sub showDates { $params->{$key} = $result->{$key}; } - my $template = template::check('studio_timeslot_dates'); - template::process( 'print', $template, $params ); + my $template = template::check($config, 'studio_timeslot_dates'); + template::process($config, 'print', $template, $params ); } sub check_params { @@ -393,7 +393,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'studio_timeslots' ); + $checked->{template} = template::check($config, $params->{template}, 'studio_timeslots' ); for my $param ('frequency') { if ( ( defined $params->{$param} ) && ( $params->{$param} =~ /(\d+)/ ) ) { diff --git a/website/agenda/planung/studios.cgi b/website/agenda/planung/studios.cgi index 12eaeb7..69995d8 100755 --- a/website/agenda/planung/studios.cgi +++ b/website/agenda/planung/studios.cgi @@ -24,7 +24,7 @@ my $debug = $config->{system}->{debug}; my ( $user, $expires ) = auth::get_user( $cgi, $config ); return if ( $user eq '' ); -my $permissions = roles::get_user_permissions(); +my $permissions = roles::get_user_permissions($config); my $user_presets = uac::get_user_presets( $config, { @@ -52,7 +52,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( 'print', template::check('default.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; print q{ @@ -199,7 +199,7 @@ sub show_studios { $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'studios' } ); uac::set_template_permissions( $permissions, $params ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub check_params { @@ -209,7 +209,7 @@ sub check_params { #template my $template = ''; - $template = template::check( $params->{template}, 'studios' ); + $template = template::check($config, $params->{template}, 'studios' ); $checked->{template} = $template; #actions diff --git a/website/agenda/planung/user_settings.cgi b/website/agenda/planung/user_settings.cgi index 7f1d19d..5ee9efe 100755 --- a/website/agenda/planung/user_settings.cgi +++ b/website/agenda/planung/user_settings.cgi @@ -51,7 +51,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( 'print', template::check('default.html'), $headerParams ); +template::process($config, 'print', template::check($config, 'default.html'), $headerParams ); return unless uac::check( $config, $params, $user_presets ) == 1; our $errors = []; @@ -113,7 +113,7 @@ sub show_settings { uac::set_template_permissions( $permissions, $params ); #print Dumper($permissions); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); #print '
'.Dumper($user_settings);
 }
@@ -165,7 +165,7 @@ sub check_params {
 
 	#template
 	my $template = '';
-	$template = template::check( $params->{template}, 'user_settings' );
+	$template = template::check($config,  $params->{template}, 'user_settings' );
 	$checked->{template} = $template;
 
 	#numeric values
diff --git a/website/agenda/planung/user_stats.cgi b/website/agenda/planung/user_stats.cgi
index 1469899..bda464e 100755
--- a/website/agenda/planung/user_stats.cgi
+++ b/website/agenda/planung/user_stats.cgi
@@ -52,7 +52,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( 'print', template::check('default.html'), $headerParams );
+template::process($config,  'print', template::check($config, 'default.html'), $headerParams );
 return unless uac::check( $config, $params, $user_presets ) == 1;
 
 our $errors = [];
@@ -76,7 +76,7 @@ sub show_stats {
 
 	$params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'user_stats' } );
 	uac::set_template_permissions( $permissions, $params );
-	template::process( 'print', $params->{template}, $params );
+	template::process($config,  'print', $params->{template}, $params );
 }
 
 sub check_params {
@@ -86,7 +86,7 @@ sub check_params {
 
 	#template
 	my $template = '';
-	$template = template::check( $params->{template}, 'user_stats' );
+	$template = template::check($config,  $params->{template}, 'user_stats' );
 	$checked->{template} = $template;
 
 	#numeric values
diff --git a/website/agenda/planung/users.cgi b/website/agenda/planung/users.cgi
index 8d9dec9..2171408 100755
--- a/website/agenda/planung/users.cgi
+++ b/website/agenda/planung/users.cgi
@@ -48,7 +48,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( 'print', template::check('default.html'), $headerParams );
+template::process($config,  'print', template::check($config, 'default.html'), $headerParams );
 return unless uac::check( $config, $params, $user_presets ) == 1;
 
 our $errors = [];
@@ -168,9 +168,9 @@ sub show_users {
 	uac::set_template_permissions( $permissions, $params );
 
 	#print Dumper($permissions);
-	template::process( 'print', $params->{template}, $params );
+	template::process($config,  'print', $params->{template}, $params );
 
-	#	template::process('print', template::check('users'), $params);
+	#	template::process($config, 'print', template::check($config, 'users'), $params);
 
 }
 
@@ -251,7 +251,7 @@ sub change_password {
 	uac::set_template_permissions( $permissions, $params );
 
 	#print Dumper($permissions);
-	template::process( 'print', template::check('change_password'), $params );
+	template::process( $config, 'print', template::check($config, 'change_password'), $params );
 }
 
 sub delete_user {
@@ -405,7 +405,7 @@ sub check_params {
 
 	#template
 	my $template = '';
-	$template = template::check( $params->{template}, 'users' );
+	$template = template::check($config,  $params->{template}, 'users' );
 	$checked->{template} = $template;
 
 	#numeric values
diff --git a/website/agenda/planung/work_time.cgi b/website/agenda/planung/work_time.cgi
index 7a2cd48..4f807dc 100755
--- a/website/agenda/planung/work_time.cgi
+++ b/website/agenda/planung/work_time.cgi
@@ -59,7 +59,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( 'print', template::check('default.html'), $headerParams );
+template::process($config,  'print', template::check($config, 'default.html'), $headerParams );
 return unless uac::check( $config, $params, $user_presets ) == 1;
 
 if ( defined $params->{action} ) {
@@ -261,7 +261,7 @@ sub show_work_schedule {
 
 	#print STDERR '
'.Dumper($params).'
'; $params->{loc} = localization::get( $config, { user => $params->{presets}->{user}, file => 'work_time' } ); - template::process( 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params ); } sub check_params { @@ -300,7 +300,7 @@ sub check_params { $checked->{studio_id} = -1; } - $checked->{template} = template::check( $params->{template}, 'edit_work_time' ); + $checked->{template} = template::check($config, $params->{template}, 'edit_work_time' ); if ( ( defined $checked->{action} ) && ( $checked->{action} eq 'save_schedule' ) ) { diff --git a/website/agenda/series.cgi b/website/agenda/series.cgi index d842f07..886a7a6 100755 --- a/website/agenda/series.cgi +++ b/website/agenda/series.cgi @@ -68,7 +68,7 @@ sub list_series { $params->{info}.="no results found" if scalar(@$series)==0; $params->{info}=''; - template::process( 'print', 'templates/series.html', $params ); + template::process($config, 'print', 'templates/series.html', $params ); } sub check_params { diff --git a/website/agenda/series_names.cgi b/website/agenda/series_names.cgi index 486de83..41e94f1 100755 --- a/website/agenda/series_names.cgi +++ b/website/agenda/series_names.cgi @@ -62,7 +62,7 @@ $template_parameters->{use_client_cache} = $config->{cache}->{use_client_cache} #output template my $template = $params->{template}; my $out = ''; -template::process( $out, $params->{template}, $template_parameters ); +template::process($config, $out, $params->{template}, $template_parameters ); print $out; #write to cache @@ -184,7 +184,7 @@ sub check_params { my $config = shift; my $params = shift; - my $template = template::check( $params->{template}, 'series_names.html' ); + my $template = template::check($config, $params->{template}, 'series_names.html' ); my $debug = $params->{debug} || ''; if ( $debug =~ /([a-z\_\,]+)/ ) {