Translation updates for Koha 3.22.10
[koha.git] / admin / biblio_framework.pl
blob2a81f88ef80ce360b21ea9a00aec1cd7ffc372a3
1 #!/usr/bin/perl
2 # NOTE: 4-character tabs
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it
12 # under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3 of the License, or
14 # (at your option) any later version.
16 # Koha is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use strict;
25 use warnings;
26 use CGI qw ( -utf8 );
27 use C4::Context;
28 use C4::Auth;
29 use C4::Output;
30 use Koha::Cache;
32 sub StringSearch {
33 my $dbh = C4::Context->dbh;
34 my $sth=$dbh->prepare("Select * from biblio_framework where (frameworkcode like ?) order by frameworktext");
35 $sth->execute((shift || '') . '%');
36 return $sth->fetchall_arrayref({});
39 my $input = new CGI;
40 my $script_name = "/cgi-bin/koha/admin/biblio_framework.pl";
41 my $frameworkcode = $input->param('frameworkcode') || '';
42 my $offset = $input->param('offset') || 0;
43 my $op = $input->param('op') || '';
44 my $pagesize = 20;
45 my $cache = Koha::Cache->get_instance();
47 my ($template, $borrowernumber, $cookie)
48 = get_template_and_user({template_name => "admin/biblio_framework.tt",
49 query => $input,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => {parameters => 'parameters_remaining_permissions'},
53 debug => 1,
54 });
56 $template->param( script_name => $script_name);
57 $template->param(($op||'else') => 1);
59 my $dbh = C4::Context->dbh;
60 ################## ADD_FORM ##################################
61 # called by default. Used to create form to add or modify a record
62 if ($op eq 'add_form') {
63 #start the page and read in includes
64 #---- if primkey exists, it's a modify action, so read values to modify...
65 my $data;
66 if ($frameworkcode) {
67 my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
68 $sth->execute($frameworkcode);
69 $data=$sth->fetchrow_hashref;
71 $template->param(
72 frameworkcode => $frameworkcode,
73 frameworktext => $data->{'frameworktext'},
75 # END $OP eq ADD_FORM
76 ################## ADD_VALIDATE ##################################
77 # called by add_form, used to insert/modify data in DB
78 } elsif ($op eq 'add_validate') {
79 my $dbh = C4::Context->dbh;
80 if ( $input->param('frameworktext') and $frameworkcode ) {
81 if ($input->param('modif')) {
82 my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
83 $sth->execute( $input->param('frameworktext'), $frameworkcode );
84 } else {
85 my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
86 $sth->execute( $frameworkcode, $input->param('frameworktext') );
88 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
89 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
90 $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
92 print $input->redirect($script_name); # FIXME: unnecessary redirect
93 exit;
94 # END $OP eq ADD_VALIDATE
95 ################## DELETE_CONFIRM ##################################
96 # called by default form, used to confirm deletion of data in DB
97 } elsif ($op eq 'delete_confirm') {
98 # Check both categoryitem and biblioitems, see Bug 199
99 my $sth = $dbh->prepare("select count(*) as total from biblio where frameworkcode=?");
100 $sth->execute($frameworkcode);
101 my $total = $sth->fetchrow_hashref->{total};
103 $sth = $dbh->prepare("select * from biblio_framework where frameworkcode=?");
104 $sth->execute($frameworkcode);
105 my $data = $sth->fetchrow_hashref;
107 $template->param(
108 frameworkcode => $frameworkcode,
109 frameworktext => $data->{'frameworktext'},
110 total => $total
112 # END $OP eq DELETE_CONFIRM
113 ################## DELETE_CONFIRMED ##################################
114 # called by delete_confirm, used to effectively confirm deletion of data in DB
115 } elsif ($op eq 'delete_confirmed') {
116 if ($frameworkcode) {
117 my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
118 $sth->execute($frameworkcode);
119 $sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
120 $sth->execute($frameworkcode);
121 $sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
122 $sth->execute($frameworkcode);
123 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
124 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
125 $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
127 print $input->redirect($script_name); # FIXME: unnecessary redirect
128 exit;
129 # END $OP eq DELETE_CONFIRMED
130 ################## DEFAULT ##################################
131 } else { # DEFAULT
132 my $results = StringSearch($frameworkcode);
133 my $count = scalar(@$results);
134 my @loop_data;
135 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
136 push @loop_data, {
137 frameworkcode => $results->[$i]{'frameworkcode'},
138 frameworktext => $results->[$i]{'frameworktext'},
141 $template->param(loop => \@loop_data);
142 if ($offset>0) {
143 my $prevpage = $offset-$pagesize;
144 $template->param(previous => "$script_name?offset=".$prevpage);
146 if ($offset+$pagesize<$count) {
147 my $nextpage =$offset+$pagesize;
148 $template->param(next => "$script_name?offset=".$nextpage);
150 } #---- END $OP eq DEFAULT
152 output_html_with_http_headers $input, $cookie, $template->output;