3 # Copyright 2000-2009 Biblibre S.A
4 # John Soros <john.soros@biblibre.com>
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
24 #need to open cgi and get the fh before anything else opens a new cgi context (see C4::Auth)
27 my $barcodefh = $input->upload('uploadbarcodes');
32 use C4::Branch qw(GetBranches);
33 use C4::Koha qw(GetAuthorisedValues GetAuthValCode);
34 use C4::Items qw(GetItemnumberFromBarcode GetItem ModItem DelItemCheck);
35 use C4::Biblio qw(GetBiblioData);
36 use C4::Koha qw(GetItemTypes);
39 my ($template, $borrowernumber, $cookie)
40 = get_template_and_user({template_name => "tools/batchMod.tmpl",
44 flagsrequired => {tools => 'batchmod'},
48 #get all input vars and put it in a hash
49 my $invars = $input->Vars;
51 # Global item status lists (this has proven to be very handy :)
53 my $authvals = [['items.notforloan', 'Item not for loan', 'notforloan'],
54 ['items.itemlost', 'Item lost', 'itemlost'],
55 ['items.wthdrawn', 'item withdrawn', 'sele'],
56 ['items.damaged', 'item damaged', 'damaged'],
57 ['items.location', 'item location', 'location'],
58 ['items.ccode', 'items.ccode', 'ccode'],
61 my $itemlevelpref = C4::Context->preference('item-level_itypes');
62 if ( $invars->{op} && $invars->{op} eq 'barcodes'){
65 if ( $invars->{'uploadbarcodes'} && length($invars->{'uploadbarcodes'})>0){
66 while (my $barcode=<$barcodefh>){
68 push @barcodelist, $barcode;
71 if ( $invars->{barcodelist} && length($invars->{barcodelist}) > 0){
72 @barcodelist = split(/\s\n/, $invars->{barcodelist});
75 my $brancheshash = GetBranches();
77 for my $branchcode (keys %$brancheshash){
79 $branch->{'name'} = $brancheshash->{$branchcode}->{'branchname'};
80 $branch->{'code'} = $branchcode;
81 push @$branches, $branch;
84 #get all item statuses
85 for my $field (@$authvals){
86 my $fieldstatusauth = {};
87 my ($fieldname, $fielddesc, $hashfdname) = @$field;
88 $fieldstatusauth->{authcode} = GetAuthValCode($fieldname);
89 if ($fieldstatusauth->{authcode} && length($fieldstatusauth->{authcode}) > 0){
90 $fieldstatusauth->{values} = GetAuthorisedValues($fieldstatusauth->{authcode});
91 $fieldstatusauth->{fieldname} = $fieldname;
92 $fieldstatusauth->{description} = $fielddesc;
93 $fieldstatusauth->{itemfieldname} = $hashfdname;
94 push @$authloop, $fieldstatusauth;
98 #we use item level itype
101 my $itypes = GetItemTypes();
102 for my $key (keys %$itypes){
103 push(@$itemtypes, $itypes->{$key});
109 if (scalar @barcodelist > 0){
110 for my $barcode (@barcodelist){
111 my $itemno = GetItemnumberFromBarcode($barcode);
112 my $item = GetItem($itemno, $barcode);
113 my $iteminfo = GetBiblioData($item->{biblionumber});
114 for my $field (qw(title isbn itemtype)){
115 $item->{$field} = $iteminfo->{$field};
117 if ($itemlevelpref) {
118 my $iteminfo = GetItem($itemno);
119 $item->{itemtype} = $iteminfo->{itype};
121 #kind of flakey, though we can be pretty sure the values will be in the same order as in the authloop
122 #have to use this since in html::template::pro i can't access one loop from inside an other,
123 #and variable substitution doesn't work (<!-- TMPL_VAR name="<!-- TMPL_VAR name="foo" -->" -->)
124 #this pushes a list of authorized valuse into each item's hash
125 my $itemauthloop = [];
126 for my $authfield (@$authloop){
128 #looking for the authvalues human-readable form
129 for my $val (@{$authfield->{values}}){
130 if( $item->{$authfield->{itemfieldname}} eq $val->{lib} || $item->{$authfield->{itemfieldname}} eq $val->{authorised_value}){
131 $authvaluename = $val->{lib};
134 if ( ! $authvaluename){
135 $authvaluename = $item->{$authfield->{itemfieldname}};
137 push(@$itemauthloop, { 'authvalue' => $authvaluename} );
140 for my $type (@$itemtypes){
141 if ( $item->{itemtype} eq $type->{itemtype} ) {
142 $item->{itemtypedesc} = $type->{description};
145 $item->{authloop} = $itemauthloop;
147 $itemslst .= $item->{'itemnumber'} . ',';
150 $template->param( 'itemsloop' => \@items,
151 'authloop' => $authloop,
152 'branches' => $branches,
155 'itemslst' => $itemslst,
156 'itemtypes' => $itemtypes,
158 } elsif ( $invars->{'itemslst'} ) {
159 for my $itemno ( split(',', $invars->{itemslst}) ) {
160 my $item = GetItem($itemno);
161 if ( $invars->{'del'} ) {
162 DelItemCheck(C4::Context->dbh, $item->{'biblionumber'}, $item->{'itemnumber'})
164 for my $auth (@$authvals){
165 my ($authfieldname, $description, $hashfdname) = @$auth;
166 my $authcode = GetAuthValCode($authfieldname);
167 if ($authcode && $invars->{$authcode} && $invars->{$authcode} ne '0'){
168 $item->{$hashfdname}=$invars->{$authcode};
171 if ($invars->{holdingbranch} && $invars->{holdingbranch} ne '0'){
172 $item->{holdingbranch} = $invars->{holdingbranch};
174 if ($invars->{homebranch} && $invars->{homebranch} ne '0'){
175 $item->{homebranch} = $invars->{homebranch};
177 if ($invars->{itemtypes} && $invars->{itemtypes} ne '0') {
178 $item->{itype} = $invars->{itemtypes};
180 ModItem($item, $item->{biblionumber}, $item->{itemnumber});
184 $template->param('del' => $input->param('del'));
185 output_html_with_http_headers $input, $cookie, $template->output;