<style>
/* {box-sizing: border-box;}*/
img {vertical-align: middle;}
.container {position: relative;}
.mySlides {display: none;}
.cursor {cursor: pointer;}
/*.prev,.next {cursor: pointer;position: absolute;top: 40%;width: auto;padding: 16px;margin-top: -50px;color: white;font-weight: bold;font-size: 20px;border-radius: 0 3px 3px 0; user-select: none; -webkit-user-select: none;}
.next {right: 0; border-radius: 3px 0 0 3px;}
.prev:hover,.next:hover {background-color: rgba(0, 0, 0, 0.8);}*/
.numbertext {color: #f2f2f2;font-size: 12px;padding: 8px 12px;position: absolute;top: 0;}
.caption-container {text-align: center;background-color:#117594;color: white;}
.row:after {content: "";display: table;clear: both;}
.column {float: left;width: 20%;}
.demo {opacity: 0.6;}
.active,.demo:hover {opacity: 1;}
</style>


<?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);
}

$rcata = $dbc->query("SELECT * FROM `categorii` WHERE `cat_id`='".$row['cat_id']."' LIMIT 1");
$rcatb = $rcata->fetch_assoc();
$rscata = $dbc->query("SELECT * FROM `scategorii` WHERE `scat_id`='".$row['scat_id']."' LIMIT 1");
if($rscata->num_rows > 0){
$rscatb = $rscata->fetch_assoc();
 }

?>
<div class="w3-row-padding">
<div class="w3-quarter">
<?php include APP.'sidebar_gen.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> / <a class="w3-text-white" href="<?=PATH.$rcatb['seo']?>.html"><?=$rcatb['titlu']?></a> / <!--<a class="w3-text-white" href="<?=PATH.$rscatb['seo']?>.html"><?=$rscatb['titlu']?></a> / --><?=$row['titlu']?>
</div>

<div class="w3-container w3-text-white" style="background-color:#117594;">
<h3><?=$row['titlu']?></h3>
</div>

<?php if($row['aprobat'] == 1){ ?>

<div class="w3-container w3-card">

<div class="w3-half w3-margin-top w3-margin-bottom">
<div class="container_ w3-margin-right w3-mobile">
<?php
$qimgs = "SELECT * FROM `imagini` WHERE `aid`='{$row['aid']}' ORDER BY `fid` ASC";
$rimgs = $dbc->query($qimgs);
$nrs = 1;
$qcnt = "SELECT COUNT(*) AS nrf FROM `imagini` WHERE `aid`='{$row['aid']}'";
  $rcnt = $dbc->query($qcnt);
  $rwcf = $rcnt->fetch_assoc();
  $cnt  = $rwcf['nrf'];
while($rowimgs = $rimgs->fetch_assoc()){ ?>  
<div class="mySlides">
   <div class="numbertext"><?=$nrs++?> / <?=$cnt?></div>
   <img class="w3-padding" src="<?php echo PATH.'imagini/'.$rowimgs['nume_fisier'];?>" alt="<?=$row['titlu']?>" title="<?=$row['titlu']?>" loading="lazy" style="width:100%;max-width:100%;height:350px;object-fit:cover;" onclick="onClick(this)"/>
  </div>



<?php } ?><!--
<a class="prev" onclick="plusSlides(-1)">&lt;</a>
<a class="next" onclick="plusSlides(1)">&gt;</a>-->

<div class="caption-container">
<p id="caption" style="font-size:18px;"><?=$row['titlu']?></p>
</div>

<div class="w3-row">
<?php
$qimgt = "SELECT * FROM `imagini` WHERE `aid`='{$row['aid']}' ORDER BY `fid` ASC";
$rimgt = $dbc->query($qimgt);
$sld = 1;
while($rowimgt = $rimgt->fetch_assoc()){ ?>
<div class="column" style="margin-top:-10px;">
      <img class="w3-padding demo cursor" src="<?=PATH.'imagini/'.$rowimgt['nume_fisier']?>" style="max-width:100%;height:65px;padding:2px;" onclick="currentSlide(<?php echo $sld++; ?>)" alt="<?=$row['titlu']?>" title="<?=$row['titlu']?>" loading="lazy"/>
    </div>
<?php } ?>
</div>

</div>
</div>

<div class="w3-half w3-margin-top w3-margin-bottom">

<div class="w3-row">
<div class="w3-right">
<i class="fa fa-map-marker"></i> <?php echo $row['judet']; ?>, 
<i class="fa fa-clock-o"></i> <?php echo date('d F Y, H:i', strtotime($row['data_publicarii'])); ?>
</div></div>
<?php if(isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'iesire'.$pagext)) { ?>
<div class="w3-row w3-border-bottom">
<div class="w3-right">
Anunț adăugat de <strong>
<?php 
if($usrprenume){echo $usrprenume;}else{echo 'user-'.$eusername.'-'.$usruid;} 
if($usrprenume){echo ' '.$usrnume;}
?></strong>
</div></div>
<?php } ?>

