From b4158f2d2485c9e57bd7f14362b210732bef9d35 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 4 Aug 2014 12:31:24 -0300 Subject: [PATCH] Bug 12716: Allow the import patrons form have drop-downs and datepickers To reproduce: - Go to Tools > Import patrons - Notice branchcode and categorycode don't have dropdown menus with valid options. - Notice dateofbirth, dateenrolled and dateexpiry don't have date-pickers - Notice each input field is labeled with the column name instead of a proper description. To test: - Apply the patch, go to Tools > Import patrons - Notice branchcode and categorycode have dropdown menus with valid options, and by default the empty value is selected. - Notice that if you go into the dateofbirth, dateenrolled and dateexpiry fields, a nice date picker widget appears. - Notice each field is labeled with the field description, and that the column name is conveniently shown at the right of the input field. Important: test switching the ExtendedPatronAttributes syspref, and verify that if enabled, the patron_attributes field appears, and also the checkbox selector controlling the extended patron attributes import behaviour shows too. Bonus points: Verify that on a different language, the descriptions get translated, and the column names show correctly Regards To+ Signed-off-by: Aleisha Signed-off-by: Katrin Fischer Passes tests and QA script. Works as described, no regressions found. Dates are output in ISO/database format, this is ok. Signed-off-by: Tomas Cohen Arazi --- C4/Templates.pm | 47 +++++++++++++++ .../prog/en/css/staff-global.css | 6 ++ .../prog/en/modules/tools/import_borrowers.tt | 60 ++++++++++++++++--- tools/import_borrowers.pl | 19 +++--- 4 files changed, 116 insertions(+), 16 deletions(-) diff --git a/C4/Templates.pm b/C4/Templates.pm index 16eeec118d..6a9d48b345 100644 --- a/C4/Templates.pm +++ b/C4/Templates.pm @@ -307,4 +307,51 @@ sub getlanguagecookie { return $cookie; } +=head2 GetColumnDefs + + my $columns = GetColumnDefs( $cgi ) + +It is passed a CGI object and returns a hash of hashes containing +the column names and descriptions for each table defined in the +columns.def file corresponding to the CGI object. + +=cut + +sub GetColumnDefs { + + my $query = shift; + + my $columns = {}; + + my $htdocs = C4::Context->config('intrahtdocs'); + my $columns_file = 'columns.def'; + + # Get theme and language to build the path to columns.def + my ($theme, $lang, $availablethemes) = + themelanguage($htdocs, 'about.tt', 'intranet', $query); + # Build columns.def path + my $path = "$htdocs/$theme/$lang/$columns_file"; + my $fh; + if ( ! open ( $fh, q{<}, $path ) ) { + carp "Error opening $path. Check your templates."; + return; + } + # Loop through the columns.def file + while ( my $input = <$fh> ){ + chomp $input; + if ( $input =~ m|(.*)| ) { + my ( $table, $column ) = split( '\.', $1); + my $description = $2; + # Initialize the table array if needed. + @{$columns->{ $table }} = () if ! defined $columns->{ $table }; + # Push field and description + push @{$columns->{ $table }}, + { field => $column, description => $description }; + } + } + close $fh; + + return $columns; +} + 1; diff --git a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css index a4ef390b02..bbd845828f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css +++ b/koha-tmpl/intranet-tmpl/prog/en/css/staff-global.css @@ -1844,6 +1844,12 @@ fieldset.rows+h3 {clear:both;padding-top:.5em;} padding-bottom: 10px; } +.field_hint { + color: grey; + font-style: italic; + padding-left: 1em; +} + .m880 { display:block; text-align:right; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt index 40410f8bc9..a0727b860d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt @@ -1,15 +1,27 @@ +[% USE Koha %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools › Import patrons [% IF ( uploadborrowers ) %]› Results[% END %] [% INCLUDE 'doc-head-close.inc' %] + [% INCLUDE 'header.inc' %] [% INCLUDE 'patron-search.inc' %] +[% INCLUDE 'calendar.inc' %] @@ -112,12 +124,44 @@
Default values
    - [% FOREACH columnkey IN columnkeys %] -
  1. - - -
  2. - [% END %] +[% FOREACH borrower_field IN borrower_fields %] + [% SWITCH borrower_field.field %] + [% CASE 'branchcode' %] +
  3. + + [% borrower_field.field %] +
  4. + [% CASE 'categorycode' %] +
  5. + + [% borrower_field.field %] +
  6. + [% CASE %] +
  7. + + [% borrower_field.field %] +
  8. + [% END %] +[% END %] +[% IF ( Koha.Preference('ExtendedPatronAttributes') == 1 ) %] +
  9. + + + patron_attributes +
  10. +[% END %]
If matching record is already in the borrowers table: @@ -129,7 +173,7 @@
- [% IF ( ExtendedPatronAttributes ) %] + [% IF ( Koha.Preference('ExtendedPatronAttributes') == 1 ) %]
Patron attributes
  1. diff --git a/tools/import_borrowers.pl b/tools/import_borrowers.pl index abbef70f5a..d99db2fd4e 100755 --- a/tools/import_borrowers.pl +++ b/tools/import_borrowers.pl @@ -41,11 +41,13 @@ use C4::Auth; use C4::Output; use C4::Dates qw(format_date_in_iso); use C4::Context; -use C4::Branch qw(GetBranchName); +use C4::Branch qw/GetBranchesLoop GetBranchName/; use C4::Members; use C4::Members::Attributes qw(:all); use C4::Members::AttributeTypes; use C4::Members::Messaging; +use C4::Reports::Guided; +use C4::Templates; use Koha::Borrower::Debarments; use Text::CSV; @@ -60,10 +62,6 @@ my (@errors, @feedback); my $extended = C4::Context->preference('ExtendedPatronAttributes'); my $set_messaging_prefs = C4::Context->preference('EnhancedMessagingPreferences'); my @columnkeys = C4::Members::columns(); -if ($extended) { - push @columnkeys, 'patron_attributes'; -} -my $columnkeystpl = [ map { {'key' => $_} } grep {$_ ne 'borrowernumber' } @columnkeys ]; # ref. to array of hashrefs. my $input = CGI->new(); our $csv = Text::CSV->new({binary => 1}); # binary needed for non-ASCII Unicode @@ -78,7 +76,14 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ debug => 1, }); -$template->param(columnkeys => $columnkeystpl); +# get the branches and pass them to the template +my $branches = GetBranchesLoop(); +$template->param( branches => $branches ) if ( $branches ); +# get the patron categories and pass them to the template +my $categories = GetBorrowercategoryList(); +$template->param( categories => $categories ) if ( $categories ); +my $columns = C4::Templates::GetColumnDefs( $input ); +$template->param( borrower_fields => $columns->{borrowers} ); if ($input->param('sample')) { print $input->header( @@ -98,8 +103,6 @@ my $overwrite_cardnumber = $input->param('overwrite_cardnumber'); $template->param( SCRIPT_NAME => $ENV{'SCRIPT_NAME'} ); -($extended) and $template->param(ExtendedPatronAttributes => 1); - if ( $uploadborrowers && length($uploadborrowers) > 0 ) { push @feedback, {feedback=>1, name=>'filename', value=>$uploadborrowers, filename=>$uploadborrowers}; my $handle = $input->upload('uploadborrowers'); -- 2.39.5