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 181-186 Link Here
181
            options['dateFormat'] = "Y-m-d H:i";
181
            options['dateFormat'] = "Y-m-d H:i";
182
            options['altFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
182
            options['altFormat'] = flatpickr_dateformat_string + " " + flatpickr_timeformat_string;
183
        }
183
        }
184
        if( $(input).data("flatpickr-time-only") === true ) {
185
            options['enableTime'] = true;
186
            options['noCalendar'] = true;
187
            options['dateFormat'] = "H:i";
188
            options['altFormat'] = flatpickr_timeformat_string;
189
            options['plugins'] = [];
190
        }
184
191
185
        let fp = $(input).flatpickr(options);
192
        let fp = $(input).flatpickr(options);
186
193
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt (-45 / +58 lines)
Lines 300-342 Link Here
300
                            </tr>
300
                            </tr>
301
                        </thead>
301
                        </thead>
302
                        <tbody>
302
                        <tbody>
303
                            [% IF library.library_hours # Existing library %]
303
                            [% SET CalendarFirstDayOfWeek = Koha.Preference("CalendarFirstDayOfWeek") %]
304
                                [% daycount = 0 %]
304
                            [% IF library.library_hours.count > 0 # Existing hours %]
305
                                [% FOREACH hr IN library.library_hours %]
305
                                [% SET library_hours = library.library_hours.as_list %]
306
                                <tr id="hours_[% daycount | html %]">
306
307
                                [% FOR i IN [0..6] %]
308
                                [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
309
                                [% SET hr = library_hours.$d %]
310
                                <tr id="hours_[% d | html %]">
307
                                    <td>
311
                                    <td>
308
                                        [% PROCESS dayname day=daycount %]
312
                                        [% PROCESS dayname day=d %]
309
                                        <input type="hidden" value="[% daycount | html %]" name="day">
313
                                        <input type="hidden" value="[% d | html %]" name="day">
310
                                    </td>
314
                                    </td>
311
                                    <td>
315
                                    <td>
312
                                        [% IF hr.day == daycount && hr.open_time %]
316
                                        [% IF hr.open_time %]
313
                                        <input type="time" value="[% hr.open_time | html %]" name="open_time">
317
                                        <input type="text" size="5" value="[% hr.open_time | html %]" name="open_time" class="flatpickr" data-flatpickr-time-only="true">
314
                                        [% ELSE %]
318
                                        [% ELSE %]
315
                                        <input type="time" value="" name="open_time">
319
                                        <input type="text" size="5" value="" name="open_time" class="flatpickr" data-flatpickr-time-only="true">
316
                                        [% END %]
320
                                        [% END %]
317
                                    </td>
321
                                    </td>
318
                                    <td>
322
                                    <td>
319
                                        [% IF hr.day == daycount && hr.close_time %]
323
                                        [% IF hr.close_time %]
320
                                        <input type="time" value="[% hr.close_time | html %]" name="close_time">
324
                                        <input type="text" size="5" value="[% hr.close_time | html %]" name="close_time" class="flatpickr" data-flatpickr-time-only="true">
321
                                        [% ELSE %]
325
                                        [% ELSE %]
322
                                        <input type="time" value="" name="close_time">
326
                                        <input type="text" size="5" value="" name="close_time" class="flatpickr" data-flatpickr-time-only="true">
323
                                        [% END %]
327
                                        [% END %]
324
                                    </td>
328
                                    </td>
325
                                </tr>
329
                                </tr>
326
                                [% daycount = daycount+1 %]
327
                                [% END %]
330
                                [% END %]
328
                            [% ELSE # New library %]
331
                            [% ELSE # New hours %]
329
                                [% FOREACH daycount IN [0..6] %]
332
                                [% FOR i IN [0..6] %]
330
                                <tr id="hours_[% day | html %]">
333
                                [% SET d = ( CalendarFirstDayOfWeek + i ) % 7 %]
334
                                <tr id="hours_[% d | html %]">
331
                                    <td>
335
                                    <td>
332
                                        [% PROCESS dayname day=daycount %]
336
                                        [% PROCESS dayname day=d %]
333
                                        <input type="hidden" value="[% daycount | html %]" name="day">
337
                                        <input type="hidden" value="[% d | html %]" name="day">
334
                                    </td>
338
                                    </td>
335
                                    <td>
339
                                    <td>
336
                                        <input type="time" value="" name="open_time">
340
                                        <input type="text" size="5" name="open_time" class="noEnterSubmit flatpickr" data-flatpickr-time-only="true">
337
                                    </td>
341
                                    </td>
338
                                    <td>
342
                                    <td>
339
                                        <input type="time" value="" name="close_time">
343
                                        <input type="text" size="5" name="close_time" class="noEnerSubmit flatpickr" data-flatpickr-time-only="true">
340
                                    </td>
344
                                    </td>
341
                                </tr>
345
                                </tr>
342
                                [% END %]
346
                                [% END %]
Lines 371-389 Link Here
371
375
372
[% BLOCK dayname %]
376
[% BLOCK dayname %]
373
    [% IF day == 0 %]
377
    [% IF day == 0 %]
374
    <span>Monday</span>
378
    <span>Sunday</span>
375
    [% ELSIF day == 1 %]
379
    [% ELSIF day == 1 %]
376
    <span>Tuesday</span>
380
    <span>Monday</span>
377
    [% ELSIF day == 2 %]
381
    [% ELSIF day == 2 %]
378
    <span>Wednesday</span>
382
    <span>Tuesday</span>
379
    [% ELSIF day == 3 %]
383
    [% ELSIF day == 3 %]
380
    <span>Thursday</span>
384
    <span>Wednesday</span>
381
    [% ELSIF day == 4 %]
385
    [% ELSIF day == 4 %]
382
    <span>Friday</span>
386
    <span>Thursday</span>
383
    [% ELSIF day == 5 %]
387
    [% ELSIF day == 5 %]
384
    <span>Saturday</span>
388
    <span>Friday</span>
385
    [% ELSE %]
389
    [% ELSE %]
386
    <span>Sunday</span>
390
    <span>Saturday</span>
387
    [% END %]
391
    [% END %]
388
[% END %]
392
[% END %]
389
393
Lines 550-556 Link Here
550
                    </li>
554
                    </li>
551
                    <li>
555
                    <li>
552
                        <span class="label">Opening hours: </span>
556
                        <span class="label">Opening hours: </span>
553
                        [% IF library.library_hours # Existing library %]
557
                        [% IF library.library_hours.count > 0 # Existing library %]
558
                            [% SET library_hours = library.library_hours.as_list %]
554
                            <table id="library_hours_table">
559
                            <table id="library_hours_table">
555
                                <thead>
560
                                <thead>
556
                                    <tr>
561
                                    <tr>
Lines 560-570 Link Here
560
                                    </tr>
565
                                    </tr>
561
                                </thead>
566
                                </thead>
562
                                <tbody>
567
                                <tbody>
563
                                    [% daycount = 0 %]
568
                                    [% FOR i IN [0..6] %]
564
                                    [% FOREACH hr IN library.library_hours %]
569
                                    [% SET d = ( CalendarFirstDayOfWeek + i) % 7 %]
565
                                    <tr id="hours_[% daycount | html %]">
570
                                    [% SET hr = library_hours.$d %]
571
                                    <tr id="hours_[% d | html %]">
566
                                        <td>
572
                                        <td>
567
                                            <span>[% PROCESS dayname day=daycount %]</span>
573
                                            <span>[% PROCESS dayname day=d %]</span>
568
                                        </td>
574
                                        </td>
569
                                        <td>
575
                                        <td>
570
                                            <span>[% hr.open_time | html %]</span>
576
                                            <span>[% hr.open_time | html %]</span>
Lines 573-579 Link Here
573
                                            <span>[% hr.close_time | html %]</span>
579
                                            <span>[% hr.close_time | html %]</span>
574
                                        </td>
580
                                        </td>
575
                                    </tr>
581
                                    </tr>
576
                                    [% daycount = daycount+1 %]
577
                                    [% END %]
582
                                    [% END %]
578
                                </tbody>
583
                                </tbody>
579
                            </table>
584
                            </table>
Lines 609-614 Link Here
609
614
610
[% MACRO jsinclude BLOCK %]
615
[% MACRO jsinclude BLOCK %]
611
    [% Asset.js("js/admin-menu.js") | $raw %]
616
    [% Asset.js("js/admin-menu.js") | $raw %]
617
    [% INCLUDE 'calendar.inc' %]
612
    [% INCLUDE 'datatables.inc' %]
618
    [% INCLUDE 'datatables.inc' %]
613
    [% INCLUDE 'columns_settings.inc' %]
619
    [% INCLUDE 'columns_settings.inc' %]
614
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
620
    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
Lines 638-643 Link Here
638
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
644
        var table_settings = [% TablesSettings.GetTableSettings( 'admin', 'libraries', 'libraries', 'json' ) | $raw %];
639
        var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
645
        var saved_table = localStorage.getItem("DataTables_libraries_/cgi-bin/koha/admin/branches.pl");
640
        var updated_settings = get_columns_saved_state(saved_table, table_settings);
646
        var updated_settings = get_columns_saved_state(saved_table, table_settings);
647
        var calendarFirstDayOfWeek = '[% Koha.Preference('CalendarFirstDayOfWeek') | html %]';
641
648
642
        $(document).ready(function() {
649
        $(document).ready(function() {
643
650
Lines 747-764 Link Here
747
                    },
754
                    },
748
                    {
755
                    {
749
                        "data": function( row, type, val, meta ) {
756
                        "data": function( row, type, val, meta ) {
750
                            const daynames = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
757
                            let result = '';
751
                            var daycount = 0;
758
                            if ( row.library_hours.length > 0 ) {
752
                            var result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
759
                                const daysOfWeek = [ _("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday") ];
753
                            while ( row.library_hours[daycount] ) {
760
754
                                result += '<tr id="hours_'+daycount+'">';
761
                                result = '<table id="library_hours_table"><thead><tr><th>Day</th><th>Open time</th><th>Close time</th></tr></thead><tbody>';
755
                                result += '<td>'+daynames[daycount]+'</td>';
762
                                let counter = 0;
756
                                result += '<td><span>'+row.library_hours[daycount].open_time+'</span></td>';
763
                                for (let i = calendarFirstDayOfWeek; counter < 7; i++) {
757
                                result += '<td><span>'+row.library_hours[daycount].close_time+'</span></td>';
764
                                    const day = i % 7; // Wrap around the day using modulo operator
758
                                result += '</tr>';
765
                                    result += '<tr id="hours_'+day+'">';
759
                                daycount++;
766
                                    result += '<td>'+daysOfWeek[day]+'</td>';
767
                                    result += '<td><span>'+row.library_hours[day].open_time+'</span></td>';
768
                                    result += '<td><span>'+row.library_hours[day].close_time+'</span></td>';
769
                                    result += '</tr>';
770
                                    counter++;
771
                                }
772
                                result += '</tbody></table>';
773
                            } else {
774
                                result = _("Library hours not set");
760
                            }
775
                            }
761
                            result += '</tbody></table>';
762
                            return result;
776
                            return result;
763
                        },
777
                        },
764
                        "searchable": false,
778
                        "searchable": false,
765
- 

Return to bug 6796