View | Details | Raw Unified | Return to bug 29695
Collapse All | Expand All

(-)a/C4/Templates.pm (-47 lines)
Lines 348-398 sub getlanguagecookie { Link Here
348
    return $cookie;
348
    return $cookie;
349
}
349
}
350
350
351
=head2 GetColumnDefs
352
353
    my $columns = GetColumnDefs( $cgi )
354
355
It is passed a CGI object and returns a hash of hashes containing
356
the column names and descriptions for each table defined in the
357
columns.def file corresponding to the CGI object.
358
359
=cut
360
361
sub GetColumnDefs {
362
363
    my $query = shift;
364
365
    my $columns = {};
366
367
    my $htdocs = C4::Context->config('intrahtdocs');
368
    my $columns_file = 'columns.def';
369
370
    # Get theme and language to build the path to columns.def
371
    my ($theme, $lang, $availablethemes) =
372
        themelanguage($htdocs, 'about.tt', 'intranet', $query);
373
    # Build columns.def path
374
    my $path = "$htdocs/$theme/$lang/$columns_file";
375
    my $fh;
376
    if ( ! open ( $fh, q{<:encoding(utf-8)}, $path ) )  {
377
        carp "Error opening $path. Check your templates.";
378
        return;
379
    }
380
    # Loop through the columns.def file
381
    while ( my $input = <$fh> ){
382
        chomp $input;
383
        if ( $input =~ m|<field name="(.*)">(.*)</field>| ) {
384
            my ( $table, $column ) =  split( '\.', $1);
385
            my $description        = $2;
386
            # Initialize the table array if needed.
387
            @{$columns->{ $table }} = () if ! defined $columns->{ $table };
388
            # Push field and description
389
            push @{$columns->{ $table }},
390
                { field => $column, description => $description };
391
        }
392
    }
393
    close $fh;
394
395
    return $columns;
396
}
397
398
1;
351
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/import_borrowers.tt (-15 / +14 lines)
Lines 246-281 Link Here
246
            </legend>
246
            </legend>
247
247
248
            <ol class="default_values" style="display:none;">
248
            <ol class="default_values" style="display:none;">
249
                [% FOREACH borrower_field IN borrower_fields %]
249
                [% FOREACH borrower_db_column IN borrower_fields.keys.sort %]
250
250
                    [% SWITCH borrower_db_column %]
251
                    [% SWITCH borrower_field.field %]
252
                    [% CASE 'branchcode' %]
251
                    [% CASE 'branchcode' %]
253
                        <li>
252
                        <li>
254
                            <label class="description" for="branchcode">[% borrower_field.description | html %]: </label>
253
                            <label class="description" for="branchcode">[% borrower_fields.$borrower_db_column | html %]: </label>
255
                            <select id="branchcode" name="branchcode">
254
                            <select id="branchcode" name="branchcode">
256
                                <option value="" selected="selected"></option>
255
                                <option value="" selected="selected"></option>
257
                                [% FOREACH library IN Branches.all() %]
256
                                [% FOREACH library IN Branches.all() %]
258
                                    <option value="[% library.branchcode | html %]">[% library.branchname | html %]</option>
257
                                    <option value="[% library.branchcode | html %]">[% library.branchname | html %]</option>
259
                                [% END %]
258
                                [% END %]
260
                            </select>
259
                            </select>
261
                            <span class="field_hint">[% borrower_field.field | html %]</span>
260
                            <span class="field_hint">[% borrower_db_column | html %]</span>
262
                        </li>
261
                        </li>
263
                    [% CASE 'categorycode' %]
262
                    [% CASE 'categorycode' %]
264
                        <li>
263
                        <li>
265
                            <label class="description" for="categorycode">[% borrower_field.description | html %]: </label>
264
                            <label class="description" for="categorycode">[% borrower_fields.$borrower_db_column | html %]: </label>
266
                            <select id="categorycode" name="categorycode">
265
                            <select id="categorycode" name="categorycode">
267
                                <option value="" selected="selected"></option>
266
                                <option value="" selected="selected"></option>
