From ea952a8021db9a0fd676ec53e265570497e72f00 Mon Sep 17 00:00:00 2001 From: Milan Date: Thu, 18 Apr 2024 20:44:37 +0200 Subject: [PATCH] studio-timeslot: add week in month --- install/migrate.sql | 9 + lib/calcms/studio_timeslot_dates.pm | 113 +++++--- lib/calcms/studio_timeslot_schedule.pm | 4 - .../agenda/planung/css/studio-timeslots.css | 11 +- website/agenda/planung/js/studio-timeslots.js | 33 +++ .../agenda/planung/pot/de/studio-timeslots.po | 153 +++++++++++ .../agenda/planung/pot/en/studio-timeslots.po | 146 ++++++++++ website/agenda/planung/studio-timeslots.cgi | 251 +++++++----------- .../planung/templates/studio-timeslots.html | 200 +++++++++++--- 9 files changed, 681 insertions(+), 239 deletions(-) diff --git a/install/migrate.sql b/install/migrate.sql index 0bcbedb..d788558 100644 --- a/install/migrate.sql +++ b/install/migrate.sql @@ -353,3 +353,12 @@ update calcms_series set image = replace(image , '/agenda_files/media/images/', update calcms_series set image = replace(image , '/agenda_files/media/icons/', '') where image like '%/agenda_files/media/icons/%'; update calcms_series set image = replace(image , '/agenda_files/media/thumbs/', '') where image like '%/agenda_files/media/thumbs/%'; +-- add day of month to studio schedules +ALTER TABLE `calcms`.`calcms_studio_timeslot_schedule` +ADD COLUMN `period_type` VARCHAR(45) NOT NULL AFTER `end_date`, +ADD COLUMN `weekday` INT UNSIGNED NULL AFTER `period_type`, +ADD COLUMN `week_of_month` INT UNSIGNED NULL AFTER `weekday`, +ADD COLUMN `month` INT UNSIGNED NULL AFTER `week_of_month`, +CHANGE COLUMN `frequency` `frequency` INT UNSIGNED NULL ; + +update `calcms_studio_timeslot_schedule` set period_type = 'days' where period_type = ''; \ No newline at end of file diff --git a/lib/calcms/studio_timeslot_dates.pm b/lib/calcms/studio_timeslot_dates.pm index 6863aef..089e7c4 100644 --- a/lib/calcms/studio_timeslot_dates.pm +++ b/lib/calcms/studio_timeslot_dates.pm @@ -4,7 +4,6 @@ use strict; use warnings; no warnings 'redefine'; -use Data::Dumper; use Date::Calc(); use time(); @@ -12,8 +11,7 @@ use time(); # table: calcms_studio_timeslot_dates # columns: id, studio_id, start(datetime), end(datetime) # TODO: delete column schedule_id -#use base 'Exporter'; -our @EXPORT_OK = qw(get_columns get insert update delete get_dates); +our @EXPORT_OK = qw(get_columns get insert update delete get_dates); sub get_columns ($){ my ($config) = @_; @@ -124,34 +122,37 @@ sub update { 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} - } + my $schedules = studio_timeslot_schedule::get($config, + {schedule_id => $entry->{schedule_id}} ); #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} ); + my $dateList; + if ($schedule->{period_type} eq 'days') { + #calculate dates from start to end_date + $dateList = get_dates($schedule->{start}, $schedule->{end}, $schedule->{end_date}, $schedule->{frequency}); + } elsif ($schedule->{period_type} eq 'week_of_month') { + my $timezone = $config->{date}->{time_zone}; + $dateList = get_week_of_month_dates($timezone, + $schedule->{start}, $schedule->{end}, $schedule->{end_date}, + $schedule->{week_of_month}, $schedule->{weekday}, $schedule->{month}, + $schedule->{nextDay} + ); + } 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; + $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 ) { + for my $date (sort keys %$dates) { my $timeslot_date = $dates->{$date}; - - #insert date my $entry = { project_id => $timeslot_date->{project_id}, studio_id => $timeslot_date->{studio_id}, @@ -159,9 +160,9 @@ sub update { 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 ); + $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); $i++; } return $i; @@ -196,7 +197,6 @@ sub get_dates { my $dates = []; return $dates if ( $date->{end} le $date->{start} ); - return $dates if ( $stop_date lt $end_date ); my $j = Date::Calc::Delta_Days( @start_date, @stop_date ); @@ -219,21 +219,19 @@ sub get_dates { 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, - { + push @$dates, { start => $start_date . ' 00:00:00', end => $next_date . ' 00:00:00', - }; - last if ( $c > 1000 ); + }; + last if $c > 1000; $c++; } #end day - push @$dates, - { + push @$dates, { start => $end_date . ' 00:00:00', end => $end_date . ' ' . $end_time, - } if ( $end_time ne '00:00:00' ); + } if $end_time ne '00:00:00'; return $dates; } @@ -247,17 +245,60 @@ sub get_dates { my $start_date = sprintf( "%04d-%02d-%02d", @start_date ); my $end_date = sprintf( "%04d-%02d-%02d", @end_date ); - push @$dates, - { + push @$dates, { start => $start_date . ' ' . $start_time, end => $end_date . ' ' . $end_time, - }; - last if ( $c > 1000 ); + }; + last if $c > 1000; $c++; } return $dates; } +# based on series_dates but with (timezone, start, end) instead of (start, duration) +sub get_week_of_month_dates ($$$$$$$$) { + my ($timezone, $start, $end, $end_date, $week, $weekday, $frequency, $nextDay) = @_; + #datetime, datetime, date, every nth week of month, weekday [1..7], every 1st,2nd,3th time, add 24 hours to start, (for night hours at last weekday of month) + + return undef if $timezone eq ''; + return undef if $start eq ''; + return undef if $end eq ''; + return undef if $end_date eq ''; + return undef if $week eq ''; + return undef if $weekday eq ''; + return undef if $frequency eq ''; + return undef if $frequency == 0; + + my $start_dates = time::get_nth_weekday_in_month($start, $end_date, $week, $weekday); + + if (defined $nextDay && $nextDay > 0) { + for (my $i = 0; $i < @$start_dates; $i++) { + $start_dates->[$i] = time::add_hours_to_datetime($start_dates->[$i], 24); + } + } + + my $results = []; + my $duration = time::get_duration($start, $end, $timezone); + my $c = -1; + for my $start_datetime (@$start_dates) { + $c++; + my @start = @{ time::datetime_to_array($start_datetime) }; + next unless @start >= 6; + next if ($c % $frequency) != 0; + my @end_datetime = Date::Calc::Add_Delta_DHMS( + $start[0], $start[1], $start[2], # start date + $start[3], $start[4], $start[5], # start time + 0, 0, $duration, 0 # delta days, hours, minutes, seconds + ); + my $end_datetime = time::array_to_datetime( \@end_datetime ); + push @$results, { + start => $start_datetime, + end => $end_datetime + }; + } + return $results; +} + #remove all studio_timeslot_dates for studio_id and schedule_id sub delete { my ($config, $entry) = @_; @@ -269,8 +310,8 @@ sub delete { my $dbh = db::connect($config); my $query = qq{ - delete - from calcms_studio_timeslot_dates + delete + from calcms_studio_timeslot_dates where schedule_id=? }; my $bind_values = [ $entry->{schedule_id} ]; diff --git a/lib/calcms/studio_timeslot_schedule.pm b/lib/calcms/studio_timeslot_schedule.pm index 5d30f86..6b32751 100644 --- a/lib/calcms/studio_timeslot_schedule.pm +++ b/lib/calcms/studio_timeslot_schedule.pm @@ -67,7 +67,6 @@ sub insert($$) { return unless defined $entry->{studio_id}; return unless defined $entry->{start}; return unless defined $entry->{end}; - return unless defined $entry->{frequency}; my $dbh = db::connect($config); return db::insert( $dbh, 'calcms_studio_timeslot_schedule', $entry ); @@ -82,7 +81,6 @@ sub update($$) { return unless defined $entry->{schedule_id}; return unless defined $entry->{start}; return unless defined $entry->{end}; - return unless defined $entry->{frequency}; $entry->{id} = $entry->{schedule_id}; delete $entry->{schedule_id}; @@ -100,8 +98,6 @@ sub update($$) { }; db::put( $dbh, $query, \@bind_values ); - #print "done\n"; - $entry->{schedule_id} = $entry->{id}; delete $entry->{id}; diff --git a/website/agenda/planung/css/studio-timeslots.css b/website/agenda/planung/css/studio-timeslots.css index 43159c8..64a2093 100644 --- a/website/agenda/planung/css/studio-timeslots.css +++ b/website/agenda/planung/css/studio-timeslots.css @@ -48,18 +48,17 @@ #content .editor .cell { display: table-cell ; vertical-align:baseline; - text-align: center; + text-align: left; } #content .frequency { width: 6em; } -#content div.weekday { - padding: 0; - width: 2em; - margin-right: -0.5em; - margin-top: 1.2em; +#content .editor div.cell.weekday { + vertical-align: bottom; + width: 2.5ch; + padding-bottom: 9px; } #content div.show_schedule_head { diff --git a/website/agenda/planung/js/studio-timeslots.js b/website/agenda/planung/js/studio-timeslots.js index 2ce10cf..449f2d7 100644 --- a/website/agenda/planung/js/studio-timeslots.js +++ b/website/agenda/planung/js/studio-timeslots.js @@ -61,6 +61,37 @@ function initTable(){ $('.tablesorter-scroller-table table').css('width','95%'); } +// show/hide schedule fields depending on period type for a given schedule element +function showScheduleFields(id){ + var select='#'+id+' select[name="period_type"]'; + var type=$(select).val(); + //hide and show values for different schedule types + if (type=='days' || type=='') { + $('#'+id+' div.cell.frequency').show(); + $('#'+id+' div.cell.end').show(); + $('#'+id+' div.cell.schedule_weekday').hide(); + $('#'+id+' div.cell.week_of_month').hide(); + $('#'+id+' div.cell.schedule_month').hide(); + $('#'+id+' div.cell.nextDay').hide(); + }else if(type=='week_of_month'){ + $('#'+id+' div.cell.frequency').hide(); + $('#'+id+' div.cell.end').show(); + $('#'+id+' div.cell.schedule_weekday').show(); + $('#'+id+' div.cell.week_of_month').show(); + $('#'+id+' div.cell.schedule_month').show(); + $('#'+id+' div.cell.nextDay').show(); + }else{ + alert("invalid schedule type"); + } +} + +function initScheduleFields(){ + $('div.row.schedule form').each(function(){ + var id = $(this).attr('id'); + if(contains(id,'schedule_'))showScheduleFields(id); + }); +} + $(document).ready( function(){ setupLocalization(function(){ @@ -88,6 +119,7 @@ $(document).ready( onSelect: function(){updateWeekdays();} }); + initScheduleFields(); setSelectedOptions(); showYearPicker('#show_date', { @@ -95,6 +127,7 @@ $(document).ready( showDates(); } }); + showDates(); }); diff --git a/website/agenda/planung/pot/de/studio-timeslots.po b/website/agenda/planung/pot/de/studio-timeslots.po index 5a327e1..0f18e75 100644 --- a/website/agenda/planung/pot/de/studio-timeslots.po +++ b/website/agenda/planung/pot/de/studio-timeslots.po @@ -64,3 +64,156 @@ msgstr "alle 28 Tage" msgid "every_month" msgstr "monatlich" +msgid "schedule_start" +msgstr "Start" + +msgid "schedule_end" +msgstr "wiederholt bis" + +msgid "duration" +msgstr "Dauer" + +msgid "duration_in_minutes" +msgstr "Dauer in Minuten" + +msgid "frequency" +msgstr "wie oft" + +msgid "frequency_days" +msgstr "alle x Tage" + +msgid "exception" +msgstr "Ausnahme" + +msgid "week_of_month" +msgstr "Woche" + +msgid "weekday" +msgstr "Wochentag" + +msgid "period_type" +msgstr "Wiederholung" + +msgid "period_type_single" +msgstr "keine" + +msgid "period_type_days" +msgstr "festes Interval" + +msgid "period_type_week_of_month" +msgstr "Woche im Monat" + +msgid "nextDay" +msgstr "Nacht" + +msgid "minutes" +msgstr "Minuten" + +msgid "hour" +msgstr "Stunde" + +msgid "hours" +msgstr "Stunden" + +msgid "day" +msgstr "Tag" + +msgid "days" +msgstr "Tage" + +msgid "daily" +msgstr "täglich" + +msgid "week" +msgstr "Woche" + +msgid "weeks" +msgstr "Wochen" + +msgid "weekly" +msgstr "wöchentlich" + +msgid "month" +msgstr "Monat" + +msgid "months" +msgstr "Monate" + +msgid "from" +msgstr "von" + +msgid "till" +msgstr "bis" + +msgid "modified" +msgstr "bearbeited" + +msgid "added" +msgstr "hinzugefügt" + +msgid "at" +msgstr "am" + +msgid "by" +msgstr "von" + +msgid "unit" +msgstr "in" + +msgid "choose_free" +msgstr "frei wählbar" + +msgid "every" +msgstr "alle" + +msgid "every_month" +msgstr "wie oft" + +msgid "every_time" +msgstr "jedes Mal" + +msgid "every_2nd_time" +msgstr "jedes 2. Mal" + +msgid "every_3rd_time" +msgstr "jedes 3. Mal" + +msgid "every_4th_time" +msgstr "jedes 4. Mal" + +msgid "week_1st" +msgstr "erster" + +msgid "week_2nd" +msgstr "zweiter" + +msgid "week_3rd" +msgstr "dritter" + +msgid "week_4th" +msgstr "vierter" + +msgid "week_5th" +msgstr "fünter" + +msgid "monday" +msgstr "Montag" + +msgid "tuesday" +msgstr "Dienstag" + +msgid "wednesday" +msgstr "Mittwoch" + +msgid "thursday" +msgstr "Donnerstag" + +msgid "friday" +msgstr "Freitag" + +msgid "saturday" +msgstr "Samstag" + +msgid "sunday" +msgstr "Sonntag" + diff --git a/website/agenda/planung/pot/en/studio-timeslots.po b/website/agenda/planung/pot/en/studio-timeslots.po index b7b414f..30fae44 100644 --- a/website/agenda/planung/pot/en/studio-timeslots.po +++ b/website/agenda/planung/pot/en/studio-timeslots.po @@ -64,4 +64,150 @@ msgstr "every four weeks" msgid "every_month" msgstr "every month" +msgid "schedule_start" +msgstr "start of schedule" + +msgid "schedule_end" +msgstr "end of schedule" + +msgid "duration" +msgstr "duration" + +msgid "duration_in_minutes" +msgstr "duration in minutes" + +msgid "frequency" +msgstr "how often" + +msgid "frequency_days" +msgstr "every n days" + +msgid "week_of_month" +msgstr "week of month" + +msgid "weekday" +msgstr "weekday" + +msgid "period_type" +msgstr "type of planning" + +msgid "period_type_days" +msgstr "regular recurrence" + +msgid "period_type_week_of_month" +msgstr "week of month" + +msgid "nextDay" +msgstr "night" + +msgid "minutes" +msgstr "minutes" + +msgid "hour" +msgstr "hour" + +msgid "hours" +msgstr "hours" + +msgid "day" +msgstr "day" + +msgid "days" +msgstr "days" + +msgid "daily" +msgstr "daily" + +msgid "week" +msgstr "week" + +msgid "weeks" +msgstr "weeks" + +msgid "weekly" +msgstr "weekly" + +msgid "month" +msgstr "month" + +msgid "months" +msgstr "months" + +msgid "from" +msgstr "from" + +msgid "till" +msgstr "till" + +msgid "modified" +msgstr "modified" + +msgid "added" +msgstr "added" + +msgid "at" +msgstr "at" + +msgid "by" +msgstr "by" + +msgid "unit" +msgstr "in" + +msgid "choose_free" +msgstr "choose freely" + +msgid "every" +msgstr "every" + +msgid "every_month" +msgstr "every nth time" + +msgid "every_time" +msgstr "every time" + +msgid "every_2nd_time" +msgstr "every 2nd time" + +msgid "every_3rd_time" +msgstr "every 3rd time" + +msgid "every_4th_time" +msgstr "every 4th time" + +msgid "week_1st" +msgstr "1st" + +msgid "week_2nd" +msgstr "2nd" + +msgid "week_3rd" +msgstr "3rd" + +msgid "week_4th" +msgstr "4th" + +msgid "week_5th" +msgstr "5th" + +msgid "monday" +msgstr "Monday" + +msgid "tuesday" +msgstr "Tuesday" + +msgid "wednesday" +msgstr "Wednesday" + +msgid "thursday" +msgstr "Thursday" + +msgid "friday" +msgstr "Friday" + +msgid "saturday" +msgstr "Saturday" + +msgid "sunday" +msgstr "Sunday" diff --git a/website/agenda/planung/studio-timeslots.cgi b/website/agenda/planung/studio-timeslots.cgi index 38981ce..7bad084 100755 --- a/website/agenda/planung/studio-timeslots.cgi +++ b/website/agenda/planung/studio-timeslots.cgi @@ -4,9 +4,6 @@ use strict; use warnings; no warnings 'redefine'; -use Data::Dumper; -use URI::Escape(); - use params(); use config(); use entry(); @@ -24,11 +21,11 @@ use localization(); binmode STDOUT, ":utf8"; my $r = shift; -( my $cgi, my $params, my $error ) = params::get($r); +(my $cgi, my $params, my $error) = params::get($r); my $config = config::get('../config/config.cgi'); -my ( $user, $expires ) = auth::get_user( $config, $params, $cgi ); -return if ( ( !defined $user ) || ( $user eq '' ) ); +my ($user, $expires) = auth::get_user($config, $params, $cgi); +return if ((!defined $user) || ($user eq '')); my $user_presets = uac::get_user_presets( $config, @@ -39,48 +36,45 @@ my $user_presets = uac::get_user_presets( } ); $params->{default_studio_id} = $user_presets->{studio_id}; -$params = uac::setDefaultStudio( $params, $user_presets ); -$params = uac::setDefaultProject( $params, $user_presets ); +$params = uac::setDefaultStudio($params, $user_presets); +$params = uac::setDefaultProject($params, $user_presets); my $request = { url => $ENV{QUERY_STRING} || '', params => { original => $params, - checked => check_params( $config, $params ), + checked => check_params($config, $params), }, }; -$request = uac::prepare_request( $request, $user_presets ); +$request = uac::prepare_request($request, $user_presets); $params = $request->{params}->{checked}; #process header -my $headerParams = uac::set_template_permissions( $request->{permissions}, $params ); -$headerParams->{loc} = localization::get( $config, { user => $user, file => 'all,menu' } ); +my $headerParams = uac::set_template_permissions($request->{permissions}, $params); +$headerParams->{loc} = localization::get($config, {user => $user, file => 'all,menu'}); my $action = $params->{action} || ''; -if ( $action eq 'show_dates' ) { +if ($action eq 'show_dates') { #print "Content-type:text/html\n\n"; } else { - template::process( $config, 'print', template::check( $config, 'default.html' ), $headerParams ); + template::process($config, 'print', template::check($config, 'default.html'), $headerParams); } -return unless uac::check( $config, $params, $user_presets ) == 1; +return unless uac::check($config, $params, $user_presets) == 1; -if ( $action eq 'show_dates' ) { +if ($action eq 'show_dates') { print "Content-Type:text/html\n\n"; } else { - template::process( $config, 'print', template::check( $config, 'studio-timeslots-header.html' ), $headerParams ); + template::process($config, 'print', template::check($config, 'studio-timeslots-header.html'), $headerParams); } -if ( defined $params->{action} ) { - save_schedule( $config, $request ) if ( $params->{action} eq 'save_schedule' ); - delete_schedule( $config, $request ) if ( $params->{action} eq 'delete_schedule' ); - if ( $params->{action} eq 'show_dates' ) { - showDates( $config, $request ); - return; - } +if (defined $params->{action}) { + save_schedule($config, $request) if $params->{action} eq 'save_schedule'; + delete_schedule($config, $request) if $params->{action} eq 'delete_schedule'; + return showDates($config, $request) if $params->{action} eq 'show_dates'; } $config->{access}->{write} = 0; -showTimeslotSchedule( $config, $request ); +showTimeslotSchedule($config, $request); return; #insert or update a schedule and update all schedule dates @@ -88,44 +82,40 @@ sub save_schedule { my ($config, $request) = @_; my $permissions = $request->{permissions}; - unless ( $permissions->{update_studio_timeslot_schedule} == 1 ) { - uac::permissions_denied('update_studio_timeslot_schedule'); - return; - } + return uac::permissions_denied('update_studio_timeslot_schedule') + unless $permissions->{update_studio_timeslot_schedule} == 1; my $params = $request->{params}->{checked}; - - for my $attr ( 'project_id', 'studio_id', 'start', 'end', 'end_date', 'schedule_studio_id' ) { - unless ( defined $params->{$attr} ) { - uac::print_error( $attr . ' not given!' ); - return; - } - } + for my $attr ('project_id', 'studio_id', 'start', 'end', 'end_date', 'schedule_studio_id') { + return uac::print_error($attr . ' not given!') unless defined $params->{$attr}; + } my $entry = {}; - for my $attr ( 'project_id', 'start', 'end', 'end_date', 'frequency' ) { - $entry->{$attr} = $params->{$attr} if defined $params->{$attr}; - } + if ($params->{period_type} eq 'days') { + entry::set_numbers($entry, $params, ['frequency']); + $entry->{period_type} = $params->{period_type}; + }elsif($params->{period_type} eq 'week_of_month') { + entry::set_numbers($entry, $params, ['weekday', 'week_of_month', 'month']); + $entry->{period_type} = $params->{period_type}; + } + + my $entry = {map {$_ => $params->{$_}} ('project_id', 'start', 'end', 'end_date')}; #set schedule's studio to value from schedule_studio_id $entry->{studio_id} = $params->{schedule_studio_id} if defined $params->{schedule_studio_id}; - if ( ( $entry->{end} ne '' ) && ( $entry->{end} le $entry->{start} ) ) { - uac::print_error('start date should be before end date!'); - return; - } + return uac::print_error('start date should be before end date!') + if $entry->{end} ne '' && $entry->{end} le $entry->{start}; $config->{access}->{write} = 1; - if ( defined $params->{schedule_id} ) { + if (defined $params->{schedule_id}) { $entry->{schedule_id} = $params->{schedule_id}; - studio_timeslot_schedule::update( $config, $entry ); - - my $updates = studio_timeslot_dates::update( $config, $entry ); + studio_timeslot_schedule::update($config, $entry); + my $updates = studio_timeslot_dates::update($config, $entry); uac::print_info("timeslot schedule saved. $updates dates scheduled"); } else { - $entry->{schedule_id} = studio_timeslot_schedule::insert( $config, $entry ); - - my $updates = studio_timeslot_dates::update( $config, $entry ); + $entry->{schedule_id} = studio_timeslot_schedule::insert($config, $entry); + my $updates = studio_timeslot_dates::update($config, $entry); uac::print_info("timeslot schedule added. $updates dates added"); } @@ -135,27 +125,20 @@ sub delete_schedule { my ($config, $request) = @_; my $permissions = $request->{permissions}; - unless ( $permissions->{update_studio_timeslot_schedule} == 1 ) { - uac::permissions_denied('update_studio_timeslot_schedule'); - return; - } - + return uac::permissions_denied('update_studio_timeslot_schedule') + unless $permissions->{update_studio_timeslot_schedule} == 1; my $params = $request->{params}->{checked}; my $entry = {}; - for my $attr ( 'project_id', 'studio_id', 'schedule_id' ) { - if ( defined $params->{$attr} ) { - $entry->{$attr} = $params->{$attr}; - } else { - uac::print_error( $attr . ' not given!' ); - return; - } + for my $attr ('project_id', 'studio_id', 'schedule_id') { + return uac::print_error($attr . ' not given!') unless defined $params->{$attr}; + $entry->{$attr} = $params->{$attr}; } $config->{access}->{write} = 1; $entry->{schedule_id} = $params->{schedule_id}; - studio_timeslot_schedule::delete( $config, $entry ); - studio_timeslot_dates::update( $config, $entry ); + studio_timeslot_schedule::delete($config, $entry); + studio_timeslot_dates::update($config, $entry); uac::print_info("timeslot schedule deleted"); } @@ -163,49 +146,38 @@ sub showTimeslotSchedule { my ($config, $request) = @_; $config->{access}->{write} = 0; - my $params = $request->{params}->{checked}; my $permissions = $request->{permissions}; - unless ( $permissions->{read_studio_timeslot_schedule} == 1 ) { - uac::permissions_denied('read_studio_timeslot_schedule'); - return; - } + return uac::permissions_denied('read_studio_timeslot_schedule') + unless $permissions->{read_studio_timeslot_schedule} == 1; - for my $param ( 'project_id', 'studio_id' ) { - unless ( defined $params->{$param} ) { - uac::print_error("missing $param"); - return; - } + for my $param ('project_id', 'studio_id') { + return uac::print_error("missing $param") unless defined $params->{$param}; } #this will be updated later (especially allow_update_events) - for my $permission ( keys %{ $request->{permissions} } ) { - $params->{'allow'}->{$permission} = $request->{permissions}->{$permission}; - } + $params->{'allow'}->{$_} = $request->{permissions}->{$_} for (keys %{$request->{permissions}}); $params->{loc} = - localization::get( $config, { user => $params->{presets}->{user}, file => 'all,studio-timeslots' } ); + localization::get($config, {user => $params->{presets}->{user}, file => 'all,studio-timeslots'}); my $studio_id = $params->{studio_id}; my $project_id = $params->{project_id}; #get project schedule my $schedules = studio_timeslot_schedule::get( - $config, - { - project_id => $project_id - - # studio_id=>$studio_id - } - ); + $config, {project_id => $project_id} +); #list of all studios by id - my $studios = studios::get( $config, { project_id => $project_id } ); + my $studios = studios::get($config, {project_id => $project_id}); #remove seconds from dates for my $schedule (@$schedules) { $schedule->{start} =~ s/(\d\d\:\d\d)\:\d\d/$1/; $schedule->{end} =~ s/(\d\d\:\d\d)\:\d\d/$1/; + $schedule->{period_type_days} = 1 if $schedule->{period_type} eq 'days'; + $schedule->{period_type_week_of_month} = 1 if $schedule->{period_type} eq 'week_of_month'; #insert assigned studio for my $studio (@$studios) { @@ -213,8 +185,8 @@ sub showTimeslotSchedule { id => $studio->{id}, name => $studio->{name}, }; - $entry->{selected} = 1 if ( $studio->{id} eq $schedule->{studio_id} ); - push @{ $schedule->{studios} }, $entry; + $entry->{selected} = 1 if $studio->{id} eq $schedule->{studio_id}; + push @{$schedule->{studios}}, $entry; } } @@ -224,22 +196,17 @@ sub showTimeslotSchedule { }; $result->{schedule} = $schedules; $result->{studios} = $studios; - $result->{start} = $params->{start}; - $result->{end} = $params->{end}; - $result->{end_date} = $params->{end_date}; - $result->{frequency} = $params->{frequency}; - + for my $attr ('start', 'end', 'end_date', 'frequency', 'period_type', 'weekday', 'week_of_month', 'month') { + $result->{$attr} = $params->{$attr}; + } #remove seconds from datetimes $result->{start} =~ s/(\d\d\:\d\d)\:\d\d/$1/ if defined $result->{start}; $result->{end} =~ s/(\d\d\:\d\d)\:\d\d/$1/ if defined $result->{end}; #copy entry values to params - for my $key ( keys %$result ) { - $params->{$key} = $result->{$key}; - } + $params->{$_} = $result->{$_} for keys %$result; - #print '
'.Dumper($params).'
'; - template::process( $config, 'print', $params->{template}, $params ); + template::process($config, 'print', $params->{template}, $params); } sub showDates { @@ -249,22 +216,16 @@ sub showDates { my $params = $request->{params}->{checked}; my $permissions = $request->{permissions}; - unless ( $permissions->{read_studio_timeslot_schedule} == 1 ) { - uac::permissions_denied('read_studio_timeslot_schedule'); - return; - } + return uac::permissions_denied('read_studio_timeslot_schedule') + unless $permissions->{read_studio_timeslot_schedule} == 1; - for my $param ( 'project_id', 'studio_id' ) { - unless ( defined $params->{$param} ) { - uac::print_error("missing $param"); - return; - } + for my $param ('project_id', 'studio_id') { + return uac::print_error("missing $param") unless defined $params->{$param}; } #this will be updated later (especially allow_update_events) - for my $permission ( keys %{ $request->{permissions} } ) { - $params->{'allow'}->{$permission} = $request->{permissions}->{$permission}; - } + $params->{'allow'}->{$_} = $request->{permissions}->{$_} + for (keys %{$request->{permissions}}); my $studio_id = $params->{studio_id}; my $project_id = $params->{project_id}; @@ -277,15 +238,13 @@ sub showDates { $config, { project_id => $project_id, - - # studio_id=>$studio_id, from => $fromDate, till => $tillDate } ); $params->{loc} = - localization::get( $config, { user => $params->{presets}->{user}, file => 'all,studio-timeslots' } ); + localization::get($config, {user => $params->{presets}->{user}, file => 'all,studio-timeslots'}); my $language = $params->{loc}->{region}; # translate weekday names to selected language @@ -299,11 +258,8 @@ sub showDates { 'Su' => $params->{loc}->{weekday_Su}, }; - my $studios = studios::get( $config, { project_id => $project_id } ); - my $studio_by_id = {}; - for my $studio (@$studios) { - $studio_by_id->{ $studio->{id} } = $studio; - } + my $studios = studios::get($config, {project_id => $project_id}); + my $studio_by_id = {map {$_->{id} => $_} @$studios}; #remove seconds from dates for my $date (@$timeslot_dates) { @@ -313,11 +269,11 @@ sub showDates { $date->{end} =~ s/(\d\d\:\d\d)\:\d\d/$1/; # translate weekday - if ( $language ne 'en' ) { - $date->{start_weekday} = $weekday->{ $date->{start_weekday} }; - $date->{end_weekday} = $weekday->{ $date->{end_weekday} }; - } - $date->{studio_name} = $studio_by_id->{ $date->{studio_id} }->{name}; + if ($language ne 'en') { + $date->{start_weekday} = $weekday->{$date->{start_weekday}}; + $date->{end_weekday} = $weekday->{$date->{end_weekday}}; + } + $date->{studio_name} = $studio_by_id->{$date->{studio_id}}->{name}; } my $result = { project_id => $project_id, @@ -326,60 +282,53 @@ sub showDates { }; #copy entry values to params - for my $key ( keys %$result ) { - $params->{$key} = $result->{$key}; - } + $params->{$_} = $result->{$_} for keys %$result; - my $template = template::check( $config, 'studio-timeslot-dates' ); - template::process( $config, 'print', $template, $params ); + my $template = template::check($config, 'studio-timeslot-dates'); + template::process($config, 'print', $template, $params); } sub check_params { - my $config = shift; - my $params = shift; + ($config, $params) = @_; my $checked = {}; + $checked->{template} = template::check($config, $params->{template}, 'studio-timeslots'); #actions and roles - if ( defined $params->{action} ) { - if ( $params->{action} =~ /^(show|save_schedule|delete_schedule|show_dates)$/ ) { - $checked->{action} = $params->{action}; - } - } + $checked->{action} = $params->{action} + if ($params->{action}//'') =~ /^(show|save_schedule|delete_schedule|show_dates)$/; $checked->{exclude} = 0; - entry::set_numbers( $checked, $params, [ + entry::set_numbers($checked, $params, [ 'id', 'project_id', 'studio_id', 'default_studio_id', 'schedule_id', 'schedule_studio_id' ]); + $checked->{default_studio_id} = $checked->{studio_id} // -1; - if ( ( defined $params->{show_date} ) && ( $params->{show_date} =~ /^(\d\d\d\d)/ ) ) { + if (($params->{show_date}//'') =~ /^(\d\d\d\d)/) { $checked->{show_date} = $1; } else { - my $date = time::date_to_array( time::time_to_date() ); + my $date = time::date_to_array(time::time_to_date()); $checked->{show_date} = $date->[0]; } - if ( defined $checked->{studio_id} ) { - $checked->{default_studio_id} = $checked->{studio_id}; - } else { - $checked->{studio_id} = -1; + entry::set_numbers($checked, $params, ['frequency']); + if ($params->{period_type}eq 'days') { + $checked->{period_type} = $params->{period_type}; + }elsif($params->{period_type}eq 'week_of_month') { + entry::set_numbers($checked, $params, ['weekday', 'week_of_month', 'month']); + $checked->{period_type} = $params->{period_type}; } - $checked->{template} = template::check( $config, $params->{template}, 'studio-timeslots' ); - - entry::set_numbers( $checked, $params, ['frequency'] ); - - for my $attr ( 'start', 'end' ) { - if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\d\d\d\d\-\d\d\-\d\d[ T]\d\d\:\d\d)/ ) ) { - $checked->{$attr} = $1 . ':00'; + for my $attr ('start', 'end') { + if (($params->{$attr}//'') =~ /(\d\d\d\d\-\d\d\-\d\d[ T]\d\d\:\d\d)/) { + $checked->{$attr} = "$1:00"; } } for my $attr ('end_date') { - if ( ( defined $params->{$attr} ) && ( $params->{$attr} =~ /(\d\d\d\d\-\d\d\-\d\d)/ ) ) { + if (($params->{$attr}//'') =~ /(\d\d\d\d\-\d\d\-\d\d)/) { $checked->{$attr} = $1; } } return $checked; } - diff --git a/website/agenda/planung/templates/studio-timeslots.html b/website/agenda/planung/templates/studio-timeslots.html index 2118a8c..cb0ebcb 100644 --- a/website/agenda/planung/templates/studio-timeslots.html +++ b/website/agenda/planung/templates/studio-timeslots.html @@ -21,18 +21,9 @@
- +
-
-
-
-
-
-
-
-
-
@@ -40,11 +31,31 @@ +
-
+
+
+ +
+
-
-
+
+
+ +
+ +
+
+ +
+ +
+
-
-
-
- + +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+ +
+
-
- + >
@@ -75,15 +129,35 @@ -
-
- - +
+ + + +
-
+
+
+ +
+
-
-
+
+
+ +
+ +
+
+ +
+ +
+
-
-
-
- + +
+
+
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+ +
+ +
+ +
+ -
+
+ +
@@ -115,12 +231,12 @@
- +
-
+