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 (+10 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 27-32 sub full_message { Link Here
27
                "The property '%s' cannot be changed, some patron attributes are using it that way.",
32
                "The property '%s' cannot be changed, some patron attributes are using it that way.",
28
                $self->property
33
                $self->property
29
            );
34
            );
35
        } elsif ( $self->isa('Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination') ) {
36
            $msg = sprintf(
37
                "The property '%s' is incompatible with the current combination of properties",
38
                $self->property
39
            );
30
        }
40
        }
31
    }
41
    }
32
42
(-)a/Koha/Patron.pm (-2 / +25 lines)
Lines 2607-2620 sub add_extended_attribute { Link Here
2607
2607
2608
=head3 extended_attributes
2608
=head3 extended_attributes
2609
2609
2610
Return object of Koha::Patron::Attributes type with all attributes set for this patron
2610
Getter/setter for Koha::Patron::Attributes. Always return the extended attributes of the patron.
2611
2611
2612
Or setter FIXME
2612
Or setter FIXME
2613
2613
2614
=over 4
2615
2616
=item C<$extended_attributes>
2617
2618
The extended attributes to set on the format [{ code => $code, attribute => $value }, ...].
2619
All extended attributes of the patron must be provided.
2620
2621
=item C<$params>
2622
2623
A hashfre for Optional parameters.
2624
2625
if called from within the staff interface C<check_editable> must be set so that
2626
attribute type settings making the attribute non editable are enforced.
2627
2628
=back
2629
2614
=cut
2630
=cut
2615
2631
2616
sub extended_attributes {
2632
sub extended_attributes {
2617
    my ( $self, $attributes ) = @_;
2633
    my ( $self, $attributes, $params ) = @_;
2634
    $params //= {};
2618
2635
2619
    if ($attributes) {    # setter
2636
    if ($attributes) {    # setter
2620
        my %attribute_changes;
2637
        my %attribute_changes;
Lines 2669-2674 sub extended_attributes { Link Here
2669
                        $change->{after}  //= [];
2686
                        $change->{after}  //= [];
2670
2687
2671
                        if ( $is_different->( $change->{before}, $change->{after} ) ) {
2688
                        if ( $is_different->( $change->{before}, $change->{after} ) ) {
2689
                            if ( $params->{check_editable} ) {
2690
                                my $type = Koha::Patron::Attribute::Types->find($code);
2691
                                unless ( $type->is_editable ) {
2692
                                    Koha::Exceptions::Patron::Attribute::NonEditable->throw( type => $code );
2693
                                }
2694
                            }
2672
                            $changed_attributes_codes{$code} = 1;
2695
                            $changed_attributes_codes{$code} = 1;
2673
2696
2674
                            unless ($repeatable) {
2697
                            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 (+71 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 (
125
        $self->hidden
126
        && (   $self->readonly
127
            || $self->secret
128
            || $self->opac_display
129
            || $self->opac_editable
130
            || $self->display_checkout )
131
        )
132
    {
133
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'hidden' );
134
    }
135
}
136
137
=head3 check_readonly
138
139
=cut
140
141
sub check_readonly {
142
    my ($self) = @_;
143
    if (
144
        $self->readonly
145
        && (   $self->hidden
146
            || $self->secret
147
            || $self->opac_editable )
148
        )
149
    {
150
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'readonly' );
151
    }
152
}
153
154
=head3 check_secret
155
156
=cut
157
158
sub check_secret {
159
    my ($self) = @_;
160
    if (
161
        $self->secret
162
        && (   $self->readonly
163
            || $self->hidden
164
            || $self->opac_display
165
            || $self->opac_editable
166
            || $self->display_checkout )
167
        )
168
    {
169
        Koha::Exceptions::Patron::Attribute::Type::InvalidPropertyCombination->throw( property => 'hidden' );
170
    }
171
}
172
173
=head3 is_editable
174
175
=cut
176
177
sub is_editable {
178
    my ($self) = @_;
179
    my $logged_in_borrowernumber = C4::Context->userenv->{'number'};
180
    if ($logged_in_borrowernumber) {
181
        my $patron = Koha::Patrons->find($logged_in_borrowernumber);
182
        return $patron->_is_superlibrarian && !( $self->hidden || $self->readonly || $self->secret ) if $patron;
183
    }
184
}
185
115
=head3 _type
186
=head3 _type
116
187
117
=cut
188
=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 (+19 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(
12
            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}
13
        );
14
15
        say $out
16
            "Added columns 'borrower_attribute_types.hidden', 'borrower_attribute_types.readonly' and 'borrower_attribute_types.secret'";
17
18
    },
19
};
(-)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 459-464 Link Here
459
            if ($("#branches option:selected").length < 1) {
486
            if ($("#branches option:selected").length < 1) {
460
                $("#branches option:first").attr("selected", "selected");
487
                $("#branches option:first").attr("selected", "selected");
461
            }
488
            }
489
            $("#hidden")
490
                .change(function () {
491
                    if (this.checked) {
492
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
493
                        $("#opac_display").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
494
                        $("#readonly").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
495
                        $("#secret").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
496
                        $("#display_checkout").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
497
                    } else {
498
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
499
                        $("#opac_display").removeAttr("disabled").parent().removeAttr("aria-disabled");
500
                        $("#readonly").removeAttr("disabled").parent().removeAttr("aria-disabled");
501
                        $("#secret").removeAttr("disabled").parent().removeAttr("aria-disabled");
502
                        $("#display_checkout").removeAttr("disabled").parent().removeAttr("aria-disabled");
503
                    }
504
                })
505
                .change();
506
507
            $("#readonly")
508
                .change(function () {
509
                    if (this.checked) {
510
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
511
                        $("#hidden").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
512
                        $("#secret").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
513
                    } else {
514
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
515
                        $("#hidden").removeAttr("disabled").parent().removeAttr("aria-disabled");
516
                        $("#secret").removeAttr("disabled").parent().removeAttr("aria-disabled");
517
                    }
518
                })
519
                .change();
520
521
            $("#secret")
522
                .change(function () {
523
                    if (this.checked) {
524
                        $("#opac_editable").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
525
                        $("#opac_display").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
526
                        $("#hidden").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
527
                        $("#readony").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
528
                        $("#display_checkout").attr("disabled", true).prop("checked", false).parent().attr("aria-disabled", "true");
529
                    } else {
530
                        $("#opac_editable").removeAttr("disabled").parent().removeAttr("aria-disabled");
531
                        $("#opac_display").removeAttr("disabled").parent().removeAttr("aria-disabled");
532
                        $("#hidden").removeAttr("disabled").parent().removeAttr("aria-disabled");
533
                        $("#readonly").removeAttr("disabled").parent().removeAttr("aria-disabled");
534
                        $("#display_checkout").removeAttr("disabled").parent().removeAttr("aria-disabled");
535
                    }
536
                })
537
                .change();
462
538
463
            $("#is_date")
539
            $("#is_date")
464
                .change(function () {
540
                .change(function () {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (-34 / +40 lines)
Lines 1515-1520 Link Here
1515
                                        </legend>
1515
                                        </legend>
1516
                                        <div class="attributes_tables">
1516
                                        <div class="attributes_tables">
1517
                                            <input type="hidden" name="setting_extended_patron_attributes" value="1" />
1517
                                            <input type="hidden" name="setting_extended_patron_attributes" value="1" />
1518
                                            [% FOREACH patron_attribute IN hidden_patron_attributes %]
1519
                                                <input type="hidden" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" value="[% patron_attribute.value | html %]" />
1520
                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1521
                                            [% END %]
1518
                                            [% FOREACH pa_loo IN patron_attributes %]
1522
                                            [% FOREACH pa_loo IN patron_attributes %]
1519
                                                <ol class="attributes_table">
1523
                                                <ol class="attributes_table">
1520
                                                    <div id="aai_[% pa_loo.class | html %]">
1524
                                                    <div id="aai_[% pa_loo.class | html %]">
Lines 1522-1535 Link Here
1522
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1526
                                                            <h3 id="[% pa_loo.class | html %]_lgd">[% pa_loo.lib | html %]</h3>
1523
                                                        [% END %]
1527
                                                        [% END %]
1524
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1528
                                                        [% FOREACH patron_attribute IN pa_loo.items %]
1525
                                                            <li data-category_code="[% patron_attribute.category_code | html %]" data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]">
1529
                                                            <li
1530
                                                                data-category_code="[% patron_attribute.category_code | html %]"
1531
                                                                data-pa_code="[% patron_attribute.code | replace('[^a-zA-Z0-9_-]', '') %]"
1532
                                                                [% IF patron_attribute.readonly %]aria-readonly="true"[% END %]
1533
                                                            >
1526
                                                                [% IF patron_attribute.mandatory %]
1534
                                                                [% IF patron_attribute.mandatory %]
1527
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1535
                                                                    <label for="[% patron_attribute.form_id | html %]" class="required" required="required">[% patron_attribute.description | html %]: </label>
1528
                                                                [% ELSE %]
1536
                                                                [% ELSE %]
1529
                                                                    <label for="[% patron_attribute.form_id | html %]">[% patron_attribute.description | html %]: </label>
1537
                                                                    <label for="[% patron_attribute.form_id | html %]">[% patron_attribute.description | html %]: </label>
1530
                                                                [% END %]
1538
                                                                [% END %]
1531
                                                                [% IF ( patron_attribute.use_dropdown ) %]
1539
                                                                [% IF ( patron_attribute.use_dropdown ) %]
1532
                                                                    <select id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" [% IF patron_attribute.mandatory %]required="required"[% END %]>
1540
                                                                    <select
1541
                                                                        id="[% patron_attribute.form_id | html %]"
1542
                                                                        name="[% patron_attribute.form_id | html %]"
1543
                                                                        [% IF patron_attribute.mandatory %]required="required"[% END %][% IF patron_attribute.readonly %]disabled[% END %]
1544
                                                                    >
1533
                                                                        <option value=""></option>
1545
                                                                        <option value=""></option>
1534
                                                                        [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
1546
                                                                        [% FOREACH auth_val_loo IN patron_attribute.auth_val_loop %]
1535
                                                                            [% IF auth_val_loo.authorised_value == patron_attribute.value %]
1547
                                                                            [% IF auth_val_loo.authorised_value == patron_attribute.value %]
Lines 1539-1583 Link Here
1539
                                                                            [% END %]
1551
                                                                            [% END %]
1540
                                                                        [% END %]
1552
                                                                        [% END %]
1541
                                                                    </select>
1553
                                                                    </select>
1554
                                                                    [% IF ( patron_attribute.readonly ) %]
1555
                                                                        <input type="hidden" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" value="[% patron_attribute.value | html %]" />
1556
                                                                    [% END %]
1542
                                                                [% ELSE %]
1557
                                                                [% ELSE %]
1543
                                                                    [% IF patron_attribute.mandatory %]
1558
                                                                    [% IF patron_attribute.is_date %]
1544
                                                                        [% IF patron_attribute.is_date %]
1559
                                                                        <input
1545
                                                                            <input
1560
                                                                            type="text"
1546
                                                                                type="text"
1561
                                                                            id="[% patron_attribute.form_id | html %]"
1547
                                                                                id="[% patron_attribute.form_id | html %]"
1562
                                                                            name="[% patron_attribute.form_id | html %]"
1548
                                                                                name="[% patron_attribute.form_id | html %]"
1563
                                                                            maxlength="10"
1549
                                                                                maxlength="10"
1564
                                                                            size="10"
1550
                                                                                size="10"
1565
                                                                            value="[% patron_attribute.value | html %]"
1551
                                                                                value="[% patron_attribute.value | html %]"
1566
                                                                            class="flatpickr"
1552
                                                                                required="required"
1567
                                                                            [% IF patron_attribute.mandatory %]required="required"[% END %]
1553
                                                                                class="flatpickr"
1568
                                                                            [% IF ( patron_attribute.readonly ) %]readonly[% ELSE %]class="flatpickr"[% END %]
1554
                                                                            />
1569
                                                                        />
1555
                                                                        [% ELSE %]
1556
                                                                            <textarea rows="2" cols="30" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]" required="required">
1557
[% patron_attribute.value | html %]</textarea
1558
                                                                            >
1559
                                                                        [% END %]
1560
                                                                    [% ELSE %]
1570
                                                                    [% ELSE %]
1561
                                                                        [% IF patron_attribute.is_date %]
1571
                                                                        <textarea
1562
                                                                            <input
1572
                                                                            rows="2"
1563
                                                                                type="text"
1573
                                                                            cols="30"
1564
                                                                                id="[% patron_attribute.form_id | html %]"
1574
                                                                            id="[% patron_attribute.form_id | html %]"
1565
                                                                                name="[% patron_attribute.form_id | html %]"
1575
                                                                            name="[% patron_attribute.form_id | html %]"
1566
                                                                                maxlength="10"
1576
                                                                            [% IF patron_attribute.mandatory %]required="required"[% END %][% IF ( patron_attribute.readonly ) %]readonly[% END %]
1567
                                                                                size="10"
1577
                                                                        >
1568
                                                                                value="[% patron_attribute.value | html %]"
1578
                                                                            [% patron_attribute.value | html %]
1569
                                                                                class="flatpickr"
1579
                                                                        </textarea>
1570
                                                                            />
1571
                                                                        [% ELSE %]
1572
                                                                            <textarea rows="2" cols="30" id="[% patron_attribute.form_id | html %]" name="[% patron_attribute.form_id | html %]">[% patron_attribute.value | html %]</textarea>
1573
                                                                        [% END %]
1574
                                                                    [% END %]
1580
                                                                    [% END %]
1575
                                                                [% END # /IF ( patron_attribute.use_dropdown ) %]
1581
                                                                [% END # /IF ( patron_attribute.use_dropdown ) %]
1576
                                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1582
                                                                <input type="hidden" id="[% patron_attribute.form_id | html %]_code" name="[% patron_attribute.form_id | html %]_code" value="[% patron_attribute.code | html %]" />
1577
                                                                [% IF ( !patron_attribute.is_date ) %]
1583
                                                                [% IF ( !patron_attribute.is_date && !patron_attribute.readonly ) %]
1578
                                                                    <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
1584
                                                                    <a href="#" class="clear_attribute"><i class="fa fa-fw fa-trash-can"></i> Clear</a>
1579
                                                                [% END %]
1585
                                                                [% END %]
1580
                                                                [% IF ( patron_attribute.repeatable ) %]
1586
                                                                [% IF ( patron_attribute.repeatable && !patron_attribute.readonly ) %]
1581
                                                                    <a href="#" class="clone_attribute"><i class="fa fa-fw fa-plus"></i> New</a>
1587
                                                                    <a href="#" class="clone_attribute"><i class="fa fa-fw fa-plus"></i> New</a>
1582
                                                                [% END %]
1588
                                                                [% END %]
1583
                                                                [% IF patron_attribute.mandatory %]<span class="required">Required</span>[% END %]
1589
                                                                [% 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 359-368 Link Here
359
                                        [% FOREACH item IN attribute.items %]
359
                                        [% FOREACH item IN attribute.items %]
360
                                            <li data-pa_code="[% item.type.code | replace('[^a-zA-Z0-9_-]', '') %]">
360
                                            <li data-pa_code="[% item.type.code | replace('[^a-zA-Z0-9_-]', '') %]">
361
                                                <span class="label">[% item.type.description | html %]: </span>
361
                                                <span class="label">[% item.type.description | html %]: </span>
362
                                                [% IF item.type.is_date %]
362
                                                [% IF item.type.secret %]
363
                                                    [% item.description | $KohaDates %]
363
                                                    *****
364
                                                [% ELSE %]
364
                                                [% ELSE %]
365
                                                    [% item.description | html_line_break %]
365
                                                    [% IF item.type.is_date %]
366
                                                        [% item.description | $KohaDates %]
367
                                                    [% ELSE %]
368
                                                        [% item.description | html_line_break %]
369
                                                    [% END %]
366
                                                [% END %]
370
                                                [% END %]
367
                                            </li>
371
                                            </li>
368
                                        [% END %]
372
                                        [% END %]
(-)a/members/memberentry.pl (-12 / +26 lines)
Lines 23-29 use Modern::Perl; Link Here
23
use Try::Tiny;
23
use Try::Tiny;
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 632-638 if ( ( !$nok ) and $nodouble and ( $op eq 'cud-insert' or $op eq 'cud-save' ) ) Link Here
632
        if ( C4::Context->preference('ExtendedPatronAttributes')
634
        if ( C4::Context->preference('ExtendedPatronAttributes')
633
            and $input->param('setting_extended_patron_attributes') )
635
            and $input->param('setting_extended_patron_attributes') )
634
        {
636
        {
635
            $patron->extended_attributes($extended_patron_attributes);
637
            $patron->extended_attributes( $extended_patron_attributes, { check_editable => 1 } );
636
        }
638
        }
637
639
638
        if (
640
        if (
Lines 936-942 sub patron_attributes_form { Link Here
936
938
937
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
939
    my $library_id      = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
938
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
940
    my $attribute_types = Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
939
    if ( $attribute_types->count == 0 ) {
941
    if ( $attribute_types->count == 0
942
        || ( !$logged_in_user->is_superlibrarian && all { $_->hidden } $attribute_types->as_list ) )
943
    {
940
        $template->param( no_patron_attribute_types => 1 );
944
        $template->param( no_patron_attribute_types => 1 );
941
        return;
945
        return;
942
    }
946
    }
Lines 950-961 sub patron_attributes_form { Link Here
950
    my @attribute_loop = ();
954
    my @attribute_loop = ();
951
    my $i              = 0;
955
    my $i              = 0;
952
    my %items_by_class;
956
    my %items_by_class;
957
    my @hidden_attributes;
958
959
    my $is_superlibrarian = $logged_in_user->is_superlibrarian;
953
    while ( my ($attr_type) = $attribute_types->next ) {
960
    while ( my ($attr_type) = $attribute_types->next ) {
954
        my $entry = {
961
        my $entry = {
955
            class         => $attr_type->class(),
962
            class         => $attr_type->class(),
956
            code          => $attr_type->code(),
963
            code          => $attr_type->code(),
957
            description   => $attr_type->description(),
964
            description   => $attr_type->description(),
958
            repeatable    => $attr_type->repeatable(),
965
            repeatable    => $attr_type->repeatable(),
966
            hidden        => !$is_superlibrarian && $attr_type->hidden(),
967
            readonly      => !$is_superlibrarian && $attr_type->readonly(),
968
            secret        => !$is_superlibrarian && $attr_type->secret(),
959
            category      => $attr_type->authorised_value_category(),
969
            category      => $attr_type->authorised_value_category(),
960
            category_code => $attr_type->category_code(),
970
            category_code => $attr_type->category_code(),
961
            mandatory     => $attr_type->mandatory(),
971
            mandatory     => $attr_type->mandatory(),
Lines 966-980 sub patron_attributes_form { Link Here
966
                my $newentry = {%$entry};
976
                my $newentry = {%$entry};
967
                $newentry->{value}        = $attr->{attribute};
977
                $newentry->{value}        = $attr->{attribute};
968
                $newentry->{use_dropdown} = 0;
978
                $newentry->{use_dropdown} = 0;
969
                if ( $attr_type->authorised_value_category() ) {
970
                    $newentry->{use_dropdown} = 1;
971
                    $newentry->{auth_val_loop} =
972
                        GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
973
                }
974
                $i++;
979
                $i++;
975
                undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
976
                $newentry->{form_id} = "patron_attr_$i";
980
                $newentry->{form_id} = "patron_attr_$i";
977
                push @{ $items_by_class{ $attr_type->class() } }, $newentry;
981
                if ( !$is_superlibrarian && ( $attr_type->hidden() || $attr_type->secret() ) ) {
982
                    push @hidden_attributes, $newentry;
983
                } else {
984
                    if ( $attr_type->authorised_value_category() ) {
985
                        $newentry->{use_dropdown} = 1;
986
                        $newentry->{auth_val_loop} =
987
                            GetAuthorisedValues( $attr_type->authorised_value_category(), $attr->{attribute} );
988
                    }
989
                    undef $newentry->{value} if ( $attr_type->unique_id() && $op eq 'duplicate' );
990
                    push @{ $items_by_class{ $attr_type->class() } }, $newentry;
991
                }
978
            }
992
            }
979
        } else {
993
        } else {
980
            $i++;
994
            $i++;
Lines 997-1003 sub patron_attributes_form { Link Here
997
        };
1011
        };
998
    }
1012
    }
999
1013
1000
    $template->param( patron_attributes => \@attribute_loop );
1014
    $template->param( patron_attributes => \@attribute_loop, hidden_patron_attributes => \@hidden_attributes );
1001
1015
1002
}
1016
}
1003
1017
(-)a/members/moremember.pl (-8 / +9 lines)
Lines 27-33 Link Here
27
=cut
27
=cut
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 142-156 unless ( Koha::Patron::Categories->search_with_library_limits( { 'me.categorycod Link Here
142
}
143
}
143
144
144
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
145
if ( C4::Context->preference('ExtendedPatronAttributes') ) {
145
    my @attributes = $patron->extended_attributes->as_list;         # FIXME Must be improved!
146
    my $is_superlibrarian = $logged_in_user->is_superlibrarian;
146
    my @classes    = uniq( map { $_->type->class } @attributes );
147
    my @attributes        = $patron->extended_attributes->as_list;         # FIXME Must be improved!
148
    my @classes           = uniq( map { $_->type->class } @attributes );
147
    @classes = sort @classes;
149
    @classes = sort @classes;
148
150
149
    my @attributes_loop;
151
    my @attributes_loop;
150
    for my $class (@classes) {
152
    for my $class (@classes) {
151
        my @items;
153
        my @items;
152
        for my $attr (@attributes) {
154
        for my $attr (@attributes) {
153
            push @items, $attr if $attr->type->class eq $class;
155
            push @items, $attr if $attr->type->class eq $class && ( $is_superlibrarian || !$attr->hidden );
154
        }
156
        }
155
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
157
        my $av  = Koha::AuthorisedValues->search( { category => 'PA_CLASS', authorised_value => $class } );
156
        my $lib = $av->count ? $av->next->lib : $class;
158
        my $lib = $av->count ? $av->next->lib : $class;
Lines 165-173 if ( C4::Context->preference('ExtendedPatronAttributes') ) { Link Here
165
    $template->param( attributes_loop => \@attributes_loop );
167
    $template->param( attributes_loop => \@attributes_loop );
166
168
167
    my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
169
    my $library_id = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
168
    my $nb_of_attribute_types =
170
    my $attribute_types =
169
        Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id )->count;
171
        Koha::Patron::Attribute::Types->search_with_library_limits( {}, {}, $library_id );
170
    if ( $nb_of_attribute_types == 0 ) {
172
    if ( $attribute_types->count == 0 || ( !$is_superlibrarian && all { $_->hidden } $attribute_types->as_list ) ) {
171
        $template->param( no_patron_attribute_types => 1 );
173
        $template->param( no_patron_attribute_types => 1 );
172
    }
174
    }
173
}
175
}
174
- 

Return to bug 39453