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

(-)a/Koha/Exceptions/Patron/Attribute.pm (+10 lines)
Lines 28-33 use Exception::Class ( Link Here
28
        isa         => 'Koha::Exceptions::Patron::Attribute',
28
        isa         => 'Koha::Exceptions::Patron::Attribute',
29
        description => "the passed value is invalid for attribute type",
29
        description => "the passed value is invalid for attribute type",
30
        fields      => ["attribute"]
30
        fields      => ["attribute"]
31
    },
32
    'Koha::Exceptions::Patron::Attribute::NonEditable' => {
33
        isa         => 'Koha::Exceptions::Patron::Attribute',
34
        description => "Cannot to modify value of non editable attribute type",
35
        fields      => ["type"]
31
    }
36
    }
32
);
37
);
33
38
Lines 60-65 sub full_message { Link Here
60
                $self->attribute->code,
65
                $self->attribute->code,
61
                $self->attribute->attribute
66
                $self->attribute->attribute
62
            );
67
            );
68
        } elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::NonEditable') ) {
69
            $msg = sprintf(
70
                "Cannot change value pf non editable attribute type. type=%s",
71
                $self->type
72
            );
63
        }
73
        }
64
    }
74
    }
65
75
(-)a/Koha/Exceptions/Patron/Attribute/Type.pm (+11 lines)
Lines 14-19 use Exception::Class ( Link Here
14
        description => "Cannot change property",
14
        description => "Cannot change property",
15
        fields      => ['property'],
15
        fields      => ['property'],
16
    },
16
    },
17
    'Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination' => {
18
        isa         => 'Koha::Exceptions::Patron::Attribute::Type',
19
        description => "An invalid property combination has been set",
20
        fields      => ['property'],
21
    },
17
);
22
);
18
23
19
sub full_message {
24
sub full_message {
Lines 28-33 sub full_message { Link Here
28
                $self->property
33
                $self->property
29
            );
34
            );
30
        }
35
        }
36
        elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination') ) {
37
            $msg = sprintf(
38
                "The property '%s' is incompatible with the current combination of properties",
39
                $self->property
40
            );
41
        }
31
    }
42
    }
32
43
33
    return $msg;
44
    return $msg;
