Bug 14042: Get rid of the home made pagination in the auth type admin
[koha.git] / admin / authtypes.pl
1 #!/usr/bin/perl
2
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)
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 use strict;
24 use warnings;
25 use CGI qw ( -utf8 );
26 use C4::Context;
27 use C4::Auth;
28 use C4::Output;
29
30 sub StringSearch  {
31     my $string = shift || '';
32     my $dbh = C4::Context->dbh;
33     return $dbh->selectall_arrayref(q|
34         SELECT authtypecode, authtypetext, auth_tag_to_report, summary
35         FROM auth_types
36         WHERE (authtypecode like ?) ORDER BY authtypecode
37     |, { Slice => {} }, $string . "%" );
38 }
39
40 my $input = new CGI;
41 my $script_name  = "/cgi-bin/koha/admin/authtypes.pl";
42 my $searchfield  = $input->param('authtypecode');  # FIXME: Auth Type search not really implemented
43 my $authtypecode = $input->param('authtypecode');
44 my $op           = $input->param('op')     || '';
45 my ($template, $borrowernumber, $cookie)
46     = get_template_and_user({template_name => "admin/authtypes.tt",
47                 query => $input,
48                 type => "intranet",
49                 authnotrequired => 0,
50                 flagsrequired => {parameters => 'parameters_remaining_permissions'},
51                 debug => 1,
52                 });
53
54 $template->param(
55     script_name => $script_name,
56     ($op || 'else') => 1,
57 );
58
59 my $dbh = C4::Context->dbh;
60
61 # called by default. Used to create form to add or  modify a record
62 if ($op eq 'add_form') {
63     #---- if primkey exists, it's a modify action, so read values to modify...
64     if ($authtypecode) {
65         my $sth = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
66         $sth->execute($authtypecode);
67         my $data = $sth->fetchrow_hashref();
68         $template->param(
69             authtypecode       => $authtypecode,
70             authtypetext       => $data->{'authtypetext'},
71             auth_tag_to_report => $data->{'auth_tag_to_report'},
72             summary            => $data->{'summary'},
73         );
74     }
75                                                     # END $OP eq ADD_FORM
76 ################## ADD_VALIDATE ##################################
77 # called by add_form, used to insert/modify data in DB
78 } elsif ($op eq 'add_validate') {
79     my $sth = $input->param('modif') ? 
80             $dbh->prepare("UPDATE auth_types SET authtypetext=? ,auth_tag_to_report=?, summary=? WHERE authtypecode=?") :
81             $dbh->prepare("INSERT INTO auth_types SET authtypetext=?, auth_tag_to_report=?, summary=?, authtypecode=?") ;
82     $sth->execute($input->param('authtypetext'),$input->param('auth_tag_to_report'),$input->param('summary'),$input->param('authtypecode'));
83     print $input->redirect($script_name);    # FIXME: unnecessary redirect
84     exit;
85                                                     # END $OP eq ADD_VALIDATE
86 ################## DELETE_CONFIRM ##################################
87 # called by default form, used to confirm deletion of data in DB
88 } elsif ($op eq 'delete_confirm') {
89     #start the page and read in includes
90     my $sth=$dbh->prepare("SELECT count(*) AS total FROM auth_tag_structure WHERE authtypecode=?");
91     $sth->execute($authtypecode);
92     my $total = $sth->fetchrow_hashref->{total};
93
94     my $sth2 = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
95     $sth2->execute($authtypecode);
96     my $data = $sth2->fetchrow_hashref;
97
98     $template->param(authtypecode => $authtypecode,
99                      authtypetext => $data->{'authtypetext'},
100                           summary => $data->{'summary'},
101                             total => $total);
102                                                     # END $OP eq DELETE_CONFIRM
103 ################## DELETE_CONFIRMED ##################################
104 # called by delete_confirm, used to effectively confirm deletion of data in DB
105 } elsif ($op eq 'delete_confirmed') {
106     #start the page and read in includes
107     my $sth=$dbh->prepare("DELETE FROM auth_types WHERE authtypecode=?");
108     $sth->execute(uc $input->param('authtypecode'));
109     print $input->redirect($script_name);   # FIXME: unnecessary redirect
110     exit;
111                                                     # END $OP eq DELETE_CONFIRMED
112 ################## DEFAULT ##################################
113 } else { # DEFAULT
114     my $results = StringSearch($searchfield);
115     $template->param( loop => $results );
116 } #---- END $OP eq DEFAULT
117 output_html_with_http_headers $input, $cookie, $template->output;