<?php
  if (isset($_GET['seo_url'])) {
    // $_GET['seo_url'] page query
    $pageAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $pageAsk->execute(array(
      'post_type' => 'post_page',
      'seo_url'   => $_GET['seo_url']
    ));
    $pagesCount=$pageAsk->rowCount();
    $pagesCheck=$pageAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] post query
    $postAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $postAsk->execute(array(
      'post_type' => 'post_post',
      'seo_url'   => $_GET['seo_url']
    ));
    $postCount=$postAsk->rowCount();
    $postCheck=$postAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] services query
    $servicesAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $servicesAsk->execute(array(
      'post_type' => 'post_services',
      'seo_url'   => $_GET['seo_url']
    ));
    $servicesCount=$servicesAsk->rowCount();
    $servicesCheck=$servicesAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] product query
    $productAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $productAsk->execute(array(
      'post_type' => 'post_products',
      'seo_url'   => $_GET['seo_url']
    ));
    $productCount=$productAsk->rowCount();
    $productCheck=$productAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] project query
    $projectAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $projectAsk->execute(array(
      'post_type' => 'post_projects',
      'seo_url'   => $_GET['seo_url']
    ));
    $projectCount=$projectAsk->rowCount();
    $projectCheck=$projectAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] project query
    $noticeAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $noticeAsk->execute(array(
      'post_type' => 'post_notices',
      'seo_url'   => $_GET['seo_url']
    ));
    $noticeCount=$noticeAsk->rowCount();
    $noticeCheck=$noticeAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] project query
    $galleryAsk=$db->prepare("SELECT * FROM posts WHERE post_type=:post_type AND seo_url=:seo_url");
    $galleryAsk->execute(array(
      'post_type' => 'post_Gallery',
      'seo_url'   => $_GET['seo_url']
    ));
    $galleryCount=$galleryAsk->rowCount();
    $galleryCheck=$galleryAsk->fetch(PDO::FETCH_ASSOC);

    // $_GET['seo_url'] categories query
    $categoriesAsk=$db->prepare("SELECT * FROM categories WHERE seo_url=:seo_url");
    $categoriesAsk->execute(array(
      'seo_url'   => $_GET['seo_url']
    ));
    $categoriesCount=$categoriesAsk->rowCount();
    $categoriesCheck=$categoriesAsk->fetch(PDO::FETCH_ASSOC);

    if ($pagesCount){
      echo '
        <title>'.$pagesCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$pagesCheck['seo_keywords'].'">
        <meta name="description" content="'.$pagesCheck['seo_description'].'">
      ';
    }elseif($postCount){
      echo '
        <title>'.$postCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$postCheck['seo_keywords'].'">
        <meta name="description" content="'.$postCheck['seo_description'].'">
      ';
    }elseif($categoriesCount){
      echo '
        <title>'.$categoriesCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$categoriesCheck['seo_keywords'].'">
        <meta name="description" content="'.$categoriesCheck['seo_description'].'">
      ';
    }elseif($servicesCount){
      echo '
        <title>'.$servicesCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$servicesCheck['seo_keywords'].'">
        <meta name="description" content="'.$servicesCheck['seo_description'].'">
      ';
    }elseif($productCount){
      echo '
        <title>'.$productCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$productCheck['seo_keywords'].'">
        <meta name="description" content="'.$productCheck['seo_description'].'">
      ';
    }elseif($projectCount){
      echo '
        <title>'.$projectCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$projectCheck['seo_keywords'].'">
        <meta name="description" content="'.$projectCheck['seo_description'].'">
      ';
    }elseif($noticeCount){
      echo '
        <title>'.$noticeCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$noticeCheck['seo_keywords'].'">
        <meta name="description" content="'.$noticeCheck['seo_description'].'">
      ';
    }elseif($galleryCount){
      echo '
        <title>'.$galleryCheck['seo_title'].'</title>
        <meta name="keywords" content="'.$galleryCheck['seo_keywords'].'">
        <meta name="description" content="'.$galleryCheck['seo_description'].'">
      ';
    }
  }else{
    echo '
      <title>'.$langArray['404_TITLE'].'</title>
      <meta name="keywords" content="'.$langArray['404_TITLE'].'">
      <meta name="description" content="'.$langArray['404_DESC'].'">
    ';
  }

?>