(-)a/Koha/Patron.pm (-2 / +23 lines)
Lines 2270-2283 sub add_extended_attribute { Link Here
2270
2270
2271
=head3 extended_attributes
2271
=head3 extended_attributes
2272
2272
2273
Return object of Koha::Patron::Attributes type with all attributes set for this patron
2273
Getter/setter for Koha::Patron::Attributes. Allways return the extended attributes of the patron.
2274
2274
2275
Or setter FIXME
2275
Or setter FIXME
2276
2276
2277
=over 4
2278
2279
=item C<$extended_attributes>
2280
2281
The extended attributes to set on the format [{ code => $code, attribute => $value }, ...].
2282
All extended attributes of the patron must be provided.
2283
2284
=item C<$params>
2285
2286
A hashfre for Optional parameters.
2287
2288
if called from within the staff interface C<check_editable> must be set so that
2289
attribute type settings making the attribute non editable are enforced.
2290
2277
=cut
2291
=cut
2278
2292
2279
sub extended_attributes {
2293
sub extended_attributes {
2280
    my ( $self, $attributes ) = @_;
2294
    my ( $self, $attributes, $params ) = @_;
2295
    $params //= {};
2281
2296
2282
    if ($attributes) {    # setter
2297
    if ($attributes) {    # setter
2283
        my %attribute_changes;
2298
        my %attribute_changes;
Lines 2332-2337 sub extended_attributes { Link Here
2332
                        $change->{after}  //= [];
2347
                        $change->{after}  //= [];
2333
2348
2334
                        if ( $is_different->( $change->{before}, $change->{after} ) ) {
2349
                        if ( $is_different->( $change->{before}, $change->{after} ) ) {
2350
                            if ($params->{check_editable}) {
2351
                                my $type = Koha::Patron::Attribute::Types->find($code);
2352
                                unless ($type->is_editable) {
2353
                                    Koha::Exceptions::Patron::Attribute::NonEditable->throw( type => $code )
2354
                                }
2355
                            }
2335
                            $changed_attributes_codes{$code} = 1;
2356
                            $changed_attributes_codes{$code} = 1;
2336
2357
2337
                            unless ($repeatable) {
2358
                            unless ($repeatable) {
(-)a/Koha/Patron/Attribute.pm (+2 lines)
Lines 20-27 use Modern::Perl; Link Here
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Exceptions::Patron::Attribute;
21
use Koha::Exceptions::Patron::Attribute;
22
use Koha::Patron::Attribute::Types;
22
use Koha::Patron::Attribute::Types;
23
use Koha::Patron::Attributes;
23
use Koha::AuthorisedValues;
24
use Koha::AuthorisedValues;
24
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use C4::Context;
25
27
26
use base qw(Koha::Object);
28
use base qw(Koha::Object);
27
29
(-)a/Koha/Patron/Attribute/Type.pm (+68 lines)
Lines 46-51 sub store { Link Here
46
46
47
    $self->check_repeatables;
47
    $self->check_repeatables;
48
    $self->check_unique_ids;
48
    $self->check_unique_ids;
49
    $self->check_hidden;
50
    $self->check_readonly;
51
    $self->check_secret;
49
52
50
    return $self->SUPER::store();
53
    return $self->SUPER::store();
51
}
54
}
Lines 112-117 sub check_unique_ids { Link Here
112
    return $self;
115
    return $self;
113
}
116
}
114
117
118
=head3 check_hidden
119
120
=cut
121
122
sub check_hidden {
123
    my ($self) = @_;
124
    if ( $self->hidden && (
125
            $self->readonly ||
126
            $self->secret ||
127
            $self->opac_display ||
128
            $self->opac_editable ||
129
            $self->display_checkout
130
        )
131
    ) {
132
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'hidden' );
133
    }
134
}
135
136
=head3 check_readonly
137
138
=cut
139
140
sub check_readonly {
141
    my ($self) = @_;
142
    if ( $self->readonly && (
143
            $self->hidden ||
144
            $self->secret ||
145
            $self->opac_editable
146
        )
147
    ) {
148
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'readonly' );
149
    }
150
}
151
152
=head3 check_secret
153
154
=cut
155
156
sub check_secret {
157
    my ($self) = @_;
158
    if ( $self->secret && (
159
            $self->readonly ||
160
            $self->hidden ||
161
            $self->opac_display ||
162
            $self->opac_editable ||
163
            $self->display_checkout
164
        )
165
    ) {
166
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'hidden' );
167
    }
168
}
169
170
=head3 is_editable
171
172
=cut
173
174
sub is_editable {
175
    my ($self) = @_;
176
    my $logged_in_borrowernumber = C4::Context->userenv->{'number'};
177
    if ($logged_in_borrowernumber) {
178
        my $patron = Koha::Patrons->find($logged_in_borrowernumber);
179
        return $patron->_is_superlibrarian && !( $self->hidden || $self->readonly || $self->secret ) if $patron;
180
    }
181
}
182
115
=head3 _type
183
=head3 _type
116
184
117
=cut
185
=cut
(-)a/admin/patron-attr-types.pl (+6 lines)
Lines 109-114 sub add_update_attribute_type { Link Here
109
    my $description               = $input->param('description');
109
    my $description               = $input->param('description');
110
    my $repeatable                = $input->param('repeatable')                ? 1 : 0;
110
    my $repeatable                = $input->param('repeatable')                ? 1 : 0;
111
    my $unique_id                 = $input->param('unique_id')                 ? 1 : 0;
111
    my $unique_id                 = $input->param('unique_id')                 ? 1 : 0;
112
    my $hidden                    = $input->param('hidden')                    ? 1 : 0;
113
    my $readonly                  = $input->param('readonly')                  ? 1 : 0;
114
    my $secret                    = $input->param('secret')                    ? 1 : 0;
112
    my $is_date                   = $input->param('is_date')                   ? 1 : 0;
115
    my $is_date                   = $input->param('is_date')                   ? 1 : 0;
113
    my $opac_display              = $input->param('opac_display')              ? 1 : 0;
116
    my $opac_display              = $input->param('opac_display')              ? 1 : 0;
114
    my $opac_editable             = $input->param('opac_editable')             ? 1 : 0;
117
    my $opac_editable             = $input->param('opac_editable')             ? 1 : 0;
Lines 146-151 sub add_update_attribute_type { Link Here
146
        {
149
        {
147
            repeatable                => $repeatable,
150
            repeatable                => $repeatable,
148
            unique_id                 => $unique_id,
151
            unique_id                 => $unique_id,
152
            hidden                    => $hidden,
153
            readonly                  => $readonly,
154
            secret                    => $secret,
149
            is_date                   => $is_date,
155
            is_date                   => $is_date,
150
            opac_display              => $opac_display,
156
            opac_display              => $opac_display,
151
            opac_editable             => $opac_editable,
157
            opac_editable             => $opac_editable,
(-)a/installer/data/mysql/atomicupdate/bug_39453-add-new-columns-to-borrower-attribute-types.pl (+16 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_success say_info);
3
4
return {
5
    bug_number  => "39453",
6
    description => "Add attribute type settings for restricting access to extended attributes",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        $dbh->do( q{ALTER TABLE `borrower_attribute_types` ADD COLUMN `hidden` tinyint(1) NOT NULL DEFAULT 0, ADD COLUMN `readonly` tinyint(1) NOT NULL DEFAULT 0, ADD COLUMN `secret` tinyint(1) NOT NULL DEFAULT 0} );
12
13
        say $out "Added columns 'borrower_attribute_types.hidden', 'borrower_attribute_types.readonly' and 'borrower_attribute_types.secret'";
14
15
    },
16
};
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/patron-attr-types.tt (+76 lines)
Lines 139-144 Link Here
139
                        [% END %]
139
                        [% END %]
140
                        <span class="hint">If checked, attribute will be a unique identifier. If a value is given to a patron record, the same value cannot be given to a different record.</span>
140
                        <span class="hint">If checked, attribute will be a unique identifier. If a value is given to a patron record, the same value cannot be given to a different record.</span>
141
                    </li>
141
                    </li>
142
                    <li>
143
                        <label for="hidden">Hidden: </label>
144
                        [% IF attribute_type AND attribute_type.hidden %]
145
                            <input type="checkbox" id="hidden" name="hidden" checked="checked" />
146
                        [% ELSE %]
147
                            <input type="checkbox" id="hidden" name="hidden" />
148
                        [% END %]
149
                        <span class="hint">Check to hide this attribute on a patron's details page in the OPAC and staff interface, and when creating or editing a patron from the staff interface. Does not apply for superlibrarians.</span>
150
                    </li>
151
                   <li>
152
                        <label for="readonly">Readonly: </label>
153
                        [% IF attribute_type AND attribute_type.readonly %]
154
                            <input type="checkbox" id="readonly" name="readonly" checked="checked" />
155
                        [% ELSE %]
156
                            <input type="checkbox" id="readonly" name="readonly" />
157
                        [% END %]
158
                        <span class="hint">Check to make this attribute readonly when creating or editing a patron from the staff interface. Does not apply for superlibrarians.</span>
159
                    </li>
160
                    <li>
161
                        <label for="secret">Secret: </label>
162
                        [% IF attribute_type AND attribute_type.secret %]
163
                            <input type="checkbox" id="secret" name="secret" checked="checked" />
164
                        [% ELSE %]
165
                            <input type="checkbox" id="secret" name="secret" />
166
                        [% END %]
167
                        <span class="hint">Check to mask attribute value on a patron's details page, and hide when creating or editing a patron. Does not apply for superlibrarians.</span>
168
                    </li>
142
                    <li
169
                    <li
143
                        ><label for="is_date">Is a date: </label>
170
                        ><label for="is_date">Is a date: </label>
144
                        [% IF attribute_type AND attribute_type.is_date %]
171
                        [% IF attribute_type AND attribute_type.is_date %]
Lines 424-429 Link Here
424
            if ($("#branches option:selected").length < 1) {
451
            if ($("#branches option:selected").length < 1) {
425
                $("#branches option:first").attr("selected", "selected");
452
                $("#branches option:first").attr("selected", "selected");
426
            }
453
            }
454
            $('#hidden')
455
                .change(function() {
456
                    if (this.checked) {
457
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
458
                        $("#opac_display").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
459
                        $("#readonly").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
460
                        $("#secret").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
461
                        $("#display_checkout").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
462
                    } else {
463
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
464
                        $("#opac_display").removeAttr("disabled").parent().removeAttr("aria-disabled");
465
                        $("#readonly").removeAttr("disabled").parent().removeAttr("aria-disabled");
466
                        $("#secret").removeAttr("disabled").parent().removeAttr("aria-disabled");
467
                        $("#display_checkout").removeAttr("disabled").parent().removeAttr("aria-disabled");
468
                    }
469
                })
470
                .change();
471
472
            $('#readonly')
473
                .change(function() {
474
                    if (this.checked) {
475
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
476
                        $("#hidden").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
477
                        $("#secret").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
478
                    } else {
479
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
480
                        $("#hidden").removeAttr("disabled").parent().removeAttr("aria-disabled");
481
                        $("#secret").removeAttr("disabled").parent().removeAttr("aria-disabled");
482
                    }
483
                })
484
                .change();
485
486
            $('#secret')
487
                .change(function() {
488
                    if (this.checked) {
489
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
490
                        $("#opac_display").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
491
                        $("#hidden").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
492
                        $("#readony").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
493
                        $("#display_checkout").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
494
                    } else {
495
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
496
                        $("#opac_display").removeAttr("disabled").parent().removeAttr("aria-disabled");
497
                        $("#hidden").removeAttr("disabled").parent().removeAttr("aria-disabled");
498
                        $("#readonly").removeAttr("disabled").parent().removeAttr("aria-disabled");
499
                        $("#display_checkout").removeAttr("disabled").parent().removeAttr("aria-disabled");
500
                    }
501
                })
502
                .change();
427
503
428
            $("#opac_display")
504
            $("#opac_display")
429
                .change(function () {
505
                .change(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-34 / +25 lines)
Lines 1512-1517 Link Here
1512
                                        </legend>
1512
                                        </legend>
1513
                                        <div class="attributes_tables">
1513
                                        <div class="attributes_tables">
1514
                                            <input type="hidden" name="setting_extended_patron_attributes" value="1" />
1514
                                            <input type="hidden" name="setting_extended_patron_attributes" value="1" />
1515
                                            [% FOREACH patron_attribute IN hidden_patron_attributes %]
1516
                                                <input type="hidden" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" value="[% patron_attribute.value | html %]" />
1517
                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1518
                                            [% END %]
1515
                                            [% FOREACH pa_loo IN patron_attributes %]
1519
                                            [% FOREACH pa_loo IN patron_attributes %]
1516
                                                <ol class="attributes_table">
1520
                                                <ol class="attributes_table">
1517
                                                    <div id="aai_[% pa_loo.class | html %]">
1521
                                                    <div id="aai_[% pa_loo.class | html %]">
Lines 1519-1532 Link Here
1519
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1523
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1520
                                                        [% END %]
1524
                                                        [% END %]
1521
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1525
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1522
                                                            <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1526
                                                            <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]"[% IF patron_attribute.readonly %] aria-readonly="true"[% END %]>
1523
                                                                [% IF patron_attribute.mandatory %]
1527
                                                                [% IF patron_attribute.mandatory %]
1524
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1528
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1525
                                                                [% ELSE %]
1529
                                                                [% ELSE %]
1526
                                                                    <label for="[% patron_attribute.form_id | html %]">[% patron_attribute.description | html %]: </label>
1530
                                                                    <label for="[% patron_attribute.form_id | html %]">[% patron_attribute.description | html %]: </label>
1527
                                                                [% END %]
1531
                                                                [% END %]
1528
                                                                [% IF ( patron_attribute.use_dropdown ) %]
1532
                                                                [% IF ( patron_attribute.use_dropdown ) %]
1529
                                                                    <select id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" [% IF patron_attribute.mandatory %]required="required"[% END %]>
1533
                                                                    <select id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]"[% IF patron_attribute.mandatory %] required="required"[% END %][% IF patron_attribute.readonly %] disabled[% END %]>
1530
                                                                        <option value=""></option>
1534
                                                                        <option value=""></option>
1531
                                                                        [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
1535
                                                                        [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
1532
                                                                            [% IF auth_val_loo.authorised_value == patron_attribute.value %]
1536
                                                                            [% IF auth_val_loo.authorised_value == patron_attribute.value %]
Lines 1536-1580 Link Here
1536
                                                                            [% END %]
1540
                                                                            [% END %]
1537
                                                                        [% END %]
1541
                                                                        [% END %]
1538
                                                                    </select>
1542
                                                                    </select>
1543
                                                                    [% IF ( patron_attribute.readonly ) %]
1544
                                                                        <input type="hidden" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" value="[% patron_attribute.value | html %]" />
1545
                                                                    [% END %]
1539
                                                                [% ELSE %]
1546
                                                                [% ELSE %]
1540
                                                                    [% IF patron_attribute.mandatory %]
1547
                                                                    [% IF patron_attribute.is_date %]
1541
                                                                        [% IF patron_attribute.is_date %]
1548
                                                                        <input
1542
                                                                            <input
1549
                                                                            type="text"
1543
                                                                                type="text"
1550
                                                                            id="[% patron_attribute.form_id | html %]"
1544
                                                                                id="[% patron_attribute.form_id | html %]"
1551
                                                                            name="[% patron_attribute.form_id | html %]"
1545
                                                                                name="[% patron_attribute.form_id | html %]"
1552
                                                                            maxlength="10"
1546
                                                                                maxlength="10"
1553
                                                                            size="10"
1547
                                                                                size="10"
1554
                                                                            value="[% patron_attribute.value | html %]"
1548
                                                                                value="[% patron_attribute.value | html %]"
1555
                                                                            [% IF patron_attribute.mandatory %]required="required"[% END %]
1549
                                                                                required="required"
1556
                                                                            [% IF ( patron_attribute.readonly ) %]readonly[% ELSE %]class="flatpickr"[% END %]
1550
                                                                                class="flatpickr"
1557
                                                                        />
1551
                                                                            />
1552
                                                                        [% ELSE %]
1553
                                                                            <textarea rows="2" cols="30" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" required="required">
1554
    [% patron_attribute.value | html %]</textarea
1555
                                                                            >
1556
                                                                        [% END %]
1557
                                                                    [% ELSE %]
1558
                                                                    [% ELSE %]
1558
                                                                        [% IF patron_attribute.is_date %]
1559
                                                                        <textarea rows="2" cols="30" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]"[% IF patron_attribute.mandatory %] required="required"[% END %][% IF ( patron_attribute.readonly ) %] readonly[% END %]>
1559
                                                                            <input
1560
[% patron_attribute.value | html %]</textarea
1560
                                                                                type="text"
1561
                                                                        >
1561
                                                                                id="[% patron_attribute.form_id | html %]"
1562
                                                                                name="[% patron_attribute.form_id | html %]"
1563
                                                                                maxlength="10"
1564
                                                                                size="10"
1565
                                                                                value="[% patron_attribute.value | html %]"
1566
                                                                                class="flatpickr"
1567
                                                                            />
1568
                                                                        [% ELSE %]
1569
                                                                            <textarea rows="2" cols="30" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]">[% patron_attribute.value | html %]</textarea>
1570
                                                                        [% END %]
1571
                                                                    [% END %]
1562
                                                                    [% END %]
1572
                                                                [% END # /IF ( patron_attribute.use_dropdown ) %]
1563
                                                                [% END # /IF ( patron_attribute.use_dropdown ) %]
1573
                                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1564
                                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1574
                                                                [% IF ( !patron_attribute.is_date ) %]
1565
                                                                [% IF ( !patron_attribute.is_date && !patron_attribute.readonly ) %]
1575
                                                                    <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
1566
                                                                    <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
1576
                                                                [% END %]
1567
                                                                [% END %]
1577
                                                                [% IF ( patron_attribute.repeatable ) %]
1568
                                                                [% IF ( patron_attribute.repeatable && !patron_attribute.readonly ) %]
1578
                                                                    <a href="#" class="clone_attribute"><i class="fa fa-fw fa-plus"></i> New</a>
1569
                                                                    <a href="#" class="clone_attribute"><i class="fa fa-fw fa-plus"></i> New</a>
1579
                                                                [% END %]
1570
                                                                [% END %]
1580
                                                                [% IF patron_attribute.mandatory %]<span class="required">Required</span>[% END %]
1571
                                                                [% IF patron_attribute.mandatory %]<span class="required">Required</span>[% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tt (-3 / +7 lines)
Lines 350-359 Link Here
350
                                        [% FOREACH item IN attribute.items %]
350
                                        [% FOREACH item IN attribute.items %]
351
                                            <li data-pa_code="[% item.type.code | replace('[^a-zA-Z0-9_-]', '') %]">
351
                                            <li data-pa_code="[% item.type.code | replace('[^a-zA-Z0-9_-]', '') %]">
352
                                                <span class="label">[% item.type.description | html %]: </span>
352
                                                <span class="label">[% item.type.description | html %]: </span>
353
                                                [% IF item.type.is_date %]
353
                                                [% IF item.type.secret %]
354
                                                    [% item.description | $KohaDates %]
354
                                                    *****
355
                                                [% ELSE %]
355
                                                [% ELSE %]
356
                                                    [% item.description | html_line_break %]
356
                                                    [% IF item.type.is_date %]
357
                                                        [% item.description | $KohaDates %]
358
                                                    [% ELSE %]
359
                                                        [% item.description | html_line_break %]
360
                                                    [% END %]
357
                                                [% END %]
361
                                                [% END %]
358
                                            </li>
362
                                            </li>
359
                                        [% END %]
363
                                        [% END %]
(-)a/members/memberentry.pl (-11 / +23 lines)
Lines 24-29 use Try::Tiny; Link Here
24
24
25
# external modules
25
# external modules
26
use CGI qw ( -utf8 );
26
use CGI qw ( -utf8 );
27
use List::Util qw ( all );
27
28
28
# internal modules
29
# internal modules
29
use C4::Auth qw( get_template_and_user haspermission );
30
use C4::Auth qw( get_template_and_user haspermission );
Lines 164-171 foreach (@field_check) { Link Here
164
$template->param( "quickadd"  => 1 ) if ($quickadd);
165
$template->param( "quickadd"  => 1 ) if ($quickadd);
165
$template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
166
$template->param( "duplicate" => 1 ) if ( $op eq 'duplicate' );
166
$template->param( "checked"   => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
167
$template->param( "checked"   => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
168
my $logged_in_user = Koha::Patrons->find($loggedinuser);
169
167
if ( $op eq 'edit_form' or $op eq 'cud-save' or $op eq 'duplicate' ) {
170
if ( $op eq 'edit_form' or $op eq 'cud-save' or $op eq 'duplicate' ) {
168
    my $logged_in_user = Koha::Patrons->find($loggedinuser);
169
    output_and_exit_if_error(
171
    output_and_exit_if_error(
170
        $input, $cookie, $template,
172
        $input, $cookie, $template,
171
        { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
173
        { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron }
Lines 627-633 if ( ( !$nok ) and $nodouble and ( $op eq 'cud-insert' or $op eq 'cud-save' ) ) Link Here
627
        if ( C4::Context->preference('ExtendedPatronAttributes')
629
        if ( C4::Context->preference('ExtendedPatronAttributes')
628
            and $input->param('setting_extended_patron_attributes') )
630
            and $input->param('setting_extended_patron_attributes') )
629
        {
631
        {
630
            $patron->extended_attributes($extended_patron_attributes);
632
            $patron->extended_attributes( $extended_patron_attributes, { check_editable => 1 } );
631
        }
633
        }
632
634
633
        if (
635
        if (
Lines 927-933 sub patron_attributes_form { Link Here
927
929
928
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
930
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
929
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
931
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
930
    if ( $attribute_types->count == 0 ) {
932
    if ( $attribute_types->count == 0 || ( !$logged_in_user->is_superlibrarian && all { $_->hidden } $attribute_types->as_list ) ) {
931
        $template->param( no_patron_attribute_types => 1 );
933
        $template->param( no_patron_attribute_types => 1 );
932
        return;
934
        return;
933
    }
935
    }
Lines 941-952 sub patron_attributes_form { Link Here
941
    my @attribute_loop = ();
943
    my @attribute_loop = ();
942
    my $i              = 0;
944
    my $i              = 0;
943
    my %items_by_class;
945
    my %items_by_class;
946
    my @hidden_attributes;
947
948
    my $is_superlibrarian = $logged_in_user->is_superlibrarian;
944
    while ( my ($attr_type) = $attribute_types->next ) {
949
    while ( my ($attr_type) = $attribute_types->next ) {
945
        my $entry = {
950
        my $entry = {
946
            class         => $attr_type->class(),
951
            class         => $attr_type->class(),
947
            code          => $attr_type->code(),
952
            code          => $attr_type->code(),
948
            description   => $attr_type->description(),
953
            description   => $attr_type->description(),
949
            repeatable    => $attr_type->repeatable(),
954
            repeatable    => $attr_type->repeatable(),
955
            hidden        => !$is_superlibrarian && $attr_type->hidden(),
956
            readonly      => !$is_superlibrarian && $attr_type->readonly(),
957
            secret        => !$is_superlibrarian && $attr_type->secret(),
950
            category      => $attr_type->authorised_value_category(),
958
            category      => $attr_type->authorised_value_category(),
951
            category_code => $attr_type->category_code(),
959
            category_code => $attr_type->category_code(),
952
            mandatory     => $attr_type->mandatory(),
960
            mandatory     => $attr_type->mandatory(),
Lines 957-971 sub patron_attributes_form { Link Here
957
                my $newentry = {%$entry};
965
                my $newentry = {%$entry};
958
                $newentry->{value}        = $attr->{attribute};
966
                $newentry->{value}        = $attr->{attribute};
959
                $newentry->{use_dropdown} = 0;
967
                $newentry->{use_dropdown} = 0;
960
                if ( $attr_type->authorised_value_category() ) {
961
                    $newentry->{use_dropdown} = 1;
962
                    $newentry->{auth_val_loop} =
963
                        GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
964
                }
965
                $i++;
968
                $i++;
966
                undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
967
                $newentry->{form_id} = "patron_attr_$i";
969
                $newentry->{form_id} = "patron_attr_$i";
968
                push @{ $items_by_class{ $attr_type->class() } }, $newentry;
970
                if (!$is_superlibrarian && ( $attr_type->hidden() || $attr_type->secret() ) ) {
971
                    push @hidden_attributes, $newentry;
972
                } else {
973
                    if ( $attr_type->authorised_value_category() ) {
974
                        $newentry->{use_dropdown} = 1;
975
                        $newentry->{auth_val_loop} =
976
                            GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
977
                    }
978
                    undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
979
                    push @{ $items_by_class{ $attr_type->class() } }, $newentry;
980
                }
969
            }
981
            }
970
        } else {
982
        } else {
971
            $i++;
983
            $i++;
Lines 988-994 sub patron_attributes_form { Link Here
988
        };
1000
        };
989
    }
1001
    }
990
1002
991
    $template->param( patron_attributes => \@attribute_loop );
1003
    $template->param( patron_attributes => \@attribute_loop, hidden_patron_attributes => \@hidden_attributes );
992
1004
993
}
1005
}
994
1006
(-)a/members/moremember.pl (-5 / +6 lines)
Lines 28-33 Link Here
28
28
29
use Modern::Perl;
29
use Modern::Perl;
30
use CGI qw ( -utf8 );
30
use CGI qw ( -utf8 );
31
use List::Util qw ( all );
31
use C4::Context;
32
use C4::Context;
32
use C4::Auth   qw( get_template_and_user );
33
use C4::Auth   qw( get_template_and_user );
33
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
34
use C4::Output qw( output_and_exit_if_error output_and_exit output_html_with_http_headers );
Lines 138-143 unless ( Koha::Patron::Categories->search_with_library_limits( { 'me.categorycod Link Here
138
}
139
}
139
140
140
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
141
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
142
    my $is_superlibrarian = $logged_in_user->is_superlibrarian;
141
    my @attributes = $patron->extended_attributes->as_list;         # FIXME Must be improved!
143
    my @attributes = $patron->extended_attributes->as_list;         # FIXME Must be improved!
142
    my @classes    = uniq( map { $_->type->class } @attributes );
144
    my @classes    = uniq( map { $_->type->class } @attributes );
143
    @classes = sort @classes;
145
    @classes = sort @classes;
Lines 146-152 if ( C4::Context->preference('ExtendedPatronAttributes') ) { Link Here
146
    for my $class (@classes) {
148
    for my $class (@classes) {
147
        my @items;
149
        my @items;
148
        for my $attr (@attributes) {
150
        for my $attr (@attributes) {
149
            push @items, $attr if $attr->type->class eq $class;
151
            push @items, $attr if $attr->type->class eq $class && ( $is_superlibrarian || !$attr->hidden );
150
        }
152
        }
151
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
153
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
152
        my $lib = $av->count ? $av->next->lib : $class;
154
        my $lib = $av->count ? $av->next->lib : $class;
Lines 161-169 if ( C4::Context->preference('ExtendedPatronAttributes') ) { Link Here
161
    $template->param( attributes_loop => \@attributes_loop );
163
    $template->param( attributes_loop => \@attributes_loop );
162
164
163
    my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
165
    my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
164
    my $nb_of_attribute_types =
166
    my $attribute_types =
165
        Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id )->count;
167
        Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
166
    if ( $nb_of_attribute_types == 0 ) {
168
    if ( $attribute_types->count == 0 || ( !$is_superlibrarian && all { $_->hidden } $attribute_types->as_list ) ) {
167
        $template->param( no_patron_attribute_types => 1 );
169
        $template->param( no_patron_attribute_types => 1 );
168
    }
170
    }
169
}
171
}
170
- 

Return to bug 39453