<?php
include($_SERVER["DOCUMENT_ROOT"].'/devbook/incs/config.inc.php');
include(BASE);
// Get Content
$page = $_GET['p'];

$rp1 = $dbc->query('SELECT * FROM `pages` WHERE `pages`.`seo`="'.$page.'"');
$rp2 = $dbc->query('SELECT * FROM `users_pages` WHERE `users_pages`.`seo`="'.$page.'"');
$rp3 = $dbc->query('SELECT * FROM `admin_pages` WHERE `admin_pages`.`seo`="'.$page.'"');
$rp4 = $dbc->query('SELECT * FROM `country_page` WHERE `country_page`.`seo`="'.$page.'"');
$rp5 = $dbc->query('SELECT * FROM `counties` WHERE `counties`.`seo`="'.$page.'"');
$rp6 = $dbc->query('SELECT * FROM `books` WHERE `books`.`seo`="'.$page.'"');
$rp7 = $dbc->query('SELECT * FROM `user_details` WHERE `user_details`.`seo`="'.$page.'"');

if($rp1->num_rows > 0){$row   = $rp1->fetch_assoc();}
if($rp2->num_rows > 0){$row   = $rp2->fetch_assoc();}
if($rp3->num_rows > 0){$row   = $rp3->fetch_assoc();}
if($rp4->num_rows > 0){$row   = $rp4->fetch_assoc();}
if($rp5->num_rows > 0){$row   = $rp5->fetch_assoc();}
if($rp6->num_rows > 0){$row   = $rp6->fetch_assoc();}
if($rp7->num_rows > 0){$row   = $rp7->fetch_assoc();}

$rimg = $dbc->query('SELECT `logo` FROM `settings` WHERE 1=1');
$dbc->close();

$lp          = $row['seo'];
$title       = $row['title'];
$description = $row['description'];

if($row['usdet_id'] == true){
    include(BASE);
$getuseracc = $dbc->query("SELECT * FROM `users` WHERE `uid`='{$row['uid']}' LIMIT 1");
$rusac = $getuseracc->fetch_assoc();
$dbc->close();

if($rusac['last_name']){
    $titlecontent = $rusac['first_name'].' '.$rusac['last_name'];
}else{
    $titlecontent = $rusac['first_name'];
}


$title       = BASE_NAME.' :: '.$titlecontent;
$description = 'This is the presentation page of '.$titlecontent.' user from '.BASE_NAME.'.';

 }

if(!empty($row['tags'])){
          $keyords = $row['tags'];
       }else{
         $keyords = 'books, people';
       }

if($page == $lp){
    include(HEAD);
    include(FORM);
    if($row['pid'] == true){
        if (file_exists(THM.$set['theme'].'/page.php')){
            include THM.$set['theme'].'/page.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['uaid'] == true){
        if (file_exists(THM.$set['theme'].'/myaccount.php')){
            include THM.$set['theme'].'/myaccount.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['asid'] == true){
        if (file_exists(THM.$set['theme'].'/admin.php')){
            include THM.$set['theme'].'/admin.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['copa_id'] == true){
        if (file_exists(THM.$set['theme'].'/country.php')){
            include THM.$set['theme'].'/country.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['cnty_id'] == true){
        if (file_exists(THM.$set['theme'].'/county.php')){
            include THM.$set['theme'].'/county.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['bkid'] == true){
        if (file_exists(THM.$set['theme'].'/book.php')){
            include THM.$set['theme'].'/book.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }elseif($row['usdet_id'] == true){
        if (file_exists(THM.$set['theme'].'/user.php')){
            include THM.$set['theme'].'/user.php';
              }else{
                include THM.$set['theme'].'/404.php';
              }
    }
  include(FOOT);
  }else{
    $title       = 'Eroare pagina cu 404';
    $description = 'Pagia a rezultat cu o eroare';
    include(HEAD);
    include THM.$set['theme'].'/404.php';
    include(FOOT);
}
?>