<?php

  // User Check
  $askUser=$db->prepare("SELECT * FROM user WHERE email=:email");
  $askUser->execute(array(
    'email' => $_SESSION['email']
    ));
  $count=$askUser->rowCount();
  $checkUser=$askUser->fetch(PDO::FETCH_ASSOC);
  if ($count==0) {
    Header("Location:login.php");
    exit;
  }
  // Language Check
  $generalSettingAsk=$db->prepare("SELECT * FROM general_setting");
  $generalSettingAsk->execute();
  $generalSettingCheck=$generalSettingAsk->fetch(PDO::FETCH_ASSOC);

  //webmaster
  $wmAsk=$db->prepare("SELECT * FROM webmaster WHERE webmaster_id=1");
  $wmAsk->execute();
  $wmCheck=$wmAsk->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 = "lang/".$statusFileLangCheck['country_code'].".php";
     break;
    }
  }
  include $lang_file;

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

  // Check Country
  $countryAsk=$db->prepare("SELECT * FROM countries");
  $countryAsk->execute();

  // All Banks List
  $allIconAsk=$db->prepare("SELECT * FROM iconlist");
  $allIconAsk->execute();

  // All Lang List
  $allLangAsk=$db->prepare("SELECT * FROM language");
  $allLangAsk->execute();

  // All Users List
  $allUsersAsk=$db->prepare("SELECT * FROM user");
  $allUsersAsk->execute();

  // All Person List
  $allPersonAsk=$db->prepare("SELECT * FROM person");
  $allPersonAsk->execute();

  // All Person Social List
  $allPerSocialAsk=$db->prepare("SELECT * FROM person_social");
  $allPerSocialAsk->execute();

  // All BD List
  $allbdAsk=$db->prepare("SELECT * FROM branchdealer");
  $allbdAsk->execute();

  // All Banks List
  $allBanksAsk=$db->prepare("SELECT * FROM banks");
  $allBanksAsk->execute();

  // All Social List
  $allSocialAsk=$db->prepare("SELECT * FROM social");
  $allSocialAsk->execute();

  // All Categories List
  $allCatAsk=$db->prepare("SELECT * FROM categories WHERE language=:language");
  $allCatAsk->execute(array(
    'language'        => $getLangCheck['language_id']
  ));

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

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

  // All Post List
  $allPostAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");

  // All Post List
  $allPostAsk1=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND post_id=:post_id AND language=:language");


  // All Post product List
  $allPostProductAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND post_id=:post_id");

  // All customer comments List
  $allCustomerCommentAsk=$db->prepare("SELECT * FROM comments WHERE language=:language");
  $allCustomerCommentAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All slider List
  $allSliderAsk=$db->prepare("SELECT * FROM slider WHERE language=:language");
  $allSliderAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All Reference List
  $allRefAsk=$db->prepare("SELECT * FROM reference WHERE language=:language");
  $allRefAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All Catalog List
  $allCatalogAsk=$db->prepare("SELECT * FROM catalog WHERE language=:language");
  $allCatalogAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All Document List
  $allDocumentAsk=$db->prepare("SELECT * FROM document WHERE language=:language");
  $allDocumentAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All Offer List
  $allOfferAsk=$db->prepare("SELECT * FROM offer");
  $allOfferAsk->execute();

  $statusOfferAsk=$db->prepare("SELECT * FROM offer WHERE status=:status");
  $statusOfferAsk->execute(array(
    'status' => 0
  ));
  $countOffer=$statusOfferAsk->rowCount();
  // All Counter List
  $allCounterAsk=$db->prepare("SELECT * FROM counter WHERE language=:language");
  $allCounterAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // 10 project List
  $recentlyProjectAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language ORDER BY post_id DESC LIMIT 5");
  $recentlyProjectAsk->execute(array(
    'post_type'        => 'post_projects',
    'language'        => $getLangCheck['language_id']
  ));

  // 10 product List
  $recentlyProductAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language ORDER BY post_id DESC LIMIT 5");
  $recentlyProductAsk->execute(array(
    'post_type'        => 'post_products',
    'language'         => $getLangCheck['language_id']
  ));

  // All packet feature List
  $allPackFeatureAsk=$db->prepare("SELECT * FROM packet_features WHERE language=:language");

  // All packet List
  $allPackAsk=$db->prepare("SELECT * FROM packets WHERE language=:language");

  // All packet List
  $allPackAsk1=$db->prepare("SELECT * FROM packets WHERE packet_id=:packet_id");

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

  // All vGallery List
  $allvGalleryAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $allvGalleryAsk->execute(array(
    'post_type'       => 'post_vGallery',
    'language'        => $getLangCheck['language_id']
  ));

  // All iGallery List
  $alliGalleryAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $alliGalleryAsk->execute(array(
    'post_type'   => 'post_Gallery',
    'language'    => $getLangCheck['language_id']
  ));

  // All Skill List
  $allSkillAsk=$db->prepare("SELECT * FROM skills WHERE language=:language");
  $allSkillAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));

  // All Proccess List
  $allProccessAsk=$db->prepare("SELECT * FROM posts WHERE language=:language and post_type=:post_type");
  $allProccessAsk->execute(array(
    'post_type' => 'post_proccess',
    'language'  => $getLangCheck['language_id']
  ));

  // All contact List
  $allContactAsk=$db->prepare("SELECT * FROM contact_log WHERE status=:status");

  // All product List
  $orderAsk=$db->prepare("SELECT * FROM orders WHERE order_type=:order_type");

  $orderAsk1=$db->prepare("SELECT * FROM orders WHERE order_type=:order_type AND status=:status");
  $orderAsk1->execute(array(
    'order_type' => 'order_packet',
    'status' => 0
  ));
  $orderPacketCount=$orderAsk1->rowCount();
  $orderAsk2=$db->prepare("SELECT * FROM orders WHERE order_type=:order_type AND status=:status");
  $orderAsk2->execute(array(
    'order_type' => 'order_product',
    'status' => 0
  ));
  $orderProductCount=$orderAsk2->rowCount();
  // ==============================================
  // ==============================================
  // ============= COUNT ORDER SORT ===============
  // ==============================================
  // ==============================================

  // Reference Categories order_sort
  $referenceCategoriesCountAsk=$db->prepare("SELECT * FROM categories WHERE language=:language and categories_type=:categories_type");
  $referenceCategoriesCountAsk->execute(array(
    'categories_type' => 'reference_categories',
    'language' => $getLangCheck['language_id']
  ));
  $referenceCategoriesCount=$referenceCategoriesCountAsk->rowCount();

  // Project Categories order_sort
  $projectCategoriesCountAsk=$db->prepare("SELECT * FROM categories WHERE language=:language and categories_type=:categories_type");
  $projectCategoriesCountAsk->execute(array(
    'categories_type' => 'project_categories',
    'language'        => $getLangCheck['language_id']
  ));
  $projectCategoriesCount=$projectCategoriesCountAsk->rowCount();

  // Project Categories order_sort
  $postCategoriesCountAsk=$db->prepare("SELECT * FROM categories WHERE language=:language and categories_type=:categories_type");
  $postCategoriesCountAsk->execute(array(
    'categories_type' => 'post_categories',
    'language'        => $getLangCheck['language_id']
  ));
  $postCategoriesCount=$postCategoriesCountAsk->rowCount();

  // Packet Categories order_sort
  $packetCategoriesCountAsk=$db->prepare("SELECT * FROM categories WHERE language=:language and categories_type=:categories_type");
  $packetCategoriesCountAsk->execute(array(
    'categories_type' => 'packet_categories',
    'language'        => $getLangCheck['language_id']
  ));
  $packetCategoriesCount=$packetCategoriesCountAsk->rowCount();

  // Product Categories order_sort
  $productCategoriesCountAsk=$db->prepare("SELECT * FROM categories WHERE language=:language and categories_type=:categories_type");
  $productCategoriesCountAsk->execute(array(
    'categories_type' => 'product_categories',
    'language'        => $getLangCheck['language_id']
  ));
  $productCategoriesCount=$productCategoriesCountAsk->rowCount();

  // Posts order_sort
  $postCountAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $postCountAsk->execute(array(
    'post_type'   => 'post_post',
    'language' => $getLangCheck['language_id']
  ));
  $postCount=$postCountAsk->rowCount();

  // Banks order_sort
  $bankCountAsk=$db->prepare("SELECT * FROM banks");
  $bankCountAsk->execute();
  $bankCount=$bankCountAsk->rowCount();

  // Branch Dealer order_sort
  $branchCountAsk=$db->prepare("SELECT * FROM branchdealer");
  $branchCountAsk->execute();
  $branchCount=$branchCountAsk->rowCount();

  // Faqs order_sort
  $faqCountAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $faqCountAsk->execute(array(
    'post_type' => 'post_faqs',
    'language'  => $getLangCheck['language_id']
  ));
  $faqCount=$faqCountAsk->rowCount();

  // Person order_sort
  $personCountAsk=$db->prepare("SELECT * FROM person");
  $personCountAsk->execute();
  $personCount=$personCountAsk->rowCount();

  // Counter order_sort
  $counterCountAsk=$db->prepare("SELECT * FROM counter WHERE language=:language");
  $counterCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $counterCount=$counterCountAsk->rowCount();

  // Catalog order_sort
  $catalogCountAsk=$db->prepare("SELECT * FROM catalog WHERE language=:language");
  $catalogCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $catalogCount=$catalogCountAsk->rowCount();

  // Document order_sort
  $documentCountAsk=$db->prepare("SELECT * FROM document WHERE language=:language");
  $documentCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $documentCount=$documentCountAsk->rowCount();

  // Services order_sort
  $servicesCountAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $servicesCountAsk->execute(array(
    'post_type' => 'post_services',
    'language'  => $getLangCheck['language_id']
  ));
  $servicesCount=$servicesCountAsk->rowCount();

  // Notices order_sort
  $noticeCountAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $noticeCountAsk->execute(array(
    'post_type' => 'post_notices',
    'language'  => $getLangCheck['language_id']
  ));
  $noticeCount=$noticeCountAsk->rowCount();

  // Reference order_sort
  $referenceCountAsk=$db->prepare("SELECT * FROM reference WHERE language=:language");
  $referenceCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $referenceCount=$referenceCountAsk->rowCount();

  // Social order_sort
  $socialCountAsk=$db->prepare("SELECT * FROM social");
  $socialCountAsk->execute();
  $socialCount=$socialCountAsk->rowCount();

  // Comments order_sort
  $commentCountAsk=$db->prepare("SELECT * FROM comments WHERE language=:language");
  $commentCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $commentCount=$commentCountAsk->rowCount();

  // Slider order_sort
  $sliderCountAsk=$db->prepare("SELECT * FROM slider WHERE language=:language");
  $sliderCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $sliderCount=$sliderCountAsk->rowCount();

  // Project order_sort
  $projectCountAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND language=:language");
  $projectCountAsk->execute(array(
    'post_type' => 'post_projects',
    'language'  => $getLangCheck['language_id']
  ));
  $projectCount=$projectCountAsk->rowCount();

  // Packets order_sort
  $packetCountAsk=$db->prepare("SELECT * FROM packets WHERE language=:language");
  $packetCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $packetCount=$packetCountAsk->rowCount();

  // Packets Features order_sort
  $packetfeatCountAsk=$db->prepare("SELECT * FROM packet_features WHERE language=:language");
  $packetfeatCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $packetfeatCount=$packetfeatCountAsk->rowCount();

  // Products order_sort
  $productsCountAsk=$db->prepare("SELECT * FROM posts WHERE language=:language AND post_type=:post_type");
  $productsCountAsk->execute(array(
    'language'   => $getLangCheck['language_id'],
    'post_type'  => 'post_products'
  ));
  $productsCount=$productsCountAsk->rowCount();

  // Language order_sort
  $languageCountAsk=$db->prepare("SELECT * FROM language");
  $languageCountAsk->execute();
  $languageCount=$languageCountAsk->rowCount();

  // iGallery order_sort
  $iGalleryCountAsk=$db->prepare("SELECT * FROM posts WHERE language=:language AND post_type=:post_type");
  $iGalleryCountAsk->execute(array(
    'post_type'    => 'post_Gallery',
    'language'     => $getLangCheck['language_id']
  ));
  $iGalleryCount=$iGalleryCountAsk->rowCount();

  // Menu order_sort
  $menuCountAsk=$db->prepare("SELECT * FROM menu WHERE language=:language");
  $menuCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $menuCount=$menuCountAsk->rowCount();

  // skill order_sort
  $skillCountAsk=$db->prepare("SELECT * FROM skills WHERE language=:language");
  $skillCountAsk->execute(array(
    'language' => $getLangCheck['language_id']
  ));
  $skillCount=$skillCountAsk->rowCount();

  // proccess order_sort
  $proccessCountAsk=$db->prepare("SELECT * FROM posts WHERE language=:language and post_type=:post_type");
  $proccessCountAsk->execute(array(
    'post_type' => 'post_proccess',
    'language'  => $getLangCheck['language_id']
  ));
  $proccessCount=$proccessCountAsk->rowCount();

  // CONTACT 0 order_sort
  $contactRowCountAsk=$db->prepare("SELECT * FROM contact_log WHERE status=:status");
  $contactRowCountAsk->execute(array(
    'status' => 0
  ));
  $contactRowCount=$contactRowCountAsk->rowCount();

  // CONTACT 1 order_sort
  $contactRowCountAsk1=$db->prepare("SELECT * FROM contact_log WHERE status=:status");
  $contactRowCountAsk1->execute(array(
    'status' => 1
  ));
  $contactRowCount1=$contactRowCountAsk1->rowCount();
?>
