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 53-58 use Koha::Libraries; Link Here
53
53
54
use Koha::BiblioFrameworks;
54
use Koha::BiblioFrameworks;
55
use Koha::Patrons;
55
use Koha::Patrons;
56
use Koha::UI::Form::Builder::Biblio;
56
57
57
use MARC::File::USMARC;
58
use MARC::File::USMARC;
58
use MARC::File::XML;
59
use MARC::File::XML;
Lines 172-253 sub MARCfindbreeding { Link Here
172
    return -1;
173
    return -1;
173
}
174
}
174
175
175
=head2 build_authorized_values_list
176
177
=cut
178
179
sub build_authorized_values_list {
180
    my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
181
182
    my @authorised_values;
183
    my %authorised_lib;
184
185
    # builds list, depending on authorised value...
186
187
    #---- branch
188
    my $category = $tagslib->{$tag}->{$subfield}->{authorised_value};
189
    if ( $category eq "branches" ) {
190
        my $libraries = Koha::Libraries->search_filtered({}, {order_by => ['branchname']});
191
        while ( my $l = $libraries->next ) {
192
            push @authorised_values, $l->branchcode;;
193
            $authorised_lib{$l->branchcode} = $l->branchname;
194
        }
195
    }
196
    elsif ( $category eq "itemtypes" ) {
197
        push @authorised_values, "";
198
199
        my $itemtype;
200
        my $itemtypes = Koha::ItemTypes->search_with_localization;
201
        while ( $itemtype = $itemtypes->next ) {
202
            push @authorised_values, $itemtype->itemtype;
203
            $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description;
204
        }
205
        $value = $itemtype unless ($value);
206
    }
207
    elsif ( $category eq "cn_source" ) {
208
        push @authorised_values, "";
209
210
        my $class_sources = GetClassSources();
211
212
        my $default_source = C4::Context->preference("DefaultClassificationSource");
213
214
        foreach my $class_source (sort keys %$class_sources) {
215
            next unless $class_sources->{$class_source}->{'used'} or
216
                        ($value and $class_source eq $value) or
217
                        ($class_source eq $default_source);
218
            push @authorised_values, $class_source;
219
            $authorised_lib{$class_source} = $class_sources->{$class_source}->{'description'};
220
        }
221
        $value = $default_source unless $value;
222
    }
223
    else {
224
        my $branch_limit = C4::Context->userenv ? C4::Context->userenv->{"branch"} : "";
225
        $authorised_values_sth->execute(
226
            $tagslib->{$tag}->{$subfield}->{authorised_value},
227
            $branch_limit ? $branch_limit : (),
228
        );
229
230
        push @authorised_values, "";
231
232
        while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) {
233
            push @authorised_values, $value;
234
            $authorised_lib{$value} = $lib;
235
        }
236
    }
237
    $authorised_values_sth->finish;
238
239
    return {
240
        type     => 'select',
241
        id       => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
242
        name     => "tag_".$tag."_subfield_".$subfield."_".$index_tag."_".$index_subfield,
243
        default  => $value,
244
        values   => \@authorised_values,
245
        labels   => \%authorised_lib,
246
        ( ( grep { $_ eq $category } ( qw(branches itemtypes cn_source) ) ) ? () : ( category => $category ) ),
247
    };
248
249
}
250
251
=head2 CreateKey
176
=head2 CreateKey
252
177
253
    Create a random value to set it into the input name
178
    Create a random value to set it into the input name
Lines 282-494 sub GetMandatoryFieldZ3950 { Link Here
282
    };
207
    };
283
}
208
}
284
209
285
=head2 create_input
286
287
 builds the <input ...> entry for a subfield.
