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