[Koha-patches] [PATCH] Bug 7422: name control when creating a new vendor
Adrien Saurat
adrien.saurat at biblibre.com
Tue Jan 10 15:54:20 CET 2012
Ensures that :
- name is not a space only string
- name is unique
- name does not contain quotation marks
---
acqui/supplier.pl | 13 ++++++
.../prog/en/modules/acqui/supplier.tt | 41 +++++++++++++++++--
2 files changed, 49 insertions(+), 5 deletions(-)
diff --git a/acqui/supplier.pl b/acqui/supplier.pl
index 3faa560..a71f0ff 100755
--- a/acqui/supplier.pl
+++ b/acqui/supplier.pl
@@ -121,6 +121,18 @@ if ( $op eq 'display' ) {
print $query->redirect('/cgi-bin/koha/acqui/acqui-home.pl');
exit;
} else {
+ my $dbh = C4::Context->dbh;
+ # get the list of existing vendors to ensure (client-side with JS)
+ # that we won't create a duplicate
+ my $sth = $dbh->prepare( "SELECT DISTINCT name FROM aqbooksellers");
+ $sth->execute();
+ my $name;
+ my $loop_names;
+ while ($name = $sth->fetchrow_array) { # retrieve one row
+ $name =~ s/"/'/g;
+ push @{$loop_names}, $name;
+ }
+
my @currencies = GetCurrencies();
my $loop_currency;
my $active_currency = GetCurrency();
@@ -174,6 +186,7 @@ if ( $op eq 'display' ) {
loop_currency => $loop_currency,
GST => $tax_rate,
enter => 1,
+ loop_names => $loop_names,
default_gst_rate => $default_gst_rate,
);
}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
index f30d839..6059b4c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt
@@ -9,12 +9,43 @@ function confirm_deletion() {
}
}
function check(f) {
-if (f.company.value == "") {
- alert(_("You must specify a name for this vendor."));
- return false;
-}
- f.submit();
+ // invalid characters
+ var patt=/"/g;
+
+ // array containing names of existing vendors (to avoid duplicates)
+ var nameloop = new Array();
+ [% FOREACH existingname IN loop_names %]nameloop[[% loop.count %]] = "[% existingname %]";
+ [% END %]
+
+ var companyName = f.company.value;
+ companyName = companyName.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
+
+ if (companyName == "") {
+ alert(_("You must specify a name for this vendor."));
+ return false;
+ }
+ else if (patt.test(companyName) ) {
+ alert(_("The vendor name contains invalid characters."));
+ return false;
+ }
+ else {
+ var i;
+ var duplicateFound = 0;
+ for (i=1;i<=nameloop.length-1;i++) {
+ if (companyName.toLowerCase() == nameloop[i].toString().toLowerCase()) {
+ duplicateFound = 1;
+ }
+ }
+ if (duplicateFound) {
+ alert(_("A vendor with this name already exists."));
+ return false;
+ }
+ else {
+ f.submit();
+ }
+ }
}
+
//]]>
</script>
</head>
--
1.7.4.1
More information about the Koha-patches
mailing list