{if $smarty.request.submit_send neq "" && $smarty.request.fromEmail neq ""}{include_php file="shared_handle:adminMultiMailTemplate"}{/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">
<input type="hidden" name="pg" value="sendTemplatedEmail"> 
<input type="hidden" name="no_expire" value="true">

<div>{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><input type="checkbox" name="toNewsletterSubscribers" value="1" /> Send to All Newsletter Subscribers?</b>
<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>* Will not send message to addresses in the OPT-OUT database table.</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:500px;display:block;" name="toAddresses"></textarea>
<small><em>* These addresses are not checked against the OPT-OUT database table.</em></small><br /><br />

<b>Title:</b> <small>(to be shown in offline email clients)</small><br />
<input style="width:300px;" type="text" name="offlinetitle" value="{$smarty.request.offlinetitle|stripslashes|default:'eHealthComplete Newsletter'}" /><br />

<br />
<input type="checkbox" name="hidestorelink" /> <b>Hide Store Link?</b><br />
<input type="checkbox" name="hidebannerad" /> <b>Hide Banner Ad?</b> <small>(not necessary if no ad image is entered)</small><br />
<input type="checkbox" name="hidesponsorads" /> <b>Hide Sponsor Images</b> <small>(not necessary if no sponsor images are entered)</small><br />
<br />
<b>Main Banner Image:</b><br/>
* Note: this will not change the image until a caching error is resolved.<br/>
<script>{literal}
function setMainBannerImage(str) {
document.getElementById('mainbannerimage').src="/systems/wlw/layouts/newsletter/" + str;
}
{/literal}</script>
<img id="mainbannerimage" src="/systems/wlw/layouts/newsletter/{$smarty.request.mainbannerimage|stripslashes|default:"banner_shoes.jpg"}" style="border:2px solid #000000; margin:5px 0px;"><br/>
{php}
global $SPADE;
$bannerimages = array(
array("name" => "banner_apples.jpg", "title" => "Apples"),
array("name" => "banner_autumn.jpg", "title" => "Autumn Trees"),
array("name" => "banner_basketball.jpg", "title" => "Basketball"),
array("name" => "banner_beach.jpg", "title" => "Beach"),
array("name" => "banner_fruit.jpg", "title" => "Fruit Splashing"),
array("name" => "banner_grass.jpg", "title" => "Grass & Sky"),
array("name" => "banner_jogging.jpg", "title" => "Jogging People"),
array("name" => "banner_jumping.jpg", "title" => "Jumping Girl"),
array("name" => "banner_kiwi.jpg", "title" => "Kiwis"),
array("name" => "banner_palmtrees.jpg", "title" => "Palm Trees & Ocean"),
array("name" => "banner_pond.jpg", "title" => "Pond"),
array("name" => "banner_pumpkins1.jpg", "title" => "Pumpkins #1"),
array("name" => "banner_pumpkins2.jpg", "title" => "Pumpkins #2"),
array("name" => "banner_rose.jpg", "title" => "Rose"),
array("name" => "banner_runner.jpg", "title" => "Runner"),
array("name" => "banner_scale.jpg", "title" => "Weight Scale"),
array("name" => "banner_shoes.jpg", "title" => "Running Shoes"),
array("name" => "banner_snowman.jpg", "title" => "Snowman"),
array("name" => "banner_springtime.jpg", "title" => "Girl Smiling"),
array("name" => "banner_thanksgiving1.jpg", "title" => "Thanksgiving #1"),
array("name" => "banner_thanksgiving2.jpg", "title" => "Thanksgiving #2"),
array("name" => "banner_tulips.jpg", "title" => "Tulips"),
array("name" => "banner_vegetables.jpg", "title" => "Vegetables"),
array("name" => "banner_weights.jpg", "title" => "Weights"),
array("name" => "banner_wheat.jpg", "title" => "Wheat"),
array("name" => "banner_winter.jpg", "title" => "Winter")
);
$SPADE['template']->assign("bannerimages", $bannerimages);
{/php}
<table border="0">
<tr>
{foreach name=banners item=b from=$bannerimages}
<td><input type="radio" name="mainbannerimage" value="{$b.name}" {if $smarty.request.mainbannerimage == $b.name}checked{/if} onclick="setMainBannerImage(this.value);"/> {$b.title}</td>
{if $smarty.foreach.banners.iteration % 3 == 0 && !$smarty.foreach.banners.last}</tr><tr>{/if}
{/foreach}
</tr>
</table>
<br/>
<table border="0">
<tr><td colspan="4"><b>Banner Ad:</b></td></tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="bannerimage" value="{$smarty.request.bannerimage|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="bannerurl" value="{$smarty.request.bannerurl|stripslashes}" /></td>
</tr>
<tr><td colspan="4"><b>Sponsor Ads:</b></td></tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor1image" value="{$smarty.request.sponsor1image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor1url" value="{$smarty.request.sponsor1url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor2image" value="{$smarty.request.sponsor2image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor2url" value="{$smarty.request.sponsor2url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor3image" value="{$smarty.request.sponsor3image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor3url" value="{$smarty.request.sponsor3url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor4image" value="{$smarty.request.sponsor4image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor4url" value="{$smarty.request.sponsor4url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor5image" value="{$smarty.request.sponsor5image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor5url" value="{$smarty.request.sponsor5url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor6image" value="{$smarty.request.sponsor6image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor6url" value="{$smarty.request.sponsor6url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor7image" value="{$smarty.request.sponsor7image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor7url" value="{$smarty.request.sponsor7url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor8image" value="{$smarty.request.sponsor8image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor8url" value="{$smarty.request.sponsor8url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor9image" value="{$smarty.request.sponsor9image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor9url" value="{$smarty.request.sponsor9url|stripslashes}" /></td>
</tr>
<tr>
<td><small>Image URL:</small></td><td><input type="text" name="sponsor10image" value="{$smarty.request.sponsor10image|stripslashes}" /></td>
<td><small>Link URL:</small></td><td><input type="text" name="sponsor10url" value="{$smarty.request.sponsor10url|stripslashes}" /></td>
</tr>

</table>
<small><em>* image urls MUST be absolute (e.g. "http://...").</em></small><br />

<br />
<b>Feature Image URL:</b><br />
<input style="width:300px;" type="text" name="featureimage" value="{$smarty.request.featureimage|stripslashes}" /><br />
<small><em>* image urls MUST be absolute (e.g. "http://...").</em></small><br />
<b>Feature Title:</b><br />
<input style="width:300px;" type="text" name="featuretitle" value="{$smarty.request.featuretitle|stripslashes}" /><br />
<b>Feature Content:</b><br />
<textarea style="width:500px;height:200px;" name="featurebody">{$smarty.request.featurebody|stripslashes}</textarea><br />


<br />
<b>Recipe of the Week Title:</b><br />
<input style="width:300px;" type="text" name="recipetitle" value="{$smarty.request.recipetitle|stripslashes}" /><br />
<b>Recipe of the Week Content:</b><br />
<textarea style="width:500px;height:140px;" name="recipebody">{$smarty.request.recipebody|stripslashes}</textarea><br />

<br />
<b>Tip of the Week:</b><br />
<textarea style="width:500px;height:100px;" name="tipbody">{$smarty.request.tipbody|stripslashes}</textarea><br />

<br />
<b>Hero Highlight:</b><br />
<textarea style="width:500px;height:100px;" name="herobody">{$smarty.request.herobody|stripslashes}</textarea><br />

<br />
<b>Quote:</b><br />
<textarea style="width:500px;height:100px;" name="quotebody">{$smarty.request.quotebody|stripslashes}</textarea><br />

<br />

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

</form>

<script language="javascript">{literal}
function prepareToSend() {
	dF = document.emailForm;
	dF.pg.value = "sendTemplatedEmail";	
	dF.target = '_self';

}
function previewHTML() {
	dF = document.emailForm;
	dF.pg.value = "newsletterpreview";	

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