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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
28 my $sth = C4
::Context
->dbh->prepare("SELECT * FROM cities WHERE (city_name LIKE ?)");
29 $sth->execute("%" . (shift || '') . "%");
30 return $sth->fetchall_arrayref({});
34 my $script_name = "/cgi-bin/koha/admin/cities.pl";
35 my $searchfield = $input->param('city_name');
36 my $cityid = $input->param('cityid');
37 my $op = $input->param('op') || '';
39 my ($template, $loggedinuser, $cookie)
40 = get_template_and_user
({template_name
=> "admin/cities.tt",
44 flagsrequired
=> {parameters
=> 'parameters_remaining_permissions'},
48 $template->param( script_name
=> $script_name,
50 searchfield
=> $searchfield);
52 my $dbh = C4
::Context
->dbh;
53 ################## ADD_FORM ##################################
54 # called by default. Used to create form to add or modify a record
55 if ($op eq 'add_form') {
56 $template->param(add_form
=> 1);
58 #---- if primkey exists, it's a modify action, so read values to modify...
61 my $sth=$dbh->prepare("select cityid,city_name,city_state,city_zipcode,city_country from cities where cityid=?");
62 $sth->execute($cityid);
63 $data=$sth->fetchrow_hashref;
67 city_name
=> $data->{'city_name'},
68 city_state
=> $data->{'city_state'},
69 city_zipcode
=> $data->{'city_zipcode'},
70 city_country
=> $data->{'city_country'});
72 ################## ADD_VALIDATE ##################################
73 # called by add_form, used to insert/modify data in DB
74 } elsif ($op eq 'add_validate') {
77 if ($input->param('cityid') ){
78 $sth=$dbh->prepare("UPDATE cities SET city_name=?,city_state=?,city_zipcode=?,city_country=? WHERE cityid=?");
79 $sth->execute($input->param('city_name'),$input->param('city_state'),$input->param('city_zipcode'),$input->param('city_country'),$input->param('cityid'));
82 $sth=$dbh->prepare("INSERT INTO cities (city_name,city_state,city_zipcode,city_country) values (?,?,?,?)");
83 $sth->execute($input->param('city_name'),$input->param('city_state'),$input->param('city_zipcode'),$input->param('city_country'));
85 print $input->redirect($script_name);
87 ################## DELETE_CONFIRM ##################################
88 # called by default form, used to confirm deletion of data in DB
89 } elsif ($op eq 'delete_confirm') {
90 $template->param(delete_confirm
=> 1);
91 my $sth=$dbh->prepare("select cityid,city_name,city_state,city_zipcode,city_country from cities where cityid=?");
92 $sth->execute($cityid);
93 my $data=$sth->fetchrow_hashref;
95 city_name
=> $data->{'city_name'},
96 city_state
=> $data->{'city_state'},
97 city_zipcode
=> $data->{'city_zipcode'},
98 city_country
=> $data->{'city_country'},
100 ################## DELETE_CONFIRMED ##################################
101 # called by delete_confirm, used to effectively confirm deletion of data in DB
102 } elsif ($op eq 'delete_confirmed') {
103 my $sth=$dbh->prepare("delete from cities where cityid=?");
104 $sth->execute($cityid);
105 print $input->redirect($script_name);
106 exit; # FIXME: what's the point of redirecting to this same page?
107 # END $OP eq DELETE_CONFIRMED
109 $template->param(else => 1);
110 $template->param(loop => StringSearch
($searchfield));
112 } #---- END $OP eq DEFAULT
113 output_html_with_http_headers
$input, $cookie, $template->output;