<?php     
if(isset($_GET['y'], $_GET['a']) && filter_var($_GET['y']) && filter_var($_GET['a'])) {
    $titlupagina = 'Aptobare anunț';
$qcheck = "SELECT * FROM `anunturi` WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' LIMIT 1";
$rcheck = $dbc->query($qcheck);
$rck = $rcheck->fetch_assoc();
$refuzat = $rck['refuzat'];

if($refuzat == 0){
$q = "UPDATE `anunturi` SET `aprobat`='1' WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' LIMIT 1";
$r = $dbc->query($q);    
if ($dbc->affected_rows == 1) {
$rau = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");
while($row = $rau->fetch_assoc()){$uid = $row['uid'];}

$qu = "SELECT * FROM `utilizatori` WHERE `utilizatori`.`uid`='".$uid."' LIMIT 1";
$ru = $dbc->query($qu);
$rwu = $ru->fetch_assoc();
$uemail = $rwu['email'];

$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");
while($rwa = $ra->fetch_assoc()){
        $titluanunt = $rwa['titlu'];
        $continutanunt = $rwa['descriere'];
        $anuntseo = $rwa['seo'];
        }
    
require_once(SML.'Send_Mail.php');
$to = $uemail;
$subject = BASE_NAME." :: Anunț aprobat!";                    
$body = "<!DOCTYPE HTML>
      <head>
      <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
      <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
      <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">
      <title>Anunț aprobat</title>
      </head>
      <body>
      <div style=\"margin:16px;width:800px;max-width:100%;\">      
      <div style=\"margin:16px;padding:16px;\">
      <p>Bun găsit!</p>
      <p>Avem vești bune pentru dumneavoastră!</p>
      <p><strong>Anunțul dumneavoastră a fost aprobat!</strong></p>\n\n";
$body .= '<p>Anunțul este publicat la adresa: '.BASE_URL.$anuntseo.'.html<br /></p><br/>';
$body .= '<p>---</p>
          <p>Salutări calde,<br />
              &nbsp;&nbsp;&nbsp;&nbsp; Echipa <a href="'. BASE_URL . '" style="text-decoration:none;">'.BASE_NAME.'</a></p>
          </div></div>
</body>
</html>';                    
Send_Mail($to,$subject,$body);    
$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");    
while($row = $ra->fetch_assoc()){$anuntseo = $row['seo'];} 
$active =  "Anunțul a fost aprobat!<br/>(Veți fi redirectat către anunț ->".BASE_URL.$anuntseo.".html)";
$url = BASE_URL.$anuntseo.".html";
header( "refresh:5;url=$url" );
    } else {        
$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");    
while($row = $ra->fetch_assoc()){$anuntseo = $row['seo'];}        
$inactive = "Anunțul este deja APROBAT.<br/>(Veți fi redirectat către anunț ->".BASE_URL.$anuntseo.".html)";
$url = BASE_URL.$anuntseo.".html";
header( "refresh:5;url=$url" );
    }
    //$dbc->close();
 }else{
    $status = 'Anunțul nu poate fi aprobat, deoarece este refuzat.';
 }
 }
 
// Refuzare Anunt
if(isset($_GET['n'], $_GET['a']) && filter_var($_GET['n']) && filter_var($_GET['a'])) {
    $titlupagina = 'Refuzare anunț';
$qcheck = "SELECT * FROM `anunturi` WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' LIMIT 1";
$rcheck = $dbc->query($qcheck);
$rck = $rcheck->fetch_assoc();
$aprobat = $rck['aprobat'];

if($aprobat == 0){
$q = "UPDATE `anunturi` SET `refuzat`='1', `motiv`='Anunțul nu poate fi aprobat, datorită conținutului său.' WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' LIMIT 1";
$r = $dbc->query($q);    
if ($dbc->affected_rows == 1) {
$rau = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");
while($row = $rau->fetch_assoc()){$uid = $row['uid'];}

$qu = "SELECT * FROM `utilizatori` WHERE `utilizatori`.`uid`='".$uid."' LIMIT 1";
$ru = $dbc->query($qu);
$rwu = $ru->fetch_assoc();
$uemail = $rwu['email'];

$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `anunturi`.`aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");
while($rwa = $ra->fetch_assoc()){
        $titluanunt = $rwa['titlu'];
        $continutanunt = $rwa['descriere'];
        $anuntseo = $rwa['seo'];
        $motiv = $rwa['motiv'];
        }
    
require_once(SML.'Send_Mail.php');
$to = $uemail;
$subject = BASE_NAME." :: Anunț REFUZAT!";                    
$body = "<!DOCTYPE HTML>
      <head>
      <meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
      <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">
      <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\">
      <title>Anunț REFUZAT</title>
      </head>
      <body>
      <div style=\"margin:16px;width:800px;max-width:100%;\">      
      <div style=\"margin:16px;padding:16px;\">
      <p>Bun găsit!</p>
      <p>Avem vești nu prea bune pentru dumneavoastră!</p>
      <p><strong>Anunțul dumneavoastră a fost refuzat!</strong></p>\n\n";
$body .= '<p style="color:red;">Motivul refuzului: <strong>'.$motiv.'</strong></p><br/>';
$body .= '<p>---</p>
          <p>Salutări calde,<br />
              &nbsp;&nbsp;&nbsp;&nbsp; Echipa <a href="'. BASE_URL . '" style="text-decoration:none;">'.BASE_NAME.'</a></p>
          </div></div>
</body>
</html>';                    
Send_Mail($to,$subject,$body);    
$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");    
while($row = $ra->fetch_assoc()){$anuntseo = $row['seo'];} 
$active =  "Anunțul a fost refuzat!";
$url = BASE_URL;
header( "refresh:5;url=$url" );
    } else {        
$ra = $dbc->query("SELECT * 
                   FROM `anunturi` 
                   WHERE `aid`='".$dbc->real_escape_string($_GET['a'])."' 
                   LIMIT 1");    
while($row = $ra->fetch_assoc()){$anuntseo = $row['seo'];}        
$inactive = "Anunțul este deja REFUZAT.";
$url = BASE_URL;
header( "refresh:5;url=$url" );
    }
    //$dbc->close();
 }else{
    $status = 'Anunțul nu poate fi refuzat, deoarece este aprobat.';
 }
 
 }
?>
<div class="w3-row-padding">
<div class="w3-quarter">
<?php include APP.'sidebar_gen.php'; ?>
</div>
<div class="w3-threequarter">
 
 <div class="w3-row">
   <div class="w3-rest w3-card w3-container w3-text-white w3-margin-bottom" style="background-color:#117594;">
   <h3><?=$titlupagina?></h3>
   
<?php if(isset($active)){ ?>
<div class="w3-panel w3-padding w3-green w3-center"><?php echo $active; ?><br/><br/>
<p><i class="fa fa-check-square-o w3-center" style="font-size:100px;"></i></p>
</div>
<?php } ?>

<?php if(isset($status)){ ?>
<div class="w3-panel w3-padding w3-orange w3-text-white w3-center"><?php echo $status; ?><br/><br/>
<p><i class="fa fa-ban w3-center" style="font-size:100px;"></i></p>
</div>
<?php } ?>

<?php if(isset($inactive)){ ?>
<div class="w3-panel w3-padding w3-red w3-center"><?php echo $inactive; ?><br/><br/>
<p><i class="fa fa-close w3-center" style="font-size:100px;"></i></p>
</div>
<?php } ?>   
   </div>
  </div>
 </div>
</div>