View | Details | Raw Unified | Return to bug 6796
Collapse All | Expand All

(-)a/admin/branches.pl (-21 / +38 lines)
Lines 102-136 if ( $op eq 'add_form' ) { Link Here
102
            Koha::Database->new->schema->txn_do(
102
            Koha::Database->new->schema->txn_do(
103
                sub {
103
                sub {
104
                    $library->store->discard_changes;
104
                    $library->store->discard_changes;
105
105
                    # Deal with SMTP server
106
                    # Deal with SMTP server
106
                    my $smtp_server_id = $input->param('smtp_server');
107
                    my $smtp_server_id = $input->param('smtp_server');
107
108
108
                    if ( $smtp_server_id ) {
109
                    if ($smtp_server_id) {
109
                        if ( $smtp_server_id eq '*' ) {
110
                        if ( $smtp_server_id eq '*' ) {
110
                            $library->smtp_server({ smtp_server => undef });
111
                            $library->smtp_server( { smtp_server => undef } );
111
                        }
112
                        } else {
112
                        else {
113
                            my $smtp_server = Koha::SMTP::Servers->find($smtp_server_id);
113
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
114
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
114
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
115
                                unless $smtp_server;
115
                                unless $smtp_server;
116
                            $library->smtp_server({ smtp_server => $smtp_server });
116
                            $library->smtp_server( { smtp_server => $smtp_server } );
117
                        }
117
                        }
118
                    }
118
                    }
119
119
120
                    # Deal with opening hours
120
                    my @days        = $input->multi_param("day");
121
                    my @days        = $input->multi_param("day");
121
                    my @open_times  = $input->multi_param("open_time");
122
                    my @open_times  = $input->multi_param("open_time");
122
                    my @close_times = $input->multi_param("close_time");
123
                    my @close_times = $input->multi_param("close_time");
123
124
125
                    my $index = 0;
124
                    foreach my $day (@days) {
126
                    foreach my $day (@days) {
125
                        if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
127
                        if ( $open_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
126
                            $open_times[$day] = undef;
128
                            $open_times[$index] = undef;
127
                        }
129
                        }
128
                        if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
130
                        if ( $close_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
129
                            $close_times[$day] = undef;
131
                            $close_times[$index] = undef;
130
                        }
132
                        }
131
133
132
                        my $openday = Koha::Library::Hours->find( { library_id => $branchcode, day => $day } )
134
                        my $openday = Koha::Library::Hours->find( { library_id => $branchcode, day => $day } );
133
                            ->update( { open_time => $open_times[$day], close_time => $close_times[$day] } );
135
                        if ($openday) {
136
                            $openday->update(
137
                                { open_time => $open_times[$index], close_time => $close_times[$index] } );
138
                        } else {
139
                            $openday = Koha::Library::Hour->new(
140
                                {
141
                                    library_id => $branchcode, day => $day, open_time => $open_times[$index],
142
                                    close_time => $close_times[$index]
143
                                }
144
                            )->store;
145
                        }
146
                        $index++;
134
                    }
147
                    }
135
148
136
                    push @messages, { type => 'message', code => 'success_on_update' };
149
                    push @messages, { type => 'message', code => 'success_on_update' };
Lines 162-194 if ( $op eq 'add_form' ) { Link Here
162
175
163
                    my $smtp_server_id = $input->param('smtp_server');
176
                    my $smtp_server_id = $input->param('smtp_server');
164
177
165
                    if ( $smtp_server_id ) {
178
                    # Deal with SMTP server
179
                    if ($smtp_server_id) {
166
                        if ( $smtp_server_id ne '*' ) {
180
                        if ( $smtp_server_id ne '*' ) {
167
                            my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id );
181
                            my $smtp_server = Koha::SMTP::Servers->find($smtp_server_id);
168
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
182
                            Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' )
169
                                unless $smtp_server;
183
                                unless $smtp_server;
170
                            $library->smtp_server({ smtp_server => $smtp_server });
184
                            $library->smtp_server( { smtp_server => $smtp_server } );
171
                        }
185
                        }
172
                    }
186
                    }
173
187
188
                    # Deal with opening hours
174
                    my @days        = $input->multi_param("day");
189
                    my @days        = $input->multi_param("day");
175
                    my @open_times  = $input->multi_param("open_time");
190
                    my @open_times  = $input->multi_param("open_time");
176
                    my @close_times = $input->multi_param("close_time");
191
                    my @close_times = $input->multi_param("close_time");
177
192
193
                    my $index = 0;
178
                    foreach my $day (@days) {
194
                    foreach my $day (@days) {
179
                        if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
195
                        if ( $open_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
180
                            $open_times[$day] = undef;
196
                            $open_times[$index] = undef;
181
                        }
197
                        }
182
                        if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) {
198
                        if ( $close_times[$index] !~ /([0-9]{2}:[0-9]{2})/ ) {
183
                            $close_times[$day] = undef;
199
                            $close_times[$index] = undef;
184
                        }
200
                        }
185
201
186
                        my $openday = Koha::Library::Hour->new(
202
                        my $openday = Koha::Library::Hour->new(
187
                            {
203
                            {
188
                                library_id => $branchcode, day => $day, open_time => $open_times[$day],
204
                                library_id => $branchcode, day => $day, open_time => $open_times[$index],
189
                                close_time => $close_times[$day]
205
                                close_time => $close_times[$index]
190
                            }
206
                            }
191
                        )->store;
207
                        )->store;
208
                        $index++;
192
                    }
209
                    }
193
210
194
                    push @messages, { type => 'message', code => 'success_on_insert' };
211
                    push @messages, { type => 'message', code => 'success_on_insert' };
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc (+7 lines)
Lines 188-193 Link Here
188
        if( typeof maxDate !== 'undefined' ) {
188
        if( typeof maxDate !== 'undefined' ) {
189
            options['maxDate'] = new Date(maxDate);
189
            options['maxDate'] = new Date(maxDate);
190
        }
190
        }
191
        if( $(input).data("flatpickr-time-only") === true ) {
192
            options['enableTime'] = true;
193
            options['noCalendar'] = true;
194
            options['dateFormat'] = "H:i";
195
            options['altFormat'] = flatpickr_timeformat_string;
196
            options['plugins'] = [];
197
        }
191
198
192
        let fp = $(input).flatpickr(options);
199
        let fp = $(input).flatpickr(options);
193
200
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-45 / +58 lines)
Lines 301-343 Link Here
301
                            </tr>
