<link href="css/tender_project.css" rel="stylesheet" type="text/css" />
<?php

function GetFieldValue($table,$condition,$field)
{
  	 global $db;
   	 $sql=DB_query("select ".$field." from ".$table." where $condition",$db);
	 $r=DB_fetch_array($sql);

   	return ($r[$field]);
}

//include('includes/function_lib.php');
	if($_REQUEST['action']=='delete' && !empty($_REQUEST['scon']))
	{
		if($s->DeleteRecord('sub_contractor_definition',"id=".$_REQUEST['scon']))
		{
						
			$_SESSION['success_msg']="Delete Successfully";	
			echo "<script>location.href='index.php?route=PMS/Maintenance/Contractor_Definition_index&modid=".$_REQUEST['modid']."&frmid=".$_REQUEST['frmid']."'</script>";	
		}
	}

?>
<?php
if($_REQUEST['search']!='')
{
	//print_r($_REQUEST);
	$filter = array();
	
	if(isset($_REQUEST['categoryname']) && $_REQUEST['categoryname'] != '')
			
	$filter[]="sub_contractor_definition.contractor_category='".$_REQUEST['categoryname']."'";
	if(isset($_REQUEST['contractor']) && $_REQUEST['contractor'] != '')
			
	$filter[]="sub_contractor_definition.contractor_name='".$_POST['contractor']."'";
	$filter1 = implode("and ",$filter); 
	if($filter1!='')
			{
				$sql="select * from sub_contractor_definition where $filter1";
			}
			else
			{
				$masg="No Record Found.";
				
			}
	
}
else
{
	 $sql = "SELECT * FROM sub_contractor_definition";
				
}
?>


<link rel="stylesheet" type="text/css" href="SubContractors/css/paginate.css" />

<style>
.label{
background-color: #B7B7B7;
    color: #000000;
    font-size: 10.5px;
    font-weight: bold !important;
    padding: 5px 10px;
    text-align: left;
}



</style>


<div class="tender_main_page">
<h1> Contractor Definition</h1>
<form action="" method="post">
<table width="75%" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <!--<td><strong>Category Code</strong></td>-->
    <!--<td><select name="categoryname">
		<option value="">Select Category Code</option>
		<?php
		$sqlcategory=DB_query("select * from tbl_subcontractor_contractor_category",$db);
		while($category_row=DB_fetch_array($sqlcategory))
		{
				$s='';
				if($_REQUEST['categoryname']==$category_row['id'])
				$s="selected";
		?>
		 <option value="<?php echo $category_row['id'];?>" <?php echo $s;?>><?php echo $category_row['Contractor_category_name'];?></option>
		<?php } ?>
	</select>
	</td>-->
    <td>Contractor Name</td>
    <td><input type="text" name="contractor"/></td>
    <td><input type="submit" name="search" value="Search" /><input type="reset" value="Reset" name="reset" /></td>
  </tr>
</table>
</form>

<div id="tableContainer" class="tableContainer">

<table class="scrollTable" width="100%" border="1" cellpadding="0" cellspacing="3">

	<tr>
		<td class="tabledata">Contractor Name</td>
		<td class="tabledata">Contractor Code </td>
		<td class="tabledata">State</td>
		<td class="tabledata">Location</td>
		<td class="tabledata">Delete</td>
		
	</tr>
	
	<?php 
          	
			$rpp = 10; // results per page
			$adjacents = 5;
			
			$page = intval($_GET["page"]);
			if($page<=0) $page = 1;
			
			$reload ="index.php?route=PMS/Maintenance/Contractor_Definition_index".$rurl;
			
			
			// select appropriate results from DB:
			
			
			//$sql = "SELECT * FROM sub_contractor_definition";
			$result =DB_query($sql,$db);
			
			// count total number of appropriate listings:
			$tcount = DB_num_rows($result);
			
			// count number of pages:
			$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
			
			$count = 0;
			$i = ($page-1)*$rpp;
			while(($count<$rpp) && ($i<$tcount)) {
				DB_data_seek($result,$i);
				$query = DB_fetch_array($result);
				extract($query);
	
	?>
		
	<tr bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#fffeb3'; this.style.color='#00f';" onMouseOut="this.style.backgroundColor='#FFF'; this.style.color='#000000';">
		<td class="tabledata1"><a href="index.php?route=PMS/Maintenance/Contractor_Definition_add<?php echo $rurl;?>&action=edit&scon=<?php echo $id; ?>" style="color:#000000"><?php echo $contractor_name; ?></a></td>
		<td class="tabledata1"> <a href="index.php?route=PMS/Maintenance/Contractor_Definition_add<?php echo $rurl;?>&action=edit&scon=<?php echo $id; ?>" style="color:#000000">
		<?php echo $contractor_category;?>
		</a>
		<?php
	
	 $state =GetFieldValue('state_master',"id='".$state."'",'state');
	  
	 $locationname =GetFieldValue('city_master',"id='".$location."'",'city');
	 
		 ?>
		</td>
		<td class="tabledata1"><a href="index.php?route=PMS/Maintenance/Contractor_Definition_add<?php echo $rurl;?>&action=edit&scon=<?php echo $id; ?>" style="color:#000000"><?php echo $state; ?></a></td>
		<td class="tabledata1"><a href="index.php?route=PMS/Maintenance/Contractor_Definition_add<?php echo $rurl;?>&action=edit&scon=<?php echo $id; ?>" style="color:#000000"><?php echo $locationname; ?></a></td>
	
		<td class="tabledata1"><a href="index.php?route=PMS/Maintenance/Contractor_Definition_index<?php echo $rurl;?>&action=delete&scon=<?php echo $id; ?>" onclick="return confirm('Are you sure you want to delete?')"> <img src="images/Icon_Delete.png" /></a></td>
	</tr>
	
	<?php  $i++;  $count++; }
	// call pagination function:

echo paginate_two($reload, $page, $tpages, $adjacents).'<br />';

 ?>
</table>
 <font color="#FF0000"><?php echo $masg; ?></font>





</div>

<p align="left" style="padding-left:10px;"><a href="index.php?route=PMS/Maintenance/Contractor_Definition_add&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>">Add New</a>
</p>

</div>


<script>
//$(document).ready(function(){
 //   $('table tr').click(function(){
    //    window.location = $(this).attr('href');
    //    return false;
   // });
//});


</script>
<?php if(isset($_SESSION['success_msg']))
{ ?>
	<script> alert("<?php echo ($_SESSION['success_msg']);?>");</script>
<?php 
unset($_SESSION['success_msg']);
}

?>



