Bug 22949: Markup error in OPAC course reserves template
[koha.git] / admin / biblio_framework.pl
blob0c30e95774fccf9c8836eca16799e5e3ee82ee8b
1 #!/usr/bin/perl
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 use Modern::Perl;
22 use CGI qw ( -utf8 );
23 use C4::Context;
24 use C4::Auth;
25 use C4::Output;
26 use Koha::Biblios;
27 use Koha::BiblioFramework;
28 use Koha::BiblioFrameworks;
29 use Koha::Caches;
31 my $input = new CGI;
32 my $frameworkcode = $input->param('frameworkcode') || q||;
33 my $op = $input->param('op') || q|list|;
34 my $cache = Koha::Caches->get_instance();
35 my @messages;
37 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 { template_name => "admin/biblio_framework.tt",
39 query => $input,
40 type => "intranet",
41 authnotrequired => 0,
42 flagsrequired => { parameters => 'manage_marc_frameworks' },
43 debug => 1,
47 my $dbh = C4::Context->dbh;
48 if ( $op eq 'add_form' ) {
49 my $framework;
50 if ($frameworkcode) {
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');
57 my $is_a_modif = $input->param('is_a_modif');
59 if ($is_a_modif) {
60 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
61 $framework->frameworktext($frameworktext);
62 eval { $framework->store; };
63 if ($@) {
64 push @messages, { type => 'error', code => 'error_on_update' };
65 } else {
66 push @messages, { type => 'message', code => 'success_on_update' };
68 } else {
69 my $framework = Koha::BiblioFramework->new(
70 { frameworkcode => $frameworkcode,
71 frameworktext => $frameworktext,
74 eval { $framework->store; };
75 if ($@) {
76 push @messages, { type => 'error', code => 'error_on_insert' };
77 } else {
78 push @messages, { type => 'message', code => 'success_on_insert' };
81 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
82 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
83 $cache->clear_from_cache("default_value_for_mod_marc-");
84 $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
85 $op = 'list';
86 } elsif ( $op eq 'delete_confirm' ) {
87 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
88 my $count = Koha::Biblios->search( { frameworkcode => $frameworkcode, } )->count;
90 $template->param(
91 framework => $framework,
92 biblios_use_this_framework => $count,
94 } elsif ( $op eq 'delete_confirmed' ) {
95 my $framework = Koha::BiblioFrameworks->find($frameworkcode);
96 my $deleted = eval { $framework->delete; };
98 if ( $@ or not $deleted ) {
99 push @messages, { type => 'error', code => 'error_on_delete' };
100 } else {
101 eval {
102 my $dbh = C4::Context->dbh;
103 $dbh->do( q|DELETE FROM marc_tag_structure WHERE frameworkcode=?|, undef, $frameworkcode );
104 $dbh->do( q|DELETE FROM marc_subfield_structure WHERE frameworkcode=?|, undef, $frameworkcode );
106 if ($@) {
107 push @messages, { type => 'error', code => 'error_on_delete_fk' };
108 } else {
109 push @messages, { type => 'message', code => 'success_on_delete' };
112 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
113 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
114 $cache->clear_from_cache("default_value_for_mod_marc-");
115 $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
116 $op = 'list';
119 if ( $op eq 'list' ) {
120 my $frameworks = Koha::BiblioFrameworks->search( {}, { order_by => ['frameworktext'], } );
121 $template->param( frameworks => $frameworks, );
124 $template->param(
125 messages => \@messages,
126 op => $op,
129 output_html_with_http_headers $input, $cookie, $template->output;