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

(-)a/Koha/UI/Form/Builder/Biblio.pm (+372 lines)
Line 0 Link Here
1
package Koha::UI::Form::Builder::Biblio;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
use C4::Context;
20
use C4::ClassSource qw( GetClassSources );
21
use Koha::DateUtils qw( dt_from_string );
22
use Koha::ItemTypes;
23
use Koha::Libraries;
24
25
=head1 NAME
26
27
Koha::UI::Form::Builder::Biblio
28
29
Helper to build a form to add or edit a new biblio
30
31
=head1 API
32
33
=head2 Class methods
34
35
=cut
36
37
=head3 new
38
39
    my $form = Koha::UI::Form::Builder::Biblio->new(
40
        {
41
            biblionumber => $biblionumber,
42
        }
43
    );
44
45
=cut
46
47
48
sub new {
49
    my ( $class, $params ) = @_;
50
51
    my $self = {};
52
    $self->{biblionumber} = $params->{biblionumber};
53
54
    bless $self, $class;
55
    return $self;
56
}
57
58
=head3 generate_subfield_form
59
60
Generate subfield's info for given tag, subfieldtag, etc.
61
62
=cut
63
64
sub generate_subfield_form {
65
    my ($self, $params) = @_;
66
67
    my $tag = $params->{tag};
68
    my $subfield = $params->{subfield};
69
    my $value = $params->{value} // '';
70
    my $index_tag = $params->{index_tag};
71
    my $rec = $params->{record};
72
    my $hostitemnumber = $params->{hostitemnumber};
73
    my $op = $params->{op} // '';
74
    my $changed_framework = $params->{changed_framework};
75
    my $breedingid = $params->{breedingid};
76
    my $tagslib = $params->{tagslib};
77
    my $mandatory_z3950 = $params->{mandatory_z3950} // {};
78
79
    my $index_subfield = $self->create_key(); # create a specifique key for each subfield
80
81
    # Apply optional framework default value when it is a new record,
82
    # or when editing as new (duplicating a record),
83
    # or when changing a record's framework,
84
    # or when importing a record,
85
    # based on the ApplyFrameworkDefaults setting.
86
    # Substitute date parts, user name
87
    my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults');
88
    if ( $value eq '' && (
89
        ( $applydefaults =~ /new/ && !$self->{biblionumber} ) ||
90
        ( $applydefaults =~ /duplicate/ && $op eq 'duplicate' ) ||
91
        ( $applydefaults =~ /changed/ && $changed_framework ) ||
92
        ( $applydefaults =~ /imported/ && $breedingid )
93
    ) ) {
94
        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{};
95
96
        # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
97
        my $today_dt = dt_from_string;
98
        my $year = $today_dt->strftime('%Y');
99
        my $shortyear = $today_dt->strftime('%y');
100
        my $month = $today_dt->strftime('%m');
101
        my $day = $today_dt->strftime('%d');
102
        $value =~ s/<<YYYY>>/$year/g;
103
        $value =~ s/<<YY>>/$shortyear/g;
104
        $value =~ s/<<MM>>/$month/g;
105
        $value =~ s/<<DD>>/$day/g;
106
        # And <<USER>> with surname (?)
107
        my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
108
        $value=~s/<<USER>>/$username/g;
109
    }
110
111
    my $dbh = C4::Context->dbh;
112
113
    # map '@' as "subfield" label for fixed fields
114
    # to something that's allowed in a div id.
115
    my $id_subfield = $subfield;
116
    $id_subfield = "00" if $id_subfield eq "@";
117
118
    my %subfield_data = (
119
        tag        => $tag,
120
        subfield   => $id_subfield,
121
        marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
122
        tag_mandatory  => $tagslib->{$tag}->{mandatory},
123
        mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
124
        important      => $tagslib->{$tag}->{$subfield}->{important},
125
        repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
126
        kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
127
        index          => $index_tag,
128
        id             => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
129
        value          => $value,
130
        maxlength      => $tagslib->{$tag}->{$subfield}->{maxlength},
131
        random         => $self->create_key(),
132
    );
133
134
    if (exists $mandatory_z3950->{$tag.$subfield}){
135
        $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
136
    }
137
    # Subfield is hidden depending of hidden and mandatory flag, and is always
138
    # shown if it contains anything or if its field is mandatory or important.
139
    my $tdef = $tagslib->{$tag};
140
    $subfield_data{visibility} = "display:none;"
141
        if $tdef->{$subfield}->{hidden} % 2 == 1 &&
142
           $value eq '' &&
143
           !$tdef->{$subfield}->{mandatory} &&
144
           !$tdef->{mandatory} &&
145
           !$tdef->{$subfield}->{important} &&
146
           !$tdef->{important};
147
    # expand all subfields of 773 if there is a host item provided in the input
148
    $subfield_data{visibility} = '' if ($tag eq '773' and $hostitemnumber);
149
150
151
    # it's an authorised field
152
    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
153
        $subfield_data{marc_value} = $self->build_authorized_values_list(
154
            {
155
                tag => $tag,
156
                subfield => $subfield,
157
                value => $value,
158
                index_tag => $index_tag,
159
                index_subfield => $index_subfield,
160
                tagslib => $tagslib,
161
            }
162
        );
163
    }
164
    # it's a subfield $9 linking to an authority record - see bug 2206 and 28022
165
    elsif ($subfield eq "9" and
166
           exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
167
           defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
168
           $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and
169
           $tagslib->{$tag}->{'a'}->{hidden} > -4 and
170
           $tagslib->{$tag}->{'a'}->{hidden} < 5) {
171
        $subfield_data{marc_value} = {
172
            type      => 'text',
173
            id        => $subfield_data{id},
174
            name      => $subfield_data{id},
175
            value     => $value,
176
            size      => 5,
177
            maxlength => $subfield_data{maxlength},
178
            readonly  => 1,
179
        };
180
181
    # it's a thesaurus / authority field
182
    }
183
    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
184
        # when authorities auto-creation is allowed, do not set readonly
185
        my $is_readonly = C4::Context->preference('RequireChoosingExistingAuthority');
186
187
        $subfield_data{marc_value} = {
188
            type      => 'text',
189
            id        => $subfield_data{id},
190
            name      => $subfield_data{id},
191
            value     => $value,
192
            size      => 67,
193
            maxlength => $subfield_data{maxlength},
194
            readonly  => ($is_readonly) ? 1 : 0,
195
            authtype  => $tagslib->{$tag}->{$subfield}->{authtypecode},
196
        };
197
198
    # it's a plugin field
199
    } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
200
        require Koha::FrameworkPlugin;
201
        my $plugin = Koha::FrameworkPlugin->new( {
202
            name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
203
        });
204
        my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
205
            id => $subfield_data{id} };
206
        $plugin->build( $pars );
207
        if( !$plugin->errstr ) {
208
            $subfield_data{marc_value} = {
209
                type           => 'text_complex',
210
                id             => $subfield_data{id},
211
                name           => $subfield_data{id},
212
                value          => $value,
213
                size           => 67,
214
                maxlength      => $subfield_data{maxlength},
215
                javascript     => $plugin->javascript,
216
                plugin         => $plugin->name,
217
                noclick        => $plugin->noclick,
218
            };
219
        } else {
220
            warn $plugin->errstr;
221
            # supply default input form
222
            $subfield_data{marc_value} = {
223
                type      => 'text',
224
                id        => $subfield_data{id},
225
                name      => $subfield_data{id},
226
                value     => $value,
227
                size      => 67,
228
                maxlength => $subfield_data{maxlength},
229
                readonly  => 0,
230
            };
231
        }