<div class="w3-row w3-border-bottom">
<div class="w3-center w3-margin">
<h4>Preț: <?=$row['pret']?> <?=$usrmoneda?></h4>
</div></div>

<div class="w3-row w3-right">
<div class="w3-bar">
 
<button class="w3-button w3-bar-item w3-indigo w3-hover-black w3-padding-small" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=<?php echo 'https://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?>&amp;src=sdkpreparse', 'Share This', 'menubar=no,toolbar=no,resizable=no,scrollbars=no, width=600,height=455');">
<i class="fa fa-facebook w3-large"></i><span class="w3-hide-small"> Facebook</span></button>

<button class="w3-button w3-bar-item w3-blue w3-hover-indigo w3-padding-small" onclick="window.open('https://twitter.com/intent/tweet?text=<?=$row['titlu']?>+<?php echo 'https://'.$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]; ?>', 'Publică un tweet pe twitter', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,width=600,height=455');">
<i class="fa fa-twitter w3-large"></i><span class="w3-hide-small"> Twitter</span></button>

<button class="w3-button w3-bar-item w3-green w3-hover-teal w3-padding-small" onclick="window.open('https://api.whatsapp.com/send?text=Am găsit o pagină care te interesa pe <?=BASE_NAME?>, despre: ***<?=$row['titlu']?>***, să arunci o privire când ai timp.', 'Trimite pagina pe WhatsApp', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,width=600,height=455');">
<i class="fa fa-whatsapp w3-large"></i><span class="w3-hide-small"> WhatsApp</span></button>

<button onclick="document.getElementById('trimite_email').style.display='block'" class="w3-button w3-bar-item w3-blue w3-hover-indigo w3-padding-small"><i class="fa fa-envelope-o w3-large"></i><span class="w3-hide-small"> E-mail</span></button>

</div></div>

<div class="w3-map">
<iframe src="https://maps.google.com/maps?q=<?php echo $row['judet']; ?>&t=&z=8&ie=UTF8&iwloc=&output=embed" width="600" height="245" frameborder="0" style="width:100%;border:0;" allowfullscreen=""></iframe>
</div>

<div class="w3-bar w3-div-bottom">
<?php if($usrmobil == true){ $cleanusermobil = str_replace(' ','', $usrmobil);?>
<a href="tel:<?=$cleanusermobil?>" class="w3-button w3-bar-item w3-blue w3-hover-indigo w3-hide-large" style="width:<?php if($usrwhatsapp == true){echo '40%';}else{echo '100%';}?>;"><i class="fa fa-mobile"></i> Sună</a>
<?php }else{ ?>
<a href="#mesaj" class="w3-button w3-bar-item w3-blue w3-hover-indigo w3-hide-small w3-hide-medium" style="width:<?php if($usrwhatsapp == true){echo '40%';}else{echo '100%';}?>;"><i class="fa fa-envelope"></i> Mesaj</a>
<?php } ?>

<?php if($usrwhatsapp == true){ $cleanusrwhatsapp = str_replace(' ','', $usrwhatsapp);?>
<a href="https://api.whatsapp.com/send?phone=<?=$cleanusrwhatsapp?>&text=Vă contactez de pe <?=BASE_NAME?>, în legătură cu anunțul: ***<?=$row['titlu']?>*** și vreau să iau legătura cu dvs. Mulțumesc!" target="_blank" class="w3-button w3-bar-item w3-green w3-hover-teal" style="width:60%;"><i class="fa fa-whatsapp"></i> WhatsApp</a>
<?php } ?>
</div>

