Bug 14153: Noisy warns in admin/transport-cost-matrix.pl
[koha.git] / admin / biblio_framework.pl
bloba6fc24c72ad466f1500eed046ae5320c20d39cbc
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");
91 print $input->redirect($script_name); # FIXME: unnecessary redirect
92 exit;
93 # END $OP eq ADD_VALIDATE
94 ################## DELETE_CONFIRM ##################################
95 # called by default form, used to confirm deletion of data in DB
96 } elsif ($op eq 'delete_confirm') {
97 # Check both categoryitem and biblioitems, see Bug 199
98 my $sth = $dbh->prepare("select count(*) as total from biblio where frameworkcode=?");
99 $sth->execute($frameworkcode);
100 my $total = $sth->fetchrow_hashref->{total};
102 $sth = $dbh->prepare("select * from biblio_framework where frameworkcode=?");
103 $sth->execute($frameworkcode);
104 my $data = $sth->fetchrow_hashref;
106 $template->param(
107 frameworkcode => $frameworkcode,
108 frameworktext => $data->{'frameworktext'},
109 total => $total
111 # END $OP eq DELETE_CONFIRM
112 ################## DELETE_CONFIRMED ##################################
113 # called by delete_confirm, used to effectively confirm deletion of data in DB
114 } elsif ($op eq 'delete_confirmed') {
115 if ($frameworkcode) {
116 my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
117 $sth->execute($frameworkcode);
118 $sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
119 $sth->execute($frameworkcode);
120 $sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
121 $sth->execute($frameworkcode);
122 $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
123 $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
125 print $input->redirect($script_name); # FIXME: unnecessary redirect
126 exit;
127 # END $OP eq DELETE_CONFIRMED
128 ################## DEFAULT ##################################
129 } else { # DEFAULT
130 my $results = StringSearch($frameworkcode);
131 my $count = scalar(@$results);
132 my @loop_data;
133 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
134 push @loop_data, {
135 frameworkcode => $results->[$i]{'frameworkcode'},
136 frameworktext => $results->[$i]{'frameworktext'},
139 $template->param(loop => \@loop_data);
140 if ($offset>0) {
141 my $prevpage = $offset-$pagesize;
142 $template->param(previous => "$script_name?offset=".$prevpage);
144 if ($offset+$pagesize<$count) {
145 my $nextpage =$offset+$pagesize;
146 $template->param(next => "$script_name?offset=".$nextpage);
148 } #---- END $OP eq DEFAULT
150 output_html_with_http_headers $input, $cookie, $template->output;