{extends file="layout.html"}
{block name=title}LMS: {$layout.pagetitle|striphtml}{/block}
{block name=module_content}
<!--// $Id$ //-->
{$xajax}
<SCRIPT type="text/javascript">
<!--
	function SelectAllCustomers()
	{
		if (document.setwarnings.customers.checked) 
			for (var i = 0; i < document.getElementById('customerslist').length; i++)
				document.getElementById('customerslist').options[i].selected = true;
		else
			for (var i = 0; i < document.getElementById('customerslist').length; i++)
				document.getElementById('customerslist').options[i].selected = false;
	}

	function SelectAllCustomers2()
	{
		document.setwarnings.customers.checked = !document.setwarnings.customers.checked;
		SelectAllCustomers();
	}
	
	function switchbox(id)
	{
		if ((id.name == 'setwarnings[warnon]') && id.checked ) 
			document.setwarnings.elements['setwarnings[warnoff]'].checked = false;
		if ((id.name == 'setwarnings[warnoff]') && id.checked ) 
			document.setwarnings.elements['setwarnings[warnon]'].checked = false;
	}

	function switchbox1()
	{
		document.setwarnings.elements['setwarnings[warnon]'].checked = !document.setwarnings.elements['setwarnings[warnon]'].checked;
		switchbox(document.setwarnings.elements['setwarnings[warnon]']);
	}

	function switchbox2()
	{
		document.setwarnings.elements['setwarnings[warnoff]'].checked = !document.setwarnings.elements['setwarnings[warnoff]'].checked;
		switchbox(document.setwarnings.elements['setwarnings[warnoff]']);
	}

	function change_message_template(tmplid) {
		if (tmplid) {
			xjx.$('msgtmplid').disabled = true;
			xajax_getMessageTemplate(tmplid);
		}
	}

	function messageTemplateReceived(message) {
		var editor = tinyMCE.get(0);
		if (editor) {
			editor.setContent(message);
			xjx.$('message').value = message;
		} else {
			xjx.$('message').value = message;
		}
		xjx.$('msgtmplid').disabled = false;
	}
//-->
</SCRIPT>
<H1>{$layout.pagetitle}</H1>
<FORM name="setwarnings" method="post" action="?m=customerwarn" id="setwarnings">
<p style="display: none;">
<INPUT type="submit" class="hiddenbtn">
</p>
<TABLE width="100%" cellpadding="3">
	<TR>
		<TD style="width: 1%;" class="valign-top">
			<TABLE class="lmsbox">
				<THEAD>
				<TR>
					<TD style="width: 1%;" class="bold">
						<IMG src="img/customer.gif" alt="">&nbsp;{trans("Customers:")}
					</TD>
					<TD style="width: 99%;" class="bold" colspan="2">
						<IMG src="img/mail.gif" alt="">&nbsp;{trans("Notice content:")}
					</TD>
				</TR>
				</THEAD>
				<TBODY>
				<TR>
					<TD>
						<SELECT size="30" name="setwarnings[mcustomerid][]" id="customerslist" multiple {tip text="Select customers"}>
							{foreach from=$customerlist key=key item=item}
							<OPTION value="{$key}"{if $item.warning} class="red"{/if}{if isset($selected.$key)} selected{/if}>{$item.customername|truncate:40:"&hellip;":true} ({$key|string_format:"%04d"})</OPTION>
							{/foreach}
						</SELECT>
					</TD>
					<TD colspan="2">
						<TABLE cellpadding="3">
							<TR>
								<TD colspan="3">
									<label>
										{trans("Message template:")}
										<select name="setwarnings[tmplid]" id="msgtmplid" {tip trigger="msgtmplid" text="Select message template"} onChange="javascript:change_message_template(this.options[this.selectedIndex].value);">
											<option value="0">{trans("— none —")}</option>
											{foreach $messagetemplates as $msgtmpl}
											<option value="{$msgtmpl.id}">{$msgtmpl.name}</option>
											{/foreach}
										</select>
									</label>
								</TD>
							</TR>
							<TR>
								<TD colspan="3" {tip text="Customer notice content"}>
									<TEXTAREA name="setwarnings[message]" class="lms-ui-wysiwyg-editor" rows="20" cols="75">{$warnmessage}</TEXTAREA>
								</TD>
							</TR>
							<TR>
								<td colspan="3">
									<input type="radio" name="setwarnings[tmploper]" id="msgtmplradionone" value="1" onClick="javascript:document.getElementById('msgtmplname').style.display='none';" checked><label for="msgtmplradionone">{trans("no operation on message template")}</label><br>
									<input type="radio" name="setwarnings[tmploper]" id="msgtmplradioupdate" value="2" onClick="javascript:document.getElementById('msgtmplname').style.display='none';"><label for="msgtmplradioupdate">{trans("message template update")}</label><br>
									<input type="radio" name="setwarnings[tmploper]" id="msgtmplradionew" value="3" onClick="javascript:document.getElementById('msgtmplname').style.display='';"><label for="msgtmplradionew">{trans("message template creation")}</label>
									<input type="text" size="40" name="setwarnings[tmplname]" id="msgtmplname" style="display: none;" {tip trigger="tmplname" text="Enter name of the new message template"}>
								</td>
							</TR>
						</TABLE>
					</TD>
				</TR>
				<TR>
					<TD style="width: 1%;">
						<INPUT type="checkbox" name="customers" OnClick="javascript:SelectAllCustomers()"><A href="javascript:SelectAllCustomers2()">{trans("Select All<!masculine>")}</A>
					</TD>
					<TD class="text-left nobr">
						<INPUT type="checkbox" name="setwarnings[warnon]" id="warnon" OnClick="switchbox(this);"{if $warnon} checked{/if}><A href="javascript:switchbox1()">{trans("Enable")}</A>
						/ <INPUT type="checkbox" name="setwarnings[warnoff]" id="warnoff" OnClick="switchbox(this);"{if $warnoff} checked{/if}><A href="javascript:switchbox2()">{trans("Disable")}</A>
					</TD>
					<TD class="text-right">
						<A href="javascript:document.setwarnings.submit()" accesskey="s">{trans("Submit")} <IMG src="img/save.gif" alt=""></A>
					</TD>
				</TR>
				</TBODY>
			</TABLE>
		</TD>
	</TR>
</TABLE>
</FORM>
<SCRIPT type="text/javascript">
<!--
	$(function() {
		$('form[name="setwarnings"] [name="setwarnings[message]"]').focus();
	});
//-->
</SCRIPT>
{/block}
