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

(-)a/course_reserves/batch_rm_items.pl (+80 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# This file is part of Koha.
4
#
5
# Copyright (C) 2020  Fenway Library Organization
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use CGI qw( -utf8 );
23
use List::MoreUtils qw( uniq );
24
25
use C4::Auth;
26
use C4::Output;
27
use C4::CourseReserves qw(GetItemCourseReservesInfo DelCourseReserve);
28
29
use Koha::Items;
30
31
my $cgi = new CGI;
32
33
my $action    = $cgi->param('action')    || q{};
34
my $barcodes  = $cgi->param('barcodes')  || q{};
35
36
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37
    {
38
        template_name   => "course_reserves/batch_rm_items.tt",
39
        query           => $cgi,
40
        type            => "intranet",
41
        flagsrequired   => { coursereserves => 'delete_reserves' },
42
    }
43
);
44
45
if ( !$action ) {
46
    $template->param( action => 'display_form' );
47
}
48
49
elsif ( $action eq 'batch_rm' ) {
50
    my @barcodes = uniq( split (/\s\n/, $barcodes ) );
51
52
    my @items;
53
    my @invalid_barcodes;
54
    foreach my $bar (@barcodes) {
55
        my $item = Koha::Items->find( { barcode => $bar } );
56
57
        if($item) {
58
            #takes each course item and finds the courses they are attached to
59
            push( @items, $item );
60
            my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
61
            foreach my $cr (@$res_info) {
62
                if($cr->{cr_id}) {
63
                    DelCourseReserve('cr_id' => $cr->{cr_id});
64
                }
65
            }
66
        }
67
        else {
68
            push( @invalid_barcodes, $bar );
69
        }
70
71
    }
72
73
    $template->param(
74
        action => 'display_results',
75
        items_deleted => \@items,
76
        invalid_barcodes => \@invalid_barcodes,
77
    );
78
}
79
80
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_rm_items.tt (+80 lines)
Line 0 Link Here
1
[% SET footerjs = 1 %]
2
3
[% INCLUDE 'doc-head-open.inc' %]
4
<title>Koha &rsaquo; Course reserves &rsaquo; Remove items</title>
5
[% INCLUDE 'doc-head-close.inc' %]
6
</head>
7
<body id="courses_rm_items" class="course">
8
9
[% INCLUDE 'header.inc' %]
10
[% INCLUDE 'cat-search.inc' %]
11
12
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/course_reserves/course-reserves.pl">Course reserves</a> &rsaquo; Batch remove reserves</div>
13
14
<div class="main container-fluid">
15
    <div class="row">
16
        <div class="col-md-8 col-md-offset-2">
17
        [% IF action == 'display_form' %]
18
            <form method="post" action="/cgi-bin/koha/course_reserves/batch_rm_items.pl">
19
                <input type="hidden" name="action" value="batch_rm" />
20
                <fieldset class="rows">
21
                    <legend>Remove items: scan barcodes</legend>
22
                    <ol>
23
                        <li>
24
                            <label class="required" for="barcodes">Item barcodes:</label>
25
                            <textarea rows="20" cols="50" id="barcodes" name="barcodes" class="focus"></textarea>
26
                        </li>
27
                    </ol>
28
                </fieldset>
29
                <fieldset class="action">
30
                    <p>All course reserve items will be deleted from <i>all</i> courses to which they are attached.</p>
31
                    <input type="submit" value="Submit" class="submit" id="batch_rm_btn" />
32
                    <a href="/cgi-bin/koha/course_reserves/course-reserves.pl" class="cancel">Cancel</a>
33
                </fieldset>
34
            </form>
35
        [% END %]
36
37
        [% IF action == 'display_results' %]
38
            <h1>Results</h1>
39
40
            <h3>Items deleted</h3>
41
            [% IF items_deleted.size > 0 %]
42
                <p>The following items were removed from all courses:</p>
43
                <ul>
44
                    [% FOREACH i IN items_deleted %]
45
                        <li>[% i.biblio.title | html %] ( [% i.barcode | html %] )</li>
46
                    [% END %]
47
                </ul>
48
            [% ELSE %]
49
                No valid item barcodes found.
50
            [% END %]
51
52
53
            [% IF invalid_barcodes.size > 0 %]
54
                <h3>Invalid barcodes</h3>
55
                <p>The following invalid barcodes were skipped:</p>
56
                <ul>
57
                    [% FOREACH b IN invalid_barcodes %]
58
                        <li>[% b | html %]</li>
59
                    [% END %]
60
                </ul>
61
            [% END %]
62
63
            <p>
64
                <a class='btn btn-default'  href="/cgi-bin/koha/course_reserves/course-reserves.pl">Return</a>
65
            </p>
66
        [% END %]
67
    </div>
68
</div>
69
70
[% MACRO jsinclude BLOCK %]
71
    <script>
72
        $(document).ready(function() {
73
            $("#batch_rm_btn").click(function(){
74
                return confirmDelete(_("Are you sure you want to remove these items from all courses?"));
75
            });
76
        });
77
    </script>
78
[% END %]
79
80
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-reserves.tt (-2 / +4 lines)
Lines 20-30 Link Here
20
        <div class="row">
20
        <div class="row">
21
            <div class="col-md-10 col-md-offset-1">
21
            <div class="col-md-10 col-md-offset-1">
22
22
23
                    [% IF CAN_user_coursereserves_add_reserves OR CAN_user_coursereserves_manage_courses OR CAN_user_coursereserves_manage_courses %]
23
                    [% IF CAN_user_coursereserves_add_reserves OR CAN_user_coursereserves_manage_courses OR CAN_user_coursereserves_manage_courses OR CAN_user_coursereserves_delete_reserves %]
24
                    <div id="toolbar">
24
                    <div id="toolbar">
25
                        [% IF ( CAN_user_coursereserves_manage_courses ) %]
25
                        [% IF ( CAN_user_coursereserves_manage_courses ) %]
26
                            <a class="btn btn-default" id="new_course" href="/cgi-bin/koha/course_reserves/course.pl"><i class="fa fa-plus"></i> New course</a>
26
                            <a class="btn btn-default" id="new_course" href="/cgi-bin/koha/course_reserves/course.pl"><i class="fa fa-plus"></i> New course</a>
27
                        [% END %]
27
                        [% END %]
28
                        [% IF ( CAN_user_coursereserves_delete_reserves ) %]
29
                            <a class="btn btn-default" id="batch_rm" href="/cgi-bin/koha/course_reserves/batch_rm_items.pl"><i class="fa fa-minus"></i> Batch remove items</a>
30
                        [% END %]
28
                    </div><!-- /toolbar -->
31
                    </div><!-- /toolbar -->
29
                    [% END %]
32
                    [% END %]
30
33
31
- 

Return to bug 14648