<?php 
session_start();
require 'authenticate.user.php';

require 'configuration.php';
require_once 'includes/common.functions.php';
require_once ('classes/database.php');
require_once ('classes/functions.php');
$sqlObj = new mysqlClass;
$funcObj = new funcClass;
$table = "##addressbook";
$curFile = basename(__FILE__);
$ACTION				= 'add';

if ($_SESSION['IS_USER_CLIENT'])
{
	die ("Sorry, you are not authorized to access this page");
}

$id = intval($_GET['id']);
if (empty($id))
	die("Required parameter is missing");

$query = "SELECT CAMPAIGN_NAME, FROM_NAME, FROM_EMAIL, SUBJECT  FROM ##campaigns WHERE ID = '{$id}'";
$result = $funcObj->CustomQuery($query);
$campaignName = $result[0]['CAMPAIGN_NAME'];

$campaignID = $_SESSION['CAMPAIGNID'];
if (empty($campaignID))
	die ("Required data missing. Please try again from step 1");

$query = "SELECT * FROM ##contacts WHERE ADDR_ID = '{$campaignID}' ORDER BY EMAIL LIMIT 1";
$contactResult = $funcObj->CustomQuery($query);
/* ACTIVATE THE TAB */
$activeTab = 'Campaigns';
if(isset($_POST) && !empty($_POST['smtp_option'])){
  $_SESSION['smtp_option'] =  $_POST['smtp_option'];
  if($_POST['smtp_option'] == 'multiple'){
    if(isset($_POST['smtps']) && !empty($_POST['smtps'])){
      $implode_ids = implode(',',$_POST['smtps']);
       $_SESSION['SMTP_ID'] = $implode_ids;
       $session_id = session_id();
       $query_update = "UPDATE ##campaign_send_stats SET SMTP_ID = '{$implode_ids}' WHERE ADDR_ID = '{$campaignID}' AND CAMPAIGN_ID = '{$id}' AND SESSION_ID = '{$session_id}' ";
       $updateId = $funcObj->updateQuery($query_update);
    }
  }else{
    $_SESSION['SMTP_ID'] = '';
  }
}
?>
<!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/segnantmailer.css" />
<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/common.jquery.js"></script>
<script type="text/javascript">
jsid = '<?php echo $id; ?>';
</script>
<script type="text/javascript" src="includes/js/send3.jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
	$('#extLinks').click(function()
	{
		$('#extlinksdiv').slideToggle('slow');

	})
});
</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"><? 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 width="100%" height="50" valign="top" class="heading">Send Campaign</td>
        </tr>
      <tr>
        <td>
        <table width="100%" border="0" cellspacing="1" cellpadding="1">
              <?php if (!empty($message))
					  echo "
                      <tr>
                        <td class='message'>$message</td>
                      </tr>
					  ";
					  ?>
              <tr>
                <td><form name="frmListing" id="frmListing" action="send4.php?id=<?=$id?>" method="post" style="margin:0; padding: 0">
                    <?php
					$searchTxt =isset($searchTxt) ? $searchTxt : '';
					$searchArray =isset($searchArray) ? $searchArray : '';
			  //$resultSet = $funcObj->FetchRecords("$table",$searchTxt,$searchArray,'NAME ASC', $pageObj->start, $pageObj->limit);
			  $resultSet = $funcObj->FetchRecords("$table",$searchTxt,$searchArray,'NAME ASC', '', '');
			  ?>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="inactiveTable">
                      <tr class="inactiveTab">
                        <td width="30" align="center"><img src="images/10.png" alt="" hspace="8" border="0" /></td>
                        <td width="90%"><span><strong>Campaign:</strong> select data sources for "
                          <?=$campaignName?>
                          "</span></td>
                        <td width="10%" nowrap="nowrap" align="right" style="padding-right:10px"><a href="send.php?&id=<?=$id?>&action=edit">Edit Settings</a></td>
                      </tr>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="inactiveTable" style="margin-top: 3px;">
                      <tr class="inactiveTab">
                        <td width="30" align="center"><img src="images/20.png" alt="" hspace="8" border="0" /></td>
                        <td width="90%"><span><strong>Campaign:</strong> summary for "
                          <?=$campaignName?>
                          "</span></td>
                        <td width="10%" nowrap="nowrap" align="right" style="padding-right:10px"><a href="send2.php?&id=<?=$id?>&action=edit">Edit Settings</a></td>
                      </tr>
                    </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="activeTable" style="margin-top: 3px;">
                      <tr class="activeTab">
                        <td align="left"><img src="images/31.png" alt="" border="0" hspace="8" align="absmiddle" /> <span><strong>Campaign:</strong> live preview for "
                          <?=$campaignName?>
                          "</span></td>
                        <td width="10%" nowrap="nowrap">&nbsp;</td>
                      </tr>
                                            <tr>
                        <td colspan="3" height="40" style="padding: 8px;">Please check the LIVE PREVIEW of your newsletter. Make sure it is correct before you continue.
                        <br /><br /><small><strong>Note:</strong> LIVE PREVIEW is using the data of first record from the first selected addressbook(s).</small>
                        </td>
                      </tr>
					<tr>
                        <td colspan="3" style="padding: 20px;" align="center">
                        <table border="0" cellpadding="0" cellspacing="0" align="center" bgcolor="#ededed" style="border: 2px solid #cccccc;">
                        <tr>
                        <td>
                         <table width="100%" cellpadding="0" cellspacing="0" align="center">
                          <tr>
                            <td>
                            <table width="100%" cellspacing="0" cellpadding="0">
                            <tr>
                            <td width="50%" style="padding: 15px 0px 0px 10px;" align="left">
                            <table cellspacing="0" cellpadding="0" class="tabtable">
                                <tr>
                                  <td nowrap="nowrap" id="previewhtml" style="cursor:pointer;" onclick='updateTabs("previewhtml")' class="active"> HTML version </td>
                                  <td nowrap="nowrap" id="previewcode" style="cursor:pointer;" onclick='updateTabs("previewcode")'> HTML code </td>
                                  <td nowrap="nowrap" id="previewtext" style="cursor:pointer;" onclick='updateTabs("previewtext")'> Plain text version </td>
                                </tr>
                              </table>
                              </td>
                              <td align="right" style="padding-right: 10px;"><div id="progressbar"><img src="images/ajax-loader3.gif" alt="" /></div></td>
                              </tr>
                              </table>
                              </td>
                          </tr>
                        </table>
                        </td>
                        </tr>
                        <tr>
                        <td align="left" bgcolor="#ffffff" height="10">&nbsp;</td>
                        </tr>
                        <tr>
                        <td height="410" valign="top" align="center" bgcolor="#ffffff">
                        
                        <div style="width: 900px; height: 400px; overflow: auto; border: 0px solid #ccc;" id="renderview" align="left" title="">
                        </div>
                        </td>
                        </tr>
                        </table>
                        </td>
                      </tr>
                    </table>
                    <div style="height: 50px; border: 0px solid #000; vertical-align: middle; padding: 5px; text-align: right">
                  <input type="submit" value="Goto Step 4" class="button" />
                </div>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="inactiveTable" style="margin-top: 3px;">
                      <tr class="inactiveTab">
                        <td width="30" align="center"><img src="images/40.png" alt="" hspace="8" border="0" /></td>
                        <td width="90%"><span><strong>Campaign:</strong> send</span></td>
                        <td width="10%" nowrap="nowrap">&nbsp;</td>
                      </tr>
                    </table>
                    <input type="hidden" name="id" value="<?php echo $_GET['id']?>" />
                    <input type="hidden" name="formaction" value="<?php echo $ACTION?>" />
                  </form></td>
              </tr>
            </table>
        </td>
      </tr>
    </table></td>
  </tr>
<? require_once 'includes/inc.footer.php' ?>
</table>
</body>
</html>
