{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<H1>{$layout.pagetitle}</H1>
<FORM name="record" method="POST" action="{if $layout.module == 'recordedit'}?m=recordedit&id={$record.id}{else}?m=recordadd&d={$record.domain_id}{/if}">
<INPUT type="submit" class="hiddenbtn">
<TABLE class="lmsbox">
    <THEAD>
	<TR>
                <TD width="1%">
	                <IMG src="img/dns.gif" alt="">
	        </TD>
	        <TD width="1%" nowrap>
		        <B>{trans("Type")}:</B>
		</TD>
		<TD width="98%">
			<SELECT SIZE="1" NAME="record[type]" {tip text="Select record type" trigger="type"}
					onchange="change_rec_type(this)">
				<OPTION VALUE="A" {if $record.type == 'A'} SELECTED{/if}>A</OPTION>
				<OPTION VALUE="AAAA" {if $record.type == 'AAAA'} SELECTED{/if}>AAAA</OPTION>
				<OPTION VALUE="ALIAS" {if $record.type == 'ALIAS'} SELECTED{/if}>ALIAS</OPTION>
				<OPTION VALUE="ANAME" {if $record.type == 'ANAME'} SELECTED{/if}>ANAME</OPTION>
				<OPTION VALUE="CNAME" {if $record.type == 'CNAME'} SELECTED{/if}>CNAME</OPTION>
				<OPTION VALUE="HINFO" {if $record.type == 'HINFO'} SELECTED{/if}>HINFO</OPTION>
				<OPTION VALUE="MX" {if $record.type == 'MX'} SELECTED{/if}>MX</OPTION>
				<OPTION VALUE="NAPTR" {if $record.type == 'NAPTR'} SELECTED{/if}>NAPTR</OPTION>
				<OPTION VALUE="NS" {if $record.type == 'NS'} SELECTED{/if}>NS</OPTION>
				<OPTION VALUE="PTR" {if $record.type == 'PTR' || (!$record.type && preg_match('/in-addr\.arpa$/', $record.domainname))} SELECTED{/if}>PTR</OPTION>
				<OPTION VALUE="SOA" {if $record.type == 'SOA'} SELECTED{/if}>SOA</OPTION>
				<OPTION VALUE="SPF" {if $record.type == 'SPF'} SELECTED{/if}>SPF</OPTION>
				<OPTION VALUE="SRV" {if $record.type == 'SRV'} SELECTED{/if}>SRV</OPTION>
				<OPTION VALUE="SSHFP" {if $record.type == 'SSHFP'} SELECTED{/if}>SSHFP</OPTION>
				<OPTION VALUE="TXT" {if $record.type == 'TXT'} SELECTED{/if}>TXT</OPTION>
			</SELECT>
		</TD>
	</TR>
    </THEAD>
    <TBODY>
	<TR>
                <TD width="1%">
	                <IMG src="img/time.gif" alt="">
	        </TD>
	        <TD width="1%" nowrap>
		        {trans("TTL")}:
		</TD>
		<TD width="98%">
			<input type="text" size="7" value="{$record.ttl}" name="record[ttl]" {tip text="Enter record TTL" trigger="ttl"}>
		</TD>
	</TD>
	<TR id="name" style="display: none">
                <TD width="1%"><IMG src="img/domain.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Domain:")}</TD>
		<TD width="98%"><input type="text" value="{$record.name|escape}" name="record[name]" size="30" {tip text="Enter domain name" trigger="name"}> .{$record.domainname}.</TD>
	</TD>
	<TR id="alias" style="display: none">
                <TD width="1%"><IMG src="img/domain.gif" alt=""></TD>
		<TD width="1%" nowrap>{trans("Alias:")}</TD>
		<TD width="98%"><input type="text" value="{$record.alias|escape}" name="record[alias]" size="30" {tip text="Enter alias name" trigger="alias"}> .{$record.domainname}.</TD>
	</TD>
	<TR id="ipdst" style="display: none">
                <TD width="1%"><IMG src="img/ip.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("IP Address:")}</TD>
		<TD width="98%"><input type="text" value="{$record.ipdst|escape}" name="record[ipdst]" size="30" {tip text="Enter IP address" trigger="ipdst"}></TD>
	</TD>
	<TR id="ns" style="display: none">
                <TD width="1%"><IMG src="img/dns.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("DNS Server:")}</TD>
		<TD width="98%"><input type="text" value="{$record.ns|escape}" name="record[ns]" size="40" {tip text="Enter DNS server name" trigger="ns"}> .</TD>
	</TD>
	<TR id="mailserver" style="display: none">
                <TD width="1%"><IMG src="img/email.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Mail Server:")}</TD>
		<TD width="98%"><input type="text" value="{$record.mailserver|escape}" name="record[mailserver]" size="40" {tip text="Enter mail server name" trigger="mailserver"}> .</TD>
	</TD>
	<TR id="weight" style="display: none">
                <TD width="1%"><IMG src="img/id.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Weight:")}</TD>
		<TD width="98%"><input type="text" value="{$record.weight|escape}" name="record[weight]" size="10" {tip text="Enter record relative weight" trigger="weight"}></TD>
	</TD>
	<TR id="port" style="display: none">
                <TD width="1%"><IMG src="img/port.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Port:")}</TD>
		<TD width="98%"><input type="text" value="{$record.port|escape}" name="record[port]" size="10" {tip text="Enter port number" trigger="port"}></TD>
	</TD>
	<TR id="domain" style="display: none">
                <TD width="1%"><IMG src="img/domain.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Domain:")}</TD>
		<TD width="98%"><input type="text" value="{$record.domain|escape}" name="record[domain]" size="40" {tip text="Enter domain name" trigger="domain"}> .</TD>
	</TR>
	<TR id="host" style="display: none">
                <TD width="1%"><IMG src="img/domain.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Domain:")}</TD>
		<TD width="98%"><input type="text" value="{$record.host|escape}" name="record[host]" size="30" {tip text="Enter host name" trigger="host"}> .{$record.domainname}.</TD>
	</TR>
	<TR id="desc" style="display: none">
                <TD width="1%"><IMG src="img/info.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Description:")}</TD>
		<TD width="98%"><input type="text" value="{$record.desc|escape}" name="record[desc]" size="60" {tip text="Enter description" trigger="desc"}></TD>
	</TR>
	<TR id="prio" style="display: none">
                <TD width="1%"><IMG src="img/id.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Priority:")}</TD>
		<TD width="98%"><input type="text" size="5" value="{$record.prio|escape}" name="record[prio]" {tip text="Enter record priority" trigger="prio"}></TD>
	</TD>
	<TR id="email" style="display: none">
                <TD width="1%"><IMG src="img/mail.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("E-mail address:")}</TD>
		<TD width="98%"><input type="email" value="{$record.email|escape}" name="record[email]" size="40" {tip text="Enter e-mail address" trigger="email"}></TD>
	</TD>
	<TR id="serial" style="display: none">
                <TD width="1%"><IMG src="img/serialnumber.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Serial number:")}</TD>
		<TD width="98%"><input type="text" value="{$record.serial|escape}" name="record[serial]" size="10" {tip text="Enter zone serial number" trigger="serial"}></TD>
	</TD>
	<TR id="refresh" style="display: none">
                <TD width="1%"><IMG src="img/time.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Refresh interval:")}</TD>
		<TD width="98%"><input type="text" value="{$record.refresh|escape}" name="record[refresh]" size="10" {tip text="Enter zone refresh interval" trigger="refresh"}></TD>
	</TD>
	<TR id="retry" style="display: none">
                <TD width="1%"><IMG src="img/time.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Retry interval:")}</TD>
		<TD width="98%"><input type="text" value="{$record.retry|escape}" name="record[retry]" size="10" {tip text="Enter zone retry interval" trigger="retry"}></TD>
	</TD>
	<TR id="expiry" style="display: none">
                <TD width="1%"><IMG src="img/time.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Expire time:")}</TD>
		<TD width="98%"><input type="text" value="{$record.expire|escape}" name="record[expire]" size="10" {tip text="Enter zone expiration time" trigger="expire"}></TD>
	</TD>
	<TR id="minttl" style="display: none">
                <TD width="1%"><IMG src="img/time.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Default TTL:")}</TD>
		<TD width="98%"><input type="text" value="{$record.minttl|escape}" name="record[minttl]" size="10" {tip text="Enter default TTL value" trigger="minttl"}></TD>
	</TD>
	<TR id="algo" style="display: none">
                <TD width="1%"><IMG src="img/pass.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Algorithm:")}</TD>
		<TD width="98%">
		    <select name="record[algo]" {tip text="Select algorithm of the public key" trigger="algo"}>
			<option value="1"{if $record.algo=='1'} selected{/if}>RSA</option>
			<option value="2"{if $record.algo=='2'} selected{/if}>DSS</option>
		    </select>
		</TD>
	</TD>
	<TR id="ftype" style="display: none">
                <TD width="1%"><IMG src="img/pass.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Type:")}</TD>
		<TD width="98%">
		    <select name="record[ftype]" {tip text="Select algorithm used to generate the fingerprint" trigger="ftype"}>
			<option value="1">SHA-1</option>
		    </select>
		</TD>
	</TD>
	<TR id="fingerprint" style="display: none">
                <TD width="1%"><IMG src="img/pass.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Fingerprint:")}</TD>
		<TD width="98%"><input type="text" value="{$record.fingerprint|escape}" name="record[fingerprint]" size="80" {tip text="Enter public key fingerprint" trigger="fingerprint"}></TD>
	</TR>
	<TR id="content" style="display: none">
                <TD width="1%"><IMG src="img/info.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Content:")}</TD>
		<TD width="98%"><input type="text" value="{$record.content|escape}" name="record[content]" size="80" {tip text="Enter record contents" trigger="content"}></TD>
	</TR>
	<TR id="cpu" style="display: none">
                <TD width="1%"><IMG src="img/node.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("CPU Type:")}</TD>
		<TD width="98%"><input type="text" value="{$record.cpu|escape}" name="record[cpu]" size="40" {tip text="Enter CPU type" trigger="cpu"}></TD>
	</TR>
	<TR id="os" style="display: none">
                <TD width="1%"><IMG src="img/node.gif" alt=""></TD>
	        <TD width="1%" nowrap>{trans("Operating System Type:")}</TD>
		<TD width="98%"><input type="text" value="{$record.os|escape}" name="record[os]" size="40" {tip text="Enter operating system type" trigger="os"}></TD>
	</TR>
	<TR>
		<TD colspan="3" align="right" nowrap>
			<A href="javascript: document.record.submit();" accesskey="s">{trans("Submit")} <IMG SRC="img/save.gif" ALT=""></A>
			<A href="?m=recordlist">{trans("Cancel")} <IMG SRC="img/cancel.gif" ALT=""></A>
		</TD>
	</TR>
    </TBODY>
