3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2002 Paul Poulain
6 # This file is part of Koha.
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.
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.
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>.
21 =head1 admin/itemtypes.pl
36 use Koha::Localizations;
39 my $searchfield = $input->param('description');
40 my $itemtype_code = $input->param('itemtype');
41 my $op = $input->param('op') // 'list';
43 $searchfield =~ s/\,//g if $searchfield;
44 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
45 { template_name => "admin/itemtypes.tt",
49 flagsrequired => { parameters => 'parameters_remaining_permissions' },
54 my $dbh = C4::Context->dbh;
56 my $sip_media_type = $input->param('sip_media_type');
57 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$/;
59 if ( $op eq 'add_form' ) {
60 my $itemtype = Koha::ItemTypes->find($itemtype_code);
61 my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
62 my $searchcategory = GetAuthorisedValues("ITEMTYPECAT", ( $itemtype ? $itemtype->searchcategory : '' ) );
64 itemtype => $itemtype,
65 imagesets => $imagesets,
66 searchcategory => $searchcategory,
68 } elsif ( $op eq 'add_validate' ) {
69 my $is_a_modif = $input->param('is_a_modif');
70 my $itemtype = Koha::ItemTypes->find($itemtype_code);
71 my $description = $input->param('description');
72 my $rentalcharge = $input->param('rentalcharge');
73 my $image = $input->param('image') || q||;
75 my $notforloan = $input->param('notforloan') ? 1 : 0;
77 $image eq 'removeImage' ? ''
79 $image eq 'remoteImage' ? $input->param('remoteImage')
82 my $summary = $input->param('summary');
83 my $checkinmsg = $input->param('checkinmsg');
84 my $checkinmsgtype = $input->param('checkinmsgtype');
85 my $hideinopac = $input->param('hideinopac') // 0;
86 my $searchcategory = $input->param('searchcategory');
88 if ( $itemtype and $is_a_modif ) { # it's a modification
89 $itemtype->description($description);
90 $itemtype->rentalcharge($rentalcharge);
91 $itemtype->notforloan($notforloan);
92 $itemtype->imageurl($imageurl);
93 $itemtype->summary($summary);
94 $itemtype->checkinmsg($checkinmsg);
95 $itemtype->checkinmsgtype($checkinmsgtype);
96 $itemtype->sip_media_type($sip_media_type);
97 $itemtype->hideinopac($hideinopac);
98 $itemtype->searchcategory($searchcategory);
100 eval { $itemtype->store; };
103 push @messages, { type => 'error', code => 'error_on_update' };
105 push @messages, { type => 'message', code => 'success_on_update' };
107 } elsif ( not $itemtype and not $is_a_modif ) {
108 my $itemtype = Koha::ItemType->new(
109 { itemtype => $itemtype_code,
110 description => $description,
111 rentalcharge => $rentalcharge,
112 notforloan => $notforloan,
113 imageurl => $imageurl,
115 checkinmsg => $checkinmsg,
116 checkinmsgtype => $checkinmsgtype,
117 sip_media_type => $sip_media_type,
118 hideinopac => $hideinopac,
119 searchcategory => $searchcategory,
122 eval { $itemtype->store; };
125 push @messages, { type => 'error', code => 'error_on_insert' };
127 push @messages, { type => 'message', code => 'success_on_insert' };
132 code => 'already_exists',
138 } elsif ( $op eq 'delete_confirm' ) {
140 # Check both items and biblioitems
141 my ($total) = $dbh->selectrow_array( '
142 SELECT COUNT(*) AS total FROM (
143 SELECT itemtype AS t FROM biblioitems
145 SELECT itype AS t FROM items
148 ', {}, $itemtype_code );
151 push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total };
154 my $itemtype = Koha::ItemTypes->find($itemtype_code);
155 $template->param( itemtype => $itemtype, );
158 } elsif ( $op eq 'delete_confirmed' ) {
159 my $itemtype = Koha::ItemTypes->find($itemtype_code);
160 my $deleted = eval { $itemtype->delete };
161 if ( $@ or not $deleted ) {
162 push @messages, { type => 'error', code => 'error_on_delete' };
164 push @messages, { type => 'message', code => 'success_on_delete' };
170 if ( $op eq 'list' ) {
171 my $itemtypes = Koha::ItemTypes->search;
173 itemtypes => $itemtypes,
174 messages => \@messages,
178 $template->param( op => $op );
180 output_html_with_http_headers $input, $cookie, $template->output;