<?php ob_start();
session_start();
require_once("../dbconnect.php");
?>
<!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=iso-8859-1" />
<title>Welcome to B'Dazzled Swim</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>


<script language="javascript" src="ajaxcoupon.js"></script>
<script language="javascript" src="ajaxvalid.js"></script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />

<!--calender files-->
<SCRIPT LANGUAGE="JavaScript">
var cal1 = new CalendarPopup();
</SCRIPT>
		<style type="text/css" media="screen,projection">
			@import url(calendar.css);
		</style>
		<script src="calendar.js" type="text/javascript" language="javascript"></script>
<!---->

</head>
<body >

<table width="1003" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td><?php require_once("header.php"); ?></td>
          </tr>
          <tr>
            <td><?php 
session_start();
ob_start();
$month=date('m');
$year=date('Y');
?>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="left" valign="top" class="body_td"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="left" valign="top"><table width="100%" align="right" cellpadding="0" cellspacing="0">
              <tr>
                <td height="25" align="left" valign="top"><h1>View Coupon Codes</h1></td>
                </tr>
              <tr>
                <td height="25" align="left" valign="middle">Coupon codes allow you to provide customers with discounts on products available for purchase from your store.</td>
                </tr>
              <tr>
                <td align="left" valign="middle">&nbsp;</td>
                </tr>
              <tr>
                <td align="left" valign="middle">&nbsp;</td>
                </tr>
              <tr>
                <td align="left" valign="middle"><a href="addcoupon.php"><img src="images/button_new_coupon.gif" border="0" width="105" height="22" /></a></td>
                </tr>
              <tr>
                <td align="left" valign="top">&nbsp;</td>
                </tr>
              <tr>
                <td align="left" valign="middle">&nbsp;</td>
                </tr>
              <tr>
                <td align="left" valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="40" align="left" valign="middle" style="background:url(images/sub_heasd.gif) repeat-x left; border:#93A6B4 solid 1px; border-bottom:0px; border-top:0px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="25" align="center" valign="middle"><label>
                          <input type="checkbox" name="checkbox" id="checkal" onclick="checkall(this);"/>
                          </label></td>
                        <td width="130" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="right" valign="middle" class="customer_head">Coupon Name</td>
                            <td width="35%"><table width="20" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_name','asc');"><img src="images/up.gif" width="7" height="4" border="0" id="Fnameasc" style="margin:2px;"/></a></td>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_name','desc');"><img src="images/down-lite.gif" width="7" height="4" border="0" id="Fnamedesc" style="margin:2px;"/></a></td>
                              </tr>
                            </table></td>
                            </tr>
                          </table></td>
                      <td width="200" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="right" valign="middle" class="customer_head">Coupon Code</td>
                            <td width="45%"><table width="20" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_descr','asc');"><img src="images/up-lite.gif" width="7" height="4" border="0" style="margin:2px;" id="Emailasc"/></a></td>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_descr','desc');"><img src="images/down-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="Emaildesc"/></a></td>
                              </tr>
                            </table></td>
                            </tr>
                          </table></td>
                        <td width="100" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="right" valign="middle" class="customer_head">Discount:</td>
                            <td width="42%"><table width="20" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_amt','asc');"><img src="images/up-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="Phoneasc"/></a></td>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_amt','desc');"><img src="images/down-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="Phonedesc"/></a></td>
                              </tr>
                            </table></td>
                            </tr>
                        </table></td>
                        <td width="120" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="right" valign="middle" class="customer_head">Expiry Date</td>
                            <td width="35%"><table width="20" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_end_date','asc');"><img src="images/up-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="regdateasc"/></a></td>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('coupon_end_date','desc');"><img src="images/down-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="regdatedesc"/></a></td>
                              </tr>
                            </table></td>
                            </tr>
                        </table></td>
                        <td width="100" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td align="right" valign="middle" class="customer_head">No. Uses:&nbsp; </td>
                            <td width="30%"><!--<table width="20" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('orders','asc');"><img src="images/up-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="ordersasc"/></a></td>
                                <td align="center" valign="middle"><a href="javascript:" onclick="sortusers('orders','desc');"><img src="images/down-lite.gif" width="7" height="4" border="0" style="margin:2px;"  id="ordersdesc"/></a></td>
                              </tr>
                            </table> --></td>
                            </tr>
                          </table></td>
                        <td width="100" align="center" valign="middle" class="customer_head">Action </td>
                        </tr>
                      </table></td>
                    </tr>
                  <tr>
                    <td height="5"></td>
                  </tr>
                  <tr>
                	<td align="left" valign="top" ><div id="pageorder">
                    
                    
                    <?php  
				$adjacents = 2;
	
	/* 
	   First get total number of rows in data table. 
	   If you have a WHERE clause in your query, make sure you mirror it here.
	*/
	
	
		$total_pages = mysql_fetch_array(mysql_query("Select count(*) as num from coupons order by coupon_id asc"));
	
	$total_pages = $total_pages[num];
	
	/* Setup vars for query. */
	//$targetpage = "welcomepage.php?sortorder=".$_GET[sortorder]; 	//your file name  (the name of this file)
	$limit = 10; 								//how many items to show per page
	$page = $_GET['page'];
	if($page) 
		$start = ($page - 1) * $limit; 			//first item to display on this page
	else
		$start = 0;								//if no page var is given, set start to 0
	
	/* Get data. */
	
		$sql1 = "select * from coupons order by coupon_id asc LIMIT $start,$limit";
	
	$getuser_list = mysql_query($sql1); 
	
	/* Setup page vars for display. */
	if ($page == 0) $page = 1;					//if no page var is given, default to 1.
	$prev = $page - 1;							//previous page is page - 1
	$next = $page + 1;							//next page is page + 1
	$lastpage = ceil($total_pages/$limit);		//lastpage is = total pages / items per page, rounded up.
	$lpm1 = $lastpage - 1;						//last page minus 1
	
	/* 
		Now we apply our rules and draw the pagination object. 
		We're actually saving the code to a variable in case we want to draw it more than once.
	*/
	$pagination = "";
	if($lastpage > 1)
	{	
		$pagination .= "<div class=\"pagination\"> (Page 1 of ".$lastpage.") &nbsp;&nbsp; ";
		//previous button
		if ($page > 1) 
			$pagination.= "<a href=\"javascript:couponpage($prev)\">&laquo; previous</a>";
		else
			$pagination.= "<span class=\"disabled\">&laquo; previous</span>";	
		
		//pages	
		if ($lastpage < 7 + ($adjacents * 2))	//not enough pages to bother breaking it up
		{	
			for ($counter = 1; $counter <= $lastpage; $counter++)
			{
				if ($counter == $page)
					$pagination.= "<span class=\"current\">$counter</span>";
				else
					$pagination.= "<a href=\"javascript:couponpage($counter)\">$counter</a>";					
			}
		}
		elseif($lastpage > 5 + ($adjacents * 2))	//enough pages to hide some
		{
			//close to beginning; only hide later pages
			if($page < 1 + ($adjacents * 2))		
			{
				for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"javascript:couponpage($counter)\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"javascript:couponpage($lpm1)\">$lpm1</a>";
				$pagination.= "<a href=\"javascript:couponpage($lastpage)\">$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "<a href=\"javascript:couponpage(1)\">1</a>";
				$pagination.= "<a href=\"javascript:couponpage(2)\">2</a>";
				$pagination.= "...";
				for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"javascript:couponpage($counter)\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"javascript:couponpage($lpm1)\">$lpm1</a>";
				$pagination.= "<a href=\"javascript:couponpage($lastpage)\">$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				$pagination.= "<a href=\"javascript:couponpage(1)\">1</a>";
				$pagination.= "<a href=\"javascript:couponpage(2)\">2</a>";
				$pagination.= "...";
				for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
				{
					if ($counter == $page)
						$pagination.= "<span class=\"current\">$counter</span>";
					else
						$pagination.= "<a href=\"javascript:couponpage($counter)\">$counter</a>";					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			$pagination.= "<a href=\"javascript:couponpage($next)\">next &raquo;</a>";
		else
			$pagination.= "<span class=\"disabled\">next &raquo;</span>";
		$pagination.= "</div>\n";		

	}
				
				?>
                
                <?php  while($user_details=mysql_fetch_array($getuser_list))
					   {
						   
						   $count_order=mysql_fetch_array(mysql_query("select count(*) as num from couponusage where coupon_code='".$user_details[coupon_code]."'"));
						  
						   
					?>
                 <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-bottom:#EBEBEB solid 1px;">
                  <tr>
                    <td align="left" valign="top" style="border-bottom:#EBEBEB solid 1px; height:25px;">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="25" align="center" valign="middle"><label>
                          <input type="checkbox" name="<?php  echo $user_details[coupon_id]?>" onclick="checkuserstat();"/>
                          </label></td>
                        <td width="130" align="center" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="19"><img src="images/plus.gif" id="arrow<?php  echo $user_details[coupon_id]?>" alt="<?php  echo $user_details[coupon_id]?>" style="cursor:pointer;"/></td>
                            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td width="20"><img src="images/customer.gif" width="16" height="16" /></td>
                                <td align="left" valign="middle" class="customenr_text"><?php  echo $user_details[coupon_name]?> </td>
                                </tr>
                              </table></td>
                            </tr>
                          </table></td>
                        <td width="200" height="35" align="center" valign="middle"><?php  echo $user_details[coupon_code]?></td>
                        <td width="100" align="center" valign="middle" class="customenr_text"> <?php  echo $user_details[coupon_amt]; if($user_details[amttype]==0) { echo "&nbsp;$"; } else if($user_details[amttype]==1) { echo "%"; } ?> </td>
                        <td width="120" align="center" valign="middle"><?php  echo $user_details[coupon_end_date]?> </td>
                        <td width="100" align="center" valign="middle"><?php  echo $count_order[num]?></td>
                        <td width="100" align="center" valign="middle"><a href="editcoupon.php?coupon_id=<?php  echo $user_details[coupon_id]?>" class="customer">Edit</a>&nbsp;<a href="dbcoupon.php?action=delete&coupon_id=<?php  echo $user_details[coupon_id]?>" class="customer">Delete</a> <br />
                         </td>
                        </tr>
                      </table></td>
                  </tr>
                  
                  </table>
                  <?php  } ?>
                  
                  <input type="hidden" value="1" name="pageno" id="pageno"/>
                  <input type="hidden" value="coupon_id" name="column" id="column"/>
                  <input type="hidden" value="asc" name="order" id="order"/>
                <input type="hidden" name="whichpage" id="whichpage" value="coupon"  />
                <input type="hidden" name="letter" id="letter" value=""  />
                  <div align="right" style="height:25px; padding-top:8px;">
					 <?php  echo $pagination?></div>
                     
                      </div>
                    </td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="25" align="left" valign="middle">&nbsp;</td>
                </tr>
              <tr>
                <td height="10" align="left" valign="middle">&nbsp;</td>
                </tr>
              </table></td>
            </tr>
          </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</td>
          </tr>
          
          
              
            </table></td>
          </tr>
          

          <tr>
            <td><?php require_once("footer.php"); ?></td>
          </tr>
          <tr>
            <td height="200">&nbsp; </td>
          </tr>
        </table>
</body>
</html>
