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 ($searchstring,$type)=@_;
33 my $dbh = C4::Context->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
37 my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE (authtypecode like ?) ORDER BY authtypecode");
38 $sth->execute("$data[0]%");
40 while (my $data=$sth->fetchrow_hashref){
45 return (scalar(@results),\@results);
49 my $searchfield=$input->param('authtypecode');
50 my $offset=$input->param('offset');
51 my $script_name="/cgi-bin/koha/admin/authtypes.pl";
52 my $authtypecode=$input->param('authtypecode');
54 my $op = $input->param('op');
55 $searchfield=~ s/\,//g;
56 my ($template, $borrowernumber, $cookie)
57 = get_template_and_user({template_name => "admin/authtypes.tmpl",
61 flagsrequired => {parameters => 1},
66 $template->param(script_name => $script_name,
67 $op => 1); # we show only the TMPL_VAR names $op
69 $template->param(script_name => $script_name,
70 'else' => 1); # we show only the TMPL_VAR names $op
72 ################## ADD_FORM ##################################
73 # called by default. Used to create form to add or modify a record
74 if ($op eq 'add_form') {
75 #start the page and read in includes
76 #---- if primkey exists, it's a modify action, so read values to modify...
79 my $dbh = C4::Context->dbh;
80 my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
81 $sth->execute($authtypecode);
82 $data=$sth->fetchrow_hashref;
84 $template->param(authtypecode => $authtypecode,
85 authtypetext => $data->{'authtypetext'},
86 auth_tag_to_report => $data->{'auth_tag_to_report'},
87 summary => $data->{'summary'},
91 ################## ADD_VALIDATE ##################################
92 # called by add_form, used to insert/modify data in DB
93 } elsif ($op eq 'add_validate') {
94 my $dbh = C4::Context->dbh;
95 if ($input->param('modif')) {
96 my $sth=$dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?");
97 $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode'));
100 my $sth=$dbh->prepare("INSERT INTO auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=?, authtypecode=?");
101 $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode'));
104 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
106 # END $OP eq ADD_VALIDATE
107 ################## DELETE_CONFIRM ##################################
108 # called by default form, used to confirm deletion of data in DB
109 } elsif ($op eq 'delete_confirm') {
110 #start the page and read in includes
111 my $dbh = C4::Context->dbh;
114 for my $table ('auth_tag_structure') {
115 my $sth=$dbh->prepare("SELECT count(*) AS total FROM $table WHERE authtypecode=?");
116 $sth->execute($authtypecode);
117 $total += $sth->fetchrow_hashref->{total};
121 my $sth=$dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
122 $sth->execute($authtypecode);
123 my $data=$sth->fetchrow_hashref;
126 $template->param(authtypecode => $authtypecode,
127 authtypetext => $data->{'authtypetext'},
128 summary => $data->{'summary'},
130 # END $OP eq DELETE_CONFIRM
131 ################## DELETE_CONFIRMED ##################################
132 # called by delete_confirm, used to effectively confirm deletion of data in DB
133 } elsif ($op eq 'delete_confirmed') {
134 #start the page and read in includes
135 my $dbh = C4::Context->dbh;
136 my $authtypecode=uc($input->param('authtypecode'));
137 my $sth=$dbh->prepare("DELETE FROM auth_types WHERE authtypecode=?");
138 $sth->execute($authtypecode);
140 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
142 # END $OP eq DELETE_CONFIRMED
143 ################## DEFAULT ##################################
145 my ($count,$results)=StringSearch($searchfield,'web');
148 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
150 if ($toggle eq 'white'){
151 $row_data{toggle}="#ffffcc";
153 $row_data{toggle}="white";
155 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
156 $row_data{authtypetext} = $results->[$i]{'authtypetext'};
157 $row_data{auth_tag_to_report} = $results->[$i]{'auth_tag_to_report'};
158 $row_data{summary} = $results->[$i]{'summary'};
159 push(@loop_data, \%row_data);
161 $template->param(loop => \@loop_data);
163 my $prevpage = $offset-$pagesize;
164 $template->param(previous => "$script_name?offset=".$prevpage);
166 if ($offset+$pagesize<$count) {
167 my $nextpage =$offset+$pagesize;
168 $template->param(next => "$script_name?offset=".$nextpage);
170 } #---- END $OP eq DEFAULT
171 output_html_with_http_headers $input, $cookie, $template->output;