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

(-)a/cataloguing/additem.pl (-7 / +96 lines)
Lines 97-102 if ($op eq "additem") { Link Here
97
    my @indicator = $input->param('indicator');
97
    my @indicator = $input->param('indicator');
98
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
98
    my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
99
    my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
99
    my $record = MARC::Record::new_from_xml($xml, 'UTF-8');
100
101
    # type of add
102
    my $add_submit                 = $input->param('add_submit');
103
    my $add_duplicate_submit       = $input->param('add_duplicate_submit');
104
    my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit');
105
    my $number_of_copies           = $input->param('number_of_copies');
106
100
    # if autoBarcode is set to 'incremental', calculate barcode...
107
    # if autoBarcode is set to 'incremental', calculate barcode...
101
	# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
108
	# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code
102
	# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
109
	# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript
Lines 114-129 if ($op eq "additem") { Link Here
114
            $record->insert_fields_ordered($fieldItem);
121
            $record->insert_fields_ordered($fieldItem);
115
        }
122
        }
116
    }
123
    }
117
# check for item barcode # being unique
124
118
    my $addedolditem = TransformMarcToKoha($dbh,$record);
125
    my $addedolditem = TransformMarcToKoha($dbh,$record);
119
    my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
126
120
    push @errors,"barcode_not_unique" if($exist_itemnumber);
127
    # If we have to add or add & duplicate, we add the item
121
    # if barcode exists, don't create, but report The problem.
128
    if ($add_submit || $add_duplicate_submit) {
122
    my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber);
129
	# check for item barcode # being unique
123
    $nextop = "additem";
130
	my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'});
124
    if ($exist_itemnumber) {
131
	push @errors,"barcode_not_unique" if($exist_itemnumber);
132
	# if barcode exists, don't create, but report The problem.
133
	my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber);
134
	$nextop = "additem";
135
	if ($exist_itemnumber) {
136
	    $itemrecord = $record;
137
	}
138
    }
139
140
    # If we have to add & duplicate
141
    if ($add_duplicate_submit) {
142
143
        # We try to get the next barcode
144
        use C4::Barcodes;
145
        my $barcodeobj = C4::Barcodes->new;
146
        my $barcodevalue = $barcodeobj->next_value($addedolditem->{'barcode'}) if $barcodeobj;
147
        my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
148
        if ($record->field($tagfield)->subfield($tagsubfield)) {
149
            # If we got the next codebar value, we put it in the record
150
            if ($barcodevalue) {
151
                $record->field($tagfield)->update($tagsubfield => $barcodevalue);
152
            # If not, we delete the recently inserted barcode from the record (so the user can input a barcode himself)
153
            } else {
154
                $record->field($tagfield)->update($tagsubfield => '');
155
            }
156
        }
125
        $itemrecord = $record;
157
        $itemrecord = $record;
126
    }
158
    }
159
160
    # If we have to add multiple copies
161
    if ($add_multiple_copies_submit) {
162
163
        use C4::Barcodes;
164
        my $barcodeobj = C4::Barcodes->new;
165
        my $oldbarcode = $addedolditem->{'barcode'};
166
        my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode);
167
168
	# If there is a barcode and we can't find him new values, we can't add multiple copies
169
        my $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj;
170
	if ($oldbarcode && !$testbarcode) {
171
172
	    push @errors, "no_next_barcode";
173
	    $itemrecord = $record;
174
175
	} else {
176
	# We add each item
177
178
	    # For the first iteration
179
	    my $barcodevalue = $oldbarcode;
180
	    my $exist_itemnumber;
181
182
183
	    for (my $i = 0; $i < $number_of_copies;) {
184
185
		# If there is a barcode
186
		if ($barcodevalue) {
187
188
		    # Getting a new barcode (if it is not the first iteration or the barcode we tried already exists)
189
		    $barcodevalue = $barcodeobj->next_value($oldbarcode) if ($i > 0 || $exist_itemnumber);
190
191
		    # Putting it into the record
192
		    if ($barcodevalue) {
193
			$record->field($tagfield)->update($tagsubfield => $barcodevalue);
194
		    }
195
196
		    # Checking if the barcode already exists
197
		    $exist_itemnumber = get_item_from_barcode($barcodevalue);
198
		}
199
200
		# Adding the item
201
		my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber);
202
203
		# We count the item only if it was really added
204
		# That way, all items are added, even if there was some already existing barcodes
205
		# FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode
206
		$i++ unless ($exist_itemnumber);
207
208
		# Preparing the next iteration
209
		$oldbarcode = $barcodevalue;
210
	    }
211
	    undef($itemrecord);
212
	}
213
    }
214
215
127
#-------------------------------------------------------------------------------
216
#-------------------------------------------------------------------------------
128
} elsif ($op eq "edititem") {
217
} elsif ($op eq "edititem") {
129
#-------------------------------------------------------------------------------
218
#-------------------------------------------------------------------------------
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tmpl (-2 / +23 lines)
Lines 23-28 function active(numlayer) Link Here
23
    }
23
    }
