<?php 

require_once('config/config.php');

require_once(CLASS_DIR.'dbClass.php');

$active = 'Buy Fuel';

require_once(INCLUDES_DIR.'header.php');

$pageName = 'As per Specification';

include('hitCounter.php');

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

$dat = date('Y-m-j');


if(isset($_POST['submit']) && $_POST['submit'] == 'Submit'){
	
 $valid = validmess($_POST['commodity'], "Commodity"); if(isset($valid) && $valid != ''){ $error[] = $valid;}
 $valid = validmess($_POST['origin'], "Origin"); if(isset($valid) && $valid != ''){ $error[] = $valid;}

}

?>
<script type="text/javascript" src="citySelection.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/
ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="JqueryLoader.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.5/mootools-yui-compressed.js"></script>


<script>
function change_origin1(val) {
	if(val=='Indian') {
		document.getElementById('area').style.display='';
		document.getElementById('port').style.display='none';
        document.getElementById('area1').style.display='';
		document.getElementById('port1').style.display='none';
	}
	else {
		document.getElementById('area').style.display='none';
		document.getElementById('port').style.display='';
        document.getElementById('area1').style.display='none';
		document.getElementById('port1').style.display='';	
	}
}

function changeCommudity(val){
   if(val=='Coal') {
		document.getElementById('coalselection').style.display='';
		document.getElementById('noncoalselection').style.display='none';
		document.getElementById('noncoalselection1').style.display='none';
		document.getElementById('noncoalselection2').style.display='none';
	}
	else {
		document.getElementById('coalselection').style.display='none';
		document.getElementById('noncoalselection').style.display='';
		document.getElementById('noncoalselection1').style.display='';
		document.getElementById('noncoalselection2').style.display='';		
	}
}
</script>




        <div class="workarea">

            <div class="workareatop">

                <img src="images/workareatopcorner_03.PNG" alt="" />

            </div>

            

            <div class="workareamid">

                <div id="floatleft" style="width:590px; float:left;">

                    <div class="welcomediv">

                        <h2>Fuel as per Specifications</h2>
<div class="err_msg"><?php ShowError($error); ShowInfo($info);?></div>
<?php
if(isset($_GET['page'])) { ?>
<div style="float:right;margin-right:10px;"><a href="spec.php" style="color:blue;">Back to Search</a></div>
<?php } ?>
<div class="contactform">
<div <?php if(isset($_GET['page'])) { ?>style="display:none;"<?php } ?>>
<form name="contact" method="POST" action="">
<div id="preloader" style="margin-top:80px;"><img src="ajax-loader.gif"  style="border:none;"/></div>
    <table>
  <tr>
    <tr>
        <td class="formtxt">Commodity*</td>
        <td><select name="commodity" class="txt_box2" onChange="changeCommudity(this.value)">

					<option value="">Select</option>

<?php 

$obj1 = new DBClass();

$sql2 = "SELECT DISTINCT(commodity) as commodity FROM coal_listing where `commodity`!='' order by commodity ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['commodity'];?>"><?php echo $row2['commodity'];?></option>

<?php } ?>

				</select></td></tr>
                
    <tr>
        <td class="formtxt">Origin*</td>
        <td><select name="origin" id="origin" class="txt_box2" onchange="change_origin1(this.value)">

					<option value="">Select</option>

<?php 

$obj1 = new DBClass();

$sql2 = "SELECT DISTINCT(origin) as origin FROM coal_listing where `origin`!='' order by origin ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['origin'];?>"><?php echo $row2['origin'];?></option>

