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

(-)a/course_reserves/batch_rm_items.pl (+90 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 GetCourseItem);
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
    my @invalid_barcodes;
52
    my @item_and_count;
53
54
    foreach my $bar (@barcodes) {
55
        my $item = Koha::Items->find( { barcode => $bar } );
56
        if($item) {
57
            my $courseitem = GetCourseItem(itemnumber => $item->id);
58
            if($courseitem) {
59
60
                my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
61
62
                my $no_of_res = @$res_info;
63
64
                my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res};
65
                push ( @item_and_count, $delitemcount );
66
67
                foreach my $cr (@$res_info) {
68
                    if($cr->{cr_id}) {
69
                        DelCourseReserve('cr_id' => $cr->{cr_id});
70
                    }
71
                }
72
            }
73
            else {
74
                push( @invalid_barcodes, $bar);
75
            }
76
        }
77
        else {
78
            push( @invalid_barcodes, $bar );
79
        }
80
81
    }
82
83
    $template->param(
84
        action => 'display_results',
85
        invalid_barcodes => \@invalid_barcodes,
86
        item_and_count => \@item_and_count,
87
    );
88
}
89
90
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_rm_items.tt (+84 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 all 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 item_and_count > 0 %]
42
                <p>The following items were removed from all courses:</p>
43
                <ul>
44
                    [% FOREACH i IN item_and_count %]
45
                      [% IF i.delcount == 1 %]
46
                          <li>[% i.delitem.biblio.title | html %] ([% i.delitem.barcode | html %]) was removed from [% i.delcount %] course.</li>
47
                      [% ELSIF i.delcount > 1 %]
48
                          <li>[% i.delitem.biblio.title | html %] ([% i.delitem.barcode | html %]) was removed from [% i.delcount %] courses.</li>
49
                      [% END %]
50
                    [% END %]
51
                </ul>
52
            [% ELSE %]
53
                No valid item barcodes found.
54
            [% END %]
55
56
57
            [% IF invalid_barcodes.size > 0 %]
58
                <h3>Invalid barcodes</h3>
59
                <p>The following invalid barcodes were skipped:</p>
60
                <ul>
61
                    [% FOREACH b IN invalid_barcodes %]
62
                        <li>[% b | html %]</li>
63
                    [% END %]
64
                </ul>
65
            [% END %]
66
67
            <p>
68
                <a class='btn btn-default'  href="/cgi-bin/koha/course_reserves/course-reserves.pl">Return</a>
69
            </p>
70
        [% END %]
71
    </div>
72
</div>
73
74
[% MACRO jsinclude BLOCK %]
75
    <script>
76
        $(document).ready(function() {
77
            $("#batch_rm_btn").click(function(){
78
                return confirmDelete(_("Are you sure you want to remove these items from all courses?"));
79
            });
80
        });
81
    </script>
82
[% END %]
83
84
[% 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