<?php 
session_start();
$ID 				= NULL;
$CAMPAIGN_NAME		= NULL;
$SUBJECT			= NULL;
$FROM_NAME			= NULL;
$FROM_EMAIL			= NULL;
$REPLYTO_NAME		= NULL;
$REPLYTO_EMAIL		= NULL;
$CONTENTS			= NULL;
$CONTENTSPLAIN		= NULL;
require 'authenticate.user.php';

require 'configuration.php';
require_once 'includes/common.functions.php';
require_once ('classes/database.php');
require_once ('classes/functions.php');
require_once('classes/paging.class.php');
$sqlObj = new mysqlClass;
$funcObj = new funcClass;
$table = "##campaigns";
$curFile = basename(__FILE__);
$ACTION				= 'add';
require_once ('includes/validate.campaigns.php');
$show = isset($_GET['show']) ? $_GET['show'] : '';

$uri_parts = explode('?', $_SERVER['REQUEST_URI'], 2);
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $uri_parts[0];


$appendToQuery = "";
## If the client is logged in then 
## give access to only those campaigns for which
## access has been granted to this user.
$currentUserId 	= intval($_SESSION['SUPER_USER_ID']);

if ($_SESSION['IS_USER_CLIENT'])
{
	$appendToQuery = " AND ID IN (SELECT CAMPAIGN_ID FROM smlr_client_access WHERE USER_ID = '$currentUserId') ";
}

//print_r($_POST);

//ADD RECORD
if ((isset($_POST['formaction']) && $_POST['formaction'] == 'add') && (empty($error)))
{
	## give add permissions only if the user is admin
	$query = "SELECT COUNT(*) FROM $table WHERE CAMPAIGN_NAME = '$CAMPAIGN_NAME'";
	$queryCount=$funcObj->CustomQueryCount($query)[0]['COUNT(*)'];
	if ($queryCount == 0)
	{
		
		$query = "INSERT INTO $table SET CAMPAIGN_NAME='$CAMPAIGN_NAME', FROM_NAME='$FROM_NAME', FROM_EMAIL='$FROM_EMAIL', REPLYTO_NAME='$REPLYTO_NAME', REPLYTO_EMAIL='$REPLYTO_EMAIL', SUBJECT='$SUBJECT', CONTENTS='$CONTENTS', CONTENTSPLAIN='$CONTENTSPLAIN', IS_SENT='0',FAILED_EMAILS='0', DATE_CREATED=NOW()";
		
		$insertId = $funcObj->insertQuery($query);
		if ($insertId > 0)
		{
			$message = "Record has been added successfully";
		}
		## RESET THE FORM SO THAT 
		## NO VALUES SHOULD BE SHOWN
		## IF THE FORM IS IN THE ADD
		## MODE
		
	}
	else
	{
		$message = "Same campaign already available. Please try with different campaign name.";
	}
}

## DELETE MULTIPLE RECORDS
if (isset($_POST['formtype']) && $_POST['formtype'] == 'multipledelete')
{
	if (count($_POST['chkContacts']))
	{
		$delIDs = implode("," ,$_POST['chkContacts']);
		
		## delete records from campaign table
		$query = "DELETE FROM ##campaigns WHERE ID IN ($delIDs)";
		$funcObj->CustomDelete($query);	
		
		## delete records from reports table.
		$query = "DELETE FROM ##campaign_send_stats WHERE CAMPAIGN_ID IN ($delIDs)";
		$funcObj->CustomDelete($query);	
		
		$query = "DELETE FROM ##report WHERE CAMPAIGN_ID IN ($delIDs)";
		$funcObj->CustomDelete($query);	
		
		## delete records from GEO Map table.
		$query = "DELETE FROM ##visitor_map WHERE campaign_id IN ($delIDs)";
		$funcObj->CustomDelete($query);	
		header("location: $redirect");
	}
}

