<?php
ob_start();
session_start();
/******************INCLUDES**********************/
include('connection/connection.php');
include_once('index.fns.php');
include_once('lib/class.user.php');
include_once('lib/class.report_handler.php');
include_once('lib/class.validate.php');
include_once 'admin_end/config.php';
include_once 'admin_end/includes/mysql.inc.php';
$frontEnd= new frontEnd;
$user= new user;
/************************************************/

$action = isset($_POST['action'])?$_POST['action']:NULL;

$company_id = $_REQUEST['company_id'];
$cat_id = $_REQUEST['cat_id'];
$level= $_REQUEST['level'];
$parent= $_REQUEST['parent'];
if($action) {
	switch ($action) {
	
		case 'register':
			$data=$_REQUEST;
			if($user->register($_POST)) {
				$frontEnd->redirect('/register.php');
			}
		break;
		default:
			echo "Invalid Action. ";
		break;
		}
	}
	
$table = "level".$level."_categories";
$qz = mysqli_query($db, "select * from companies WHERE company_id=".$company_id);
$qz1 = mysqli_query($db, "select * from  level1_categories WHERE id=".$cat_id);

if($qz)
{
	$row=mysqli_fetch_array($qz);
}
if($qz1){
	$row1=mysqli_fetch_array($qz1);
}
		
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<meta name="keywords" content="<?=$row['name']?>, <?=$row['name']?>, <?=$row['metaKeyword']?>">
<meta name="description" content="<?=$row['name']?>, <?=$row['name']?>,  <?=$row['metaDescr']?>">

<link href="css/style.css" type="text/css" rel="stylesheet" />
<link href="css/menu1.css" type="text/css" rel="stylesheet" />
<title><?php echo $row['Search']; ?></title>

<style type="text/css">
<!--
maintext {
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
color:#000000;
}
-->
</style>

