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
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
28 my ($searchstring,$type)=@_;
29 my $dbh = C4
::Context
->dbh;
30 $searchstring=~ s/\'/\\\'/g;
31 my @data=split(' ',$searchstring);
33 my $sth=$dbh->prepare("Select * from roadtype where (road_type like ?)");
34 $sth->execute("$data[0]%");
36 while (my $data=$sth->fetchrow_hashref){
41 return (scalar(@results),\
@results);
45 my $searchfield=$input->param('road_type');
46 my $script_name="/cgi-bin/koha/admin/roadtype.pl";
47 my $roadtypeid=$input->param('roadtypeid');
48 my $op = $input->param('op');
50 my ($template, $loggedinuser, $cookie)
51 = get_template_and_user
({template_name
=> "admin/roadtype.tmpl",
55 flagsrequired
=> {parameters
=> 1},
60 $template->param( script_name
=> $script_name,
61 roadtypeid
=> $roadtypeid ,
62 searchfield
=> $searchfield);
65 ################## ADD_FORM ##################################
66 # called by default. Used to create form to add or modify a record
67 if ($op eq 'add_form') {
68 $template->param(add_form
=> 1);
70 #---- if primkey exists, it's a modify action, so read values to modify...
73 my $dbh = C4
::Context
->dbh;
74 my $sth=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
75 $sth->execute($roadtypeid);
76 $data=$sth->fetchrow_hashref;
81 road_type
=> $data->{'road_type'},
83 ##############ICI#####################
85 ################## ADD_VALIDATE #################################
86 # called by add_form, used to insert/modify data in DB
87 } elsif ($op eq 'add_validate') {
88 my $dbh = C4
::Context
->dbh;
91 if ($input->param('roadtypeid') ){
92 $sth=$dbh->prepare("UPDATE roadtype SET road_type=? WHERE roadtypeid=?");
93 $sth->execute($input->param('road_type'),$input->param('roadtypeid'));
97 $sth=$dbh->prepare("INSERT INTO roadtype (road_type) VALUES (?)");
98 $sth->execute($input->param('road_type'));
101 print $input->redirect("/cgi-bin/koha/admin/roadtype.pl");
104 # END $OP eq ADD_VALIDATE
105 ################## DELETE_CONFIRM ##################################
106 # called by default form, used to confirm deletion of data in DB
107 } elsif ($op eq 'delete_confirm') {
108 $template->param(delete_confirm
=> 1);
109 my $dbh = C4
::Context
->dbh;
110 my $sth=$dbh->prepare("select count(*) as total from borrowers,roadtype where borrowers.streettype=roadtype.road_type and roadtypeid=?");
111 $sth->execute($roadtypeid);
112 my $total = $sth->fetchrow_hashref;
114 $template->param(total
=> $total->{'total'});
115 my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
116 $sth2->execute($roadtypeid);
117 my $data=$sth2->fetchrow_hashref;
119 if ($total->{'total'} >0) {
120 $template->param(totalgtzero
=> 1);
124 road_type
=> ( $data->{'road_type'}),
128 # END $OP eq DELETE_CONFIRM
129 ################## DELETE_CONFIRMED ##################################
130 # called by delete_confirm, used to effectively confirm deletion of data in DB
131 } elsif ($op eq 'delete_confirmed') {
132 my $dbh = C4
::Context
->dbh;
133 my $categorycode=uc($input->param('roadtypeid'));
134 my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?");
135 $sth->execute($roadtypeid);
137 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
139 # END $OP eq DELETE_CONFIRMED
141 $template->param(else => 1);
143 my ($count,$results)=StringSearch
($searchfield,'web');
145 for (my $i=0; $i < $count; $i++){
146 my %row = (roadtypeid
=> $results->[$i]{'roadtypeid'},
147 road_type
=> $results->[$i]{'road_type'},
159 $template->param(loop => \
@loop);
162 } #---- END $OP eq DEFAULT
163 output_html_with_http_headers
$input, $cookie, $template->output;