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

(-)a/C4/ImportBatch.pm (-1 / +5 lines)
Lines 26-31 use C4::Biblio; Link Here
26
use C4::Items;
26
use C4::Items;
27
use C4::Charset;
27
use C4::Charset;
28
use C4::AuthoritiesMarc;
28
use C4::AuthoritiesMarc;
29
use Koha::MarcModificationTemplates;
29
30
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
31
32
Lines 316-322 sub ModAuthInBatch { Link Here
316
=head2 BatchStageMarcRecords
317
=head2 BatchStageMarcRecords
317
318
318
  ($batch_id, $num_records, $num_items, @invalid_records) = 
319
  ($batch_id, $num_records, $num_items, @invalid_records) = 
319
    BatchStageMarcRecords($record_type, $encoding, $marc_records, $file_name,
320
    BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template,
320
                          $comments, $branch_code, $parse_items,
321
                          $comments, $branch_code, $parse_items,
321
                          $leave_as_staging, 
322
                          $leave_as_staging, 
322
                          $progress_interval, $progress_callback);
323
                          $progress_interval, $progress_callback);
Lines 328-333 sub BatchStageMarcRecords { Link Here
328
    my $encoding = shift;
329
    my $encoding = shift;
329
    my $marc_records = shift;
330
    my $marc_records = shift;
330
    my $file_name = shift;
331
    my $file_name = shift;
332
    my $marc_modification_template = shift;
331
    my $comments = shift;
333
    my $comments = shift;
332
    my $branch_code = shift;
334
    my $branch_code = shift;
333
    my $parse_items = shift;
335
    my $parse_items = shift;
Lines 378-383 sub BatchStageMarcRecords { Link Here
378
380
379
        $encoding = $charset_guessed unless $encoding;
381
        $encoding = $charset_guessed unless $encoding;
380
382
383
        ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template );
384
381
        my $import_record_id;
385
        my $import_record_id;
382
        if (scalar($marc_record->fields()) == 0) {
386
        if (scalar($marc_record->fields()) == 0) {
383
            push @invalid_records, $marc_blob;
387
            push @invalid_records, $marc_blob;
(-)a/C4/Koha.pm (+17 lines)
Lines 1488-1493 sub _isbn_cleanup { Link Here
1488
    return;
1488
    return;
1489
}
1489
}
1490
1490
1491
=head2
1492
1493
  Log( $message );
1494
1495
  Writes data to /tmp/koha.log.
1496
1497
  This is useful for debugging forked processes
1498
  that do not write to the apache error log
1499
1500
=cut
1501
1502
sub Log {
1503
  my ($data) = @_;
1504
  open (MYFILE, '>>/tmp/koha.log');
1505
  print MYFILE "$data\n";
1506
  close (MYFILE);
1507
}
1491
1;
1508
1;
1492
1509
1493
__END__
1510
__END__
(-)a/Koha/MarcModificationTemplates.pm (+579 lines)
Line 0 Link Here
1
package Koha::MarcModificationTemplates;
2
3
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
## NOTE:
21
## Parts of this module are used from cgi scripts that are detached from apache before
22
## execution. For this reason, the C4::Koha::Log function has been used to capture
23
## output for debugging purposes.
24
25
use strict;
26
use warnings;
27
28
use DateTime;
29
30
use C4::Context;
31
use Koha::SimpleMARC;
32
33
use vars qw($VERSION @ISA @EXPORT);
34
35
use constant DEBUG => 0;
36
37
BEGIN {
38
	$VERSION = 1.00;	# set the version for version checking
39
	@ISA = qw(Exporter);
40
	@EXPORT = qw(
41
		&GetModificationTemplates
42
		&AddModificationTemplate
43
		&DelModificationTemplate
44
45
		&GetModificationTemplateAction
46
		&GetModificationTemplateActions
47
48
		&AddModificationTemplateAction
49
		&ModModificationTemplateAction
50
		&DelModificationTemplateAction
51
		&MoveModificationTemplateAction
52
53
                &ModifyRecordsWithTemplate
54
		&ModifyRecordWithTemplate
55
	);
56
}
57
58
59
=head1 NAME
60
61
Koha::MarcModificationTemplates - Module to manage MARC Modification Templates
62
63
=head1 DESCRIPTION
64
65
MARC Modification Templates are a tool for marc batch imports,
66
so that librarians can set up templates for various vendors'
67
files telling Koha what fields to insert data into.
68
69
=head1 FUNCTIONS
70
71
=cut
72
73
=head2 GetModificationTemplates
74
75
  my @templates = GetModificationTemplates( [ $template_id ] );
76
77
  Passing a $template_id will mark the given id as the selected template.
78
=cut
79
80
sub GetModificationTemplates {
81
  my ( $template_id ) = @_;
82
  C4::Koha::Log("Koha::MarcModificationTemplates::GetModificationTemplates( $template_id )") if DEBUG;
83
  warn("Koha::MarcModificationTemplates::GetModificationTemplates( $template_id )") if DEBUG;
84
85
  my $dbh = C4::Context->dbh;
86
  my $sth = $dbh->prepare("SELECT * FROM marc_modification_templates");
87
  $sth->execute();
88
89
  my @templates;
90
  while ( my $template = $sth->fetchrow_hashref() ) {
91
    $template->{'selected'} = 1 if ( $template->{'template_id'} eq $template_id );
92
    push( @templates, $template );
93
  }
94
95
  return @templates;
96
}
97
98
=head2
99
  AddModificationTemplate
100
101
  $template_id = AddModificationTemplate( $template_name[, $template_id ] );
102
103
  If $template_id is supplied, the actions from that template will be copied
104
  into the newly created template.
105
=cut
106
107
sub AddModificationTemplate {
108
  my ( $template_name, $template_id_copy ) = @_;
109
110
  my $dbh = C4::Context->dbh;
111
  my $sth = $dbh->prepare("INSERT INTO marc_modification_templates ( name ) VALUES ( ? )");
112
  $sth->execute( $template_name );
113
114
  $sth = $dbh->prepare("SELECT * FROM marc_modification_templates WHERE name = ?");
115
  $sth->execute( $template_name );
116
  my $row = $sth->fetchrow_hashref();
117
  my $template_id = $row->{'template_id'};
118
119
  if ( $template_id_copy ) {
120
    my @actions = GetModificationTemplateActions( $template_id_copy );
121
    foreach my $action ( @actions ) {
122
      AddModificationTemplateAction(
123
        $template_id,
124
        $action->{'action'},
125
        $action->{'field_number'},
126
        $action->{'from_field'},
127
        $action->{'from_subfield'},
128
        $action->{'field_value'},
129
        $action->{'to_field'},
130
        $action->{'to_subfield'},
131
        $action->{'to_regex'},
132
        $action->{'conditional'},
133
        $action->{'conditional_field'},
134
        $action->{'conditional_subfield'},
135
        $action->{'conditional_comparison'},
136
        $action->{'conditional_value'},
137
        $action->{'conditional_regex'},
138
        $action->{'description'},
139
      );
140
141
    }
142
  }
143
144
  return $template_id;
145
}
146
147
=head2
148
  DelModificationTemplate
149
150
  DelModificationTemplate( $template_id );
151
=cut
152
153
sub DelModificationTemplate {
154
  my ( $template_id ) = @_;
155
156
  my $dbh = C4::Context->dbh;
157
  my $sth = $dbh->prepare("DELETE FROM marc_modification_templates WHERE template_id = ?");
158
  $sth->execute( $template_id );
159
160
  $sth = $dbh->prepare("DELETE FROM marc_modification_template_actions WHERE template_id = ?");
161
  $sth->execute( $template_id );
162
}
163
164
=head2
165
  GetModificationTemplateAction
166
167
  my $action = GetModificationTemplateAction( $mmta_id );
168
=cut
169
170
sub GetModificationTemplateAction {
171
  my ( $mmta_id ) = @_;
172
173
  my $dbh = C4::Context->dbh;
174
  my $sth = $dbh->prepare("SELECT * FROM marc_modification_template_actions WHERE mmta_id = ?");
175
  $sth->execute( $mmta_id );
176
  my $action = $sth->fetchrow_hashref();
177
178
  return $action;
179
}
180
181
=head2
182
  GetModificationTemplateActions
183
184
  my @actions = GetModificationTemplateActions( $template_id );
185
=cut
186
187
sub GetModificationTemplateActions {
188
  my ( $template_id ) = @_;
189
190
  C4::Koha::Log( "Koha::MarcModificationTemplates::GetModificationTemplateActions( $template_id )" ) if DEBUG;
191
  warn( "Koha::MarcModificationTemplates::GetModificationTemplateActions( $template_id )" ) if DEBUG;
192
193
  my $dbh = C4::Context->dbh;
194
  my $sth = $dbh->prepare("SELECT * FROM marc_modification_template_actions WHERE template_id = ? ORDER BY ordering");
195
  $sth->execute( $template_id );
196
197
  my @actions;
198
  while ( my $action = $sth->fetchrow_hashref() ) {
199
    push( @actions, $action );
200
  }
201
202
  C4::Koha::Log( Data::Dumper::Dumper( @actions ) ) if DEBUG > 4;
203
  warn( Data::Dumper::Dumper( @actions ) ) if DEBUG > 4;
204
205
  return @actions;
206
}
207
208
=head2
209
  AddModificationTemplateAction
210
211
  AddModificationTemplateAction(
212
    $template_id, $action, $field_number,
213
    $from_field, $from_subfield, $field_value,
214
    $to_field, $to_subfield, $to_regex,
215
    $conditional, $conditional_field, $conditional_subfield,
216
    $conditional_comparison, $conditional_value,
217
    $conditional_regex, $description
218
  );
219
220
  Adds a new action to the given modification template.
221
222
=cut
223
224
sub AddModificationTemplateAction {
225
  my (
226
    $template_id,
227
    $action,
228
    $field_number,
229
    $from_field,
230
    $from_subfield,
231
    $field_value,
232
    $to_field,
233
    $to_subfield,
234
    $to_regex,
235
    $conditional,
236
    $conditional_field,
237
    $conditional_subfield,
238
    $conditional_comparison,
239
    $conditional_value,
240
    $conditional_regex,
241
    $description
242
  ) = @_;
243
244
  C4::Koha::Log( "Koha::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
245
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
246
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
247
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
248
  warn( "Koha::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
249
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
250
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
251
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
252
253
  $conditional_regex ||= '0';
254
255
  my $dbh = C4::Context->dbh;
256
  my $sth = $dbh->prepare( 'SELECT MAX(ordering) + 1 AS next_ordering FROM marc_modification_template_actions WHERE template_id = ?' );
257
  $sth->execute( $template_id );
258
  my $row = $sth->fetchrow_hashref;
259
  my $ordering = $row->{'next_ordering'} || 1;
260
261
  my $query = "
262
  INSERT INTO marc_modification_template_actions (
263
  mmta_id,
264
  template_id,
265
  ordering,
266
  action,
267
  field_number,
268
  from_field,
269
  from_subfield,
270
  field_value,
271
  to_field,
272
  to_subfield,
273
  to_regex,
274
  conditional,
275
  conditional_field,
276
  conditional_subfield,
277
  conditional_comparison,
278
  conditional_value,
279
  conditional_regex,
280
  description
281
  )
282
  VALUES ( NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
283
284
  $sth = $dbh->prepare( $query );
285
286
  $sth->execute(
287
    $template_id,
288
    $ordering,
289
    $action,
290
    $field_number,
291
    $from_field,
292
    $from_subfield,
293
    $field_value,
294
    $to_field,
295
    $to_subfield,
296
    $to_regex,
297
    $conditional,
298
    $conditional_field,
299
    $conditional_subfield,
300
    $conditional_comparison,
301
    $conditional_value,
302
    $conditional_regex,
303
    $description
304
  );
305
}
306
307
=head2
308
  ModModificationTemplateAction
309
310
  ModModificationTemplateAction(
311
    $mmta_id, $action, $field_number, $from_field,
312
    $from_subfield, $field_value, $to_field,
313
    $to_subfield, $to_regex, $conditional,
314
    $conditional_field, $conditional_subfield,
315
    $conditional_comparison, $conditional_value,
316
    $conditional_regex, $description
317
  );
318
319
  Modifies an existing action.
320
321
=cut
322
323
sub ModModificationTemplateAction {
324
  my (
325
    $mmta_id,
326
    $action,
327
    $field_number,
328
    $from_field,
329
    $from_subfield,
330
    $field_value,
331
    $to_field,
332
    $to_subfield,
333
    $to_regex,
334
    $conditional,
335
    $conditional_field,
336
    $conditional_subfield,
337
    $conditional_comparison,
338
    $conditional_value,
339
    $conditional_regex,
340
    $description
341
  ) = @_;
342
343
  my $dbh = C4::Context->dbh;
344
345
  my $query = "
346
  UPDATE marc_modification_template_actions SET
347
  action = ?,
348
  field_number = ?,
349
  from_field = ?,
350
  from_subfield = ?,
351
  field_value = ?,
352
  to_field = ?,
353
  to_subfield = ?,
354
  to_regex = ?,
355
  conditional = ?,
356
  conditional_field = ?,
357
  conditional_subfield = ?,
358
  conditional_comparison = ?,
359
  conditional_value = ?,
360
  conditional_regex = ?,
361
  description = ?
362
  WHERE mmta_id = ?";
363
364
  my $sth = $dbh->prepare( $query );
365
366
  $sth->execute(
367
    $action,
368
    $field_number,
369
    $from_field,
370
    $from_subfield,
371
    $field_value,
372
    $to_field,
373
    $to_subfield,
374
    $to_regex,
375
    $conditional,
376
    $conditional_field,
377
    $conditional_subfield,
378
    $conditional_comparison,
379
    $conditional_value,
380
    $conditional_regex,
381
    $description,
382
    $mmta_id
383
  );
384
}
385
386
387
=head2
388
  DelModificationTemplateAction
389
390
  DelModificationTemplateAction( $mmta_id );
391
392
  Deletes the given template action.
393
=cut
394
395
sub DelModificationTemplateAction {
396
  my ( $mmta_id ) = @_;
397
398
  my $action = GetModificationTemplateAction( $mmta_id );
399
400
  my $dbh = C4::Context->dbh;
401
  my $sth = $dbh->prepare("DELETE FROM marc_modification_template_actions WHERE mmta_id = ?");
402
  $sth->execute( $mmta_id );
403
404
  $sth = $dbh->prepare("UPDATE marc_modification_template_actions SET ordering = ordering - 1 WHERE template_id = ? AND ordering > ?");
405
  $sth->execute( $action->{'template_id'}, $action->{'ordering'} );
406
}
407
408
=head2
409
  MoveModificationTemplateAction
410
411
  MoveModificationTemplateAction( $mmta_id, $where );
412
413
  Changes the order for the given action.
414
  Options for $where are 'up', 'down', 'top' and 'bottom'
415
=cut
416
sub MoveModificationTemplateAction {
417
  my ( $mmta_id, $where ) = @_;
418
419
  my $action = GetModificationTemplateAction( $mmta_id );
420
421
  return if ( $action->{'ordering'} eq '1' && ( $where eq 'up' || $where eq 'top' ) );
422
  return if ( $action->{'ordering'} eq GetModificationTemplateActions( $action->{'template_id'} ) && ( $where eq 'down' || $where eq 'bottom' ) );
423
424
  my $dbh = C4::Context->dbh;
425
  my ( $sth, $query );
426
427
  if ( $where eq 'up' || $where eq 'down' ) {
428
429
    ## For up and down, we just swap the ordering number with the one above or below it.
430
431
    ## Change the ordering for the other action
432
    $query = "UPDATE marc_modification_template_actions SET ordering = ? WHERE template_id = ? AND ordering = ?";
433
434
    my $ordering = $action->{'ordering'};
435
    $ordering-- if ( $where eq 'up' );
436
    $ordering++ if ( $where eq 'down' );
437
438
    $sth = $dbh->prepare( $query );
439
    $sth->execute( $action->{'ordering'}, $action->{'template_id'}, $ordering );
440
441
    ## Change the ordering for this action
442
    $query = "UPDATE marc_modification_template_actions SET ordering = ? WHERE mmta_id = ?";
443
    $sth = $dbh->prepare( $query );
444
    $sth->execute( $ordering, $action->{'mmta_id'} );
445
446
  } elsif ( $where eq 'top' ) {
447
448
    $sth = $dbh->prepare('UPDATE marc_modification_template_actions SET ordering = ordering + 1 WHERE template_id = ? AND ordering < ?');
449
    $sth->execute( $action->{'template_id'}, $action->{'ordering'} );
450
451
    $sth = $dbh->prepare('UPDATE marc_modification_template_actions SET ordering = 1 WHERE mmta_id = ?');
452
    $sth->execute( $mmta_id );
453
454
  } elsif ( $where eq 'bottom' ) {
455
456
    my $ordering = GetModificationTemplateActions( $action->{'template_id'} );
457
458
    $sth = $dbh->prepare('UPDATE marc_modification_template_actions SET ordering = ordering - 1 WHERE template_id = ? AND ordering > ?');
459
    $sth->execute( $action->{'template_id'}, $action->{'ordering'} );
460
461
    $sth = $dbh->prepare('UPDATE marc_modification_template_actions SET ordering = ? WHERE mmta_id = ?');
462
    $sth->execute( $ordering, $mmta_id );
463
464
  }
465
466
}
467
468
=head2
469
  ModifyRecordsWithTemplate
470
471
  ModifyRecordsWithTemplate( $template_id, $batch );
472
473
  Accepts a template id and a MARC::Batch object.
474
=cut
475
476
sub ModifyRecordsWithTemplate {
477
  my ( $template_id, $batch ) = @_;
478
  C4::Koha::Log( "Koha::MarcModificationTemplates::ModifyRecordsWithTemplate( $template_id, $batch )" ) if DEBUG;
479
  warn( "Koha::MarcModificationTemplates::ModifyRecordsWithTemplate( $template_id, $batch )" ) if DEBUG;
480
481
  while ( my $record = $batch->next() ) {
482
    ModifyRecordWithTemplate( $template_id, $record );
483
  }
484
}
485
486
=head2
487
  ModifyRecordWithTemplate
488
489
  ModifyRecordWithTemplate( $template_id, $record )
490
491
  Accepts a MARC::Record object ( $record ) and modifies
492
  it based on the actions for the given $template_id
493
=cut
494
495
sub ModifyRecordWithTemplate {
496
  my ( $template_id, $record ) = @_;
497
  C4::Koha::Log( "Koha::MarcModificationTemplates::ModifyRecordWithTemplate( $template_id, $record )" ) if DEBUG;
498
  warn( "Koha::MarcModificationTemplates::ModifyRecordWithTemplate( $template_id, $record )" ) if DEBUG;
499
  C4::Koha::Log( "Unmodified Record:\n" . $record->as_formatted() ) if DEBUG >= 10;
500
  warn( "Unmodified Record:\n" . $record->as_formatted() ) if DEBUG >= 10;
501
502
  my $current_date = DateTime->now()->ymd();
503
  my $branchcode = C4::Context->userenv->{branch};
504
505
  my @actions = GetModificationTemplateActions( $template_id );
506
507
  foreach my $a ( @actions ) {
508
    my $action = $a->{'action'};
509
    my $field_number = $a->{'field_number'};
510
    my $from_field = $a->{'from_field'};
511
    my $from_subfield = $a->{'from_subfield'};
512
    my $field_value = $a->{'field_value'};
513
    my $to_field = $a->{'to_field'};
514
    my $to_subfield = $a->{'to_subfield'};
515
    my $to_regex = $a->{'to_regex'};
516
    my $conditional = $a->{'conditional'};
517
    my $conditional_field = $a->{'conditional_field'};
518
    my $conditional_subfield = $a->{'conditional_subfield'};
519
    my $conditional_comparison = $a->{'conditional_comparison'};
520
    my $conditional_value = $a->{'conditional_value'};
521
    my $conditional_regex = $a->{'conditional_regex'};
522
523
    my $eval = "$action( \$record, '$from_field', '$from_subfield', ";
524
525
    if ( $field_value ) {
526
      C4::Koha::Log( "Field value before replacements: $field_value" ) if ( DEBUG >= 3 );
527
      warn( "Field value before replacements: $field_value" ) if ( DEBUG >= 3 );
528
529
      $field_value =~ s/__CURRENTDATE__/$current_date/g;
530
      $field_value =~ s/__BRANCHCODE__/$branchcode/g;
531
532
      $eval .= " '$field_value' ";
533
534
      C4::Koha::Log( "Field value after replacements: $field_value" ) if ( DEBUG >= 3 );
535
      warn( "Field value after replacements: $field_value" ) if ( DEBUG >= 3 );
536
    } elsif ( $to_field ) {
537
      $eval .= " '$to_field', '$to_subfield', '$to_regex' ";
538
    }
539
540
    $eval .= ", '$field_number' " if ( $field_number );
541
    $eval .= ') ';
542
543
    if ( $conditional ) {
544
      $eval .= " $conditional ( ";
545
546
      if ( $conditional_comparison eq 'exists' ) {
547
        $eval .= "field_exists( \$record, '$conditional_field', '$conditional_subfield' )";
548
549
      } elsif ( $conditional_comparison eq 'not_exists' ) {
550
        $eval .= "!field_exists( \$record, '$conditional_field', '$conditional_subfield' )";
551
552
      } elsif ( $conditional_comparison eq 'equals' ) {
553
        $eval .= "field_equals( \$record, '$conditional_value', '$conditional_field', '$conditional_subfield', '$conditional_regex' ) ";
554
555
      } elsif ( $conditional_comparison eq 'not_equals' ) {
556
        $eval .= "!field_equals( \$record, '$conditional_value', '$conditional_field', '$conditional_subfield', '$conditional_regex' ) ";
557
      }
558
559
      $eval .= " )";
560
    }
561
562
    $eval .= ";";
563
564
    C4::Koha::Log("eval $eval") if DEBUG >= 2;
565
    warn("eval $eval") if DEBUG >= 2;
566
    eval $eval;
567
    C4::Koha::Log( $record->as_formatted() ) if DEBUG >= 10;
568
    warn( $record->as_formatted() ) if DEBUG >= 10;
569
570
  }
571
}
572
1;
573
__END__
574
575
=head1 AUTHOR
576
577
Kyle M Hall
578
579
=cut
(-)a/Koha/SimpleMARC.pm (+331 lines)
Line 0 Link Here
1
package Koha::SimpleMARC;
2
3
# Copyright 2009 Kyle M. Hall <kyle.m.hall@gmail.com>
4
5
use strict;
6
use warnings;
7
8
#use MARC::Record;
9
10
require Exporter;
11
12
our @ISA = qw(Exporter);
13
our %EXPORT_TAGS = ( 'all' => [ qw(
14
15
) ] );
16
17
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
18
19
our @EXPORT = qw(
20
  read_field
21
  update_field
22
  copy_field
23
  move_field
24
  delete_field
25
  field_exists
26
  field_equals
27
);
28
29
our $VERSION = '0.01';
30
31
our $debug = 0;
32
33
=head1 NAME
34
35
SimpleMARC - Perl modle for making simple MARC record alterations.
36
37
=head1 SYNOPSIS
38
39
  use SimpleMARC;
40
41
=head1 DESCRIPTION
42
43
SimpleMARC is designed to make writing scripts
44
to modify MARC records simple and easy.
45
46
Every function in the modules requires a
47
MARC::Record object as its first parameter.
48
49
=head1 AUTHOR
50
51
Kyle Hall <lt>kyle.m.hall@gmail.com<gt>
52
53
=head1 COPYRIGHT AND LICENSE
54
55
Copyright (C) 2009 by Kyle Hall
56
57
This library is free software; you can redistribute it and/or modify
58
it under the same terms as Perl itself, either Perl version 5.8.7 or,
59
at your option, any later version of Perl 5 you may have available.
60
61
=head1 FUNCTIONS
62
63
=head2
64
65
  copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName[, $regex[, $n ] ] );
66
67
  Copies a value from one field to another. If a regular expression ( $regex ) is supplied,
68
  the value will be transformed by the given regex before being copied into the new field.
69
  Example: $regex = 's/Old Text/Replacement Text/'
70
71
  If $n is passed, copy_field will only copy the Nth field of the list of fields.
72
  E.g. $n = 1 will only use the first field's value, $n = 2 will use only the 2nd field's value.
73
74
=cut
75
76
sub copy_field {
77
  my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_;
78
  C4::Koha::Log( "C4::SimpleMARC::copy_field( '$record', '$fromFieldName', '$fromSubfieldName', '$toFieldName', '$toSubfieldName', '$regex', '$n' )" ) if $debug;
79
80
  if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; }
81
82
  my @values = read_field( $record, $fromFieldName, $fromSubfieldName );
83
  @values = ( $values[$n-1] ) if ( $n );
84
  C4::Koha::Log( "@values = read_field( $record, $fromFieldName, $fromSubfieldName )" ) if $debug >= 3;
85
86
  if ( $regex ) {
87
    foreach my $value ( @values ) {
88
      C4::Koha::Log( "\$value =~ s$regex" ) if ( $debug >= 3 );
89
      eval "\$value =~ s$regex";
90
    }
91
  }
92
93
  update_field( $record, $toFieldName, $toSubfieldName, @values );
94
95
}
96
97
=head2
98
99
  update_field( $record, $fieldName, $subfieldName, $value[, $value,[ $value ... ] ] );
100
101
  Updates a field with the given value, creating it if neccessary.
102
103
  If multiple values are supplied, they will be used to update a list of repeatable fields
104
  until either the fields or the values are all used.
105
106
  If a single value is supplied for a repeated field, that value will be used to update
107
  each of the repeated fields.
108
109
=cut
110
111
sub update_field {
112
  my ( $record, $fieldName, $subfieldName, @values ) = @_;
113
  C4::Koha::Log( "C4::SimpleMARC::update_field( $record, $fieldName, $subfieldName, @values )" ) if $debug;
114
115
  if ( ! ( $record && $fieldName ) ) { return; }
116
117
  if ( @values eq 1 ) {
118
    _update_repeatable_field_with_single_value( $record, $fieldName, $subfieldName, @values );
119
    return;
120
  }
121
122
  my $i = 0;
123
  my $field;
124
  if ( $subfieldName ) {
125
    if ( my @fields = $record->field( $fieldName ) ) {
126
      foreach my $field ( @fields ) {
127
        $field->update( "$subfieldName" => $values[$i++] );
128
      }
129
    } else {
130
      ## Field does not exist, create it.
131
      foreach my $value ( @values ) {
132
        $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $values[$i++] );
133
        $record->append_fields( $field );
134
      }
135
    }
136
  } else { ## No subfield
137
    if ( my @fields = $record->field( $fieldName ) ) {
138
      foreach my $field ( @fields ) {
139
        $field->update( $values[$i++] );
140
      }
141
    } else {
142
      ## Field does not exists, create it
143
      foreach my $value ( @values ) {
144
        $field = MARC::Field->new( $fieldName, $value );
145
        $record->append_fields( $field );
146
      }
147
    }
148
  }
149
}
150
151
=head2
152
153
  my @values = read_field( $record, $fieldName[, $subfieldName, [, $n ] ] );
154
155
  Returns an array of field values for the given field and subfield
156
157
  If $n is given, it will return only the $nth value of the array.
158
  E.g. If $n = 1, it return the 1st value, if $n = 3, it will return the 3rd value.
159
160
=cut
161
162
sub read_field {
163
  my ( $record, $fieldName, $subfieldName, $n ) = @_;
164
  C4::Koha::Log( "C4::SimpleMARC::read_field( '$record', '$fieldName', '$subfieldName', '$n' )" ) if $debug;
165
166
  my @fields = $record->field( $fieldName );
167
168
  return @fields unless $subfieldName;
169
170
  my @subfields;
171
  foreach my $field ( @fields ) {
172
    my @sf = $field->subfield( $subfieldName );
173
    push( @subfields, @sf );
174
  }
175
176
  if ( $n ) {
177
    return $subfields[$n-1];
178
  } else {
179
    return @subfields;
180
  }
181
}
182
183
=head2
184
185
  $bool = field_exists( $record, $fieldName[, $subfieldName ]);
186
187
  Returns true if the field exits, false otherwise.
188
189
=cut
190
191
sub field_exists {
192
  my ( $record, $fieldName, $subfieldName ) = @_;
193
  C4::Koha::Log( "C4::SimpleMARC::field_exists( $record, $fieldName, $subfieldName )" ) if $debug;
194
195
  if ( ! $record ) { return; }
196
197
  my $return = 0;
198
  if ( $fieldName && $subfieldName ) {
199
    $return = $record->field( $fieldName ) && $record->subfield( $fieldName, $subfieldName );
200
  } elsif ( $fieldName ) {
201
    $return = $record->field( $fieldName ) && 1;
202
  }
203
204
  C4::Koha::Log( "C4:SimpleMARC::field_exists: Returning '$return'" ) if $debug >= 2;
205
  return $return;
206
}
207
208
=head2
209
210
  $bool = field_equals( $record, $value, $fieldName[, $subfieldName[, $regex [, $n ] ] ]);
211
212
  Returns true if the field equals the given value, false otherwise.
213
214
  If a regular expression ( $regex ) is supplied, the value will be compared using
215
  the given regex. Example: $regex = 'm/sought_text/'
216
217
  If $n is passed, the Nth field of a repeatable series will be used for comparison.
218
  Set $n to 1 or leave empty for a non-repeatable field.
219
220
=cut
221
222
sub field_equals {
223
  my ( $record, $value, $fieldName, $subfieldName, $regex, $n ) = @_;
224
  $n = 1 unless ( $n ); ## $n defaults to first field of a repeatable field series
225
  C4::Koha::Log( "C4::SimpleMARC::field_equals( '$record', '$value', '$fieldName', '$subfieldName', '$regex', '$n')" ) if $debug;
226
227
  if ( ! $record ) { return; }
228
229
  my @field_values = read_field( $record, $fieldName, $subfieldName, $n );
230
  my $field_value = $field_values[$n-1];
231
232
  if ( $regex ) {
233
    C4::Koha::Log( "Testing '$field_value' =~ m$value" ) if $debug >= 3;
234
    return eval "\$field_value =~ m$value";
235
  } else {
236
    return $field_value eq $value;
237
  }
238
}
239
240
=head2
241
242
  move_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName[, $regex [, $n ] ] );
243
244
  Moves a value from one field to another. If a regular expression ( $regex ) is supplied,
245
  the value will be transformed by the given regex before being moved into the new field.
246
  Example: $regex = 's/Old Text/Replacement Text/'
247
248
  If $n is passed, only the Nth field will be moved. $n = 1
249
  will move the first repeatable field, $n = 3 will move the third.
250
251
=cut
252
253
sub move_field {
254
  my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_;
255
  C4::Koha::Log( "C4::SimpleMARC::move_field( '$record', '$fromFieldName', '$fromSubfieldName', '$toFieldName', '$toSubfieldName', '$regex', '$n' )" ) if $debug;
256
  copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n );
257
  delete_field( $record, $fromFieldName, $fromSubfieldName, $n );
258
}
259
260
=head2
261
262
  delete_field( $record, $fieldName[, $subfieldName [, $n ] ] );
