<?php
include($_SERVER["DOCUMENT_ROOT"].'/anunturi/config/loadconfig.php');
//include(BASE);
// Get Content
$page = $_GET['page'];
$rpage1 = $dbc->query('SELECT * FROM `pagina` WHERE `pagina`.`seo`="'.$page.'"');
$rpage2 = $dbc->query('SELECT * FROM `anunturi` WHERE `anunturi`.`seo`="'.$page.'"');
$rpage3 = $dbc->query('SELECT * FROM `categorii` WHERE `categorii`.`seo`="'.$page.'"');
$rpage4 = $dbc->query('SELECT * FROM `scategorii` WHERE `scategorii`.`seo`="'.$page.'"');

if($rpage1->num_rows > 0){$row   = $rpage1->fetch_assoc();}
if($rpage2->num_rows > 0){$row   = $rpage2->fetch_assoc();}
if($rpage3->num_rows > 0){$row   = $rpage3->fetch_assoc();}
if($rpage4->num_rows > 0){$row   = $rpage4->fetch_assoc();}

$rimg = $dbc->query('SELECT * FROM `imagini` WHERE `aid`="'.$row['aid'].'"');

$loadpage    = $row['seo'];
$title       = $row['titlu'];
$description = $row['descriere'];
if(!empty($row['etichete'])){
$keyords     = $row['etichete'];
}else{
    $keyords = 'anunturi, gratuite, romania';
}

if($page == $loadpage){    
    include(HEAD);
    if (file_exists(APP.$loadpage.'.php')){    
    include APP.$loadpage.'.php';
    }else{
        if(($row['vizualizari'] == true)){
           if (file_exists(APP.'anunt.php')){            
               include APP.'anunt.php';
              }else{
                include APP.'404.php';
              }
         }elseif(($row['cat_id'] == true) && ($row['scat_id'] == true)){
            if (file_exists(APP.'scategorie.php')){            
               include APP.'scategorie.php';
              }else{
                include APP.'404.php';
            }
            
         }else{        
           if (file_exists(APP.'categorie.php')){            
               include APP.'categorie.php';
              }else{
                include APP.'404.php';
            }
          }
    }
    include(FOOT);
 }else{
    $title       = 'Eroare pagina cu 404';
    $description = 'Pagia a rezultat cu o eroare';
    include(HEAD);
    include APP.'404.php';
    include(FOOT);
}
?>