232
233
    # it's an hidden field
234
    } elsif ( $tag eq '' ) {
235
        $subfield_data{marc_value} = {
236
            type      => 'hidden',
237
            id        => $subfield_data{id},
238
            name      => $subfield_data{id},
239
            value     => $value,
240
            size      => 67,
241
            maxlength => $subfield_data{maxlength},
242
        };
243
244
    }
245
    else {
246
        # it's a standard field
247
        if (
248
            length($value) > 100
249
            or
250
            ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
251
                and $tag < 400 && $subfield eq 'a' )
252
            or (    $tag >= 500
253
                and $tag < 600
254
                && C4::Context->preference("marcflavour") eq "MARC21" )
255
          )
256
        {
257
            $subfield_data{marc_value} = {
258
                type      => 'textarea',
259
                id        => $subfield_data{id},
260
                name      => $subfield_data{id},
261
                value     => $value,
262
            };
263
264
        }
265
        else {
266
            $subfield_data{marc_value} = {
267
                type      => 'text',
268
                id        => $subfield_data{id},
269
                name      => $subfield_data{id},
270
                value     => $value,
271
                size      => 67,
272
                maxlength => $subfield_data{maxlength},
273
                readonly  => 0,
274
            };
275
276
        }
277
    }
278
    $subfield_data{'index_subfield'} = $index_subfield;
279
280
    return \%subfield_data;
281
}
282
283
sub build_authorized_values_list {
284
    my ($self, $params) = @_;
285
286
    my $tag = $params->{tag};
287
    my $subfield = $params->{subfield};
288
    my $value = $params->{value};
289
    my $index_tag = $params->{index_tag};
290
    my $index_subfield = $params->{index_subfield};
291
    my $tagslib = $params->{tagslib};
292
293
    my @authorised_values;
294
    my %authorised_lib;
295
296
    # builds list, depending on authorised value...
297
298
    #---- branch
299
    my $category = $tagslib->{$tag}->{$subfield}->{authorised_value};
300
    if ( $category eq "branches" ) {
301
        my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
302
        while ( my $l = $libraries->next ) {
303
            push @authorised_values, $l->branchcode;
304
            $authorised_lib{$l->branchcode} = $l->branchname;
305
        }
306
    }
307
    elsif ( $category eq "itemtypes" ) {
308
        push @authorised_values, "";
309
310
        my $itemtype;
311
        my $itemtypes = Koha::ItemTypes->search_with_localization;
312
        while ( $itemtype = $itemtypes->next ) {
313
            push @authorised_values, $itemtype->itemtype;
314
            $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
315
        }
316
        $value = $itemtype unless ($value);
317
    }
318
    elsif ( $category eq "cn_source" ) {
319
        push @authorised_values, "";
320
321
        my $class_sources = GetClassSources();
322
323
        my $default_source = C4::Context->preference("DefaultClassificationSource");
324
325
        foreach my $class_source (sort keys %$class_sources) {
326
            next unless $class_sources->{$class_source}->{'used'} or
327
                        ($value and $class_source eq $value) or
328
                        ($class_source eq $default_source);
329
            push @authorised_values, $class_source;
330
            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
331
        }
332
        $value = $default_source unless $value;
333
    }
334
    else {
335
        my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{branch} : '';
336
        my $query = 'SELECT authorised_value, lib FROM authorised_values';
337
        $query .= ' LEFT JOIN authorised_values_branches ON ( id = av_id )' if $branch_limit;
338
        $query .= ' WHERE category = ?';
339
        $query .= ' AND ( branchcode = ? OR branchcode IS NULL )' if $branch_limit;
340
        $query .= ' GROUP BY authorised_value,lib ORDER BY lib, lib_opac';
341
        my $authorised_values_sth = C4::Context->dbh->prepare($query);
342
343
        $authorised_values_sth->execute(
344
            $tagslib->{$tag}->{$subfield}->{authorised_value},
345
            $branch_limit ? $branch_limit : (),
346
        );
347
348
        push @authorised_values, "";
349
350
        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
351
            push @authorised_values, $value;
352
            $authorised_lib{$value} = $lib;
353
        }
354
    }
355
356
    return {
357
        type     => 'select',
358
        id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
359
        name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
360
        default  => $value,
361
        values   => \@authorised_values,
362
        labels   => \%authorised_lib,
363
        ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ),
364
    };
365
366
}
367
368
sub create_key {
369
    return int(rand(1000000));
370
}
371
372
1;
(-)a/acqui/neworderempty.pl (-32 / +28 lines)
Lines 99-104 use Koha::ItemTypes; Link Here
99
use Koha::Patrons;
99
use Koha::Patrons;
100
use Koha::RecordProcessor;
100
use Koha::RecordProcessor;
101
use Koha::Subscriptions;
101
use Koha::Subscriptions;
102
use Koha::UI::Form::Builder::Biblio;
102
103
103
our $input           = CGI->new;
104
our $input           = CGI->new;
104
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
105
my $booksellerid    = $input->param('booksellerid');	# FIXME: else ERROR!
Lines 207-215 if ( not $ordernumber ) { # create order Link Here
207
    }
208
    }
208
209
209
    if ( not $biblionumber and Koha::BiblioFrameworks->find('ACQ') ) {
210
    if ( not $biblionumber and Koha::BiblioFrameworks->find('ACQ') ) {
211
        my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new();
210
        foreach my $tag ( sort keys %{$tagslib} ) {
212
        foreach my $tag ( sort keys %{$tagslib} ) {
211
            next if $tag eq '';
213
            next if $tag eq '';
212
            next if $tag eq $itemnumber_tag;    # skip items fields
214
            next if $tag eq $itemnumber_tag;    # skip items fields
215
            my $index_tag = int(rand(1000000));
213
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
216
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
214
                my $mss = $tagslib->{$tag}{$subfield};
217
                my $mss = $tagslib->{$tag}{$subfield};
215
                next if IsMarcStructureInternal($mss);
218
                next if IsMarcStructureInternal($mss);
Lines 241-272 if ( not $ordernumber ) { # create order Link Here
241
                    }
244
                    }
242
                }
245
                }
243
246
244
                if ( $value ) {
247
                push @catalog_details, $biblio_form_builder->generate_subfield_form(
245
248
                    {
246
                    # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
249
                        tag => $tag,
247
                    my $today_dt = dt_from_string;
250
                        subfield => $subfield,
248
                    my $year     = $today_dt->strftime('%Y');
251
                        value => $value,
249
                    my $shortyear = $today_dt->strftime('%y');
252
                        index_tag => $index_tag,
250
                    my $month    = $today_dt->strftime('%m');
253
                        tagslib => $tagslib,
251
                    my $day      = $today_dt->strftime('%d');
254
                    }
252
                    $value =~ s/<<YYYY>>/$year/g;
255
                );
253
                    $value =~ s/<<YY>>/$shortyear/g;
254
                    $value =~ s/<<MM>>/$month/g;
255
                    $value =~ s/<<DD>>/$day/g;
256
257
                    # And <<USER>> with surname (?)
258
                    my $username =
259
                      (   C4::Context->userenv
260
                        ? C4::Context->userenv->{'surname'}
261
                        : "superlibrarian" );
262
                    $value =~ s/<<USER>>/$username/g;
263
                }
264
                push @catalog_details, {
265
                    tag      => $tag,
266
                    subfield => $subfield,
267
                    %$mss,    # Do we need plugins support (?)
268
                    value => $value,
269
                };
270
            }
