Bug 5569: Corrections to addbiblio.tmpl to be able to delete repetable mandatory...
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / modules / cataloguing / addbiblio.tmpl
1 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2 <title>Koha &rsaquo; Cataloging &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <!-- TMPL_VAR NAME="title" escape="html" --> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></title>
3 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/bubbling-min.js"></script>
5 <script type="text/javascript">
6 //<![CDATA[
7
8      var fields_in_use = {};
9          $(document).ready(function() {
10                 $('#addbibliotabs > ul').tabs().bind('show.ui-tabs', function(e, ui) {
11                         $("#"+ui.panel.id+" input:eq(0)").focus();
12                 });
13         $('.tag').each(function() {
14             var field_id = this.getAttribute('id').substring(0, 7);
15             if (field_id in fields_in_use) {
16                 fields_in_use[field_id]++;
17             } else {
18                 fields_in_use[field_id] = 1;
19             }
20         });
21         $('.subfield_line').each(function() {
22             var field_id = this.getAttribute('id').substring(0, 12);
23             if (field_id in fields_in_use) {
24                 fields_in_use[field_id]++;
25             } else {
26                 fields_in_use[field_id] = 1;
27             }
28         });
29          });
30          
31          $('#header_search > ul').tabs().bind('show.ui-tabs', function(e, ui) { $('#header_search > div:not(.ui-tabs-hide)').find('input').eq(0).focus(); });
32
33 function confirmnotdup(redirect){
34         $("#confirm_not_duplicate").attr("value","1");
35     $("#redirect").attr("value",redirect);
36         Check();
37 }
38
39 /**
40  * 
41  * 
42  */
43 function Check(){
44     var StrAlert = AreMandatoriesNotOk();
45     if( ! StrAlert ){
46         document.f.submit();
47         return true;
48     } else {
49         alert(StrAlert);
50         return false;
51     }
52 }
53
54 function Dopop(link,i) {
55     defaultvalue = document.getElementById(i).value;
56     window.open(link+"&result="+defaultvalue,"valuebuilder",'width=700,height=550,toolbar=false,scrollbars=yes');
57 }
58
59 /**
60  * this function open a popup to search on z3950 server.
61  */
62 function PopupZ3950() {
63     var strQuery = GetZ3950Terms();
64         if(strQuery){
65         window.open("/cgi-bin/koha/cataloguing/z3950_search.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"+strQuery,"z3950search",'width=740,height=450,location=yes,toolbar=no,scrollbars=yes,resize=yes');
66     } 
67 }
68
69 function PopupMARCFieldDoc(field, blocknumber) {
70     <!-- TMPL_IF NAME="MARC21" -->
71         _MARC21FieldDoc(field);
72     <!-- TMPL_ELSE -->
73         _UNIMARCFieldDoc(field, blocknumber);
74     <!-- /TMPL_IF -->
75 }
76
77 function _MARC21FieldDoc(field) {
78     if(field == 0) {
79         window.open("http://www.loc.gov/marc/bibliographic/bdleader.html");
80     } else if (field < 900) {
81         window.open("http://www.loc.gov/marc/bibliographic/bd" + ("000"+field).slice(-3) + ".html");
82     } else {
83         window.open("http://www.loc.gov/marc/bibliographic/bd9xx.html");
84     }
85 }
86
87 function _UNIMARCFieldDoc(field, blocknumber) {
88     /* http://archive.ifla.org/VI/3/p1996-1/ is an outdated version of UNIMARC, but
89        seems to be the only version available that can be linked to per tag.  More recent
90        versions of the UNIMARC standard are available on the IFLA website only as
91        PDFs!
92     */
93     if(field == 0) {
94         window.open("http://archive.ifla.org/VI/3/p1996-1/uni.htm");
95     } else if (field < 100) {
96         window.open("http://archive.ifla.org/VI/3/p1996-1/uni"+blocknumber+".htm#b" + ("000"+field).slice(-3));
97     } else if (field < 900) {
98         window.open("http://archive.ifla.org/VI/3/p1996-1/uni"+blocknumber+".htm#" + ("000"+field).slice(-3));
99     } else {
100         window.open("http://archive.ifla.org/VI/3/p1996-1/uni9.htm");
101     }
102 }
103
104 /**
105  * check if mandatory subfields are written
106  */
107 function AreMandatoriesNotOk(){
108     var mandatories = new Array();
109     var mandatoriesfields = new Array();
110     var tab = new Array();
111     var label = new Array();
112     var flag=0;
113     var tabflag= new Array();  
114     <!-- TMPL_LOOP NAME='BIG_LOOP' -->
115         <!-- TMPL_LOOP NAME='innerloop' -->
116                 <!-- TMPL_IF NAME="mandatory" -->
117                 mandatoriesfields.push(new Array("<!-- TMPL_VAR NAME="tag" -->","<!-- TMPL_VAR NAME="index" --><!-- TMPL_VAR NAME="random" -->","<!-- TMPL_VAR NAME="index" -->"));
118                 <!-- /TMPL_IF -->
119                 <!-- TMPL_LOOP NAME='subfield_loop'-->
120                         <!-- TMPL_IF NAME='mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
121                         tab.push("<!-- TMPL_VAR NAME='number' -->");
122                         label.push("<!-- TMPL_VAR NAME='marc_lib' -->");
123                 <!-- /TMPL_IF -->
124             <!-- /TMPL_LOOP -->
125         <!-- /TMPL_LOOP -->
126     <!-- /TMPL_LOOP -->
127     var StrAlert = _("Can't save this record because the following field aren't filled:");
128     StrAlert += "\n\n";
129     for(var i=0,len=mandatories.length; i<len ; i++){
130         var tag=mandatories[i].substr(4,3);
131         var subfield=mandatories[i].substr(17,1);
132         var tagnumber=mandatories[i].substr(19,mandatories[i].lastIndexOf("_")-19);
133         if (tabflag[tag+subfield+tagnumber] ==  null) { 
134             tabflag[tag+subfield+tagnumber]=new Array();
135             tabflag[tag+subfield+tagnumber][0]=0; 
136         }
137         if( tabflag[tag+subfield+tagnumber][0] != 1 && (document.getElementById(mandatories[i]) != null && ! document.getElementById(mandatories[i]).value || document.getElementById(mandatories[i]) == null)){
138             tabflag[tag+subfield+tagnumber][0] = 0 + tabflag[tag+subfield+tagnumber] ;
139             document.getElementById(mandatories[i]).setAttribute('class','subfield_not_filled');
140             document.getElementById(mandatories[i]).focus();
141             tabflag[tag+subfield+tagnumber][1]=label[i];
142             tabflag[tag+subfield+tagnumber][2]=tab[i];
143         } else {
144             tabflag[tag+subfield+tagnumber][0] = 1;
145         }    
146     }
147     for (var tagsubfieldid in tabflag){
148       if (tabflag[tagsubfieldid][0]==0){
149         var tag=tagsubfieldid.substr(0,3);
150         var subfield=tagsubfieldid.substr(3,1);    
151         StrAlert += "\t* "+_("tag ")+tag+_(" subfield ")+subfield+" "+tabflag[tagsubfieldid][1]+_(" in tab ")+tabflag[tagsubfieldid][2]+"\n";
152         //StrAlert += "\t* "+label[i]+_(" in tab ")+tab[i]+"\n"; 
153         flag=1;    
154       }   
155     }   
156     
157     /* Check for mandatories field(not subfields) */
158     for(var i=0,len=mandatoriesfields.length; i<len; i++){
159             isempty  = true;
160                 arr      = mandatoriesfields[i];
161         divid    = "tag_" + arr[0] + "_" + arr[1];
162         varegexp = new RegExp("^tag_" + arr[0] + "_code_");
163         
164                 if(parseInt(arr[0]) >= 10){
165                 elem = document.getElementById(divid);
166                 eleminputs = elem.getElementsByTagName('input');
167                 
168                 for(var j=0,len2=eleminputs.length; j<len2; j++){
169         
170                         if(eleminputs[j].name.match(varegexp) && eleminputs[j].value){
171                                         inputregexp = new RegExp("^tag_" + arr[0] + "_subfield_" + eleminputs[j].value + "_" + arr[2]);
172                                         
173                                         for( var k=0; k<len2; k++){
174                                                 if(eleminputs[k].id.match(inputregexp) && eleminputs[k].value){
175                                                         isempty = false
176                                                 }
177                                         }
178                                         
179                                         elemselect = elem.getElementsByTagName('select');
180                                         for( var k=0; k<elemselect.length; k++){
181                                                 if(elemselect[k].id.match(inputregexp) && elemselect[k].value){
182                                                         isempty = false
183                                                 }
184                                         }
185                         }
186                 }
187
188                 elemtextareas = elem.getElementsByTagName('textarea');
189                 for(var j=0,len2=elemtextareas.length; j<len2; j++){
190                 // this bit assumes that the only textareas in this context would be for subfields
191                 if (elemtextareas[j].value) {
192                     isempty = false;
193                 }
194             }
195         }else{
196                 isempty = false;
197         }
198         
199         if(isempty){
200                 flag = 1;
201                 StrAlert += _("\t* Field ") + arr[0] + _(" is mandatory, at least one of its subfields must be filled.") + "\n";
202         }
203         
204     }
205     
206     if(flag){
207             return StrAlert;
208         } else {
209                 return flag;
210         }
211 }
212
213 /** 
214  * check if z3950 mandatories are set or not
215  */
216 function GetZ3950Terms(){
217  var strQuery="&frameworkcode="+document.forms['f'].frameworkcode.value;
218     var mandatories = new Array();
219     var mandatories_label = new Array();
220     <!-- TMPL_LOOP NAME='BIG_LOOP' --><!-- TMPL_LOOP NAME='innerloop' --><!-- TMPL_LOOP NAME='subfield_loop'--><!-- TMPL_IF NAME='z3950_mandatory'-->mandatories.push("<!-- TMPL_VAR NAME='id' -->");
221         mandatories_label.push("<!-- TMPL_VAR NAME='z3950_mandatory' -->");<!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP -->
222     
223     for(var i=0,len=mandatories.length; i<len ; i++){
224         var field_value = document.getElementById(mandatories[i]).value;
225         if( field_value ){
226             strQuery += "&"+mandatories_label[i]+"="+field_value;
227         }
228     }
229     return strQuery;
230 }
231
232 function Changefwk(FwkList) {
233         var fwk = FwkList.options[FwkList.selectedIndex].value;
234         window.location = "/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->&breedingid=<!-- TMPL_VAR name="breedingid" -->&frameworkcode="+fwk;
235
236 }
237
238 // returns the subfieldcode based upon subfieldid writing
239 function getSubfieldcode(tagsubfieldid){
240     // 3 : tag +3 : tagnumber +4 : number of _ +8 subfield -1 begins at 0  
241     return tagsubfieldid.substr(3+3+4+8-1,1);
242 }
243
244 // Take the base of tagsubfield information (removing the subfieldcodes and subfieldindexes)
245 // returns the filter
246 function getTagInputnameFilter(tagsubfieldid){
247     var tagsubfield=tagsubfieldid.substr(0,tagsubfieldid.lastIndexOf("_"));  
248     var tagcode=tagsubfield.substr(tagsubfield.lastIndexOf("_"));
249     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
250     tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_"));
251     tagsubfield=tagsubfield+"_."+tagcode;
252     return tagsubfield;  
253 }
254
255 function openAuth(tagsubfieldid,authtype) {
256     // let's take the base of tagsubfield information (removing the indexes and the codes
257     var element=document.getElementById(tagsubfieldid);
258     var tagsubfield=getTagInputnameFilter(tagsubfieldid);
259     var elementsubfcode=getSubfieldcode(element.name);
260     var mainmainstring=element.value;
261     var mainstring="";  
262     var inputs = element.parentNode.parentNode.getElementsByTagName("input");
263
264     for (var myindex =0; myindex<inputs.length;myindex++){
265         if (inputs[myindex].name && inputs[myindex].name.match(tagsubfield)){
266             var subfieldcode=getSubfieldcode(inputs[myindex].name);
267             if (isNaN(parseInt(subfieldcode)) && inputs[myindex].value != "" && subfieldcode!=elementsubfcode){
268                 mainstring=inputs[myindex].value+" "+mainstring;
269             }      
270         }
271     }           
272         newin=window.open("../authorities/auth_finder.pl?authtypecode="+  authtype+ "&index="+tagsubfieldid+"&value_mainstr="+encodeURI(mainmainstring)+"&value_main="+encodeURI(mainstring), "_blank",'width=700,height=550,toolbar=false,scrollbars=yes');
273 }
274
275
276 function ExpandField(index) {
277     var original = document.getElementById(index); //original <div>
278     var divs = original.getElementsByTagName('div');
279     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
280         if(divs[i].getAttribute('id').match(/^subfield/)){  // if it s a subfield
281             if (divs[i].style.display == 'block') {
282                 divs[i].style.display = 'none';
283             } else {
284                 divs[i].style.display = 'block';
285             }
286         }
287     }
288 }
289
290 /**
291  * To clone a field or a subfield by clicking on '+' button
292  */ 
293 function CloneField(index) {
294     var original = document.getElementById(index); //original <div>
295     fields_in_use[index.substr(0, 7)]++;
296     var clone = original.cloneNode(true);
297     var new_key = CreateKey();
298     var new_id  = original.getAttribute('id')+new_key;
299     
300     clone.setAttribute('id',new_id); // setting a new id for the parent div
301     
302     var divs = clone.getElementsByTagName('div');
303     
304     <!-- TMPL_UNLESS NAME='hide_marc'--> // No indicator if hide_marc
305         // setting a new name for the new indicator
306         for(var i=0; i < 2; i++) {
307             var indicator = clone.getElementsByTagName('input')[i];
308             indicator.setAttribute('name',indicator.getAttribute('name')+new_key);
309         }
310     <!-- /TMPL_UNLESS -->
311         
312     // settings all subfields
313     for(var i=0,divslen = divs.length ; i<divslen ; i++){      // foreach div
314         if(divs[i].getAttribute("id").match(/^subfield/)){  // if it s a subfield
315             
316             // set the attribute for the new 'div' subfields
317             divs[i].setAttribute('id',divs[i].getAttribute('id')+new_key);
318             
319             var inputs   = divs[i].getElementsByTagName('input');
320             var id_input = "";
321             
322             for( j = 0 ; j < inputs.length ; j++ ) {
323                 if(inputs[j].getAttribute("id") && inputs[j].getAttribute("id").match(/^tag_/) ){
324                         inputs[j].value = "";
325                 }
326             }
327             
328             inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
329             inputs[0].setAttribute('name',inputs[0].getAttribute('name')+new_key);
330             var id_input;
331             try {
332                 id_input = inputs[1].getAttribute('id')+new_key;
333                 inputs[1].setAttribute('id',id_input);
334                 inputs[1].setAttribute('name',inputs[1].getAttribute('name')+new_key);
335             } catch(e) {
336                 try{ // it s a select if it is not an input
337                     var selects = divs[i].getElementsByTagName('select');
338                     id_input = selects[0].getAttribute('id')+new_key;
339                     selects[0].setAttribute('id',id_input);
340                     selects[0].setAttribute('name',selects[0].getAttribute('name')+new_key);
341                 }catch(e2){ // it is a textarea if it s not a select or an input
342                         var textaeras = divs[i].getElementsByTagName('textarea');
343                         id_input = textaeras[0].getAttribute('id')+new_key;
344                         textaeras[0].setAttribute('id',id_input);
345                     textaeras[0].setAttribute('name',textaeras[0].getAttribute('name')+new_key);
346                 }
347             }
348             
349             <!-- TMPL_UNLESS NAME='advancedMARCEditor'-->
350             // when cloning a subfield, re set its label too.
351             var labels = divs[i].getElementsByTagName('label');
352             labels[0].setAttribute('for',id_input);
353             <!-- /TMPL_UNLESS -->
354             
355             <!-- TMPL_UNLESS NAME='hide_marc'-->
356                 // updating javascript parameters on button up
357                 var imgs = divs[i].getElementsByTagName('img');
358                 imgs[0].setAttribute('onclick',"upSubfield(\'"+divs[i].getAttribute('id')+"\');");
359             <!-- /TMPL_UNLESS -->
360             
361             // setting its '+' and '-' buttons
362             try {
363                 var anchors = divs[i].getElementsByTagName('a');
364                 for (var j = 0; j < anchors.length; j++) {
365                     if(anchors[j].getAttribute('class') == 'buttonPlus'){
366                         anchors[j].setAttribute('onclick',"CloneSubfield('" + divs[i].getAttribute('id') + "')");
367                     } else if (anchors[j].getAttribute('class') == 'buttonMinus') {
368                         anchors[j].setAttribute('onclick',"UnCloneField('" + divs[i].getAttribute('id') + "')");
369                     }
370                 }
371             }
372             catch(e){
373                 // do nothig if ButtonPlus & CloneButtonPlus don t exist.
374             }
375             
376             // button ...
377             var spans=0;
378             try {
379                 spans = divs[i].getElementsByTagName('a');
380             } catch(e) {
381                 // no spans
382             }
383             if(spans){
384                 var buttonDot;
385                 if(!CloneButtonPlus){ // it s impossible to have  + ... (buttonDot AND buttonPlus)
386                     buttonDot = spans[0];
387                     if(buttonDot){
388                         // 2 possibilities :
389                         try{
390                             var buttonDotOnClick = buttonDot.getAttribute('onclick');
391                             if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
392                                 var re = /\('.*'\)/i;
393                                 buttonDotOnClick = buttonDotOnClick.replace(re,"('"+inputs[1].getAttribute('id')+"')");
394                                 if(buttonDotOnClick){
395                                     buttonDot.setAttribute('onclick',buttonDotOnClick);
396                                 }
397                             } else {
398                                 if(buttonDotOnClick.match('Dopop')) {  // -2- It's a auth value
399                                     var re1 = /&index=.*',/;
400                                     var re2 = /,.*\)/;
401
402                                     buttonDotOnClick = buttonDotOnClick.replace(re1,"&index="+inputs[1].getAttribute('id')+"',");
403                                     buttonDotOnClick = buttonDotOnClick.replace(re2,",'"+inputs[1].getAttribute('id')+"')");
404                                     
405                                     if(buttonDotOnClick){
406                                             buttonDot.setAttribute('onclick',buttonDotOnClick);
407                                     }
408                                 }
409                             }
410                             try {
411                                 // do not copy the script section.
412                                 var script = spans[0].getElementsByTagName('script')[0];
413                                 spans[0].removeChild(script);
414                             } catch(e) {
415                                 // do nothing if there is no script
416                             }
417                         }catch(e){}
418                         }
419                 }
420             }
421             <!-- TMPL_UNLESS NAME='hide_marc'-->
422                 var buttonUp = divs[i].getElementsByTagName('img')[0];
423                 buttonUp.setAttribute('onclick',"upSubfield('" + divs[i].getAttribute('id') + "')");
424             <!-- /TMPL_UNLESS -->
425             
426         } else { // it's a indicator div
427             if(divs[i].getAttribute('id').match(/^div_indicator/)){
428                 var inputs = divs[i].getElementsByTagName('input');
429                 inputs[0].setAttribute('id',inputs[0].getAttribute('id')+new_key);
430                 inputs[1].setAttribute('id',inputs[1].getAttribute('id')+new_key);
431                 
432                 var CloneButtonPlus;
433                 try {
434                     var anchors = divs[i].getElementsByTagName('a');
435                     for (var j = 0; j < anchors.length; j++) {
436                         if (anchors[j].getAttribute('class') == 'buttonPlus') {
437                             anchors[j].setAttribute('onclick',"CloneField('" + new_id + "')");
438                         } else if (anchors[j].getAttribute('class') == 'buttonMinus') {
439                             anchors[j].setAttribute('onclick',"UnCloneField('" + new_id + "')");
440                         } else if (anchors[j].getAttribute('class') == 'expandfield') {
441                             anchors[j].setAttribute('onclick',"ExpandField('" + new_id + "')");
442                         }
443                     }
444                 }
445                 catch(e){
446                     // do nothig CloneButtonPlus doesn't exist.
447                 }
448
449             }
450         }
451     }
452     
453     // insert this line on the page
454     original.parentNode.insertBefore(clone,original.nextSibling);
455 }
456
457 function CloneSubfield(index){
458     var original = document.getElementById(index); //original <div>
459     fields_in_use[index.substr(0, 12)]++;
460     var clone = original.cloneNode(true);
461     var new_key = CreateKey();
462     var new_id  = original.getAttribute('id')+new_key;
463     // set the attribute for the new 'div' subfields
464     var inputs     = clone.getElementsByTagName('input');
465     var selects    = clone.getElementsByTagName('select');
466     var textareas  = clone.getElementsByTagName('textarea');
467     var linkid;
468
469     // input
470     var id_input = "";
471     for(var i=0,len=inputs.length; i<len ; i++ ){
472         id_input = inputs[i].getAttribute('id')+new_key;
473         inputs[i].setAttribute('id',id_input);
474         inputs[i].setAttribute('name',inputs[i].getAttribute('name')+new_key);
475         linkid = id_input;
476     }
477     
478     // select 
479     for(var i=0,len=selects.length; i<len ; i++ ){
480         id_input = selects[i].getAttribute('id')+new_key;
481         selects[i].setAttribute('id',selects[i].getAttribute('id')+new_key);
482         selects[i].setAttribute('name',selects[i].getAttribute('name')+new_key);
483     }
484     
485     // textarea
486     for(var i=0,len=textareas.length; i<len ; i++ ){
487         id_input = textareas[i].getAttribute('id')+new_key;
488         textareas[i].setAttribute('id',textareas[i].getAttribute('id')+new_key);
489         textareas[i].setAttribute('name',textareas[i].getAttribute('name')+new_key);
490     }
491
492     // Changing the "..." link's onclick attribute for plugin callback
493     var links  = clone.getElementsByTagName('a');
494     var link = links[0];
495     var buttonDotOnClick = link.getAttribute('onclick');
496     if(buttonDotOnClick.match('Clictag')){   // -1- It s a plugin
497         var re = /\('.*'\)/i;
498         buttonDotOnClick = buttonDotOnClick.replace(re,"('"+linkid+"')");
499         if(buttonDotOnClick){
500             link.setAttribute('onclick',buttonDotOnClick);
501         }
502     }
503
504
505     <!-- TMPL_UNLESS NAME='advancedMARCEditor' -->
506     // when cloning a subfield, reset its label too.
507     var label = clone.getElementsByTagName('label')[0];
508     label.setAttribute('for',id_input);
509     <!-- /TMPL_UNLESS -->
510     
511     // setting a new id for the parent div
512     clone.setAttribute('id',new_id);
513     
514     try {
515         var buttonUp = clone.getElementsByTagName('img')[0];
516         buttonUp.setAttribute('onclick',"upSubfield('" + new_id + "')");
517         var anchors = clone.getElementsByTagName('a');
518         if(anchors.length){
519             for(var i = 0 ,lenanchors = anchors.length ; i < lenanchors ; i++){
520                 if(anchors[i].getAttribute('class') == 'buttonPlus'){
521                     anchors[i].setAttribute('onclick',"CloneSubfield('" + new_id + "')");
522                 } else if (anchors[i].getAttribute('class') == 'buttonMinus') {
523                     anchors[i].setAttribute('onclick',"UnCloneField('" + new_id + "')");
524                 }
525             }
526         }
527     }
528     catch(e){
529         // do nothig if ButtonPlus & CloneButtonPlus don't exist.
530     }
531     // insert this line on the page
532     original.parentNode.insertBefore(clone,original.nextSibling);
533 }
534
535  /**
536  * This function removes or clears unwanted subfields
537  */
538 function UnCloneField(index) {
539     var original = document.getElementById(index);
540     var field_id;
541     if (index.match("tag")) {
542         field_id = index.substr(0, 7);
543     } else {
544         field_id = index.substr(0, 12);
545     }
546     if (1 == fields_in_use[field_id]) {
547         // clear inputs, but don't delete
548         $(":input.input_marceditor", original).each(function(){
549             // thanks to http://www.learningjquery.com/2007/08/clearing-form-data for
550             // hint about clearing selects correctly
551             var type = this.type;
552             var tag = this.tagName.toLowerCase();
553             if (type == 'text' || type == 'password' || tag == 'textarea') {
554                 this.value = "";
555             } else if (type == 'checkbox' || type == 'radio') {
556                 this.checked = false;
557             } else if (tag == 'select') {
558                 this.selectedIndex = -1;
559             }
560         });
561         $(":input.indicator", original).val("");
562     } else {
563         original.parentNode.removeChild(original);
564         fields_in_use[field_id]--;
565     }
566 }
567
568 /**
569  * This function create a random number
570  */
571 function CreateKey(){
572     return parseInt(Math.random() * 100000);
573 }
574
575 /**
576  * This function allows to move a subfield up by clickink on the 'up' button .
577  */
578 function upSubfield(index) {
579     try{
580         var line = document.getElementById(index); // get the line where the user has clicked.
581     } catch(e) {
582         return; // this line doesn't exist...
583     }
584     var tag = line.parentNode; // get the dad of this line. (should be "<div id='tag_...'>")
585     
586     // getting all subfields for this tag
587     var subfields = tag.getElementsByTagName('div');
588     var subfieldsLength = subfields.length;
589     
590     if(subfieldsLength<=1) return; // nothing to do if there is just one subfield.
591     
592     // among all subfields 
593     for(var i=0;i<subfieldsLength;i++){ 
594         if(subfields[i].getAttribute('id') == index){ //looking for the subfield which is clicked :
595             if(i==1){ // if the clicked subfield is on the top
596                 tag.appendChild(subfields[1]);
597                 return;
598             } else {
599                 var lineAbove = subfields[i-1];
600                 tag.insertBefore(line,lineAbove);
601                 return;
602             }
603         }
604     }
605 }
606
607 function unHideSubfield(index,labelindex) { // FIXME :: is it used ?
608     subfield = document.getElementById(index);
609     subfield.style.display = 'block';
610     label = document.getElementById(labelindex);
611     label.style.display='none'; 
612 }
613 //]]>
614 </script>
615 <link type="text/css" rel="stylesheet" href="<!-- TMPL_VAR NAME="themelang" -->/css/addbiblio.css" />
616 </head>
617 <body>
618 <div id="yui-cms-loading">
619       <div id="yui-cms-float">
620           Loading, please wait...
621       </div>
622   </div>
623 <script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/yui/plugins/loading-min.js"></script>
624 <script type="text/javascript">
625 //<![CDATA[
626 (function() {
627         // configuring the loading mask
628         YAHOO.widget.Loading.config({
629                 opacity: 0.8
630         });
631 })();
632 //]]>
633 </script>
634 <!-- TMPL_INCLUDE NAME="header.inc" -->
635 <div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/cataloguing/addbooks.pl">Cataloging</a>  &rsaquo; <!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)<!-- TMPL_ELSE -->Add MARC Record<!-- /TMPL_IF --></div>
636
637 <div id="doc" class="yui-t7">
638
639 <div id="bd">
640         <div id="yui-main">
641         <div class="yui-g">
642
643
644
645 <h1><!-- TMPL_IF NAME="biblionumber" -->Editing <em><!-- TMPL_VAR NAME="title" escape="html" --></em> (Record Number <!-- TMPL_VAR name="biblionumber" -->)</h1><!-- TMPL_ELSE -->Add MARC Record</h1><!-- /TMPL_IF -->
646
647 <!-- TMPL_UNLESS name="number" -->
648     <!-- show duplicate warning on tab 0 only -->
649         <!-- TMPL_IF name="duplicatebiblionumber" -->
650                     <div class="dialog alert">
651                         <h4>Duplicate Record suspected</h4>
652                         <p>Is this a duplicate of <a href="/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->" onclick="openWindow('../MARCdetail.pl?biblionumber=<!-- TMPL_VAR name="duplicatebiblionumber" -->&amp;popup=1', 'Duplicate biblio'; return false;)"><!-- TMPL_VAR name="duplicatetitle" --></a>?</p>
653                         <!-- TMPL_IF NAME="CAN_user_editcatalogue_edit_items" --><form action="/cgi-bin/koha/cataloguing/additem.pl" method="get">
654                                                     <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="duplicatebiblionumber" -->" />
655                                                     <input type="submit" class="edit" value="Yes: Edit existing items" />
656                                                 </form><!-- TMPL_ELSE --><form action="/cgi-bin/koha/catalogue/detail.pl" method="get">
657                                                     <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR name="duplicatebiblionumber" -->" />
658                                                     <input type="submit" value="Yes: View existing items" />
659                                                 </form><!-- /TMPL_IF -->
660                         <form action="/cgi-bin/koha/cataloguing/addbiblio.pl" method="get">
661                         <!-- TMPL_IF NAME="CAN_user_editcatalogue_edit_items" --><input type="button" class="save" onclick="confirmnotdup('items'); return false;" value="No: Save as New Record" /><!-- TMPL_ELSE --><input type="button" class="save" onclick="confirmnotdup('view'); return false;" value="No: Save as New Record" /><!-- /TMPL_IF -->
662                         </form>
663                     </div>
664         <!-- /TMPL_IF -->
665     <!-- /TMPL_UNLESS -->
666
667 <!--TMPL_IF Name="done"-->
668     <script type="text/javascript">
669         opener.document.forms['f'].biblionumber.value=<!--TMPL_VAR Name="biblionumber"-->;
670         opener.document.forms['f'].title.value='<!--TMPL_VAR Name="title" ESCAPE="HTML"-->';
671         window.close();
672     </script>
673 <!--TMPL_ELSE-->
674     <form method="post" name="f" id="f" action="/cgi-bin/koha/cataloguing/addbiblio.pl" onsubmit="return Check();">
675     <input type="hidden" value="<!-- tmpl_if name="biblionumber" -->view<!-- tmpl_else -->items<!-- /tmpl_if -->" id="redirect" name="redirect" />
676         <input type="hidden" value="0" id="confirm_not_duplicate" name="confirm_not_duplicate" />
677 <!-- /TMPL_IF -->
678         
679 <div id="toolbar">
680
681 <script type="text/javascript">
682         //<![CDATA[
683
684         // prepare DOM for YUI Toolbar
685
686          $(document).ready(function() {
687                 $("#z3950searchc").empty();
688         $("#savebutton").empty();
689             yuiToolbar();
690          });
691
692     function redirect(dest){
693         $("#redirect").attr("value",dest);
694         return Check();
695     }
696 <!-- TMPL_IF NAME="CAN_user_editcatalogue_edit_items" -->
697     var onOption = function () {
698         return Check();
699     }
700
701     var savemenu = [
702         { text: _("Save and view record"), value: 1, onclick: {fn:function(){redirect("view");}} },
703         { text: _("Save and edit items"), value: 2, onclick: {fn:function(){redirect("items");}} }
704     ];
705 <!-- /TMPL_IF -->
706
707         // YUI Toolbar Functions
708
709         function yuiToolbar() {
710 <!-- TMPL_IF NAME="CAN_user_editcatalogue_edit_items" -->
711         var savesplitmenu = new YAHOO.widget.Button({
712             type: "split",
713             label: _("Save"),
714             id: "addbiblio",
715             name: "savemenubutton",
716             menu: savemenu,
717             container: "savebutton"
718          });
719
720         savesplitmenu.on("click", onOption); 
721 <!-- TMPL_ELSE -->
722         new YAHOO.widget.Button({
723             id: "addbiblio",
724             type: "button",
725             label: _("Save"),
726             container: "savebutton",
727             onclick: {fn:function(){redirect("view");}}
728         });
729 <!-- /TMPL_IF -->
730                 new YAHOO.widget.Button({
731             id: "z3950search",
732             type: "button",
733             label: _("Z39.50 Search"),
734             container: "z3950searchc",
735                         onclick: {fn:function(){PopupZ3950()}}
736         });
737         }
738
739         //]]>
740         </script>
741
742                 <ul class="toolbar">
743                         <li id="savebutton"><input id="addbiblio" type="submit" value="Save" /></li>
744                         <li id="z3950searchc"><input type="button" id="z3950search" value="Z39.50 Search" onclick="PopupZ3950(); return false;" /></li>
745                         <li id="changeframework"><label for="Frameworks">Change framework: </label>
746                         <select name="Frameworks" id="Frameworks" onchange="Changefwk(this);">
747                                         <option value="Default">Default</option>
748                                                         <!-- TMPL_LOOP NAME="frameworkcodeloop" -->                                             
749                                 <option value="<!-- TMPL_VAR NAME="value"-->" <!-- TMPL_VAR NAME="selected" -->>
750                                                      <!-- TMPL_VAR NAME="frameworktext" -->                                      
751                                  </option>                          
752                                                 <!-- /TMPL_LOOP -->
753                         </select> 
754 <input type="hidden" name="op" value="addbiblio" /></li>
755                 </ul>
756 </div>
757
758 <!--TMPL_IF Name="popup"-->
759         <input type="hidden" name="mode" value="popup" />
760 <!--/TMPL_IF-->
761         <input type="hidden" name="frameworkcode" value="<!-- TMPL_VAR NAME="frameworkcode" -->" />
762         <input type="hidden" name="biblionumber" value="<!-- TMPL_VAR NAME="biblionumber" -->" />
763         <input type="hidden" name="breedingid" value="<!-- TMPL_VAR NAME="breedingid" -->" />
764
765 <div id="addbibliotabs" class="toptabs numbered">
766         <ul><!-- TMPL_LOOP name="BIG_LOOP" -->
767           <li>  <!-- TMPL_IF name="number" -->
768                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
769             <!-- TMPL_ELSE -->
770                 <a href="/cgi-bin/koha/cataloguing/addbiblio.pl#tab<!-- TMPL_VAR name="number" -->XX"><!-- TMPL_VAR name="number"--></a>
771             <!-- /TMPL_IF --></li>
772         <!--  /TMPL_LOOP --></ul>
773
774 <!-- TMPL_LOOP name="BIG_LOOP" -->
775 <!-- hide every tab except the 1st -->
776 <!-- TMPL_IF name="number" -->
777     <div id="tab<!-- TMPL_VAR name="number" -->XX">
778 <!-- TMPL_ELSE -->
779     <div id="tab<!-- TMPL_VAR name="number" -->XX">
780 <!-- /TMPL_IF -->
781
782     
783     <!-- TMPL_LOOP NAME="innerloop" -->
784         <!-- TMPL_IF NAME="tag" -->
785         <div class="tag" id="tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
786         <div class="tag_title" id="div_indicator_tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->">
787             <!-- TMPL_UNLESS name="hide_marc" -->
788                 <!-- TMPL_IF NAME="advancedMARCEditor" -->
789                 <a href="#" tabindex="1" class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib"--> - Click to Expand this Tag" onclick="ExpandField('tag_<!-- TMPL_VAR NAME="tag"-->_<!-- TMPL_VAR NAME='index' --><!-- TMPL_VAR NAME="random" -->'); return false;"><!-- TMPL_VAR NAME="tag" --></a>
790                 <!-- TMPL_ELSE -->
791                         <span class="tagnum" title="<!-- TMPL_VAR NAME="tag_lib" -->"><!-- TMPL_VAR NAME="tag" --><a 
792                  onclick="PopupMARCFieldDoc('<!-- TMPL_VAR NAME="tag" -->', <!-- TMPL_VAR NAME="number" -->); return false;">&nbsp;?</a></span>
793                 <!-- /TMPL_IF -->
794                 <!-- TMPL_IF NAME="fixedfield" -->
795                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
796                         <input tabindex="1" class="indicator flat" type="text" style="display:none;" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
797                 <!-- TMPL_ELSE -->
798                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator1" -->" />
799                         <input tabindex="1" class="indicator flat" type="text" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" size="1" maxlength="1" value="<!-- TMPL_VAR NAME="indicator2" -->" />
800                 <!-- /TMPL_IF --> -
801             <!-- TMPL_ELSE -->
802                 <!-- TMPL_IF NAME="fixedfield" -->
803                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
804                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
805                 <!-- TMPL_ELSE -->
806                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator1_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator1" -->" />
807                     <input tabindex="1" type="hidden" name="tag_<!-- TMPL_VAR NAME="tag" -->_indicator2_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->" value="<!-- TMPL_VAR NAME="indicator2" -->" />
808                 <!-- /TMPL_IF -->
809             <!-- /TMPL_UNLESS -->
810
811             <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
812                     <a href="#" tabindex="1" class="expandfield" onclick="ExpandField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Click to Expand this Tag"><!-- TMPL_VAR NAME="tag_lib" --></a>
813             <!-- /TMPL_UNLESS -->
814             <!-- TMPL_IF name="repeatable" -->
815                 <a href="#" tabindex="1" class="buttonPlus" onclick="CloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Repeat this Tag">+</a>
816             <!-- /TMPL_IF -->
817                 <a href="#" tabindex="1" class="buttonMinus" onclick="UnCloneField('tag_<!-- TMPL_VAR name="tag"-->_<!-- TMPL_VAR NAME='index'--><!-- TMPL_VAR name="random" -->'); return false;" title="Delete this Tag">&#8722;</a>
818             
819         </div>
820         
821         <!-- TMPL_LOOP NAME="subfield_loop" -->
822             <!--  One line on the marc editor -->
823             <div class="subfield_line" style="<!-- TMPL_VAR NAME='visibility' -->; float: left; clear: left; width: 100%;" id="subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->">
824             
825                 <!--TMPL_UNLESS NAME="advancedMARCEditor" -->
826                     <label for="tag_<!-- TMPL_VAR NAME='tag'-->_subfield_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" <!-- TMPL_IF NAME="fixedfield" --> style="display:none;" <!-- /TMPL_IF --> class="labelsubfield">
827                 <!-- /TMPL_UNLESS --> 
828                 
829                 <!-- TMPL_UNLESS name="hide_marc" -->
830                 <span class="subfieldcode"><!-- TMPL_IF NAME="fixedfield" --> 
831                         <img class="buttonUp" style="display:none;" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
832                     <!-- TMPL_ELSE -->
833                         <img class="buttonUp" src="<!-- TMPL_VAR NAME="themelang" -->/../img/up.png" onclick="upSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->')" alt="Move Up" title="Move Up" />
834                     <!-- /TMPL_IF -->
835                         <input title="<!-- TMPL_VAR NAME='marc_lib_plain' -->" style=" <!-- TMPL_IF NAME="fixedfield" -->display:none; <!-- /TMPL_IF -->border:0;" type="text" tabindex="0" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" size="1" maxlength="1" class="flat" />
836  </span>
837                 <!-- TMPL_ELSE -->
838                     <input type="hidden" name="tag_<!-- TMPL_VAR NAME='tag'-->_code_<!--  TMPL_VAR NAME='subfield'-->_<!-- TMPL_VAR NAME='index'-->_<!-- TMPL_VAR NAME='index_subfield'-->" value="<!-- TMPL_VAR NAME="subfield" -->" />
839  </span>
840                 <!-- /TMPL_UNLESS -->
841             
842                 <!-- TMPL_UNLESS NAME="advancedMARCEditor" -->
843                     <!-- TMPL_IF name="mandatory" --><span class="subfield subfield_mandatory"><!-- TMPL_ELSE --><span class="subfield"><!-- /TMPL_IF -->
844                         <!-- TMPL_VAR NAME="marc_lib_plain" -->
845                         <!-- TMPL_IF NAME="mandatory" --><span class="mandatory_marker" title="This field is mandatory">*</span><!-- /TMPL_IF -->
846                     </span>
847                     </label>
848                 <!-- /TMPL_UNLESS -->
849                 
850                 <!-- TMPL_VAR NAME="marc_value" -->
851                 
852                 <!-- TMPL_IF NAME="repeatable" -->
853                     <span class="subfield_controls"><a href="#" class="buttonPlus" tabindex="1" onclick="CloneSubfield('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/clone-subfield.png" alt="Clone" title="Clone this subfield" /></a>
854                                         <a href="#" class="buttonMinus" tabindex="1" onclick="UnCloneField('subfield<!-- TMPL_VAR NAME='tag' --><!-- TMPL_VAR NAME='subfield' --><!-- TMPL_VAR name="random" -->'); return false;"><img src="/intranet-tmpl/prog/img/delete-subfield.png" alt="Delete" title="Delete this subfield" /></a></span>
855                 <!-- /TMPL_IF -->
856
857                 
858             </div>
859             <!-- End of the line -->
860             
861         <!-- /TMPL_LOOP -->
862         </div>
863         <!-- /TMPL_IF --><!-- tag -->
864     <!-- /TMPL_LOOP -->
865     </div>
866 <!-- /TMPL_LOOP -->
867 </div>
868 </form>
869
870 </div>
871 </div>
872 </div>
873
874 <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->