<!--<script src="Scripts/scriptaculous/scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript" src="js/fading.js"></script>-->
<?php include("includes/fading.php"); ?>
</head>
<body>
<div id="main_wrap">
  <div id="main_container">
    <?php
				include("includes/index_header.php");
			?>
    <div class="blue_line"> <?php
			include("includes/menu.php");
		?></div>
   <div class="top_content">

       <?php

				include("includes/top_bar.php");

		?>

    </div>

	
    <div id="inner_content">
      <div class="left_side_content">
        <div class="search_box_content">
          <?php
			include("includes/search.php");
		?>
        </div>
        <div class="left_content">
          <?php
		

		//echo '<table border="1" style="width:750px;"><tr><td><h2>'.$row1['category_name']. ' > '.$row['name'].'</h2></td></tr>';
		$j=0;
		?>
          <table width="98%" border="0" cellspacing="0" cellpadding="5" style="margin-bottom:20px;">
            <tr>
              <td><h2><?php 
			  if($row1['category_name'] != '')
			  echo '<a href="companies.php?id='.$row1['id'].'&level='.$level.'&parent='.$row1['level1_id'].'" style="font-size:17px;">'.$row1['category_name']. '</a> > ';
			  echo $row['name']; ?></h2></td>
            </tr>
            <tr>
              <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td></td>
                    <td width="41%" rowspan="3" valign="top" style="border:1px solid #adadad; padding:10px; background-image:url(images/prBg.jpg); background-repeat:repeat-x; background-position:bottom;">&nbsp;
					<?php
					echo '<p align="justify"><span class="default_font">'.stripslashes($row['description']).'</span></p>'; 
					?>
					<?php 
					$query2='SELECT * FROM ' . $company_images_tbl . ' WHERE company_id='.$company_id.' ORDER BY image_id DESC';
					$result2=mysqli_query($db, $query2) or die('Unable to retreive images');
					$imgs=mysqli_num_rows($result2);
					if($row['CompanyPhoto'] != '') echo '<div style="float:left; clear:both; height:150px;"><img src="images/companyImages/photo/'.$row['CompanyPhoto'].'" class="img" width="250" height="150" style="margin-bottom:10px;"></div>';
					?>
					<div id="container">
					<?php if($imgs > 0) { 
					echo '<div id="images" style="margin-top:10px;float:left; clear:both;height:150px;">';
					$k=$imgs;
					while($rowimg=mysqli_fetch_array($result2)) {
						$thumbsize=250;					
$imgfile = "images/companyImages/gallery/".$rowimg['image_name'];
list($width, $height) = getimagesize($imgfile);
 $x=$width-$height;
if($x>0 and $x>150)
{

$newwidth=250;
$height=($height/$width)*$newwidth;

}
elseif($x>(-150) and $x<0)
{

$newwidth=100;
$height=($height/$width)*$newwidth;

}
elseif($x==0)
{

$newwidth=150;
$height=($height/$width)*$newwidth;

}

else
{
$newwidth=180;
$height=($height/$width)*$newwidth;
}
			
					?>
                <div style="width:250px; height:150px;" >
                   <img src="images/companyImages/gallery/<?php echo $rowimg['image_name']; ?>" alt="" width="<?php echo $newwidth;?>" height="<?php echo $height;?>" align="" class="img">
				   </div>
			
					<?php 
					$k--;
					} 
					echo '</div>';
					}
					?>
					</div>
					<?php
					if($row['GoogleMapCode'] != '') {
						echo '<p><div style="margin-top:260px;clear:both; float:left;"><strong>Find Ous</strong>';
						echo ''.stripslashes($row['GoogleMapCode']).'</div></p>'; 
					}
					if($row['LocationImage'] != '') {
						echo '<p><div style="margin-top:10px; clear:both; float:left; clear:both;height:170px;"><strong>';
							if($row['Location']!='')
							{
							echo $row['Location'];
							}
							else
							{
							echo "Our Location";
							}
						echo '</strong>';
						?>
						
<script language="Javascript">
   function PopupPic(sPicURL) {
     window.open( ""+sPicURL, "",  
     "resizable=1,HEIGHT=250,WIDTH=250");
	 
   }
   </script>
   
   
					<img src="images/companyImages/location/<?=$row['LocationImage']?>" alt="" width="250" height="150" class="img" onclick="PopupPic('images/companyImages/location/<?=$row['LocationImage']?>')" style="cursor:pointer">
</div></p>'; 
<?
					}
					?>
					</td>
                    <td width="35%" rowspan="3" valign="top" style="border:1px solid #adadad; padding:10px; background-image:url(images/prBg.jpg); background-repeat:repeat-x; background-position:bottom; border-left:0px;">&nbsp;
					
					<?php 
					$prquery='SELECT * FROM products WHERE company_id='.$company_id;
					$prresult=mysqli_query($db, $prquery) or die('Unable to retreive products');
					$prrows=mysqli_num_rows($prresult);


					if($prrows > 0) {
						echo '<div style="background-color:#0772b5; border:1px solid #0772b5;margin-bottom:10px;"><img src="images/buy_now.jpg" alt="buy now" width="50" height="38" align="middle" /><a href="categories.php?id='.$company_id.'&level='.$level.'&category_id='.$cat_id.'&parent='.$parent.'" style="font-size:12px; color:#ffffff; text-decoration: blink;">&nbsp;&nbsp;&nbsp;&nbsp;Click here to order online</a></div>';
					}
					?>
					<script language="JavaScript" src="admin_end/admin/sms/md5.js"></script>
	  <script type="text/javascript">
	  function sendSMS() {
	  	document.getElementById("smsBox").style.display='block';
	  }
	  
	  function validate() {
		var v = document.getElementById("frmsendSMS");
		//alert(v);
		var errors='';
		if(v.Content.value == '' || v.Sender.value =='') {
			errors = "Enter the required fields\n";
		}
		if(v.Sender.value != "" && v.Sender.value.length != 8){
		alert("Mobile should be only 8 digits. Please exclude the country code");
		return false;
		}
		if(v.Sender.value != '' &&  ((v.Sender.value).substr(0, 3) == 965)) {
			alert("Please exclude the country code");
			return false;
		}
	
		if(errors != '') alert(errors);
		if(errors) {
			return false;
		} else {
			//document.getElementById("Hash").value = hex_md5(document.getElementById("Password").value);
			//alert(document.getElementById("Hash").value);
			v.submit();
		}
		
	}
	  </script>
        
		<?php if($row['expand_company']=='Yes')
		{
		$row_form_style=$row['form_style'];
		$row_company_id=$row['company_id'];
		 ?>
		<div style="width:150px;  padding:5px;">
		 
		
		 <a href="expand/<?php echo $row['form_style'];?>/index.php?company_id=<?php echo $row['company_id'];?>&form_style=<?php echo $row['form_style'];?>&cat_id=<?php echo $cat_id;?>&level=<?php echo $level;?>&parent=<?php echo $parent;?>" target="_blank"><img src="images/deatiled_page.gif" border="0" /></a></div>

		<?php 
		}
		 ?>
		 <br />
		
		<div style="width:150px; background-color:#FFCC33; padding:5px;"> <a href="#" onclick="sendSMS();"><img src="images/sendSms.jpg" alt="send sms" border="0"  /></a></div>
		<div id="smsBox" style="display:<?php if($_SESSION['user_id']!=''){echo '';} else echo 'none'; ?>; margin-bottom:10px;">
		<?php
		$query_string = $_SERVER['QUERY_STRING'];
		if(!isset($_SESSION['user_id'])) {
			echo '<div style="width:150px; background-color:#FFCC66; border-top:2px solid #333333; padding:5px; margin-top:5px;"><h2 style="color:#333333;">Please login first to send sms. <a href="login.php?url=detailA.php?'.urlencode($query_string).'" style="font-size:18px;">Click here</a> to login</h2></div>';
		} else {
			$userData = $user->getUserById($_SESSION['user_id']);
			//print_r($userData);
			$user_name = $userData->firstName.' '.$userData->lastName;
			$user_mobile = $userData->mobile;
			if(!$userData->active == 1) {
				echo 'Your account is not yet activated. Please activate your account by visiting the activation link sent to your email address and then trying SMS';
			} else {
			?>
				<form name="frmsendSMS" id="frmsendSMS" action="send_sms.php" method="post" onSubmit="return validate();"> 
				<input type="hidden" name="url" value="<?php echo 'detailA.php?'.$query_string; ?>" />
				<input type="hidden" name="Recipient" value="<?php echo $row['MobileNo1']; ?>" />
				<input type="hidden" name="company_id" value="<?php echo $company_id; ?>" />
				<input type="hidden" name="UserName" value="<?php echo $user_name; ?>" />
				
				<input type="hidden" name="Format" value="1" />
				<input type="hidden" name="SendOn" value="60" />
				<input type="hidden" name="Notification" value="0" />
				Mobile No:<br />965 - <input type="text" name="Sender" value="<?php echo $user_mobile; ?>" readonly="1" /><small style="color:red">* <br />(without country code)</small>
				<br />Text: <small style="color:red">*</small><br /><textarea name="Content"></textarea>
				<input type="submit" name="send" value="send" />
				</form>
			<?php } 
		}
		?></p></div>
					<?php
					if($row['ProductCatalogue'] != '') {
						echo '<div align="justify" style="border-bottom:1px solid #61a7d8;"><br><img border="0" src="images/bul.jpg" ><span class="default_font">'.stripslashes(nl2br($row['ProductCatalogue'])).'</span></div></p>'; 
					}
					if($row['SupplierList'] != '')
					{
						echo '<div align="justify" style="border-bottom:1px solid #61a7d8;"><br><img border="0" src="images/bul.jpg" ><span class="default_font">'.stripslashes($row['SupplierList']).'<span></div></p>'; 
					}
					?>
					<p>
					  
					</td>
                  </tr>
                 
                  <tr>
                    <td valign="top" style="font-size:11px;" class="maintext"><?php 
					if($row['CompanyLogo'] != '') {
						echo '<div><img src="images/companyImages/logo/'.$row['CompanyLogo'].'" width="180" class="img"></div>'; 
					}
					$quer3y='SELECT * FROM comp_social_link WHERE companyid="'.$row['company_id'].'"';
