<?php 
  $moduleAskData=$db->prepare("SELECT * FROM modules where module_id=:module_id");
  $moduleAskData->execute(array(
    'module_id' => 5
    ));
  $moduleCheckData=$moduleAskData->fetch(PDO::FETCH_ASSOC);

if ($moduleCheckData['status']==1){
?>
    <section class="tp-pricing-area pt-120 pb-90">
            <div class="container">
                <div class="row align-items-center">
                    <div class="col-md-8">
                        <div class="section-title-wrapper mb-55 wow fadeInUp" data-wow-delay=".2s">
                                                        <h2 class="tp-section-title"><?php echo $langArray['PRICING_HEAD']; ?></h2>
                            <h5 class="tp-section-subtitle common-yellow-shape mb-20"><?php echo $langArray['PRICING_DESC']; ?></h5>
                        </div>
                    </div>
                 
                    <div class="col-md-4">
                        <nav class="text-start text-md-end wow fadeInUp" data-wow-delay=".4s">
                              <?php
                $lineNumber=0;
                $packCatAsk->execute(array(
                  'language'        => $getLangCheck['language_id'],
                  'status'          => 1,
                  'categories_type' => 'packet_categories'
                ));
                while ($packCatCheck=$packCatAsk->fetch(PDO::FETCH_ASSOC)){
                  $lineNumber++;
              ?>
                            <div class="nav tp-pricing-tabs" id="nav-tab" role="tablist">
                              <button class="nav-link <?php echo $lineNumber == "1" ? 'active' : ''; ?>" id="nav-home-tab" data-bs-toggle="tab" data-bs-target="#nav-<?php echo $packCatCheck['categories_id']; ?>" type="button" role="tab" aria-controls="nav-home" aria-selected="true"><?php echo $packCatCheck['title']; ?></button><?php } ?>   
                              
                            </div>
                        </nav>                          
                    </div>
                </div>
                <div class="row">
                    <div class="col-12">
                        <div class="tab-content" id="nav-tabContent">
                          <?php
            $lineNumber=0;
            $packCatAsk->execute(array(
              'language'        => $getLangCheck['language_id'],
              'status'          => 1,
              'categories_type' => 'packet_categories'
            ));
            while ($packCatCheck=$packCatAsk->fetch(PDO::FETCH_ASSOC)){
              $lineNumber++;
          ?>
                            <div class="tab-pane fade <?php echo $lineNumber == "1" ? ' show active' : ''; ?>" id="nav-<?php echo $packCatCheck['categories_id']; ?>" role="tabpanel" aria-labelledby="nav-home-tab">
                                <div class="row">
                                  <?php
                 $packAsk->execute(array(
                   'language'        => $getLangCheck['language_id'],
                   'status'          => 1,
                   'categories'      => $packCatCheck['categories_id']
                 ));
                 while ($packCheck=$packAsk->fetch(PDO::FETCH_ASSOC)){
                   $packprice = $packCheck['price'];
                   $packtitle = $packCheck['title'];
                 ?>
                                    <div class="col-xl-4 col-md-6 mb-30">
                                        <div class="tp-pricing grey-bg text-center wow flipInY" data-wow-delay=".2s">
                                           
                                            <div class="tp-pricing-rate">
                                                <div class="tp-pricing-rate-inner text-center">
                                                    <h4 class="tp-pricing-rate-subtitle mb-30"><?php echo $packCheck['title']; ?></h4>
                                                    <h2 class="tp-pricing-rate-title mb-45"><?php echo $packCheck['price']; ?><span><?php echo $packCheck['currency']; ?></span></h2>
                                                </div>
                                            </div>
                                            <div class="tp-pricing-list mb-45">
                                                <ul>
                                                   <?php
                           $tags = explode(',', $packCheck['features']);
                           $a = count($tags);
                           for ($i=0; $i <$a; $i++) {
                             $packId=$tags[$i];
                             $packFeatureAsk=$db->prepare("SELECT * FROM packet_features where feature_id=$packId");
                             $packFeatureAsk->execute();
                             $packFeatureCheck=$packFeatureAsk->fetch(PDO::FETCH_ASSOC);
                         ?>
                       <li><?php echo $packFeatureCheck['title'];?></li>
                     <?php } ?>
                                                </ul>
                                            </div>
                                            <div class="tp-pricing-btn">
                                                <a data-bs-toggle="modal" data-bs-target="#pack-<?php echo $packCheck['packet_id']; ?>" class="theme-btn"><span class="txt" ><?php echo $langArray['GLOBAL_FORM_TABLE_ORDER']; ?></span></a>
                                            </div>
                                        </div>
                                    </div>  
                                     <div id="pack-<?php echo $packCheck['packet_id']; ?>" class="modal fade" role="dialog">
                   <div class="modal-dialog">
                     <div class="modal-content">
                       <div class="modal-header">
                       <h4 class="modal-title"><?php echo $packCheck['title']; ?></h4>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>                       </div>
                       <div class="modal-body">
                         <?php
                           if(isset($_POST['packetOrder'])){
                             global $packtitle;
                             global $packprice;
                             error_reporting(1);
                             require_once 'adminx/system/db.php';
                             require_once 'adminx/system/class.phpmailer.php';
                             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_packet',
                                 'order_code' => seo($_POST['title']) .'-'.mb_substr($code, 0, 5),
                                 'ip' => $ip_adresi,
                                 'product' => strip_tags($_POST['packet']),
                                 'price' => strip_tags($_POST['price']),
                                 'quantity' => 1,
                                 '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_PACKET'];
                                 $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>
                               ';
                             }
                           }
                         ?>
                         <form action="" method="POST" enctype="multipart/form-data">
                           <input type="hidden" name="packet" value="<?=$packCheck["packet_id"] ?>">
                           <input type="hidden" name="price" value="<?=$packCheck["price"] ?>">
                           <input type="hidden" name="title" value="<?=$packCheck["title"] ?>">
                           <div class="row">
                             <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="theme-btn" name="packetOrder" value="<?php echo $langArray['GLOBAL_FORM_TABLE_ORDER']; ?>">
                               </div>
                             </div>
                           </div>
                         </form>
                       </div>
                     </div>
                   </div>
                 </div><?php  }?>
                                    
                                </div>
                            </div><?php  }?> 
                          
                        </div>
                    </div>
                </div>
            </div>
        </section>

<?php } ?>
