Followup 300bd572d3d21bbde1e91e8682611ad224992a7a
[koha.git] / admin / roadtype.pl
blobdd3bbe09e08998c6a0a30aa9ff3d1f85fa5c70fb
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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 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 $sth=$dbh->prepare("select count(*) as total from borrowers,roadtype where borrowers.streettype=roadtype.road_type and roadtypeid=?");
102 $sth->execute($roadtypeid);
103 my $total = $sth->fetchrow_hashref;
104 $sth->finish;
105 $template->param(total => $total->{'total'});
106 my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
107 $sth2->execute($roadtypeid);
108 my $data=$sth2->fetchrow_hashref;
109 $sth2->finish;
110 if ($total->{'total'} >0) {
111 $template->param(totalgtzero => 1);
114 $template->param(
115 road_type => ( $data->{'road_type'}),
119 # END $OP eq DELETE_CONFIRM
120 ################## DELETE_CONFIRMED ##################################
121 # called by delete_confirm, used to effectively confirm deletion of data in DB
122 } elsif ($op eq 'delete_confirmed') {
123 my $dbh = C4::Context->dbh;
124 my $categorycode=uc($input->param('roadtypeid'));
125 my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?");
126 $sth->execute($roadtypeid);
127 $sth->finish;
128 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
129 exit;
130 # END $OP eq DELETE_CONFIRMED
131 } else { # DEFAULT
132 $template->param(else => 1);
133 $template->param(loop => StringSearch($searchfield));
136 } #---- END $OP eq DEFAULT
137 output_html_with_http_headers $input, $cookie, $template->output;