288
289
=cut
290
291
sub create_input {
292
    my ( $tag, $subfield, $value, $index_tag, $rec, $authorised_values_sth,$cgi ) = @_;
293
294
    my $index_subfield = CreateKey(); # create a specifique key for each subfield
295
296
    # Apply optional framework default value when it is a new record,
297
    # or when editing as new (duplicating a record),
298
    # or when changing a record's framework,
299
    # or when importing a record,
300
    # based on the ApplyFrameworkDefaults setting.
301
    # Substitute date parts, user name
302
    my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults');
303
    if ( $value eq '' && (
304
        ( $applydefaults =~ /new/ && !$cgi->param('biblionumber') ) ||
305
        ( $applydefaults =~ /duplicate/ && $cgi->param('op') eq 'duplicate' ) ||
306
        ( $applydefaults =~ /changed/ && $cgi->param('changed_framework') ) ||
307
        ( $applydefaults =~ /imported/ && $cgi->param('breedingid') )
308
    ) ) {
309
        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} // q{};
310
311
        # get today date & replace <<YYYY>>, <<YY>>, <<MM>>, <<DD>> if provided in the default value
312
        my $today_dt = dt_from_string;
313
        my $year = $today_dt->strftime('%Y');
314
        my $shortyear = $today_dt->strftime('%y');
315
        my $month = $today_dt->strftime('%m');
316
        my $day = $today_dt->strftime('%d');
317
        $value =~ s/<<YYYY>>/$year/g;
318
        $value =~ s/<<YY>>/$shortyear/g;
319
        $value =~ s/<<MM>>/$month/g;
320
        $value =~ s/<<DD>>/$day/g;
321
        # And <<USER>> with surname (?)
322
        my $username=(C4::Context->userenv?C4::Context->userenv->{'surname'}:"superlibrarian");
323
        $value=~s/<<USER>>/$username/g;
324
    }
325
326
    my $dbh = C4::Context->dbh;
327
328
    # map '@' as "subfield" label for fixed fields
329
    # to something that's allowed in a div id.
330
    my $id_subfield = $subfield;
331
    $id_subfield = "00" if $id_subfield eq "@";
332
333
    my %subfield_data = (
334
        tag        => $tag,
335
        subfield   => $id_subfield,
336
        marc_lib       => $tagslib->{$tag}->{$subfield}->{lib},
337
        tag_mandatory  => $tagslib->{$tag}->{mandatory},
338
        mandatory      => $tagslib->{$tag}->{$subfield}->{mandatory},
339
        important      => $tagslib->{$tag}->{$subfield}->{important},
340
        repeatable     => $tagslib->{$tag}->{$subfield}->{repeatable},
341
        kohafield      => $tagslib->{$tag}->{$subfield}->{kohafield},
342
        index          => $index_tag,
343
        id             => "tag_".$tag."_subfield_".$id_subfield."_".$index_tag."_".$index_subfield,
344
        value          => $value,
345
        maxlength      => $tagslib->{$tag}->{$subfield}->{maxlength},
346
        random         => CreateKey(),
347
    );
348
349
    if(exists $mandatory_z3950->{$tag.$subfield}){
350
        $subfield_data{z3950_mandatory} = $mandatory_z3950->{$tag.$subfield};
351
    }
352
    # Subfield is hidden depending of hidden and mandatory flag, and is always
353
    # shown if it contains anything or if its field is mandatory or important.
354
    my $tdef = $tagslib->{$tag};
355
    $subfield_data{visibility} = "display:none;"
356
        if $tdef->{$subfield}->{hidden} % 2 == 1 &&
357
           $value eq '' &&
358
           !$tdef->{$subfield}->{mandatory} &&
359
           !$tdef->{mandatory} &&
360
           !$tdef->{$subfield}->{important} &&
361
           !$tdef->{important};
362
    # expand all subfields of 773 if there is a host item provided in the input
363
    $subfield_data{visibility} ="" if ($tag eq 773 and $cgi->param('hostitemnumber'));
364
365
366
    # it's an authorised field
367
    if ( $tagslib->{$tag}->{$subfield}->{authorised_value} ) {
368
        $subfield_data{marc_value} =
369
          build_authorized_values_list( $tag, $subfield, $value, $dbh,
370
            $authorised_values_sth,$index_tag,$index_subfield );
371
372
    # it's a subfield $9 linking to an authority record - see bug 2206 and 28022
373
    }
374
    elsif ($subfield eq "9" and
375
           exists($tagslib->{$tag}->{'a'}->{authtypecode}) and
376
           defined($tagslib->{$tag}->{'a'}->{authtypecode}) and
377
           $tagslib->{$tag}->{'a'}->{authtypecode} ne '' and
378
           $tagslib->{$tag}->{'a'}->{hidden} > -4 and
379
           $tagslib->{$tag}->{'a'}->{hidden} < 5) {
380
        $subfield_data{marc_value} = {
381
            type      => 'text',
382
            id        => $subfield_data{id},
383
            name      => $subfield_data{id},
384
            value     => $value,
385
            size      => 5,
386
            maxlength => $subfield_data{maxlength},
387
            readonly  => 1,
388
        };
389
390
    # it's a thesaurus / authority field
391
    }