263
264
  Deletes the given field.
265
266
  If $n is passed, only the Nth field will be deleted. $n = 1
267
  will delete the first repeatable field, $n = 3 will delete the third.
268
269
=cut
270
271
sub delete_field {
272
  my ( $record, $fieldName, $subfieldName, $n ) = @_;
273
  C4::Koha::Log( "C4::SimpleMARC::delete_field( '$record', '$fieldName', '$subfieldName', '$n' )" ) if $debug;
274
275
  my @fields = $record->field( $fieldName );
276
277
  @fields = ( $fields[$n-1] ) if ( $n );
278
279
  if ( @fields && !$subfieldName ) {
280
    foreach my $field ( @fields ) {
281
      $record->delete_field( $field );
282
    }
283
  } elsif ( @fields && $subfieldName ) {
284
    foreach my $field ( @fields ) {
285
      $field->delete_subfield( code => $subfieldName );
286
    }
287
  }
288
}
289
290
=head2
291
292
  _update_repeatable_field_with_single_value( $record, $fieldName, $subfieldName, $value );
293
294
  Updates a repeatable field, giving all existing copies of that field the given value.
295
296
  This is an internal function, and thus is not exported.
297
298
=cut
299
300
sub _update_repeatable_field_with_single_value {
301
  my ( $record, $fieldName, $subfieldName, $value ) = @_;
302
  C4::Koha::Log( "C4::SimpleMARC::_update_repeatable_field_with_single_value( $record, $fieldName, $subfieldName, $value )" ) if $debug;
303
304
  if ( ! ( $record && $fieldName ) ) { return; }
305
306
  my $field;
307
  if ( $subfieldName ) {
308
    if ( my @fields = $record->field( $fieldName ) ) {
309
      foreach my $field ( @fields ) {
310
        $field->update( "$subfieldName" => $value );
311
      }
312
    } else {
313
      ## Field does not exist, create it.
314
      $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value );
315
      $record->append_fields( $field );
316
    }
317
  } else { ## No subfield
318
    if ( my @fields = $record->field( $fieldName ) ) {
319
      foreach my $field ( @fields ) {
320
        $field->update( $value );
321
      }
322
    } else {
323
      ## Field does not exists, create it
324
      $field = MARC::Field->new( $fieldName, $value );
325
      $record->append_fields( $field );
326
    }
327
  }
