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

if ($moduleCheckData['status']==1){
?>  <section class="tp-appoint-cta-area yellow-dark-bg pt-80 pb-65" id="offerSection">
            <div class="container">
                <div class="row align-items-center custom-mar-20">
                    <div class="col-xl-2 col-lg-12 custom-pad-20">
                        <div class="tp-appoint wow fadeInUp" data-wow-delay=".1s">
                            <h4 class="tp-appoint-title"><?php echo $langArray['OFFER_HEAD']; ?> </h4>
                        </div>
                    </div>
                    <div class="col-xl-8 col-lg-9 custom-pad-20">
                         <form method="post" action="">
                          <div class="row align-items-center custom-mar-20">
                         
                            <div class="col-lg-3 custom-pad-20">
                                <div class="tp-appoint wow fadeInUp" data-wow-delay=".3s">
                                    <input type="text"name="offer_name" placeholder="<?= $langArray['NAME_SURNAME']; ?>">
                                </div>
                            </div>
                            <div class="col-lg-3 custom-pad-20">
                                <div class="tp-appoint wow fadeInUp" data-wow-delay=".5s">
                                    <input type="text" name="offer_phone" placeholder="<?= $langArray['PHONE']; ?>">
                                </div>
                            </div>
                            <div class="col-lg-3 custom-pad-20">
                                 <div class="g-recaptcha" data-sitekey="<?php echo $generalSettingCheck['site_recap_sitekey']; ?>"></div>
                            </div>

                            <div class="col-lg-3 custom-pad-20">
                                <div class="tp-appoint select-field-arrow wow fadeInUp" data-wow-delay=".7s">
                                    <select>
                                       <?php
                    $postAsk->execute(array(
                      'post_type' => 'post_services',
                      'language'  => $getLangCheck['language_id']
                    ));
                    while ($offerServices=$postAsk->fetch(PDO::FETCH_ASSOC)) {
                  ?>
                    <option value="<?= $offerServices['post_id'] ?>"><?= $offerServices['title'] ?></option>
                 <?php } ?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xl-2 col-lg-3 custom-pad-20">

                            
                        <div class="tp-appoint text-end wow fadeInUp" data-wow-delay=".9s">
                            <input type="submit" name="offerAdd" value="Gönder" class="btn-style-four">
                        </div>
                    </div>
                     <?php
            if(isset($_POST['offerAdd'])){
              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
                $offerAdd=$db->prepare("INSERT INTO offer SET
                  ip=:ip,
                  offer_name=:offer_name,
                  offer_phone=:offer_phone,
                  offer_email=:offer_email,
                  offer_services=:offer_services,
                  status=:status
                ");
                $insert=$offerAdd->execute(array(
                  'ip' => $ip_adresi,
                  'offer_name' => strip_tags($_POST['offer_name']),
                  'offer_phone' => strip_tags($_POST['offer_phone']),
                  'offer_email' => strip_tags($_POST['offer_email']),
                  'offer_services' => strip_tags($_POST['offer_services']),
                  '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['offer_name'];;
                  $mail->AddAddress($generalSettingCheck['site_email']);
                  $mail->Subject  = $langArray['MSG_HEAD_OFFER'];
                  $mail->IsHTML(true);
                  $mail->Body     =  $langArray['MSG_CONTENT_OFFER'];
                  if(!$mail->Send()){
                      echo "Mesaj Gönderilemedi";
                      echo "Mailer Error: " . $mail->ErrorInfo;
                      exit;
                  }
                  echo '
                  <div class="row">
                    <div class="col-sm-12">
                      <span class="alert alert-success block">'.$langArray['ACCEPT_OFFER'].'</span>
                    </div>
                  </div>
                  ';
                }else{
                  echo '
                  <div class="row">
                    <div class="col-sm-12">
                      <span class="alert alert-success block">'.$langArray['ACCEPT_ERROR'].'</span>
                    </div>
                  </div>
                  ';
                }
              }else{
                echo '
                <div class="row">
                  <div class="col-sm-12">
                    <span class="alert alert-danger block">'.$langArray['VERIFICATION_ERROR'].'</span>
                  </div>
                </div>
                ';
              }
            }
          ?>
                    </form>
                </div>
            </div>
        </section>
  
<?php } ?>