<?php } ?>

				</select></td>
    </tr>
    <tr id="coalselection" <?php if(($_POST['commodity'] != 'Coal') || ($_POST['origin']=='')){ ?> style="display:none"<?php } ?>>
        <td class="formtxt"><span id="area1" <?php if($_POST['origin']=='Imported') { ?> style="display:none"<?php } ?>>Area/Mines</span><span id="port1" <?php if($_POST['origin']!='Imported') { ?> style="display:none"<?php } ?>>Port</span></td>
        <td><span id="area" <?php if($_POST['origin']=='Imported') { ?> style="display:none"<?php } ?>><select name="area" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT DISTINCT(area) as area FROM coal_listing where `area`!='' order by area ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['area'];?>" <?php if($_POST['area'] == $row2['area']) echo 'selected'; ?>><?php echo $row2['area'];?></option>

<?php } ?>

				</select></span><span id="port" <?php if($_POST['origin']!='Imported') { ?> style="display:none"<?php } ?>><select name="mines" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT DISTINCT(port) as port FROM coal_listing where `port`!='' order by port ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['port'];?>" <?php if($_POST['mines'] == $row2['port']) echo 'selected'; ?>><?php echo $row2['port'];?></option>

<?php } ?>

				</select></span></td>
    </tr>
	<tr id="noncoalselection" <?php if(($_POST['commodity'] == 'Coal') || ($_POST['commodity'] == '')) { ?> style="display:none"<?php } ?>>
	<td>State</td>				
	<td>
	<select name="noncoal_state" class="txt_box2" id="noncoal_state">
		<option value="">Select</option>
		
	<?php 

$sql2 = "SELECT DISTINCT(noncoal_state) as noncoal_state FROM coal_listing where `noncoal_state`!='' order by noncoal_state ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['noncoal_state'];?>" <?php if($_POST['noncoal_state'] == $row2['noncoal_state']) echo 'selected'; ?>><?php echo $row2['noncoal_state'];?></option>

<?php } ?>
	</select>
	</td>
</tr>
<tr id="noncoalselection1" <?php if(($_POST['commodity'] == 'Coal') || ($_POST['commodity'] == '')) { ?> style="display:none"<?php } ?>>
	<td>District</td>	
	<td>
	<select name="noncoal_district" class="txt_box2" id="noncoaldistrict">
		<option value="">Select</option>
	</select>
	</td>
