<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->Koha -- 權威控制
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="masthead.inc" -->
<!-- TMPL_INCLUDE NAME="authorities-topmenu.inc" -->
<!-- TMPL_INCLUDE NAME="intranet-nav.inc" -->

<div id="main">
<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR NAME="themelang" -->/includes/marc-editor.css">

<div class="tabbed">
	<form method="post" action="authorities.pl" name="f">
	<!-- TMPL_IF name="authid" -->
		<h1>修改權威記錄 #<!-- TMPL_VAR NAME="authid" --> <!-- TMPL_IF NAME="authtypetext" -->(<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF --></h1>
	<!-- TMPL_ELSE -->
		<h1>新增權威記錄 <!-- TMPL_IF NAME="authtypetext" -->(<!-- TMPL_VAR name="authtypetext" -->)<!-- /TMPL_IF --></h1>
	<!-- /TMPL_IF -->
	<p>
		<input type="hidden" name="op" value="add" />
		<input type="hidden" name="addfield_field" />
		<input type="hidden" name="authtypecode" value="<!-- TMPL_VAR NAME="authtypecode" -->" />
		<input type="hidden" name="authid" value="<!-- TMPL_VAR NAME="authid" -->" />
		<!-- TMPL_IF name="authid" -->
			<input type="button" value="儲存" onClick="Check(this.form)" accesskey="w" class="submit" />
		<!-- TMPL_ELSE -->
			<input type="button" value="新增權威記錄" onClick="Check(this.form)" accesskey="w" class="submit" />
		<!-- /TMPL_IF -->
<!--		<a href="javascript:PopupZ3950()" class="button authority">z3950 查詢</a> -->
	</p>
</div>

<!-- TMPL_IF name="duplicateauthid" -->
	<div class="error">
		<p>Duplicate suspected with <a href="javascript:openWindow('detail.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->&amp;popup=1', 'Duplicate Authority')"><!-- TMPL_VAR name="duplicateauthvalue" --></a></p>
		<p>你必須 :</p>
		<ul>
			<p><input type="checkbox" value="1" name="confirm_not_duplicate" />確認這是一個複本 (而且再點選 <input type="button" value="新增權威記錄" onClick="Check(this.form)" accesskey="w" class="button authority"> )</p>
			<p>返回 <a href="authorities.pl?authid=<!-- TMPL_VAR name="duplicateauthid" -->" >原始權威記錄</a></p>
		</ul>
	</div>
<!-- /TMPL_IF -->

<!-- TMPL_LOOP NAME="0XX" -->
	<!-- TMPL_IF name="tag" -->
		<p class="MARCtag">
		<!-- TMPL_VAR NAME="tag" -->
		<input type="hidden" name="ind_tag" value="<!-- TMPL_VAR NAME="tag" -->">
		<input type="text" name="indicator" size="3" maxlength="2" value="<!-- TMPL_VAR NAME="indicator" -->"> - <TMPL_VAR NAME="tag_lib">
		<!-- TMPL_IF name="repeatable" -->
			<a href="javascript:AddField(<!-- TMPL_VAR NAME="tag" -->)">+</a>
		<!-- /TMPL_IF -->
		</p>
	<!-- /TMPL_IF -->
	<!-- TMPL_LOOP NAME="subfield_loop" -->
		<p>
			<label class="labelsubfield">
				<!-- TMPL_UNLESS name="hide_marc" -->
					<a href="#" onclick="upSubfield('<!-- TMPL_VAR name="index" -->'); return false;">前一頁</a>
						<input type="text" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->" size="1" maxlength="1">
				<!-- TMPL_ELSE -->
						<input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->">
				<!-- /TMPL_UNLESS -->
				<!-- TMPL_IF name="mandatory" --><b><!-- /TMPL_IF -->
				<!-- TMPL_VAR NAME="marc_lib" -->
				<!-- TMPL_IF name="mandatory" --> *</b><!-- /TMPL_IF -->
			</label>
			<!-- TMPL_VAR NAME="marc_value" -->
			<input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->">
			<input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->">
			<input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->">
			<input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
			<input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->">
		</p>
	<!-- /tmpl_loop -->
<!-- /tmpl_loop -->
		
		<div name="hidden" id="hidden" class="tab">
		<!-- TMPL_LOOP NAME="hidden_loop" -->
				<input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="tag" -->">
				<input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="subfield" -->">
				<input type="hidden" name="mandatory" value="<!-- TMPL_VAR NAME="mandatory" -->">
				<input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
				<input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->">
		<!-- /TMPL_LOOP -->
		</div>
		<!-- TMPL_IF name="oldbiblionumtagfield" -->
			<input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldbiblionumtagfield" -->">
			<input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldbiblionumtagsubfield" -->">
			<input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="oldbiblionumber" -->">
			<input type="hidden" name="mandatory" value="0">
			<input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
			<input type="hidden" name="tag" value="<!-- TMPL_VAR NAME="oldbiblioitemnumtagfield" -->">
			<input type="hidden" name="subfield" value="<!-- TMPL_VAR NAME="oldbiblioitemnumtagsubfield" -->">
			<input type="hidden" name="field_value" value="<!-- TMPL_VAR NAME="oldbiblioitemnumber" -->">
			<input type="hidden" name="mandatory" value="0">
			<input type="hidden" name="kohafield" value="<!-- TMPL_VAR NAME="kohafield" -->">
			<input type="hidden" name="tag_mandatory" value="<!-- TMPL_VAR NAME="tag_mandatory" -->">
		<!-- /TMPL_IF -->
	</form>
