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
=> 'manage_itemtypes' },
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");
63 my $translated_languages = C4
::Languages
::getTranslatedLanguages
( undef , C4
::Context
->preference('template') );
65 itemtype
=> $itemtype,
66 imagesets
=> $imagesets,
67 searchcategory
=> $searchcategory,
68 can_be_translated
=> ( scalar(@
$translated_languages) > 1 ?
1 : 0 ),
70 } elsif ( $op eq 'add_validate' ) {
71 my $is_a_modif = $input->param('is_a_modif');
72 my $itemtype = Koha
::ItemTypes
->find($itemtype_code);
73 my $description = $input->param('description');
74 my $rentalcharge = $input->param('rentalcharge');
75 my $defaultreplacecost = $input->param('defaultreplacecost');
76 my $processfee = $input->param('processfee');
77 my $image = $input->param('image') || q
||;
79 my $notforloan = $input->param('notforloan') ?
1 : 0;
81 $image eq 'removeImage' ?
''
83 $image eq 'remoteImage' ?
$input->param('remoteImage')
86 my $summary = $input->param('summary');
87 my $checkinmsg = $input->param('checkinmsg');
88 my $checkinmsgtype = $input->param('checkinmsgtype');
89 my $hideinopac = $input->param('hideinopac') // 0;
90 my $searchcategory = $input->param('searchcategory');
92 if ( $itemtype and $is_a_modif ) { # it's a modification
93 $itemtype->description($description);
94 $itemtype->rentalcharge($rentalcharge);
95 $itemtype->defaultreplacecost($defaultreplacecost);
96 $itemtype->processfee($processfee);
97 $itemtype->notforloan($notforloan);
98 $itemtype->imageurl($imageurl);
99 $itemtype->summary($summary);
100 $itemtype->checkinmsg($checkinmsg);
101 $itemtype->checkinmsgtype($checkinmsgtype);
102 $itemtype->sip_media_type($sip_media_type);
103 $itemtype->hideinopac($hideinopac);
104 $itemtype->searchcategory($searchcategory);
106 eval { $itemtype->store; };
109 push @messages, { type
=> 'error', code
=> 'error_on_update' };
111 push @messages, { type
=> 'message', code
=> 'success_on_update' };
113 } elsif ( not $itemtype and not $is_a_modif ) {
114 my $itemtype = Koha
::ItemType
->new(
115 { itemtype
=> $itemtype_code,
116 description
=> $description,
117 rentalcharge
=> $rentalcharge,
118 defaultreplacecost
=> $defaultreplacecost,
119 processfee
=> $processfee,
120 notforloan
=> $notforloan,
121 imageurl
=> $imageurl,
123 checkinmsg
=> $checkinmsg,
124 checkinmsgtype
=> $checkinmsgtype,
125 sip_media_type
=> $sip_media_type,
126 hideinopac
=> $hideinopac,
127 searchcategory
=> $searchcategory,
130 eval { $itemtype->store; };
133 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
135 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
140 code
=> 'already_exists',
147 } elsif ( $op eq 'delete_confirm' ) {
148 my $itemtype = Koha
::ItemTypes
->find($itemtype_code);
149 my $can_be_deleted = $itemtype->can_be_deleted();
150 if ($can_be_deleted == 0) {
151 push @messages, { type
=> 'error', code
=> 'cannot_be_deleted'};
154 $template->param( itemtype
=> $itemtype, );
157 } 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;