{if $smarty.request.fromEmail neq ""}{include_php file="shared_handle:adminMultiMail"}{/if}
{assign var="hideWidgets" value="true"}
{assign var="wideFormat" value="true"}

{select_query assign="aGroups" return="array"}
	name, description from _groups
{/select_query}

{select_query assign="aCompanies" return="array"}
	id, companyName AS name FROM companies
{/select_query}
 
<h1 class="underline">Broadcast an Email</h1>
<br />

<form name="emailForm" method="post" action="index.php" style="margin:0px;">
<input type="hidden" name="pg" value="sendEmail"> 
<input type="hidden" name="no_expire" value="true">

<div style="width:900px;">{assign var="userName" value="`$user->firstName` `$user->lastName`"}
<b>From Name:&nbsp;</b><input type="text" name="fromName" value="{$smarty.request.fromName|stripslashes|default:$userName}" /> &nbsp; 
<b>From Email:&nbsp;</b><input type="text" name="fromEmail" value="{$smarty.request.fromEmail|default:$user->email}" /><br />
<b>Subject Line:&nbsp;</b><input type="text" name="mailSubject" value="{$smarty.request.mailSubject|stripslashes}" style="width:380px;" /><br /><br />

<b>Select each Company:</b> <small>(hold <b>CTRL</b> key)</small><br />
<select name="toCompanies[]" multiple>{foreach from=$aCompanies item="row"}
	<option value="{$row.id}">{$row.name} - {$row.description}</option>{/foreach}
</select><br />
<small><em>* Under Construction, may not yet work properly.</em></small><br /><br />

<b>Select the Email Groups:</b> <small>(hold <b>CTRL</b> key)</small><br />
<select name="toGroups[]" multiple>{foreach from=$aGroups item="row"}
	<option value="{$row.name}">{$row.name} - {$row.description}</option>{/foreach}
</select><br />
<small><em>* Will not send message to addresses in the OPT-OUT database table.</em></small><br /><br />

<b>Enter Additional Email Addresses: <small>(comma delimited)</small></b>
<textarea style="width:900px;display:block;" name="toAddresses"></textarea>
<small><em>* These addresses are not checked against the OPT-OUT database table.</em></small><br /><br />

<b>Enter Plain Text Message Body:</b>
<textarea style="width:900px;display:block;height:200px;" name="plainText">{$smarty.request.plainText|stripslashes}</textarea><br />

<b>Enter/Paste HTML Message Body:</b>
<textarea style="width:900px;display:block;height:200px;" name="mailBody">{$smarty.request.mailBody|stripslashes}</textarea><br />

<div style="text-align:right;"><input type="button" value="Preview HTML" onclick="previewHTML()"><input type="submit" name="submit" value="Send Now" /></div>
</div>

</form>

<form name="previewForm" method="post" action="index.php">
<input type="hidden" name="pg" value="multiEmail/preview">
<input type="hidden" name="mailBody" value="">
</form>

<script language="javascript">{literal}
function previewHTML() {
	dF = document.previewForm;
	dF.mailBody.value = document.emailForm.mailBody.value;	

	webPreview = parent.window.open("index.php?pg=multiEmail/preview", "webPreview", "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=640,height=480,left=10,top=10");
	dF.target = 'webPreview';
	dF.submit();
	webPreview.focus();
}
{/literal}</script>