diff --git a/admin/branches.pl b/admin/branches.pl
index 0e5d9ab33b..b6d705cd18 100755
--- a/admin/branches.pl
+++ b/admin/branches.pl
@@ -102,35 +102,48 @@ if ( $op eq 'add_form' ) {
Koha::Database->new->schema->txn_do(
sub {
$library->store->discard_changes;
+
# Deal with SMTP server
my $smtp_server_id = $input->param('smtp_server');
- if ( $smtp_server_id ) {
+ if ($smtp_server_id) {
if ( $smtp_server_id eq '*' ) {
- $library->smtp_server({ smtp_server => undef });
- }
- else {
- my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
+ $library->smtp_server( { smtp_server => undef } );
+ } else {
+ my $smtp_server = Koha::SMTP::Servers->find($smtp_server_id);
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
unless $smtp_server;
- $library->smtp_server({ smtp_server => $smtp_server });
+ $library->smtp_server( { smtp_server => $smtp_server } );
}
}
+ # Deal with opening hours
my @days = $input->multi_param("day");
my @open_times = $input->multi_param("open_time");
my @close_times = $input->multi_param("close_time");
+ my $index = 0;
foreach my $day (@days) {
- if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
- $open_times[$day] = undef;
+ if ( $open_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
+ $open_times[$index] = undef;
}
- if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
- $close_times[$day] = undef;
+ if ( $close_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
+ $close_times[$index] = undef;
}
- my $openday = Koha::Library::Hours->find( { library_id => $branchcode, day => $day } )
- ->update( { open_time => $open_times[$day], close_time => $close_times[$day] } );
+ my $openday = Koha::Library::Hours->find( { library_id => $branchcode, day => $day } );
+ if ($openday) {
+ $openday->update(
+ { open_time => $open_times[$index], close_time => $close_times[$index] } );
+ } else {
+ $openday = Koha::Library::Hour->new(
+ {
+ library_id => $branchcode, day => $day, open_time => $open_times[$index],
+ close_time => $close_times[$index]
+ }
+ )->store;
+ }
+ $index++;
}
push @messages, { type => 'message', code => 'success_on_update' };
@@ -162,33 +175,37 @@ if ( $op eq 'add_form' ) {
my $smtp_server_id = $input->param('smtp_server');
- if ( $smtp_server_id ) {
+ # Deal with SMTP server
+ if ($smtp_server_id) {
if ( $smtp_server_id ne '*' ) {
- my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
+ my $smtp_server = Koha::SMTP::Servers->find($smtp_server_id);
Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
unless $smtp_server;
- $library->smtp_server({ smtp_server => $smtp_server });
+ $library->smtp_server( { smtp_server => $smtp_server } );
}
}
+ # Deal with opening hours
my @days = $input->multi_param("day");
my @open_times = $input->multi_param("open_time");
my @close_times = $input->multi_param("close_time");
+ my $index = 0;
foreach my $day (@days) {
- if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
- $open_times[$day] = undef;
+ if ( $open_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
+ $open_times[$index] = undef;
}
- if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
- $close_times[$day] = undef;
+ if ( $close_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
+ $close_times[$index] = undef;
}
my $openday = Koha::Library::Hour->new(
{
- library_id => $branchcode, day => $day, open_time => $open_times[$day],
- close_time => $close_times[$day]
+ library_id => $branchcode, day => $day, open_time => $open_times[$index],
+ close_time => $close_times[$index]
}
)->store;
+ $index++;
}
push @messages, { type => 'message', code => 'success_on_insert' };
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
index a3d213675c..ac1525fa32 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc
@@ -188,6 +188,13 @@
if( typeof maxDate !== 'undefined' ) {
options['maxDate'] = new Date(maxDate);
}
+ if( $(input).data("flatpickr-time-only") === true ) {
+ options['enableTime'] = true;
+ options['noCalendar'] = true;
+ options['dateFormat'] = "H:i";
+ options['altFormat'] = flatpickr_timeformat_string;
+ options['plugins'] = [];
+ }
let fp = $(input).flatpickr(options);
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
index 741a710cb0..37afcd259b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt
@@ -301,43 +301,47 @@
- [% IF library.library_hours # Existing library %]
- [% daycount = 0 %]
- [% FOREACH hr IN library.library_hours %]
-
+ [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %]
+ [% IF library.library_hours.count > 0 # Existing hours %]
+ [% SET library_hours = library.library_hours.as_list %]
+
+ [% FOR i IN [0..6] %]
+ [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
+ [% SET hr = library_hours.$d %]
+
- [% PROCESS dayname day=daycount %]
-
+ [% PROCESS dayname day=d %]
+
- [% IF hr.day == daycount && hr.open_time %]
-
+ [% IF hr.open_time %]
+
[% ELSE %]
-
+
[% END %]
- [% IF hr.day == daycount && hr.close_time %]
-
+ [% IF hr.close_time %]
+
[% ELSE %]
-
+
[% END %]
- [% daycount = daycount+1 %]
[% END %]
- [% ELSE # New library %]
- [% FOREACH daycount IN [0..6] %]
-
+ [% ELSE # New hours %]
+ [% FOR i IN [0..6] %]
+ [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
+
- [% PROCESS dayname day=daycount %]
-
+ [% PROCESS dayname day=d %]
+
-
+
-
+
[% END %]
@@ -372,19 +376,19 @@
[% BLOCK dayname %]
[% IF day == 0 %]
- Monday
- [% ELSIF day == 1 %]
- Tuesday
- [% ELSIF day == 2 %]
- Wednesday
- [% ELSIF day == 3 %]
- Thursday
- [% ELSIF day == 4 %]
- Friday
- [% ELSIF day == 5 %]
- Saturday
- [% ELSE %]
Sunday
+ [% ELSIF day == 1 %]
+ Monday
+ [% ELSIF day == 2 %]
+ Tuesday
+ [% ELSIF day == 3 %]
+ Wednesday
+ [% ELSIF day == 4 %]
+ Thursday
+ [% ELSIF day == 5 %]
+ Friday
+ [% ELSE %]
+ Saturday
[% END %]
[% END %]
@@ -552,7 +556,8 @@
Opening hours:
- [% IF library.library_hours # Existing library %]
+ [% IF library.library_hours.count > 0 # Existing library %]
+ [% SET library_hours = library.library_hours.as_list %]
@@ -562,11 +567,12 @@
- [% daycount = 0 %]
- [% FOREACH hr IN library.library_hours %]
-
+ [% FOR i IN [0..6] %]
+ [% SET d = ( CalendarFirstDayOfWeek + i) % 7 %]
+ [% SET hr = library_hours.$d %]
+
- [% PROCESS dayname day=daycount %]
+ [% PROCESS dayname day=d %]
[% hr.open_time | html %]
@@ -575,7 +581,6 @@
[% hr.close_time | html %]
- [% daycount = daycount+1 %]
[% END %]
@@ -611,6 +616,7 @@
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/admin-menu.js") | $raw %]
+ [% INCLUDE 'calendar.inc' %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'columns_settings.inc' %]
[% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
@@ -640,6 +646,7 @@
var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
var updated_settings = get_columns_saved_state(saved_table, table_settings);
+ var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
$(document).ready(function() {
@@ -749,18 +756,25 @@
},
{
"data": function( row, type, val, meta ) {
- const daynames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
- var daycount = 0;
- var result = 'Day Open time Close time ';
- while ( row.library_hours[daycount] ) {
- result += '';
- result += ''+daynames[daycount]+' ';
- result += ''+row.library_hours[daycount].open_time+' ';
- result += ''+row.library_hours[daycount].close_time+' ';
- result += ' ';
- daycount++;
+ let result = '';
+ if ( row.library_hours.length > 0 ) {
+ const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
+
+ result = 'Day Open time Close time ';
+ let counter = 0;
+ for (let i = calendarFirstDayOfWeek; counter < 7; i++) {
+ const day = i % 7; // Wrap around the day using modulo operator
+ result += '';
+ result += ''+daysOfWeek[day]+' ';
+ result += ''+row.library_hours[day].open_time+' ';
+ result += ''+row.library_hours[day].close_time+' ';
+ result += ' ';
+ counter++;
+ }
+ result += '
';
+ } else {
+ result = _("Library hours not set");
}
- result += '
';
return result;
},
"searchable": false,