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",
48 flagsrequired => { parameters => 'manage_itemtypes' },
53 my $dbh = C4::Context->dbh;
55 my $sip_media_type = $input->param('sip_media_type');
56 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$/;
58 if ( $op eq 'add_form' ) {
59 my $itemtype = Koha::ItemTypes->find($itemtype_code);
61 my $parent_type = $itemtype ? $itemtype->parent_type : undef;
62 my $parent_types = Koha::ItemTypes->search({parent_type=>undef,itemtype => {'!='=>$itemtype_code}});
63 my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) );
64 my $searchcategory = GetAuthorisedValues("ITEMTYPECAT");
65 my $translated_languages = C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') );
67 itemtype => $itemtype,
68 parent_type => $parent_type,
69 parent_types => $parent_types,
70 is_a_parent => $itemtype ? Koha::ItemTypes->search({parent_type=>$itemtype_code})->count : 0,
71 imagesets => $imagesets,
72 searchcategory => $searchcategory,
73 can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
75 } elsif ( $op eq 'add_validate' ) {
76 my $is_a_modif = $input->param('is_a_modif');
77 my $itemtype = Koha::ItemTypes->find($itemtype_code);
78 my $parent_type = $input->param('parent_type') || undef;
79 my $description = $input->param('description');
80 my $rentalcharge = $input->param('rentalcharge');
81 my $rentalcharge_daily = $input->param('rentalcharge_daily');
82 my $rentalcharge_hourly = $input->param('rentalcharge_hourly');
83 my $defaultreplacecost = $input->param('defaultreplacecost');
84 my $processfee = $input->param('processfee');
85 my $image = $input->param('image') || q||;
86 my @branches = grep { $_ ne q{} } $input->multi_param('branches');
88 my $notforloan = $input->param('notforloan') ? 1 : 0;
90 $image eq 'removeImage' ? ''
92 $image eq 'remoteImage' ? $input->param('remoteImage')
95 my $summary = $input->param('summary');
96 my $checkinmsg = $input->param('checkinmsg');
97 my $checkinmsgtype = $input->param('checkinmsgtype');
98 my $hideinopac = $input->param('hideinopac') // 0;
99 my $searchcategory = $input->param('searchcategory');
100 my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0;
101 my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0;
102 my $automatic_checkin = $input->param('automatic_checkin') // 0;
104 if ( $itemtype and $is_a_modif ) { # it's a modification
105 $itemtype->description($description);
106 $itemtype->parent_type($parent_type);
107 $itemtype->rentalcharge($rentalcharge);
108 $itemtype->rentalcharge_daily($rentalcharge_daily);
109 $itemtype->rentalcharge_hourly($rentalcharge_hourly);
110 $itemtype->defaultreplacecost($defaultreplacecost);
111 $itemtype->processfee($processfee);
112 $itemtype->notforloan($notforloan);
113 $itemtype->imageurl($imageurl);
114 $itemtype->summary($summary);
115 $itemtype->checkinmsg($checkinmsg);
116 $itemtype->checkinmsgtype($checkinmsgtype);
117 $itemtype->sip_media_type($sip_media_type);
118 $itemtype->hideinopac($hideinopac);
119 $itemtype->searchcategory($searchcategory);
120 $itemtype->rentalcharge_daily_calendar($rentalcharge_daily_calendar);
121 $itemtype->rentalcharge_hourly_calendar($rentalcharge_hourly_calendar);
122 $itemtype->automatic_checkin($automatic_checkin);
126 $itemtype->replace_library_limits( \@branches );
130 push @messages, { type => 'alert', code => 'error_on_update' };
132 push @messages, { type => 'message', code => 'success_on_update' };
134 } elsif ( not $itemtype and not $is_a_modif ) {
135 my $itemtype = Koha::ItemType->new(
137 itemtype => $itemtype_code,
138 description => $description,
139 parent_type => $parent_type,
140 rentalcharge => $rentalcharge,
141 rentalcharge_daily => $rentalcharge_daily,
142 rentalcharge_hourly => $rentalcharge_hourly,
143 defaultreplacecost => $defaultreplacecost,
144 processfee => $processfee,
145 notforloan => $notforloan,
146 imageurl => $imageurl,
148 checkinmsg => $checkinmsg,
149 checkinmsgtype => $checkinmsgtype,
150 sip_media_type => $sip_media_type,
151 hideinopac => $hideinopac,
152 searchcategory => $searchcategory,
153 rentalcharge_daily_calendar => $rentalcharge_daily_calendar,
154 rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar,
155 automatic_checkin => $automatic_checkin,
160 $itemtype->replace_library_limits( \@branches );
164 push @messages, { type => 'alert', code => 'error_on_insert' };
166 push @messages, { type => 'message', code => 'success_on_insert' };
171 code => 'already_exists',
178 } elsif ( $op eq 'delete_confirm' ) {
179 my $itemtype = Koha::ItemTypes->find($itemtype_code);
180 my $can_be_deleted = $itemtype->can_be_deleted();
181 if ($can_be_deleted == 0) {
182 push @messages, { type => 'alert', code => 'cannot_be_deleted'};
185 $template->param( itemtype => $itemtype, );
188 } elsif ( $op eq 'delete_confirmed' ) {
190 my $itemtype = Koha::ItemTypes->find($itemtype_code);
191 my $deleted = eval { $itemtype->delete };
192 if ( $@ or not $deleted ) {
193 push @messages, { type => 'alert', code => 'error_on_delete' };
195 push @messages, { type => 'message', code => 'success_on_delete' };
201 if ( $op eq 'list' ) {
203 itemtypes => scalar Koha::ItemTypes->search,
204 messages => \@messages,
208 $template->param( op => $op );
210 output_html_with_http_headers $input, $cookie, $template->output;