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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tmpl (+22 lines)
Lines 15-20 var allColumns = new Array(<!-- TMPL_LOOP NAME="item_header_loop" -->'<!-- TMPL_ Link Here
15
for( x=0; x<allColumns.length; x++ ){
15
for( x=0; x<allColumns.length; x++ ){
16
  allColumns[x] = Number(allColumns[x]) + 2;
16
  allColumns[x] = Number(allColumns[x]) + 2;
17
}
17
}
18
$("#itemst").tablesorter({ widgets : ['zebra'], headers: {0:{sorter: false}} });
19
$("#selectallbutton").click(function() {
20
    $("#itemst").find("input:checkbox").each(function() {
21
	$(this).attr("checked", true);
22
    });
23
});
24
$("#clearallbutton").click(function() {
25
    $("#itemst").find("input:checkbox").each(function() {
26
	$(this).attr("checked", false);
27
    });
28
});
29
$("input[name='disable_input']").click(function() {
30
    if ($(this).is(":checked")){
31
	$(this).val($(this).siblings("[name='subfield']").val());
32
	$(this).siblings().attr('disabled',true);
33
    }
34
    else {
35
	$(this).siblings().removeAttr('disabled');
36
    }
37
});
18
//]]>
38
//]]>
19
</script>
39
</script>
20
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/js/pages/batchMod.js"></script>
40
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/js/pages/batchMod.js"></script>
Lines 117-122 for( x=0; x<allColumns.length; x++ ){ Link Here
117
137
118
<div id="cataloguing_additem_newitem">
138
<div id="cataloguing_additem_newitem">
119
        <h2>Edit Items</h2>
139
        <h2>Edit Items</h2>
140
	<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>
120
  <fieldset class="rows">
141
  <fieldset class="rows">
121
  <ol>
142
  <ol>
122
        <!-- TMPL_LOOP NAME="item" -->
143
        <!-- TMPL_LOOP NAME="item" -->
Lines 126-131 for( x=0; x<allColumns.length; x++ ){ Link Here
126
          <!-- TMPL_VAR NAME="marc_lib" -->
147
          <!-- TMPL_VAR NAME="marc_lib" -->
127
          <!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
148
          <!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
128
         </label>
149
         </label>
150
		<input type="checkbox" title="check to delete subfield <!-- TMPL_VAR NAME="subfield" -->" name="disable_input" value="<!-- TMPL_VAR NAME="subfield" -->" />
129
                <!-- TMPL_VAR NAME="marc_value" -->
151
                <!-- TMPL_VAR NAME="marc_value" -->
130
                <input type="hidden" name="tag"       value="<!-- TMPL_VAR NAME="tag" -->" />
152
                <input type="hidden" name="tag"       value="<!-- TMPL_VAR NAME="tag" -->" />
131
                <input type="hidden" name="subfield"       value="<!-- TMPL_VAR NAME="subfield" -->" />
153
                <input type="hidden" name="subfield"       value="<!-- TMPL_VAR NAME="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