392
    elsif ( $tagslib->{$tag}->{$subfield}->{authtypecode} ) {
393
        # when authorities auto-creation is allowed, do not set readonly
394
        my $is_readonly = C4::Context->preference("RequireChoosingExistingAuthority");
395
396
        $subfield_data{marc_value} = {
397
            type      => 'text',
398
            id        => $subfield_data{id},
399
            name      => $subfield_data{id},
400
            value     => $value,
401
            size      => 67,
402
            maxlength => $subfield_data{maxlength},
403
            readonly  => ($is_readonly) ? 1 : 0,
404
            authtype  => $tagslib->{$tag}->{$subfield}->{authtypecode},
405
        };
406
407
    # it's a plugin field
408
    } elsif ( $tagslib->{$tag}->{$subfield}->{'value_builder'} ) {
409
        require Koha::FrameworkPlugin;
410
        my $plugin = Koha::FrameworkPlugin->new( {
411
            name => $tagslib->{$tag}->{$subfield}->{'value_builder'},
412
        });
413
        my $pars= { dbh => $dbh, record => $rec, tagslib => $tagslib,
414
            id => $subfield_data{id} };
415
        $plugin->build( $pars );
416
        if( !$plugin->errstr ) {
417
            $subfield_data{marc_value} = {
418
                type           => 'text_complex',
419
                id             => $subfield_data{id},
420
                name           => $subfield_data{id},
421
                value          => $value,
422
                size           => 67,
423
                maxlength      => $subfield_data{maxlength},
424
                javascript     => $plugin->javascript,
425
                plugin         => $plugin->name,
426
                noclick        => $plugin->noclick,
427
            };
428
        } else {
429
            warn $plugin->errstr;
430
            # supply default input form
431
            $subfield_data{marc_value} = {
432
                type      => 'text',
433
                id        => $subfield_data{id},
434
                name      => $subfield_data{id},
435
                value     => $value,
436
                size      => 67,
437
                maxlength => $subfield_data{maxlength},
438
                readonly  => 0,
439
            };
440
        }
441
442
    # it's an hidden field
443
    } elsif ( $tag eq '' ) {
444
        $subfield_data{marc_value} = {
445
            type      => 'hidden',
446
            id        => $subfield_data{id},
447
            name      => $subfield_data{id},
448
            value     => $value,
449
            size      => 67,
450
            maxlength => $subfield_data{maxlength},
451
        };
452
453
    }
454
    else {
455
        # it's a standard field
456
        if (
457
            length($value) > 100
458
            or
459
            ( C4::Context->preference("marcflavour") eq "UNIMARC" && $tag >= 300
460
                and $tag < 400 && $subfield eq 'a' )
461
            or (    $tag >= 500
462
                and $tag < 600
463
                && C4::Context->preference("marcflavour") eq "MARC21" )
464
          )
465
        {
466
            $subfield_data{marc_value} = {
467
                type      => 'textarea',
468
                id        => $subfield_data{id},
469
                name      => $subfield_data{id},
470
                value     => $value,
471
            };
472
473
        }
474
        else {
475
            $subfield_data{marc_value} = {
476
                type      => 'text',
477
                id        => $subfield_data{id},
478
                name      => $subfield_data{id},
479
                value     => $value,
480
                size      => 67,
481
                maxlength => $subfield_data{maxlength},
482
                readonly  => 0,
483
            };
484
485
        }
486
    }
487
    $subfield_data{'index_subfield'} = $index_subfield;
488
    return \%subfield_data;