</div>

<p class="w3-padding w3-border-bottom"><i class="fa fa-tags"></i>
<?php
$tags = explode(',', $row['etichete']);

foreach ($tags as $tag) {
    $tag = trim($tag);
    echo '<a class="w3-button w3-padding-small" href="#eticheta-' . $tag . '" style="text-decoration:none;">' . $tag . '</a>';
}
?>
</p>

<div class="w3-row w3-border-bottom">
<p style="white-space: pre-line;"><?=$row['descriere']?></p>
<p class="w3-right" style="margin-right:5px;">Vizualizări: <?=$row['vizualizari']?></p>
</div>

<div class="w3-row w3-margin-top" id="mesaj">
<h4>Contactează vânzătorul</h4>
<?php if(isset($_SESSION['user_id']) AND (substr($_SERVER['PHP_SELF'], -10) != 'iesire'.$pagext)) {
if($usrmobil == true){   
?>
<h5>Telefon: <i class="fa fa-phone"></i> <?=$usrmobil?></h5>
<?php } ?>
<label>Trimite un mesaj vanzatorului</label>

<form action="" method="post">
<textarea class="w3-input w3-border w3-round" title="Mesajul tau..." name="mesajutu" style="white-space: pre-line;" required=""></textarea>
<div class="w3-center w3-margin">
<button type="submit" class="w3-button w3-text-white w3-hover-teal" style="background-color:#117594;"><i class="fa fa-envelope-o"></i> Trimite</button> <?php if(isset($mutuok) == '1'){?><span class="w3-text-green">Mesaj trimis</span><?php } if(isset($mutunot) == '1'){?><span class="w3-text-red">Mesajul nu a fost trimis</span><?php } ?>
</div>
<input type="hidden" name="sender" value="<?=$_SESSION['user_id']?>"/>
<input type="hidden" name="receiver" value="<?=$usruid?>"/>
<input type="hidden" name="titluanuntmutu" value="<?=$row['titlu']?>"/>
<input type="hidden" name="msgusertouser" value="true"/>
</form>
<?php } else{ if($usrmobil == true){ ?>
<h5>Telefon: <i class="fa fa-phone"></i> <?php
function mascareNumarTelefon($numar){    
    $masc_numar =  substr($numar, 0, 2) . '- <a onclick="document.getElementById(\'acces\').style.display=\'block\'" class="w3-button w3-text-white w3-hover-teal w3-padding-small" style="background-color:#117594;">autentificare</a>';    
    return $masc_numar;}
echo mascareNumarTelefon($usrmobil);
}
?></h5>  
<label>Trimite un mesaj vanzatorului</label>
<textarea class="w3-input w3-border w3-round" title="Mesajul tau..." disabled="">Trebuie să fi autentificat pentru a transmite un mesaj...</textarea>
<div class="w3-center w3-margin">
<a onclick="document.getElementById('acces').style.display='block'" class="w3-button w3-hover-teal w3-text-white" style="text-decoration:none;background-color:#117594;">Autentificare</a>
<?php } ?>
</div>

</div>

</div>


<div id="trimite_email" class="w3-modal w3-margin-top">
    <div class="w3-modal-content w3-animate-top w3-card-4" style="width:500px;max-width:100%;">
      <header class="w3-container w3-text-white" style="background-color:#117594;"> 
        <span onclick="document.getElementById('trimite_email').style.display='none'" 
        class="w3-button w3-display-topright">&times;</span>
        <h4 style="margin-top:4px;">Trimite anunțul către un prieten</h4>
      </header>
      <div class="w3-container">        
        <div class="w3-row-padding">
