<?php
if(isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'iesire.html')) {
    
    $qcont = "SELECT * FROM `utilizatori` WHERE `uid`='".$_SESSION['user_id']."' LIMIT 1";
    $rcont = $dbc->query($qcont);
    $rowct = $rcont->fetch_assoc(); 
    
    $qanunt = "SELECT * FROM `anunturi` WHERE `uid`='".$_SESSION['user_id']."'";
    $ranunt = $dbc->query($qanunt);
?>
<div class="w3-row-padding">
<div class="w3-quarter">
<?php include APP.'sidebar_usr.php'; ?>
</div>
<div class="w3-threequarter">
<div class="w3-row w3-indigo">
<h3 class="w3-container"><i class="fa fa-bullhorn"></i> Anunțurile mele</h3>
</div>

<?php if(isset($stareanunt) == 1){?>
<div class="w3-panel w3-padding w3-green">
<i class="fa fa-check"></i> Anunțul a fost șters</div>
<?php }elseif(isset($stareanunt) == 2){ ?>
<div class="w3-panel w3-padding w3-red">
<i class="fa fa-remove"></i> Anunțul nu a fost șters</div>
<?php } ?>

<div class="w3-row w3-margin-top">
<div class="w3-responsive">
<table class="w3-table-all">
<tr>
<th>Nr.</th>
<th>Titlu anunț</th>
<th class="w3-center">Vizualizări</th>
<th>Data adăugării</th>
<th></th>
</tr>
<?php if($ranunt->num_rows > 0){
    $nr = 1;
    while($rwa = $ranunt->fetch_assoc()){        
echo '<tr class="w3-hover-pale-blue">
  <td>'.$nr++.'</td>
  <td><a class="w3-text-black" href="'.PATH.$rwa['seo'].'.html" style="text-decoration:none;">'.$rwa['titlu'].'</a></td>
  <td class="w3-center">'.$rwa['vizualizari'].'</td>
  <td>'.$rwa['data_publicarii'].'</td>
  <td><div class="w3-center">
  <form action="editare-anunt.html" method="post">  
  <button class="w3-button w3-col w3-padding-small w3-hover-none" style="width:15%;"><i class="fa fa-pencil-square-o w3-text-blue w3-hover-text-black"></i></button>
  <input type="hidden" name="aid" value="'.$rwa['aid'].'"/>
  <input type="hidden" name="uid" value="'.$_SESSION['user_id'].'"/>
  </form>
  <form action="" method="post">  
  <button class="w3-button w3-col w3-padding-small w3-hover-none" style="width:15%;"><i class="fa fa-trash-o w3-text-red w3-hover-text-black"></i></button>
  <input type="hidden" name="aid" value="'.$rwa['aid'].'"/>
  <input type="hidden" name="uid" value="'.$_SESSION['user_id'].'"/>
  <input type="hidden" name="sterganuntulmeu" value="true"/>
  </form>';
  

if($rwa['aprobat'] == '1'){
    echo '<div class="w3-text-green" style="margin-top:4px;">&nbsp; <i class="fa fa-check"></i> Aprobat</div>';
}
if(($rwa['aprobat'] == '0') && ($rwa['refuzat'] == '0')){
    echo '<div class="w3-text-blue" style="margin-top:4px;">&nbsp; <i class="fa fa-clock-o"></i> În curs de verificare</div>';
}
if($rwa['refuzat'] == '1'){
    echo '<div class="w3-text-red" style="margin-top:4px;">&nbsp; <i class="fa fa-times"></i> Refuzat <i class="fa fa-info-circle w3-right" title="'.$rwa['motiv'].'"></i></div>';
}

  
echo '</div></td>
</tr>';
     }
   }else{ ?>
<tr>
<td class="w3-center" colspan="4">Nu ați adăugat niciun anunț!</td>
</tr>
<?php } ?>

</table>
</div>

</div>

</div></div>
<?php
 }else{
    $url = PATH.'index.html';
    ob_end_clean();
    header("Location: $url");
    exit();
 }
?>