Bug 7372: Move road types from the roadtype table to the ROADTYPE AV

Currently road types are stored in a specific table in DB. Moreover, an
admin page is present in order to manage them.
This patch proposes to remove this table and this page in favour of a
new authorised value category 'ROADTYPE'.

This patch:
- adds a new AV category 'ROADTYPE' (created from the roadtype table
  content).
- remove the roadtype table.
- remove the .pl and .tt file admin/roadtype
- remove the 2 routines C4::Members::GetRoadTypes and
  C4::Members::GetRoadTypeDetails

Test plan:
1/ Execute the updatedatabase entry and verify existing roadtypes are
now stored in the AV 'ROADTYPE'.
2/ Verify you can add/update a streettype for patrons.
3/ Verify on following pages the streettype is displayed in patron
information (top left):
  circ/circulation.pl
  members/memberentry.pl
  members/moremember.pl
  members/routing-lists.pl

Signed-off-by: Sophie Meynieux <sophie.meynieux@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
Jonathan Druart 2013-10-23 14:27:45 +02:00 committed by Galen Charlton
parent 40ba1763af
commit a691ebc3f1
12 changed files with 50 additions and 358 deletions

View file

@ -71,8 +71,6 @@ BEGIN {
&GetAge
&GetCities
&GetRoadTypes
&GetRoadTypeDetails
&GetSortDetails
&GetTitles
@ -1860,48 +1858,6 @@ EOF
return 0;
}
=head2 GetRoadTypes (OUEST-PROVENCE)
($idroadtypearrayref, $roadttype_hashref) = &GetRoadTypes();
Looks up the different road type . Returns two
elements: a reference-to-array, which lists the id_roadtype
codes, and a reference-to-hash, which maps the road type of the road .
=cut
sub GetRoadTypes {
my $dbh = C4::Context->dbh;
my $query = qq|
SELECT roadtypeid,road_type
FROM roadtype
ORDER BY road_type|;
my $sth = $dbh->prepare($query);
$sth->execute();
my %roadtype;
my @id;
# insert empty value to create a empty choice in cgi popup
while ( my $data = $sth->fetchrow_hashref ) {
push @id, $data->{'roadtypeid'};
$roadtype{ $data->{'roadtypeid'} } = $data->{'road_type'};
}
#test to know if the table contain some records if no the function return nothing
my $id = @id;
if ( $id eq 0 ) {
return ();
}
else {
unshift( @id, "" );
return ( \@id, \%roadtype );
}
}
=head2 GetTitles (OUEST-PROVENCE)
($borrowertitle)= &GetTitles();
@ -2001,29 +1957,6 @@ sub GetHideLostItemsPreference {
return $hidelostitems;
}
=head2 GetRoadTypeDetails (OUEST-PROVENCE)
($roadtype) = &GetRoadTypeDetails($roadtypeid);
Returns the description of roadtype
C<&$roadtype>return description of road type
C<&$roadtypeid>this is the value of roadtype s
=cut
sub GetRoadTypeDetails {
my ($roadtypeid) = @_;
my $dbh = C4::Context->dbh;
my $query = qq|
SELECT road_type
FROM roadtype
WHERE roadtypeid=?|;
my $sth = $dbh->prepare($query);
$sth->execute($roadtypeid);
my $roadtype = $sth->fetchrow;
return ($roadtype);
}
=head2 GetBorrowersToExpunge
$borrowers = &GetBorrowersToExpunge(

View file

@ -1,129 +0,0 @@
#! /usr/bin/perl
# Copyright 2006 SAN OUEST-PROVENCE et Paul POULAIN
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
use CGI;
use C4::Context;
use C4::Output;
use C4::Auth;
sub StringSearch {
my $sth = C4::Context->dbh->prepare("Select * from roadtype where (road_type like ?) ORDER BY road_type");
$sth->execute((shift || '') . '%');
return $sth->fetchall_arrayref({});
}
my $input = new CGI;
my $searchfield=$input->param('road_type');
my $script_name="/cgi-bin/koha/admin/roadtype.pl";
my $roadtypeid=$input->param('roadtypeid');
my $op = $input->param('op') || '';
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "admin/roadtype.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 'parameters_remaining_permissions'},
debug => 1,
});
$template->param( script_name => $script_name,
roadtypeid => $roadtypeid ,
searchfield => $searchfield);
################## ADD_FORM ##################################
# called by default. Used to create form to add or modify a record
if ($op eq 'add_form') {
$template->param(add_form => 1);
#---- if primkey exists, it's a modify action, so read values to modify...
my $data;
if ($roadtypeid) {
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
$sth->execute($roadtypeid);
$data=$sth->fetchrow_hashref;
$sth->finish;
}
$template->param(
road_type => $data->{'road_type'},
);
##############ICI#####################
# END $OP eq ADD_FORM
################## ADD_VALIDATE #################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
my $sth;
if ($input->param('roadtypeid') ){
$sth=$dbh->prepare("UPDATE roadtype SET road_type=? WHERE roadtypeid=?");
$sth->execute($input->param('road_type'),$input->param('roadtypeid'));
}
else{
$sth=$dbh->prepare("INSERT INTO roadtype (road_type) VALUES (?)");
$sth->execute($input->param('road_type'));
}
$sth->finish;
print $input->redirect("/cgi-bin/koha/admin/roadtype.pl");
exit;
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB
} elsif ($op eq 'delete_confirm') {
$template->param(delete_confirm => 1);
my $dbh = C4::Context->dbh;
my $sth2=$dbh->prepare("select roadtypeid,road_type from roadtype where roadtypeid=?");
$sth2->execute($roadtypeid);
my $data=$sth2->fetchrow_hashref;
$sth2->finish;
$template->param(
road_type => ( $data->{'road_type'}),
);
# END $OP eq DELETE_CONFIRM
################## DELETE_CONFIRMED ##################################
# called by delete_confirm, used to effectively confirm deletion of data in DB
} elsif ($op eq 'delete_confirmed') {
my $dbh = C4::Context->dbh;
my $categorycode=uc($input->param('roadtypeid'));
my $sth=$dbh->prepare("delete from roadtype where roadtypeid=?");
$sth->execute($roadtypeid);
$sth->finish;
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=roadtype.pl\"></html>";
exit;
# END $OP eq DELETE_CONFIRMED
} else { # DEFAULT
$template->param(else => 1);
$template->param(loop => StringSearch($searchfield));
} #---- END $OP eq DEFAULT
output_html_with_http_headers $input, $cookie, $template->output;