256
            }
271
        }
257
        }
272
    }
258
    }
Lines 298-307 if ( not $ordernumber or $biblionumber ) { Link Here
298
    if ( C4::Context->preference('UseACQFrameworkForBiblioRecords') ) {
284
    if ( C4::Context->preference('UseACQFrameworkForBiblioRecords') ) {
299
        my $biblio = Koha::Biblios->find($biblionumber);
285
        my $biblio = Koha::Biblios->find($biblionumber);
300
        my $record = $biblio ? $biblio->metadata->record : undef;
286
        my $record = $biblio ? $biblio->metadata->record : undef;
287
        my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new(
288
            {
289
                biblionumber => $biblionumber,
290
            }
291
        );
301
        foreach my $tag ( sort keys %{$tagslib} ) {
292
        foreach my $tag ( sort keys %{$tagslib} ) {
302
            next if $tag eq '';
293
            next if $tag eq '';
303
            next if $tag eq $itemnumber_tag; # skip items fields
294
            next if $tag eq $itemnumber_tag; # skip items fields
304
            my @fields = $biblionumber ? $record->field($tag) : ();
295
            my @fields = $biblionumber ? $record->field($tag) : ();
296
            my $index_tag = int(rand(1000000));
305
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
297
            foreach my $subfield ( sort keys %{ $tagslib->{$tag} } ) {
306
                my $mss = $tagslib->{$tag}{$subfield};
298
                my $mss = $tagslib->{$tag}{$subfield};
307
                next if IsMarcStructureInternal($mss);
299
                next if IsMarcStructureInternal($mss);
Lines 309-320 if ( not $ordernumber or $biblionumber ) { Link Here
309
                # We only need to display the values
301
                # We only need to display the values
310
                my $value = join '; ', map { $tag < 10 ? $_->data : $_->subfield( $subfield ) } @fields;
302
                my $value = join '; ', map { $tag < 10 ? $_->data : $_->subfield( $subfield ) } @fields;
311
                if ( $value ) {
303
                if ( $value ) {
312
                    push @catalog_details, {
304
                    push @catalog_details, $biblio_form_builder->generate_subfield_form(
313
                        tag => $tag,
305
                        {
314
                        subfield => $subfield,
306
                            tag => $tag,
315
                        %$mss,
307
                            subfield => $subfield,
316
                        value => $value,
308
                            value => $value,
317
                    };
309
                            index_tag => $index_tag,
310
                            record => $record,
311
                            tagslib => $tagslib,
312
                        }
313
                    );
318
                }
314
                }
319
            }
315
            }
320
        }
316
        }
(-)a/cataloguing/addbiblio.pl (-295 / +55 lines)
Lines 52-57 use Koha::Libraries; Link Here
52
52
53
use Koha::BiblioFrameworks;
53
use Koha::BiblioFrameworks;
54
use Koha::Patrons;
54
use Koha::Patrons;
55
use Koha::UI::Form::Builder::Biblio;
55
56
56
use MARC::File::USMARC;
57
use MARC::File::USMARC;
57
use MARC::File::XML;
58
use MARC::File::XML;
Lines 171-252 sub MARCfindbreeding { Link Here
171
    return -1;
172
    return -1;
172
}
173
}
173
174
174
=head2 build_authorized_values_list
175
176
=cut
177
178
sub build_authorized_values_list {
179
    my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
180
181
    my @authorised_values;
182
    my %authorised_lib;
183
184
    # builds list, depending on authorised value...
185
186
    #---- branch
187
    my $category = $tagslib->{$tag}->{$subfield}->{authorised_value};
188
    if ( $category eq "branches" ) {
189
        my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
190
        while ( my $l = $libraries->next ) {
191
            push @authorised_values, $l->branchcode;;
192
            $authorised_lib{$l->branchcode} = $l->branchname;
193
        }
194
    }
195
    elsif ( $category eq "itemtypes" ) {
196
        push @authorised_values, "";
197
198
        my $itemtype;
199
        my $itemtypes = Koha::ItemTypes->search_with_localization;
200
        while ( $itemtype = $itemtypes->next ) {
201
            push @authorised_values, $itemtype->itemtype;
202
            $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
203
        }
204
        $value = $itemtype unless ($value);
205
    }
206
    elsif ( $category eq "cn_source" ) {
207
        push @authorised_values, "";
208
209
        my $class_sources = GetClassSources();
210
211
        my $default_source = C4::Context->preference("DefaultClassificationSource");
212
213
        foreach my $class_source (sort keys %$class_sources) {
214
            next unless $class_sources->{$class_source}->{'used'} or
215
                        ($value and $class_source eq $value) or
216
                        ($class_source eq $default_source);
217
            push @authorised_values, $class_source;
218
            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
219
        }
220
        $value = $default_source unless $value;
221
    }
222
    else {
223
        my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
224
        $authorised_values_sth->execute(
225
            $tagslib->{$tag}->{$subfield}->{authorised_value},
226
            $branch_limit ? $branch_limit : (),
227
        );
228
229
        push @authorised_values, "";
230
231
        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
232
            push @authorised_values, $value;
233
            $authorised_lib{$value} = $lib;
234
        }
235
    }
236
    $authorised_values_sth->finish;
237
238
    return {
239
        type     => 'select',
240
        id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
241
        name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
242
        default  => $value,
243
        values   => \@authorised_values,
244
        labels   => \%authorised_lib,
245
        ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ),
246
    };
247
248
}
249
250
=head2 CreateKey
175
=head2 CreateKey
251
176
252
    Create a random value to set it into the input name
177
    Create a random value to set it into the input name
Lines 281-493 sub GetMandatoryFieldZ3950 { Link Here
281
    };
206
    };
282
}
207
}
283
208
284
=head2 create_input
285
286
 builds the <input ...> entry for a subfield.
287
288
=cut
289
290
sub create_input {
291
    my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth,$cgi ) = @_;
292
293
    my $index_subfield = CreateKey(); # create a specifique key for each subfield
294
295
    # Apply optional framework default value when it is a new record,
296
    # or when editing as new (duplicating a record),
297
    # or when changing a record's framework,
298
    # or when importing a record,
299
    # based on the ApplyFrameworkDefaults setting.
300
    # Substitute date parts, user name
301
    my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults');
