<?php

  // Language Check
  $generalSettingAsk=$db->prepare("SELECT * FROM general_setting");
  $generalSettingAsk->execute();
  $generalSettingCheck=$generalSettingAsk->fetch(PDO::FETCH_ASSOC);

  // Ask Language
  if(isset($_GET['lang'])){
    $lang = $_GET['lang'];
    $_SESSION['lang'] = $lang;
    setcookie('lang', $lang, time() + (3600 * 24 * 30));
  }elseif(isset($_SESSION['lang'])){
    $lang = $_SESSION['lang'];
  }elseif(isset($_COOKIE['lang'])){
    $lang = $_COOKIE['lang'];
  }else{
    $lang = $generalSettingCheck['site_language'];
  }

  // Get Language Ask
  $getLangAsk=$db->prepare("SELECT * FROM language WHERE country_code=:country_code");
  $getLangAsk->execute(array(
    'country_code' => $lang
  ));
  $getLangCheck=$getLangAsk->fetch(PDO::FETCH_ASSOC);

  $statusFileLangAsk=$db->prepare("SELECT * FROM language WHERE status=:status");
  $statusFileLangAsk->execute(array(
    'status' => 1
  ));
  while ($statusFileLangCheck=$statusFileLangAsk->fetch(PDO::FETCH_ASSOC)) {
    switch ($lang) {
     case $statusFileLangCheck['country_code']:
     $lang_file = "adminx/lang/".$statusFileLangCheck['country_code'].".php";
     break;
    }
  }
  include $lang_file;
  if (isset($_GET['seo_url'])) {
    $postSeoLangAsk=$db->prepare(" SELECT * FROM posts WHERE seo_url=:seo_url");
    $postSeoLangAsk->execute(array(
      'seo_url' => $_GET['seo_url']
    ));
    $postSeoLangCheck=$postSeoLangAsk->fetch(PDO::FETCH_ASSOC);
    $langAsk1=$db->prepare("SELECT * FROM language WHERE language_id=:language_id");
    $langAsk1->execute(array(
      'language_id' => $postSeoLangCheck['language']
    ));
    $lang1=$langAsk1->fetch(PDO::FETCH_ASSOC);

    $catSeoLangAsk=$db->prepare(" SELECT * FROM categories WHERE seo_url=:seo_url");
    $catSeoLangAsk->execute(array(
      'seo_url' => $_GET['seo_url']
    ));
    $catSeoLangCheck=$catSeoLangAsk->fetch(PDO::FETCH_ASSOC);
    $langAsk11=$db->prepare("SELECT * FROM language WHERE language_id=:language_id");
    $langAsk11->execute(array(
      'language_id' => $catSeoLangCheck['language']
    ));
    $lang11=$langAsk11->fetch(PDO::FETCH_ASSOC);

    if ($postSeoLangCheck>0) {
      if ($lang != $lang1['country_code']) {
        $lang = $lang1['country_code'];
         header('Location: '.$_GET['seo_url'].'?lang='.$lang.' ');
      }
    }elseif($catSeoLangCheck>0){
      if ($lang != $lang11['country_code']) {
        $lang = $lang11['country_code'];
         header('Location: '.$_GET['seo_url'].'?lang='.$lang.' ');
      }
    }
  }
  // Slider
  $sliderAsk=$db->prepare("SELECT * FROM slider WHERE language=:language ORDER BY order_sort");
  $sliderAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // Language
  $langAsk=$db->prepare("SELECT * FROM language WHERE status=:status ORDER BY order_sort");
  $langAsk->execute(array(
    'status' => 1
  ));

  // Language Posts
  $postAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language ORDER BY order_sort");

  // Type Posts
  $typePostAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language ORDER BY order_sort");

  //Get Post
  $getPostAsk=$db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url AND post_type=:post_type");

  // All Media List
  $allMediaAsk=$db->prepare("SELECT * FROM media WHERE gallery_type_id=:gallery_type_id");

  // Projects Categories
  $projectCatAsk=$db->prepare("SELECT * FROM categories WHERE categories_type=:categories_type AND language=:language AND status=:status ORDER BY order_sort");

  // Projects
  $homeProjectAsk=$db->prepare("SELECT * FROM posts WHERE language=:language AND status=:status AND home_status=:home_status AND post_type=:post_type ORDER BY order_sort");

  // Products
  $homeProductsAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language AND status=:status AND home_status=:home_status ORDER BY order_sort");

  // Products
  $productAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language AND status=:status ORDER BY order_sort");

  // Products details
  $homeProductsDetailAsk=$db->prepare("SELECT * FROM products WHERE product_post_id=:product_post_id");

  // Footer Product 3
  $footerProductsAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language AND status=:status ORDER BY post_id LIMIT 3");

  // PackCat
  $packCatAsk=$db->prepare("SELECT * FROM categories WHERE language=:language AND status=:status AND categories_type=:categories_type ORDER BY order_sort");

  // Pack
  $packAsk=$db->prepare("SELECT * FROM packets WHERE language=:language AND status=:status AND categories=:categories ORDER BY order_sort");
  $packAsk1=$db->prepare("SELECT * FROM packets WHERE language=:language AND status=:status AND packet_id=:packet_id ORDER BY order_sort");

  // Pack Features
  $packFeatureAsk=$db->prepare("SELECT * FROM packet_features WHERE language=:language AND status=:status AND categories=:categories ORDER BY order_sort");

  // Customer Comments
  $cusComAsk=$db->prepare("SELECT * FROM comments WHERE language=:language AND status=:status  ORDER BY order_sort");

  // Pack
  $counterAsk=$db->prepare("SELECT * FROM counter WHERE language=:language AND status=:status  ORDER BY order_sort");

  // Blog 10
  $homeNewsAsk=$db->prepare("SELECT * FROM posts WHERE language=:language AND status=:status AND post_type=:post_type AND home_status=:home_status ORDER BY order_sort LIMIT 10");

  // Blog 5
  $footerNewsAsk=$db->prepare("SELECT * FROM posts WHERE language=:language AND status=:status AND post_type=:post_type ORDER BY post_id LIMIT 5");

  // All Id Category List
  $allCategoriesIdAsk=$db->prepare("SELECT * FROM categories WHERE language=:language AND categories_id=:categories_id AND categories_type=:categories_type");

  // Person
  $personAsk=$db->prepare("SELECT * FROM person WHERE status=:status ORDER BY order_sort");

  // Person Social
  $personSocialAsk=$db->prepare("SELECT * FROM person_social WHERE status=:status AND personel_id=:personel_id");

  // Client Reference
  $referenceAsk=$db->prepare("SELECT * FROM reference WHERE status=:status AND language=:language ORDER BY order_sort");

  // Client Reference
  $socialAsk=$db->prepare("SELECT * FROM social WHERE status=:status ORDER BY order_sort");

  // Categories seo_url
  $categoriesDataAsk=$db->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");

  // page seo type
  $pageDataAsk=$db->prepare("SELECT * FROM posts WHERE seo_url=:seo_url AND post_type=:post_type AND language=:language");

  // All Type Category List
  $allCategoriesAsk=$db->prepare("SELECT * FROM categories WHERE language=:language AND categories_type=:categories_type");

  // Skill List
  $skillAsk=$db->prepare("SELECT * FROM skills WHERE status=:status AND language=:language");

  // ==================================
  // ========= Module Setting =========
  // ==================================

  // Modules
  $moduleAsk=$db->prepare("SELECT * FROM modules WHERE module_name=:module_name");
 
?>