489
}
490
491
492
=head2 format_indicator
210
=head2 format_indicator
493
211
494
Translate indicator value for output form - specifically, map
212
Translate indicator value for output form - specifically, map
Lines 543-548 sub build_tabs { Link Here
543
    if($max_num_tab >= 9){
261
    if($max_num_tab >= 9){
544
        $max_num_tab = 9;
262
        $max_num_tab = 9;
545
    }
263
    }
264
265
    my $biblio_form_builder = Koha::UI::Form::Builder::Biblio->new(
266
        {
267
            biblionumber => scalar $input->param('biblionumber'),
268
        }
269
    );
270
546
    # loop through each tab 0 through 9
271
    # loop through each tab 0 through 9
547
    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
272
    for ( my $tabloop = 0 ; $tabloop <= $max_num_tab ; $tabloop++ ) {
548
        my @loop_data = (); #innerloop in the template.
273
        my @loop_data = (); #innerloop in the template.
Lines 583-591 sub build_tabs { Link Here
583
                            'biblio.biblionumber' );
308
                            'biblio.biblionumber' );
584
                        push(
309
                        push(
585
                            @subfields_data,
310
                            @subfields_data,
586
                            &create_input(
311
                            $biblio_form_builder->generate_subfield_form(
587
                                $tag, $subfield, $value, $index_tag, $record,
312
                                {
588
                                $authorised_values_sth,$input
313
                                    tag => $tag,
314
                                    subfield => $subfield,
315
                                    value => $value,
316
                                    index_tag => $index_tag,
317
                                    record => $record,
318
                                    hostitemnumber => scalar $input->param('hostitemnumber'),
319
                                    op => scalar $input->param('op'),
320
                                    changed_framework => scalar $input->param('changed_framework'),
321
                                    breedingid => scalar $input->param('breedingid'),
322
                                    tagslib => $tagslib,
323
                                    mandatory_z3950 => $mandatory_z3950,
324
                                }
589
                            )
325
                            )
590
                        );
326
                        );
591
                    }
327
                    }
Lines 598-606 sub build_tabs { Link Here
598
                            next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
334
                            next if ( !defined $tagslib->{$tag}->{$subfield} || $tagslib->{$tag}->{$subfield}->{tab} ne $tabloop );
599
                            push(
335
                            push(
600
                                @subfields_data,
336
                                @subfields_data,
601
                                &create_input(
337
                                $biblio_form_builder->generate_subfield_form(
602
                                    $tag, $subfield, $value, $index_tag,
338
                                    {
603
                                    $record, $authorised_values_sth,$input
339
                                        tag => $tag,
340
                                        subfield => $subfield,
341
                                        value => $value,
342
                                        index_tag => $index_tag,
343
                                        record => $record,
344
                                        hostitemnumber => scalar $input->param('hostitemnumber'),
345
                                        tagslib => $tagslib,
346
                                        mandatory_z3950 => $mandatory_z3950,
347
                                    }
604
                                )
348
                                )
605
                            );
349
                            );
606
                        }
350
                        }
Lines 628-636 sub build_tabs { Link Here
628
                        next if ( defined( $field->subfield($subfield) ) );
372
                        next if ( defined( $field->subfield($subfield) ) );
629
                        push(
373
                        push(
630
                            @subfields_data,
374
                            @subfields_data,
631
                            &create_input(
375
                            $biblio_form_builder->generate_subfield_form(
632
                                $tag, $subfield, '', $index_tag, $record,
376
                                {
633
                                $authorised_values_sth,$input
377
                                    tag => $tag,
378
                                    subfield => $subfield,
379
                                    value => '',
380
                                    index_tag => $index_tag,
381
                                    record => $record,
382
                                    hostitemnumber => scalar $input->param('hostitemnumber'),
383
                                    tagslib => $tagslib,
384
                                    mandatory_z3950 => $mandatory_z3950,
385
                                }
634
                            )
386
                            )
635
                        );
387
                        );
636
                    }
388
                    }
Lines 684-692 sub build_tabs { Link Here
684
                      if ( $subfield->{tab} ne $tabloop );
436
                      if ( $subfield->{tab} ne $tabloop );
685
			push(
437
			push(
686
                        @subfields_data,
438
                        @subfields_data,
687
                        &create_input(
439
                        $biblio_form_builder->generate_subfield_form(
688
                            $tag, $subfield->{subfield}, '', $index_tag, $record,
440
                            {
689
                            $authorised_values_sth,$input
441
                                tag => $tag,
442
                                subfield => $subfield->{subfield},
443
                                value => '',
444
                                index_tag => $index_tag,
445
                                record => $record,
446
                                hostitemnumber => scalar $input->param('hostitemnumber'),
447
                                tagslib => $tagslib,
448
                                mandatory_z3950 => $mandatory_z3950,
449
                            }
690
                        )
450
                        )
691
                    );
451
                    );
692
                }
452
                }
(-)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 264-284 Link Here
264
            [% IF biblionumber %]
446
            [% IF biblionumber %]
265
                <ol>
