3 # Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN
4 # Copyright 2015 Koha Development Team
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 my $city_name_filter = $input->param('city_name_filter') // q
||;
31 my $cityid = $input->param('cityid');
32 my $op = $input->param('op') || 'list';
35 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
36 { template_name
=> "admin/cities.tt",
40 flagsrequired
=> { parameters
=> 'manage_cities' },
45 my $dbh = C4
::Context
->dbh;
46 if ( $op eq 'add_form' ) {
49 $city = Koha
::Cities
->find($cityid);
52 $template->param( city
=> $city, );
53 } elsif ( $op eq 'add_validate' ) {
54 my $city_name = $input->param('city_name');
55 my $city_state = $input->param('city_state');
56 my $city_zipcode = $input->param('city_zipcode');
57 my $city_country = $input->param('city_country');
60 my $city = Koha
::Cities
->find($cityid);
61 $city->city_name($city_name);
62 $city->city_state($city_state);
63 $city->city_zipcode($city_zipcode);
64 $city->city_country($city_country);
65 eval { $city->store; };
67 push @messages, { type
=> 'error', code
=> 'error_on_update' };
69 push @messages, { type
=> 'message', code
=> 'success_on_update' };
72 my $city = Koha
::City
->new(
73 { city_name
=> $city_name,
74 city_state
=> $city_state,
75 city_zipcode
=> $city_zipcode,
76 city_country
=> $city_country,
79 eval { $city->store; };
81 push @messages, { type
=> 'error', code
=> 'error_on_insert' };
83 push @messages, { type
=> 'message', code
=> 'success_on_insert' };
88 } elsif ( $op eq 'delete_confirm' ) {
89 my $city = Koha
::Cities
->find($cityid);
90 $template->param( city
=> $city, );
91 } elsif ( $op eq 'delete_confirmed' ) {
92 my $city = Koha
::Cities
->find($cityid);
93 my $deleted = eval { $city->delete; };
95 if ( $@
or not $deleted ) {
96 push @messages, { type
=> 'error', code
=> 'error_on_delete' };
98 push @messages, { type
=> 'message', code
=> 'success_on_delete' };
103 if ( $op eq 'list' ) {
104 $template->param( cities_count
=> Koha
::Cities
->search->count );
109 city_name_filter
=> $city_name_filter,
110 messages
=> \
@messages,
114 output_html_with_http_headers
$input, $cookie, $template->output;