<?php 
$active = 'My Shop';
$pageName = "My Enquirys";

require_once('config/config.php');
require_once(CLASS_DIR.'dbClass.php');
require_once(INCLUDES_DIR.'header.php');
require_once(INCLUDES_DIR.'script.php');

include('checklogin.php');
include('hitCounter.php');

$obj = new DBClass();
$obj5 = new DBClass();

if(isset($_GET['action']) && $_GET['action'] == 'delete'){
	$sql1 = "DELETE FROM ".TBL_ENQ." WHERE id = '".$_GET['id']."' ";
	$rs1 = $obj->executeQry($sql1,$link);
	$info[] = 'Record deleted successfully';
	@header("location:myenquiries.php");
	exit;
}


?>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="js/fancybox/fancybox/jquery.mousewheel-3.0.2.pack.js"></script>
<script type="text/javascript" src="js/fancybox/fancybox/jquery.fancybox-1.3.0.pack.js"></script>
<link rel="stylesheet" type="text/css" href="js/fancybox/fancybox/jquery.fancybox-1.3.0.css" media="screen" />
<script src="JqueryLoader.js" type="text/javascript"></script>

<!--workarea start------------------------->
<div class="workarea">
	<div class="workareatop">
		<img src="images/workareatopcorner_03.PNG" alt="" />
	</div>
	<!--workareamid start--------------------->
	<div class="workareamid">
		<div id="floatleft" style="width:590px; float:left;">
			<div class="welcomediv">
			
                        <h2>Enquiries about your Listings</h2>
                   <br />
<table  class="main" width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
			<td class="bdr1">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
							
							<tr>
								<td>
										<table width="100%" border="0" cellpadding="0" cellspacing="0" class="main">  
												<tr height="30" class="form_head ">
														<td width="20%" height="30" align="center" valign="middle" class="bdr2">Name</td>
														<td width="20%" height="30" align="center" valign="middle" class="bdr2">Email</td>
														<td width="20%" height="30" align="center" valign="middle" class="bdr2">Phone</td>
														<td width="17%" height="30" align="center" valign="middle" class="bdr2">Date</td>
														<td width="13%" height="30" align="center" valign="middle" class="bdr2">View</td>
														<td width="13%" height="30" align="center" valign="middle" class="bdr2">Delete</td>
    											</tr>
  <?php 
$adjacents = 5;

$tbl_name=TBL_ENQ;

$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE (memberID = '".$_COOKIE['memberID']."' OR memberID = '".$_SESSION['memberID']."')";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$targetpage = "myenquiries.php";

$limit = 20;
$page = $_GET['page'];
if($page) 
	$start = ($page - 1) * $limit;
else
	$start = 0;	

$sql = "SELECT * FROM $tbl_name WHERE (memberID = '".$_COOKIE['memberID']."' OR memberID = '".$_SESSION['memberID']."') order by ondate DESC LIMIT $start, $limit";
	$result = mysql_query($sql);
	

	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\">";
		//previous button
		if ($page > 1) 
			$pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>";
		else
			$pagination.= "<span class=\"disabled\">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=\"$targetpage?page=$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=\"$targetpage?page=$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
			}
			//in middle; hide some front and some back
			elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
			{
				$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
				$pagination.= "<a href=\"$targetpage?page=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=\"$targetpage?page=$counter\">$counter</a>";					
				}
				$pagination.= "...";
				$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
				$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";		
			}
			//close to end; only hide early pages
			else
			{
				$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
				$pagination.= "<a href=\"$targetpage?page=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=\"$targetpage?page=$counter\">$counter</a>";					
				}
			}
		}
		
		//next button
		if ($page < $counter - 1) 
			$pagination.= "<a href=\"$targetpage?page=$next\">next</a>";
		else
			$pagination.= "<span class=\"disabled\">next</span>";
		$pagination.= "</div>\n";		
	}

							$rs = $obj->executeQry($sql,$link);
							$rownum = $obj->getrow();
							$i=1;
                            if($obj->getrow()>0) {
							while($row = $obj->fetchrow()) {  
							
							?>												
												<tr class="<?php echo (($i%2) == 0) ? "bg_td1" : "bg_td1";?>">
														<td align="center" style="padding-left:5px"><?php echo $row['name'];?></td>
														<td align="center" style="padding-left:5px"><?php echo $row['email']; ?></td>
														<td align="center" style="padding-left:5px"><?php echo $row['phone']; ?></td>
														<td align="center" style="padding-left:5px"><?php echo date("d-m-Y",strtotime($row['ondate'])); ?></td>
														<td align="center" style="padding-left:5px"><a href="view_listing.php?id=<?php echo $row['listingID'];?>" class="pupUpBox"><img src="images/icon_view.png" name="Image64" title="view" width="28" height="24" border="0" id="Image64" style="border:none" /></a></td>
														<td align="center" style="padding-left:5px"><a href="myenquiries.php?action=delete&id=<?php echo $row['id'];?>" onClick="if(confirm('Are you sure, You want delete this listing?')){location.replace('myenquiries.php?action=delete&id=<?php echo $row['id']?>');}return false;" ><img src="images/icon_del1.png" title="Delete" name="Image66" width="28" height="24" border="0" id="Image66" style="border:none" /></a></td>
												 </tr>
												<?php $i++;	}  } else { ?>													
												<tr class="bg_td1">
													<td colspan="6" style="color:#D40000;padding-left:10px;"><strong>Record Not Found !</strong></td>
												</tr>
												<?php } ?>
										</table>
								</td>
								
							</tr>
					</table>												  
			</td>
	</tr>
</table>
<table width="100%" align="center" cellpadding="0" cellspacing="0">
	<tr>
      	<td align="center" width="100%"><?php echo $pagination; ?></td>
    </tr>                   
</table>				   


						</div>
				</div>
				<?php require_once(INCLUDES_DIR.'left_bar.php');?>
                <!--floatright close-------------------->
                <div style="clear:both;"></div>
            </div>
            <!--workareamid close--------------------->
            <div class="workareabottom">
                <img src="images/workareabottomcorner_03.PNG" alt="" />
            </div>
        </div>
    <!--workarea close------------------------->
<?php require_once(INCLUDES_DIR.'footer.php');?>