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>.
27 use Koha::BiblioFramework;
28 use Koha::BiblioFrameworks;
32 my $frameworkcode = $input->param('frameworkcode') || q||;
33 my $op = $input->param('op') || q|list|;
34 my $cache = Koha::Cache->get_instance();
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 { template_name => "admin/biblio_framework.tt",
42 flagsrequired => { parameters => 'parameters_remaining_permissions' },
47 my $dbh = C4::Context->dbh;
48 if ( $op eq 'add_form' ) {
51 $framework = Koha::BiblioFrameworks->find($frameworkcode);
53 $template->param( framework => $framework );
54 } elsif ( $op eq 'add_validate' ) {
55 my $frameworkcode = $input->param('frameworkcode');
56 my $frameworktext = $input->param('frameworktext');
58 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
60 $framework->frameworktext($frameworktext);
61 eval { $framework->store; };
63 push @messages, { type => 'error', code => 'error_on_update' };
65 push @messages, { type => 'message', code => 'success_on_update' };
68 $framework = Koha::BiblioFramework->new(
69 { frameworkcode => $frameworkcode,
70 frameworktext => $frameworktext,
73 eval { $framework->store; };
75 push @messages, { type => 'error', code => 'error_on_insert' };
77 push @messages, { type => 'message', code => 'success_on_insert' };
80 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
81 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
83 } elsif ( $op eq 'delete_confirm' ) {
84 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
85 my $count = Koha::Biblios->search( { frameworkcode => $frameworkcode, } )->count;
88 framework => $framework,
89 biblios_use_this_framework => $count,
91 } elsif ( $op eq 'delete_confirmed' ) {
92 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
93 my $deleted = eval { $framework->delete; };
95 if ( $@ or not $deleted ) {
96 push @messages, { type => 'error', code => 'error_on_delete' };
99 my $dbh = C4::Context->dbh;
100 $dbh->do( q|DELETE FROM marc_tag_structure WHERE frameworkcode=?|, undef, $frameworkcode );
101 $dbh->do( q|DELETE FROM marc_subfield_structure WHERE frameworkcode=?|, undef, $frameworkcode );
104 push @messages, { type => 'error', code => 'error_on_delete_fk' };
106 push @messages, { type => 'message', code => 'success_on_delete' };
109 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
110 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
114 if ( $op eq 'list' ) {
115 my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'], } );
116 $template->param( frameworks => $frameworks, );
120 messages => \@messages,
124 output_html_with_http_headers $input, $cookie, $template->output;