<script language="JavaScript" type="text/javascript">
function _(s) { return s } // dummy function for gettext
function active(numlayer)
{
	for (i=0; i < 10 ; i++ ) {
		ong = i+"XX";
		link = "link"+i;
		if (numlayer==i) {
			document.getElementById(ong).style.visibility="visible";
		} else {
			document.getElementById(ong).style.visibility="hidden";
		}
	}
}
function Check(f) {
	// Scan for nonempty fields
	var field_is_nonempty_p = new Array();
	for (i=0 ; i<f.field_value.length ; i++) {
	    field_is_nonempty_p[f.tag[i].value] = 0;
	}
	for (i=0 ; i<f.field_value.length ; i++) {
	    if (f.field_value[i].value.length != 0) {
		field_is_nonempty_p[f.tag[i].value] += 1;
	    }
	}

	// Scan for missing mandatory subfields
	var total_missing_mandatory_subfields = 0;
	for (i=0 ; i<f.field_value.length-2 ; i++) {
		if (f.field_value[i].value.length==0 && f.mandatory[i].value==1) {
		    // We should not flag an error unless the tag is also
		    // mandatory, or if something else in the tag is entered

		    if (f.tag_mandatory[i].value == 1 || field_is_nonempty_p[f.tag[i].value]) {
			document.getElementById("error"+i).style.backgroundColor="#FF0000";
			total_missing_mandatory_subfields++;
		    }
		} else {
			document.getElementById("error"+i).style.backgroundColor="#FFFFFF";
		}
	}

	// Scan for missing mandatory tags
	var total_missing_mandatory_tags = 0;
	var seen_mandatory_tag_p = new Array();
	for (i=0 ; i<f.field_value.length ; i++) {
	    var j = f.tag[i].value;
	    if (!field_is_nonempty_p[j] && f.tag_mandatory[i].value == 1) {
		if (seen_mandatory_tag_p[j] != 1) {
		    seen_mandatory_tag_p[j] = 1;
		    total_missing_mandatory_tags++;
		}
		document.getElementById("error"+i).style.backgroundColor="#ffff00";
	    }
	}

	var total_errors = total_missing_mandatory_tags + total_missing_mandatory_subfields;
	var alertString2;
	if (total_errors!=0) {
		alertString2  = _("表格無法寄送，因為皆下來問題");
		alertString2 += "\n------------------------------------------------------------------------------------\n";
		alertString2 += "\n- "+ total_missing_mandatory_tags +_(" 必要欄位是空的");
		alertString2 += "\n- "+ total_missing_mandatory_subfields +_(" 必要欄位是空的 (請看粗體分欄)");
		alert(alertString2);
	} else {
		document.forms[1].submit();
	}
}
function Dopop(link,i) {
	defaultvalue=document.forms['f'].field_value[i].value;
	newin=window.open(link+"&result="+defaultvalue,"value builder",'width=550,height=550,toolbar=false,scrollbars=yes');
}

function PopupZ3950() {
    var strQuery="";
	for (i=0 ; i<document.forms['f'].field_value.length ; i++) {
		if (document.forms['f'].kohafield[i].value == "biblioitems.isbn" && document.forms['f'].field_value[i].value.length>0) {
		    strQuery += "&isbn="+document.forms['f'].field_value[i].value;
		}
		if (document.forms['f'].kohafield[i].value == "biblio.title" && document.forms['f'].field_value[i].value.length>0) {
		    strQuery += "&title="+document.forms['f'].field_value[i].value;
		}
		if (document.forms['f'].kohafield[i].value == "biblio.author" &&document.forms['f'].field_value[i].value.length>0) {
		    strQuery += "&author="+document.forms['f'].field_value[i].value;
		}
		if (document.forms['f'].kohafield[i].value == "biblioitems.issn" && document.forms['f'].field_value[i].value.length>0) {
		    strQuery += "&issn="+document.forms['f'].field_value[i].value;
		}
	}
	newin=window.open("../z3950/search.pl?bibid=<!-- TMPL_VAR NAME="bibid" -->"+strQuery,"z3950 查詢",'width=500,height=400,toolbar=false,scrollbars=yes');
}

function AddField(field) {
	document.forms[1].op.value = "addfield";
	document.forms[1].addfield_field.value=field;
	document.f.submit();
}

function upSubfield(index) {
	temp = document.forms['f'].field_value[index-1].value;
	document.forms['f'].field_value[index-1].value=document.forms['f'].field_value[index].value;
	document.forms['f'].field_value[index].value= temp;
	temp = document.forms['f'].subfield[index-1].value;
	document.forms['f'].subfield[index-1].value=document.forms['f'].subfield[index].value;
	document.forms['f'].subfield[index].value = temp;
	temp = document.forms['f'].mandatory[index-1].value;
	document.forms['f'].mandatory[index-1].value=document.forms['f'].mandatory[index].value;
	document.forms['f'].mandatory[index].value = temp;
	temp = document.forms['f'].kohafield[index-1].value;
	document.forms['f'].kohafield[index-1].value=document.forms['f'].kohafield[index].value;
	document.forms['f'].kohafield[index].value = temp;
}

</script>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
