Lines 31-38
use C4::Koha;
Link Here
|
31 |
use C4::Context; |
31 |
use C4::Context; |
32 |
use C4::Auth; |
32 |
use C4::Auth; |
33 |
use C4::Output; |
33 |
use C4::Output; |
34 |
|
|
|
35 |
use Koha::ItemTypes; |
34 |
use Koha::ItemTypes; |
|
|
35 |
use Koha::ItemType; |
36 |
use Koha::Localizations; |
36 |
use Koha::Localizations; |
37 |
|
37 |
|
38 |
my $input = new CGI; |
38 |
my $input = new CGI; |
Lines 137-156
if ( $op eq 'add_form' ) {
Link Here
|
137 |
|
137 |
|
138 |
$searchfield = ''; |
138 |
$searchfield = ''; |
139 |
$op = 'list'; |
139 |
$op = 'list'; |
140 |
} elsif ( $op eq 'delete_confirm' ) { |
140 |
|
141 |
|
141 |
} elsif ( $op eq 'delete_confirm' ) { |
142 |
# Check both items and biblioitems |
142 |
my $ItemType = Koha::ItemType->new(); |
143 |
my ($total) = $dbh->selectrow_array( ' |
143 |
my $overalltotal = $ItemType->can_be_deleted(); |
144 |
SELECT COUNT(*) AS total FROM ( |
144 |
if ($overalltotal == 0) { |
145 |
SELECT itemtype AS t FROM biblioitems |
145 |
push @messages, { type => 'error', code => 'cannot_be_deleted'}; |
146 |
UNION ALL |
|
|
147 |
SELECT itype AS t FROM items |
148 |
) AS tmp |
149 |
WHERE tmp.t=? |
150 |
', {}, $itemtype_code ); |
151 |
|
152 |
if ($total) { |
153 |
push @messages, { type => 'error', code => 'cannot_be_deleted', total => $total }; |
154 |
$op = 'list'; |
146 |
$op = 'list'; |
155 |
} else { |
147 |
} else { |
156 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
148 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
Lines 158-165
if ( $op eq 'add_form' ) {
Link Here
|
158 |
} |
150 |
} |
159 |
|
151 |
|
160 |
} elsif ( $op eq 'delete_confirmed' ) { |
152 |
} elsif ( $op eq 'delete_confirmed' ) { |
|
|
153 |
|
161 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
154 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
162 |
my $deleted = eval { $itemtype->delete }; |
155 |
my $deleted = eval{ $itemtype->delete };; |
163 |
if ( $@ or not $deleted ) { |
156 |
if ( $@ or not $deleted ) { |
164 |
push @messages, { type => 'error', code => 'error_on_delete' }; |
157 |
push @messages, { type => 'error', code => 'error_on_delete' }; |
165 |
} else { |
158 |
} else { |