//EDIT RECORD
if ((isset($_POST['formaction']) && $_POST['formaction'] == 'edit') && empty($error))
{
	# check for duplicate record entry
	$query = "SELECT COUNT(*) FROM $table WHERE CAMPAIGN_NAME = '$CAMPAIGN_NAME'";
	$countRecords = $funcObj->CustomQueryCount($query)[0]['COUNT(*)'];
	if ($countRecords < 2)
	{
		
		$query = "UPDATE $table SET CAMPAIGN_NAME='$CAMPAIGN_NAME', FROM_NAME='$FROM_NAME', FROM_EMAIL='$FROM_EMAIL', REPLYTO_NAME='$REPLYTO_NAME', REPLYTO_EMAIL='$REPLYTO_EMAIL', SUBJECT='$SUBJECT', CONTENTS='$CONTENTS', CONTENTSPLAIN='$CONTENTSPLAIN', DATE_CREATED=NOW()"; 
		$query .= " WHERE ID = {$ID}";
		
		$updateId = $funcObj->updateQuery($query);
		if ($updateId == 1)
		{
			$message = "Record has been successfully updated.";
		}
		
		## RESET THE FORM SO THAT 
		## NO VALUES SHOULD BE SHOWN
		## IF THE FORM IS IN THE ADD
		## MODE
		
		
	}
	else
	{
		$message = "Same campaign already available. Please try with different campaign name.";
	}
}

## if edit is EDIT
# then load values into the form
if (isset($_GET['action']) && $_GET['action'] == 'edit')
{
	$ID = $_GET['id'];
	$whereFields['ID'] = $ID;
	$resultSet = $funcObj->getRecordDetails($table,$whereFields);
	$ID					= trim($funcObj->AppendSlashes($resultSet[0]['ID']));
	$CAMPAIGN_NAME		= trim($funcObj->AppendSlashes($resultSet[0]['CAMPAIGN_NAME']));
	$SUBJECT			= trim($funcObj->AppendSlashes($resultSet[0]['SUBJECT']));
	$FROM_NAME			= trim($funcObj->AppendSlashes($resultSet[0]['FROM_NAME']));
	$FROM_EMAIL			= trim($funcObj->AppendSlashes($resultSet[0]['FROM_EMAIL']));
	$REPLYTO_NAME		= trim($funcObj->AppendSlashes($resultSet[0]['REPLYTO_NAME']));
	$REPLYTO_EMAIL		= trim($funcObj->AppendSlashes($resultSet[0]['REPLYTO_EMAIL']));
	$CONTENTS 			= trim($funcObj->AppendSlashes($resultSet[0]['CONTENTS']));
	$CONTENTSPLAIN 		= trim($funcObj->AppendSlashes($resultSet[0]['CONTENTSPLAIN']));
	$ACTION				= 'edit';
}
$searchbox = isset($_REQUEST['searchbox']) ? $_REQUEST['searchbox'] : '';
$sent =isset($_REQUEST['sent']) ? $_REQUEST['sent'] : '';
$searchTxt = trim($funcObj->AppendSlashes($searchbox));
$searchArray = 'ID,CAMPAIGN_NAME,SUBJECT';

if(isset($_GET['action']) && $_GET['action']=='del')
{
	$whereField = "ID";
	$whereValue = $ID;
	$funcObj->DeleteRecord($table,$whereField,$whereValue);
	$message = "Campaign(s) have been deleted successfully";
}

$resultSet = $funcObj->CountAllRecords("$table",$searchTxt,$searchArray);

$records	= $funcObj->fetchParameterValue('SHOW_RECORDS_PER_PAGE')[0]['FIELDVALUE'];
if($records > 0)
{
	$limit = intval($records);
}
else
{
	$limit = $configAdminPaging;
}

if(isset($_REQUEST['start']))
	$start = $_REQUEST['start'];
else
	$start = 0;
	

if (isset($_GET['show']) && $_GET['show'] == 'sent')
{
	$file = "'campaigns.php?show=sent'";
	$isSent = " IS_SENT='1' ";
}	
else
{
	$file = "'campaigns.php'";
	$isSent = " IS_SENT='0' ";	
}	

/*
GET COUNT for sent and unsent campaigns
*/
$query 		= "SELECT COUNT(ID) AS TOTAL FROM ##campaigns WHERE IS_SENT = '0' $appendToQuery
			   UNION
			   SELECT COUNT(ID) AS TOTAL FROM ##campaigns WHERE IS_SENT = '1' $appendToQuery";
			   
