<?php
$admin_sql=mysqli_query($GLOBALS['dbconn'],"select * from admin_details");
$admin_res=mysqli_fetch_array($admin_sql);
$referer = $_SERVER['HTTP_REFERER'];
$ip=$_SERVER['REMOTE_ADDR'];
$mobileNumber = "";

if (isset($_POST['submit-side']))
{
    $name = !empty($_POST['names'])?$_POST['names']:'';
    $email = !empty($_POST['emails'])?$_POST['emails']:'';
    $mobileNumber = (!empty($_POST['mobiles']))?$_POST['mobiles']:'';
    $locations = !empty($_POST['locations'])?$_POST['locations']:'';
    $message = !empty($_POST['messages'])?$_POST['messages']:'';
    if(strpos($locations,'#')!==false || strpos($locations,'%')!==false || strpos($locations,'@')!==false || strpos($locations,'&')!==false || strpos($locations,'~')!==false || strpos($locations,'https')!==false || strpos($locations,'http')!==false || strpos($locations,'www')!==false || strpos($locations,'?')!==false){
        $errMsgs ='URL(s) and special characters are not allowed!';
      } else { 
    
    if(strpos($message,'#')!==false || strpos($message,'%')!==false || strpos($message,'@')!==false || strpos($message,'&')!==false || strpos($message,'~')!==false || strpos($message,'https')!==false || strpos($message,'http')!==false || strpos($message,'www')!==false || strpos($message,'?')!==false){
  $errMsgs ='URL(s) and special characters are not allowed!';
} else { 
        
        if($name != '' && $email != '' && $mobileNumber != '' && $locations != '' && $message != '' && $ip != '' ){

//$qry=mysql_query($sql_ens);	
//reCAPTCHA validation
           if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

               
    //get verify response data
    $data = array( 'secret' => secret_key, 'response' => $_POST['g-recaptcha-response'] ); $verify = curl_init(); curl_setopt($verify, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify"); curl_setopt($verify, CURLOPT_POST, true); curl_setopt($verify, CURLOPT_POSTFIELDS, http_build_query($data)); curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($verify, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($verify); //var_dump($response);
    $response = json_decode($response);
    
    if (!$response->success) {
        $errMsgs = 'Please click on the reCAPTCHA box.';
    }	
    
    if($response->success) {

        $sql_ens="insert into tbl_enquiry set en_name='$name', en_email='$email', en_mobile='$mobileNumber', en_country='$locations', en_comment='$message', en_url='$referer', en_date=now()";
        $qry=mysqli_query($GLOBALS['dbconn'],$sql_ens);

        $subject = utf8_encode('Webpulseindia.com '.' - '. $admin_res['subject']);
        // $htmlContent = "
        // Customer Details:

        // Url: ".$referer."

        // Name: ".$name."

        // Email: ".$email."

        // Mobile: ".$mobileNumber."

        // Location:".$locations."

        // Message: ".$message."
        // ";
        $htmlContent =  '<table border="0" width="100%">
        <tbody>
  <tr>
    <td colspan="2">
      <strong>Dear Admin</strong></td>
  </tr>
  <tr>
    <td colspan="2">
      Enquiry Received with following info :</td>
  </tr>
  <tr>
    <td colspan="2">
      &nbsp;</td>
  </tr>
  <tr>
    <td width="26%">
      <strong>Post URL : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $referer . '</span></td>
  </tr>
   <tr>
    <td width="26%">
      <strong>Name : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $name . '</span></td>
  </tr>

  <tr>
    <td width="26%">
      <strong>Email Id : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $email . '</span></td>
  </tr>

  <tr>
    <td width="26%">
      <strong>Contact No : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $mobileNumber . '</span></td>
  </tr>

  <tr>
    <td>
      <strong>Location : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $locations . '</span></td>
  </tr>
  <tr>
    <td>
      <strong>Message : </strong></td>
    <td>
      <span style="margin-top: 15px;">' . $message . '</span></td>
  </tr>
</tbody>
       
        </table>';
        
        $to = $admin_res['email'];
        $to2 = $admin_res['cc'];
        $to3 = 'webpulseindia@gmail.com';  
        // $to3 = 'vicky.wpsranchi@gmail.com';
        // $headers = 'From: '.'Webpulseindia.com'.' enquiry@webpulseindia.com' . "\r\n" .
        // 'Reply-To:  '.$name.'<'.$email.'>' . "\r\n" .
        // 'X-Mailer: PHP/' . phpversion();
        // @mail($to,$subject,$htmlContent,$headers);
        // @mail($to2,$subject,$htmlContent,$headers);
        // @mail($to3,$subject,$htmlContent,$headers);
        if($to!='')
         {
         smtp_mailer($to, $email, $name, $subject, $htmlContent);
         }
         if($to2!='')
         {
         smtp_mailer($to2, $email, $name, $subject, $htmlContent);
         }
   
         smtp_mailer($to3, $email, $name, $subject, $htmlContent);
         
        $succMsg = 'Thank you for your enquiry. Our team will contact you soon.';
$name = '';
$email = '';
$mobileNumber = '';
$locations = '';
$message = '';    

}  
} else { $errMsgs ='Robot verification failed, please try again.';}
} else { $errMsgs ='All the fields are Mandatory!';}

}
}
}

