<?php
  $getPostAsk->execute(array(
    'seo_url'    => $_GET["seo_url"],
    'post_type'  => 'post_products'
  ));
  $productDataCheck=$getPostAsk->fetch(PDO::FETCH_ASSOC);

  $productDetailAsk=$db->prepare("SELECT * FROM products WHERE product_post_id={$productDataCheck['post_id']}");
  $productDetailAsk->execute();
  $productDetailCheck=$productDetailAsk->fetch(PDO::FETCH_ASSOC);
?>
  <section class="page-title">
    <div class="pattern-layer-one" style="background-image: url(assets/images/background/pattern-14.png)"></div>
    <div class="pattern-layer-two" style="background-image: url(assets/images/background/pattern-15.png)"></div>
    <div class="auto-container">
      <h2><?php echo $productDataCheck['title']; ?></h2>
      <ul class="page-breadcrumb">
        <li>
          <a href="<?php echo $generalSettingCheck['site_url']; ?>">
            <?php echo $langArray['LINK_HOME']; ?>
          </a>
        </li>
        <?php if ($productDataCheck['post_type'] == 'post_products') { ?>
        <li>
           <a href="<?php echo $generalSettingCheck['site_url']; ?><?php echo $langArray['LINK_PRODUCT_LINK']; ?>">
             <?php echo $langArray['LINK_PRODUCT']; ?>
           </a>
        </li>
        <?php } ?>
        <?php
           if ($productDataCheck['categories'] > 0) {
             $topCategoriesAsk=$db->prepare("SELECT * FROM categories WHERE categories_id=:categories_id");
             $topCategoriesAsk->execute(array(
               'categories_id' => $productDataCheck['categories']
             ));
             $topCategoriesCheck=$topCategoriesAsk->fetch(PDO::FETCH_ASSOC);
         ?>
        <li>
          <a href="<?php echo $topCategoriesCheck['seo_url']; ?>">
            <?php echo $topCategoriesCheck['title']; ?>
          </a>
        </li>
         <?php } ?>
        <li class="active"><?php echo $productDataCheck['title']; ?></li>
      </ul>
    </div>
  </section>

    <section class="shop-single-section">
      <div class="auto-container">
            <div class="shop-page product-details">
                <div class="basic-details">
                    <div class="row clearfix">
                        <div class="image-column col-lg-7 col-md-12 col-sm-12">
                            <div class="carousel-outer">
                                <ul class="image-carousel owl-carousel owl-theme">
                                  <?php
                                      $typeandid = 'product_gallery-'.$productDataCheck['post_id'];
                                      $allMediaAsk->execute(array(
                                        'gallery_type_id'        => $typeandid
                                      ));
                                      while ($allTypeCheck=$allMediaAsk->fetch(PDO::FETCH_ASSOC)){
                                   ?>
                                    <li>
                                      <a href="<?php echo $allTypeCheck['media_full']; ?>" class="lightbox-image" title="Image Caption Here">
                                        <img style="width: 100%;" src="<?php echo $allTypeCheck['media_full']; ?>" alt="<?php echo $productDataCheck['title']; ?>">
                                      </a>
                                    </li>
                                   <?php } ?>
                                </ul>
                                <ul class="thumbs-carousel owl-carousel owl-theme">
                                 <?php
                                    $typeandid = 'product_gallery-'.$productDataCheck['post_id'];
                                    $allMediaAsk->execute(array(
                                      'gallery_type_id'        => $typeandid
                                    ));
                                    while ($allTypeCheck=$allMediaAsk->fetch(PDO::FETCH_ASSOC)){
                                  ?>
                                     <img src="<?php echo $allTypeCheck['media_full']; ?>" alt="white sample"/>
                                 <?php } ?>
                                </ul>
                            </div>
                        </div>
                        <div class="info-column col-lg-5 col-md-12 col-sm-12">
                            <div class="details-header">
                                <h2><?php echo $productDataCheck['title']; ?></h2>

                                <div class="item-price">
                                  <?php
                                    if ($productDetailCheck['discount_price'] == "") {
                                      $productDetailCheck['discount_price'] = 0;
                                    }
                                    $productVatRate = $productDetailCheck['vat'];
                                    $productPrice = $productDetailCheck['price'];
                                    $productPercentRate = $productDetailCheck['discount_price'];
                                    $disPriceRate = percentCalc($productPrice,$productPercentRate);
                                    $productDisTotal = $productPrice-$disPriceRate;
                                    if ($productVatRate>0) {
                                      $disVatResult = addVat($productDisTotal,$productVatRate);
                                      $vatResult = addVat($productPrice,$productVatRate);
                                    }else{
                                      $disVatResult = $productDisTotal;
                                      $vatResult = $productPrice;
                                    }
                                    ?>
                <?php if ($productDetailCheck['discount_price']) { ?>
                  <span><del><?php echo $vatResult; ?> <?php echo $productDetailCheck['currency']; ?></del>
                  <?php echo $disVatResult; ?> <?php echo $productDetailCheck['currency']; ?></span>
                <?php }else{ ?>
                  <span><?php echo $vatResult; ?> <?php echo $productDetailCheck['currency']; ?></span>
                <?php } ?>
              </div>
                            </div>
  <ul class="shop-list">
                            <li><strong><?php echo $langArray['HEAD_CATEGORIES']; ?> :</strong> <span><a href="<?php echo $topCategoriesCheck['seo_url']; ?>"><?php echo $topCategoriesCheck['title']; ?></a></span></li>
                <li><strong><?php echo $langArray['GLOBAL_FORM_TABLE_VAT']; ?> :</strong> <span>%<?php echo $productDetailCheck['vat']; ?></span></li>
                <?php if ($productDetailCheck['discount_price']) { ?>
                <li><strong><?php echo $langArray['GLOBAL_FORM_TABLE_DISCOUNT_PRICE']; ?> : </strong><span>%<?php echo $productDetailCheck['discount_price']; ?></span></li>
                <?php } ?>
                <?php if ($productDetailCheck['product_code']) { ?>
                <li><strong><?php echo $langArray['GLOBAL_FORM_TABLE_PRODUCT_CODE']; ?> : </strong><span><?php echo $productDetailCheck['product_code']; ?></span></li>
                <?php } ?>
                <?php if ($productDetailCheck['stock_number']) { ?>
                <li><strong><?php echo $langArray['GLOBAL_FORM_TABLE_STOCK_NUMBER']; ?> :</strong> <span><?php echo $productDetailCheck['stock_number']; ?></span></li>
                <?php } ?>
                            </ul>
                            <div class="text">
                                <p><?php echo $productDataCheck['content']; ?></p>
                            </div>

                            <div class="other-options">
                                <div class="clearfix">
                               <?php if ($productDetailCheck['order_sales'] == "order") {?>
                                    <div class="pull-left">
                                        <div class="btns-box">
                                           <a data-toggle="modal" data-target="#exampleModal" class="theme-btn btn-style-three"><span class="txt" style="color:white;"><?php echo $langArray['GLOBAL_FORM_TABLE_ORDER']; ?></span></a>
                                        </div>
                                    </div>
                                      <?php }else{ ?>
                                          <div class="pull-left">
                                        <div class="btns-box">
                                           <a href="<?php echo $productDetailCheck['other_link']; ?>" target="_blank"> <button type="button" class="theme-btn btn-style-three"><span class="txt"><?php echo $langArray['PRODUCT_BUY']; ?></span></button></a>
                                        </div>
                                    </div> <?php } ?>
                                       <div class="pull-right">
                                        <div class="btns-box">
                                           <a class="theme-btn btn-style-three" href="https://api.whatsapp.com/send?phone=<?= $generalSettingCheck['contact_whatsapp'] ?>&text=<?php echo $productDataCheck['title'] ?> &source=&data=" target="_blank">
                                              <?php echo $langArray['WHATSAPP_ORDER']; ?>
                                            </a>
                                        </div>
                                    </div>
                                 </div>
                            </div>
                                <hr>
            <div class="product-share">
              <h5 class="share-title"><?php echo $langArray['SHARE_TEXT']; ?></h5>
              <div class="a2a_kit a2a_kit_size_32 a2a_default_style">
                <a class="a2a_dd" href="https://www.addtoany.com/share"></a>
                <a class="a2a_button_facebook"></a>
                <a class="a2a_button_twitter"></a>
                <a class="a2a_button_email"></a>
                <a class="a2a_button_pinterest"></a>
                <a class="a2a_button_linkedin"></a>
                <a class="a2a_button_reddit"></a>
                <a class="a2a_button_whatsapp"></a>
              </div>
              <script>
              var a2a_config = a2a_config || {};
              a2a_config.locale = "tr";
              </script>
              <script async src="https://static.addtoany.com/menu/page.js"></script>
            </div>


                        </div>

                    </div>
                </div>

                <div class="product-info-tabs">
                    <div class="prod-tabs tabs-box">
                        <ul class="tab-btns tab-buttons clearfix">
                            <li data-tab="#content" class="tab-btn active-btn"><?php echo $langArray['ABOUT_THE_PROJECT']; ?></li>
            <?php if ($productDetailCheck['video']){?>
                            <li data-tab="#video" class="tab-btn"><?php echo $langArray['PROJECT_VIDEO']; ?></li><?php } ?>
                        </ul>

                        <div class="tabs-content">

                            <!--Tab / Active Tab-->
                            <div class="tab active-tab" id="content">
                                <div class="content">
                                    <p><?php echo $productDataCheck['content']; ?></p>
                                </div>
                            </div>

                            <?php if ($productDetailCheck['video']){?>
                            <div class="tab" id="video">
                                <div class="content">
                                    <iframe width="560" height="315" src="https://www.youtube.com/embed/<?php echo $productDetailCheck['video']; ?>" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                                </div>
                            </div>
                             <?php } ?>
                            <!--Tab-->
                            <div class="tab" id="prod-reviews">
                                <!--Reviews Container-->
                                <div class="reviews-container">

                                    <!--Review-->
                                    <div class="review-box clearfix">
                                        <figure class="rev-thumb"><img src="images/resource/author-3.jpg" alt=""></figure>
                                        <div class="rev-content">
                                            <div class="rev-header clearfix">
                                                <h4>Michel Britney</h4>
                                                <div class="rating"><span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star-o"></span> <span class="fa fa-star-o"></span></div>
                                                <div class="time">18 Hours Ago</div>
                                            </div>
                                            <div class="rev-text">The mad lightning no one you beat of just one drum they call him Flipper Flipper faster than lightning no one you see is smarter each week my friends you are sure to get a smile from seven stranded cast aways here on Gilligans Isle they call him Flipper Flipper faster.</div>
                                        </div>
                                    </div>

                                    <!--Review-->
                                    <div class="review-box clearfix">
                                        <figure class="rev-thumb"><img src="images/resource/author-4.jpg" alt=""></figure>
                                        <div class="rev-content">
                                            <div class="rev-header clearfix">
                                                <h4>Denny</h4>
                                                <div class="rating"><span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star-o"></span> <span class="fa fa-star-o"></span></div>
                                                <div class="time">18 Hours Ago</div>
                                            </div>
                                            <div class="rev-text">The mad lightning no one you beat of just one drum they call him Flipper Flipper faster than lightning no one you see is smarter each week my friends you are sure to get a smile from seven stranded cast aways here on Gilligans Isle they call him Flipper Flipper faster than lightning no one you see is smarter than he loveable space that needs your face threes company too.</div>
                                        </div>
                                    </div>

                                    <!--Add Review-->
                                    <div class="add-review">
                                        <h2>Add a Review</h2>

                                        <form method="post" action="https://expert-themes.com/html/meto/shop-single.html">
                                            <div class="row clearfix">
                                                <div class="form-group col-md-6 col-sm-12 col-xs-12">
                                                    <label>Name *</label>
                                                    <input type="text" name="name" value="" placeholder="" required>
                                                </div>
                                                <div class="form-group col-md-6 col-sm-12 col-xs-12">
                                                    <label>Email *</label>
                                                    <input type="email" name="email" value="" placeholder="" required>
                                                </div>
                                                <div class="form-group col-md-6 col-sm-12 col-xs-12">
                                                    <label>Website *</label>
                                                    <input type="text" name="website" value="" placeholder="" required>
                                                </div>
                                                <div class="form-group col-md-6 col-sm-12 col-xs-12">
                                                    <label>Rating </label>
                                                    <div class="rating">
                                                        <a href="#" class="rate-box" title="1 Out of 5"><span class="fa fa-star"></span></a>
                                                        <a href="#" class="rate-box" title="2 Out of 5"><span class="fa fa-star"></span> <span class="fa fa-star"></span></a>
                                                        <a href="#" class="rate-box" title="3 Out of 5"><span class="fa fa-star"></span> <span class="fa fa-star"> </span> <span class="fa fa-star"></span></a>
                                                        <a href="#" class="rate-box" title="4 Out of 5"><span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span></a>
                                                        <a href="#" class="rate-box" title="5 Out of 5"><span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span> <span class="fa fa-star"></span></a>
                                                    </div>
                                                </div>
                                                <div class="form-group col-md-12 col-sm-12 col-xs-12">
                                                    <label>Your Review</label>
                                                    <textarea name="review-message"></textarea>
                                                </div>
                                                <div class="form-group text-right col-md-12 col-sm-12 col-xs-12">
                                                    <button type="button" class="theme-btn btn-style-three"><span class="txt">Add Review</span></button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>

                                </div>
                            </div>
                            <!--End Tab-->

                        </div>
                    </div>

                </div>
                <!--End Product Info Tabs-->

            </div>

        </div>
    </section>
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
       <div class="modal-dialog">
         <div class="modal-content">
           <div class="modal-body">
              <form action="" method="POST" enctype="multipart/form-data">
                 <input type="hidden" name="product" value="<?=$productDataCheck["post_id"] ?>">
                 <div class="row">
                   <div class="col-md-6">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['QUANTITY']; ?></label>
                       <input type="number" name="quantity" class="form-control" value="1" required>
                     </div>
                   </div>
                   <div class="col-md-6">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['NAME_SURNAME']; ?></label>
                       <input type="text" name="name_surname" class="form-control" >
                     </div>
                   </div>
                   <div class="col-md-6">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['PHONE']; ?></label>
                       <input type="text" name="phone" class="form-control" >
                     </div>
                   </div>
                   <div class="col-md-6">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['EMAIL']; ?></label>
                       <input type="email" name="email" class="form-control" >
                     </div>
                   </div>
                   <div class="col-md-6">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['ADRESS']; ?></label>
                       <input type="text" name="adress" class="form-control" >
                     </div>
                   </div>
                   <div class="col-md-12">
                     <div class="form-group">
                       <label for="" class="control-label"><?php echo $langArray['DESCRIPTION']; ?></label>
                       <textarea name="description" class="form-control"></textarea>
                     </div>
                   </div>
                   <div class="col-md-12">
                     <div class="form-group">
                       <div class="g-recaptcha" data-sitekey="<?php echo $generalSettingCheck['site_recap_sitekey']; ?>"></div>
                     </div>
                   </div>
                   <div class="col-md-12">
                     <div class="form-group">
                       <input type="submit" class="btn btn-block btn-primary" name="productOrder" value="<?php echo $langArray['GLOBAL_FORM_TABLE_ORDER']; ?>">
                     </div>
                   </div>
                 </div>
               </form>
           </div>
             <?php
               if(isset($_POST['productOrder'])){
                 error_reporting(0);
                 require_once 'adminx/system/db.php';
                 require_once 'adminx/system/class.phpmailer.php';
                 function GetIP(){
                  if(getenv("HTTP_CLIENT_IP")) {
                    $ip = getenv("HTTP_CLIENT_IP");
                  } elseif(getenv("HTTP_X_FORWARDED_FOR")) {
                    $ip = getenv("HTTP_X_FORWARDED_FOR");
                    if (strstr($ip, ',')) {
                      $tmp = explode (',', $ip);
                      $ip = trim($tmp[0]);
                    }
                  } else {
                    $ip = getenv("REMOTE_ADDR");
                  }
                  return $ip;
                 }
                 $ip_adresi = GetIP();
                 if ($productDetailCheck['discount_price']) {
                   $price = $disVatResult;
                 }else{
                   $price = $vatResult;
                 }
                 date_default_timezone_set('Europe/Istanbul');
                 $dates = date("Y-m-d H:i:s");

                 $secretKey =  $generalSettingCheck['site_recap_secretkey'];
                 $responseKey = $_POST['g-recaptcha-response'];
                 $UserIP = $_SERVER['REMOTE_ADDR'];
                 $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$UserIP";

                 $response = file_get_contents($url);
                 $response = json_decode($response);

                 if ($response->success) {
                   // VT Ekleme
                   $haberekle=$db->prepare("INSERT INTO orders SET
                     order_type=:order_type,
                     order_code=:order_code,
                     ip=:ip,
                     product=:product,
                     price=:price,
                     quantity=:quantity,
                     name_surname=:name_surname,
                     phone=:phone,
                     email=:email,
                     adress=:adress,
                     description=:description,
                     dates=:dates,
                     status=:status
                   ");
                   $insert=$haberekle->execute(array(
                     'order_type' => 'order_product',
                     'order_code' => $productDetailCheck['product_code'] .'-'.mb_substr($code, 0, 5),
                     'ip' => $ip_adresi,
                     'product' => strip_tags($_POST['product']),
                     'price' => $price,
                     'quantity' => strip_tags($_POST['quantity']),
                     'name_surname' => strip_tags($_POST['name_surname']),
                     'phone' => strip_tags($_POST['phone']),
                     'email' => strip_tags($_POST['email']),
                     'adress' => strip_tags($_POST['adress']),
                     'description' => strip_tags($_POST['description']),
                     'dates' => $dates,
                     'status' => 0
                   ));

                   if ($insert) {
                     // Mail Gonderme
                     $mail = new PHPMailer();
                     $mail->IsSMTP();
                     $mail->Host     = $generalSettingCheck['site_smtphost'];
                     $mail->SMTPAuth = true;
                     $mail->Username = $generalSettingCheck['site_smtpuser'];
                     $mail->Password = $generalSettingCheck['site_smtppassword'];
                     $mail->CharSet = 'UTF-8';
                     $mail->Port   = $generalSettingCheck['site_smtpport'];
                     $mail->From     = $generalSettingCheck['site_smtpuser'];
                     $mail->Fromname = $_POST['name_surname'];;
                     $mail->AddAddress($generalSettingCheck['site_email']);
                     $mail->Subject  = $langArray['MSG_HEAD'];
                     $mail->IsHTML(true);
                     $mail->Body     =  $langArray['MSG_CONTENT'];
                     if(!$mail->Send()){
                         echo "Mesaj Gönderilemedi";
                         echo "Mailer Error: " . $mail->ErrorInfo;
                         exit;
                     }
                     echo '
                     <div class="col-sm-12">
                       <span class="alert alert-success block">'.$langArray['ACCEPT_ORDER'].'</span>
                     </div>
                     ';
                   }else{
                     echo '
                     <div class="col-sm-12">
                       <span class="alert alert-success block">'.$langArray['ACCEPT_ERROR'].'</span>
                     </div>
                     ';
                   }
                 }else{
                   echo '
                   <div class="col-sm-12">
                     <span class="alert alert-danger block">'.$langArray['VERIFICATION_ERROR'].'</span>
                   </div>
                   ';
                 }
               }
             ?>
         </div>
       </div>
    </div>