447
                <ol>
266
                    [% FOREACH field IN catalog_details %]
448
                    [% FOREACH field IN catalog_details %]
267
                        <li>
449
                        <li class="subfield_line">
268
                            <div class="subfield_line">
450
                            <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
269
                                <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
451
                            [% field.value | html %]
270
                                [% field.value | html %]
271
                            </div>
272
                        </li>
452
                        </li>
273
                    [% END %]
453
                    [% END %]
274
                </ol>
454
                </ol>
275
            [% ELSE %]
455
            [% ELSE %]
276
                <ol>
456
                <ol>
277
                    [% FOREACH field IN catalog_details %]
457
                    [% FOREACH field IN catalog_details %]
278
                        <li>
458
                        <li class="subfield_line">
279
                            <div class="subfield_line">
459
                            [% PROCESS display_subfield field=field %]
280
                                [% PROCESS display_subfield field=field %]
281
                            </div>
282
                        </li>
460
                        </li>
283
                    [% END %]
461
                    [% END %]
284
                </ol>
462
                </ol>
Lines 564-789 Link Here
564
</div> <!-- /.row -->
742
</div> <!-- /.row -->
565
743
566
[% MACRO jsinclude BLOCK %]
744
[% MACRO jsinclude BLOCK %]
567
    [% Asset.js("js/acquisitions-menu.js") | $raw %]
568
    [% Asset.js("js/acq.js") | $raw %]
569
    [% Asset.js("js/additem.js") | $raw %]
570
    [% Asset.js("js/cataloging.js") | $raw %]
571
    [% INCLUDE 'calendar.inc' %]
572
    [% INCLUDE 'select2.inc' %]
573
    <script>
574
        actTotal = "";
575
576
        function Check(ff) {
577
            [% IF (AcqCreateItemOrdering) %]
578
                // Remove last itemblock if it is not in items_list
579
                var lastitemblock = $("#outeritemblock > div:last");
580
                var tobedeleted = true;
581
                var listitems = $("#items_list tr");
582
                $(listitems).each(function(){
583
                    if($(this).attr('idblock') == $(lastitemblock).attr('id')){
584
                        tobedeleted = false;
585
                    }
586
                });
587
                if(tobedeleted){
588
                    $(lastitemblock).remove();
589
                }
590
            [% END %]
591
592
            var ok=0;
593
            var _alertString= _("Form not submitted because of the following problem(s)")+"\n";
594
595
            _alertString +="-------------------------------------------------------------------\n\n";
596
597
            if(isNull(ff.budget_id,1)){
598
                ok=1;
599
                _alertString += "\n- "+ _("You must select a fund");
600
            }
601
602
            if (!(isNum(ff.quantity,0)) || ff.quantity.value == 0){
603
                ok=1;
604
                            _alertString += "\n- " + _("Quantity must be greater than '0'");
605
            }
606
607
            if (!(isNum(ff.listprice,0))){
608
                ok=1;
609
                            _alertString += "\n- " + _("Vendor price must be a number");
610
            }
611
612
            if (!(isNum(ff.total,0))){
613
                ok=1;
614
                            _alertString += "\n- " + _("Total must be a number");
615
            }
616
617
            if (totalExceedsBudget(ff.budget_id.value, ff.total.value  )  ) {
618
                ok=1;
619
                _alertString += "\n- " + _("Order total (%s) exceeds budget available (%s)").format(ff.total.value, actTotal);
620
            }
621
622
            if ( ff.field_value ) {
623
                var empty_item_mandatory = CheckMandatorySubfields(ff);
624
                if (empty_item_mandatory > 0) {
625
                    ok = 1;
626
                    _alertString +=
627
                        "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory);
628
                }
629
630
            }
631
632
            if (ok) {
633
                alert(_alertString);
634
                [% IF (AcqCreateItemOrdering) %]
635
                    if(tobedeleted) {
636
                        $(lastitemblock).appendTo('#outeritemblock');
637
                    }
638
                [% END %]
639
                return false;
640
            }
641
642
            [% IF (AcqCreateItemOrdering) %]
643
                if(check_additem('[% UniqueItemFields | html %]') == false) {
644
                    alert(_("Duplicate values detected. Please correct the errors and resubmit.") );
645
                    if(tobedeleted) {
646
                        $(lastitemblock).appendTo('#outeritemblock');
647
                    }
648
                    return false;
649
                }
650
            [% END %]
651
        }