View file

@ -686,7 +686,7 @@ if($bor_messages_loop){ $template->param(flagged => 1 ); }
# Computes full borrower address
my @fulladdress;
push @fulladdress, $borrower->{'streetnumber'} if ( $borrower->{'streetnumber'} );
push @fulladdress, &GetRoadTypeDetails( $borrower->{'streettype'} ) if ( $borrower->{'streettype'} );
push @fulladdress, C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{'streettype'} ) if ( $borrower->{'streettype'} );
push @fulladdress, $borrower->{'address'} if ( $borrower->{'address'} );
my $fast_cataloging = 0;

View file

@ -7974,6 +7974,37 @@ if(CheckVersion($DBversion)) {
SetVersion($DBversion);
}
$DBversion = "3.13.00.XXX";
if ( CheckVersion($DBversion) ) {
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
my $av_added = $dbh->do(q|
INSERT INTO authorised_values(category, authorised_value, lib, lib_opac)
SELECT 'ROADTYPE', roadtypeid, road_type, road_type
FROM roadtype;
|);
my $rt_deleted = $dbh->do(q|
DELETE FROM roadtype
|);
if ( $av_added == $rt_deleted or $rt_deleted eq "0E0" ) {
$dbh->do(q|
DROP TABLE roadtype;
|);
$dbh->commit;
print "Upgrade to $DBversion done (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values)\n";
SetVersion($DBversion);
} else {
print "Upgrade to $DBversion failed (Bug 7372: Move road types from the roadtype table to the ROADTYPE authorised values.\nTransaction aborted because $@\n)";
$dbh->rollback;
}
$dbh->{AutoCommit} = 1;
$dbh->{RaiseError} = 0;
}
=head1 FUNCTIONS
=head2 TableExists($table)

View file

@ -33,7 +33,6 @@
<li><a href="/cgi-bin/koha/admin/transport-cost-matrix.pl">Transport cost matrix</a></li>
<li><a href="/cgi-bin/koha/admin/item_circulation_alerts.pl">Item circulation alerts</a></li>
<li><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></li>
<li><a href="/cgi-bin/koha/admin/roadtype.pl">Road types</a></li>
</ul>
<h5>Catalog</h5>

View file

@ -56,9 +56,6 @@
<dd>Define rules for check-in and checkout notifications for combinations of libraries, patron categories, and item types</dd>
<dt><a href="/cgi-bin/koha/admin/cities.pl">Cities and towns</a></dt>
<dd>Define cities and towns that your patrons live in.</dd>
<dt><a href="/cgi-bin/koha/admin/roadtype.pl" >Road types</a>
</dt>
<dd>Define road types (street, avenue, way, etc.). Road types display as authorized values when adding/editing patrons and can be used in geographic statistics.</dd>
</dl>
</div>
<div class="yui-u">

