<?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;

$curFile = basename(__FILE__);

$table = "##contacts";



$id = intval($_GET['id']);

if (empty($id))

	die("Required parameter is missing");



###FETCH ACTIVE ADDRESSBOOK(S)########################

$query = "SELECT A.ID AS CAMPAIGNID 

FROM ##addressbook AS A,

##campaign_send_stats AS B

WHERE B.ADDR_ID = A.ID

AND B.SESSION_ID = '".session_id()."'

AND B.CAMPAIGN_ID = '{$id}'";

$AddrResultSet = array();

$AddrResultSet = $funcObj->CustomQueryArray($query);



$campIds = array();

foreach($AddrResultSet as $row)

{

	$campIds[] = $row['CAMPAIGNID'];

}

$campIdsStr = implode(",", $campIds);

######################################################



$searchTxt = trim($funcObj->AppendSlashes($_REQUEST['searchbox']));

$searchArray = 'ID,EMAIL,FIRSTNAME,LASTNAME,MISC_1,MISC_2,MISC_3,LAST_UPDATED';

$status = $_REQUEST['status'];

$ID=$_REQUEST['id'];



$records	= 200;

if($records > 0)

{

	$limit = intval($records);

}

else

{

	$limit = $configAdminPaging;

}



if($_REQUEST['start'])

	$start = $_REQUEST['start'];

else

	$start = 0;

	

$query = "SELECT COUNT(DISTINCT(EMAIL)) AS TOTAL FROM ##contacts WHERE ADDR_ID IN ($campIdsStr)";

$resultCampIds = $funcObj->CustomQuery($query);



$proCount = $resultCampIds[0]->TOTAL;

$link = $curFile.'?id='.$id;



require_once('classes/paging.class.php');

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

?>

<!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 - Entire Mailing List</title>

<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">

$(document).ready(function() {

	$("table").tablesorter({

		// pass the headers argument and assing a object

		headers: {

			0: {

				// disable it by setting the property sorter to false

				sorter: false

			}

		}

	});

});



</script>

<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />

</head>

<body>

<center>

<table width="100%" border="0" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF">

  <tr>

    <td width="100%" height="50" valign="top" class="heading">Entire Mailing List</td>

  </tr>

  

  <?php if (!empty($message))

		  echo "

		  <tr>

			<td class='message'>$message</td>

		  </tr>

		  ";

		  ?>

	  <tr>

		<td>

			<table cellspacing="1" class="tablesorter">

              <thead>

			  <tr>

				<th width="50" align="center">#</th>

				<th align="left">Email</th>

				<th width="25%" align="left">First name</th>

				<th width="25%" align="left">Last name</th>

			  </tr>

              </thead>

              <tbody>

			  <?php

				if(!empty($searchTxt))

				{

					$searchctr = " AND (";

					$searchArray1=explode(",",$searchArray);

					

					$searchctr.= "ID = '$searchTxt' OR EMAIL like '%$searchTxt%' 

					OR FIRSTNAME like '%$searchTxt%' 

					OR LASTNAME like '%$searchTxt%'"; 

					$searchctr .= ") ";

				}

			

				$query = "SELECT DISTINCT(EMAIL), FIRSTNAME, LASTNAME FROM

				##contacts WHERE ADDR_ID IN ($campIdsStr) $searchctr ORDER BY EMAIL ASC

				LIMIT {$pageObj->start}, {$pageObj->limit}";

		$resultSet = $funcObj->CustomQuery($query);

		$i=0 + intval($_GET['start']);

		if(count($resultSet)!=0)

		{

		foreach ($resultSet as $row)

		{

			$i++;

			echo "<tr>";

			echo "

			<td align='center'>{$i}</td>

			<td align='left'>";

			echo $row->EMAIL; 

			echo "</td>

			<td align='left'>{$row->FIRSTNAME}&nbsp;</td>

			<td align='left'>{$row->LASTNAME}&nbsp;</td>";

			}

		}

		else

		{

			echo "<tr><td colspan='4' align='center' height='30' valign='middle' class='row0'>No Record Found... </td></tr>";

		}

		?>

        </tbody>

        </table>

</td>

  </tr>

  <tr>

    <td class="pagingTD"><table cellspacing='0' cellpadding='0'  width='100%'>

        <tr>

          <td height='35' 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>

</center>

</body>

</html>