?>
<div class="col-xxl-3 col-xl-3 col-lg-3 col-md-3 col-sm-3 col-lg-pull-9 col-md-pull-9 order-xxl-first order-xl-first order-lg-first order-md-first order-sm-first order-last">
     <div class="left_sidebar">
         <div class="left_title">Our Products</div>
         <ul>
                                    <?php
                $sql=mysqli_query($GLOBALS['dbconn'],"select * from category_tbl where parentID='0'");
                while($res=mysqli_fetch_array($sql))
                {
                ?>
                <li><a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($res['catName']);?>.htm" title="<?php echo $res['displayName']; ?> in <?= $ca_nam1;?>"><?php echo $res['displayName']; ?></a>

                <?php 
                if($res['catName']==$cat_res4[catName] || $res['catName']==$cat_res3[catName] || $res['catName']==$cat_res2[catName] || $res['catName']==$catn)
                {
                $catID=$res['catID'];
                $sql_sub=mysqli_query($GLOBALS['dbconn'],"select * from category_tbl where parentID='$catID'");
                if(mysqli_num_rows($sql_sub) > 0)
                {
                ?>

                <ul>
                <?php
                while($subres=mysqli_fetch_array($sql_sub))
                {
                $catIDs=$subres['catID'];
                $sql_subsub=mysqli_query($GLOBALS['dbconn'],"select * from category_tbl where parentID='$catIDs'");
                if(mysqli_num_rows($sql_subsub) > 0)
                {
                ?>
                <li><a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($subres['catName']);?>.htm" title="<?php echo $subres['displayName']; ?> in <?= $ca_nam1;?>"><?php echo $subres['displayName']; ?></a>
                <ul>
                <?php
                while($subsubres=mysqli_fetch_array($sql_subsub))
                {
                $catIDss=$subsubres['catID'];
                $sql_final=mysqli_query($GLOBALS['dbconn'],"select * from category_tbl where parentID='$catIDss'");
                if(mysqli_num_rows($sql_final) > 0)
                {
                ?>
                <li>
                <a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($subsubres['catName']);?>.htm" title="<?php echo $subsubres['displayName']; ?> in <?= $ca_nam1;?>"><?php echo $subsubres['displayName']; ?></a>
                <ul>
                <?php
                while($finalres=mysqli_fetch_array($sql_final))
                {
                ?>
                <li>
                <a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($finalres['catName']);?>.htm" title="<?php echo $finalres['displayName']; ?> in <?= $ca_nam1;?> "><?php echo $finalres['displayName']; ?></a>
                </li>
                <?php 
                }
                ?>
                </ul>
                </li>
                <?php 
                }
                else
                {
                ?>
                <li>
                <a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($subsubres['catName']);?>.htm" title="<?php echo $subsubres['displayName']; ?> in <?= $ca_nam1;?>"><?php echo $subsubres['displayName']; ?></a>
                </li>
                <?php
                }
                }
                ?>
                </ul>
                </li>
                <?php
                }
                else
                {
                ?>
                <li>
                <a href="<?=site_url;?>/<?=getValidFileName($ca_nam1);?>/<?=getValidFileName($subres['catName']);?>.htm" title="<?php echo $subres['displayName']; ?> in <?= $ca_nam1;?> "><?php echo $subres['displayName']; ?></a>
                </li>
                <?php
                }
                }
                ?>
                </ul>

                <?php
                }
                }
                ?>
                </li>
                <?php 
                }
                ?>
                                        </ul>
         

     </div>
     <div class="left_sidebar">

         <div class="left_title">Quick Contact</div>
         <form name="contact-form" method="post" class="quick_form" id="quick_form">
         <?php if(!empty($errMsgs)): ?><div class="alert alert-danger"><?php echo $errMsgs; ?></div><?php endif; ?>
<?php if(!empty($succMsg)): ?><div class="alert alert-success"><?php echo $succMsg; ?></div><?php endif; ?>
             <div class="form-group">
                     <input class="form-control" type="text" name="names" id="name" placeholder="Full Name*" value="<?php echo !empty($name)?$name:''; ?>" pattern="[a-z A-Z]+" required="" onkeypress="return ValidateAlpha(event)">
             </div>

             <div class="form-group">
                     <input class="form-control" type="email" name="emails" id="email" placeholder="Email ID*" value="<?php echo !empty($email)?$email:''; ?>" required>
             </div>

             <div class="form-group">
                     <input class="form-control" type="tel" name="mobiles" id="mobile" placeholder="Phone No*" maxlength="12" minlength="7" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" value="<?php echo (!empty($mobileNumber))?$mobileNumber:''; ?>" required="">
             </div>
             <div class="form-group">
                     <input class="form-control" type="text" name="locations" placeholder="Location*"  onkeypress="return ValidateAlpha(event)"  value="<?php echo !empty($locations)?$locations:''; ?>" autocomplete="off" required="">
             </div>
             <div class="form-group">
                     <textarea class="form-control" name="messages" id="message" placeholder="Message*" required><?php echo !empty($message)?$message:''; ?></textarea>
             </div>
                            <div class="form-group" style="margin-bottom:5px;">
                                <div class="g-recaptcha" data-sitekey="<?=site_key;?>"></div>
                            </div>
                        

             <div class="form-group">
                 <button class="submit_btn" type="submit" name="submit-side">Submit</button>
             </div>
         </form>
     </div>

 </div>