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
30 use C4::Interface::CGI::Output;
34 my ($env,$searchstring,$type)=@_;
35 my $dbh = C4::Context->dbh;
36 $searchstring=~ s/\'/\\\'/g;
37 my @data=split(' ',$searchstring);
39 my $sth=$dbh->prepare("Select * from auth_types where (authtypecode like ?) order by authtypecode");
40 $sth->execute("$data[0]%");
42 while (my $data=$sth->fetchrow_hashref){
47 return (scalar(@results),\@results);
51 my $searchfield=$input->param('authtypecode');
52 my $offset=$input->param('offset');
53 my $script_name="/cgi-bin/koha/admin/authtypes.pl";
54 my $authtypecode=$input->param('authtypecode');
56 my $op = $input->param('op');
57 $searchfield=~ s/\,//g;
58 my ($template, $borrowernumber, $cookie)
59 = get_template_and_user({template_name => "parameters/authtypes.tmpl",
63 flagsrequired => {parameters => 1},
68 $template->param(script_name => $script_name,
69 $op => 1); # we show only the TMPL_VAR names $op
71 $template->param(script_name => $script_name,
72 else => 1); # we show only the TMPL_VAR names $op
74 ################## ADD_FORM ##################################
75 # called by default. Used to create form to add or modify a record
76 if ($op eq 'add_form') {
77 #start the page and read in includes
78 #---- if primkey exists, it's a modify action, so read values to modify...
81 my $dbh = C4::Context->dbh;
82 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
83 $sth->execute($authtypecode);
84 $data=$sth->fetchrow_hashref;
87 warn "=> $data->{'authtypetext'} : ".$data->{'summary'};
88 $template->param(authtypecode => $authtypecode,
89 authtypetext => $data->{'authtypetext'},
90 auth_tag_to_report => $data->{'auth_tag_to_report'},
91 summary => $data->{'summary'},
95 ################## ADD_VALIDATE ##################################
96 # called by add_form, used to insert/modify data in DB
97 } elsif ($op eq 'add_validate') {
98 my $dbh = C4::Context->dbh;
99 my $sth=$dbh->prepare("replace auth_types (authtypecode,authtypetext,auth_tag_to_report,summary) values (?,?,?,?)");
100 $sth->execute($input->param('authtypecode'),$input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'));
102 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
104 # END $OP eq ADD_VALIDATE
105 ################## DELETE_CONFIRM ##################################
106 # called by default form, used to confirm deletion of data in DB
107 } elsif ($op eq 'delete_confirm') {
108 #start the page and read in includes
109 my $dbh = C4::Context->dbh;
112 for my $table ('auth_tag_structure') {
113 my $sth=$dbh->prepare("select count(*) as total from $table where authtypecode=?");
114 $sth->execute($authtypecode);
115 $total += $sth->fetchrow_hashref->{total};
119 my $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
120 $sth->execute($authtypecode);
121 my $data=$sth->fetchrow_hashref;
124 $template->param(authtypecode => $authtypecode,
125 authtypetext => $data->{'authtypetext'},
126 summary => $data->{'summary'},
128 # END $OP eq DELETE_CONFIRM
129 ################## DELETE_CONFIRMED ##################################
130 # called by delete_confirm, used to effectively confirm deletion of data in DB
131 } elsif ($op eq 'delete_confirmed') {
132 #start the page and read in includes
133 my $dbh = C4::Context->dbh;
134 my $authtypecode=uc($input->param('authtypecode'));
135 my $sth=$dbh->prepare("delete from auth_tag_structure where authtypecode=?");
136 $sth->execute($authtypecode);
137 $sth=$dbh->prepare("delete from auth_subfield_structure where authtypecode=?");
138 $sth->execute($authtypecode);
139 $sth=$dbh->prepare("delete from auth_types where authtypecode=?");
140 $sth->execute($authtypecode);
142 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
144 # END $OP eq DELETE_CONFIRMED
145 ################## DEFAULT ##################################
148 my ($count,$results)=StringSearch($env,$searchfield,'web');
151 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
153 if ($toggle eq 'white'){
154 $row_data{toggle}="#ffffcc";
156 $row_data{toggle}="white";
158 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
159 $row_data{authtypetext} = $results->[$i]{'authtypetext'};
160 $row_data{auth_tag_to_report} = $results->[$i]{'auth_tag_to_report'};
161 $row_data{summary} = $results->[$i]{'summary'};
162 push(@loop_data, \%row_data);
164 $template->param(loop => \@loop_data);
166 my $prevpage = $offset-$pagesize;
167 $template->param(previous => "$script_name?offset=".$prevpage);
169 if ($offset+$pagesize<$count) {
170 my $nextpage =$offset+$pagesize;
171 $template->param(next => "$script_name?offset=".$nextpage);
173 } #---- END $OP eq DEFAULT
174 output_html_with_http_headers $input, $cookie, $template->output;