Bug 5143: Help file revisions per Owen Leonard
[koha.git] / admin / roadtype.pl
bloba75659437fb5b4c2395a0761d86a88cd70ba790f
1 #! /usr/bin/perl
3 # Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use strict;
21 use warnings;
23 use CGI;
24 use C4::Context;
25 use C4::Output;
26 use C4::Auth;
29 sub StringSearch {
30 my $sth = C4::Context->dbh->prepare("Select * from roadtype where (road_type like ?) ORDER BY road_type");
31 $sth->execute((shift || '') . '%');
32 return $sth->fetchall_arrayref({});
35 my $input = new CGI;
36 my $searchfield=$input->param('road_type');
37 my $script_name="/cgi-bin/koha/admin/roadtype.pl";
38 my $roadtypeid=$input->param('roadtypeid');
39 my $op = $input->param('op') || '';
41 my ($template, $loggedinuser, $cookie)
42 = get_template_and_user({template_name => "admin/roadtype.tmpl",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => {parameters => 1},
47 debug => 1,
48 });
51 $template->param( script_name => $script_name,
52 roadtypeid => $roadtypeid ,
53 searchfield => $searchfield);
56 ################## ADD_FORM ##################################
57 # called by default. Used to create form to add or modify a record
58 if ($op eq 'add_form') {
59 $template->param(add_form => 1);
61 #---- if primkey exists, it's a modify action, so read values to modify...
62 my $data;
63 if ($roadtypeid) {
64 my $dbh = C4::Context->dbh;
65 my $sth=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
66 $sth->execute($roadtypeid);
67 $data=$sth->fetchrow_hashref;
68 $sth->finish;
71 $template->param(
72 road_type => $data->{'road_type'},
74 ##############ICI#####################
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 $dbh = C4::Context->dbh;
80 my $sth;
82 if ($input->param('roadtypeid') ){
83 $sth=$dbh->prepare("UPDATE roadtype SET road_type=? WHERE roadtypeid=?");
84 $sth->execute($input->param('road_type'),$input->param('roadtypeid'));
87 else{
88 $sth=$dbh->prepare("INSERT INTO roadtype (road_type) VALUES (?)");
89 $sth->execute($input->param('road_type'));
91 $sth->finish;
92 print $input->redirect("/cgi-bin/koha/admin/roadtype.pl");
93 exit;
95 # END $OP eq ADD_VALIDATE
96 ################## DELETE_CONFIRM ##################################
97 # called by default form, used to confirm deletion of data in DB
98 } elsif ($op eq 'delete_confirm') {
99 $template->param(delete_confirm => 1);
100 my $dbh = C4::Context->dbh;
101 my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
102 $sth2->execute($roadtypeid);
103 my $data=$sth2->fetchrow_hashref;
104 $sth2->finish;
106 $template->param(
107 road_type => ( $data->{'road_type'}),
111 # END $OP eq DELETE_CONFIRM
112 ################## DELETE_CONFIRMED ##################################
113 # called by delete_confirm, used to effectively confirm deletion of data in DB
114 } elsif ($op eq 'delete_confirmed') {
115 my $dbh = C4::Context->dbh;
116 my $categorycode=uc($input->param('roadtypeid'));
117 my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?");
118 $sth->execute($roadtypeid);
119 $sth->finish;
120 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
121 exit;
122 # END $OP eq DELETE_CONFIRMED
123 } else { # DEFAULT
124 $template->param(else => 1);
125 $template->param(loop => StringSearch($searchfield));
128 } #---- END $OP eq DEFAULT
129 output_html_with_http_headers $input, $cookie, $template->output;