Fix for bug 1296, making surnames uppercase a systems preference
[koha.git] / admin / roadtype.pl
1 #! /usr/bin/perl
2
3 # Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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
19
20 use strict;
21 use CGI;
22 use C4::Context;
23 use C4::Output;
24 use C4::Auth;
25
26
27 sub StringSearch  {
28         my ($searchstring,$type)=@_;
29         my $dbh = C4::Context->dbh;
30         $searchstring=~ s/\'/\\\'/g;
31         my @data=split(' ',$searchstring);
32         my $count=@data;
33         my $sth=$dbh->prepare("Select * from roadtype where (road_type like ?)");
34         $sth->execute("$data[0]%");
35         my @results;
36         while (my $data=$sth->fetchrow_hashref){
37         push(@results,$data);
38         }
39         #  $sth->execute;
40         $sth->finish;
41         return (scalar(@results),\@results);
42 }
43
44 my $input = new CGI;
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');
49
50 my ($template, $loggedinuser, $cookie)
51     = get_template_and_user({template_name => "admin/roadtype.tmpl",
52                              query => $input,
53                              type => "intranet",
54                              authnotrequired => 0,
55                              flagsrequired => {parameters => 1},
56                              debug => 1,
57                              });
58
59
60 $template->param(       script_name => $script_name,
61                         roadtypeid => $roadtypeid ,
62                         searchfield => $searchfield);
63
64
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);
69         
70         #---- if primkey exists, it's a modify action, so read values to modify...
71         my $data;
72         if ($roadtypeid) {
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;
77                 $sth->finish;
78         }
79
80         $template->param(       
81                                 road_type       => $data->{'road_type'},
82                         );
83 ##############ICI#####################
84 # END $OP eq ADD_FORM
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;
89         my $sth;
90         
91         if ($input->param('roadtypeid') ){
92                 $sth=$dbh->prepare("replace roadtype (roadtypeid,road_type) values (?,?) ");
93                 $sth->execute(map { $input->param($_) } ('roadtypeid','road_type'));
94         
95         }
96         else{   
97                 $sth=$dbh->prepare("replace roadtype (road_type) values (?)");
98                 $sth->execute(map { $input->param($_) } ('road_type'));
99         }
100         $sth->finish;
101         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
102         exit;
103
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;
113         $sth->finish;
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;
118         $sth2->finish;
119         if ($total->{'total'} >0) {
120                 $template->param(totalgtzero => 1);
121         }
122
123         $template->param(       
124                                 city_name       =>      ( $data->{'road_type'}),
125                                 );
126
127
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);
136         $sth->finish;
137         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
138         exit;
139                                                                                                         # END $OP eq DELETE_CONFIRMED
140 } else { # DEFAULT
141         $template->param(else => 1);
142         my @loop;
143         my ($count,$results)=StringSearch($searchfield,'web');
144         my $toggle = 0;
145         for (my $i=0; $i < $count; $i++){
146                 my %row = (roadtypeid => $results->[$i]{'roadtypeid'},
147                                 road_type => $results->[$i]{'road_type'},
148                                 toggle => $toggle );    
149                 push @loop, \%row;
150                 if ( $toggle eq 0 )
151                 {
152                         $toggle = 1;
153                 }
154                 else
155                 {
156                         $toggle = 0;
157                 }
158         }
159         $template->param(loop => \@loop);
160
161
162 } #---- END $OP eq DEFAULT
163 output_html_with_http_headers $input, $cookie, $template->output;