fa4fc5d2c550231d972a78896468e1b203a849e3
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / TemplateBatchBibUpdate.pm
1 package OpenILS::WWW::TemplateBatchBibUpdate;
2 use strict;
3 use warnings;
4 use bytes;
5
6 use Apache2::Log;
7 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
8 use APR::Const    -compile => qw(:error SUCCESS);
9 use APR::Table;
10
11 use Apache2::RequestRec ();
12 use Apache2::RequestIO ();
13 use Apache2::RequestUtil;
14 use CGI;
15 use Data::Dumper;
16 use Text::CSV;
17
18 use OpenSRF::EX qw(:try);
19 use OpenSRF::Utils qw/:datetime/;
20 use OpenSRF::Utils::Cache;
21 use OpenSRF::System;
22 use OpenSRF::AppSession;
23 use XML::LibXML;
24 use XML::LibXSLT;
25
26 use Encode;
27 use Unicode::Normalize;
28 use OpenILS::Utils::Fieldmapper;
29 use OpenSRF::Utils::Logger qw/$logger/;
30
31 use MARC::Record;
32 use MARC::File::XML ( BinaryEncoding => 'UTF-8' );
33
34 use UNIVERSAL::require;
35
36 our @formats = qw/USMARC UNIMARC XML BRE/;
37
38 # set the bootstrap config and template include directory when
39 # this module is loaded
40 my $bootstrap;
41
42 sub import {
43     my $self = shift;
44     $bootstrap = shift;
45 }
46
47
48 sub child_init {
49     OpenSRF::System->bootstrap_client( config_file => $bootstrap );
50     Fieldmapper->import(IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL"));
51     return Apache2::Const::OK;
52 }
53
54 sub handler {
55     my $r = shift;
56     my $cgi = new CGI;
57
58     my $authid = $cgi->cookie('ses') || $cgi->param('ses');
59     my $usr = verify_login($authid);
60     return show_template($r) unless ($usr);
61
62     my $template = $cgi->param('template');
63     return show_template($r) unless ($template);
64
65
66     my $rsource = $cgi->param('recordSource');
67     # find some IDs ...
68     my @records;
69
70     if ($rsource eq 'r') {
71         @records = map { $_ ? ($_) : () } $cgi->param('recid');
72     }
73
74     if ($rsource eq 'c') { # try for a file
75         my $file = $cgi->param('idfile');
76         if ($file) {
77             my $col = $cgi->param('idcolumn') || 0;
78             my $csv = new Text::CSV;
79
80             while (<$file>) {
81                 $csv->parse($_);
82                 my @data = $csv->fields;
83                 my $id = $data[$col];
84                 $id =~ s/\D+//o;
85                 next unless ($id);
86                 push @records, $id;
87             }
88         }
89     }
90
91     my $e = OpenSRF::AppSession->connect('open-ils.cstore');
92     $e->request('open-ils.cstore.transaction.begin')->gather(1);
93     $e->request('open-ils.cstore.set_audit_info', $authid, $usr->id, $usr->wsid)->gather(1);
94
95     # still no records ...
96     my $container = $cgi->param('containerid');
97     if ($rsource eq 'b') {
98         if ($container) {
99             my $bucket = $e->request(
100                 'open-ils.cstore.direct.container.biblio_record_entry_bucket.retrieve',
101                 $container
102             )->gather(1);
103             unless($bucket) {
104                 $e->request('open-ils.cstore.transaction.rollback')->gather(1);
105                 $e->disconnect;
106                 $r->log->error("No such bucket $container");
107                 $logger->error("No such bucket $container");
108                 return Apache2::Const::NOT_FOUND;
109             }
110             my $recs = $e->request(
111                 'open-ils.cstore.direct.container.biblio_record_entry_bucket_item.search.atomic',
112                 { bucket => $container }
113             )->gather(1);
114             @records = map { ($_->target_biblio_record_entry) } @$recs;
115         }
116     }
117
118     unless (@records) {
119         $e->request('open-ils.cstore.transaction.rollback')->gather(1);
120         $e->disconnect;
121         return show_template($r);
122     }
123
124     # we have a template and some record ids, so...
125
126     # insert the template record
127     my $min_id = $e->request(
128         'open-ils.cstore.json_query',
129         { select => { bre => [{ column => 'id', transform => 'min', aggregate => 1}] }, from => 'bre' }
130     )->gather(1)->{id} - 1;
131
132     warn "new template bib id = $min_id\n";
133
134     my $tmpl_rec = Fieldmapper::biblio::record_entry->new;
135     $tmpl_rec->id($min_id);
136     $tmpl_rec->deleted('t');
137     $tmpl_rec->active('f');
138     $tmpl_rec->marc($template);
139     $tmpl_rec->creator($usr->id);
140     $tmpl_rec->editor($usr->id);
141
142     warn "about to create bib $min_id\n";
143     $e->request('open-ils.cstore.direct.biblio.record_entry.create', $tmpl_rec )->gather(1);
144
145     # create the new container for the records and the template
146     my $bucket = Fieldmapper::container::biblio_record_entry_bucket->new;
147     $bucket->owner($usr->id);
148     $bucket->btype('template_merge');
149
150     my $bname = $cgi->param('bname') || 'Temporary Merge Bucket '. localtime() . ' ' . $usr->id;
151     $bucket->name($bname);
152
153     $bucket = $e->request('open-ils.cstore.direct.container.biblio_record_entry_bucket.create', $bucket )->gather(1);
154
155     # create items in the bucket
156     my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
157     $item->bucket($bucket->id);
158     $item->target_biblio_record_entry($min_id);
159
160     $e->request('open-ils.cstore.direct.container.biblio_record_entry_bucket_item.create', $item )->gather(1);
161
162     my %seen;
163     for my $r (@records) {
164         next if ($seen{$r});
165         $item->target_biblio_record_entry($r);
166         $e->request('open-ils.cstore.direct.container.biblio_record_entry_bucket_item.create', $item )->gather(1);
167         $seen{$r}++;
168     }
169
170     $e->request('open-ils.cstore.transaction.commit')->gather(1);
171     $e->disconnect;
172
173     # fire the background bucket processor
174     my $cache_key = OpenSRF::AppSession
175         ->create('open-ils.cat')
176         ->request('open-ils.cat.container.template_overlay.background', $authid, $bucket->id)
177         ->gather(1);
178
179     return show_processing_template($r, $bucket->id, \@records, $cache_key);
180 }
181
182 sub verify_login {
183         my $auth_token = shift;
184         return undef unless $auth_token;
185
186         my $user = OpenSRF::AppSession
187                 ->create("open-ils.auth")
188                 ->request( "open-ils.auth.session.retrieve", $auth_token )
189                 ->gather(1);
190
191         if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
192                 return undef;
193         }
194
195         return $user if ref($user);
196         return undef;
197 }
198
199 sub show_processing_template {
200     my $r = shift;
201     my $bid = shift;
202     my $recs = shift;
203     my $cache_key = shift;
204
205     my $rec_string = @$recs;
206
207     $r->content_type('text/html');
208     $r->print(<<HTML);
209 <html xmlns="http://www.w3.org/1999/xhtml">
210
211     <head>
212         <title>Merging records...</title>
213         <style type="text/css">
214             \@import '/js/dojo/dojo/resources/dojo.css';
215             \@import '/js/dojo/dijit/themes/tundra/tundra.css';
216             .hide_me { display: none; visibility: hidden; }
217             th       { font-weight: bold; }
218         </style>
219
220         <script type="text/javascript">
221             var djConfig= {
222                 isDebug: false,
223                 parseOnLoad: true,
224                 AutoIDL: ['aou','aout','pgt','au','cbreb']
225             }
226         </script>
227
228         <script src='/js/dojo/dojo/dojo.js'></script>
229         <!-- <script src="/js/dojo/dojo/openils_dojo.js"></script> -->
230
231         <script type="text/javascript">
232
233             dojo.require('fieldmapper.AutoIDL');
234             dojo.require('fieldmapper.dojoData');
235             dojo.require('openils.User');
236             dojo.require('openils.XUL');
237             dojo.require('dojo.cookie');
238             dojo.require('openils.CGI');
239             dojo.require('openils.widget.ProgressDialog');
240
241             var cgi = new openils.CGI();
242             var authtoken = dojo.cookie('ses') || cgi.param('ses');
243             if (!authtoken && openils.XUL.isXUL()) {
244                 var stash = openils.XUL.getStash();
245                 authtoken = stash.session.key;
246             }
247             var u = new openils.User({ authtoken: authtoken });
248
249             dojo.addOnLoad(function () {
250                 
251                 progress_dialog.update({maximum: $rec_string});
252                 progress_dialog.attr("title", "MARC Batch Editor Progress......");
253                 progress_dialog.show();
254
255                 var interval;
256                 interval = setInterval( function() {
257                     fieldmapper.standardRequest(
258                         ['open-ils.actor','open-ils.actor.anon_cache.get_value'],
259                         { async : false,
260                           params: [ u.authtoken, 'batch_edit_progress' ],
261                           onerror : function (r) { progress_dialog.hide(); },
262                           onresponse : function (r) {
263                             var counter = { success : 0, fail : 0, total : 0 };
264                             if (x = openils.Util.readResponse(r)) {
265                                 counter.success = x.succeeded;
266                                 counter.fail    = x.failed;
267                                 counter.total = counter.success + counter.fail;
268                                 if (x.complete) {
269                                     clearInterval(interval);
270                                     progress_dialog.hide();
271                                     if (x.success == 't') dojo.byId('complete_msg').innerHTML = 'Overlay completed successfully';
272                                     else dojo.byId('complete_msg').innerHTML = 'Overlay did not complet successfully';
273                                 }
274                             };
275
276                             // update the progress dialog
277                             progress_dialog.update({progress:counter.total});
278                             dojo.byId('success_count').innerHTML = counter.success;
279                             dojo.byId('fail_count').innerHTML = counter.fail;
280                             dojo.byId('total_count').innerHTML = counter.total;
281                           }
282                         }
283                     );
284                 }, 1000);
285
286             });
287         </script>
288 <style>
289 table {
290     #width:100%;
291 }
292 table, th, td {
293     border: 1px solid black;
294     border-collapse: collapse;
295 }
296 th, td {
297     padding: 5px;
298     text-align: left;
299 }
300 table tr:nth-child(even) {
301     background-color: #eee;
302 }
303 table tr:nth-child(odd) {
304    background-color:#fff;
305 }
306 table th        {
307     background-color: black;
308     color: white;
309 }
310 tr#fail {
311     color: red;
312 }
313 tr#processed    {
314     font-weight: bold;
315 }
316 div#complete_msg {
317     font-weight:bold;
318     color: green;
319     font-size: larger;
320     text-decoration: underline;
321 }
322 </style>
323     </head>
324     
325
326     <body style="margin:10px;font-size: 130%" class='tundra'>
327         <div class="hide_me"><div dojoType="openils.widget.ProgressDialog" jsId="progress_dialog"></div></div>
328
329         <h1>MARC Batch Editor Status</h1>
330
331         <table>
332             <tr>
333                 <th>Status</th>
334                 <th>Record Count</th>
335             </tr>
336             <tr>
337                 <td>Success</td>
338                 <td id='success_count'></td>
339             </tr>
340             <tr id='fail'>
341                 <td>Failure</td>
342                 <td id='fail_count'></td>
343             </tr>
344             <tr id='processed' >
345                 <td>Total Processed</td>
346                 <td id='total_count'></td>
347             </tr>
348             <tr>
349                <td></td>
350             </tr>
351             <tr>
352                 <td>Total To Process</td>
353                 <td>$rec_string</td>
354             </tr>
355         </table>
356         <br>
357         <div id='complete_msg'></div>
358
359     </body>
360 </html>
361 HTML
362
363     return Apache2::Const::OK;
364 }
365
366
367 sub show_template {
368     my $r = shift;
369
370     $r->content_type('text/html');
371     $r->print(<<'HTML');
372 <html xmlns="http://www.w3.org/1999/xhtml">
373
374     <head>
375         <title>Merge Template Builder</title>
376         <style type="text/css">
377             @import '/js/dojo/dojo/resources/dojo.css';
378             @import '/js/dojo/dijit/themes/tundra/tundra.css';
379             .hide_me { display: none; visibility: hidden; }
380             table.ruleTable th { padding: 5px; border-collapse: collapse; border-bottom: solid 1px gray; font-weight: bold; }
381             table.ruleTable td { padding: 5px; border-collapse: collapse; border-bottom: solid 1px gray; }
382         </style>
383
384         <script type="text/javascript">
385             var djConfig= {
386                 isDebug: false,
387                 parseOnLoad: true,
388                 AutoIDL: ['aou','aout','pgt','au','cbreb']
389             }
390         </script>
391
392         <script src='/js/dojo/dojo/dojo.js'></script>
393         <!-- <script src="/js/dojo/dojo/openils_dojo.js"></script> -->
394
395         <script type="text/javascript">
396
397             dojo.require('dojo.data.ItemFileReadStore');
398             dojo.require('dijit.form.Form');
399             dojo.require('dijit.form.NumberSpinner');
400             dojo.require('dijit.form.FilteringSelect');
401             dojo.require('dijit.form.TextBox');
402             dojo.require('dijit.form.Textarea');
403             dojo.require('dijit.form.Button');
404             dojo.require('MARC.Batch');
405             dojo.require('fieldmapper.AutoIDL');
406             dojo.require('fieldmapper.dojoData');
407             dojo.require('openils.User');
408             dojo.require('openils.CGI');
409             dojo.require('openils.XUL');
410             dojo.require('dojo.cookie');
411
412             var cgi = new openils.CGI();
413             var authtoken = dojo.cookie('ses') || cgi.param('ses');
414             if (!authtoken && openils.XUL.isXUL()) {
415                 var stash = openils.XUL.getStash();
416                 authtoken = stash.session.key;
417             }
418             var u = new openils.User({ authtoken: authtoken });
419
420             var bucketStore = new dojo.data.ItemFileReadStore(
421                 { data : cbreb.toStoreData(
422                         fieldmapper.standardRequest(
423                             ['open-ils.actor','open-ils.actor.container.retrieve_by_class.authoritative'],
424                             [u.authtoken, u.user.id(), 'biblio', 'staff_client']
425                         )
426                     )
427                 }
428             );
429
430             function render_preview () {
431                 var rec = ruleset_to_record();
432                 dojo.byId('marcPreview').innerHTML = rec.toBreaker();
433             }
434
435             function render_from_template () {
436                 var kid_number = dojo.byId('ruleList').childNodes.length;
437                 var clone = dojo.query('*[name=ruleTable]', dojo.byId('ruleTemplate'))[0].cloneNode(true);
438
439                 var typeSelect = dojo.query('*[name=typeSelect]',clone).instantiate(dijit.form.FilteringSelect, {
440                     onChange : function (val) {
441                         switch (val) {
442                             case 'a':
443                             case 'r':
444                                 dijit.byNode(dojo.query('*[name=marcDataContainer] .dijit',clone)[0]).attr('disabled',false);
445                                 break;
446                             default :
447                                 dijit.byNode(dojo.query('*[name=marcDataContainer] .dijit',clone)[0]).attr('disabled',true);
448                         };
449                         render_preview();
450                     }
451                 })[0];
452
453                 var marcData = dojo.query('*[name=marcData]',clone).instantiate(dijit.form.TextBox, {
454                     onChange : render_preview
455                 })[0];
456
457
458                 var tag = dojo.query('*[name=tag]',clone).instantiate(dijit.form.TextBox, {
459                     onChange : function (newtag) {
460                         var md = dijit.byNode(dojo.query('*[name=marcDataContainer] .dijit',clone)[0]);
461                         var current_marc = md.attr('value');
462
463                         if (newtag.length == 3) {
464                             if (current_marc.length == 0) newtag += ' \\\\';
465                             if (current_marc.substr(0,3) != newtag) current_marc = newtag + current_marc.substr(3);
466                         }
467                         md.attr('value', current_marc);
468                         render_preview();
469                     }
470                 })[0];
471
472                 var sf = dojo.query('*[name=sf]',clone).instantiate(dijit.form.TextBox, {
473                     onChange : function (newsf) {
474                         var md = dijit.byNode(dojo.query('*[name=marcDataContainer] .dijit',clone)[0]);
475                         var current_marc = md.attr('value');
476                         var sf_list = newsf.split('');
477
478                         for (var i in sf_list) {
479                             var re = '\\$' + sf_list[i];
480                             if (current_marc.match(re)) continue;
481                             current_marc += '$' + sf_list[i];
482                         }
483
484                         md.attr('value', current_marc);
485                         render_preview();
486                     }
487                 })[0];
488
489                 var matchSF = dojo.query('*[name=matchSF]',clone).instantiate(dijit.form.TextBox, {
490                     onChange : render_preview
491                 })[0];
492
493                 var matchRE = dojo.query('*[name=matchRE]',clone).instantiate(dijit.form.TextBox, {
494                     onChange : render_preview
495                 })[0];
496
497                 var removeButton = dojo.query('*[name=removeButton]',clone).instantiate(dijit.form.Button, {
498                     onClick : function() {
499                         dojo.addClass(
500                             dojo.byId('ruleList').childNodes[kid_number],
501                             'hide_me'
502                         );
503                         render_preview();
504                     }
505                 })[0];
506
507                 dojo.place(clone,'ruleList');
508             }
509
510             function ruleset_to_record () {
511                 var rec = new MARC.Record ({ delimiter : '$' });
512
513                 dojo.forEach( 
514                     dojo.query('#ruleList *[name=ruleTable]').filter( function (node) {
515                         if (node.className.match(/hide_me/)) return false;
516                         return true;
517                     }),
518                     function (tbl) {
519                         var rule_tag = new MARC.Field ({
520                             tag : '905',
521                             ind1 : ' ',
522                             ind2 : ' '
523                         });
524                         var rule_txt = dijit.byNode(dojo.query('*[name=tagContainer] .dijit',tbl)[0]).attr('value');
525                         rule_txt += dijit.byNode(dojo.query('*[name=sfContainer] .dijit',tbl)[0]).attr('value');
526
527                         var reSF = dijit.byNode(dojo.query('*[name=matchSFContainer] .dijit',tbl)[0]).attr('value');
528                         if (reSF) {
529                             var reRE = dijit.byNode(dojo.query('*[name=matchREContainer] .dijit',tbl)[0]).attr('value');
530                             rule_txt += '[' + reSF + '~' + reRE + ']';
531                         }
532
533                         var rtype = dijit.byNode(dojo.query('*[name=typeSelectContainer] .dijit',tbl)[0]).attr('value');
534                         rule_tag.addSubfields( rtype, rule_txt )
535                         rec.appendFields( rule_tag );
536
537                         if (rtype == 'a' || rtype == 'r') {
538                             rec.appendFields(
539                                 new MARC.Record ({
540                                     delimiter : '$',
541                                     marcbreaker : dijit.byNode(dojo.query('*[name=marcDataContainer] .dijit',tbl)[0]).attr('value')
542                                 }).fields[0]
543                             );
544                         }
545                     }
546                 );
547
548                 return rec;
549             }
550         </script>
551     </head>
552
553     <body style="margin:10px;" class='tundra'>
554
555         <div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data" action="" method="POST">
556                 <script type='dojo/method' event='onSubmit'>
557                     var rec = ruleset_to_record();
558
559                     if (rec.subfield('905','r') == '') { // no-op to force replace mode
560                         rec.appendFields(
561                             new MARC.Field ({
562                                 tag : '905',
563                                 ind1 : ' ',
564                                 ind2 : ' ',
565                                 subfields : [['r','901c']]
566                             })
567                         );
568                     }
569
570                     dojo.byId('template_value').value = rec.toXmlString();
571                     return true;
572                 </script>
573
574             <input type='hidden' id='template_value' name='template'/>
575
576             <label for='inputTypeSelect'>Record source:</label>
577             <select name='recordSource' dojoType='dijit.form.FilteringSelect'>
578                 <script type='dojo/method' event='onChange' args="val">
579                     switch (val) {
580                         case 'b':
581                             dojo.removeClass('bucketListContainer','hide_me');
582                             dojo.addClass('csvContainer','hide_me');
583                             dojo.addClass('recordContainer','hide_me');
584                             break;
585                         case 'c':
586                             dojo.addClass('bucketListContainer','hide_me');
587                             dojo.removeClass('csvContainer','hide_me');
588                             dojo.addClass('recordContainer','hide_me');
589                             break;
590                         case 'r':
591                             dojo.addClass('bucketListContainer','hide_me');
592                             dojo.addClass('csvContainer','hide_me');
593                             dojo.removeClass('recordContainer','hide_me');
594                             break;
595                     };
596                 </script>
597                 <script type='dojo/method' event='postCreate'>
598                     if (cgi.param('recordSource')) {
599                         this.attr('value',cgi.param('recordSource'));
600                         this.onChange(cgi.param('recordSource'));
601                     }
602                 </script>
603                 <option value='b'>a Bucket</option>
604                 <option value='c'>a CSV File</option>
605                 <option value='r'>a specific record ID</option>
606             </select>
607
608             <table style='margin:10px; margin-bottom:20px;'>
609 <!--
610                 <tr>
611                     <th>Merge template name (optional):</th>
612                     <td><input id='bucketName' jsId='bucketName' type='text' dojoType='dijit.form.TextBox' name='bname' value=''/></td>
613                 </tr>
614 -->
615                 <tr class='' id='bucketListContainer'>
616                     <td>Bucket named: 
617                         <div name='containerid' jsId='bucketList' dojoType='dijit.form.FilteringSelect' store='bucketStore' searchAttr='name' id='bucketList'>
618                             <script type='dojo/method' event='postCreate'>
619                                 if (cgi.param('containerid')) this.attr('value',cgi.param('containerid'));
620                             </script>
621                         </div>
622                     </td>
623                 </tr>
624                 <tr class='hide_me' id='csvContainer'>
625                     <td>
626                         Column <input style='width:75px;' type='text' dojoType='dijit.form.NumberSpinner' name='idcolumn' value='0' constraints='{min:0,max:100,places:0}' /> of: 
627                         <input id='idfile' type="file" name="idfile"/>
628                         <br/>
629                         <br/>
630                         Columns are numbered starting at 0.  For instance, when looking at a CSV file in Excel, the column labeled A is the same as column 0, and the column labeled B is the same as column 1.
631                     </td>
632                 </tr>
633                 <tr class='hide_me' id='recordContainer'>
634                     <td>Record ID: <input dojoType='dijit.form.TextBox' name='recid' style='width:75px;' type='text' value=''/></td>
635                 </tr>
636             </table>
637
638             <button type="submit" dojoType='dijit.form.Button'>GO!</button> (After setting up your template below.)
639
640             <br/>
641             <br/>
642
643         </div> <!-- end of the form -->
644
645         <hr/>
646         <table style='width: 100%'>
647             <tr>
648                 <td style='width: 50%'><div id='ruleList'></div></td>
649                 <td valign='top'>Update Template Preview:<br/><pre id='marcPreview'></pre></td>
650             </tr>
651         </table>
652
653         <button dojoType='dijit.form.Button'>Add Merge Rule
654             <script type='dojo/connect' event='onClick'>render_from_template()</script>
655             <script type='dojo/method' event='postCreate'>render_from_template()</script>
656         </button>
657
658         <div class='hide_me' id='ruleTemplate'>
659         <div name='ruleTable'>
660             <table class='ruleTable'>
661                 <tbody>
662                     <tr>
663                         <th style="text-align:center;">Rule Setup</th>
664                         <th style="text-align:center;">Data</th>
665                         <th style="text-align:center;">Help</th>
666                     </tr>
667                     <tr>
668                         <th>Action (Rule Type)</th>
669                         <td name='typeSelectContainer'>
670                             <select name='typeSelect'>
671                                 <option value='r'>Replace</option>
672                                 <option value='a'>Add</option>
673                                 <option value='d'>Delete</option>
674                             </select>
675                         </td>
676                         <td>How to change the existing records</td>
677                     </tr>
678                     <tr>
679                         <th>MARC Tag</th>
680                         <td name='tagContainer'><input style='with: 2em;' name='tag' type='text'></input</td>
681                         <td>Three characters, no spaces, no indicators, etc. eg: 245</td>
682                     </td>
683                     <tr>
684                         <th>Subfields (optional)</th>
685                         <td name='sfContainer'><input name='sf' type='text'/></td>
686                         <td>No spaces, no delimiters, eg: abcnp</td>
687                     </tr>
688                     <tr>
689                         <th>MARC Data</th>
690                         <td name='marcDataContainer'><input name='marcData' type='text'/></td>
691                         <td>MARC-Breaker formatted data with indicators and subfield delimiters, eg:<br/>245 04$aThe End</td>
692                     </tr>
693                     <tr>
694                         <th colspan='3' style='padding-top: 20px; text-align: center;'>Advanced Matching Restriction (Optional)</th>
695                     </tr>
696                     <tr>
697                         <th>Subfield</th>
698                         <td name='matchSFContainer'><input style='with: 2em;' name='matchSF' type='text'></input</td>
699                         <td>A single subfield code, no delimiters, eg: a</td>
700                     <tr>
701                         <th>Regular Expression</th>
702                         <td name='matchREContainer'><input name='matchRE' type='text'/></td>
703                         <td>See <a href="http://perldoc.perl.org/perlre.html#Regular-Expressions" target="_blank">the Perl documentation</a>
704                             for an explanation of Regular Expressions.
705                         </td>
706                     </tr>
707                     <tr>
708                         <td colspan='3' style='padding-top: 20px; text-align: center;'>
709                             <button name='removeButton'>Remove this Template Rule</button>
710                         </td>
711                     </tr>
712                 </tbody>
713             </table>
714         <hr/>
715         </div>
716         </div>
717
718     </body>
719 </html>
720 HTML
721
722     return Apache2::Const::OK;
723 }
724
725 1;
726
727