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

(-)a/C4/ImportBatch.pm (-1 / +7 lines)
Lines 25-30 use C4::Koha; Link Here
25
use C4::Biblio;
25
use C4::Biblio;
26
use C4::Items;
26
use C4::Items;
27
use C4::Charset;
27
use C4::Charset;
28
use Koha::MarcModificationTemplates;
28
29
29
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
30
31
Lines 275-281 sub ModBiblioInBatch { Link Here
275
=head2 BatchStageMarcRecords
276
=head2 BatchStageMarcRecords
276
277
277
  ($batch_id, $num_records, $num_items, @invalid_records) = 
278
  ($batch_id, $num_records, $num_items, @invalid_records) = 
278
    BatchStageMarcRecords($encoding, $marc_records, $file_name, 
279
    BatchStageMarcRecords($encoding, $marc_records, $file_name, $marc_modification_template,
279
                          $comments, $branch_code, $parse_items,
280
                          $comments, $branch_code, $parse_items,
280
                          $leave_as_staging, 
281
                          $leave_as_staging, 
281
                          $progress_interval, $progress_callback);
282
                          $progress_interval, $progress_callback);
Lines 286-291 sub BatchStageMarcRecords { Link Here
286
    my $encoding = shift;
287
    my $encoding = shift;
287
    my $marc_records = shift;
288
    my $marc_records = shift;
288
    my $file_name = shift;
289
    my $file_name = shift;
290
    my $marc_modification_template = shift;
289
    my $comments = shift;
291
    my $comments = shift;
290
    my $branch_code = shift;
292
    my $branch_code = shift;
291
    my $parse_items = shift;
293
    my $parse_items = shift;
Lines 333-344 sub BatchStageMarcRecords { Link Here
333
335
334
        $encoding = $charset_guessed unless $encoding;
336
        $encoding = $charset_guessed unless $encoding;
335
337
338
        ModifyRecordWithTemplate( $marc_modification_template, $marc_record ) if ( $marc_modification_template );
339
336
        my $import_record_id;
340
        my $import_record_id;
337
        if (scalar($marc_record->fields()) == 0) {
341
        if (scalar($marc_record->fields()) == 0) {
338
            push @invalid_records, $marc_blob;
342
            push @invalid_records, $marc_blob;
339
        } else {
343
        } else {
340
            $num_valid++;
344
            $num_valid++;
345
341
            $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0);
346
            $import_record_id = AddBiblioToBatch($batch_id, $rec_num, $marc_record, $encoding, int(rand(99999)), 0);
347
342
            if ($parse_items) {
348
            if ($parse_items) {
343
                my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
349
                my @import_items_ids = AddItemsToImportBiblio($batch_id, $import_record_id, $marc_record, 0);
344
                $num_items += scalar(@import_items_ids);
350
                $num_items += scalar(@import_items_ids);
(-)a/C4/Koha.pm (+17 lines)
Lines 1399-1404 sub _isbn_cleanup { Link Here
1399
    return;
1399
    return;
1400
}
1400
}
1401
1401
1402
=head2
1403
1404
  Log( $message );
1405
  
1406
  Writes data to /tmp/koha.log.
1407
  
1408
  This is useful for debugging forked processes
1409
  that do not write to the apache error log
1410
1411
=cut
1412
1413
sub Log {
1414
  my ($data) = @_;
1415
  open (MYFILE, '>>/tmp/koha.log');
1416
  print MYFILE "$data\n";
1417
  close (MYFILE);
1418
}
1402
1;
1419
1;
1403
1420
1404
__END__
1421
__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 (+332 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__
332
(-)a/installer/data/mysql/en/mandatory/userpermissions.sql (+1 lines)
Lines 39-44 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
39
   (13, 'moderate_tags', 'Moderate patron tags'),
39
   (13, 'moderate_tags', 'Moderate patron tags'),
40
   (13, 'rotating_collections', 'Manage rotating collections'),
40
   (13, 'rotating_collections', 'Manage rotating collections'),
41
   (13, 'upload_local_cover_images', 'Upload local cover images'),
41
   (13, 'upload_local_cover_images', 'Upload local cover images'),
42
   (13, 'marc_modification_templates', 'Manage marc modification templates'),
42
   (15, 'check_expiration', 'Check the expiration of a serial'),
43
   (15, 'check_expiration', 'Check the expiration of a serial'),
43
   (15, 'claim_serials', 'Claim missing serials'),
44
   (15, 'claim_serials', 'Claim missing serials'),
44
   (15, 'create_subscription', 'Create a new subscription'),
45
   (15, 'create_subscription', 'Create a new subscription'),
(-)a/installer/data/mysql/kohastructure.sql (+36 lines)
Lines 2846-2851 CREATE TABLE `quotes` ( Link Here
2846
  PRIMARY KEY (`id`)
2846
  PRIMARY KEY (`id`)
2847
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2847
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2848
2848
2849
--
2850
-- Table structure for table 'marc_modification_templates'
2851
--
2852
2853
CREATE TABLE IF NOT EXISTS marc_modification_templates (
2854
    template_id int(11) NOT NULL AUTO_INCREMENT,
2855
    name text NOT NULL,
2856
    PRIMARY KEY (template_id)
2857
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
2858
      
2859
--
2860
-- Table structure for table 'marc_modification_template_actions'
2861
--
2862
2863
CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
2864
  mmta_id int(11) NOT NULL AUTO_INCREMENT,
2865
  template_id int(11) NOT NULL,
2866
  ordering int(3) NOT NULL,
2867
  action enum('delete_field','update_field','move_field','copy_field') NOT NULL,
2868
  field_number smallint(6) NOT NULL DEFAULT '0',
2869
  from_field varchar(3) NOT NULL,
2870
  from_subfield varchar(1) DEFAULT NULL,
2871
  field_value varchar(100) DEFAULT NULL,
2872
  to_field varchar(3) DEFAULT NULL,
2873
  to_subfield varchar(1) DEFAULT NULL,
2874
  to_regex text,
2875
  conditional enum('if','unless') DEFAULT NULL,
2876
  conditional_field varchar(3) DEFAULT NULL,
2877
  conditional_subfield varchar(1) DEFAULT NULL,
2878
  conditional_comparison enum('exists','not_exists','equals','not_equals') DEFAULT NULL,
2879
  conditional_value text,
2880
  conditional_regex tinyint(1) NOT NULL DEFAULT '0',
2881
  description text,
2882
  PRIMARY KEY (mmta_id)
2883
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
2884
                                            
2849
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2885
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
2850
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2886
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
2851
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
2887
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
(-)a/installer/data/mysql/updatedatabase.pl (+39 lines)
Lines 5343-5348 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5343
    SetVersion($DBversion);
5343
    SetVersion($DBversion);
5344
}
5344
}
5345
5345
5346
$DBversion = "3.09.00.XXX";
5347
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
5348
    $dbh->do("CREATE TABLE IF NOT EXISTS marc_modification_templates (
5349
              template_id int(11) NOT NULL auto_increment,
5350
              name text NOT NULL,
5351
              PRIMARY KEY  (template_id)
5352
              ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;"
5353
    );
5354
    
5355
    $dbh->do("
5356
      CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
5357
      mmta_id int(11) NOT NULL auto_increment,
5358
      template_id int(11) NOT NULL,
5359
      ordering int(3) NOT NULL,
5360
      action enum('delete_field','update_field','move_field','copy_field') NOT NULL,
5361
      field_number smallint(6) NOT NULL default '0',
5362
      from_field varchar(3) NOT NULL,
5363
      from_subfield varchar(1) NULL,
5364
      field_value varchar(100) default NULL,
5365
      to_field varchar(3) default NULL,
5366
      to_subfield varchar(1) default NULL,
5367
      to_regex text,
5368
      conditional enum('if','unless') default NULL,
5369
      conditional_field varchar(3) default NULL,
5370
      conditional_subfield varchar(1) default NULL,
5371
      conditional_comparison enum('exists','not_exists','equals','not_equals') default NULL,
5372
      conditional_value text,
5373
      conditional_regex tinyint(1) NOT NULL default '0',
5374
      description text,
5375
      PRIMARY KEY  (mmta_id)
5376
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
5377
    ");
5378
5379
    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('13', 'marc_modification_templates', 'Manage marc modification templates')");
5380
    
5381
    print "Upgrade to $DBversion done ( Added tables for MARC Modification Framework )\n";
5382
    SetVersion($DBversion);
5383
}
5384
5346
=head1 FUNCTIONS
5385
=head1 FUNCTIONS
5347
5386
5348
=head2 TableExists($table)
5387
=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 64-71 Link Here
64
	<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>
64
	<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>
65
	<dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
65
	<dt><a href="/cgi-bin/koha/admin/koha2marclinks.pl">Koha to MARC mapping</a></dt>
66
	<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>
66
	<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>
67
	<dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
67
        <dt><a href="/cgi-bin/koha/admin/fieldmapping.pl">Keywords to MARC mapping</a></dt>
68
	<dd>Define the mapping between keywords and MARC fields, those keywords are used to find some datas independently of the framework.</dd>
68
        <dd>Define the mapping between keywords and MARC fields, those keywords are used to find some datas independently of the framework.</dd>
69
	<dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
69
	<dt><a href="/cgi-bin/koha/admin/checkmarc.pl">MARC Bibliographic framework test</a></dt>
70
	<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>
70
	<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>
71
    <dt><a href="/cgi-bin/koha/admin/authtypes.pl">Authority types</a></dt>
71
    <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 97-102 function CheckForm(f) { Link Here
97
            <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>
97
            <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>
98
	</li>
98
	</li>
99
</ol></fieldset>
99
</ol></fieldset>
100
  [% IF MarcModificationTemplatesLoop %]
101
    <fieldset class="rows">
102
      <legend>Use MARC Modification Template:</legend>
103
      <ol>
104
        <li>
105
          <label for="comments">Modify record using the following template: </label>
106
          <select name="marc_modification_template_id" id="marc_modification_template_id">
107
            <option value="">Do not use.</option>
108
              [% FOREACH mmt IN MarcModificationTemplatesLoop %]
109
                <option value="[% mmt.template_id %]">[% mmt.name %]</option>
110
              [% END %]
111
          </select>
112
        </li>
113
      </ol>
114
    </fieldset>
115
  [% END %]
116
100
  <fieldset class="rows">
117
  <fieldset class="rows">
101
    <legend>Look for existing records in catalog?</legend>
118
    <legend>Look for existing records in catalog?</legend>
102
    <ol><li><label for="matcher">Record matching rule:</label>
119
    <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 135-144 Link Here
135
<!--
135
<!--
136
    [% IF ( CAN_user_tools_rotating_collections ) %]
136
    [% IF ( CAN_user_tools_rotating_collections ) %]
137
    <dt><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></dt>
137
    <dt><a href="/cgi-bin/koha/rotating_collections/rotatingCollections.pl">Rotating collections</a></dt>
138
	<dd>Manage Rotating Collections</dd>
138
    <dd>Manage Rotating Collections</dd>
139
    [% END %]
139
    [% END %]
140
-->
140
-->
141
141
142
    [% IF ( CAN_user_tools_marc_modification_templates ) %]
143
    <dt><a href="/cgi-bin/koha/tools/marc_modification_templates.pl">MARC Modification Templates</a></dt>
144
    <dd>Manage templates for modifying MARC records during import.</dd>
145
    [% END %]
146
142
    [% IF ( CAN_user_tools_stage_marc_import ) %]
147
    [% IF ( CAN_user_tools_stage_marc_import ) %]
143
    <dt><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a></dt>
148
    <dt><a href="/cgi-bin/koha/tools/stage-marc-import.pl">Stage MARC records for import</a></dt>
144
    <dd>Stage MARC records into the reservoir.</dd>
149
    <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 56-61 my $parse_items = $input->param('parse_items'); Link Here
56
my $item_action = $input->param('item_action');
57
my $item_action = $input->param('item_action');
57
my $comments = $input->param('comments');
58
my $comments = $input->param('comments');
58
my $encoding = $input->param('encoding');
59
my $encoding = $input->param('encoding');
60
my $marc_modification_template = $input->param('marc_modification_template_id');
61
59
my ($template, $loggedinuser, $cookie)
62
my ($template, $loggedinuser, $cookie)
60
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
63
	= get_template_and_user({template_name => "tools/stage-marc-import.tmpl",
61
					query => $input,
64
					query => $input,
Lines 130-136 if ($completedJobID) { Link Here
130
    }
133
    }
131
134
132
    # FIXME branch code
135
    # FIXME branch code
133
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($encoding, $marcrecord, $filename, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
136
    my ($batch_id, $num_valid, $num_items, @import_errors) = BatchStageMarcRecords($encoding, $marcrecord, $filename, $marc_modification_template, $comments, '', $parse_items, 0, 50, staging_progress_callback($job, $dbh));
134
137
135
    $dbh->commit();
138
    $dbh->commit();
136
139
Lines 179-184 if ($completedJobID) { Link Here
179
                         matcher_code => $matcher_code,
182
                         matcher_code => $matcher_code,
180
                         import_batch_id => $batch_id
183
                         import_batch_id => $batch_id
181
                        );
184
                        );
185
186
182
    }
187
    }
183
188
184
} else {
189
} else {
Lines 188-193 if ($completedJobID) { Link Here
188
    }
193
    }
189
    my @matchers = C4::Matcher::GetMatcherList();
194
    my @matchers = C4::Matcher::GetMatcherList();
190
    $template->param(available_matchers => \@matchers);
195
    $template->param(available_matchers => \@matchers);
196
197
    my @templates = GetModificationTemplates();
198
    $template->param( MarcModificationTemplatesLoop => \@templates );
199
191
}
200
}
192
201
193
output_html_with_http_headers $input, $cookie, $template->output;
202
output_html_with_http_headers $input, $cookie, $template->output;
194
- 

Return to bug 8015