Bug 11319: Template modifications
[koha.git] / admin / authtypes.pl
blobbbcfff37f8d50631cbef64cbf1209b1c41ab26fe
1 #!/usr/bin/perl
3 # written 20/02/2002 by paul.poulain@free.fr
4 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
25 use CGI;
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
30 sub StringSearch {
31 my $sth = C4::Context->dbh->prepare("SELECT * FROM auth_types WHERE (authtypecode like ?) ORDER BY authtypecode");
32 $sth->execute((shift || '') . "%");
33 return $sth->fetchall_arrayref({});
36 my $input = new CGI;
37 my $script_name = "/cgi-bin/koha/admin/authtypes.pl";
38 my $searchfield = $input->param('authtypecode'); # FIXME: Auth Type search not really implemented
39 my $authtypecode = $input->param('authtypecode');
40 my $offset = $input->param('offset') || 0;
41 my $op = $input->param('op') || '';
42 my $pagesize = 20;
43 my ($template, $borrowernumber, $cookie)
44 = get_template_and_user({template_name => "admin/authtypes.tt",
45 query => $input,
46 type => "intranet",
47 authnotrequired => 0,
48 flagsrequired => {parameters => 'parameters_remaining_permissions'},
49 debug => 1,
50 });
52 $template->param(
53 script_name => $script_name,
54 ($op || 'else') => 1,
57 my $dbh = C4::Context->dbh;
59 # called by default. Used to create form to add or modify a record
60 if ($op eq 'add_form') {
61 #---- if primkey exists, it's a modify action, so read values to modify...
62 if ($authtypecode) {
63 my $sth = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
64 $sth->execute($authtypecode);
65 my $data = $sth->fetchrow_hashref();
66 $template->param(
67 authtypecode => $authtypecode,
68 authtypetext => $data->{'authtypetext'},
69 auth_tag_to_report => $data->{'auth_tag_to_report'},
70 summary => $data->{'summary'},
73 # END $OP eq ADD_FORM
74 ################## ADD_VALIDATE ##################################
75 # called by add_form, used to insert/modify data in DB
76 } elsif ($op eq 'add_validate') {
77 my $sth = $input->param('modif') ?
78 $dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?") :
79 $dbh->prepare("INSERT INTO auth_types SET authtypetext=?, auth_tag_to_report=?, summary=?, authtypecode=?") ;
80 $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode'));
81 print $input->redirect($script_name); # FIXME: unnecessary redirect
82 exit;
83 # END $OP eq ADD_VALIDATE
84 ################## DELETE_CONFIRM ##################################
85 # called by default form, used to confirm deletion of data in DB
86 } elsif ($op eq 'delete_confirm') {
87 #start the page and read in includes
88 my $sth=$dbh->prepare("SELECT count(*) AS total FROM auth_tag_structure WHERE authtypecode=?");
89 $sth->execute($authtypecode);
90 my $total = $sth->fetchrow_hashref->{total};
92 my $sth2 = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
93 $sth2->execute($authtypecode);
94 my $data = $sth2->fetchrow_hashref;
96 $template->param(authtypecode => $authtypecode,
97 authtypetext => $data->{'authtypetext'},
98 summary => $data->{'summary'},
99 total => $total);
100 # END $OP eq DELETE_CONFIRM
101 ################## DELETE_CONFIRMED ##################################
102 # called by delete_confirm, used to effectively confirm deletion of data in DB
103 } elsif ($op eq 'delete_confirmed') {
104 #start the page and read in includes
105 my $sth=$dbh->prepare("DELETE FROM auth_types WHERE authtypecode=?");
106 $sth->execute(uc $input->param('authtypecode'));
107 print $input->redirect($script_name); # FIXME: unnecessary redirect
108 exit;
109 # END $OP eq DELETE_CONFIRMED
110 ################## DEFAULT ##################################
111 } else { # DEFAULT
112 my $results = StringSearch($searchfield);
113 my $count = scalar @$results;
114 my @loop_data;
115 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
116 push @loop_data, {
117 authtypecode => $results->[$i]{'authtypecode'},
118 authtypetext => $results->[$i]{'authtypetext'},
119 auth_tag_to_report => $results->[$i]{'auth_tag_to_report'},
120 summary => $results->[$i]{'summary'},
123 $template->param(loop => \@loop_data);
124 if ($offset>0) {
125 my $prevpage = $offset-$pagesize;
126 $template->param(previous => "$script_name?offset=".$prevpage);
128 if ($offset+$pagesize<$count) {
129 my $nextpage = $offset+$pagesize;
130 $template->param(next => "$script_name?offset=".$nextpage);
132 } #---- END $OP eq DEFAULT
133 output_html_with_http_headers $input, $cookie, $template->output;