|
Lines 25-34
Link Here
|
| 25 |
use Modern::Perl; |
25 |
use Modern::Perl; |
| 26 |
use CGI qw ( -utf8 ); |
26 |
use CGI qw ( -utf8 ); |
| 27 |
|
27 |
|
| 28 |
|
|
|
| 29 |
use C4::Koha qw( getImageSets GetAuthorisedValues ); |
28 |
use C4::Koha qw( getImageSets GetAuthorisedValues ); |
| 30 |
use C4::Context; |
29 |
use C4::Context; |
| 31 |
use C4::Auth qw( get_template_and_user ); |
30 |
use C4::Auth qw( get_template_and_user ); |
| 32 |
use C4::Output qw( output_html_with_http_headers ); |
31 |
use C4::Output qw( output_html_with_http_headers ); |
| 33 |
use Koha::ItemTypes; |
32 |
use Koha::ItemTypes; |
| 34 |
use Koha::ItemType; |
33 |
use Koha::ItemType; |
|
Lines 41-50
my $op = $input->param('op') // 'list';
Link Here
|
| 41 |
my @messages; |
40 |
my @messages; |
| 42 |
$searchfield =~ s/\,//g if $searchfield; |
41 |
$searchfield =~ s/\,//g if $searchfield; |
| 43 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
42 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 44 |
{ template_name => "admin/itemtypes.tt", |
43 |
{ |
| 45 |
query => $input, |
44 |
template_name => "admin/itemtypes.tt", |
| 46 |
type => "intranet", |
45 |
query => $input, |
| 47 |
flagsrequired => { parameters => 'manage_itemtypes' }, |
46 |
type => "intranet", |
|
|
47 |
flagsrequired => { parameters => 'manage_itemtypes' }, |
| 48 |
} |
48 |
} |
| 49 |
); |
49 |
); |
| 50 |
|
50 |
|
|
Lines 56-104
undef($sip_media_type) if defined($sip_media_type) and $sip_media_type =~ /^\s*$
Link Here
|
| 56 |
if ( $op eq 'add_form' ) { |
56 |
if ( $op eq 'add_form' ) { |
| 57 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
57 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
| 58 |
|
58 |
|
| 59 |
my $parent_type = $itemtype ? $itemtype->parent_type : undef; |
59 |
my $parent_type = $itemtype ? $itemtype->parent_type : undef; |
| 60 |
my $parent_types = Koha::ItemTypes->search({parent_type=>undef,itemtype => {'!='=>$itemtype_code}}); |
60 |
my $parent_types = Koha::ItemTypes->search( { parent_type => undef, itemtype => { '!=' => $itemtype_code } } ); |
| 61 |
my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) ); |
61 |
my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) ); |
| 62 |
my $searchcategory = GetAuthorisedValues("ITEMTYPECAT"); |
62 |
my $searchcategory = GetAuthorisedValues("ITEMTYPECAT"); |
| 63 |
my $translated_languages = C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') ); |
63 |
my $translated_languages = C4::Languages::getTranslatedLanguages( "both", C4::Context->preference('template') ); |
| 64 |
$template->param( |
64 |
$template->param( |
| 65 |
itemtype => $itemtype, |
65 |
itemtype => $itemtype, |
| 66 |
parent_type => $parent_type, |
66 |
parent_type => $parent_type, |
| 67 |
parent_types => $parent_types, |
67 |
parent_types => $parent_types, |
| 68 |
is_a_parent => $itemtype ? Koha::ItemTypes->search({parent_type=>$itemtype_code})->count : 0, |
68 |
is_a_parent => $itemtype ? Koha::ItemTypes->search( { parent_type => $itemtype_code } )->count : 0, |
| 69 |
imagesets => $imagesets, |
69 |
imagesets => $imagesets, |
| 70 |
searchcategory => $searchcategory, |
70 |
searchcategory => $searchcategory, |
| 71 |
can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ), |
71 |
can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ), |
| 72 |
); |
72 |
); |
| 73 |
} elsif ( $op eq 'cud-add_validate' ) { |
73 |
} elsif ( $op eq 'cud-add_validate' ) { |
| 74 |
my $is_a_modif = $input->param('is_a_modif'); |
74 |
my $is_a_modif = $input->param('is_a_modif'); |
| 75 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
75 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
| 76 |
my $parent_type = $input->param('parent_type') || undef; |
76 |
my $parent_type = $input->param('parent_type') || undef; |
| 77 |
my $description = $input->param('description'); |
77 |
my $description = $input->param('description'); |
| 78 |
my $rentalcharge = $input->param('rentalcharge'); |
78 |
my $rentalcharge = $input->param('rentalcharge'); |
| 79 |
my $rentalcharge_daily = $input->param('rentalcharge_daily'); |
79 |
my $rentalcharge_daily = $input->param('rentalcharge_daily'); |
| 80 |
my $rentalcharge_hourly = $input->param('rentalcharge_hourly'); |
80 |
my $rentalcharge_hourly = $input->param('rentalcharge_hourly'); |
| 81 |
my $defaultreplacecost = $input->param('defaultreplacecost'); |
81 |
my $defaultreplacecost = $input->param('defaultreplacecost'); |
| 82 |
my $processfee = $input->param('processfee'); |
82 |
my $processfee = $input->param('processfee'); |
| 83 |
my $image = $input->param('image') || q||; |
83 |
my $image = $input->param('image') || q||; |
| 84 |
my @branches = grep { $_ ne q{} } $input->multi_param('branches'); |
84 |
my @branches = grep { $_ ne q{} } $input->multi_param('branches'); |
| 85 |
|
85 |
|
| 86 |
my $notforloan = $input->param('notforloan') ? 1 : 0; |
86 |
my $notforloan = $input->param('notforloan') ? 1 : 0; |
| 87 |
my $imageurl = |
87 |
my $imageurl = |
| 88 |
$image eq 'removeImage' ? '' |
88 |
$image eq 'removeImage' ? '' |
| 89 |
: ( |
89 |
: ( |
| 90 |
$image eq 'remoteImage' ? $input->param('remoteImage') |
90 |
$image eq 'remoteImage' ? $input->param('remoteImage') |
| 91 |
: $image |
91 |
: $image |
| 92 |
); |
92 |
); |
| 93 |
my $summary = $input->param('summary'); |
93 |
my $summary = $input->param('summary'); |
| 94 |
my $checkinmsg = $input->param('checkinmsg'); |
94 |
my $checkinmsg = $input->param('checkinmsg'); |
| 95 |
my $checkinmsgtype = $input->param('checkinmsgtype'); |
95 |
my $checkinmsgtype = $input->param('checkinmsgtype'); |
| 96 |
my $hideinopac = $input->param('hideinopac') // 0; |
96 |
my $hideinopac = $input->param('hideinopac') // 0; |
| 97 |
my $searchcategory = $input->param('searchcategory'); |
97 |
my $searchcategory = $input->param('searchcategory'); |
| 98 |
my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0; |
98 |
my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0; |
| 99 |
my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0; |
99 |
my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0; |
| 100 |
my $automatic_checkin = $input->param('automatic_checkin') // 0; |
100 |
my $automatic_checkin = $input->param('automatic_checkin') // 0; |
| 101 |
my $bookable = $input->param('bookable')// 0; |
101 |
my $bookable = $input->param('bookable') // 0; |
| 102 |
|
102 |
|
| 103 |
if ( $itemtype and $is_a_modif ) { # it's a modification |
103 |
if ( $itemtype and $is_a_modif ) { # it's a modification |
| 104 |
$itemtype->description($description); |
104 |
$itemtype->description($description); |
|
Lines 122-129
if ( $op eq 'add_form' ) {
Link Here
|
| 122 |
$itemtype->bookable($bookable); |
122 |
$itemtype->bookable($bookable); |
| 123 |
|
123 |
|
| 124 |
eval { |
124 |
eval { |
| 125 |
$itemtype->store; |
125 |
$itemtype->store; |
| 126 |
$itemtype->replace_library_limits( \@branches ); |
126 |
$itemtype->replace_library_limits( \@branches ); |
| 127 |
}; |
127 |
}; |
| 128 |
|
128 |
|
| 129 |
if ($@) { |
129 |
if ($@) { |
|
Lines 134-164
if ( $op eq 'add_form' ) {
Link Here
|
| 134 |
} elsif ( not $itemtype and not $is_a_modif ) { |
134 |
} elsif ( not $itemtype and not $is_a_modif ) { |
| 135 |
my $itemtype = Koha::ItemType->new( |
135 |
my $itemtype = Koha::ItemType->new( |
| 136 |
{ |
136 |
{ |
| 137 |
itemtype => $itemtype_code, |
137 |
itemtype => $itemtype_code, |
| 138 |
description => $description, |
138 |
description => $description, |
| 139 |
parent_type => $parent_type, |
139 |
parent_type => $parent_type, |
| 140 |
rentalcharge => $rentalcharge, |
140 |
rentalcharge => $rentalcharge, |
| 141 |
rentalcharge_daily => $rentalcharge_daily, |
141 |
rentalcharge_daily => $rentalcharge_daily, |
| 142 |
rentalcharge_hourly => $rentalcharge_hourly, |
142 |
rentalcharge_hourly => $rentalcharge_hourly, |
| 143 |
defaultreplacecost => $defaultreplacecost, |
143 |
defaultreplacecost => $defaultreplacecost, |
| 144 |
processfee => $processfee, |
144 |
processfee => $processfee, |
| 145 |
notforloan => $notforloan, |
145 |
notforloan => $notforloan, |
| 146 |
imageurl => $imageurl, |
146 |
imageurl => $imageurl, |
| 147 |
summary => $summary, |
147 |
summary => $summary, |
| 148 |
checkinmsg => $checkinmsg, |
148 |
checkinmsg => $checkinmsg, |
| 149 |
checkinmsgtype => $checkinmsgtype, |
149 |
checkinmsgtype => $checkinmsgtype, |
| 150 |
sip_media_type => $sip_media_type, |
150 |
sip_media_type => $sip_media_type, |
| 151 |
hideinopac => $hideinopac, |
151 |
hideinopac => $hideinopac, |
| 152 |
searchcategory => $searchcategory, |
152 |
searchcategory => $searchcategory, |
| 153 |
rentalcharge_daily_calendar => $rentalcharge_daily_calendar, |
153 |
rentalcharge_daily_calendar => $rentalcharge_daily_calendar, |
| 154 |
rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar, |
154 |
rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar, |
| 155 |
automatic_checkin => $automatic_checkin, |
155 |
automatic_checkin => $automatic_checkin, |
| 156 |
bookable => $bookable, |
156 |
bookable => $bookable, |
| 157 |
} |
157 |
} |
| 158 |
); |
158 |
); |
| 159 |
eval { |
159 |
eval { |
| 160 |
$itemtype->store; |
160 |
$itemtype->store; |
| 161 |
$itemtype->replace_library_limits( \@branches ); |
161 |
$itemtype->replace_library_limits( \@branches ); |
| 162 |
}; |
162 |
}; |
| 163 |
|
163 |
|
| 164 |
if ($@) { |
164 |
if ($@) { |
|
Lines 168-186
if ( $op eq 'add_form' ) {
Link Here
|
| 168 |
} |
168 |
} |
| 169 |
} else { |
169 |
} else { |
| 170 |
push @messages, |
170 |
push @messages, |
| 171 |
{ type => 'alert', |
171 |
{ |
|
|
172 |
type => 'alert', |
| 172 |
code => 'already_exists', |
173 |
code => 'already_exists', |
| 173 |
}; |
174 |
}; |
| 174 |
} |
175 |
} |
| 175 |
|
176 |
|
| 176 |
$searchfield = ''; |
177 |
$searchfield = ''; |
| 177 |
$op = 'list'; |
178 |
$op = 'list'; |
| 178 |
|
179 |
|
| 179 |
} elsif ( $op eq 'delete_confirm' ) { |
180 |
} elsif ( $op eq 'delete_confirm' ) { |
| 180 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
181 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
| 181 |
my $can_be_deleted = $itemtype->can_be_deleted(); |
182 |
my $can_be_deleted = $itemtype->can_be_deleted(); |
| 182 |
if ($can_be_deleted == 0) { |
183 |
if ( $can_be_deleted == 0 ) { |
| 183 |
push @messages, { type => 'alert', code => 'cannot_be_deleted'}; |
184 |
push @messages, { type => 'alert', code => 'cannot_be_deleted' }; |
| 184 |
$op = 'list'; |
185 |
$op = 'list'; |
| 185 |
} else { |
186 |
} else { |
| 186 |
$template->param( itemtype => $itemtype, ); |
187 |
$template->param( itemtype => $itemtype, ); |
|
Lines 189-195
if ( $op eq 'add_form' ) {
Link Here
|
| 189 |
} elsif ( $op eq 'cud-delete_confirmed' ) { |
190 |
} elsif ( $op eq 'cud-delete_confirmed' ) { |
| 190 |
|
191 |
|
| 191 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
192 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
| 192 |
my $deleted = eval { $itemtype->delete }; |
193 |
my $deleted = eval { $itemtype->delete }; |
| 193 |
if ( $@ or not $deleted ) { |
194 |
if ( $@ or not $deleted ) { |
| 194 |
push @messages, { type => 'alert', code => 'error_on_delete' }; |
195 |
push @messages, { type => 'alert', code => 'error_on_delete' }; |
| 195 |
} else { |
196 |
} else { |