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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt (+23 lines)
Lines 16-21 console.log(allColumns); Link Here
16
for( x=0; x<allColumns.length; x++ ){
16
for( x=0; x<allColumns.length; x++ ){
17
  allColumns[x] = Number(allColumns[x]) + 2;
17
  allColumns[x] = Number(allColumns[x]) + 2;
18
}
18
}
19
$("#itemst").tablesorter({ widgets : ['zebra'], headers: {0:{sorter: false}} });
20
$("#selectallbutton").click(function() {
21
    $("#itemst").find("input:checkbox").each(function() {
22
 $(this).attr("checked", true);
23
    });
24
});
25
$("#clearallbutton").click(function() {
26
    $("#itemst").find("input:checkbox").each(function() {
27
 $(this).attr("checked", false);
28
    });
29
});
30
$("input[name='disable_input']").click(function() {
31
    if ($(this).is(":checked")){
32
 $(this).val($(this).siblings("[name='subfield']").val());
33
 $(this).siblings().attr('disabled',true);
34
    }
35
    else {
36
 $(this).siblings().removeAttr('disabled');
37
    }
38
});
39
19
//]]>
40
//]]>
20
</script>
41
</script>
21
<script type="text/javascript" src="[% themelang %]/js/pages/batchMod.js"></script>
42
<script type="text/javascript" src="[% themelang %]/js/pages/batchMod.js"></script>
Lines 118-123 for( x=0; x<allColumns.length; x++ ){ Link Here
118
139
119
<div id="cataloguing_additem_newitem">
140
<div id="cataloguing_additem_newitem">
120
        <h2>Edit Items</h2>
141
        <h2>Edit Items</h2>
142
        <div class="hint">Checking the box right next the subfield label will disable the entry and delete the values of that subfield on all selected items</div>
121
  <fieldset class="rows">
143
  <fieldset class="rows">
122
  <ol>
144
  <ol>
123
        [% FOREACH ite IN item %]
145
        [% FOREACH ite IN item %]
Lines 127-132 for( x=0; x<allColumns.length; x++ ){ Link Here
127
          [% ite.marc_lib %]
149
          [% ite.marc_lib %]
128
          [% IF ( ite.mandatory ) %] *</b>[% END %]
150
          [% IF ( ite.mandatory ) %] *</b>[% END %]
129
         </label>
151
         </label>
152
                <input type="checkbox" title="check to delete subfield [% ite.subfield %]" name="disable_input" value="[% ite.subfield %]" />
130
                [% ite.marc_value %]
153
                [% ite.marc_value %]
131
                <input type="hidden" name="tag"       value="[% ite.tag %]" />
154
                <input type="hidden" name="tag"       value="[% ite.tag %]" />
132
                <input type="hidden" name="subfield"       value="[% ite.subfield %]" />
155
                <input type="hidden" name="subfield"       value="[% ite.subfield %]" />
(-)a/tools/batchMod.pl (-12 / +40 lines)
Lines 89-101 if ($op eq "action") { Link Here
89
    my @tags      = $input->param('tag');
89
    my @tags      = $input->param('tag');
90
    my @subfields = $input->param('subfield');
90
    my @subfields = $input->param('subfield');
91
    my @values    = $input->param('field_value');
91
    my @values    = $input->param('field_value');
92
    my @disabled  = $input->param('disable_input');
92
    # build indicator hash.
93
    # build indicator hash.
93
    my @ind_tag   = $input->param('ind_tag');
94
    my @ind_tag   = $input->param('ind_tag');
94
    my @indicator = $input->param('indicator');
95
    my @indicator = $input->param('indicator');
95
96
96
    # Is there something to modify ?
97
    # Is there something to modify ?
97
    # TODO : We shall use this var to warn the user in case no modification was done to the items
98
    # TODO : We shall use this var to warn the user in case no modification was done to the items
98
    my $something_to_modify = scalar(grep {!/^$/} @values);
99
    my $values_to_modify = scalar(grep {!/^$/} @values);
100
    my $values_to_blank  = scalar(@disabled);
101
    my $marcitem;
99
102
100
    # Once the job is done
103
    # Once the job is done
101
    if ($completedJobID) {
104
    if ($completedJobID) {
Lines 114-121 if ($op eq "action") { Link Here
114
	# Calling the template
117
	# Calling the template
115
        add_saved_job_results_to_template($template, $completedJobID);
118
        add_saved_job_results_to_template($template, $completedJobID);
116
119
117
    # While the job is getting done
118
    } else {
120
    } else {
121
    # While the job is getting done
119
122
120
	# Job size is the number of items we have to process
123
	# Job size is the number of items we have to process
121
	my $job_size = scalar(@itemnumbers);
124
	my $job_size = scalar(@itemnumbers);
Lines 128-133 if ($op eq "action") { Link Here
128
	    $callback = progress_callback($job, $dbh);
131
	    $callback = progress_callback($job, $dbh);
129
	}
132
	}
130
133
134
	#initializing values for updates
135
	my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
136
	if ($values_to_modify){
137
	    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
138
	    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
139
        }
140
        if ($values_to_blank){
141
	    foreach my $disabledsubf (@disabled){
142
		if ($marcitem && $marcitem->field($itemtagfield)){
143
		    $marcitem->field($itemtagfield)->update( $disabledsubf => "" );
144
		}
145
		else {
146
		    $marcitem = MARC::Record->new();
147
		    $marcitem->append_fields( MARC::Field->new( $itemtagfield, '', '', $disabledsubf => "" ) );
148
		}
149
	    }
150
        }
151
131
	# For each item
152
	# For each item
132
	my $i = 1; 
153
	my $i = 1; 
133
	foreach my $itemnumber(@itemnumbers){
154
	foreach my $itemnumber(@itemnumbers){
Lines 140-155 if ($op eq "action") { Link Here
140
			    $deleted_items++;
161
			    $deleted_items++;
141
			} else {
162
			} else {
142
			    $not_deleted_items++;
163
			    $not_deleted_items++;
143
			    push @not_deleted, { biblionumber => $itemdata->{'biblionumber'}, itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
164
			    push @not_deleted,
165
				{ biblionumber => $itemdata->{'biblionumber'},
166
				  itemnumber => $itemdata->{'itemnumber'},
167
				  barcode => $itemdata->{'barcode'},
168
				  title => $itemdata->{'title'},
169
				  $return => 1
170
				};
144
			}
171
			}
145
		} else {
172
		} else {
146
		    if ($something_to_modify) {
173
		    if ($values_to_modify || $values_to_blank) {
147
			my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
174
			my $localmarcitem = Item2Marc($itemdata);
148
			my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
175
			UpdateMarcWith( $marcitem, $localmarcitem );
149
			my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
176
			eval{ my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) };
150
			my $localmarcitem=Item2Marc($itemdata);
151
			UpdateMarcWith($marcitem,$localmarcitem);
152
			eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
153
		    }
177
		    }
154
		}
178
		}
155
		$i++;
179
		$i++;
Lines 505-511 sub UpdateMarcWith { Link Here
505
	my @fields_to=$marcto->field($itemtag);
529
	my @fields_to=$marcto->field($itemtag);
506
    foreach my $subfield ($fieldfrom->subfields()){
530
    foreach my $subfield ($fieldfrom->subfields()){
507
		foreach my $field_to_update (@fields_to){
531
		foreach my $field_to_update (@fields_to){
508
				$field_to_update->update($$subfield[0]=>$$subfield[1]) if ($$subfield[1] != '' or $$subfield[1] == '0');
532
		    if ($subfield->[1]){
533
			$field_to_update->update($subfield->[0]=>$subfield->[1]);
534
		    }
535
		    else {
536
			$field_to_update->delete_subfield(code=> $subfield->[0]);
537
		    }
509
		}
538
		}
510
    }
539
    }
511
  #warn "TO edited:",$marcto->as_formatted;
540
  #warn "TO edited:",$marcto->as_formatted;
512
- 

Return to bug 6068