View file

@ -1,134 +0,0 @@
[% INCLUDE 'doc-head-open.inc' %]
<title>Koha &rsaquo; Administration &rsaquo; [% IF ( add_form ) %]Road types &rsaquo; [% IF ( roadtypeid ) %] Modify road type[% ELSE %] New road type[% END %][% ELSE %][% IF ( delete_confirm ) %]Road types &rsaquo; Confirm deletion of road type[% ELSE %] Road type[% END %][% END %]</title>
[% INCLUDE 'doc-head-close.inc' %]
<script type="text/javascript">
//<![CDATA[
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNotNull(f,noalert) {
if (f.value.length == 0) {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNum(v,maybenull) {
var n = new Number(v.value);
if (isNaN(n)) {
return false;
}
if (maybenull == 0 && v.value =='') {
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Check(f) {
var ok=1;
var _alertString="";
var alertString2;
if (f.road_type.value.length == 0 ) {
_alertString += "\n- " + _("Road type");
alert(_alertString);
}
else{
document.Aform.submit();
}
}
//]]>
</script>
</head>
<body id="admin_roadtype" class="admin">
[% INCLUDE 'header.inc' %]
[% INCLUDE 'roadtype-admin-search.inc' %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> &rsaquo; [% IF ( add_form ) %]<a href="/cgi-bin/koha/admin/roadtype.pl">Road types</a> &rsaquo; [% IF ( roadtypeid ) %] Modify road type[% ELSE %] New road type[% END %][% ELSE %][% IF ( delete_confirm ) %]<a href="/cgi-bin/koha/admin/roadtype.pl">Road types</a> &rsaquo; Confirm deletion of road type[% ELSE %] Road type[% END %][% END %]</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
[% IF ( add_form ) %]
[% IF ( roadtypeid ) %]
<h1>Modify road type</h1>
[% ELSE %]
<h1>New road type</h1>
[% END %]
<form action="[% script_name %]" name="Aform" method="post">
<input type="hidden" name="op" value="add_validate" />
<input type="hidden" name="checked" value="0" />
<input type="hidden" name="roadtypeid" value="[% roadtypeid %]" />
<fieldset class="rows"><ol>
[% IF ( roadtypeid ) %]
<li>
<span class="label">Road type: </span>[% roadtypeid %]
</li>
[% END %]
<li>
<label for="road_type">Road type: </label>
<input type="text" name="road_type" id="road_type" size="80" maxlength="100" value="[% road_type |html %]" />
</li></ol></fieldset>
<fieldset class="action">
<input class="button" type="button" onclick="Check(this.form)" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/admin/roadtype.pl">Cancel</a>
</fieldset>
</form>
[% END %]
[% IF ( delete_confirm ) %]
<div class="dialog alert"><h3>Delete road type "[% road_type %]?"</h3>
<table> <tr>
<th>Road type id: </th>
<td>[% roadtypeid %]</td>
</tr>
<tr> <th>Road type: </th>
<td>[% road_type %]
</td>
</tr></table><form action="[% script_name %]" method="post">
<input type="hidden" name="op" value="delete_confirmed" />
<input type="hidden" name="roadtypeid" value="[% roadtypeid %]" /><input type="submit" class="approve" value="Yes, delete" /></form> <form action="[% script_name %]" method="post">
<input type="submit" class="deny" value="No, do not delete" /></form></div>
[% END %]
[% IF ( else ) %]
<div id="toolbar" class="btn-toolbar">
<a class="btn btn-small" id="addroad" href="/cgi-bin/koha/admin/roadtype.pl?op=add_form"><i class="icon-plus"></i> New road type</a>
</div>
<h2>Road type</h2>
[% IF ( searchfield ) %]
Search on [% searchfield %]
[% END %]
[% IF ( loop ) %] <table>
<tr>
<th>Road type</th>
<th colspan="2">&nbsp;</th>
</tr>
[% FOREACH loo IN loop %]
[% UNLESS ( loop.odd ) %]
<tr class="highlight">
[% ELSE %]
<tr>
[% END %]
<td>[% loo.road_type %]</td>
<td><a href="[% loo.script_name %]?op=add_form&amp;roadtypeid=[% loo.roadtypeid %]">Edit</a></td>
<td><a href="[% loo.script_name %]?op=delete_confirm&amp;roadtypeid=[% loo.roadtypeid %]">Delete</a></td>
</tr>
[% END %]
</table>[% END %]
[% END %]
</div>
</div>
<div class="yui-b">
[% INCLUDE 'admin-menu.inc' %]
</div>
</div>
[% INCLUDE 'intranet-bottom.inc' %]

View file

@ -218,7 +218,6 @@
<input type="hidden" name="BorrowerMandatoryField" value="[% BorrowerMandatoryField %]" />
<input type="hidden" name="category_type" value="[% category_type %]" />
<input type="hidden" name="updtype" value="[% updtype %]" />
<input type="hidden" name="select_roadtype" value="[% select_roadtype %]" />
<input type="hidden" name="destination" value="[% destination %]" />
<input type="hidden" name="check_member" value="[% check_member %]" />
<input type="hidden" name="borrowernumber" value="[% IF ( opduplicate ) %][% ELSE %][% borrowernumber %][% END %]" />
@ -456,7 +455,7 @@
</li>
[% END %]
[% UNLESS nostreettype %]
[% IF ( road_cgipopup ) %]
[% IF roadtypes %]
<li>
[% IF ( mandatorystreettype ) %]
<label for="streettype" class="required">
@ -464,7 +463,16 @@
<label for="streettype">
[% END %]
Street type: </label>
[% roadpopup %]
<select name="streettype">
<option value=""></option>
[% FOR roadtype IN roadtypes %]
[% IF roadtype.selected %]
<option value="[% roadtype.authorised_value %]" selected="selected">[% roadtype.lib %]</option>
[% ELSE %]
<option value="[% roadtype.authorised_value %]">[% roadtype.lib %]</option>
[% END %]
[% END %]
</select>
[% IF ( mandatorystreettype ) %]<span class="required">Required</span>[% END %]
</li>
[% END %]

View file

@ -212,9 +212,7 @@ function validate1(date) {
[% UNLESS ( I ) %][% IF ( othernames ) %]&ldquo;[% othernames %]&rdquo;[% END %]
<p class="address">[% streetnumber %]
[% IF ( roaddetails ) %]
[% roaddetails %]
[% END %]
[% IF roadtype %][% roadtype %][% END %]
[% address %]<br />
[% IF ( address2 ) %][% address2 %]<br />[% END %]
[% IF ( city ) %][% city %][% END %]

View file

@ -204,7 +204,6 @@ if ( $op eq 'insert' || $op eq 'modify' || $op eq 'save' || $op eq 'duplicate' )
qr/^nodouble$/,
qr/^op$/,
qr/^save$/,
qr/^select_roadtype$/,
qr/^updtype$/,
qr/^SMSnumber$/,
qr/^setting_extended_patron_attributes$/,
@ -549,17 +548,8 @@ if (@{$city_arrayref} ) {
}
}
my $default_roadtype;
$default_roadtype=$data{'streettype'} ;
my($roadtypeid,$road_type)=GetRoadTypes();
$template->param( road_cgipopup => 1) if ($roadtypeid );
my $roadpopup = CGI::popup_menu(-name=>'streettype',
-id => 'streettype',
-values=>$roadtypeid,
-labels=>$road_type,
-override => 1,
-default=>$default_roadtype
);
my $roadtypes = C4::Koha::GetAuthorisedValues( 'ROADTYPE', $data{streettype} );
$template->param( roadtypes => $roadtypes);
my $default_borrowertitle = '';
unless ( $op eq 'duplicate' ) { $default_borrowertitle=$data{'title'} }
@ -731,7 +721,6 @@ $template->param(
ethcatpopup => $ethcatpopup,
relshiploop => \@relshipdata,
city_loop => $city_arrayref,
roadpopup => $roadpopup,
borrotitlepopup => $borrotitlepopup,
guarantorinfo => $guarantorinfo,
flagloop => \@flagdata,

View file

@ -246,7 +246,7 @@ my $relissue = [];
if ( @borrowernumbers ) {
$relissue = GetPendingIssues(@borrowernumbers);
}
my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $data->{streettype} );
my $today = DateTime->now( time_zone => C4::Context->tz);
$today->truncate(to => 'day');
my @borrowers_with_issues;
@ -412,7 +412,7 @@ $template->param(
detailview => 1,
AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
CANDELETEUSER => $candeleteuser,
roaddetails => $roaddetails,
roadtype => $roadtype,
borrowernumber => $borrowernumber,
othernames => $data->{'othernames'},
categoryname => $data->{'description'},

View file

@ -101,8 +101,8 @@ if ($borrowernumber) {
# Computes full borrower address
my (undef, $roadttype_hashref) = &GetRoadTypes();
my $address = $borrower->{'streetnumber'}.' '.$roadttype_hashref->{$borrower->{'streettype'}}.' '.$borrower->{'address'};
my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} );
my $address = $borrower->{'streetnumber'} . " $roadtype " . $borrower->{'address'};
$template->param(