</tr>
    <tr>
        <td class="formtxt">Size</td>
        <td><select name="size" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='size' and `value`!='' and `status`=0 ORDER BY value ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['size'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td></tr><tr>
        <td class="formtxt">GCV (A.D.Basis)</td>
        <td><select name="gcv" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='gcv' and `value`!='' and `status`=0 ORDER BY id ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['gcv'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
    </tr>
    <tr>
        <td class="formtxt">Total Moisture(A.R.Basis)</td>
        <td ><select name="tm" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='tm' and `value`!='' and `status`=0 ORDER BY id ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['tm'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td></tr><tr>
        <td class="formtxt">ASH(A.D.Basis)</td>
        <td><select name="ash" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='ash' and `value`!='' and `status`=0 ORDER BY id ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['ash'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td>
    </tr>
    <tr>
        <td class="formtxt">Sulphur</td>
        <td><select name="sulpher" class="txt_box2">

					<option value="">Select</option>

<?php 

$sql2 = "SELECT * FROM ".TBL_OPTIONS." where `option`='sulpher' and `value`!='' and `status`=0 ORDER BY id ASC";

$rs2 = $obj1->executeQry($sql2,$link);

while($row2 = $obj1->fetchrow()){ 

?>          

					<option value="<?php echo $row2['value'];?>" <?php if($_POST['sulpher'] == $row2['value']) echo 'selected'; ?>><?php echo $row2['value'];?></option>

<?php } ?>

				</select></td></tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
        <td align="right"><input type="submit" name="submit" class="login_btn" value="Submit" /></td>
		        <td align="right"><input type="reset" name="reset" class="login_btn" value="Reset" /></td>
    </tr>
</table>
</form>
</div>
<?php 

//print_r($_POST);
if($error == ''){ 

$con = "";	
if($_POST['commodity']!='') {
	$con = " AND commodity = '".$_POST['commodity']."' ";	
}
if($_POST['size']!='') {
	$con .= " AND size = '".$_POST['size']."' ";	
}
if($_POST['origin']!='') {
	$con .= " AND origin = '".$_POST['origin']."' ";	
}

if($_POST['area']!='' && $_POST['origin']=='Indian') {
	$con .= " AND area = '".$_POST['area']."' ";	
}
if($_POST['mines']!='' && $_POST['origin']=='Imported') {
	$con .= " AND port = '".$_POST['mines']."' ";	
}

if($_POST['noncoal_state']!='') {
	$con .= " AND noncoal_state = '".$_POST['noncoal_state']."' ";	
}
if($_POST['noncoal_district']!='') {
	$con .= " AND noncoal_district = '".$_POST['noncoal_district']."' ";	
}

if($_POST['gcv']!='') {
	$con .= " AND gcv = '".$_POST['gcv']."' ";	
}

if($_POST['tm']!='') {
	$con .= " AND tm = '".$_POST['tm']."' ";	
}

if($_POST['ash']!='') {
	$con .= " AND ash = '".$_POST['ash']."' ";	
}

if($_POST['sulpher']!='') {
	$con .= " AND sulpher = '".$_POST['sulpher']."' ";	
}

$adjacents = 5;

$tbl_name="coal_listing";

$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE `id`!='' $con";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

$targetpage = "spec.php";

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

$sql = "SELECT * FROM $tbl_name WHERE `id`!='' $con 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()) { 
							
							$sql9 = "SELECT * FROM ".TBL_THEME." WHERE memberID = '".$row['memberID']."'";
							$rs2 = $obj9->executeQry($sql9,$link);
							$row9 = $obj9->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 $row['person_name'].' ('.$row['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="2" 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"><b>Address</b></td>
          				<td class="contain"><?php echo $row['address'];?>, <?php echo $row['district'];?>, <?php echo $row['state'];?> - <?php echo $row['pincode'];?></td>
          			</tr>
          			<tr>
          				<td class="contain"><b>Phone</b></td>
          				<td class="contain"><?php echo $row['phone'];?></td>
          			</tr>
          			<tr>
          				<td class="contain"><b>Fax</b></td>
          				<td class="contain"><?php echo $row['fax'];?></td>
          			</tr>
          			<tr>
          				<td class="contain"><b>Mobile</b></td>
          				<td class="contain"><?php echo $row['mobile1'];?>, <?php echo $row['mobile2'];?></td>
          			</tr>
          			<tr>
          				<td class="contain"><b>Email</b></td>
          				<td class="contain"><?php echo $row['email1'];?>, <?php echo $row['email2'];?></td>
          			</tr>
          			<tr>
          				<td class="contain"><b>Website</b></td>
          				<td class="contain"><?php echo $row['website'];?></td>
          			</tr>
					 <tr>
						<td colspan="2"><span style="text-align:right !important; float:right"><a href="showListing.php?memberID=<?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">More Details</a></span></td>
		</tr>
		</table>
		</td>
		</tr>		
		</table>
 	</td>
 	</tr>
<p>&nbsp;</p>
 </table>



							<?php 
							$i++;
							}?> <br /><br />
                            <?php } else { ?>
                            <table>
    <tr>
        <td>Record not found</td>
    </tr>
</table> <?php } ?>
<br /><?php } ?>
<table width="100%" align="center" cellpadding="0" cellspacing="0">
	<tr>
      	<td align="center" width="100%"><?php echo $pagination; ?></td>
    </tr>                   
</table>   
</div>







                        <div style="clear:both;"></div>

                    </div>

                </div>

                

                <?php require_once(INCLUDES_DIR.'left_bar.php');?>

                <div style="clear:both;"></div>

            </div>

            

            <div class="workareabottom">

                <img src="images/workareabottomcorner_03.PNG" alt="" />

            </div>

        </div>

<?php require_once(INCLUDES_DIR.'footer.php');?>