302
    if ( $value eq '' && (
303
        ( $applydefaults =~ /new/ && !$cgi->param('biblionumber') ) ||
304
        ( $applydefaults =~ /duplicate/ && $cgi->param('op') eq 'duplicate' ) ||
305
        ( $applydefaults =~ /changed/ && $cgi->param('changed_framework') ) ||
306
        ( $applydefaults =~ /imported/ && $cgi->param('breedingid') )
307
    ) ) {
308
        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{};
309
310
        # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
311
        my $today_dt = dt_from_string;
312
        my $year = $today_dt->strftime('%Y');
313
        my $shortyear = $today_dt->strftime('%y');
314
        my $month = $today_dt->strftime('%m');
315
        my $day = $today_dt->strftime('%d');
316
        $value =~ s/<<YYYY>>/$year/g;
317
        $value =~ s/<<YY>>/$shortyear/g;
318
        $value =~ s/<<MM>>/$month/g;
319
        $value =~ s/<<DD>>/$day/g;
320
        # And <<USER>> with surname (?)
321
        my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
322
        $value=~s/<<USER>>/$username/g;
323
    }
324
325
    my $dbh = C4::Context->dbh;
326
327
    # map '@' as "subfield" label for fixed fields
328
    # to something that's allowed in a div id.
329
    my $id_subfield = $subfield;
330
    $id_subfield = "00" if $id_subfield eq "@";
331
332
    my %subfield_data = (
333
        tag        => $tag,
334
        subfield   => $id_subfield,
335
        marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
336
        tag_mandatory  => $tagslib->{$tag}->{mandatory},
337
        mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
338
        important      => $tagslib->{$tag}->{$subfield}->{important},
339
        repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
340
        kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
341
        index          => $index_tag,
342
        id             => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
343
        value          => $value,
344
        maxlength      => $tagslib->{$tag}->{$subfield}->{maxlength},
345
        random         => CreateKey(),
346
    );
347
348
    if(exists $mandatory_z3950->{$tag.$subfield}){
349
        $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
350
    }
351
    # Subfield is hidden depending of hidden and mandatory flag, and is always
352
    # shown if it contains anything or if its field is mandatory or important.
353
    my $tdef = $tagslib->{$tag};
354
    $subfield_data{visibility} = "display:none;"
355
        if $tdef->{$subfield}->{hidden} % 2 == 1 &&
356
           $value eq '' &&
357
           !$tdef->{$subfield}->{mandatory} &&
358
           !$tdef->{mandatory} &&
359
           !$tdef->{$subfield}->{important} &&
360
           !$tdef->{important};
361
    # expand all subfields of 773 if there is a host item provided in the input
362
    $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
363
364
365
    # it's an authorised field
366
    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
367
        $subfield_data{marc_value} =
368
          build_authorized_values_list( $tag, $subfield, $value, $dbh,
369
            $authorised_values_sth,$index_tag,$index_subfield );
370
371
    # it's a subfield $9 linking to an authority record - see bug 2206 and 28022
372
    }
373
    elsif ($subfield eq "9" and
374
           exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
375
           defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
376
           $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and
377
           $tagslib->{$tag}->{'a'}->{hidden} > -4 and
378
           $tagslib->{$tag}->{'a'}->{hidden} < 5) {
379
        $subfield_data{marc_value} = {
380
            type      => 'text',
381
            id        => $subfield_data{id},
382
            name      => $subfield_data{id},
383
            value     => $value,
384
            size      => 5,
385
            maxlength => $subfield_data{maxlength},
386
            readonly  => 1,
387
        };
388
389
    # it's a thesaurus / authority field
390
    }
391
    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
392
        # when authorities auto-creation is allowed, do not set readonly
393
        my $is_readonly = C4::Context->preference("RequireChoosingExistingAuthority");
394
395
        $subfield_data{marc_value} = {
396
            type      => 'text',
397
            id        => $subfield_data{id},
398
            name      => $subfield_data{id},
399
            value     => $value,
400
            size      => 67,
401
            maxlength => $subfield_data{maxlength},
402
            readonly  => ($is_readonly) ? 1 : 0,
403
            authtype  => $tagslib->{$tag}->{$subfield}->{authtypecode},
404
        };
405
406
    # it's a plugin field
407
    } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
408
        require Koha::FrameworkPlugin;
409
        my $plugin = Koha::FrameworkPlugin->new( {
410
            name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
411
        });
412
        my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
413
            id => $subfield_data{id} };
414
        $plugin->build( $pars );
415
        if( !$plugin->errstr ) {
416
            $subfield_data{marc_value} = {
417
                type           => 'text_complex',
418
                id             => $subfield_data{id},
419
                name           => $subfield_data{id},
420
                value          => $value,
421
                size           => 67,
422
                maxlength      => $subfield_data{maxlength},
423
                javascript     => $plugin->javascript,
424
                plugin         => $plugin->name,
425
                noclick        => $plugin->noclick,
426
            };
427
        } else {
428
            warn $plugin->errstr;
429
            # supply default input form
430
            $subfield_data{marc_value} = {
431
                type      => 'text',
432
                id        => $subfield_data{id},
433
                name      => $subfield_data{id},
434
                value     => $value,
435
                size      => 67,
436
                maxlength => $subfield_data{maxlength},
437
                readonly  => 0,
438
            };
439
        }
440
441
    # it's an hidden field
442
    } elsif ( $tag eq '' ) {
443
        $subfield_data{marc_value} = {
444
            type      => 'hidden',
445
            id        => $subfield_data{id},
446
            name      => $subfield_data{id},
447
            value     => $value,
448
            size      => 67,
449
            maxlength => $subfield_data{maxlength},
450
        };
451
452
    }
453
    else {
454
        # it's a standard field
455
        if (
456
            length($value) > 100
457
            or
458
            ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
459
                and $tag < 400 && $subfield eq 'a' )
460
            or (    $tag >= 500
461
                and $tag < 600
462
                && C4::Context->preference("marcflavour") eq "MARC21" )
463
          )
464
        {
465
            $subfield_data{marc_value} = {
466
                type      => 'textarea',
467
                id        => $subfield_data{id},
468
                name      => $subfield_data{id},
469
                value     => $value,
470
            };
471
472
        }
473
        else {
474
            $subfield_data{marc_value} = {
475
                type      => 'text',
476
                id        => $subfield_data{id},
477
                name      => $subfield_data{id},
478
                value     => $value,
479
                size      => 67,
480
                maxlength => $subfield_data{maxlength},
481
                readonly  => 0,
482
            };
483
484
        }
485
    }
486
    $subfield_data{'index_subfield'} = $index_subfield;
487
    return \%subfield_data;
488
}
489
490
491
=head2 format_indicator
209
=head2 format_indicator
492
210
493
Translate indicator value for output form - specifically, map
211
Translate indicator value for output form - specifically, map
Lines 542-547 sub build_tabs { Link Here
542
    if($max_num_tab >= 9){
260
    if($max_num_tab >= 9){
543
        $max_num_tab = 9;
261
        $max_num_tab = 9;
544
    }
262
    }
263
264
    my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new(
265
        {
266
            biblionumber => scalar $input->param('biblionumber'),
267
        }
268
    );
269
545
    # loop through each tab 0 through 9
270
    # loop through each tab 0 through 9
546
    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
271
    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
547
        my @loop_data = (); #innerloop in the template.
272
        my @loop_data = (); #innerloop in the template.
Lines 582-590 sub build_tabs { Link Here
582
                            'biblio.biblionumber' );
307
                            'biblio.biblionumber' );
