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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tmpl (-6 / +8 lines)
Lines 117-131 for( x=0; x<allColumns.length; x++ ){ Link Here
117
117
118
<div id="cataloguing_additem_newitem">
118
<div id="cataloguing_additem_newitem">
119
        <h2>Edit Items</h2>
119
        <h2>Edit Items</h2>
120
  <fieldset class="rows">
120
    <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
  <ol>
121
	<fieldset class="rows">
122
	<ol>
122
        <!-- TMPL_LOOP NAME="item" -->
123
        <!-- TMPL_LOOP NAME="item" -->
123
               <li><div class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
124
               <li><div class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
124
               <label><!-- TMPL_VAR NAME="subfield" --> - 
125
               <label><!-- TMPL_VAR NAME="subfield" --> - 
125
          <!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF -->
126
		      <!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF -->
126
          <!-- TMPL_VAR NAME="marc_lib" -->
127
		      <!-- TMPL_VAR NAME="marc_lib" -->
127
          <!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
128
		      <!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
128
         </label>
129
	       </label>
130
           <input type="checkbox" title="check to delete subfield <!-- TMPL_VAR NAME="subfield" -->" name="disable_input">
129
                <!-- TMPL_VAR NAME="marc_value" -->
131
                <!-- TMPL_VAR NAME="marc_value" -->
130
                <input type="hidden" name="tag"       value="<!-- TMPL_VAR NAME="tag" -->" />
132
                <input type="hidden" name="tag"       value="<!-- TMPL_VAR NAME="tag" -->" />
131
                <input type="hidden" name="subfield"       value="<!-- TMPL_VAR NAME="subfield" -->" />
133
                <input type="hidden" name="subfield"       value="<!-- TMPL_VAR NAME="subfield" -->" />
(-)a/tools/batchMod.pl (-50 / +72 lines)
Lines 89-159 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) {
102
	# If we have a reasonable amount of items, we display them
105
        # If we have a reasonable amount of items, we display them
103
	if (scalar(@itemnumbers) <= 1000) {
106
        if (scalar(@itemnumbers) <= 1000) {
104
	    $items_display_hashref=BuildItemsData(@itemnumbers);
107
            $items_display_hashref=BuildItemsData(@itemnumbers);
105
	} else {
108
        } else {
106
	    # Else, we only display the barcode
109
            # Else, we only display the barcode
107
	    my @simple_items_display = map {{ itemnumber => $_, barcode => (GetBarcodeFromItemnumber($_) or ""), biblionumber => (GetBiblionumberFromItemnumber($_) or "") }} @itemnumbers;
110
            my @simple_items_display = map {{ itemnumber => $_, barcode => (GetBarcodeFromItemnumber($_) or ""), biblionumber => (GetBiblionumberFromItemnumber($_) or "") }} @itemnumbers;
108
	    $template->param("simple_items_display" => \@simple_items_display);
111
            $template->param("simple_items_display" => \@simple_items_display);
109
	}
112
        }
110
113
111
	# Setting the job as done
114
        # Setting the job as done
112
	my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
115
        my $job = C4::BackgroundJob->fetch($sessionID, $completedJobID);
113
116
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);
122
	my $job = undef;
125
        my $job = undef;
123
	my $callback = sub {};
126
        $dbh->{AutoCommit} = 0;
127
        my $callback = sub {};
124
128
125
	# If we asked for background processing
129
	# If we asked for background processing
126
	if ($runinbackground) {
130
        if ($runinbackground) {
127
	    $job = put_in_background($job_size);
131
            $job = put_in_background($job_size);
128
	    $callback = progress_callback($job, $dbh);
132
            $callback = progress_callback($job, $dbh);
129
	}
133
        }
130
134
135
    #initializing values for updates
136
        my (  $itemtagfield,   $itemtagsubfield) = &GetMarcFromKohaField("items.itemnumber", "");
137
        if ($values_to_modify){
138
                    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
139
                    $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
140
        }
141
        if ($values_to_blank){
142
                foreach my $disabledsubf (@disabled){
143
                    if ($marcitem && $marcitem->field($itemtagfield)){
144
                        $marcitem->field($itemtagfield)->update($disabledsubf=>"");
145
                    }
146
                    else {
147
                        $marcitem = MARC::Record->new();
148
                        $marcitem->append_fields(MARC::Field->new($itemtagfield,'','',$disabledsubf=>""));
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){
134
155
135
		$job->progress($i) if $runinbackground;
156
            $job->progress($i) if $runinbackground;
136
		my $itemdata=GetItem($itemnumber);
157
            my $itemdata=GetItem($itemnumber);
137
		if ($input->param("del")){
158
            if ($input->param("del")){
138
			my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
159
                my $return = DelItemCheck(C4::Context->dbh, $itemdata->{'biblionumber'}, $itemdata->{'itemnumber'});
139
			if ($return == 1) {
160
                if ($return == 1) {
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, { biblionumber => $itemdata->{'biblionumber'}, itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
144
			}
165
                }
145
		} else {
166
            } else {
146
		    if ($something_to_modify) {
167
            if ($values_to_modify||$values_to_blank) {
147
			my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
168
                my $localmarcitem=Item2Marc($itemdata);
148
			my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
169
                UpdateMarcWith($marcitem,$localmarcitem);
149
			my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
170
                eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
150
			my $localmarcitem=Item2Marc($itemdata);
171
                }
151
			UpdateMarcWith($marcitem,$localmarcitem);
172
            }
152
			eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
173
            $i++;
153
		    }
174
        }
154
		}
155
		$i++;
156
	}
157
    }
175
    }
158
}
176
}
159
#
177
#
Lines 504-512 sub UpdateMarcWith { Link Here
504
	my $fieldfrom=$marcfrom->field($itemtag);
522
	my $fieldfrom=$marcfrom->field($itemtag);
505
	my @fields_to=$marcto->field($itemtag);
523
	my @fields_to=$marcto->field($itemtag);
506
    foreach my $subfield ($fieldfrom->subfields()){
524
    foreach my $subfield ($fieldfrom->subfields()){
507
		foreach my $field_to_update (@fields_to){
525
	foreach my $field_to_update (@fields_to){
508
				$field_to_update->update($$subfield[0]=>$$subfield[1]) if ($$subfield[1] != '' or $$subfield[1] == '0');
526
             if ($subfield->[1] ne ""){
509
		}
527
		 $field_to_update->update($subfield->[0]=>$subfield->[1]);
528
            }
529
            else {
530
		$field_to_update->delete_subfield(code=> $subfield->[0]);
531
            }
532
	}
510
    }
533
    }
511
  #warn "TO edited:",$marcto->as_formatted;
534
  #warn "TO edited:",$marcto->as_formatted;
512
}
535
}
513
- 

Return to bug 6018