Bug 14424: Add on site checkouts help for 3.20
[koha.git] / misc / export_borrowers.pl
index 7d3ce47..6f0985a 100755 (executable)
@@ -4,18 +4,18 @@
 #
 # 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 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 3 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.
+# 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.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 # Script to export borrowers
 
@@ -26,7 +26,7 @@ use Getopt::Long qw(:config no_ignore_case);
 use C4::Context;
 use C4::Members;
 
-use encoding 'utf8';
+binmode STDOUT, ":encoding(UTF-8)";
 
 sub print_usage {
     ( my $basename = $0 ) =~ s|.*/||;
@@ -47,13 +47,15 @@ $0 -h
     -s, --separator=CHAR    This character will be used to separate fields.
                             Some characters like | or ; will need to be escaped
                             in the parameter setting, like -s=\\| or -s=\\;
-                            If no separator is specifield, a comma will be used.
+                            If no separator is specified, the delimiter pref
+                            will be used (or a comma, if the pref is empty)
     -H, --show-header       Print field names on first row
     -w, --where=CONDITION   Condition to filter borrowers to export
                             (SQL where clause).
-                            CONDITION must be enclosed by double quotes and
-                            if needed, where value by single quotes.
-                            example : --where "surname='De Lattre'"
+                            CONDITION must be enclosed by double quotes
+                            You can use single quotes around a field value
+                            within the condition like:
+                                --where "surname='De Lattre'"
     -h, --help              Show this help
 
 USAGE
@@ -87,6 +89,11 @@ $query .= " ORDER BY borrowernumber";
 my $sth   = $dbh->prepare($query);
 $sth->execute;
 
+unless ( $separator ) {
+    $separator = C4::Context->preference('delimiter') || ',';
+    $separator = "\t" if ($separator eq 'tabulation');
+}
+
 my $csv = Text::CSV->new( { sep_char => $separator, binary => 1 } );
 
 # If the user did not specify any field to export, we assume he wants them all