<form class="w3-container" action="" method="post">
   <div class="w3-margin-bottom">
   <label>Numele dvs.</label>
   <input class="w3-input w3-border w3-round" type="text" name="numesender" placeholder="Completați numele dvs." required=""/>
   </div>
   <div class="w3-margin-bottom">
   <label>Adresa dvs. de e-mail</label>
   <input class="w3-input w3-border w3-round" type="email" name="emailsender" placeholder="Treceți adresa dvs. de e-mail" required=""/>
   </div>
    <div class="w3-margin-bottom">
   <label>Numele prietenului(ei)</label>
   <input class="w3-input w3-border w3-round" type="text" name="numereceiver" placeholder="Completați numele prietenului(ei) dvs." required=""/>
   </div>
   <div class="w3-margin-bottom">
   <label>Adresa prietenului(ei) de e-mail</label>
   <input class="w3-input w3-border w3-round" type="email" name="emailreceiver" placeholder="Treceți adresa de e-mail a prietenului.." required=""/>
   </div>  
   <div class="w3-margin-bottom">
   <label>Mesaj</label>
   <textarea class="w3-input w3-border w3-round" name="mesajsender" placeholder="Scrieți un mesaj scurt" required=""></textarea>
   </div>   
   <div class="w3-margin-bottom w3-center">
   <button class="w3-button w3-green w3-hover-teal w3-hover-black" type="submit"><i class="fa fa-envelope"></i> Trimite E-mail</button>
   </div>
   <input type="hidden" name="titluanuntemail" value="<?=$row['titlu']?>"/>
   <input type="hidden" name="seoanuntemail" value="<?=$row['seo']?>"/>
   <input type="hidden" name="trimite_email" value="true"/>   
   </form>
</div>        
      </div>
      <footer class="w3-container w3-text-white" style="background-color:#117594;">
        <p class="w3-center" style="margin-top:6px;">Informațiile din acest formular nu se salvează.</p>
      </footer>
    </div>
  </div> 


<?php } else{
$getref = explode("=", $_SERVER["HTTP_REFERER"]);
//echo $getref[4];
//echo $row['aid'];
if($getref[4] == $row['aid']){
    //echo 'Sa trimite e-mail către admin';
// Trimite către Admin
require_once(SML.'Send_Mail.php');
$to = $rwset['aemail'];
$subject = BASE_NAME." :: Anunț nou!";                    
$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ț nou</title>
      </head>
      <body>
      <div style=\"margin:16px;width:800px;max-width:100%;\">
      
      <div style=\"margin:16px;padding:16px;\">
      <p>Bun găsit!</p>
      <p>Un anunț nou a fost adăugat!</p>
      <p>Titlu anunțului: <strong>{$row['titlu']}</strong></p>
      <p>Conținutul anunțului:<br/><em>{$row['descriere']}</em></p>
      <p><a href=\"".BASE_URL."load.php?page=acta&y=1&a=".$row['aid']."\" target=\"_blank\">Aprobă anunțul</a> | <a href=\"".BASE_URL."load.php?page=acta&n=1&a=".$row['aid']."\" target=\"_blank\">Refuză anunțul</a></p>\n\n";
$body .= '<p>După aprobare, anunțul v-a fi publicat la adresa: '.BASE_URL.$row['seo'].'.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);
// END Trimite către Admin 
}

?>
<div class="w3-container w3-card">

<div class="w3-panel w3-padding-16 w3-green w3-text-white w3-center">
<h4>Anunțul este în așteptarea aprobării de către un moderator!</h4>
Veți recepționa un mesaj, când acesta v-a fi publicat.
</div>

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

<div id="modal01" class="w3-modal" onclick="this.style.display='none'">
  <span class="w3-button w3-hover-red w3-xlarge w3-display-topright w3-hide">&times;</span>
  <div class="w3-modal-content w3-animate-zoom">
    <img id="img01" style="width:100%;max-width:100%;max-height:100%;margin:0;padding:0;"/>
  </div>
</div>




<script>
var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(slideIndex += n);
}

function currentSlide(n) {
  showSlides(slideIndex = n);
}

function showSlides(n) {
  var i;
  var slides = document.getElementsByClassName("mySlides");
  var dots = document.getElementsByClassName("demo");
  var captionText = document.getElementById("caption");
  if (n > slides.length) {slideIndex = 1}
  if (n < 1) {slideIndex = slides.length}
  for (i = 0; i < slides.length; i++) {
      slides[i].style.display = "none";
  }
  for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
  }
  slides[slideIndex-1].style.display = "block";
  dots[slideIndex-1].className += " active";
  captionText.innerHTML = dots[slideIndex-1].alt;
}
</script>