583
                        push(
308
                        push(
584
                            @subfields_data,
309
                            @subfields_data,
585
                            &create_input(
310
                            $biblio_form_builder->generate_subfield_form(
586
                                $tag, $subfield, $value, $index_tag, $record,
311
                                {
587
                                $authorised_values_sth,$input
312
                                    tag => $tag,
313
                                    subfield => $subfield,
314
                                    value => $value,
315
                                    index_tag => $index_tag,
316
                                    record => $record,
317
                                    hostitemnumber => scalar $input->param('hostitemnumber'),
318
                                    op => scalar $input->param('op'),
319
                                    changed_framework => scalar $input->param('changed_framework'),
320
                                    breedingid => scalar $input->param('breedingid'),
321
                                    tagslib => $tagslib,
322
                                    mandatory_z3950 => $mandatory_z3950,
323
                                }
588
                            )
324
                            )
589
                        );
325
                        );
590
                    }
326
                    }
Lines 597-605 sub build_tabs { Link Here
597
                            next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
333
                            next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
598
                            push(
334
                            push(
599
                                @subfields_data,
335
                                @subfields_data,
600
                                &create_input(
336
                                $biblio_form_builder->generate_subfield_form(
601
                                    $tag, $subfield, $value, $index_tag,
337
                                    {
602
                                    $record, $authorised_values_sth,$input
338
                                        tag => $tag,
339
                                        subfield => $subfield,
340
                                        value => $value,
341
                                        index_tag => $index_tag,
342
                                        record => $record,
343
                                        hostitemnumber => scalar $input->param('hostitemnumber'),
344
                                        tagslib => $tagslib,
345
                                        mandatory_z3950 => $mandatory_z3950,
346
                                    }
603
                                )
347
                                )
604
                            );
348
                            );
605
                        }
349
                        }
Lines 627-635 sub build_tabs { Link Here
627
                        next if ( defined( $field->subfield($subfield) ) );
371
                        next if ( defined( $field->subfield($subfield) ) );
628
                        push(
372
                        push(
629
                            @subfields_data,
373
                            @subfields_data,
630
                            &create_input(
374
                            $biblio_form_builder->generate_subfield_form(
631
                                $tag, $subfield, '', $index_tag, $record,
375
                                {
632
                                $authorised_values_sth,$input
376
                                    tag => $tag,
377
                                    subfield => $subfield,
378
                                    value => '',
379
                                    index_tag => $index_tag,
380
                                    record => $record,
381
                                    hostitemnumber => scalar $input->param('hostitemnumber'),
382
                                    tagslib => $tagslib,
383
                                    mandatory_z3950 => $mandatory_z3950,
384
                                }
633
                            )
385
                            )
634
                        );
386
                        );
635
                    }
387
                    }
Lines 683-691 sub build_tabs { Link Here
683
                      if ( $subfield->{tab} ne $tabloop );
435
                      if ( $subfield->{tab} ne $tabloop );
684
			push(
436
			push(
685
                        @subfields_data,
437
                        @subfields_data,
686
                        &create_input(
438
                        $biblio_form_builder->generate_subfield_form(
687
                            $tag, $subfield->{subfield}, '', $index_tag, $record,
439
                            {
688
                            $authorised_values_sth,$input
440
                                tag => $tag,
441
                                subfield => $subfield->{subfield},
442
                                value => '',
443
                                index_tag => $index_tag,
444
                                record => $record,
445
                                hostitemnumber => scalar $input->param('hostitemnumber'),
446
                                tagslib => $tagslib,
447
                                mandatory_z3950 => $mandatory_z3950,
448
                            }
689
                        )
449
                        )
690
                    );
450
                    );
691
                }
451
                }
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-219 / +225 lines)
Lines 4-10 Link Here
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% USE Price %]
5
[% USE Price %]
6
[% USE ItemTypes %]
6
[% USE ItemTypes %]
7
[% SET footerjs = 1 %]
8
[% INCLUDE 'doc-head-open.inc' %]
7
[% INCLUDE 'doc-head-open.inc' %]
9
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
8
<title>[% IF ( ordernumber ) %]Modify order details (line #[% ordernumber | html %])[% ELSE %]New order[% END %] &rsaquo; Basket [% basketno | html %] &rsaquo; Acquisitions &rsaquo; Koha</title>
10
[% INCLUDE 'doc-head-close.inc' %]
9
[% INCLUDE 'doc-head-close.inc' %]
Lines 35-40 Link Here
35
        }
34
        }
36
    </style>
35
    </style>
37
[% END %]
36
[% END %]
37
    [% Asset.js("js/acquisitions-menu.js") | $raw %]
38
    [% Asset.js("js/acq.js") | $raw %]
39
    [% Asset.js("js/additem.js") | $raw %]
40
    [% Asset.js("js/cataloging.js") | $raw %]
41
    [% INCLUDE 'calendar.inc' %]
42
    [% INCLUDE 'select2.inc' %]
43
    <script>
44
        actTotal = "";
45
46
        function Check(ff) {
47
            [% IF (AcqCreateItemOrdering) %]
48
                // Remove last itemblock if it is not in items_list
49
                var lastitemblock = $("#outeritemblock > div:last");
50
                var tobedeleted = true;
51
                var listitems = $("#items_list tr");
52
                $(listitems).each(function(){
53
                    if($(this).attr('idblock') == $(lastitemblock).attr('id')){
54
                        tobedeleted = false;
55
                    }
56
                });
57
                if(tobedeleted){
58
                    $(lastitemblock).remove();
59
                }
60
            [% END %]
61
62
            var ok=0;
63
            var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
64
65
            _alertString +="-------------------------------------------------------------------\n\n";
66
67
            if(isNull(ff.budget_id,1)){
68
                ok=1;
69
                _alertString += "\n- "+ _("You must select a fund");
70
            }
71
72
            if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
73
                ok=1;
74
                            _alertString += "\n- " + _("Quantity must be greater than '0'");
75
            }
76
77
            if (!(isNum(ff.listprice,0))){
78
                ok=1;
79
                            _alertString += "\n- " + _("Vendor price must be a number");
80
            }
81
82
            if (!(isNum(ff.total,0))){
83
                ok=1;
84
                            _alertString += "\n- " + _("Total must be a number");
85
            }
86
87
            if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
88
                ok=1;
89
                _alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
90
            }
91
92
            if ( ff.field_value ) {
93
                var empty_item_mandatory = CheckMandatorySubfields(ff);
94
                if (empty_item_mandatory > 0) {
95
                    ok = 1;
96
                    _alertString +=
97
                        "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
98
                }
99
100
            }
101
102
            if (ok) {
103
                alert(_alertString);
104
                [% IF (AcqCreateItemOrdering) %]
105
                    if(tobedeleted) {
106
                        $(lastitemblock).appendTo('#outeritemblock');
107
                    }
108
                [% END %]
109
                return false;
110
            }
111
112
            [% IF (AcqCreateItemOrdering) %]
113
                if(check_additem('[% UniqueItemFields | html %]') == false) {
114
                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
115
                    if(tobedeleted) {
116
                        $(lastitemblock).appendTo('#outeritemblock');
117
                    }
118
                    return false;
119
                }
120
            [% END %]
121
        }