$sentUnsentCamp = $funcObj->CustomQuery($query);
$searchctr ='';
if(!empty($searchTxt))
{
	$searchctr = " AND (";
	$searchArray1=explode(",",$searchArray);
	
	$searchctr.= "ID = '$searchTxt' OR CAMPAIGN_NAME like '%$searchTxt%' 
	OR FROM_NAME like '%$searchTxt%' 
	OR FROM_EMAIL like '%$searchTxt%' 
	OR SUBJECT like '%$searchTxt%'"; 
	$searchctr .= ") ";
}

$query = "SELECT COUNT(ID) AS TOTAL FROM
smlr_campaigns WHERE $isSent $searchctr $appendToQuery ORDER BY ID DESC";
	
$proCount = $funcObj->CustomQueryCount($query)[0]['TOTAL'];	

$link = $curFile.'?sent='.$sent.'&show='.$show.'&searchbox='.$searchbox;

function getAddrUsed($campId)
{
	global $funcObj;
	$query = "SELECT DISTINCT(A.NAME) AS NAME, A.ID AS ID
	FROM smlr_addressbook AS A,
	smlr_campaign_send_stats AS B
	WHERE B.ADDR_ID = A.ID
	AND B.CAMPAIGN_ID = '$campId'
	";
	
	$addrUsedResultset = array();
	return $addrUsedResultset = $funcObj->CustomQuery($query);
}

$pageObj =  new Paging( $proCount, $start , $limit);

