<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com (C) 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "../includes/config.php";
include "../includes/session.php";
include "../includes/functions.php";

if(isset( $_SESSION["sess_adminname"]) and $_SESSION["sess_adminname"]!= ""){
	$adminname = $_SESSION["sess_adminname"];
}else{
	header("Location:login.php");
	exit;
}


if(isset($_POST['gotoPage']))
{

	header("Location:".$_SERVER['PHP_SELF']."?page=".$_POST['gotoPage']);
	
		
}


/*
$sql = "SELECT gcm.*,pr.product_image_small,pr.product_name,pr.product_price,
		CASE WHEN gcm.vgift_delete_status = 'N' THEN 'Yes' ELSE 'No' END AS vgift_deleted
		FROM ".$tableprefix."giftcoupon_master gcm,".$tableprefix."products pr,".$tableprefix."currency_master cy 
		WHERE pr.product_id = gcm.ngift_product_id".
		  $qryopt . " GROUP BY gcm.ngift_product_id ORDER BY ngift_id DESC";
*/		  
		
$sql = "SELECT nl_id, nl_subject, nl_message, nl_date
		FROM ".$tableprefix."newsletters ORDER BY nl_date DESC";		
  
		  
	if(!(isset($pagenum)))
	{
		$pagenum = 1;
	} 
	
	$limit = getSettingsValue('npagination_limit');
	
	$page = isset($_GET['page'])? trim($_GET['page']):1;

	
	$page = $_GET['page'];
	
	if(empty($page))
	{
		$page = 1;
	}
	
	$result=mysql_query($sql) or die(mysql_error());						
	
	$totalrows = mysql_num_rows($result);
	
	$limitvalue = ($page - 1) * $limit;
	
	$query_string = " LIMIT $limitvalue, $limit";
	
	$sql = $sql.$query_string;
	   
	$rs = mysql_query($sql) or die(mysql_error());

	$numofpages = ceil($totalrows / $limit);


include "../includes/htmltop.php";
?>
<script language="JavaScript" type="text/JavaScript">
function clickSearch()
{

  var form_name = new Array('txtSearch');		
  var display_name = new Array('Search Keyword');
  var count = 1;	

  if(check_fields('frmGiftCoupon',form_name,display_name,count))	
  {
  
  	
	 document.frmGiftCoupon.submit();	
   
  }
  else
  {
  
  		return false;
  
  }
     
}


function blockCertificate(val)
{

			
	if(val == 'N')
	{

		return confirm('<?php echo DISABLE_GC;?>')
	
	}
	else if(val == 'Y')
	{
	
		return confirm('<?php echo ENABLE_GC;?>')
	
	}	

}

function deleteCoupon()
{
	return confirm('<?php echo DELETE_GC;?>')
}


function ShowHideLayer(divID) {
	var box = document.getElementById("subList"+divID);	
		
	if(box.style.display == "none" || box.style.display=="") {
		box.style.display = "block"; 		
		document.getElementById("viewshow"+divID).innerHTML ="";
		
	}
	else {
		box.style.display = "none";		
		document.getElementById("viewshow"+divID).innerHTML ="<?php echo VIEW; ?>";
	}
}

</script>

		<body>
		
		<center>
		
		<div align="left" id="layout">
		
		
				
				
				<!--header area start -->
<?php

	include_once("../includes/topheader_admin.php")

?>
				
				<!--header area end -->
				
				
				
				
				<div align="left" class="main_body">
				<!--main body start -->
				
				
				
<?php
		include_once("../includes/admintopmenu.php")
?>		
																					
								
					<div align="left" class="content_area">
					
					<!--content area start -->
							
					<div align="left" class="page_title"><?php echo NL_ARCHIVES;?></div>
					<div align="center" class="text_information grey_tr"><?php echo $message?></div>
            		<br>
											
					<div align="left">			
																
				<form action="" method="get" name="frmGiftCoupon">
<!--									
						<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_top">
							<tr>
								<td width="100%" align="left" valign="middle" class=''>Search ::
									<select name="cmbSearchType" class="textbox">
									<option value="couponname" <?php // if($cmbSearchType == "couponname" || $cmbSearchType == ""){ echo("selected"); } ?>>Certificate Name</option>
									<option value="couponamount"  <?php //if($cmbSearchType == "couponamount" || $cmbSearchType == ""){ echo("selected"); } ?>>Amount</option>
									</select> &nbsp;
									<input type="text" name="txtSearch" size="20" maxlength="50" value="<?// echo(htmlentities($txtSearch)); ?>" class="textbox">
									&nbsp;
									<a style="cursor:pointer" onClick="return clickSearch();"><img src='<?php //echo $imagefolder;?>/go.jpg' border='0'></a>
								</td>
								<td align="right"><a href="gift_coupon_add.php" style="cursor:pointer"><img src="../images/add_new_btn.gif" alt="Add New" width="70" height="23" border="0" /></a></td>
							</tr>
						</table>
						-->
					
				</form>
				
				</div>
						
					<div align="left">
						
					<form action="" method="post" name="frmGiftCoupon1">
					
						<table width="100%" border="0" cellpadding="0" cellspacing="0" class="manage_table">
						
							<tr class="form_header">
								<th width="4%" align="left">#</th>
								<th width="17%" align="left" class=""><?php echo SUBJECT;?></th>
								<th width="41%" align="left"><?php echo MESSAGE;?></th>
								<th width="21%" align="left"><?php echo DATE;?></th>
								<th width="17%" align="center"><?php echo SUBSCRIBERS;?></th>								
							</tr>