328
}
329
330
1;
331
__END__
(-)a/installer/data/mysql/en/mandatory/userpermissions.sql (+1 lines)
Lines 43-48 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
43
   (13, 'moderate_tags', 'Moderate patron tags'),
43
   (13, 'moderate_tags', 'Moderate patron tags'),
44
   (13, 'rotating_collections', 'Manage rotating collections'),
44
   (13, 'rotating_collections', 'Manage rotating collections'),
45
   (13, 'upload_local_cover_images', 'Upload local cover images'),
45
   (13, 'upload_local_cover_images', 'Upload local cover images'),
46
   (13, 'marc_modification_templates', 'Manage marc modification templates'),
46
   (15, 'check_expiration', 'Check the expiration of a serial'),
47
   (15, 'check_expiration', 'Check the expiration of a serial'),
47
   (15, 'claim_serials', 'Claim missing serials'),
48
   (15, 'claim_serials', 'Claim missing serials'),
48
   (15, 'create_subscription', 'Create a new subscription'),
49
   (15, 'create_subscription', 'Create a new subscription'),
(-)a/installer/data/mysql/kohastructure.sql (+36 lines)
Lines 3232-3237 CREATE TABLE IF NOT EXISTS plugin_data ( Link Here
3232
  PRIMARY KEY (plugin_class,plugin_key)
3232
  PRIMARY KEY (plugin_class,plugin_key)
3233
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3233
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3234
3234
3235
--
3236
-- Table structure for table 'marc_modification_templates'
3237
--
3238
3239
CREATE TABLE IF NOT EXISTS marc_modification_templates (
3240
    template_id int(11) NOT NULL AUTO_INCREMENT,
3241
    name text NOT NULL,
3242
    PRIMARY KEY (template_id)
3243
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3244
3245
--
3246
-- Table structure for table 'marc_modification_template_actions'
3247
--
3248
3249
CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
3250
  mmta_id int(11) NOT NULL AUTO_INCREMENT,
3251
  template_id int(11) NOT NULL,
3252
  ordering int(3) NOT NULL,
3253
  action enum('delete_field','update_field','move_field','copy_field') NOT NULL,
3254
  field_number smallint(6) NOT NULL DEFAULT '0',
3255
  from_field varchar(3) NOT NULL,
3256
  from_subfield varchar(1) DEFAULT NULL,
3257
  field_value varchar(100) DEFAULT NULL,
3258
  to_field varchar(3) DEFAULT NULL,
3259
  to_subfield varchar(1) DEFAULT NULL,
3260
  to_regex text,
3261
  conditional enum('if','unless') DEFAULT NULL,
3262
  conditional_field varchar(3) DEFAULT NULL,
3263
  conditional_subfield varchar(1) DEFAULT NULL,
3264
  conditional_comparison enum('exists','not_exists','equals','not_equals') DEFAULT NULL,
3265
  conditional_value text,
3266
  conditional_regex tinyint(1) NOT NULL DEFAULT '0',
3267
  description text,
3268
  PRIMARY KEY (mmta_id)
3269
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3270
3235
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3271
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3236
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3272
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
3237
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
3273
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+39 lines)
Lines 7169-7174 if ( CheckVersion($DBversion) ) { Link Here
7169
    SetVersion ($DBversion);
7169
    SetVersion ($DBversion);
7170
}
7170
}
7171
7171
7172
$DBversion = "3.13.00.XXX";
7173
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
7174
    $dbh->do("CREATE TABLE IF NOT EXISTS marc_modification_templates (
7175
              template_id int(11) NOT NULL auto_increment,
7176
              name text NOT NULL,
7177
              PRIMARY KEY  (template_id)
7178
              ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;"
7179
    );
