<?php 
$active = 'New Offers';
$pageName = 'New Offer';

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

include('hitCounter.php');

$obj = new DBClass();
$obj4 = new DBClass();
$obj9 = new DBClass();
?>


<!--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>New Offers</h2>
<?php
$adjacents = 2;

$tbl_name=TBL_LISTING;

$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE  status = '0'";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$targetpage = "newarrival.php";

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

$sql = "SELECT * FROM $tbl_name WHERE  status = '0' order by added_on 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";		
	}
while($row = mysql_fetch_array($result)) { 

			$sql9 = "SELECT * FROM ".TBL_THEME." WHERE memberID = '".$row['memberID']."'";
			$rs2 = $obj9->executeQry($sql9,$link);
			$row9 = $obj9->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 bgcolor="#990066" class="form_head" style="padding-left:5px"><span style="text-align: left;"><a href="<?php echo $row9['themeID']; ?>/index.php?id=<?php echo $row['memberID']; ?>" target="_blank"><span style="font-size: small;"><b><?php echo $row4['person_name'].' ('.$row4['organisation_name'].')';?></b></span></a></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 width="40%" class="contain"><b>Commodity</b></td> 
													  <td width="60%" class="contain"><?php echo $row['commodity'] ?></td>
												   </tr>
												   <tr>
													  <td class="contain"><b>Origin</b></td> 
													  <td class="contain"><?php echo $row['origin'] ?></td>
												   </tr>
														  <tr>
													  <td class="contain"><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"><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"><b>Size</b></td> 
													  <td class="contain"><?php echo $row['size'] ?></td>
												   </tr>
												   <tr>
													  <td class="contain"><b>Gross Calorific Value(A.D.Basis)</b></td> 
													  <td class="contain"><?php echo $row['actual_gcv'] ?></td>
												   </tr>
												   <tr>
													  <td class="contain"><b>Total Moisture(A.R.Basis)</b></td> 
													  <td class="contain"><?php echo $row['actual_tm'] ?></td>
												   </tr>
												   <tr>
													  <td class="contain"><b>ASH(A.D.Basis)</b></td> 
													  <td class="contain"><?php echo $row['actual_ash'] ?></td>
												   </tr>
												   <tr>
													  <td class="contain"><b>Sulphur</b></td> 
													  <td class="contain"><?php echo $row['actual_sulpher'] ?></td>
												   </tr>
													<tr>
													  <td class="contain"><b>Base Rate (INR/Mt ,Exclude Transport)</b></td> 
													  <td class="contain"><?php echo $row['base_rate'] ?></td>
												   </tr>
												   <tr> 
												   		<td colspan="2">
																<span id="contact_<?php echo $row['id'] ?>" style="display:none;">
																		<table width="100%" border="0" cellspacing="0" cellpadding="0">
																				<tr>
																					<td colspan="3" bgcolor="#990066" class="form_head" style="padding-left:5px"><div style="text-align: center;"><span style="font-family: Tahoma;"><span style="color: rgb(0, 0, 0);"><b>Contact Details</b></span></span></div></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Address</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['address'];?>, <?php echo $row4['district'];?>, <?php echo $row4['state'];?> - <?php echo $row4['pincode'];?></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Phone</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['phone'];?></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Fax</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['fax'];?></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Mobile</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['mobile1'];?>, <?php echo $row4['mobile2'];?></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Email</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['email1'];?>, <?php echo $row4['email2'];?></td>
																				</tr>
																				<tr>
																					<td class="contain" valign="top"><b>Website</b></td>
																					<td width="5"></td>
																					<td class="contain"><?php echo $row4['website'];?></td>
																				</tr>
																				<tr>
																					<td colspan="3"><span style="text-align:right !important; float:right"><a href="showListing.php?id=<?php echo $row['memberID'] ?>">Show all product of same trader </a></span></td>
																				</tr>
																		</table>
																</span>
														</td>
												   </tr>
												   <tr>
														<td colspan="2"><span style="text-align:right !important; float:right"  id="more_<?php echo $row['id'] ?>"><a href="enq.php?id=<?php echo $row['id'] ?>" rel="ibox">Contact Details</a></span></td>
													</tr>
											</table>
									</td>
							</tr>
					</table>
			</td>
	</tr>
	<p>&nbsp;</p>
</table>                
<?php } ?>
 <br /><br /><br />
 <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');?>