268
                                [% FOREACH category IN categories %]
267
                                [% FOREACH category IN categories %]
269
                                    <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
268
                                    <option value="[% category.categorycode | html %]">[% category.description | html %]</option>
270
                                [% END %]
269
                                [% END %]
271
                            </select>
270
                            </select>
272
                            <span class="field_hint">[% borrower_field.field | html %]</span>
271
                            <span class="field_hint">[% borrower_db_column | html %]</span>
273
                        </li>
272
                        </li>
274
                    [% CASE %]
273
                    [% CASE %]
275
                        <li>
274
                        <li>
276
                            <label class="description" for="[% borrower_field.field | html %]">[% borrower_field.description | html %]: </label>
275
                            <label class="description" for="[% borrower_db_column| html %]">[% borrower_fields.$borrower_db_column | html %]: </label>
277
                            <input id="[% borrower_field.field | html %]" name="[% borrower_field.field | html %]" type="text" />
276
                            <input id="[% borrower_db_column | html %]" name="[% borrower_db_column | html %]" type="text" />
278
                            <span class="field_hint">[% borrower_field.field | html %]</span>
277
                            <span class="field_hint">[% borrower_db_column | html %]</span>
279
                        </li>
278
                        </li>
280
                    [% END %]
279
                    [% END %]
281
                [% END %]
280
                [% END %]
Lines 298-308 Link Here
298
297
299
            <ol class="preserve_values" style="display:none;">
298
            <ol class="preserve_values" style="display:none;">
300
                <div class="hint">Selected fields will be preserved from original patron record when overwriting existing patron.</div>
299
                <div class="hint">Selected fields will be preserved from original patron record when overwriting existing patron.</div>
301
                [% FOREACH borrower_field IN borrower_fields %]
300
                [% FOREACH borrower_db_column IN borrower_fields.keys.sort %]
302
                        <li>
301
                        <li>
303
                            <label class="description" for="preserve_existing_[% borrower_field.field | html %]">[% borrower_field.description | html %]: </label>
302
                            <label class="description" for="preserve_existing_[% borrower_db_column | html %]">[% borrower_fields.$borrower_db_column | html %]: </label>
304
                            <input name="preserve_existing" id="preserve_existing_[%  borrower_field.field | html %]" value="[%  borrower_field.field | html %]" type="checkbox">
303
                            <input name="preserve_existing" id="preserve_existing_[%  borrower_db_column | html %]" value="[%  borrower_db_column | html %]" type="checkbox">
305
                            <span class="field_hint">[% borrower_field.field | html %]</span>
304
                            <span class="field_hint">[% borrower_db_column | html %]</span>
306
                        </li>
305
                        </li>
307
                [% END %]
306
                [% END %]
308
            </ol>
307
            </ol>
Lines 364-370 Link Here
364
            OR choose which fields you want to supply from the following list:
363
            OR choose which fields you want to supply from the following list:
365
            <ul>
364
            <ul>
366
                <li>
365
                <li>
367
                    [% FOREACH columnkey IN borrower_fields %]'[% columnkey.field | html %]', [% END %]
366
                    [% FOREACH columnkey IN borrower_fields.keys.sort %]'[% columnkey | html %]', [% END %]
368
                </li>
367
                </li>
369
            </ul>
368
            </ul>
370
        </li>
369
        </li>
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js (-1 / +1 lines)
Lines 256-262 $( document ).ready( function () { Link Here
256
                    style = "";
256
                    style = "";
257
                    disabled = "";
257
                    disabled = "";
258
                }
258
                }
259
                items.push('<label class="' + style +'"><input class="dbcolumn_selection" type="checkbox" id="' + key + '"' + checked + disabled + ' name="pref" value="' + val + '" /> ' + key + '</label>');
259
                items.push('<label class="' + style +'"><input class="dbcolumn_selection" type="checkbox" id="' + key + '"' + checked + disabled + ' name="pref" value="' + key + '" /> ' + val + ' (' + key + ')</label>');
260
            });
260
            });
