<?php 
$heading = 'posting';
require_once('includes/header.php'); 

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

$memberID = $_REQUEST['id'];

$adjacents = 5;

$tbl_name = TBL_LISTING;

$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE memberID = '".$memberID."'";

$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$targetpage = "our-posting.php?id=".$memberID;

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

$sql = "SELECT * FROM $tbl_name WHERE memberID = '".$memberID."' order by id 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";		
	}

 ?>
<div id="page-wrapper">
	<div id="page-content">
		<div id="floatleft">
			<?php

	$rs = $obj->executeQry($sql,$link);
	$rownum = $obj->getrow();
	$i=1;
	if($obj->getrow()>0) {
	while($row = $obj->fetchrow())  { 
	
	$sql4 = "SELECT * FROM ".TBL_DIRECTORY." WHERE memberID = ".$row['memberID'];
	$rs4 = $obj4->executeQry($sql4,$link);
	$row4 = $obj4->fetchrow();
?>
<table  class="main" width="96%" border="0" cellspacing="0" cellpadding="0">
		<tr>
				<td class="bdr1">
						<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
										<td class="form_head"><span style="text-align: left;float:left;"><?php echo $row4['person_name'].' ('.$row4['organisation_name'].')';?></span><span style="float:right;padding-right:5px;padding-top:5px;font-size:10px;"><?php echo date("j-F-Y, h:i:s A",strtotime($row['added_on']));?></span></td>
								</tr>
								<tr>
										<td>
												<table width="98%" align="center" border="0" cellspacing="0" cellpadding="0">
														<tr>
																<td height="5"></td>
														</tr>
														<tr>
														  <td width="50%" class="contain">&nbsp;<b>Commodity</b></td> 
														  <td width="50%" class="contain"><?php echo $row['commodity'] ?></td>
													   </tr>
													   <tr>
														  <td class="contain">&nbsp;<b>Origin</b></td> 
														  <td class="contain"><?php echo $row['origin'] ?></td>
													   </tr>
															  <tr>
														  <td class="contain">&nbsp;<b>Location</b></td> 
														  <td class="contain"><?php if($row['commodity'] == 'Coal') { echo ($row['origin']=='Indian')?$row['area'].' ('.$row['mines_name'].')':$row['port']; } else { echo ($row['origin']=='Indian')?$row['noncoal_state']:$row['noncoal_state'].' ('.$row['noncoal_port'].')'; }?></td>
													   </tr>
													   <tr>
															  <td class="contain">&nbsp;<b>Sub Location</b></td> 
															  <td class="contain"><?php if($row['commodity'] == 'Coal') {  if($row['origin']=='Indian') { echo $row['mines_name']; } } else { echo ($row['origin']=='Indian')?$row['noncoal_district']:$row['noncoal_district']; }?></td>
														   </tr>
														   <tr>
															  <td class="contain">&nbsp;<b>Size</b></td> 
															  <td class="contain"><?php echo $row['size'] ?></td>
														   </tr>
														   <tr>
															  <td class="contain">&nbsp;<b>Gross Calorific Value(A.D.Basis)</b></td> 
															  <td class="contain"><?php echo $row['actual_gcv'] ?></td>
														   </tr>
														   <tr>
															  <td class="contain">&nbsp;<b>Total Moisture(A.R.Basis)</b></td> 
															  <td class="contain"><?php echo $row['actual_tm'] ?></td>
														   </tr>
														   <tr>
															  <td class="contain">&nbsp;<b>ASH(A.D.Basis)</b></td> 
															  <td class="contain"><?php echo $row['actual_ash'] ?></td>
														   </tr>
														   <tr>
															  <td class="contain">&nbsp;<b>Sulphur</b></td> 
															  <td class="contain"><?php echo $row['actual_sulpher'] ?></td>
														   </tr>
															<tr>
															  <td class="contain">&nbsp;<b>Base Rate (INR/Mt ,Exclude Transport)</b></td> 
															  <td class="contain"><?php echo $row['base_rate'] ?></td>
														   </tr>
														   <tr>
																<td>&nbsp;</td>
														   </tr>
												</table>
										</td>
								</tr>
						</table>
				</td>
		</tr>
		<p>&nbsp;</p>
</table>
<?php 	} ?> <br /><br />
<?php } else { ?>
<table>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td><font color="#D40000"><b>Record not found !</b></font></td>
	</tr>
</table> 
<?php } ?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">                        
	<tr>
		<td valign="top" class="bg_innerfoot">
			<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
					<td align="center" class="footer_num"><?php if ($rownum > 0) echo $pagination;?></td>
				</tr>
			</table>
		</td>
	</tr>                   
</table> 	

  
			</div>
			<?php include 'includes/left_bar.php'; ?>
	</div>
	<!-- page content end -->
</div>
<!-- page wrapper end -->
<?php require_once('includes/footer.php'); ?>