/* ACTIVATE THE TAB */
$activeTab = 'Campaigns';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Segnant Mailer - Manage Campaigns</title>
<link rel="stylesheet" type="text/css" href="includes/css/thickbox.css" />
<link rel="stylesheet" type="text/css" href="includes/css/segnantmailer.css" />
<link rel="stylesheet" href="includes/css/themes/blue/style.css" type="text/css"  media="print, projection, screen" />
<link rel="stylesheet" type="text/css" href="includes/css/paging.css"  />
<script type="text/javascript" src="includes/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="includes/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="includes/js/common.jquery.js"></script>
<script type="text/javascript" src="includes/js/campaigns.jquery.js"></script>
<script type="text/javascript" src="includes/js/thickbox-compressed.js"></script>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="79" class="headerbg"><?php require_once 'includes/inc.header.php' ?>
    </td>
  </tr>

  <tr>
    <td class="canvas" height="300" valign="top"><table width="100%" border="0" cellspacing="10" cellpadding="4">
        <tr>
          <td colspan="2" class="heading" height="50" valign="top">Manage Campaigns</td>
        </tr>
        <tr>
          <td colspan="2" bgcolor="#eaeaea" style="padding:10px;"><table cellspacing="0" cellpadding="0" class="tabtable">
              <tr>
                <?php
				//echo $file = basename($_SERVER['PHP_SELF']);
				
				## ADD EXCEPTIONS
				
				$tabArray = array("<td nowrap=\"nowrap\" style=\"cursor:pointer;\" onclick=\"javascript:window.location.href='campaigns.php'\"> Unsent Campaigns ({$sentUnsentCamp[0]['TOTAL']}) </td>",
						"<td nowrap=\"nowrap\" style=\"cursor:pointer;\" onclick=\"javascript:window.location.href='campaigns.php?show=sent'\"> Sent Campaigns ({$sentUnsentCamp[1]['TOTAL']}) </td>");
				foreach ($tabArray as $key => $val)
				{
					$strpos = strpos($val, $file);
				
					if ($strpos > 0)
					{
						$newString = str_replace('style="cursor:pointer;"','style="cursor:pointer;" class="active" ',$val);
						echo $newString;
					}
					else
					{
						echo $val;
					}	
				}
				?>
              </tr>
            </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="4">
              <tr>
                <td height="405" bgcolor="#FFFFFF" valign="top"><table width="100%" border="0" cellspacing="1" cellpadding="1">
                    <tr>
                      <td class="pageHeading">Manage Campaigns</td>
                    </tr>
                    <tr>
                      <td height="55" valign="top" align="right"><form name="formsearch" method="get" style="margin: 0;" action="">
                          <table border="0" cellspacing="2" cellpadding="2" align="right">
                            <tr>
                              <td nowrap="nowrap"><strong>Search</strong></td>
                              <td><input type="text" placeholder="search" name="searchbox" class="textbox" value="<?=$funcObj->RemoveSlashes($searchbox)?>" style="margin-bottom: 2px;" size="20" /></td>
                              <td>
                              <input type="hidden" name="show" value="<?=isset($_GET['show']) ? $_GET['show'] :''?>" />
                              <input type="submit" name="submit" value="Search" class="button size2" /></td>
                            </tr>
                          </table>
                        </form></td>
                    </tr>
                    <?php if (!empty($message))
					  echo "
                      <tr>
                        <td class='message'>$message</td>
                      </tr>
					  ";
					  ?>
                    <tr>
                      <td><form name="frmListing" id="frmListing"  method="post" style="margin:0; padding: 0" action="">
                          <table cellspacing="1" class="tablesorter">
                            <thead>
                            <tr>
                              <th width="30" align="center"><input type="checkbox" name="chkAll" id="chkAll" onclick="checkAll()" value="1" /></th>
                              <th align="left" width="90"><?= (isset($_GET['show']) && $_GET['show'] == 'sent') ? 'Date Sent' : 'Date Saved' ?></th>
                              <th width="15%" align="left">Name</th>
                              <th align="left">Subject</th>
                              <?php if (isset($_GET['show']) && $_GET['show'] == 'sent') 
                              	echo '<th align="left" width="30%">Address Book(s) Used</th>';
                              ?>
                              <th width="130" align="center">Action</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
							
					if(!empty($searchTxt))
					{
						$searchctr = " AND (";
						$searchArray1=explode(",",$searchArray);
						
						$searchctr.= "ID = '$searchTxt' OR CAMPAIGN_NAME like '%$searchTxt%' 
						OR FROM_NAME like '%$searchTxt%' 
						OR FROM_EMAIL like '%$searchTxt%' 
						OR SUBJECT like '%$searchTxt%'"; 
						$searchctr .= ") ";
					}
					
					
		
					$query = "SELECT ID, CAMPAIGN_NAME, FROM_NAME, FROM_EMAIL, REPLYTO_NAME, REPLYTO_EMAIL, SUBJECT, DATE_CREATED, DATE_SENT FROM
					smlr_campaigns WHERE $isSent $searchctr $appendToQuery ORDER BY ID DESC
					LIMIT {$pageObj->start}, {$pageObj->limit}";		
					$resultSet = $funcObj->CustomQuery($query);		
						
							
					//$resultSet = $funcObj->FetchRecords("$table",$searchTxt,$searchArray,'ID DESC', $pageObj->start, $pageObj->limit);
					$i=1;
					if(count($resultSet)!=0)
					{
					foreach ($resultSet as $row)
					{
						$i++;
						echo "<tr>";
						echo "
						<td align='center'><input type='checkbox' name='chkContacts[]' value='{$row["ID"]}' /></td>
						<td align='left'>";
						if (isset($_GET['show']) && $_GET['show'] == 'sent')
							echo date("M j, Y", strtotime($row["DATE_SENT"]));
						else
							echo date("M j, Y", strtotime($row["DATE_CREATED"]));
						echo "</td>
						<td align='left'>{$row["CAMPAIGN_NAME"]}</td>
						<td align='left'>{$row["SUBJECT"]}</td>";
						
						## only show the address book column for sent campaigns
						if (isset($_GET['show']) && $_GET['show'] == 'sent') 
						{
							echo "<td align='left'>";
							
							$addrUsedResultset = getAddrUsed($row["ID"]);
							
							$iCount = 1;
							foreach ($addrUsedResultset as $val)
							{
								echo "($iCount). " . "<a href='contacts.php?addrid={$val["ID"]}'>" . $val["NAME"] . "</a><br />";
								$iCount++;
							}
							echo "</td>";
						}
												
						echo "<td align='center' nowrap='nowrap'>
						<a href='{$curFile}?action=edit&amp;id={$row['ID']}&amp;show={$show}'><img src='images/edit.gif' alt='Edit' title='Edit' border='0' /></a>&nbsp;
						<a href='javascript:previewWindow(\"".base64_encode($row["ID"])."\")'><img src='images/ic_preview.gif' alt='Preview' title='Preview' border='0' /></a>&nbsp;";
						
						## Provide campaign send permissions only if the user is admin
						## Restrict send access for clients.
						if ($_SESSION['IS_USER_CLIENT'] == '0')
						{
							echo "<a href='send.php?&amp;id={$row["ID"]}'><img src='images/send_campaign.gif' alt='Send Campaign' title='Send Campaign' border='0' /></a>&nbsp;";
						}
						
						if (isset($_GET['show']) && $_GET['show'] == 'sent') 
							echo "<a href='reports.php?id={$row["ID"]}'><img src='images/graph.png' alt='See Report' title='See Report' border='0' /></a>";
						
						echo "</td>
						</tr>
						";
						}
					}
					else
					echo "<tr><td colspan='6' align='center' height='30' valign='middle' class='row0'>No Record Found... </td></tr>";
					?>
                          </tbody>
                          <tfoot style="background-color: #ffffff; border-color: #ffffff;">
                          <?php
							if (count($resultSet))
							{
								echo "<tr>
								<td colspan='6' align='left' style='padding-left:10px; height: 30px;' valign='top'><img src='images/selarrow.gif' alt='' border='0' /> <a href='javascript:;' onclick='return seldelete()'>Delete selected records</a></td>
								</tr>";
							}
						  ?>
                          </tfoot>
                          </table>
                          <input type="hidden" name="formtype" value="multipledelete" />
                        </form></td>
                    </tr>
                    <tr>
                      <td class="pagingTD"><table cellspacing='0' cellpadding='0'  width='100%'>
                          <tr>
                            <td style="text-align:left" class="form_base_header"><span class="pagenav">
                              <?=$pageObj->ShowPageInfo()?>
                              </span></td>
                            <td style="text-align:right" class="form_base_header"><span class="pagenav">
                              <?=$pageObj->Show($link)?>
                              </span></td>
                          </tr>
                        </table></td>
                    </tr>
                  </table></td>
                <td valign="top" align="left" width="300"><form name="formcampaign" method="post" action="campaigns.php?show=<?=$show?>" style="margin: 0;">
                    <table width="100%" border="0" cellspacing="1" cellpadding="1" class="inputformtable">
                      <tr>
                        <td class="pageHeadingRt" colspan="2"><?php echo ucwords($ACTION) ?> Campaign
                          <?php if ($ACTION == 'edit') { echo "&nbsp;&nbsp;<small>(<a href='{$_SERVER["PHP_SELF"]}'>Cancel Edit</a>)</small>"; } ?>
                        </td>
                      </tr>
					  <?php if(!empty($errorMsg)){?>
                      <tr>
                        <td height="25" colspan="2" valign="top" <?= (! empty ($errorMsg)) ? 'class="error"' : '' ?>><?php
				   errorMessage($errorMsg);
				   ?></td>
                      </tr>
					  <?php } ?>
                      <tr>
                        <td class="inputlabel" colspan="2">Campaign Name *</td>
                      </tr>
                      <tr>
                        <td colspan="2"><input type="text" name="txtname" class="textbox" value="<?=$funcObj->RemoveSlashes($CAMPAIGN_NAME)?>" maxlength="70" size="53" />
                          <br />
                          <small>Example: Segnant SEO Conference Newsletter</small> </td>
                      </tr>
                      <tr>
                        <td class="inputlabel" colspan="2">Subject *</td>
                      </tr>
                      <tr>
                        <td colspan="2"><input type="text" name="txtSubject" class="textbox" value="<?=$funcObj->RemoveSlashes($SUBJECT)?>" maxlength="250" size="53" />
                          <br />
                          <small>Put email subject</small> </td>
                      </tr>
                      <tr>
                        <td class="inputlabel" width="50%">From Name</td>
                        <td class="inputlabel" width="50%">From Email *</td>
                      </tr>
                      <tr>
                        <td><input type="text" name="txtFromName" class="textbox" value="<?=$funcObj->RemoveSlashes($FROM_NAME)?>" maxlength="45" size="21" />
                          <br />
                          <small>Example: Segnant Support</small> </td>
                        <td><input type="text" name="txtFromEmail" class="textbox" value="<?=$funcObj->RemoveSlashes($FROM_EMAIL)?>" maxlength="50" size="23" />
                          <br />
                          <small>Example: info@segnant.com</small> </td>
                      </tr>
                                            <tr>
                        <td class="inputlabel" width="50%">Reply-To Name</td>
                        <td class="inputlabel" width="50%">Reply-To Email </td>
                      </tr>
                      <tr>
                        <td><input type="text" name="txtReplyToName" class="textbox" value="<?=$funcObj->RemoveSlashes($REPLYTO_NAME)?>" maxlength="50" size="21" />
                          <br />
                          <small>Example: Steve Curry</small> </td>
                        <td><input type="text" name="txtReplyToEmail" class="textbox" value="<?=$funcObj->RemoveSlashes($REPLYTO_EMAIL)?>" maxlength="50" size="23" />
                          <br />
                          <small>Example: support@segnant.com</small> </td>
                      </tr>
                      <tr>
                        <td colspan="2"><a href="#" class="bold" id="insertActions">Personalize your email</a>
                          <div id="ActionsDiv">
                            <table width="100%" cellpadding="0" cellspacing="0">
                              <tr>
                                <td><table cellspacing="0" cellpadding="0" class="tabtable" style="margin-top: 10px;">
                                    <tr>
                                      <td nowrap="nowrap" style="cursor:pointer;" id="actionButton" class="active"> Action </td>
                                      <td nowrap="nowrap" style="cursor:pointer;" id="personalizeButton"> Personalize </td>
                                      <td class="noclass" style="padding-left: 15px;"><a href="#TB_inline?height=300&amp;width=550&amp;inlineId=helpContent" class="thickbox orange">How to use?</a></td>
                                    </tr>
                                  </table></td>
                              </tr>
                              <tr style="background-color: #FFF">
                                <td><div id="Tab1">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="1" class="listingTable" style="margin-top: 10px;">
                                      <tr>
                                        <th>Data Field</th>
                                        <th align="left" width="43%" >Link</th>
                                        <th width="20%" align="left">Insert</th>
                                      </tr>
                                      <tr class="row0">
                                        <td>Unsubscribe link</td>
                                        <td>$UNSUB$</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'$UNSUB$')">Insert</a></td>
                                      </tr>
                                      <tr class="row1">
                                        <td>Can't read link</td>
                                        <td>$CANTREAD$</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'$CANTREAD$')">Insert</a></td>
                                      </tr>
                                      <tr class="row0">
                                        <td>Link Tracking</td>
                                        <td>$LINKTRACK$</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'$LINKTRACK$')">Insert</a></td>
                                      </tr>
                                      <tr class="row0">
                                        <td>Forward to friend</td>
                                        <td>$FORWARD$</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'$FORWARD$')">Insert</a></td>
                                      </tr>
                                    </table>
                                  </div>
                                  <div id="Tab2" style="display:none">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="1" class="listingTable" style="margin-top: 10px;">
                                      <tr>
                                        <th>Field</th>
                                        <th align="left" width="35%" >Marker</th>
                                        <th width="20%" align="left">Insert</th>
                                      </tr>
                                      <tr class="row0">
                                        <td>Email</td>
                                        <td>@EMAIL@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@EMAIL@')">Insert</a></td>
                                      </tr>
                                      <tr class="row1">
                                        <td>First Name</td>
                                        <td>@FIRSTNAME@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@FIRSTNAME@')">Insert</a></td>
                                      </tr>
                                      <tr class="row0">
                                        <td>Last Name</td>
                                        <td>@LASTNAME@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@LASTNAME@')">Insert</a></td>
                                      </tr>
                                      <tr class="row1">
                                        <td>Miscellaneous Field 1</td>
                                        <td>@MISC_1@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@MISC_1@')">Insert</a></td>
                                      </tr>
                                      <tr class="row0">
                                        <td>Miscellaneous Field 2</td>
                                        <td>@MISC_2@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@MISC_2@')">Insert</a></td>
                                      </tr>
                                      <tr class="row1">
                                        <td>Miscellaneous Field 3</td>
                                        <td>@MISC_3@</td>
                                        <td><a href="javascript:;" onclick="insertAtCursor(document.formcampaign.areaBody,'@MISC_3@')">Insert</a></td>
                                      </tr>
                                    </table>
                                  </div></td>
                              </tr>
                            </table>
                          </div></td>
                      </tr>
                      <tr>
                        <td class="inputlabel" colspan="2">Campaign Body (HTML)*</td>
                      </tr>
                      <tr>
                        <td colspan="2"><textarea name="areaBody" class="textarea" rows="10" style="width: 285px"><?=$funcObj->RemoveSlashes($CONTENTS)?>