7180
7181
    $dbh->do("
7182
      CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
7183
      mmta_id int(11) NOT NULL auto_increment,
7184
      template_id int(11) NOT NULL,
7185
      ordering int(3) NOT NULL,
7186
      action enum('delete_field','update_field','move_field','copy_field') NOT NULL,
7187
      field_number smallint(6) NOT NULL default '0',
7188
      from_field varchar(3) NOT NULL,
7189
      from_subfield varchar(1) NULL,
7190
      field_value varchar(100) default NULL,
7191
      to_field varchar(3) default NULL,
7192
      to_subfield varchar(1) default NULL,
7193
      to_regex text,
7194
      conditional enum('if','unless') default NULL,
7195
      conditional_field varchar(3) default NULL,
7196
      conditional_subfield varchar(1) default NULL,
7197
      conditional_comparison enum('exists','not_exists','equals','not_equals') default NULL,
7198
      conditional_value text,
7199
      conditional_regex tinyint(1) NOT NULL default '0',
7200
      description text,
7201
      PRIMARY KEY  (mmta_id)
7202
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7203
    ");
7204
7205
    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('13', 'marc_modification_templates', 'Manage marc modification templates')");
7206
7207
    print "Upgrade to $DBversion done ( Bug 8015: Added tables for MARC Modification Framework )\n";
7208
    SetVersion($DBversion);
7209
}
7210
7172
=head1 FUNCTIONS
7211
=head1 FUNCTIONS
7173
7212
7174
=head2 TableExists($table)
7213
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc (+3 lines)
Lines 68-73 Link Here
68
    <li><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></li>
