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 under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
32 my $dbh = C4::Context->dbh;
33 my $sth=$dbh->prepare("Select * from biblio_framework where (frameworkcode like ?) order by frameworktext");
34 $sth->execute((shift || '') . '%');
35 return $sth->fetchall_arrayref({});
39 my $script_name = "/cgi-bin/koha/admin/biblio_framework.pl";
40 my $frameworkcode = $input->param('frameworkcode') || '';
41 my $offset = $input->param('offset') || 0;
42 my $op = $input->param('op') || '';
45 my ($template, $borrowernumber, $cookie)
46 = get_template_and_user({template_name => "admin/biblio_framework.tmpl",
50 flagsrequired => {parameters => 1},
54 $template->param( script_name => $script_name);
55 $template->param(($op||'else') => 1);
57 my $dbh = C4::Context->dbh;
58 ################## ADD_FORM ##################################
59 # called by default. Used to create form to add or modify a record
60 if ($op eq 'add_form') {
61 #start the page and read in includes
62 #---- if primkey exists, it's a modify action, so read values to modify...
65 my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
66 $sth->execute($frameworkcode);
67 $data=$sth->fetchrow_hashref;
70 frameworkcode => $frameworkcode,
71 frameworktext => $data->{'frameworktext'},
74 ################## ADD_VALIDATE ##################################
75 # called by add_form, used to insert/modify data in DB
76 } elsif ($op eq 'add_validate') {
77 if ($input->param('modif')) {
78 my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
79 $sth->execute($input->param('frameworktext'),$input->param('frameworkcode'));
81 my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
82 $sth->execute($input->param('frameworkcode'),$input->param('frameworktext'));
84 print $input->redirect($script_name); # FIXME: unnecessary redirect
86 # END $OP eq ADD_VALIDATE
87 ################## DELETE_CONFIRM ##################################
88 # called by default form, used to confirm deletion of data in DB
89 } elsif ($op eq 'delete_confirm') {
90 # Check both categoryitem and biblioitems, see Bug 199
91 my $sth = $dbh->prepare("select count(*) as total from marc_tag_structure where frameworkcode=?");
92 $sth->execute($frameworkcode);
93 my $total = $sth->fetchrow_hashref->{total};
95 $sth = $dbh->prepare("select * from biblio_framework where frameworkcode=?");
96 $sth->execute($frameworkcode);
97 my $data = $sth->fetchrow_hashref;
100 frameworkcode => $frameworkcode,
101 frameworktext => $data->{'frameworktext'},
104 # END $OP eq DELETE_CONFIRM
105 ################## DELETE_CONFIRMED ##################################
106 # called by delete_confirm, used to effectively confirm deletion of data in DB
107 } elsif ($op eq 'delete_confirmed') {
108 if ($frameworkcode) {
109 my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
110 $sth->execute($frameworkcode);
111 $sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
112 $sth->execute($frameworkcode);
113 $sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
114 $sth->execute($frameworkcode);
116 print $input->redirect($script_name); # FIXME: unnecessary redirect
118 # END $OP eq DELETE_CONFIRMED
119 ################## DEFAULT ##################################
121 my $results = StringSearch($frameworkcode);
122 my $count = scalar(@$results);
124 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
126 frameworkcode => $results->[$i]{'frameworkcode'},
127 frameworktext => $results->[$i]{'frameworktext'},
130 $template->param(loop => \@loop_data);
132 my $prevpage = $offset-$pagesize;
133 $template->param(previous => "$script_name?offset=".$prevpage);
135 if ($offset+$pagesize<$count) {
136 my $nextpage =$offset+$pagesize;
137 $template->param(next => "$script_name?offset=".$nextpage);
139 } #---- END $OP eq DEFAULT
141 output_html_with_http_headers $input, $cookie, $template->output;