$resul2t=mysqli_query($db, $quer3y) or die('Unable to retreive images');
while($ro2w=mysqli_fetch_array($resul2t)) 
{
 
if($ro2w['link1_logo'] !='') 
 {
$check_head1=explode("../../",$ro2w['link1_logo']);
 
 echo '<a target="_blank" href="'.$ro2w['link1'].'"><img src="'.$check_head1[1].'"   border="0" /></a>';
 }
 if($ro2w['link2_logo'] !='') 
 {
 $check_head2=explode("../../",$ro2w['link2_logo']);
 echo '<a target="_blank" href="'.$ro2w['link2'].'"><img src="'.$check_head2[1].'"   border="0" /></a>';
 }
 if($ro2w['link3_logo'] !='') 
 {
  $check_head3=explode("../../",$ro2w['link3_logo']);
 echo '<a target="_blank" href="'.$ro2w['link3'].'"><img src="'.$check_head3[1].'"  border="0" /></a>';
 }
} 
					?>
					
					<br /><br /><br /><?php 
	if($row['ContactPerson1'] != '' || $row['ContactPerson2'] != '' || $row['ContactPerson3'] != '') 
	echo '<strong style="color:#0000FF;font-size:12px;">Contact Persons:</strong><br>';
			if($row['ContactPerson1'] != '') echo $row['ContactPerson1'].'<br>';
			if($row['ContactPerson2'] != '') echo $row['ContactPerson2'].'<br>';
			if($row['ContactPerson3'] != '') echo $row['ContactPerson3'].'<br>';
  
			if($row['AdressLine1'] != '' || $row['AdressLine2'] != '' || $row['AdressLine3'] != ''  || $row['AdressLine4'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Address:</strong><br>';
			if($row['AdressLine1'] != '') echo $row['AdressLine1'].'<br>';
			if($row['AdressLine2'] != '') echo $row['AdressLine2'].'<br>';
			if($row['AdressLine3'] != '') echo $row['AdressLine3'].'<br>';
			if($row['AdressLine4'] != '') echo $row['AdressLine4'].'<br>';
			
			if($row['LocationAdressLine1'] != '' || $row['LocationAdressLine2'] != '' || $row['LocationAdressLine3'] != ''  || $row['LocationAdressLine4'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Location:</strong><br>';
			if($row['LocationAdressLine1'] != '') echo $row['LocationAdressLine1'].'<br>';
			if($row['LocationAdressLine2'] != '') echo $row['LocationAdressLine2'].'<br>';
			if($row['LocationAdressLine3'] != '') echo $row['LocationAdressLine3'].'<br>';
			if($row['LocationAdressLine4'] != '') echo $row['LocationAdressLine4'].'<br>';
			if($row['phone_hide']=='0')
			{
			if($row['PhoneNo1'] != '' || $row['PhoneNo2'] != '' || $row['PhoneNo3'] != ''  || $row['PhoneNo4'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Phone Nos:</strong><br>';
			if($row['PhoneNo1'] != '') echo $row['PhoneNo1'].'<br>';
			if($row['PhoneNo2'] != '') echo $row['PhoneNo2'].'<br>';
			if($row['PhoneNo3'] != '') echo $row['PhoneNo3'].'<br>';
			if($row['PhoneNo4'] != '') echo $row['PhoneNo4'].'<br>';
			}
			if($row['FaxNo1'] != '' || $row['FaxNo2'] != '' || $row['FaxNo3'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Fax Nos:</strong><br>';
			if($row['FaxNo1'] != '') echo ''.$row['FaxNo1'].'<br>';
			if($row['FaxNo2'] != '') echo ''.$row['FaxNo2'].'<br>';
			if($row['FaxNo3'] != '') echo ''.$row['FaxNo3'].'<br>';
			
			if($row['mobile_hide']=='0')
			{
			if($row['MobileNo1'] != '' || $row['MobileNo2'] != '' || $row['MobileNo3'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Mobile Nos:</strong><br>';
			if($row['MobileNo1'] != '') echo ''.$row['MobileNo1'].'<br>';
			if($row['MobileNo2'] != '') echo ''.$row['MobileNo2'].'<br>';
			if($row['MobileNo3'] != '') echo ''.$row['MobileNo3'].'<br>';
			}
			if($row['EmailAddress1'] != '' || $row['EmailAddress2'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Email:</strong><br>';
			if($row['EmailAddress1'] != '') echo '<a href="mailto:'.$row['EmailAddress1'].'" target="_blank" style="font-size:11px;">'.$row['EmailAddress1'].'</a><br>';
			if($row['EmailAddress2'] != '') 
			echo '<a href="mailto:'.$row['EmailAddress2'].'" target="_blank" style="font-size:11px;">'.$row['EmailAddress2'].'</a><br>';
			
			if($row['WebsiteAddress'] != '') 
			echo '<br><strong style="color:#0000FF;font-size:12px;">Website:</strong><br>';
			if($row['WebsiteAddress'] != '') echo '<a href="http://'.$row['WebsiteAddress'].'" target="_blank">'.$row['WebsiteAddress'].'</a>'.'<br>';
		
		
	if($row['company_profile']!= '') 
	{
	?>	<br>
		<a style="color:#000000; font-size:11px;" href="download_profile.php?path=<?php echo $row['company_profile'];?>&parent=<?php echo $parent;?>&level=<?php echo $level;?>&cat_id=<?php echo $cat_id;?>&company_id=<?php echo $company_id;?>&comid=<?php echo $row['company_id'];?>" >&nbsp;<?php if($row['label_profile']!='') 
		echo '<img src="images/download_icon.jpg" border="0" /><br><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">'.$row['label_profile']."</span>"; 
	else 
	{
		?><img src="images/download_icon.jpg" border="0" /><br /><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">Download Our Profile&nbsp;</span></a>
		<?php 
	}	
		?><br />
		<?php
		}	
		if($row['company_product']!= '') {?>	<br />
		<a style="color:#000000; font-size:11px;" href="download_profile.php?path=<?php echo $row['company_product'];?>&parent=<?php echo $parent;?>&level=<?php echo $level;?>&cat_id=<?php echo $cat_id;?>&company_id=<?php echo $company_id;?>&comid=<?php echo $row['company_id'];?>" >&nbsp;<?php if($row['label_product']!='') echo '<img src="images/download_icon.jpg" border="0" /><br><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">'.$row['label_product']."</span>"; else {?><img src="images/download_icon.jpg" border="0" /><br /><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">Download Our Product&nbsp;</span></a><?php }		?><br />
		<?php
		}
		if($row['company_service']!= '') {?><br />	
		<a style="color:#000000; font-size:11px;" href="download_profile.php?path=<?php echo $row['company_service'];?>&parent=<?php echo $parent;?>&level=<?php echo $level;?>&cat_id=<?php echo $cat_id;?>&company_id=<?php echo $company_id;?>&comid=<?php echo $row['company_id'];?>" >&nbsp;<?php if($row['label_service']!='') echo '<img src="images/download_icon.jpg" border="0" /><br><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">'.$row['label_service']."</span>"; else {?><img src="images/download_icon.jpg" border="0" /><br /><span style="background-color:#5f892f; color:#FFFFFF; font-size:12px">Download Our Service&nbsp;</span></a><?php }		?><br /><br />
		<?php
		}
			
	 ?></td>
                  </tr>
              </table></td>
            </tr>
          </table>
        </div>
      </div>
      <div class="right_sidebar">
        <? $frontEnd->showCategories();?>
      </div>
      </div>
	  
    </div>
	<div id="useful_links">
     <?
		echo $frontEnd->getUsefulLinks();
	?>
    </div>
    <div class="footer">
       <?php include("static/footer_statistics.php"); ?>
    </div>
  </div>
</div>

</body>
</html>
