more experimental work on grouping with pazpar2
[koha.git] / admin / biblio_framework.pl
1 #!/usr/bin/perl
2 # NOTE: 4-character tabs
3
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)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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
14 # version.
15 #
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.
19 #
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
23
24 use strict;
25 use CGI;
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
29
30
31 sub StringSearch  {
32         my ($searchstring,$type)=@_;
33         my $dbh = C4::Context->dbh;
34         $searchstring=~ s/\'/\\\'/g;
35         my @data=split(' ',$searchstring);
36         my $count=@data;
37         my $sth=$dbh->prepare("Select * from biblio_framework where (frameworkcode like ?) order by frameworktext");
38         $sth->execute("$data[0]%");
39         my @results;
40         while (my $data=$sth->fetchrow_hashref){
41         push(@results,$data);
42         }
43         #  $sth->execute;
44         $sth->finish;
45         return (scalar(@results),\@results);
46 }
47
48 my $input = new CGI;
49 my $searchfield=$input->param('frameworkcode');
50 my $offset=$input->param('offset');
51 my $script_name="/cgi-bin/koha/admin/biblio_framework.pl";
52 my $frameworkcode=$input->param('frameworkcode');
53 my $pagesize=20;
54 my $op = $input->param('op');
55 $searchfield=~ s/\,//g;
56 my ($template, $borrowernumber, $cookie)
57     = get_template_and_user({template_name => "admin/biblio_framework.tmpl",
58                              query => $input,
59                              type => "intranet",
60                              authnotrequired => 0,
61                              flagsrequired => {parameters => 1},
62                              debug => 1,
63                              });
64
65 if ($op) {
66 $template->param(script_name => $script_name,
67                                                 $op              => 1); # we show only the TMPL_VAR names $op
68 } else {
69 $template->param(script_name => $script_name,
70                                                 else              => 1); # we show only the TMPL_VAR names $op
71 }
72
73
74
75
76 ################## ADD_FORM ##################################
77 # called by default. Used to create form to add or  modify a record
78 if ($op eq 'add_form') {
79         #start the page and read in includes
80         #---- if primkey exists, it's a modify action, so read values to modify...
81         my $data;
82         if ($frameworkcode) {
83                 my $dbh = C4::Context->dbh;
84                 my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
85                 $sth->execute($frameworkcode);
86                 $data=$sth->fetchrow_hashref;
87                 $sth->finish;
88         }
89         $template->param(frameworkcode => $frameworkcode,
90                                                         frameworktext => $data->{'frameworktext'},
91                                                         );
92 ;
93                                                                                                         # END $OP eq ADD_FORM
94 ################## ADD_VALIDATE ##################################
95 # called by add_form, used to insert/modify data in DB
96 } elsif ($op eq 'add_validate') {
97         my $dbh = C4::Context->dbh;
98     if ($input->param('modif')) {
99         my $sth=$dbh->prepare("UPDATE biblio_framework SET frameworktext=? WHERE frameworkcode=?");
100         $sth->execute($input->param('frameworktext'),$input->param('frameworkcode'));
101         $sth->finish;
102     } else {
103         my $sth=$dbh->prepare("INSERT into biblio_framework (frameworkcode,frameworktext) values (?,?)");
104         $sth->execute($input->param('frameworkcode'),$input->param('frameworktext'));
105         $sth->finish;
106     }
107         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=biblio_framework.pl\"></html>";
108         exit;
109                                                                                                         # END $OP eq ADD_VALIDATE
110 ################## DELETE_CONFIRM ##################################
111 # called by default form, used to confirm deletion of data in DB
112 } elsif ($op eq 'delete_confirm') {
113         #start the page and read in includes
114         my $dbh = C4::Context->dbh;
115
116         # Check both categoryitem and biblioitems, see Bug 199
117         my $total = 0;
118         for my $table ('marc_tag_structure') {
119            my $sth=$dbh->prepare("select count(*) as total from $table where frameworkcode=?");
120            $sth->execute($frameworkcode);
121            $total += $sth->fetchrow_hashref->{total};
122            $sth->finish;
123         }
124
125         my $sth=$dbh->prepare("select * from biblio_framework where frameworkcode=?");
126         $sth->execute($frameworkcode);
127         my $data=$sth->fetchrow_hashref;
128         $sth->finish;
129
130         $template->param(frameworkcode => $frameworkcode,
131                                                         frameworktext => $data->{'frameworktext'},
132                                                         total => $total);
133                                                                                                         # END $OP eq DELETE_CONFIRM
134 ################## DELETE_CONFIRMED ##################################
135 # called by delete_confirm, used to effectively confirm deletion of data in DB
136 } elsif ($op eq 'delete_confirmed') {
137         #start the page and read in includes
138         my $dbh = C4::Context->dbh;
139         my $frameworkcode=uc($input->param('frameworkcode'));
140         my $sth=$dbh->prepare("delete from marc_tag_structure where frameworkcode=?");
141         $sth->execute($frameworkcode);
142         $sth=$dbh->prepare("delete from marc_subfield_structure where frameworkcode=?");
143         $sth->execute($frameworkcode);
144         $sth=$dbh->prepare("delete from biblio_framework where frameworkcode=?");
145         $sth->execute($frameworkcode);
146         $sth->finish;
147         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=biblio_framework.pl\"></html>";
148         exit;
149                                                                                                         # END $OP eq DELETE_CONFIRMED
150 ################## DEFAULT ##################################
151 } else { # DEFAULT
152         my ($count,$results)=StringSearch($searchfield,'web');
153         my $toggle="white";
154         my @loop_data;
155         for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
156                 my %row_data;
157                 if ($toggle eq 'white'){
158                         $row_data{toggle}="#ffffcc";
159                 } else {
160                         $row_data{toggle}="white";
161                 }
162                 $row_data{frameworkcode} = $results->[$i]{'frameworkcode'};
163                 $row_data{frameworktext} = $results->[$i]{'frameworktext'};
164                 push(@loop_data, \%row_data);
165         }
166         $template->param(loop => \@loop_data);
167         if ($offset>0) {
168                 my $prevpage = $offset-$pagesize;
169                 $template->param(previous => "$script_name?offset=".$prevpage);
170         }
171         if ($offset+$pagesize<$count) {
172                 my $nextpage =$offset+$pagesize;
173                 $template->param(next => "$script_name?offset=".$nextpage);
174         }
175 } #---- END $OP eq DEFAULT
176 output_html_with_http_headers $input, $cookie, $template->output;
177
178 # Local Variables:
179 # tab-width: 4
180 # End: