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

(-)a/course_reserves/batch_add_items.pl (+110 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
#
4
# Copyright 2018 Bywater Solutions
5
#
6
# This file is part of Koha.
7
#
8
# Koha is free software; you can redistribute it and/or modify it
9
# under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# Koha is distributed in the hope that it will be useful, but
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
use Modern::Perl;
22
23
use CGI qw ( -utf8 );
24
25
use C4::Auth;
26
use C4::Output;
27
use C4::Koha;
28
use C4::CourseReserves qw(ModCourseItem ModCourseReserve GetCourse);
29
30
use Koha::Items;
31
use Koha::ItemTypes;
32
33
my $cgi = new CGI;
34
35
my $action    = $cgi->param('action')    || q{};
36
my $course_id = $cgi->param('course_id') || q{};
37
my $barcodes  = $cgi->param('barcodes')  || q{};
38
39
my $itype         = $cgi->param('itype');
40
my $ccode         = $cgi->param('ccode');
41
my $holdingbranch = $cgi->param('holdingbranch');
42
my $location      = $cgi->param('location');
43
my $staff_note    = $cgi->param('staff_note');
44
my $public_note   = $cgi->param('public_note');
45
46
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
47
    {
48
        template_name   => "course_reserves/batch_add_items.tt",
49
        query           => $cgi,
50
        type            => "intranet",
51
        authnotrequired => 0,
52
        flagsrequired   => { coursereserves => 'add_reserves' },
53
    }
54
);
55
56
$template->param( course => GetCourse($course_id) );
57
58
if ( !$action ) {
59
60
    my $itemtypes = Koha::ItemTypes->search;
61
    $template->param(
62
        action    => 'display_form',
63
        ccodes    => GetAuthorisedValues('CCODE'),
64
        locations => GetAuthorisedValues('LOC'),
65
        itypes    => $itemtypes,
66
    );
67
68
}
69
elsif ( $action eq 'add' ) {
70
    my @barcodes = split( "\r\n", $barcodes );
71
72
    my @items;
73
    my @invalid_barcodes;
74
    for my $b (@barcodes) {
75
        my $item = Koha::Items->find( { barcode => $b } );
76
77
        if ($item) {
78
            push( @items, $item );
79
        }
80
        else {
81
            push( @invalid_barcodes, $b );
82
        }
83
    }
84
85
    foreach my $item (@items) {
86
        my $ci_id = ModCourseItem(
87
            itemnumber    => $item->id,
88
            itype         => $itype,
89
            ccode         => $ccode,
90
            holdingbranch => $holdingbranch,
91
            location      => $location,
92
        );
93
94
        my $cr_id = ModCourseReserve(
95
            course_id   => $course_id,
96
            ci_id       => $ci_id,
97
            staff_note  => $staff_note,
98
            public_note => $public_note,
99
        );
100
    }
101
102
    $template->param(
103
        action           => 'display_results',
104
        items_added      => \@items,
105
        invalid_barcodes => \@invalid_barcodes,
106
        course_id        => $course_id,
107
    );
108
}
109
110
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt (+146 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Course reserves &rsaquo; Add items</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
</head>
5
<body id="courses_add_items_step1" class="course">
6
7
[% INCLUDE 'header.inc' %]
8
[% INCLUDE 'cat-search.inc' %]
9
10
<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; Add reserves for <i><a href="/cgi-bin/koha/course_reserves/course-details.pl?course_id=[% course.course_id %]">[% course.course_name %]</a></i></div>
11
12
<div class="main container-fluid">
13
    <div class="row">
14
        <div class="col-md-8 col-md-offset-2">
15
16
        [% IF action == 'display_form' %]
17
            <form method="post" action="/cgi-bin/koha/course_reserves/batch_add_items.pl">
18
                <input type="hidden" name="course_id" value="[% course.course_id %]" />
19
                <input type="hidden" name="action" value="add" />
20
21
                <fieldset class="rows">
22
                    <legend>Add items: scan barcodes</legend>
23
                    <ol>
24
                        <li>
25
                            <label class="required" for="barcodes">Item barcodes:</label>
26
                            <textarea rows="20" cols="50" id="barcodes" name="barcodes" class="focus"></textarea>
27
                        </li>
28
                        [% IF item_level_itypes %]
29
                        <li>
30
                            <label class="required" for="itype">Item type:</label>
31
                            <select id="itype" name="itype">
32
                                <option value="">LEAVE UNCHANGED</option>
33
34
                                [% FOREACH it IN itypes %]
35
                                    [% IF course_item.itype && ( ( course.enabled == 'yes' && it.itemtype == item.itype ) || ( course.enabled == 'no' && it.itemtype == course_item.itype ) ) %]
36
                                        <option value="[% it.itemtype %]" selected="selected">[% it.description %]</option>
37
                                    [% ELSE %]
38
                                        <option value="[% it.itemtype %]">[% it.description %]</option>
39
                                    [% END %]
40
                                [% END %]
41
                            </select>
42
                        </li>
43
                        [% END %]
44
45
                        <li>
46
                            <label class="required" for="ccode">Collection code:</label>
47
                            <select id="ccode" name="ccode">
48
                                <option value="">LEAVE UNCHANGED</option>
49
50
                                [% FOREACH c IN ccodes %]
51
                                    [% IF course_item.ccode && ( ( course.enabled == 'yes' && c.authorised_value == item.ccode ) || ( course.enabled == 'no' && c.authorised_value == course_item.ccode ) ) %]
52
                                        <option value="[% c.authorised_value %]" selected="selected">[% c.lib %]</option>
53
                                    [% ELSE %]
54
                                        <option value="[% c.authorised_value %]">[% c.lib %]</option>
55
                                    [% END %]
56
                                [% END %]
57
                            </select>
58
                        </li>
59
60
                        <li>
61
                            <label class="required" for="location">Shelving location:</label>
62
                            <select id="location" name="location">
63
                                <option value="">LEAVE UNCHANGED</option>
64
65
                                [% FOREACH s IN locations %]
66
                                    [% IF course_item.location && ( ( course.enabled == 'yes' && s.authorised_value == item.location ) || ( course.enabled == 'no' && s.authorised_value == course_item.location ) ) %]
67
                                        <option value="[% s.authorised_value %]" selected="selected">[% s.lib %]</option>
68
                                    [% ELSE %]
69
                                        <option value="[% s.authorised_value %]">[% s.lib %]</option>
70
                                    [% END %]
71
                                [% END %]
72
                            </select>
73
                        </li>
74
75
                        <li>
76
                            <label class="required" for="holdingbranch">Holding library:</label>
77
                            <select id="holdingbranch" name="holdingbranch">
78
                                <option value="">LEAVE UNCHANGED</option>
79
                                [% FOREACH b IN Branches.all() %]
80
                                    [% IF course_item.holdingbranch && ( ( course.enabled == 'yes' && b.value == item.holdingbranch ) || ( course.enabled == 'no' && b.value == course_item.holdingbranch ) ) %]
81
                                        <option value="[% b.branchcode %]" selected="selected">[% b.branchname %]</option>
82
                                    [% ELSE %]
83
                                        <option value="[% b.branchcode %]">[% b.branchname %]</option>
84
                                    [% END %]
85
                                [% END %]
86
                            </select>
87
                        </li>
88
89
                        <li>
90
                            <label for="staff_note">Staff note:</label>
91
                            <textarea name="staff_note" id="staff_note">[% course_reserve.staff_note %]</textarea>
92
                        </li>
93
94
                        <li>
95
                            <label for="public_note">Public note:</label>
96
                            <textarea name="public_note" id="public_note">[% course_reserve.public_note %]</textarea>
97
                        </li>
98
                    </ol>
99
                </fieldset>
100
101
                <p>
102
                    Any items with existing course reserves will have their <i>on reserve</i> values updated.
103
                </p>
104
105
                <fieldset class="action">
106
                    <input type="submit" value="Submit" class="submit" />
107
108
                    <a href="/cgi-bin/koha/course_reserves/course-details.pl?course_id=[% course.course_id %]" class="cancel">Cancel</a>
109
                </fieldset>
110
            </form>
111
        [% END %]
112
113
        [% IF action == 'display_results' %]
114
            <h1>Results</h1>
115
116
            <h3>Items added</h3>
117
            [% IF items_added.size > 0 %]
118
                <p>The following items were added or updated:</p>
119
                <ul>
120
                    [% FOREACH i IN items_added %]
121
                        <li>[% i.biblio.title %] ( [% i.barcode %] )</li>
122
                    [% END %]
123
                </ul>
124
            [% ELSE %]
125
                No valid item barcodes found.
126
            [% END %]
127
128
129
            [% IF invalid_barcodes.size > 0 %]
130
                <h3>Invalid barcodes</h3>
131
                <p>The following invalid barcodes were skipped:</p>
132
                <ul>
133
                    [% FOREACH b IN invalid_barcodes %]
134
                        <li>[% b %]</li>
135
                    [% END %]
136
                </ul>
137
            [% END %]
138
139
            <p>
140
                <a class='btn btn-default' href="/cgi-bin/koha/course_reserves/course-details.pl?course_id=[% course_id %]">View course</a>
141
            </p>
142
        [% END %]
143
    </div>
144
</div>
145
146
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/course-details.tt (-1 / +1 lines)
Lines 24-29 Link Here
24
            <div id="toolbar">
24
            <div id="toolbar">
25
                [% IF CAN_user_coursereserves_add_reserves %]
25
                [% IF CAN_user_coursereserves_add_reserves %]
26
                    <a class="btn btn-default btn-sm" id="add_items" href="/cgi-bin/koha/course_reserves/add_items.pl?course_id=[% course.course_id %]"><i class="fa fa-plus"></i> Add reserves</a>
26
                    <a class="btn btn-default btn-sm" id="add_items" href="/cgi-bin/koha/course_reserves/add_items.pl?course_id=[% course.course_id %]"><i class="fa fa-plus"></i> Add reserves</a>
27
                    <a class="btn btn-default btn-sm" id="add_items" href="/cgi-bin/koha/course_reserves/batch_add_items.pl?course_id=[% course.course_id %]"><i class="fa fa-plus"></i> Batch add reserves</a>
27
                [% END %]
28
                [% END %]
28
                [% IF ( CAN_user_coursereserves_manage_courses ) %]
29
                [% IF ( CAN_user_coursereserves_manage_courses ) %]
29
                    <a class="btn btn-default btn-sm" id="edit_course" href="/cgi-bin/koha/course_reserves/course.pl?course_id=[% course.course_id %]"><i class="fa fa-pencil"></i> Edit course</a>
30
                    <a class="btn btn-default btn-sm" id="edit_course" href="/cgi-bin/koha/course_reserves/course.pl?course_id=[% course.course_id %]"><i class="fa fa-pencil"></i> Edit course</a>
30
- 

Return to bug 20467