<?php /*
$qusr = "SELECT * FROM `utilizatori` WHERE `uid`='{$row['uid']}' LIMIT 1";
$rusr = $dbc->query($qusr);
while($rowusr = $rusr->fetch_assoc()){
    $usruid       = $rowusr['uid'];
    $usremail     = $rowusr['email'];
    $usrprenume   = $rowusr['prenume'];
    $usrnume      = $rowusr['nume'];
    $usrmobil     = $rowusr['mobil'];
    $usrmoneda    = $rowusr['moneda'];
}

$getusermail = explode("@", $usremail);
$eusername = $getusermail[0];

if($row['aprobat'] == 1){
    $qvizita = "UPDATE `anunturi` SET `vizualizari`=`vizualizari` + 1 WHERE `aid`='{$row['aid']}' LIMIT 1";
    $rvizita = $dbc->query($qvizita);
}
*/
?>
<div class="w3-row-padding">
<div class="w3-quarter">
<?php include APP.'sidebar_cat.php'; ?>
</div>


<div class="w3-threequarter">
<div class="w3-container w3-text-white" style="background-color:#117594;margin-bottom:4px;">
<a class="w3-text-white" href="<?=BASE_URL?>"><i class="fa fa-home"></i></a> / <?=$row['titlu']?>
</div>

<div class="w3-container w3-text-white" style="background-color:#117594;">
<h3 style="white-space: nowrap;font-size:22px;padding-top:4px;"><i class="fa fa-th-list"></i> <?=$row['titlu']?></h3>
</div>


<?php
$qscat = "SELECT * FROM `scategorii` WHERE `cat_id`={$row['cat_id']}";
$rscat = $dbc->query($qscat);
if($rscat->num_rows > 0){
    echo '<div class="w3-row w3-card">
    <div class="w3-bar">';
while($rwscat = $rscat->fetch_assoc()){
?>
<a href="<?=PATH.$rwscat['seo']?>.html">
<div class="w3-col w3-mobile" style="width:23%;max-width:48%;margin:1%;">
<button class="w3-button w3-light-gray w3-hover-teal w3-padding-small" title="<?=$rwscat['titlu']?>" style="width:100%;"><i class="fa fa-hand-o-right"></i> <?=$rwscat['titlu']?></button>
</div>
</a>
<?php } 
echo '</div></div>';
 } ?>


<?php
function lungime_text($x, $length){
  if(strlen($x)<=$length)  {
    echo $x;
  }else{
    $y=substr($x,0,$length) . '...';
    echo $y;
  }
 }
?>
<div class="w3-row-padding w3-margin-top">



<?php
if(isset($filterCAT) == true){
    
    
    $fjudet  = $_POST['judet'];
    $fcatid  = $_POST['cat'];
    $fscatid = $_POST['scat'];
    $fpret   = $_POST['pret'];
    $fmoneda = $_POST['moneda'];

    //Do real escaping here

    $query = "SELECT * FROM anunturi";
    $conditions = array();

    if(! empty($fjudet)) {
      $conditions[] = "judet='$fjudet'";
    }
    if(! empty($fcatid)) {
      $conditions[] = "cat_id='$fcatid'";
    }
    if(! empty($fscatid)) {
      $conditions[] = "scat_id='$fscatid'";
    }
    if(! empty($fpret)) {
      $conditions[] = "pret='$fpret'";
    }    

    $sql = $query;
    if (count($conditions) > 0) {
      $sql .= " WHERE " . implode(' AND ', $conditions);
    }

    $result = $dbc->query($sql);
    return $result;
    
    
    echo 'Filtrare';
 }else{

$qacat = "SELECT * FROM `anunturi` WHERE `verificat` IS NULL AND `aprobat`=1 AND `cat_id`={$row['cat_id']} ORDER BY `data_publicarii` DESC";
$racat = $dbc->query($qacat);
   if($racat->num_rows > 0){
   while($rwacat = $racat->fetch_assoc()){
       $qgetimage = "SELECT * FROM `imagini` WHERE `aid`={$rwacat['aid']}";
       $rgetimage = $dbc->query($qgetimage);
       $rowgetimg = $rgetimage->fetch_assoc();
       
       $qgetuser = "SELECT * FROM `utilizatori` WHERE `uid`={$rwacat['uid']}";
       $rgetuser = $dbc->query($qgetuser);
       $rowgetusr = $rgetuser->fetch_assoc();         
?>

<a href="<?=PATH.$rwacat['seo']?>.html">
<div class="w3-half w3-hover-light-gray w3-text-black w3-margin-bottom" style="padding:5px;">
<div class="w3-col w3-card">
<div class="w3-col w3-hide-small" style="width:26%;">
<img src="<?=BASE_URL.'imagini/'.$rowgetimg['nume_fisier']?>" style="width:100px;height:100px;" alt="<?php echo lungime_text($rwacat['titlu'], 36); ?>" title="<?php echo $rwacat['titlu']; ?>" loading="lazy" class="w3-margin"/>
</div>
<div class="w3-col w3-hide-medium w3-hide-large" style="width:30%;">
<img src="<?=BASE_URL.'imagini/'.$rowgetimg['nume_fisier']?>" style="width:70px;height:70px;" alt="<?php echo lungime_text($rwacat['titlu'], 36); ?>" title="<?php echo $rwacat['titlu']; ?>" loading="lazy"/>
</div>
<div class="w3-col w3-hide-small" style="width:74%;">
<h4 class="w3-border-bottom" style="font-size:20px;">
<?php echo lungime_text($rwacat['titlu'], 36); ?></h4>
<div style="text-align: justify;padding-left:5px;padding-right:5px;">
<span><?php echo lungime_text($rwacat['descriere'], 90); ?></span></div>
<div class="w3-row w3-border-top w3-green">
<div class="w3-right" style="padding-right:5px;">
<i class="fa fa-money"></i> Preț: <?php if($rwacat['pret'] > 0){echo '<strong>'.$rwacat['pret'].'</strong> '.$rowgetusr['moneda'];}else{echo 'GRATUIT';} ?>
</div>
</div>

<div class="w3-row w3-border-top">
<div class="w3-left" style="padding-left:5px;">
<i class="fa fa-map-marker"></i> <?php echo $rwacat['judet']; ?>
</div>
<div class="w3-right" style="padding-right:5px;">
<i class="fa fa-clock-o"></i> <?php echo date('d F Y, H:i', strtotime($rwacat['data_publicarii'])); ?>
</div>
</div>

</div>

<div class="w3-col w3-hide-medium w3-hide-large" style="width:70%;">
<h5 class="w3-border-bottom" style="font-size:15px;">
<?php echo lungime_text($rwacat['titlu'], 28); ?>
</h5>
<span><?php echo lungime_text($rwacat['descriere'], 42); ?></span>
</div></div>
</div></a>
<?php } 
 } }
?>


</div>


</div>
</div>