652
653
        $(document).ready(function(){
654
            [% IF AcqCreateItemOrdering and not basket.is_standing %]
655
                cloneItemBlock(0, '[% UniqueItemFields | html %]');
656
            [% END %]
657
658
            [% IF ( suggestionid ) %]updateCosts();[% END %]
659
            $("#quantity").change(function() {
660
                updateCosts();
661
            });
662
663
            //We apply the fonction only for modify option
664
            [% IF ( quantityrec and not subscriptionid ) %]
665
                [% IF ( acqcreate ) %]
666
                    $('#quantity').blur(function(){
667
                        // if user decreases the quantity
668
                        if($(this).val() < [% quantityrec | html %]){
669
                            alert(_("You have deleted item(s) in the order, don't forget to delete it(them) in the catalog"));
670
                            return true;
671
                        } else {
672
                            // if user increases the quantity
673
                            alert(_("You can't add a new item, please create a new order line"));
674
                            // and we replace the original value
675
                            $(this).val([% quantityrec | html %])
676
                            updateCosts(); // blur is invoked after change which updated values
677
                            return false;
678
                        }
679
                    });
680
                [% END %]
681
            [% END %]
682
683
            //keep a copy of all budgets before removing the inactives
684
            disabledBudgetsCopy = $('#budget_id').html();
685
            $('#budget_id .b_inactive').remove();
686
687
            $('#showallbudgets').click(function() {
688
                if ($(this).is(":checked")) {
689
                    $('#budget_id').html(disabledBudgetsCopy); //Puts back all the funds
690
                }
691
                else {
692
                    $('#budget_id .b_inactive').remove();
693
                }
694
            });
695
696
            $("#budget_id").change(function(){
697
                var destination_sort1 = $(this).parents('fieldset.rows').find('input[name="sort1"]');
698
                var sort1_authcat = $(this).find("option:selected").attr('data-sort1-authcat');
699
                var sort1 = $(destination_sort1).val() || "";
700
                if ( destination_sort1.length < 1 ) {
701
                    destination_sort1 = $(this).parents('fieldset.rows').find('select[name="sort1"]');
702
                }
703
                var destination_sort2 = $(this).parents('fieldset.rows').find('input[name="sort2"]');
704
                var sort2_authcat = $(this).find("option:selected").attr('data-sort2-authcat');
705
                var sort2 = $(destination_sort2).val() || "";
706
                if ( destination_sort2.length < 1 ) {
707
                    destination_sort2 = $(this).parents('fieldset.rows').find('select[name="sort2"]');
708
                }
709
                getAuthValueDropbox( 'sort1', sort1_authcat, destination_sort1, sort1 );
710
                getAuthValueDropbox( 'sort2', sort2_authcat, destination_sort2, sort2 );
711
            });
712
            $("#budget_id").change();
713
        });
714
715
        function UserSearchPopup(f) {
716
            window.open(
717
                "/cgi-bin/koha/members/search.pl?columns=cardnumber,name,category,branch,action&selection_type=add",
718
                'UserSearchPopup',
719
                'width=1024, height=768, scrollbars=yes, toolbar=no,'
720
             );
721
        }
722
723
        function add_user(borrowernumber, borrowername) {
724
            var ids = $("#users_ids").val();
725
            if(ids.length > 0) {
726
                ids = ids.split(':');
727
            } else {
728
                ids = new Array;
729
            }
730
        if (ids.indexOf(borrowernumber.toString()) < 0) {
731
                ids.push(borrowernumber);
732
                $("#users_ids").val(ids.join(':'));
733
                var li = '<li id="user_'+borrowernumber+'">'+borrowername
734
                    + ' [<a style="cursor:pointer" onclick="del_user('+borrowernumber+');">'
735
                    + _("Delete user") + '</a>]</li>';
736
                $("#users_names").append(li);
737
                return 0;
738
            }
739
            return -1;
740
        }
741
742
        function del_user(borrowernumber) {
743
            $("#user_"+borrowernumber).remove();
744
            var ids = $("#users_ids").val().split(':');
745
            ids.splice(ids.indexOf(borrowernumber.toString()), 1);
746
            $("#users_ids").val(ids.join(':'));
747
        }
748
    </script>
