<?php
# check for duplicate record entry
if ($_SESSION['IS_USER_CLIENT'] && $_POST['formaction'] == 'add')
{
	$errorMsg = "Sorry, you do not have access to create new Campaign!";
}
else
{
	if (isset($_POST['formaction']) && ($_POST['formaction'] == 'add' || $_POST['formaction'] == 'edit'))
	{
		$ID					= $_POST['ID'];
		$CAMPAIGN_NAME		= trim($funcObj->AppendSlashes($_POST['txtname']));
		$SUBJECT			= trim($funcObj->AppendSlashes($_POST['txtSubject']));
		// $FROM_NAME			= trim($funcObj->AppendSlashes($_POST['txtFromName']));
		// $FROM_EMAIL			= trim($funcObj->AppendSlashes($_POST['txtFromEmail']));
		// $REPLYTO_NAME		= trim($funcObj->AppendSlashes($_POST['txtReplyToName']));
		// $REPLYTO_EMAIL		= trim($funcObj->AppendSlashes($_POST['txtReplyToEmail']));
		$CONTENTS			= trim($funcObj->AppendSlashes($_POST['areaBody']));
		$CONTENTSPLAIN		= trim($funcObj->AppendSlashes($_POST['areaBodyText']));
		
		if (isset($_POST['duplicate']) && $_POST['duplicate'] == 'Duplicate Campaign')
		{
			$CAMPAIGN_NAME .= ' (copy)'; 
			$_POST['formaction'] = 'add';
		}
		
		$error = "";
		if (empty($CAMPAIGN_NAME))
		{
			$error .= "Campaign name cannot be left blank.<br />";
		}
		if (empty($SUBJECT))
		{
			$error .= "Campaign subject cannot be left blank.<br />";
		}
		// if (empty($FROM_EMAIL))
		// {
		// 	$error .= "From email cannot be left blank.<br />";
		// }
		// else if (!validate_email ($FROM_EMAIL))
		// {
		// 	$error 	= "Invalid From e-mail address.<br />";
		// }
		// if (!empty($REPLYTO_EMAIL))
		// {
		// 	if (!validate_email ($REPLYTO_EMAIL))
		// 	{
		// 		$error 	= "Invalid Reply-To e-mail address.<br />";
		// 	}
		// }	
		if (empty($CONTENTS))
		{
			$error .= "Message HTML body cannot be left blank.<br />";
		}
		if (empty($CONTENTSPLAIN))
		{
			$error .= "Message plain text body cannot be left blank.<br />";
		}
		if (strlen($error))
		{
			$errorMsg = "<strong>Please correct the following error(s):</strong> <br />
			$error";
		}	
	}
}
?>