</textarea>
                          <br />
                          <small>Paste your HTML contents in the box above.</small></td>
                      </tr>
                      <tr>
                        <td class="inputlabel" colspan="2">Campaign Body (Plain Text)*</td>
                      </tr>
                      <tr>
                        <td colspan="2"><textarea name="areaBodyText" class="textarea" rows="10" style="width: 285px"><?=$funcObj->RemoveSlashes($CONTENTSPLAIN)?>
</textarea>
                          <br />
                          <small>Paste your plain text contents in the box above.</small></td>
                      </tr>
                      <tr>
                        <td height="35" colspan="2"><input type="submit" name="submit" value="Save" class="button size1" />&nbsp; 
						<?php if ($ACTION == 'edit') 
						{ 
							echo '<input type="submit" name="duplicate" value="Duplicate Campaign" class="button size1" />';						
						}
						?>
                        </td>
                      </tr>
                      <tr>
                        <td height="45" colspan="2">Fields marked with * are mandatory.</td>
                      </tr>
                    </table>
                    <input type="hidden" name="ID" value="<?php echo isset($_GET['id']) ? $_GET['id'] : '' ?>" />
                    <input type="hidden" name="formaction" value="<?php echo $ACTION?>" />
                  </form></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
  <?php require_once 'includes/inc.footer.php' ?>