<?php
if(mysql_num_rows($result) > 0 )
{
	$i = 1;
	
	while($row = mysql_fetch_array($rs))
	{

	$res_subscribe=mysql_query("SELECT first_name,last_name,".$tableprefix."users.user_id,email, nl_id FROM ".$tableprefix."subscribers,".$tableprefix."users where ".$tableprefix."users.user_id=".$tableprefix."subscribers.user_id AND nl_id=".$row["nl_id"]) or die(mysql_error());
	$num_subscribe=	mysql_num_rows($res_subscribe);
	if($num_subscribe>0){
	$sub_cont=1;
	$data_sub="<span align='center'><strong>".NL_LIST."</strong></span><br><br>";
	while ($data_subscribe=mysql_fetch_array($res_subscribe)){
	$data_sub.=$data_subscribe['first_name']." ".$data_subscribe['last_name']." : ".$data_subscribe['email'];
		if($sub_cont==2){
		$data_sub.="&nbsp;&nbsp;<br>";
		$sub_cont=0;
		}else
		{
		$data_sub.="&nbsp;&nbsp;  &nbsp;&nbsp;";
		}
	$sub_cont++;
	}
		$data_sub.="<br>";
	}
																													
?>
								<tr class="">
									<td valign="top"><?php echo $i?></td>
									<td align="left" valign="top" ><?php echo $link .($row["nl_subject"])."</a>";?></td>
									<td align="left"><?php 
									$messageBody =strip_tags(stripslashes($row["nl_message"]));
									if(strlen($messageBody)>50)
									{
									echo substr($messageBody, 0, 700)."...."; 									
									}else{
									echo $messageBody;
									}	
									list($date,$hrs) = explode(" ",$row['nl_date']);
									$date_con        = dateFormat($date,"Y-m-d","m/d/Y")										
									?></td>									
									<td align="left"><?php echo $date_con." ".$hrs;?></td>
									<td align="center"><a onClick="javascript:ShowHideLayer('<?php echo $i?>')" style="cursor:pointer;"><div id="viewshow<?php echo $i?>"><?php echo VIEW;?></div></a></td>
								</tr>
								<tr class="">
									<td colspan="5"><div id="subList<?php echo $i?>" align="center" style="display:none;"><div align="left" style="width:600px; border: 1px solid #505050; padding: 3px 10px 10px 10px";>
									<a onClick="javascript:ShowHideLayer('<?php echo $i?>')" style="cursor:pointer;"><div align="right" id="viewshow<?php echo $i?>"><?php echo CLOSE;?></div></a>
									<?php echo $data_sub;?></div></div></td>									
								</tr>
<?php
	$i++;
	
	}
											
}
else
{
										
?>					
							<tr>
									<td align="center" valign="middle" colspan="5"  class="text_information"><?php echo NO_RECORDS_FOUND;?> !!</td>
							</tr>					
<?php										
}


							if($page > 1)
							{
								$pageprev = $page-1;
								
								$previous_page = "<a href=".$_SERVER['PHP_SELF']."?page=$pageprev alt='Previous' border='0' class='small_gray_button'>".TEXT_PREV."</a>";
								
							}
																											
																				
							if($page < $numofpages)
							{
								$pagenext = ($page + 1);
								
								$next = "<a href=".$_SERVER['PHP_SELF']."?page=$pagenext alt='Next' border='0' class='small_gray_button'>".TEXT_NEXT."</a>";
								
							}	




							  if($page < $numofpages || $page > 1)
							  {
							  ?><tr>
											<td align="center" colspan="5">
											
											<table width="100%" border="0" cellspacing="10" cellpadding="0">
												<tr align="left" valign="middle">
													<td width="21%" align="right"><?php echo $previous_page?></td>
													<td width="23%" align="right">
														<?php echo PAGE."(".S.")";?> <?php echo $page ?>/<?php echo $numofpages?>&nbsp;&nbsp;
														<?php echo GO_TO;?>
													</td>
													<td width="8%" align="right">
														<select class="textarea2" name="gotoPage" style="padding:4px 5px; margin-bottom:1px; ">
  <?php
									for($i=1;$i<=$numofpages;$i++)
									{		
										
										
										if($i == $_GET['page'])
										{
											$page_selected = "selected";
										}
										else
										{
											$page_selected = "";
										}
										
										
?>									
									  <option value="<?php echo $i?>" <?php echo $page_selected?>><?php echo $i?></option>
									  
<?php
									}
									
?>									
										        </select>
													</td>
													<td width="7%">
														<a onClick="Javascript:document.frmGiftCoupon1.submit();" class="go_button_2"><?php echo GO; ?></a>
													</td>
													<td width="41%" align="center"><?php echo $next?></td>
												</tr>
											</table>
											 </td>
											</tr>
										<?php
										}?>
					  </table>
					  </form>
										
																	

						</div>
						
						
				<!--content area end-->
								
				</div>
				
								
					<div align="left" class="clear_float"><img src="<?php echo $imagefolder;?>/clear.gif" alt="" width="1" height="1" /></div>
				<!--main body end -->
				</div>
				
				
<?php
	include "../includes/footer.php";
?>