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
29 use C4::Koha qw( getImageSets GetAuthorisedValues );
31 use C4::Auth qw( get_template_and_user );
32 use C4::Output qw( output_html_with_http_headers );
35 use Koha::Localizations;
38 my $searchfield = $input->param('description');
39 my $itemtype_code = $input->param('itemtype');
40 my $op = $input->param('op') // 'list';
42 $searchfield =~ s/\,//g if $searchfield;
43 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
44 { template_name => "admin/itemtypes.tt",
47 flagsrequired => { parameters => 'manage_itemtypes' },
51 my $dbh = C4::Context->dbh;
53 my $sip_media_type = $input->param('sip_media_type');
54 undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$/;
56 if ( $op eq 'add_form' ) {
57 my $itemtype = Koha::ItemTypes->find($itemtype_code);
59 my $parent_type = $itemtype ? $itemtype->parent_type : undef;
60 my $parent_types = Koha::ItemTypes->search({parent_type=>undef,itemtype => {'!='=>$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( "both", C4::Context->preference('template') );
65 itemtype => $itemtype,
66 parent_type => $parent_type,
67 parent_types => $parent_types,
68 is_a_parent => $itemtype ? Koha::ItemTypes->search({parent_type=>$itemtype_code})->count : 0,
69 imagesets => $imagesets,
70 searchcategory => $searchcategory,
71 can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ),
73 } elsif ( $op eq 'add_validate' ) {
74 my $is_a_modif = $input->param('is_a_modif');
75 my $itemtype = Koha::ItemTypes->find($itemtype_code);
76 my $parent_type = $input->param('parent_type') || undef;
77 my $description = $input->param('description');
78 my $rentalcharge = $input->param('rentalcharge');
79 my $rentalcharge_daily = $input->param('rentalcharge_daily');
80 my $rentalcharge_hourly = $input->param('rentalcharge_hourly');
81 my $defaultreplacecost = $input->param('defaultreplacecost');
82 my $processfee = $input->param('processfee');
83 my $image = $input->param('image') || q||;
84 my @branches = grep { $_ ne q{} } $input->multi_param('branches');
86 my $notforloan = $input->param('notforloan') ? 1 : 0;
88 $image eq 'removeImage' ? ''
90 $image eq 'remoteImage' ? $input->param('remoteImage')
93 my $summary = $input->param('summary');
94 my $checkinmsg = $input->param('checkinmsg');
95 my $checkinmsgtype = $input->param('checkinmsgtype');
96 my $hideinopac = $input->param('hideinopac') // 0;
97 my $searchcategory = $input->param('searchcategory');
98 my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0;
99 my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0;
100 my $automatic_checkin = $input->param('automatic_checkin') // 0;
102 if ( $itemtype and $is_a_modif ) { # it's a modification
103 $itemtype->description($description);
104 $itemtype->parent_type($parent_type);
105 $itemtype->rentalcharge($rentalcharge);
106 $itemtype->rentalcharge_daily($rentalcharge_daily);
107 $itemtype->rentalcharge_hourly($rentalcharge_hourly);
108 $itemtype->defaultreplacecost($defaultreplacecost);
109 $itemtype->processfee($processfee);
110 $itemtype->notforloan($notforloan);
111 $itemtype->imageurl($imageurl);
112 $itemtype->summary($summary);
113 $itemtype->checkinmsg($checkinmsg);
114 $itemtype->checkinmsgtype($checkinmsgtype);
115 $itemtype->sip_media_type($sip_media_type);
116 $itemtype->hideinopac($hideinopac);
117 $itemtype->searchcategory($searchcategory);
118 $itemtype->rentalcharge_daily_calendar($rentalcharge_daily_calendar);
119 $itemtype->rentalcharge_hourly_calendar($rentalcharge_hourly_calendar);
120 $itemtype->automatic_checkin($automatic_checkin);
124 $itemtype->replace_library_limits( \@branches );
128 push @messages, { type => 'alert', code => 'error_on_update' };
130 push @messages, { type => 'message', code => 'success_on_update' };
132 } elsif ( not $itemtype and not $is_a_modif ) {
133 my $itemtype = Koha::ItemType->new(
135 itemtype => $itemtype_code,
136 description => $description,
137 parent_type => $parent_type,
138 rentalcharge => $rentalcharge,
139 rentalcharge_daily => $rentalcharge_daily,
140 rentalcharge_hourly => $rentalcharge_hourly,
141 defaultreplacecost => $defaultreplacecost,
142 processfee => $processfee,
143 notforloan => $notforloan,
144 imageurl => $imageurl,
146 checkinmsg => $checkinmsg,
147 checkinmsgtype => $checkinmsgtype,
148 sip_media_type => $sip_media_type,
149 hideinopac => $hideinopac,
150 searchcategory => $searchcategory,
151 rentalcharge_daily_calendar => $rentalcharge_daily_calendar,
152 rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar,
153 automatic_checkin => $automatic_checkin,
158 $itemtype->replace_library_limits( \@branches );
162 push @messages, { type => 'alert', code => 'error_on_insert' };
164 push @messages, { type => 'message', code => 'success_on_insert' };
169 code => 'already_exists',
176 } elsif ( $op eq 'delete_confirm' ) {
177 my $itemtype = Koha::ItemTypes->find($itemtype_code);
178 my $can_be_deleted = $itemtype->can_be_deleted();
179 if ($can_be_deleted == 0) {
180 push @messages, { type => 'alert', code => 'cannot_be_deleted'};
183 $template->param( itemtype => $itemtype, );
186 } elsif ( $op eq 'delete_confirmed' ) {
188 my $itemtype = Koha::ItemTypes->find($itemtype_code);
189 my $deleted = eval { $itemtype->delete };
190 if ( $@ or not $deleted ) {
191 push @messages, { type => 'alert', code => 'error_on_delete' };
193 push @messages, { type => 'message', code => 'success_on_delete' };
199 if ( $op eq 'list' ) {
201 itemtypes => Koha::ItemTypes->search,
202 messages => \@messages,
206 $template->param( op => $op );
208 output_html_with_http_headers $input, $cookie, $template->output;