Add and change preferences, change tab names in sysprefs editor
[koha.git] / admin / cities.pl
blob1e7e87759404bbba49f186409314f17d21c59c49
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;
22 use CGI;
23 use C4::Context;
24 use C4::Auth;
25 use C4::Output;
27 sub StringSearch {
28 my $sth = C4::Context->dbh->prepare("SELECT * FROM cities WHERE (city_name LIKE ?)");
29 $sth->execute("%" . (shift || '') . "%");
30 return $sth->fetchall_arrayref({});
33 my $input = new CGI;
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.tmpl",
41 query => $input,
42 type => "intranet",
43 authnotrequired => 0,
44 flagsrequired => {parameters => 1},
45 debug => 1,
46 });
48 $template->param( script_name => $script_name,
49 cityid => $cityid ,
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...
59 my $data;
60 if ($cityid) {
61 my $sth=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?");
62 $sth->execute($cityid);
63 $data=$sth->fetchrow_hashref;
66 $template->param(
67 city_name => $data->{'city_name'},
68 city_zipcode => $data->{'city_zipcode'});
69 # END $OP eq ADD_FORM
70 ################## ADD_VALIDATE ##################################
71 # called by add_form, used to insert/modify data in DB
72 } elsif ($op eq 'add_validate') {
73 my $sth;
75 if ($input->param('cityid') ){
76 $sth=$dbh->prepare("UPDATE cities SET city_name=?,city_zipcode=? WHERE cityid=?");
77 $sth->execute($input->param('city_name'),$input->param('city_zipcode'),$input->param('cityid'));
79 else{
80 $sth=$dbh->prepare("INSERT INTO cities (city_name,city_zipcode) values (?,?)");
81 $sth->execute($input->param('city_name'),$input->param('city_zipcode'));
83 print $input->redirect($script_name);
84 exit;
85 ################## DELETE_CONFIRM ##################################
86 # called by default form, used to confirm deletion of data in DB
87 } elsif ($op eq 'delete_confirm') {
88 $template->param(delete_confirm => 1);
89 my $sth=$dbh->prepare("select count(*) as total from borrowers,cities where borrowers.city=cities.city_name and cityid=?");
90 # FIXME: this check used to pretend there was a FK "select_city" in borrowers.
91 $sth->execute($cityid);
92 my $total = $sth->fetchrow_hashref;
93 my $sth2=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?");
94 $sth2->execute($cityid);
95 my $data=$sth2->fetchrow_hashref;
96 $template->param(
97 total => $total->{'total'},
98 city_name => $data->{'city_name'},
99 city_zipcode => $data->{'city_zipcode'},
101 ################## DELETE_CONFIRMED ##################################
102 # called by delete_confirm, used to effectively confirm deletion of data in DB
103 } elsif ($op eq 'delete_confirmed') {
104 my $sth=$dbh->prepare("delete from cities where cityid=?");
105 $sth->execute($cityid);
106 print $input->redirect($script_name);
107 exit; # FIXME: what's the point of redirecting to this same page?
108 # END $OP eq DELETE_CONFIRMED
109 } else { # DEFAULT
110 $template->param(else => 1);
111 $template->param(loop => StringSearch($searchfield));
113 } #---- END $OP eq DEFAULT
114 output_html_with_http_headers $input, $cookie, $template->output;