Bug 9468: use new SUGGEST_FORMAT list
[koha.git] / admin / authtypes.pl
1 #!/usr/bin/perl
2
3 # written 20/02/2002 by paul.poulain@free.fr
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Auth;
26 use C4::Output;
27
28 sub StringSearch  {
29     my $string = shift || '';
30     my $dbh = C4::Context->dbh;
31     return $dbh->selectall_arrayref(q|
32         SELECT authtypecode, authtypetext, auth_tag_to_report, summary
33         FROM auth_types
34         WHERE (authtypecode like ?) ORDER BY authtypecode
35     |, { Slice => {} }, $string . "%" );
36 }
37
38 my $input = new CGI;
39 my $script_name  = "/cgi-bin/koha/admin/authtypes.pl";
40 my $searchfield  = $input->param('authtypecode');  # FIXME: Auth Type search not really implemented
41 my $authtypecode = $input->param('authtypecode');
42 my $op           = $input->param('op')     || '';
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                 });
51
52 $template->param(
53     script_name => $script_name,
54     ($op || 'else') => 1,
55 );
56
57 my $dbh = C4::Context->dbh;
58
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 ( defined $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'},
71         );
72     }
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};
91
92     my $sth2 = $dbh->prepare("SELECT * FROM auth_types WHERE authtypecode=?");
93     $sth2->execute($authtypecode);
94     my $data = $sth2->fetchrow_hashref;
95
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     $template->param( loop => $results );
114 } #---- END $OP eq DEFAULT
115 output_html_with_http_headers $input, $cookie, $template->output;