301
                            </tr>
302
                        </thead>
302
                        </thead>
303
                        <tbody>
303
                        <tbody>
304
                            [% IF library.library_hours # Existing library %]
304
                            [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %]
305
                                [% daycount = 0 %]
305
                            [% IF library.library_hours.count > 0 # Existing hours %]
306
                                [% FOREACH hr IN library.library_hours %]
306
                                [% SET library_hours = library.library_hours.as_list %]
307
                                <tr id="hours_[% daycount | html %]">
307
308
                                [% FOR i IN [0..6] %]
309
                                [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
310
                                [% SET hr = library_hours.$d %]
311
                                <tr id="hours_[% d | html %]">
308
                                    <td>
312
                                    <td>
309
                                        [% PROCESS dayname day=daycount %]
313
                                        [% PROCESS dayname day=d %]
310
                                        <input type="hidden" value="[% daycount | html %]" name="day">
314
                                        <input type="hidden" value="[% d | html %]" name="day">
311
                                    </td>
315
                                    </td>
312
                                    <td>
316
                                    <td>
313
                                        [% IF hr.day == daycount && hr.open_time %]
317
                                        [% IF hr.open_time %]
314
                                        <input type="time" value="[% hr.open_time | html %]" name="open_time">
318
                                        <input type="text" size="5" value="[% hr.open_time | html %]" name="open_time" class="flatpickr" data-flatpickr-time-only="true">
315
                                        [% ELSE %]
319
                                        [% ELSE %]
316
                                        <input type="time" value="" name="open_time">
320
                                        <input type="text" size="5" value="" name="open_time" class="flatpickr" data-flatpickr-time-only="true">
317
                                        [% END %]
321
                                        [% END %]
318
                                    </td>
322
                                    </td>
319
                                    <td>
323
                                    <td>
320
                                        [% IF hr.day == daycount && hr.close_time %]
324
                                        [% IF hr.close_time %]
321
                                        <input type="time" value="[% hr.close_time | html %]" name="close_time">
325
                                        <input type="text" size="5" value="[% hr.close_time | html %]" name="close_time" class="flatpickr" data-flatpickr-time-only="true">
322
                                        [% ELSE %]
326
                                        [% ELSE %]
323
                                        <input type="time" value="" name="close_time">
327
                                        <input type="text" size="5" value="" name="close_time" class="flatpickr" data-flatpickr-time-only="true">
324
                                        [% END %]
328
                                        [% END %]
325
                                    </td>
329
                                    </td>
326
                                </tr>
330
                                </tr>
327
                                [% daycount = daycount+1 %]
328
                                [% END %]
331
                                [% END %]
329
                            [% ELSE # New library %]
332
                            [% ELSE # New hours %]
330
                                [% FOREACH daycount IN [0..6] %]
333
                                [% FOR i IN [0..6] %]
331
                                <tr id="hours_[% day | html %]">
334
                                [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
335
                                <tr id="hours_[% d | html %]">
332
                                    <td>
336
                                    <td>
333
                                        [% PROCESS dayname day=daycount %]
337
                                        [% PROCESS dayname day=d %]
334
                                        <input type="hidden" value="[% daycount | html %]" name="day">
338
                                        <input type="hidden" value="[% d | html %]" name="day">
335
                                    </td>
339
                                    </td>
336
                                    <td>
340
                                    <td>
337
                                        <input type="time" value="" name="open_time">
341
                                        <input type="text" size="5" name="open_time" class="noEnterSubmit flatpickr" data-flatpickr-time-only="true">
338
                                    </td>
342
                                    </td>
339
                                    <td>
343
                                    <td>
340
                                        <input type="time" value="" name="close_time">
344
                                        <input type="text" size="5" name="close_time" class="noEnerSubmit flatpickr" data-flatpickr-time-only="true">
341
                                    </td>
345
                                    </td>
342
                                </tr>
346
                                </tr>
343
                                [% END %]
347
                                [% END %]
Lines 372-390 Link Here
372
376
373
[% BLOCK dayname %]
377
[% BLOCK dayname %]
374
    [% IF day == 0 %]
378
    [% IF day == 0 %]
375
    <span>Monday</span>
379
    <span>Sunday</span>
376
    [% ELSIF day == 1 %]
380
    [% ELSIF day == 1 %]
377
    <span>Tuesday</span>
381
    <span>Monday</span>
378
    [% ELSIF day == 2 %]
382
    [% ELSIF day == 2 %]
379
    <span>Wednesday</span>
383
    <span>Tuesday</span>
380
    [% ELSIF day == 3 %]
384
    [% ELSIF day == 3 %]
381
    <span>Thursday</span>
385
    <span>Wednesday</span>
382
    [% ELSIF day == 4 %]
386
    [% ELSIF day == 4 %]
383
    <span>Friday</span>
387
    <span>Thursday</span>
384
    [% ELSIF day == 5 %]
388
    [% ELSIF day == 5 %]
385
    <span>Saturday</span>
389
    <span>Friday</span>
386
    [% ELSE %]
390
    [% ELSE %]
387
    <span>Sunday</span>
391
    <span>Saturday</span>
388
    [% END %]
392
    [% END %]
389
[% END %]
393
[% END %]
390
394
Lines 552-558 Link Here
552
                    </li>
556
                    </li>
553
                    <li>
557
                    <li>
554
                        <span class="label">Opening hours: </span>
558
                        <span class="label">Opening hours: </span>
555
                        [% IF library.library_hours # Existing library %]
559
                        [% IF library.library_hours.count > 0 # Existing library %]
560
                            [% SET library_hours = library.library_hours.as_list %]
556
                            <table id="library_hours_table">
561
                            <table id="library_hours_table">
557
                                <thead>
562
                                <thead>
558
                                    <tr>
563
                                    <tr>
Lines 562-572 Link Here
562
                                    </tr>
567
                                    </tr>
563
                                </thead>
568
                                </thead>
564
                                <tbody>
569
                                <tbody>
565
                                    [% daycount = 0 %]
570
                                    [% FOR i IN [0..6] %]
566
                                    [% FOREACH hr IN library.library_hours %]
571
                                    [% SET d = ( CalendarFirstDayOfWeek + i) % 7 %]
567
                                    <tr id="hours_[% daycount | html %]">
572
                                    [% SET hr = library_hours.$d %]
573
                                    <tr id="hours_[% d | html %]">
568
                                        <td>
574
                                        <td>
569
                                            <span>[% PROCESS dayname day=daycount %]</span>
575
                                            <span>[% PROCESS dayname day=d %]</span>
570
                                        </td>
576
                                        </td>
571
                                        <td>
577
                                        <td>
572
                                            <span>[% hr.open_time | html %]</span>
578
                                            <span>[% hr.open_time | html %]</span>
Lines 575-581 Link Here
575
                                            <span>[% hr.close_time | html %]</span>
581
                                            <span>[% hr.close_time | html %]</span>
576
                                        </td>
582
                                        </td>
577
                                    </tr>
583
                                    </tr>
578
                                    [% daycount = daycount+1 %]
579
                                    [% END %]
584
                                    [% END %]
580
                                </tbody>
585
                                </tbody>
581
                            </table>
586
                            </table>
Lines 611-616 Link Here
611
616
612
[% MACRO jsinclude BLOCK %]
617
[% MACRO jsinclude BLOCK %]
613
    [% Asset.js("js/admin-menu.js") | $raw %]
618
    [% Asset.js("js/admin-menu.js") | $raw %]
619
    [% INCLUDE 'calendar.inc' %]
614
    [% INCLUDE 'datatables.inc' %]
620
    [% INCLUDE 'datatables.inc' %]
615
    [% INCLUDE 'columns_settings.inc' %]
621
    [% INCLUDE 'columns_settings.inc' %]
616
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
622
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
Lines 640-645 Link Here
640
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
646
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
641
        var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
647
        var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
642
        var updated_settings = get_columns_saved_state(saved_table, table_settings);
648
        var updated_settings = get_columns_saved_state(saved_table, table_settings);
649
        var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
643
650
644
        $(document).ready(function() {
651
        $(document).ready(function() {
645
652
Lines 749-766 Link Here
749
                    },
756
                    },
750
                    {
757
                    {
751
                        "data": function( row, type, val, meta ) {
758
                        "data": function( row, type, val, meta ) {
752
                            const daynames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
759
                            let result = '';
753
                            var daycount = 0;
760
                            if ( row.library_hours.length > 0 ) {
754
                            var result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
761
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
755
                            while ( row.library_hours[daycount] ) {
762
756
                                result += '<tr id="hours_'+daycount+'">';
763
                                result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
757
                                result += '<td>'+daynames[daycount]+'</td>';
764
                                let counter = 0;
758
                                result += '<td><span>'+row.library_hours[daycount].open_time+'</span></td>';
765
                                for (let i = calendarFirstDayOfWeek; counter < 7; i++) {
759
                                result += '<td><span>'+row.library_hours[daycount].close_time+'</span></td>';
766
                                    const day = i % 7; // Wrap around the day using modulo operator
760
                                result += '</tr>';
767
                                    result += '<tr id="hours_'+day+'">';
761
                                daycount++;
768
                                    result += '<td>'+daysOfWeek[day]+'</td>';
769
                                    result += '<td><span>'+row.library_hours[day].open_time+'</span></td>';
770
                                    result += '<td><span>'+row.library_hours[day].close_time+'</span></td>';
771
                                    result += '</tr>';
772
                                    counter++;
773
                                }
774
                                result += '</tbody></table>';
775
                            } else {
776
                                result = _("Library hours not set");
762
                            }
777
                            }
763
                            result += '</tbody></table>';
764
                            return result;
778
                            return result;
765
                        },
779
                        },
766
                        "searchable": false,
780
                        "searchable": false,
767
- 

Return to bug 6796