<?php 
$active = 'Directory';
$pageName = 'Directory';

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

include('hitCounter.php');

$obj = new DBClass();
$obj9 = new DBClass();
$obj5 = new DBClass();
?>
<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>


<!--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>Directory</h2>
<div id="preloader" style="margin-top:25px;margin-left:250px;"><img src="ajax-loader.gif" style="border:none;"/></div>						               
<form action="directory.php" method="POST">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td colspan="5"><div class="err_msg">Select any or all..</div></td>
				</tr>
				<tr>
					<td colspan="5">&nbsp;</td>
				</tr>
				<tr>
					<td width="20%">
						<select name="category_of_service" class="txt_box2" style="width:120px;">
								<option value="">Category of Service</option>
								<?php
									$obj1 = new DBClass();
									$sql2 = "SELECT DISTINCT(category_of_service) as category_of_service FROM ".TBL_DIRECTORY." WHERE category_of_service != '' UNION SELECT DISTINCT(category_of_service2) as category_of_service FROM ".TBL_DIRECTORY." WHERE category_of_service2 != '' UNION SELECT DISTINCT(category_of_service3) as category_of_service FROM ".TBL_DIRECTORY." WHERE category_of_service3 != ''";
									$rs2 = $obj1->executeQry($sql2,$link);
									while($row2 = $obj1->fetchrow()){ 
								?>
								<option value="<?php echo $row2['category_of_service'];?>" <?php if($_REQUEST['category_of_service'] == $row2['category_of_service']) echo 'selected'; ?>><?php echo $row2['category_of_service'];?></option>
								<?php } ?>
						</select>
					</td>
					<td width="20%">
						<select name="country" class="txt_box2" style="width:120px;" id="directoryCountry">
							<option value="">--Country--</option>
							<?php
								$obj1 = new DBClass();
								$sql2 = "SELECT DISTINCT(country) as country FROM ".TBL_DIRECTORY." order by country";
								$rs2 = $obj1->executeQry($sql2,$link);
								while($row2 = $obj1->fetchrow()){ 
							?>
							<option value="<?php echo $row2['country'];?>" <?php if($_REQUEST['country'] == $row2['country']) echo 'selected'; ?>><?php echo $row2['country'];?></option>
							<?php } ?>
						</select>
					</td>
					<td width="20%">
						<select name="state" id="directroyState" class="txt_box2" style="width:120px;">
								<option value="">--State--</option>
								<?php 
								$obj1 = new DBClass();								
								$sql2 = "SELECT DISTINCT(state) as st FROM ".TBL_DIRECTORY." order by state";								
								$rs2 = $obj1->executeQry($sql2,$link);								
								while($row2 = $obj1->fetchrow()){ 								
								?>
								<option value="<?php echo $row2['st'];?>" <?php if($_REQUEST['state'] == $row2['st']) echo 'selected'; ?>><?php echo $row2['st'];?></option>
								<?php } ?>
						</select>	
					</td>
					<td width="20%">
						<select name="city" id="directoryCity" class="txt_box2" style="width:120px;">
							<option value="">--District--</option>
						</select>
					</td>
					 <td width="20%" align="right"><input type="submit" name="submit" style="width:60px; height: 22px;" class="login_btn" value="Find" /></td>
				</tr>
		</table>
</form>
<br /><br />
<?php 
	$con = "";
	$cond = "?submit=Search";


	if($_REQUEST['category_of_service']!='') {
	$con .= " AND ( category_of_service = '".$_REQUEST['category_of_service']."' ";	
	$cond .= "&category_of_service=".$_REQUEST['category_of_service'];
	}
	
	if($_REQUEST['category_of_service']!='') {
		$con .= " OR category_of_service2 = '".$_REQUEST['category_of_service']."' ";
		$cond .= "&category_of_service2=".$_REQUEST['category_of_service'];	
	}
	
	if($_REQUEST['category_of_service']!='') {
		$con .= " OR category_of_service3 = '".$_REQUEST['category_of_service']."' )";
		$cond .= "&category_of_service3=".$_REQUEST['category_of_service'];	
	}
	if($_REQUEST['country']!='') {
		$con .= " AND country = '".$_REQUEST['country']."' ";
		$cond .= "&country=".$_REQUEST['country'];	
	}
	if($_REQUEST['state']!='') {
		$con .= " AND state = '".$_REQUEST['state']."' ";	
		$cond .= "&state=".$_REQUEST['state'];
	}
	if($_REQUEST['city']!='') {
		$con .= " AND district = '".$_REQUEST['city']."' ";
		$cond .= "&city=".$_REQUEST['city'];	
	}


$adjacents = 5;

$tbl_name=TBL_DIRECTORY;

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

$targetpage = "directory.php".$cond;

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

$sql = "SELECT * FROM $tbl_name WHERE status = '0' $con ORDER BY organisation_name ASC 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="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
			<td class="bdr1">
					<table width="100%" border="0" align="center">
							<tr>
									<td colspan="2" bgcolor="#990066" class="form_head" style="padding-left:5px"><a href="<?php echo $row9['themeID']; ?>/index.php?id=<?php echo $row['memberID']; ?>" target="_blank"><span style="font-size: small;"><b><?php echo $row['organisation_name'].' ('.$row['person_name'].')';?></b></span></a></td>
							</tr>
							  <tr class="bg_td1" <?php if($row['company_details'] == '') { ?> style="display:none;"<?php } ?>>
									<td colspan="2" class="contain"><?php echo $row['company_details'];?><hr /></td>
							  </tr>
							  <tr>
									<td width="15%"  class="contain" valign="top"><b>Service Info</b></td>
									<td width="85%" class="contain"><?php echo $row['category_of_service'].' , ' . $row['category_of_service2'].' , ' .$row['category_of_service3'] ;?></td>
							  </tr>
							  <tr>
									<td class="contain" valign="top"><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?id=<?php echo $row['memberID'] ?>">Show all product of same trader </a></span></td>
							  </tr>
					</table>
			</td>
	</tr>
    <p>&nbsp;</p>  
</table>
<?php $i++;	} 	?>
<br /><br />
<?php } else { ?>
<table>
    <tr>
        <td style="color:#D40000;">Record Not Found !</td>
    </tr>
</table>
<?php } ?>
<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');?>