</table>
<div id="helpContent" style="display:none">
  <p><strong class="size14 bold orange"> You can add actions and personalize markers in your existing newsletter/email to personalize it.</strong></p>
  <p><strong>What are Actions:</strong><br />
    With the help of <em><strong>actions</strong></em> you can track various actions performed by the recipients. These actions are like how many people have clicked the unsubscribe link, can't read link etc. We can also track hits on certain links.</p>
  <p>Just move your cursor to the position where you like to add the <em><strong>Actions</strong></em> then hit the <em><strong>Insert link</strong></em> to embed the link at the cursor position. These actions will be converted to meaningful URL by the system itself.</p>
  <p><strong>How to use them?</strong><br />
    Suppose this is your ordinary unsubscribe link:</p>
  <p>&lt;a href=&quot;http://sitename.com/unsubscribe.aspx&quot;&gt;Unsubscribe now&lt;/a&gt;</p>
  <p>Please modify this link using Actions. Below is the example:</p>
  <p>Place your cursor in the begining of the URL and click the Insert '<em><strong>Unsubscribe link</strong></em>'. The link will be converted to something like:</p>
  <p>&lt;a href=&quot;$UNSUB$http://sitename.com/unsubscribe.aspx&quot;&gt;Unsubscribe now&lt;/a&gt;</p>
  <p><strong>How to use Forward to a friend data marker?<br />
  </strong>&lt;a href=&quot;$FORWARD$&quot;&gt;Forward email to a friend&lt;/a&gt;</p>
  <p>You can change the display text to anything. You can even use an image instead of plain text. But make sure that the href part of <strong>A</strong> tag has <strong>$FORWARD$</strong> in it. <br />
  It's that simple.</p>
  <p><strong>What is the USE of inserting Actions and how it works?</strong><br />
    Whenever the end recipient click on the link it will first visit the Segnant Mailer website, identify the user and update the hits and then it will redirect the user to the actual link. All this will be done in fraction of seconds. </p>
  <p><strong>How to personalize emails?</strong><br />
    Sometimes we need to dynamically insert person's name, email or any other information specific to the recipient user. <em><strong>Personalize TAB</strong></em> will help you to perform this action.</p>
  <p><strong>How to add personal identities and how do they work?</strong><br />
    If you like to display person's last name, you can do it in the following manner:</p>
  <p>Dear @LASTNAME@,</p>
  <p>The system will automatically replace the @LASTNAME@ with the actual LAST NAME of the recipient. But you have to make sure that the <em><strong>marker</strong></em> you are adding has a value in database for the address book you are going to use for this newsletter/email. You can add <em><strong>marker</strong></em> to <em><strong>Subject</strong></em> and <em><strong>Campaign Body (HTML)</strong></em> fields by clicking on <em><strong>Personalize yuor email</em></strong> link and then click on <em><strong>Personalize </em></strong>tab. Just move your cursor to position where you like to add <em><strong>marker</em></strong> then hit the <em><strong>Insert link</em></strong> followed by <em><strong>marker</em></strong> name to add the marker at the cursor position.</p>
  <p>I hope this information would be helpful!</p>
  <p> </p>
</div>
</body>
</html>