122
123
        $(document).ready(function(){
124
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
125
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
126
            [% END %]
127
128
            [% IF ( suggestionid ) %]updateCosts();[% END %]
129
            $("#quantity").change(function() {
130
                updateCosts();
131
            });
132
133
            //We apply the fonction only for modify option
134
            [% IF ( quantityrec and not subscriptionid ) %]
135
                [% IF ( acqcreate ) %]
136
                    $('#quantity').blur(function(){
137
                        // if user decreases the quantity
138
                        if($(this).val() < [% quantityrec | html %]){
139
                            alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
140
                            return true;
141
                        } else {
142
                            // if user increases the quantity
143
                            alert(_("You can't add a new item, please create a new order line"));
144
                            // and we replace the original value
145
                            $(this).val([% quantityrec | html %])
146
                            updateCosts(); // blur is invoked after change which updated values
147
                            return false;
148
                        }
149
                    });
150
                [% END %]
151
            [% END %]
152
153
            //keep a copy of all budgets before removing the inactives
154
            disabledBudgetsCopy = $('#budget_id').html();
155
            $('#budget_id .b_inactive').remove();
156
157
            $('#showallbudgets').click(function() {
158
                if ($(this).is(":checked")) {
159
                    $('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
160
                }
161
                else {
162
                    $('#budget_id .b_inactive').remove();
163
                }
164
            });
165
166
            $("#budget_id").change(function(){
167
                var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
168
                var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
169
                var sort1 = $(destination_sort1).val() || "";
170
                if ( destination_sort1.length < 1 ) {
171
                    destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
172
                }
173
                var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
174
                var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
175
                var sort2 = $(destination_sort2).val() || "";
176
                if ( destination_sort2.length < 1 ) {
177
                    destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
178
                }
179
                getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
180
                getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
181
            });
182
            $("#budget_id").change();
183
        });
184
185
        function UserSearchPopup(f) {
186
            window.open(
187
                "/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
188
                'UserSearchPopup',
189
                'width=1024, height=768, scrollbars=yes, toolbar=no,'
190
             );
191
        }
192
193
        function add_user(borrowernumber, borrowername) {
194
            var ids = $("#users_ids").val();
195
            if(ids.length > 0) {
196
                ids = ids.split(':');
197
            } else {
198
                ids = new Array;
199
            }
200
        if (ids.indexOf(borrowernumber.toString()) < 0) {
201
                ids.push(borrowernumber);
202
                $("#users_ids").val(ids.join(':'));
203
                var li = '<li id="user_'+borrowernumber+'">'+borrowername
204
                    + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
205
                    + _("Delete user") + '</a>]</li>';
206
                $("#users_names").append(li);
207
                return 0;
208
            }
209
            return -1;
210
        }
211
212
        function del_user(borrowernumber) {
213
            $("#user_"+borrowernumber).remove();
214
            var ids = $("#users_ids").val().split(':');
215
            ids.splice(ids.indexOf(borrowernumber.toString()), 1);
216
            $("#users_ids").val(ids.join(':'));
217
        }
218
    </script>
219
[% Asset.css("css/addbiblio.css") | $raw %]
38
</head>
220
</head>
39
221
40
<body id="acq_neworderempty" class="acq">
222
<body id="acq_neworderempty" class="acq">
Lines 274-294 Link Here
274
            [% IF biblionumber %]
456
            [% IF biblionumber %]
275
                <ol>
457
                <ol>
276
                    [% FOREACH field IN catalog_details %]
458
                    [% FOREACH field IN catalog_details %]
277
                        <li>
459
                        <li class="subfield_line">
278
                            <div class="subfield_line">
460
                            <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
279
                                <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
461
                            [% field.value | html %]
280
                                [% field.value | html %]
281
                            </div>
282
                        </li>
462
                        </li>
283
                    [% END %]
463
                    [% END %]
284
                </ol>
464
                </ol>
285
            [% ELSE %]
465
            [% ELSE %]
286
                <ol>
466
                <ol>
287
                    [% FOREACH field IN catalog_details %]
467
                    [% FOREACH field IN catalog_details %]
288
                        <li>
468
                        <li class="subfield_line">
289
                            <div class="subfield_line">
469
                            [% PROCESS display_subfield field=field %]
290
                                [% PROCESS display_subfield field=field %]
291
                            </div>
292
                        </li>
470
                        </li>
293
                    [% END %]
471
                    [% END %]
294
                </ol>
472
                </ol>
Lines 574-799 Link Here
574
</div> <!-- /.row -->
752
</div> <!-- /.row -->
575
753
576
[% MACRO jsinclude BLOCK %]
754
[% MACRO jsinclude BLOCK %]
577
    [% Asset.js("js/acquisitions-menu.js") | $raw %]
578
    [% Asset.js("js/acq.js") | $raw %]
579
    [% Asset.js("js/additem.js") | $raw %]
580
    [% Asset.js("js/cataloging.js") | $raw %]
581
    [% INCLUDE 'calendar.inc' %]
582
    [% INCLUDE 'select2.inc' %]
583
    <script>
584
        actTotal = "";
585
586
        function Check(ff) {
587
            [% IF (AcqCreateItemOrdering) %]
588
                // Remove last itemblock if it is not in items_list
589
                var lastitemblock = $("#outeritemblock > div:last");
590
                var tobedeleted = true;
591
                var listitems = $("#items_list tr");
592
                $(listitems).each(function(){
593
                    if($(this).attr('idblock') == $(lastitemblock).attr('id')){
594
                        tobedeleted = false;
595
                    }
596
                });
597
                if(tobedeleted){
598
                    $(lastitemblock).remove();
599
                }
600
            [% END %]
601
602
            var ok=0;
603
            var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
604
605
            _alertString +="-------------------------------------------------------------------\n\n";
606
607
            if(isNull(ff.budget_id,1)){
608
                ok=1;
609
                _alertString += "\n- "+ _("You must select a fund");
610
            }
611
612
            if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
613
                ok=1;
614
                            _alertString += "\n- " + _("Quantity must be greater than '0'");
615
            }
616
617
            if (!(isNum(ff.listprice,0))){
618
                ok=1;
619
                            _alertString += "\n- " + _("Vendor price must be a number");
620
            }
621
622
            if (!(isNum(ff.total,0))){
623
                ok=1;
624
                            _alertString += "\n- " + _("Total must be a number");
625
            }
626
627
            if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
628
                ok=1;
629
                _alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
630
            }
631
632
            if ( ff.field_value ) {
633
                var empty_item_mandatory = CheckMandatorySubfields(ff);
634
                if (empty_item_mandatory > 0) {
635
                    ok = 1;
636
                    _alertString +=
637
                        "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
638
                }
639
640
            }
641
642
            if (ok) {
643
                alert(_alertString);
644
                [% IF (AcqCreateItemOrdering) %]
645
                    if(tobedeleted) {
646
                        $(lastitemblock).appendTo('#outeritemblock');
647
                    }
648
                [% END %]
649
                return false;
650
            }
651
652
            [% IF (AcqCreateItemOrdering) %]
653
                if(check_additem('[% UniqueItemFields | html %]') == false) {
654
                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
655
                    if(tobedeleted) {
656
                        $(lastitemblock).appendTo('#outeritemblock');
657
                    }
658
                    return false;
659
                }