68
    <li><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></li>
69
    [% END %]
69
    [% END %]
70
-->
70
-->
71
    [% IF ( CAN_user_tools_marc_modification_templates ) %]
72
	<li><a href="/cgi-bin/koha/tools/marc_modification_templates.pl">Manage MARC modification templates</a></li>
73
    [% END %]
71
    [% IF ( CAN_user_tools_stage_marc_import ) %]
74
    [% IF ( CAN_user_tools_stage_marc_import ) %]
72
	<li><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC for import</a></li>
75
	<li><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC for import</a></li>
73
    [% END %]
76
    [% END %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (-2 / +2 lines)
Lines 68-75 Link Here
68
	<dd>Create and manage Bibliographic frameworks that define the characteristics of your MARC Records (field and subfield definitions) as well as templates for the MARC editor.</dd>
68
	<dd>Create and manage Bibliographic frameworks that define the characteristics of your MARC Records (field and subfield definitions) as well as templates for the MARC editor.</dd>
69
	<dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
69
	<dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
70
	<dd>Define the mapping between the Koha transactional database (SQL) and the MARC Bibliographic records. Note that the mapping can be defined through MARC Bibliographic Framework. This tool is just a shortcut to speed up linkage.</dd>
70
	<dd>Define the mapping between the Koha transactional database (SQL) and the MARC Bibliographic records. Note that the mapping can be defined through MARC Bibliographic Framework. This tool is just a shortcut to speed up linkage.</dd>
71
	<dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
71
        <dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
72
	<dd>Define the mapping between keywords and MARC fields, those keywords are used to find some datas independently of the framework.</dd>
72
        <dd>Define the mapping between keywords and MARC fields, those keywords are used to find some datas independently of the framework.</dd>
73
	<dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
73
	<dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
74
	<dd>Checks the MARC structure. If you change your MARC Bibliographic framework it's recommended that you run this tool to test for errors in your definition.</dd>
74
	<dd>Checks the MARC structure. If you change your MARC Bibliographic framework it's recommended that you run this tool to test for errors in your definition.</dd>
75
    <dt><a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a></dt>
75
    <dt><a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a></dt>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (+492 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; MARC Modification Templates</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
<script type="text/javascript">
6
//<![CDATA[
7
$(document).ready(function() {
8
        $('#select_template').find("input:submit").hide();
9
        $('#select_template').change(function() {
10
                $('#select_template').submit();
11
        });
12
});
13
//]]>
14
</script>
15
16
<script>
17
function onActionChange(selectObj) {
18
	// get the index of the selected option
19
	var idx = selectObj.selectedIndex;
20
21
	// get the value of the selected option
22
	var action = selectObj.options[idx].value;
23
24
	switch( action ) {
25
		case 'delete_field':
26
			show('field_number_block');
27
			hide('with_value_block');
28
			hide('to_field_block');
29
			break;
30
31
		case 'update_field':
32
			hide('field_number_block');
33
			show('with_value_block');
34
			hide('to_field_block');
35
			break;
36
37
		case 'move_field':
38
			show('field_number_block');
39
			hide('with_value_block');
40
			show('to_field_block');
41
			break;
42
43
		case 'copy_field':
44
			show('field_number_block');
45
			hide('with_value_block');
46
			show('to_field_block');
47
			break;
48
49
	}
50
}
51
52
function onConditionalChange(selectObj) {
53
        // get the index of the selected option
54
        var idx = selectObj.selectedIndex;
55
56
        // get the value of the selected option
57
        var action = selectObj.options[idx].value;
58
59
        switch( action ) {
60
                case '':
61
                        hide('conditional_block');
62
                        break;
63
64
                case 'if':
65
                case 'unless':
66
                        show('conditional_block');
67
                        break;
68
        }
69
}
70
71
function onConditionalComparisonChange(selectObj) {
72
        // get the index of the selected option
73
        var idx = selectObj.selectedIndex;
74
75
        // get the value of the selected option
76
        var action = selectObj.options[idx].value;
77
78
        switch( action ) {
79
                case 'equals':
80
                case 'not_equals':
81
                        show('conditional_comparison_block');
82
                        break;
83
84
		default:
85
                        hide('conditional_comparison_block');
86
                        break;
87
        }
88
}
89
90
function onToFieldRegexChange( checkboxObj ) {
91
	if ( checkboxObj.checked ) {
92
		show('to_field_regex_value_block');
93
	} else {
94
		hide('to_field_regex_value_block');
95
	}
96
}
97
98
function onConditionalRegexChange( checkboxObj ) {
99
        if ( checkboxObj.checked ) {
100
		document.getElementById( 'match_regex_prefix' ).style.visibility='visible';
101
        } else {
102
		document.getElementById( 'match_regex_prefix' ).style.visibility='hidden';
103
        }
104
}
105
106
function show(eltId) {
107
	elt = document.getElementById( eltId );
108
	elt.style.display='inline';
109
}
110
111
function hide(eltId) {
112
	clearFormElements( eltId );
113
	elt = document.getElementById( eltId );
114
	elt.style.display='none';
115
}
116
117
function clearFormElements(divId) {
118
	myBlock = document.getElementById( divId );
119
120
	var inputElements = myBlock.getElementsByTagName( "input" );
121
	for (var i = 0; i < inputElements.length; i++) {
122
		switch( inputElements[i].type ) {
123
			case "text":
124
				inputElements[i].value = '';
125
				break;
126
			case "checkbox":
127
				inputElements[i].checked = false;
128
				break;
129
		}
130
	}
131
132
	var selectElements = myBlock.getElementsByTagName( "select" );
133
	for (var i = 0; i < selectElements.length; i++) {
134
		selectElements[i].selectedIndex = 0;
135
	}
136
137
}
138
139
function confirmDelete() {
140
	var agree = confirm("Are you sure you wish to delete this template?");
141
	return agree;
142
}
143
144
var modaction_legend_innerhtml;
145
var action_submit_value;
146
147
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
148
	to_subfield, to_regex, conditional, conditional_field, conditional_subfield,
149
	conditional_comparison, conditional_value, conditional_regex, description
150
) {
151
	document.getElementById('mmta_id').value = mmta_id;
152
153
	setSelectByValue( 'action', action );
154
	document.getElementById('action').onchange();
155
156
	setSelectByValue( 'field_number', field_number );
157
158
	document.getElementById('from_field').value = from_field;
159
	document.getElementById('from_subfield').value = from_subfield;
160
	document.getElementById('field_value').value = field_value;
161
	document.getElementById('to_field').value = to_field;
162
	document.getElementById('to_subfield').value = to_subfield;
163
	document.getElementById('to_regex').value = to_regex;
164
165
	document.getElementById('to_field_regex').checked = to_regex.length;
166
	document.getElementById('to_field_regex').onchange();
167
168
	setSelectByValue( 'conditional', conditional );
169
	document.getElementById('conditional').onchange();
170
171
	document.getElementById('conditional_field').value = conditional_field;
172
	document.getElementById('conditional_subfield').value = conditional_subfield;
173
174
	setSelectByValue( 'conditional_comparison', conditional_comparison );
175
	document.getElementById('conditional_comparison').onchange();
176
177
	document.getElementById('conditional_value').value = conditional_value;
178
179
	document.getElementById('conditional_regex').checked = parseInt( conditional_regex );
180
181
	document.getElementById('description').value = description;
182
183
	window.modaction_legend_innerhtml = document.getElementById('modaction_legend').innerhtml;
184
	document.getElementById('modaction_legend').innerhtml = "Edit Action " + ordering;
185
186
	window.action_submit_value = document.getElementById('action_submit').value;
187
	document.getElementById('action_submit').value = "Update Action";
188
189
	show('cancel_edit');
190
}
191
192
function cancelEditAction() {
193
	document.getElementById('mmta_id').value = '';
194
195
	setSelectByValue( 'action', 'delete_field' );
196
	document.getElementById('action').onchange();
197
198
	document.getElementById('from_field').value = '';
199
	document.getElementById('from_subfield').value = '';
200
	document.getElementById('field_value').value = '';
201
	document.getElementById('to_field').value = '';
202
	document.getElementById('to_subfield').value = '';
203
	document.getElementById('to_regex').value = '';
204
205
	document.getElementById('to_field_regex').checked = false;
206
	document.getElementById('to_field_regex').onchange();
207
208
	setSelectByValue( 'conditional', '' );
209
	document.getElementById('conditional').onchange();
210
211
	document.getElementById('conditional_field').value = '';
212
	document.getElementById('conditional_subfield').value = '';
213
214
	setSelectByValue( 'conditional_comparison', '' );
215
	document.getElementById('conditional_comparison').onchange();
216
217
	document.getElementById('conditional_value').value = '';
218
219
	document.getElementById('conditional_regex').checked = false;
220
221
	document.getElementById('modaction_legend').innerhtml = window.modaction_legend_innerhtml;
222
	document.getElementById('action_submit').value = window.action_submit_value;
223
224
	hide('cancel_edit');
225
}
226
227
function setSelectByValue( selectId, value ) {
228
	s = document.getElementById( selectId );
229
230
	for ( i = 0; i < s.options.length; i++ ) {
231
		if ( s.options[i].value == value ) {
232
			s.selectedIndex = i;
233
		}
234
	}
235
}
236
237
</script>
238
239
</head>
240
241
<body>
242
[% INCLUDE 'header.inc' %]
243
[% INCLUDE 'cat-search.inc' %]
244
245
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; MARC Modification Templates</div>
246
247
<div id="doc3" class="yui-t2">
248
	<div id="yui-main">
249
		<div class="yui-b">
250
			<h2>MARC Modification Templates</h2>
251
252
			[% IF ( TemplatesLoop ) %]
253
254
				<form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="select_template">
255
					<label for="select_template">Template: </label>
256
					<select name="template_id" id="select_template" style="width:20em;">
257
						[% FOREACH TemplatesLoo IN TemplatesLoop %]
258
							<option value="[% TemplatesLoo.template_id %]" [% IF ( TemplatesLoo.selected ) %] selected [% END %] > [% TemplatesLoo.name %]</option>
259
						[% END %]
260
					</select>
261
					<input type="hidden" name="op" value="select_template">
262
					<input type="submit" value="Go" />
263
				</form>
264
265
				<form method="get" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="delete_template">
266
					<input type="hidden" name="template_id" value="[% template_id %]" />
267
					<input type="hidden" name="op" value="delete_template">
268
					<input type="submit" value="Delete Template" onClick="return confirmDelete()" />
269
				</form>
270
271
272
				[% IF ( ActionsLoop ) %]
273
					<table>
274
						<caption>Actions for this template</caption>
275
276
						<tr>
277
							<th>Change Order</th>
278
							<th>Order</th>
279
							<th>Action</th>
280
							<th>Description</th>
281
							<th>&nbsp</th>
282
							<th>&nbsp</th>
283
						</tr>
284
285
						[% FOREACH ActionsLoo IN ActionsLoop %]
286
							<tr>
287
        <td style="white-space:nowrap;">
288
	        <a title="Move Action Up" href="marc_modification_templates.pl?op=move_action&amp;where=up&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
289
			<img src="/intranet-tmpl/[% theme %]/img/go-up.png" border="0" alt="Go up" />
290
                </a>
291
292
		<a title="Move Action To Top" href="marc_modification_templates.pl?op=move_action&amp;where=top&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
293
			<img src="/intranet-tmpl/[% theme %]/img/go-top.png" border="0" alt="Go top" />
294
                </a>
295
296
                <a title="Move Action To Bottom" href="marc_modification_templates.pl?op=move_action&amp;where=bottom&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
297
			<img src="/intranet-tmpl/[% theme %]/img/go-bottom.png" border="0" alt="Go bottom" />
298
                </a>
299
300
                <a title="Move Action Down" href="marc_modification_templates.pl?op=move_action&amp;where=down&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
301
			<img src="/intranet-tmpl/[% theme %]/img/go-down.png" border="0" alt="Go down" />
302
                </a>
303
        </td>
304
305
								<td>[% ActionsLoo.ordering %]</td>
306
								<td>
307
									[% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
308
									[% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
309
									[% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
310
									[% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
311
312
									[% UNLESS ( ActionsLoo.action_update_field ) %]
313
										[% IF ( ActionsLoo.field_number ) %]
314
											1st
315
										[% END %]
316
									[% END %]
317
318
									field
319
320
									[% ActionsLoo.from_field %][% IF ( ActionsLoo.from_subfield ) %]$[% ActionsLoo.from_subfield %][% END %]
321
322
									[% IF ( ActionsLoo.field_value ) %]
323
										with value <i>[% ActionsLoo.field_value %]</i>
324
									[% END %]
325
326
									[% IF ( ActionsLoo.to_field ) %]
327
										to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
328
329
										[% IF ( ActionsLoo.to_regex ) %]
330
											 using RegEx s<strong>[% ActionsLoo.to_regex %]</strong>
331
										[% END %]
332
									[% END %]
333
334
									[% IF ( ActionsLoo.conditional ) %]
335
										[% IF ( ActionsLoo.conditional_if ) %] if [% END %]
336
										[% IF ( ActionsLoo.conditional_unless ) %] unless [% END %]
337
338
										[% ActionsLoo.conditional_field %][% IF ( ActionsLoo.conditional_subfield ) %]$[% ActionsLoo.conditional_subfield %][% END %]
339
340
										[% IF ( ActionsLoo.conditional_comparison_exists ) %] exists [% END %]
341
										[% IF ( ActionsLoo.conditional_comparison_not_exists ) %] does not exist [% END %]
342
										[% IF ( ActionsLoo.conditional_comparison_equals ) %] matches [% END %]
343
										[% IF ( ActionsLoo.conditional_comparison_not_equals ) %] does not match [% END %]
344
345
										[% IF ( ActionsLoo.conditional_regex ) %] RegEx m[% END %]<strong>[% ActionsLoo.conditional_value %]</strong>
346
									[% END %]
347
								</td>
348
								<td>[% ActionsLoo.description %]</td>
349
								<td><a href="#modaction" onclick='editAction(
350
													"[% ActionsLoo.mmta_id |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
351
													"[% ActionsLoo.ordering |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
352
													"[% ActionsLoo.action |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
353
													"[% ActionsLoo.field_number |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
354
													"[% ActionsLoo.from_field |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
355
													"[% ActionsLoo.from_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
356
													"[% ActionsLoo.field_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
357
													"[% ActionsLoo.to_field |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
358
													"[% ActionsLoo.to_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
359
													"[% ActionsLoo.to_regex |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
360
													"[% ActionsLoo.conditional |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
361
													"[% ActionsLoo.conditional_field |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
362
													"[% ActionsLoo.conditional_subfield |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
363
													"[% ActionsLoo.conditional_comparison |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
364
													"[% ActionsLoo.conditional_value |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
365
													"[% ActionsLoo.conditional_regex |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
366
													"[% ActionsLoo.description |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]"
367
												)'>Edit</a></td>
368
								<td><a href="marc_modification_templates.pl?template_id=[% ActionsLoo.template_id %]&op=delete_action&mmta_id=[% ActionsLoo.mmta_id %]">Delete</a></td>
369
							</tr>
370
						[% END %]
371
					</table>
372
				[% ELSE %]
373
					<div class="dialog message"><p>There are no defined actions for this template.</p></div>
374
				[% END %]
375
376
				<form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_action" >
377
					<a name="modaction"></a>
378
					<fieldset>
379
						<legend id="modaction_legend">Add A New Action</legend>
380
381
						<select name="action" id="action" onchange="onActionChange(this);">
382
							<option value="delete_field">Delete</option>
383
							<option value="update_field">Add/Update</option>
384
							<option value="move_field">Move</option>
385
							<option value="copy_field">Copy</option>
386
						</select>
387
388
						<span id="field_number_block">
389
							<select name="field_number" id="field_number">
390
								<option value="0">All</option>
391
								<option value="1">1st</option>
392
							</select>
393
						</span>
394
395
						field(s) <input type="text" name="from_field" id="from_field" size="3" maxlength="3" /> <input type="text" name="from_subfield" id="from_subfield" size="1" maxlength="1" />
396
397
						<span name="with_value_block" id="with_value_block" style="display:none;">
398
							with value <input type="text" name="field_value" id="field_value" />
399
						</span>
400
401
						<span name="to_field_block" id="to_field_block" style="display:none;">
402
							to field <input type="text" name="to_field" id="to_field" size="3" maxlength="3" /> <input type="text" name="to_subfield" id="to_subfield" size="1" maxlength="1" />
403
404
							<span name="to_field_regex_block" id="to_field_regex_block">
405
								<sup>
406
									<label for="to_field_regex">RegEx</label>
407
									<input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
408
409
									<span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
410
										s<input type="text" name="to_regex" id="to_regex" />
411
									</span>
412
								</sup>
413
							</span>
414
						</span>
415
416
						<p/>
417
418
						<select name="conditional" id="conditional" onchange="onConditionalChange(this);">
419
							<option value="" selected />
420
							<option value="if">if</option>
421
							<option value="unless">unless</option>
422
						</select>
423
424
						<span name="conditional_block" id="conditional_block" style="display:none;">
425
							field <input type="text" name="conditional_field" id="conditional_field" size="3" maxlength="3" /> <input type="text" name="conditional_subfield" id="conditional_subfield" size="1" maxlength="1" />
426
427
							<select name="conditional_comparison" id="conditional_comparison" onchange="onConditionalComparisonChange(this);">
428
								<option value="" />
429
								<option value="exists">exists</option>
430
								<option value="not_exists">doesn't exist</option>
431
								<option value="equals">matches</option>
432
								<option value="not_equals">doesn't match</option>
433
							</select>
434
435
							<span name="conditional_comparison_block" id="conditional_comparison_block" style="display:none;">
436
437
								<span id="match_regex_prefix" style="visibility:hidden;">m</span><input type="text" id="conditional_value" name="conditional_value" />
438
439
								<sup>
440
									<label for="conditional_regex">RegEx</label>
441
									<input type="checkbox" name="conditional_regex" id="conditional_regex" onchange="onConditionalRegexChange(this);" />
442
								</sup>
443
444
							</span>
445
						</span>
446
447
						<input type="hidden" name="template_id" value="[% template_id %]" />
448
						<input type="hidden" name="mmta_id" id="mmta_id" />
449
						<input type="hidden" name="op" value="add_action" />
450
451
						<br/><br/>
452
						<label for="description">Description:</label>
453
						<input type="text" name="description" id="description" size="60" />
454
455
						<br/><br/>
456
						<input id="action_submit" type="submit" value="Add Action" /> <a href="#modaction" id="cancel_edit" onclick="cancelEditAction();" style="display:none;">Cancel</a>
457
458
					</fieldset>
459
				</form>
460
461
			[% ELSE %]
462
				<div class="dialog message"><p>There are no defined templates. Please create a template first.</p></div>
463
			[% END %]
464
465
			<form method="post" action="/cgi-bin/koha/tools/marc_modification_templates.pl" id="add_template" >
466
				<fieldset>
467
					<legend>Create A New Template</legend>
468
469
					<label for="template_name">Name: </label>
470
					<input name="template_name" id="template_name" type="text" size="30" />
471
472
					<input type="hidden" name="op" value="create_template" />
473
					<input type="submit" value="Create Template" />
474
475
					[% IF ( template_id ) %]
476
						<input type="hidden" name="template_id" value="[% template_id %]" />
477
						<input type="checkbox" name="duplicate_current_template" id="duplicate_current_template" />
478
						<label for="duplicate_current_template">Duplicate Current Template</label>
479
					[% END %]
480
				</fieldset>
481
			</form>
482
483
484
485
		</div>
486
	</div>
487
488
	<div class="yui-b">
489
		[% INCLUDE 'tools-menu.inc' %]
490
	</div>
491
</div>
492
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (+17 lines)
Lines 117-122 function CheckForm(f) { Link Here
117
            <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></select>
117
            <select name="encoding" id="encoding"><option value="utf8" selected="selected">UTF-8 (Default)</option><option value="MARC-8">MARC 8</option><option value="ISO_5426">ISO 5426</option><option value="ISO_6937">ISO 6937</option><option value=ISO_8859-1">ISO 8859-1</option><option value="EUC-KR">EUC-KR</option></select>
118
	</li>
118
	</li>
119
</ol></fieldset>
119
</ol></fieldset>
120
  [% IF MarcModificationTemplatesLoop %]
121
    <fieldset class="rows">
122
      <legend>Use MARC Modification Template:</legend>
123
      <ol>
124
        <li>
125
          <label for="comments">Modify record using the following template: </label>
126
          <select name="marc_modification_template_id" id="marc_modification_template_id">
127
            <option value="">Do not use.</option>
128
              [% FOREACH mmt IN MarcModificationTemplatesLoop %]
129
                <option value="[% mmt.template_id %]">[% mmt.name %]</option>
130
              [% END %]
131
          </select>
132
        </li>
133
      </ol>
134
    </fieldset>
135
  [% END %]
136
120
  <fieldset class="rows">
137
  <fieldset class="rows">
121
    <legend>Look for existing records in catalog?</legend>
138
    <legend>Look for existing records in catalog?</legend>
122
    <ol><li><label for="matcher">Record matching rule:</label>
139
    <ol><li><label for="matcher">Record matching rule:</label>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (-1 / +6 lines)
Lines 140-149 Link Here
140
<!--
140
<!--
141
    [% IF ( CAN_user_tools_rotating_collections ) %]
141
    [% IF ( CAN_user_tools_rotating_collections ) %]
142
    <dt><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></dt>
142
    <dt><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></dt>
143
	<dd>Manage Rotating Collections</dd>
143
    <dd>Manage Rotating Collections</dd>
144
    [% END %]
144
    [% END %]
145
-->
145
-->
146
146
147
    [% IF ( CAN_user_tools_marc_modification_templates ) %]
148
    <dt><a href="/cgi-bin/koha/tools/marc_modification_templates.pl">MARC Modification Templates</a></dt>
149
    <dd>Manage templates for modifying MARC records during import.</dd>
150
    [% END %]
151
147
    [% IF ( CAN_user_tools_stage_marc_import ) %]
152
    [% IF ( CAN_user_tools_stage_marc_import ) %]
148
    <dt><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a></dt>
153
    <dt><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a></dt>
149
    <dd>Stage MARC records into the reservoir.</dd>
154
    <dd>Stage MARC records into the reservoir.</dd>
(-)a/tools/marc_modification_templates.pl (+151 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
# Copyright 2010 Kyle M Hall <kyle.m.hall@gmail.com>
3
#
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 2 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along
16
# with Koha; if not, write to the Free Software Foundation, Inc.,
17
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
use strict;
20
use warnings;
21
22
use CGI;
23
24
use C4::Auth;
25
use C4::Koha;
26
use C4::Output;
27
use Koha::MarcModificationTemplates;
28
29
my $cgi = new CGI;
30
31
my $op = $cgi->param('op');
32
my $template_id = $cgi->param('template_id');
33
34
my ($template, $loggedinuser, $cookie)
35
    = get_template_and_user({template_name => "tools/marc_modification_templates.tmpl",
36
			     query => $cgi,
37
			     type => "intranet",
38
			     authnotrequired => 0,
39
			     flagsrequired => { tools => 'marc_modfication_templates' },
40
			     debug => 1,
41
			     });
42
43
if ( $op eq "create_template" ) {
44
  $template_id = '' unless $cgi->param('duplicate_current_template');
45
  $template_id = AddModificationTemplate( $cgi->param('template_name'), $template_id );
46
47
} elsif ( $op eq "delete_template" ) {
48
49
  DelModificationTemplate( $template_id );
50
  $template_id = '';
51
52
} elsif ( $op eq "add_action" ) {
53
54
  my $mmta_id = $cgi->param('mmta_id');
55
  my $action = $cgi->param('action');
56
  my $field_number = $cgi->param('field_number');
57
  my $from_field = $cgi->param('from_field');
58
  my $from_subfield = $cgi->param('from_subfield');
59
  my $field_value = $cgi->param('field_value');
60
  my $to_field = $cgi->param('to_field');
61
  my $to_subfield = $cgi->param('to_subfield');
62
  my $to_regex = $cgi->param('to_regex');
63
  my $conditional = $cgi->param('conditional');
64
  my $conditional_field = $cgi->param('conditional_field');
65
  my $conditional_subfield = $cgi->param('conditional_subfield');
66
  my $conditional_comparison = $cgi->param('conditional_comparison');
67
  my $conditional_value = $cgi->param('conditional_value');
68
  my $conditional_regex = $cgi->param('conditional_regex') eq 'on';
69
  my $description = $cgi->param('description');
70
71
  unless ( $mmta_id ) {
72
    AddModificationTemplateAction(
73
      $template_id,
74
      $action,
75
      $field_number,
76
      $from_field,
77
      $from_subfield,
78
      $field_value,
79
      $to_field,
80
      $to_subfield,
81
      $to_regex,
82
      $conditional,
83
      $conditional_field,
84
      $conditional_subfield,
85
      $conditional_comparison,
86
      $conditional_value,
87
      $conditional_regex,
88
      $description
89
    );
90
  } else {
91
    ModModificationTemplateAction(
92
      $mmta_id,
93
      $action,
94
      $field_number,
95
      $from_field,
96
      $from_subfield,
97
      $field_value,
98
      $to_field,
99
      $to_subfield,
100
      $to_regex,
101
      $conditional,
102
      $conditional_field,
103
      $conditional_subfield,
104
      $conditional_comparison,
105
      $conditional_value,
106
      $conditional_regex,
107
      $description
108
    );
109
110
  }
111
112
} elsif ( $op eq "delete_action" ) {
113
  DelModificationTemplateAction( $cgi->param('mmta_id') );
114
115
} elsif ( $op eq "move_action" ) {
116
117
  MoveModificationTemplateAction( $cgi->param('mmta_id'), $cgi->param('where') );
118
119
}
120
121
my @templates = GetModificationTemplates( $template_id );
122
123
unless ( $template_id ) {
124
  $template_id = $templates[0]->{'template_id'};
125
  @templates = GetModificationTemplates( $template_id );
126
}
127
128
my @actions = GetModificationTemplateActions( $template_id );
129
foreach my $action ( @actions ) {
130
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
131
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
132
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
133
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
134
135
  $action->{'conditional_if'} = ( $action->{'conditional'} eq 'if' );
136
  $action->{'conditional_unless'} = ( $action->{'conditional'} eq 'unless' );
137
138
  $action->{'conditional_comparison_exists'} = ( $action->{'conditional_comparison'} eq 'exists' );
139
  $action->{'conditional_comparison_not_exists'} = ( $action->{'conditional_comparison'} eq 'not_exists' );
140
  $action->{'conditional_comparison_equals'} = ( $action->{'conditional_comparison'} eq 'equals' );
141
  $action->{'conditional_comparison_not_equals'} = ( $action->{'conditional_comparison'} eq 'not_equals' );
142
}
143
144
$template->param(
145
  TemplatesLoop => \@templates,
146
  ActionsLoop => \@actions,
147
148
  template_id => $template_id,
149
);
150
151
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/tools/stage-marc-import.pl (-2 / +10 lines)
Lines 41-46 use C4::ImportBatch; Link Here
41
use C4::Matcher;
41
use C4::Matcher;
42
use C4::UploadedFile;
42
use C4::UploadedFile;
43
use C4::BackgroundJob;
43
use C4::BackgroundJob;
44
use Koha::MarcModificationTemplates;
44
45
45
my $input = new CGI;
46
my $input = new CGI;
46
my $dbh = C4::Context->dbh;
47
my $dbh = C4::Context->dbh;
Lines 57-62 my $item_action = $input->param('item_action'); Link Here
57
my $comments = $input->param('comments');
58
my $comments = $input->param('comments');
58
my $record_type = $input->param('record_type');
59
my $record_type = $input->param('record_type');
59
my $encoding = $input->param('encoding');
60
my $encoding = $input->param('encoding');
61
my $marc_modification_template = $input->param('marc_modification_template_id');
62
60
my ($template, $loggedinuser, $cookie)
63
my ($template, $loggedinuser, $cookie)
61
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
64
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
62
					query => $input,
65
					query => $input,
Lines 131-137 if ($completedJobID) { Link Here
131
    }
134
    }
132
135
133
    # FIXME branch code
136
    # FIXME branch code
134
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
137
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($record_type, $encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
135
138
136
    $dbh->commit();
139
    $dbh->commit();
137
140
Lines 180-185 if ($completedJobID) { Link Here
180
                         matcher_code => $matcher_code,
183
                         matcher_code => $matcher_code,
181
                         import_batch_id => $batch_id
184
                         import_batch_id => $batch_id
182
                        );
185
                        );
186
187
183
    }
188
    }
184
189
185
} else {
190
} else {
Lines 189-194 if ($completedJobID) { Link Here
189
    }
194
    }
190
    my @matchers = C4::Matcher::GetMatcherList();
195
    my @matchers = C4::Matcher::GetMatcherList();
191
    $template->param(available_matchers => \@matchers);
196
    $template->param(available_matchers => \@matchers);
197
198
    my @templates = GetModificationTemplates();
199
    $template->param( MarcModificationTemplatesLoop => \@templates );
200
192
}
201
}
193
202
194
output_html_with_http_headers $input, $cookie, $template->output;
203
output_html_with_http_headers $input, $cookie, $template->output;
195
- 

Return to bug 8015