261
            $("<div/>", {
261
            $("<div/>", {
262
                "class": "columns-2",
262
                "class": "columns-2",
(-)a/t/db_dependent/Templates.t (-21 / +14 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use CGI;
20
use CGI;
21
21
22
use Test::More tests => 8;
22
use Test::More tests => 5;
23
use Test::Deep;
23
use Test::Deep;
24
use Test::MockModule;
24
use Test::MockModule;
25
use Test::Warn;
25
use Test::Warn;
Lines 30-57 use t::lib::Mocks; Link Here
30
use C4::Auth qw( get_template_and_user );
30
use C4::Auth qw( get_template_and_user );
31
31
32
BEGIN {
32
BEGIN {
33
    use_ok('C4::Templates', qw( GetColumnDefs getlanguagecookie setlanguagecookie themelanguage gettemplate param output availablethemes badtemplatecheck ));
33
    use_ok('C4::Templates', qw( getlanguagecookie setlanguagecookie themelanguage gettemplate param output availablethemes badtemplatecheck ));
34
    can_ok( 'C4::Templates',
34
    can_ok(
35
         qw/ GetColumnDefs
35
        'C4::Templates',
36
             getlanguagecookie
36
        qw(
37
             setlanguagecookie
37
          getlanguagecookie
38
             themelanguage
38
          setlanguagecookie
39
             gettemplate
39
          themelanguage
40
             _get_template_file
40
          gettemplate
41
             param
41
          _get_template_file
42
             output /);
42
          param
43
          output
44
          )
45
    );
43
}
46
}
44
47
45
my $query   = CGI->new();
46
my $columns = C4::Templates::GetColumnDefs( $query );
47
48
is( ref( $columns ) eq 'HASH', 1, 'GetColumnDefs returns a hashref' );
49
# get the tables names, sorted
50
my @keys = sort keys %{$columns};
51
is( scalar @keys, 6, 'GetColumnDefs correctly returns the 5 tables defined in columns.def' );
52
my @tables = qw( biblio biblioitems borrowers items statistics subscription );
53
cmp_deeply( \@keys, \@tables, 'GetColumnDefs returns the expected tables');
54
55
subtest 'Testing themelanguage' => sub {
48
subtest 'Testing themelanguage' => sub {
56
    plan tests => 12;
49
    plan tests => 12;
57
    my $testing_language;
50
    my $testing_language;
(-)a/tools/import_borrowers.pl (-5 / +2 lines)
Lines 38-44 use Modern::Perl; Link Here
38
38
39
use C4::Auth qw( get_template_and_user );
39
use C4::Auth qw( get_template_and_user );
40
use C4::Output qw( output_and_exit output_html_with_http_headers );
40
use C4::Output qw( output_and_exit output_html_with_http_headers );
41
use C4::Templates;
41
use Koha::Database::Columns;
42
use Koha::Patrons;
42
use Koha::Patrons;
43
use Koha::DateUtils qw( dt_from_string );
43
use Koha::DateUtils qw( dt_from_string );
44
use Koha::Token;
44
use Koha::Token;
Lines 78-86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
78
# get the patron categories and pass them to the template
78
# get the patron categories and pass them to the template
79
my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']});
79
my @patron_categories = Koha::Patron::Categories->search_with_library_limits({}, {order_by => ['description']});
80
$template->param( categories => \@patron_categories );
80
$template->param( categories => \@patron_categories );
81
my $columns = C4::Templates::GetColumnDefs( $input )->{borrowers};
81
$template->param( borrower_fields => Koha::Database::Columns->columns->{borrowers} );
82
$columns = [ grep { $_->{field} ne 'borrowernumber' ? $_ : () } @$columns ];
83
$template->param( borrower_fields => $columns );
84
82
85
if ( $input->param('sample') ) {
83
if ( $input->param('sample') ) {
86
    our $csv = Text::CSV->new( { binary => 1 } );    # binary needed for non-ASCII Unicode
84
    our $csv = Text::CSV->new( { binary => 1 } );    # binary needed for non-ASCII Unicode
87
- 

Return to bug 29695