660
            [% END %]
661
        }
662
663
        $(document).ready(function(){
664
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
665
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
666
            [% END %]
667
668
            [% IF ( suggestionid ) %]updateCosts();[% END %]
669
            $("#quantity").change(function() {
670
                updateCosts();
671
            });
672
673
            //We apply the fonction only for modify option
674
            [% IF ( quantityrec and not subscriptionid ) %]
675
                [% IF ( acqcreate ) %]
676
                    $('#quantity').blur(function(){
677
                        // if user decreases the quantity
678
                        if($(this).val() < [% quantityrec | html %]){
679
                            alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
680
                            return true;
681
                        } else {
682
                            // if user increases the quantity
683
                            alert(_("You can't add a new item, please create a new order line"));
684
                            // and we replace the original value
685
                            $(this).val([% quantityrec | html %])
686
                            updateCosts(); // blur is invoked after change which updated values
687
                            return false;
688
                        }
689
                    });
690
                [% END %]
691
            [% END %]
692
693
            //keep a copy of all budgets before removing the inactives
694
            disabledBudgetsCopy = $('#budget_id').html();
695
            $('#budget_id .b_inactive').remove();
696
697
            $('#showallbudgets').click(function() {
698
                if ($(this).is(":checked")) {
699
                    $('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
700
                }
701
                else {
702
                    $('#budget_id .b_inactive').remove();
703
                }
704
            });
705
706
            $("#budget_id").change(function(){
707
                var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
708
                var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
709
                var sort1 = $(destination_sort1).val() || "";
710
                if ( destination_sort1.length < 1 ) {
711
                    destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
712
                }
713
                var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
714
                var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
715
                var sort2 = $(destination_sort2).val() || "";
716
                if ( destination_sort2.length < 1 ) {
717
                    destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
718
                }
719
                getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
720
                getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
721
            });
722
            $("#budget_id").change();
723
        });
724
725
        function UserSearchPopup(f) {
726
            window.open(
727
                "/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
728
                'UserSearchPopup',
729
                'width=1024, height=768, scrollbars=yes, toolbar=no,'
730
             );
731
        }
732
733
        function add_user(borrowernumber, borrowername) {
734
            var ids = $("#users_ids").val();
735
            if(ids.length > 0) {
736
                ids = ids.split(':');
737
            } else {
738
                ids = new Array;
739
            }
740
        if (ids.indexOf(borrowernumber.toString()) < 0) {
741
                ids.push(borrowernumber);
742
                $("#users_ids").val(ids.join(':'));
743
                var li = '<li id="user_'+borrowernumber+'">'+borrowername
744
                    + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
745
                    + _("Delete user") + '</a>]</li>';
746
                $("#users_names").append(li);
747
                return 0;
748
            }
749
            return -1;
750
        }
751
752
        function del_user(borrowernumber) {
753
            $("#user_"+borrowernumber).remove();
754
            var ids = $("#users_ids").val().split(':');
755
            ids.splice(ids.indexOf(borrowernumber.toString()), 1);
756
            $("#users_ids").val(ids.join(':'));
757
        }
758
    </script>
759
[% END %]
755
[% END %]
760
756
761
[% INCLUDE 'intranet-bottom.inc' %]
757
[% INCLUDE 'intranet-bottom.inc' %]
762
758
763
[% BLOCK display_subfield %]
759
[% BLOCK display_subfield %]
764
    <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
760
    <label>[% field.marc_lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
765
    [% IF field.authorised_value %]
761
766
        [% SWITCH field.authorised_value %]
762
    [% SET mv = field.marc_value %]
767
        [% CASE 'branches' %]
763
    [% IF ( mv.type == 'text' ) %]
768
            [% IF field.mandatory %]
764
        [% IF ( mv.readonly == 1 ) %]
769
            <select name="bib_field_value" required="required">
765
            <input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor readonly" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" readonly="readonly" />
766
        [% ELSE %]
767
            <input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
768
        [% END %]
769
770
    [% ELSIF ( mv.type == 'text_complex' ) %]
771
        <input type="text" id="[%- mv.id | html -%]" name="bib_field_value" value="[%- mv.value | html -%]" class="input_marceditor framework_plugin" tabindex="1" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" />
772
        [% mv.javascript | $raw %]
773
    [% ELSIF ( mv.type == 'hidden' ) %]
774
        <input tabindex="1" type="hidden" id="[%- mv.id | html -%]" name="bib_field_value" size="[%- mv.size | html -%]" maxlength="[%- mv.maxlength | html -%]" value="[%- mv.value | html -%]" />
775
    [% ELSIF ( mv.type == 'textarea' ) %]
776
        <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="bib_field_value" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
777
    [% ELSIF ( mv.type == 'select' ) %]
778
        <select name="bib_field_value" tabindex="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
779
        [% FOREACH aval IN mv.values %]
780
            [% IF aval == mv.default %]
781
            <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
770
            [% ELSE %]
782
            [% ELSE %]
771
            <select name="bib_field_value">
783
            <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
772
            [% END %]
784
            [% END %]
773
                <option value=""></option>
785
        [% END %]
774
                [% PROCESS options_for_libraries libraries => Branches.all( selected => "FIXME" ) %]
786
        </select>
775
            </select>
787
    [% END  # /IF (mv.type...) %]
776
        [% CASE 'itemtypes' %]
788
777
            [% IF field.mandatory %]
789
    <div class="subfield_controls">
778
            <select name="bib_field_value" required="required">
790
        [% IF ( mv.type == 'text_complex' ) %]
791
            [% IF mv.noclick %]
792
                <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
779
            [% ELSE %]
793
            [% ELSE %]
780
            <select name="bib_field_value">
794
                [% IF mv.plugin == "upload.pl" %]
795
                    <a href="#" id="buttonDot_[% mv.id | html %]" class="tag_editor upload framework_plugin" tabindex="1"><i class="fa fa-upload" aria-hidden="true"></i> Upload</a>
796
                [% ELSE %]
797
                    <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
798
                [% END %]
781
            [% END %]
799
            [% END %]
782
                <option value=""></option>
783
                [% PROCESS options_for_item_types itemtypes => ItemTypes.Get(), selected_itemtype => "FIXME" %]
784
            </select>
785
        [% CASE 'cn_source' %]
786
        [% CASE %]
787
            [% PROCESS 'av-build-dropbox.inc' name="bib_field_value", category=field.authorised_value, default="FIXME" %]
788
        [% END %]
789
    [% ELSE %]
790
        [% IF field.mandatory %]
791
        <input type="text" name="bib_field_value" value="[% field.value | html %]" required="required" size="50" />
792
        [% ELSE %]
793
        <input type="text" name="bib_field_value" value="[% field.value | html %]" size="50" />
794
        [% END %]
800
        [% END %]
801
    </div>
795
802
796
    [% END %]
797
    <input type="hidden" name="bib_kohafield" value="[% field.kohafield | html %]" />
803
    <input type="hidden" name="bib_kohafield" value="[% field.kohafield | html %]" />
798
    <input type="hidden" name="bib_tag" value="[% field.tag | html %]" />
804
    <input type="hidden" name="bib_tag" value="[% field.tag | html %]" />
799
    <input type="hidden" name="bib_subfield" value="[% field.subfield | html %]" />
805
    <input type="hidden" name="bib_subfield" value="[% field.subfield | html %]" />
(-)a/koha-tmpl/intranet-tmpl/prog/js/cataloging.js (-1 / +2 lines)
Lines 45-51 function openAuth(tagsubfieldid,authtype,source) { Link Here
45
    var mainmainstring=element.value;
45
    var mainmainstring=element.value;
46
    var mainstring = new Array();
46
    var mainstring = new Array();
47
47
48
    var inputs = element.closest('ul').getElementsByTagName('input');
48
    var ul = element.closest('ul');
49
    var inputs = ul ? ul.getElementsByTagName('input') : element.parentNode.getElementsByTagName('input');
49
    for (var myindex =0; myindex<inputs.length;myindex++){
50
    for (var myindex =0; myindex<inputs.length;myindex++){
50
        if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
51
        if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
51
            var subfieldcode=getSubfieldCode(inputs[myindex].name);
52
            var subfieldcode=getSubfieldCode(inputs[myindex].name);
(-)a/t/db_dependent/Koha/UI/Form/Builder/Biblio.t (-1 / +182 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use DateTime;
6
use Test::More;
7
8
use C4::ClassSource;
9
10
use Koha::ClassSources;
11
use Koha::ItemTypes;
12
use Koha::Libraries;
13
14
use_ok('Koha::UI::Form::Builder::Biblio');
15
16
subtest 'generate_subfield_form default value' => sub {
17
    my $builder = Koha::UI::Form::Builder::Biblio->new();
18
19
    my $subfield = $builder->generate_subfield_form(
20
        {
21
            tag => '999',
22
            subfield => '9',
23
            value => '',
24
            index_tag => int(rand(1000000)),
25
            tagslib => {
26
                '999' => {
27
                    '9' => {
28
                        defaultvalue => 'The date is <<YYYY>>-<<MM>>-<<DD>> and user is <<USER>>',
29
                        hidden => 0,
30
                    }
31
                }
32
            },
33
        },
34
    );
35
36
    my $today = DateTime->now->ymd;
37
    is($subfield->{marc_value}->{value}, "The date is $today and user is superlibrarian");
38
};
39
40
subtest 'generate_subfield_form branches' => sub {
41
    my $builder = Koha::UI::Form::Builder::Biblio->new();
42
43
    my $subfield = $builder->generate_subfield_form(
44
        {
45
            tag => '999',
46
            subfield => '9',
47
            value => '',
48
            index_tag => int(rand(1000000)),
49
            tagslib => {
50
                '999' => {
51
                    '9' => {
52
                        authorised_value => 'branches',
53
                        hidden => 0,
54
                    }
55
                }
56
            },
57
        },
58
    );
59
60
    my @libraries = Koha::Libraries->search({}, {order_by => 'branchname'})->as_list;
61
    my %labels = map { $_->branchcode => $_->branchname } @libraries;
62
    my @values = map { $_->branchcode } @libraries;
63
64
    is($subfield->{marc_value}->{type}, 'select');
65
    is_deeply($subfield->{marc_value}->{labels}, \%labels);
66
    is_deeply($subfield->{marc_value}->{values}, \@values);
67
};
68
69
subtest 'generate_subfield_form itemtypes' => sub {
70
    my $builder = Koha::UI::Form::Builder::Biblio->new();
71
72
    my $subfield = $builder->generate_subfield_form(
73
        {
74
            tag => '999',
75
            subfield => '9',
76
            value => '',
77
            index_tag => int(rand(1000000)),
78
            tagslib => {
79
                '999' => {
80
                    '9' => {
81
                        authorised_value => 'itemtypes',
82
                        hidden => 0,
83
                    }
84
                }
85
            },
86
        },
87
    );
88
89
    my @itemtypes = Koha::ItemTypes->search_with_localization()->as_list;
90
    my %labels = map { $_->itemtype => $_->description } @itemtypes;
91
    my @values = ('', map { $_->itemtype } @itemtypes);
92
93
    is($subfield->{marc_value}->{type}, 'select');
94
    is_deeply($subfield->{marc_value}->{labels}, \%labels);
95
    is_deeply($subfield->{marc_value}->{values}, \@values);
96
};
97
98
subtest 'generate_subfield_form class sources' => sub {
99
    my $builder = Koha::UI::Form::Builder::Biblio->new();
100
101
    my $subfield = $builder->generate_subfield_form(
102
        {
103
            tag => '999',
104
            subfield => '9',
105
            value => '',
106
            index_tag => int(rand(1000000)),
107
            tagslib => {
108
                '999' => {
109
                    '9' => {
110
                        authorised_value => 'cn_source',
111
                        hidden => 0,
112
                    }
113
                }
114
            },
115
        },
116
    );
117
118
    my @class_sources = Koha::ClassSources->search({used => 1}, {order_by => 'cn_source'})->as_list;
119
    my %labels = map { $_->cn_source => $_->description } @class_sources;
120
    my @values = ('', map { $_->cn_source } @class_sources);
121
122
    is($subfield->{marc_value}->{type}, 'select');
123
    is_deeply($subfield->{marc_value}->{labels}, \%labels);
124
    is_deeply($subfield->{marc_value}->{values}, \@values);
125
};
126
127
subtest 'generate_subfield_form authorised value' => sub {
128
    my $builder = Koha::UI::Form::Builder::Biblio->new();
129
130
    my $subfield = $builder->generate_subfield_form(
131
        {
132
            tag => '999',
133
            subfield => '9',
134
            value => '',
135
            index_tag => int(rand(1000000)),
136
            tagslib => {
137
                '999' => {
138
                    '9' => {
139
                        authorised_value => 'YES_NO',
140
                        hidden => 0,
141
                    }
142
                }
143
            },
144
        },
145
    );
146
147
    my @authorised_values = Koha::AuthorisedValues->search({category => 'YES_NO'}, {order_by => ['lib', 'lib_opac']})->as_list;
148
    my %labels = map { $_->authorised_value => $_->lib } @authorised_values;
149
    my @values = ('', map { $_->authorised_value } @authorised_values);
150
151
    is($subfield->{marc_value}->{type}, 'select');
152
    is_deeply($subfield->{marc_value}->{labels}, \%labels);
153
    is_deeply($subfield->{marc_value}->{values}, \@values);
154
};
155
156
subtest 'generate_subfield_form framework plugin' => sub {
157
    my $builder = Koha::UI::Form::Builder::Biblio->new();
158
159
    my $subfield = $builder->generate_subfield_form(
160
        {
161
            tag => '999',
162
            subfield => '9',
163
            value => '',
164
            index_tag => int(rand(1000000)),
165
            tagslib => {
166
                '999' => {
167
                    '9' => {
168
                        value_builder => 'barcode.pl',
169
                        hidden => 0,
170
                    }
171
                }
172
            },
173
        },
174
    );
175
176
    is($subfield->{marc_value}->{type}, 'text_complex');
177
    is($subfield->{marc_value}->{plugin}, 'barcode.pl');
178
    is($subfield->{marc_value}->{noclick}, 1);
179
    like($subfield->{marc_value}->{javascript}, qr,<script>.*</script>,s);
180
};
181
182
done_testing();

Return to bug 32484