</TABLE>
</FORM>
<SCRIPT type="text/javascript">
<!--
function change_rec_type(select)
{
	var i, j,
		rows = document.forms['record'].getElementsByTagName('TR'),
		type = select.value,
		records = {
			'A': 	['name', 'ipdst'],
			'AAAA':	['name', 'ipdst'],
			'ALIAS': ['alias', 'domain'],
			'ANAME': ['alias', 'domain'],
			'NS': 	['name', 'ns'],
			'MX':	['name', 'mailserver', 'prio'],
			'CNAME':['alias', 'domain'],
			'TXT':  ['name', 'desc'],
			'SPF':  ['name', 'desc'],
			'PTR':  ['name', 'domain'],
			'SOA':  ['ns', 'email', 'serial', 'refresh', 'retry', 'expiry', 'minttl'],
			'SRV':  ['name', 'weight', 'port', 'domain'],
			'SSHFP':['name', 'algo', 'ftype', 'fingerprint'],
			'HINFO':['name', 'cpu', 'os'],
			'NAPTR':['name', 'content'] // @TODO
		};

	if (!records[type])
		return;

	for (i=0; i<rows.length; i++) {
		if (!rows[i].id)
			continue;
		for (j=0; j<records[type].length; j++) {
			if (rows[i].id == records[type][j]) {
				rows[i].style.display = '';
				break;
			}
		}

		if (j == records[type].length) {
			rows[i].style.display = 'none';
		}
	}
}

$(function() {
	var elem = $('form[name="record"] [name="record[type]"]');
	elem.focus();
	change_rec_type(elem[0]);
});
//-->
</SCRIPT>
{/block}