24
}
24
}
25
function Check(f) {
25
function Check(f) {
26
26
    var total_errors=0;
27
    var total_errors=0;
27
//	alert(f.field_value.length);
28
//	alert(f.field_value.length);
28
    for (i=0 ; i<f.field_value.length ; i++) {
29
    for (i=0 ; i<f.field_value.length ; i++) {
Lines 45-50 function Check(f) { Link Here
45
        return false;
46
        return false;
46
    }
47
    }
47
}
48
}
49
function CheckMultipleAdd(f) {
50
51
    if (!f || isNaN(f) || !parseInt(f) == f || f <= 0) { 
52
	alert(_("Please enter a number of items to create.")); 
53
	return false;	
54
    }
55
}
48
function Dopop(link,i) {
56
function Dopop(link,i) {
49
    defaultvalue=document.forms[0].field_value[i].value;
57
    defaultvalue=document.forms[0].field_value[i].value;
50
    newin=window.open(link+"&result="+defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes');
58
    newin=window.open(link+"&result="+defaultvalue,"valuebuilder",'width=500,height=400,toolbar=false,scrollbars=yes');
Lines 169-174 function set_to_today(id, force) { Link Here
169
<h1>Items for <!-- TMPL_VAR name="title" escape="html" --> <!-- TMPL_IF NAME="author" --> by <!-- TMPL_VAR name="author" --><!-- /TMPL_IF --> (Record #<!-- TMPL_VAR NAME="biblionumber" -->)</h1>
177
<h1>Items for <!-- TMPL_VAR name="title" escape="html" --> <!-- TMPL_IF NAME="author" --> by <!-- TMPL_VAR name="author" --><!-- /TMPL_IF --> (Record #<!-- TMPL_VAR NAME="biblionumber" -->)</h1>
170
178
171
<!-- TMPL_IF NAME="barcode_not_unique" --><div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div><!-- /TMPL_IF -->
179
<!-- TMPL_IF NAME="barcode_not_unique" --><div class="dialog alert"><strong>Error saving item</strong>: Barcode must be unique.</div><!-- /TMPL_IF -->
180
<!-- TMPL_IF NAME="no_next_barcode" --><div class="dialog alert"><strong>Error saving items</strong>: Unable to automatically determine values for barcodes. No item has been inserted.</div><!-- /TMPL_IF -->
172
<!-- TMPL_IF NAME="book_on_loan" --><div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div><!-- /TMPL_IF -->
181
<!-- TMPL_IF NAME="book_on_loan" --><div class="dialog alert"><strong>Cannot Delete</strong>: item is checked out.</div><!-- /TMPL_IF -->
173
<!-- TMPL_IF NAME="book_reserved" --><div class="dialogalert"><strong>Cannot Delete</strong>: item has a waiting hold.</div><!-- /TMPL_IF -->
182
<!-- TMPL_IF NAME="book_reserved" --><div class="dialogalert"><strong>Cannot Delete</strong>: item has a waiting hold.</div><!-- /TMPL_IF -->
174
183
Lines 230-236 function set_to_today(id, force) { Link Here
230
    <input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
239
    <input type="hidden" name="itemnumber" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
231
240
232
<fieldset class="action">    <!-- TMPL_IF name="opisadd" -->
241
<fieldset class="action">    <!-- TMPL_IF name="opisadd" -->
233
    <input type="submit" value="Add item" onclick="return Check(this.form)" />
242
    <input type="submit" name="phony_submit" value="phony_submit" id="phony_submit" style="display:none;" onclick="return false;" />
243
    <!-- Note : We use here a false submit button because we have several submit buttons and we don't want the user to believe he validated the adding of multiple copies 
244
		when pressing the enter key, while in fact it is the first submit button that is validated, in our case the "add (single) item" button. 
245
		It is a bit tricky, but necessary in the sake of UI correctness. 
246
    -->
247
248
    <input type="submit" name="add_submit" value="Add item" onclick="return Check(this.form)" />
249
    <input type="submit" name="add_duplicate_submit" value="Add &amp; Duplicate" onclick="return Check(this.form)" />
250
    <input type="submit" name="add_multiple_copies" value="Add Multiple Copies" onclick="javascript:this.nextSibling.style.visibility='visible';document.f.number_of_copies.focus(); return false;" /><span id="add_multiple_copies_span" style="visibility:hidden">
251
	<label for="number_of_copies">Number of copies to add : </label>
252
	<input type="text" id="number_of_copies" name="number_of_copies" value="" size="2" />
253
	<input type="submit" id="add_multiple_copies_submit" name="add_multiple_copies_submit" value="Add" onclick="javascript:return Check(this.form) &amp;&amp; CheckMultipleAdd(this.form.number_of_copies.value);" />
254
    </span>
255
234
    <!-- TMPL_ELSE -->
256
    <!-- TMPL_ELSE -->
235
    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="itemtagfield" -->" />
257
    <input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="itemtagfield" -->" />
236
    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="itemtagsubfield" -->" />
258
    <input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="itemtagsubfield" -->" />
237
- 

Return to bug 2593