|
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-163
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::ItemTypes->find($itemtype_code); |
| 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 |
$template->param( itemtype => $ItemType, ); |
| 157 |
$template->param( itemtype => $itemtype, ); |
|
|
| 158 |
} |
149 |
} |
| 159 |
|
150 |
|
| 160 |
} elsif ( $op eq 'delete_confirmed' ) { |
151 |
} elsif ( $op eq 'delete_confirmed' ) { |
|
|
152 |
|
| 161 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
153 |
my $itemtype = Koha::ItemTypes->find($itemtype_code); |
| 162 |
my $deleted = eval { $itemtype->delete }; |
154 |
my $deleted = eval { $itemtype->delete }; |
| 163 |
if ( $@ or not $deleted ) { |
155 |
if ( $@ or not $deleted ) { |