749
[% END %]
745
[% END %]
750
746
751
[% INCLUDE 'intranet-bottom.inc' %]
747
[% INCLUDE 'intranet-bottom.inc' %]
752
748
753
[% BLOCK display_subfield %]
749
[% BLOCK display_subfield %]
754
    <label>[% field.lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
750
    <label>[% field.marc_lib | html %] ([% field.tag | html %][% field.subfield | html %])</label>
755
    [% IF field.authorised_value %]
751
756
        [% SWITCH field.authorised_value %]
752
    [% SET mv = field.marc_value %]
757
        [% CASE 'branches' %]
753
    [% IF ( mv.type == 'text' ) %]
758
            [% IF field.mandatory %]
754
        [% IF ( mv.readonly == 1 ) %]
759
            <select name="bib_field_value" required="required">
755
            <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" />
756
        [% ELSE %]
757
            <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 -%]" />
758
        [% END %]
759
760
    [% ELSIF ( mv.type == 'text_complex' ) %]
761
        <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 -%]" />
762
        [% mv.javascript | $raw %]
763
    [% ELSIF ( mv.type == 'hidden' ) %]
764
        <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 -%]" />
765
    [% ELSIF ( mv.type == 'textarea' ) %]
766
        <textarea cols="70" rows="4" id="[%- mv.id | html -%]" name="bib_field_value" class="input_marceditor" tabindex="1">[%- mv.value | html -%]</textarea>
767
    [% ELSIF ( mv.type == 'select' ) %]
768
        <select name="bib_field_value" tabindex="1" class="input_marceditor select2" id="[%- mv.id | html -%]">
769
        [% FOREACH aval IN mv.values %]
770
            [% IF aval == mv.default %]
771
            <option value="[%- aval | html -%]" selected="selected">[%- mv.labels.$aval | html -%]</option>
760
            [% ELSE %]
772
            [% ELSE %]
761
            <select name="bib_field_value">
773
            <option value="[%- aval | html -%]">[%- mv.labels.$aval | html -%]</option>
762
            [% END %]
774
            [% END %]
763
                <option value=""></option>
775
        [% END %]
764
                [% PROCESS options_for_libraries libraries => Branches.all( selected => "FIXME" ) %]
776
        </select>
765
            </select>
777
    [% END  # /IF (mv.type...) %]
766
        [% CASE 'itemtypes' %]
778
767
            [% IF field.mandatory %]
779
    <div class="subfield_controls">
768
            <select name="bib_field_value" required="required">
780
        [% IF ( mv.type == 'text_complex' ) %]
781
            [% IF mv.noclick %]
782
                <span class="buttonDot tag_editor disabled" tabindex="-1" title="Field autofilled by plugin"></span>
769
            [% ELSE %]
783
            [% ELSE %]
770
            <select name="bib_field_value">
784
                [% IF mv.plugin == "upload.pl" %]
785
                    <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>
786
                [% ELSE %]
787
                    <a href="#" id="buttonDot_[% mv.id | html %]" class="buttonDot tag_editor framework_plugin" tabindex="1" title="Tag editor">Tag editor</a>
788
                [% END %]
771
            [% END %]
789
            [% END %]
772
                <option value=""></option>
773
                [% PROCESS options_for_item_types itemtypes => ItemTypes.Get(), selected_itemtype => "FIXME" %]
774
            </select>
775
        [% CASE 'cn_source' %]
776
        [% CASE %]
777
            [% PROCESS 'av-build-dropbox.inc' name="bib_field_value", category=field.authorised_value, default="FIXME" %]
778
        [% END %]
779
    [% ELSE %]
780
        [% IF field.mandatory %]
781
        <input type="text" name="bib_field_value" value="[% field.value | html %]" required="required" size="50" />
782
        [% ELSE %]
783
        <input type="text" name="bib_field_value" value="[% field.value | html %]" size="50" />
784
        [% END %]
790
        [% END %]
791
    </div>
785
792
786
    [% END %]
787
    <input type="hidden" name="bib_kohafield" value="[% field.kohafield | html %]" />
793
    <input type="hidden" name="bib_kohafield" value="[% field.kohafield | html %]" />
788
    <input type="hidden" name="bib_tag" value="[% field.tag | html %]" />
794
    <input type="hidden" name="bib_tag" value="[% field.tag | html %]" />
789
    <input type="hidden" name="bib_subfield" value="[% field.subfield | html %]" />
795
    <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