From 902d19dfa93d5709848afb26ab474b3353efcd4a Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 22 Jul 2011 14:58:43 -0400 Subject: [PATCH] Fix for Bug 5433 - Separate state field for cities - Updates cities management (admin/cities.pl) to record a separate state and country field. - Updates the cities table with these new columns - Modifies the patron entry form to populate city, state, zip and country when the user chooses a prepopulated city entry Signed-off-by: Paul Poulain Signed-off-by: Chris Cormack --- C4/Members.pm | 8 +++-- admin/cities.pl | 18 ++++++----- installer/data/mysql/updatedatabase.pl | 8 +++++ .../prog/en/modules/admin/cities.tt | 30 +++++++++++++++---- .../prog/en/modules/members/memberentrygen.tt | 10 ++++--- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index 2ce30308a6..ce694e590e 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1304,10 +1304,10 @@ sub getzipnamecity { my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( - "select city_name,city_zipcode from cities where cityid=? "); + "select city_name,city_state,city_zipcode,city_country from cities where cityid=? "); $sth->execute($cityid); my @data = $sth->fetchrow; - return $data[0], $data[1]; + return $data[0], $data[1], $data[2], $data[3]; } @@ -1627,13 +1627,15 @@ sub GetCities { my $dbh = C4::Context->dbh; my $city_arr = $dbh->selectall_arrayref( - q|SELECT cityid,city_zipcode,city_name FROM cities ORDER BY city_name|, + q|SELECT cityid,city_zipcode,city_name,city_state,city_country FROM cities ORDER BY city_name|, { Slice => {} }); if ( @{$city_arr} ) { unshift @{$city_arr}, { city_zipcode => q{}, city_name => q{}, cityid => q{}, + city_state => q{}, + city_country => q{}, }; } diff --git a/admin/cities.pl b/admin/cities.pl index 58e33aed17..0303a484cf 100755 --- a/admin/cities.pl +++ b/admin/cities.pl @@ -58,14 +58,16 @@ if ($op eq 'add_form') { #---- if primkey exists, it's a modify action, so read values to modify... my $data; if ($cityid) { - my $sth=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?"); + my $sth=$dbh->prepare("select cityid,city_name,city_state,city_zipcode,city_country from cities where cityid=?"); $sth->execute($cityid); $data=$sth->fetchrow_hashref; } $template->param( city_name => $data->{'city_name'}, - city_zipcode => $data->{'city_zipcode'}); + city_state => $data->{'city_state'}, + city_zipcode => $data->{'city_zipcode'}, + city_country => $data->{'city_country'}); # END $OP eq ADD_FORM ################## ADD_VALIDATE ################################## # called by add_form, used to insert/modify data in DB @@ -73,12 +75,12 @@ if ($op eq 'add_form') { my $sth; if ($input->param('cityid') ){ - $sth=$dbh->prepare("UPDATE cities SET city_name=?,city_zipcode=? WHERE cityid=?"); - $sth->execute($input->param('city_name'),$input->param('city_zipcode'),$input->param('cityid')); + $sth=$dbh->prepare("UPDATE cities SET city_name=?,city_state=?,city_zipcode=?,city_country=? WHERE cityid=?"); + $sth->execute($input->param('city_name'),$input->param('city_state'),$input->param('city_zipcode'),$input->param('city_country'),$input->param('cityid')); } else{ - $sth=$dbh->prepare("INSERT INTO cities (city_name,city_zipcode) values (?,?)"); - $sth->execute($input->param('city_name'),$input->param('city_zipcode')); + $sth=$dbh->prepare("INSERT INTO cities (city_name,city_state,city_zipcode,city_country) values (?,?,?,?)"); + $sth->execute($input->param('city_name'),$input->param('city_state'),$input->param('city_zipcode'),$input->param('city_country')); } print $input->redirect($script_name); exit; @@ -86,12 +88,14 @@ if ($op eq 'add_form') { # called by default form, used to confirm deletion of data in DB } elsif ($op eq 'delete_confirm') { $template->param(delete_confirm => 1); - my $sth=$dbh->prepare("select cityid,city_name,city_zipcode from cities where cityid=?"); + my $sth=$dbh->prepare("select cityid,city_name,city_state,city_zipcode,city_country from cities where cityid=?"); $sth->execute($cityid); my $data=$sth->fetchrow_hashref; $template->param( city_name => $data->{'city_name'}, + city_state => $data->{'city_state'}, city_zipcode => $data->{'city_zipcode'}, + city_country => $data->{'city_country'}, ); ################## DELETE_CONFIRMED ################################## # called by delete_confirm, used to effectively confirm deletion of data in DB diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 2076edfabb..fb2bfd1cae 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -4391,6 +4391,14 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.05.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE `cities` ADD `city_state` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `city_name`;"); + $dbh->do("ALTER TABLE `cities` ADD `city_country` VARCHAR( 100 ) NULL DEFAULT NULL AFTER `city_zipcode`;"); + print "Add state and country to cities table corresponding to new columns in borrowers\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 DropAllForeignKeys($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt index 2e9bdd2fdf..f286b7c9ec 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cities.tt @@ -4,9 +4,10 @@