<?php
function lungime_text($x, $length){
  if(strlen($x)<=$length)  {
    echo $x;
  }else{
    $y=substr($x,0,$length) . '...';
    echo $y;
  }
 }
$rlast = $dbc->query("SELECT * FROM `anunturi` 
                               WHERE `verificat` IS NULL 
                               AND `aprobat`=1 
                               ORDER BY `data_publicarii` DESC 
                               LIMIT 6");

$rpop = $dbc->query("SELECT * FROM `anunturi` 
                              WHERE `verificat` IS NULL 
                              AND `aprobat`=1 
                              ORDER BY `vizualizari` DESC 
                              LIMIT 6");
?>

<div class="w3-row-padding">
<div class="w3-quarter w3-hide-small w3-hide-medium">
<?php include APP.'sidebar_gen.php'; ?>
</div>
<div class="w3-rest">
<?php include APP.'searchform.php'; ?>
 
 <div class="w3-row">
   <div class="w3-half">
   
   <div class="w3-margin-bottom w3-hide-small w3-mobile">
   <h3 class="w3-card w3-text-white w3-container" style="margin-right:2px;padding-top:2px;padding-bottom:2px;background-color:#117594;">Ultimele anunțuri</h3>
   </div>
   
   <div class="w3-margin-bottom w3-hide-large w3-hide-medium">
   <h3 class="w3-card w3-text-white w3-container w3-margin-right w3-mobile" style="padding-top:2px;padding-bottom:2px;background-color:#117594;">Ultimele anunțuri</h3>
   </div>
   
<?php
   while($rowlast = $rlast->fetch_assoc()){
       $qgetimage = "SELECT * FROM `imagini` WHERE `aid`={$rowlast['aid']}";
       $rgetimage = $dbc->query($qgetimage);
       $rowgetimg = $rgetimage->fetch_assoc();
       
       $qgetuser = "SELECT * FROM `utilizatori` WHERE `uid`={$rowlast['uid']}";
       $rgetuser = $dbc->query($qgetuser);
       $rowgetusr = $rgetuser->fetch_assoc();         
?>
<a href="<?=PATH.$rowlast['seo']?>.html">
<div class="w3-col l6 m12 s12 w3-hover-light-gray w3-text-black w3-margin-bottom">
<div class="w3-col" style="width:96%;margin:1%;margin-bottom:0;">
<img src="<?=BASE_URL.'imagini/'.$rowgetimg['nume_fisier']?>" style="object-fit:cover;width:100%;height:150px;max-height:100%;" alt="<?php echo lungime_text($rowlast['titlu'], 36); ?>" title="<?php echo $rowlast['titlu']; ?>" loading="lazy" class="w3-card"/>
</div>
<div class="w3-col" style="width:96%;margin:1%;">
<h4 class="w3-card" style="font-size:16px;padding-left:4px;margin-bottom:0;">
<?php echo lungime_text($rowlast['titlu'], 20); ?></h4>
<div class="w3-row w3-green" style="margin-top:0;">
<div class="w3-right" style="padding-right:5px;">
<i class="fa fa-money"></i> <?php if($rowlast['pret'] > 0){echo '<strong>'.$rowlast['pret'].'</strong> '.$rowgetusr['moneda'];}else{echo 'GRATUIT';} ?>
</div>
</div>

</div>

</div></a>
<?php } ?>
   </div>
   
   <div class="w3-half">
   
   <div class="w3-margin-bottom w3-hide-small">
   <h3 class="w3-card w3-text-white w3-container" style="margin-left:2px;padding-top:2px;padding-bottom:2px;background-color:#117594;">Cele mai populare</h3>
   </div>
   
   <div class="w3-margin-bottom w3-hide-large w3-hide-medium">
   <h3 class="w3-card w3-text-white w3-container w3-mobile" style="padding-top:2px;padding-bottom:2px;background-color:#117594;">Cele mai populare</h3>
   </div>
      
<?php   
while($rowpop = $rpop->fetch_assoc()){
       $qgetimage = "SELECT * FROM `imagini` WHERE `aid`={$rowpop['aid']}";
       $rgetimage = $dbc->query($qgetimage);
       $rowgetimg = $rgetimage->fetch_assoc();
       
       $qgetuser = "SELECT * FROM `utilizatori` WHERE `uid`={$rowpop['uid']}";
       $rgetuser = $dbc->query($qgetuser);
       $rowgetusr = $rgetuser->fetch_assoc();         
?>
<a href="<?=PATH.$rowpop['seo']?>.html">
<div class="w3-col l6 m12 s12 w3-hover-light-gray w3-text-black w3-margin-bottom">
<div class="w3-col" style="width:96%;margin:1%;margin-bottom:0;">
<img src="<?=BASE_URL.'imagini/'.$rowgetimg['nume_fisier']?>" data-src="<?=BASE_URL.'imagini/'.$rowgetimg['nume_fisier']?>" style="object-fit:cover;width:100%;height:150px;max-height:100%;" alt="<?php echo $rowpop['titlu']; ?>" title="<?php echo $rowpop['titlu']; ?>" loading="lazy" class="w3-card"/>
</div>

<div class="w3-col" style="width:96%;margin:1%;">
<h4 class="w3-card" style="font-size:16px;padding-left:4px;margin-bottom:0;">
<?php echo lungime_text($rowpop['titlu'], 20); ?></h4>
<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($rowpop['pret'] > 0){echo '<strong>'.$rowpop['pret'].'</strong> '.$rowgetusr['moneda'];}else{echo 'GRATUIT';} ?>
</div>
</div>

</div>

</div></a>
<?php } ?>
   </div>
 </div>

</div>

</div>