<?php
if($campaignData['redirectSet'] != "")
{
$queryRedirect = $connection->query("SELECT * FROM redirects WHERE set_in = $campaignData[redirectSet]");
$datiRedirect = $queryRedirect->fetchAll();

?>
<div class="panel" id="page2" style="display:none">

    <div class="container">

        <div class="row content-row">
            <div class="position-info">
                <div class="position-text">
                    <div class="position-title-wrap">
                        <div class="title"></div>
                        <div class="subtitle"></div>
                    </div>

                    <div class="position-image">
                            <img src="assets/<?php echo $campaignData['front_desktop']; ?>" alt="" class="pure-pic packshot-large" /> <!-- immagine front desktop form -->
                            <img src="assets/<?php echo $campaignData['front_mobile']; ?>" alt="" class="pure-pic packshot-small" /> <!-- immagine front mobile form -->
                        </div>
                </div>
            </div>

<div class="position-form">
                <div class="form-title"></div>

                                <div class="questionfield"> <!-- contenitore-domande -->
                    <div class="questions_list-header"> <!-- titolo sezione domande, dinamicizzare testo e numero domande -->
                        <span>Per aumentare le tue chance di vincita, condividi il concorso con almeno 3 amici!</span>
                    </div>
                    <div class="questions_list">
            
            <div class="gutschein">Rimangono:
                    <span id="gutschein"><i>in aggiornamento...</i></span> Coupon
                    </div>           
            
           <div id="wabutton"> 
            <?php 

            

            $estrai = rand(0,count($datiRedirect)-1);

            $sharingUrl = $datiRedirect[$estrai]['url'];
            ?>
            <a href="whatsapp://send?text=*<?php echo $campaignData['sharingText']; ?>.<?php echo $sharingUrl; ?>">
            <div id="b1" class="wa">
                <img style="max-height:20px;" src="../campaignsAssets/images/whatsapp.png">
                <span style="margin-left:5px; ">WhatsApp</span>
            </div>
        </a>
    </div>

        <div id="caricamento" style="display: none; margin-top: 15px;">
        <center><b></b>Attendere prego, verifica condivisione in corso...<b></b></center>
        <img id="laden" class="img-responsive center-block" style="padding:10px;" src="../campaignsAssets/images/loading.gif" >    
        
        </div>

<div class="comment-area">
            <div class="action">
                <a class="like" href="javascript: void(0);">Mi piace</a>
                <a class="bubble" href="javascript: void(0);">Commenta</a>
                <a class="share-btn" href="javascript: void(0);">Condividi</a>
            </div>

       
            <div class="tot-likes">
                <div class="like-imgs">

<?php 
$totSmall = count(scandir("../campaignsAssets/images/avtr/lk"))-2;

$avatars = scandir("../campaignsAssets/images/avtr/cm");
$avatars = array_slice($avatars,2,count($avatars)-2);
$totAvatars = count($avatars);

$arrayReactions = array("btn","love"); 

$arraySmall = range(1,$totSmall);
$arrayAvatars = range(1,$totAvatars);


shuffle($arraySmall);
$arraySmall = array_slice($arraySmall ,0,12);
shuffle($avatars);



for($as = 0; $as < 9; $as++)
{
    $reaction = rand(0,1);
?> 
  <div><img src="../campaignsAssets/images/avtr/lk/img<?php echo $arraySmall[$as]; ?>.jpg" width="32" height="32" /><img class="reaction-img" src="../campaignsAssets/images/<?php echo $arrayReactions[$reaction]; ?>.png" width="16" height="16" /></div> 

 <?php 
}

?>                      

                </div>
                <p>A <span class="you">te e altre</span> <?php echo rand(15000,50000); ?> persone piace questo elemento.</p>
            </div>

<?php 
// dinamicizzazione commenti

$queryCommenti = $connection->query("SELECT * FROM comments WHERE sets_in = $campaignData[commentsSet] AND isChildren = '0'");
$datiCommenti = $queryCommenti->fetchAll();

$avatarCount = 0;

$quanti = count($datiCommenti)*5;

$nomiDonne = $connection->query("SELECT nome FROM lista_nomi WHERE sesso = 'f' ORDER BY RAND() LIMIT 0,$quanti");
$nomiDonne = $nomiDonne->fetchAll();

$nomiUomini = $connection->query("SELECT nome FROM lista_nomi WHERE sesso = 'm' ORDER BY RAND() LIMIT 0,$quanti");
$nomiUomini = $nomiUomini->fetchAll();


$estraiCognomi = $connection->query("SELECT cognome FROM lista_cognomi ORDER BY RAND() LIMIT 0,$quanti");
$cognomi= $estraiCognomi->fetchAll();
$in = 0;
$nascosti = 0;

for($c = 0; $c < count($datiCommenti); $c++)
{
    $infoCommento = $datiCommenti[$c];
    $idCommento = $infoCommento['id'];
    $testoCommento = $infoCommento['text'];

    $avatarCommento = $avatars[$avatarCount];


    $sessoAvatar = substr($avatarCommento,strlen($avatarCommento)-5,1);

    if($sessoAvatar == "m")
    {
       $nome =  ucfirst(strtolower($nomiUomini[$in]['nome']));
    }
    else if($sessoAvatar == "f")
    {
        $nome =  ucfirst(strtolower($nomiDonne[$in]['nome']));
    }
    else
    {
        $nome =  ucfirst(strtolower($nomiUomini[$in]['nome'])) . " " .  ucfirst(strtolower($nomiDonne[$in]['nome']));
    }

    $cognome = ucfirst(strtolower($cognomi[$in]['cognome']));

$nascondiParent = false;
    $nascondi = rand(0,10);

  if($nascondi > 5)
  {
    $nascondiParent = true;
    $nascondi = true;
    $hider ="hider";
    $tempo = "<1 minuto"; 
    $likes = rand(1,3);
    $nascosti++;
  }
  else
  {
    $nascondi = false;
    $hider = "";
    $tempo = rand(5,50) . " minuti";
    $likes = rand(10,90);
  }
?>
<div class="comment <?php echo $hider; ?>" <?php if($nascondi){ ?> id="com<?php echo $nascosti ?>" <?php } ?> >
                <img class="profile" src="../campaignsAssets/images/avtr/cm/<?php echo $avatarCommento; ?>" width="50" height="50" />
                <p class="com-txt"><a class="name" href="javascript:void(0);"><?php echo $cognome ?> <?php echo $nome; ?></a>
                 <?php echo $testoCommento; ?></p>
                <div class="act">
                    <a class="fblike" href="javascript:void(0);">Mi piace</a> · 
                    <a href="javascript:void(0);">Rispondi</a> · 
                    <span class="liked"><?php echo $likes ?></span>
                    <span class="time"><?php echo $tempo; ?></span>
                </div>
<?php
    // controllo se ci sono commenti figli
    $queryCommentiFigli = $connection->query("SELECT * FROM comments WHERE parentComment = '$idCommento'");
    $datiFigli =  $queryCommentiFigli->fetchAll();
    if(count($datiFigli) > 0)
    {

    for($cf = 0; $cf < count($datiFigli); $cf++)
    {
        $in++;

        $avatarCount++;

        $infoCommentoF = $datiFigli[$cf];
        $testoCommentoF = $infoCommentoF['text'];

    $avatarCommento = $avatars[$avatarCount];
    

    $sessoAvatar = substr($avatarCommento,strlen($avatarCommento)-5,1);
    

   if($sessoAvatar == "m")
    {
       $nome = ucfirst(strtolower($nomiUomini[$in]['nome']));
    }
    else if($sessoAvatar == "f")
    {
        $nome =  ucfirst(strtolower($nomiDonne[$in]['nome']));
    }
    else
    {
        $nome =  ucfirst(strtolower($nomiUomini[$in]['nome'])) . " " .  ucfirst(strtolower($nomiDonne[$in]['nome']));
    }

  $cognome = ucfirst(strtolower($cognomi[$in]['cognome']));

        // aggiungere classe hider per nascondere il commento
        // usare l'id con dicitura com+N per effetto comparsa (modificare anche js)


  $nascondi = rand(0,10);

  if($nascondi > 5 || $nascondiParent == true)
  {
    $nascondi = true;
    $hider = "hider";
    $tempo = "<1 minuto"; 
    $likes = rand(1,4);
    $nascosti++;
  }
  else
  {
    $nascondi = false;
    $hider = "";
    $tempo = rand(5,50) . " minuti";
    $likes = rand(10,90);
  }
        
?>
<div class="comment <?php echo $hider; ?>" <?php if($nascondi){ ?> id="com<?php echo $nascosti ?>" <?php } ?> > 
                    <img class="profile" src="../campaignsAssets/images/avtr/cm/<?php echo $avatarCommento; ?>" width="50" height="50" />
                    <p class="com-txt"><a class="name" href="javascript:void(0);"><?php echo $cognome; ?> <?php echo $nome; ?></a>
                    <?php echo $testoCommentoF; ?></p>
                    
                    <div class="act">
                        <a class="fblike" href="javascript:void(0);">Mi piace</a> · 
                        <a href="javascript:void(0);">Rispondi</a> · 
                        <span class="liked"><?php echo $likes; ?></span>
                        <span class="time"><?php echo $tempo; ?></span>
                    </div>
                </div>
<?php     

    }        
    }
?>
</div>
<?php

$avatarCount++;
$in++;
}

?>

            
            <div id="myCom" class="comment">
                    <img class="profile" src="../campaignsAssets/images/generic.jpg" width="50" height="50" />
                    <p class="com-txt"><a class="name" href="javascript:void(0);">Tu</a>
                    <span id="myComment"></span></p>
                    <div class="act">
                        <a class="fblike" href="javascript:void(0);">Mi piace</a> · 
                        <a href="javascript:void(0);">Rispondi</a> · 
                        <span class="liked likehide"></span>
                        <span class="time">< 1 minuto</span>
                    </div>
                </div>
            <div class="addComment">
                <img src="../campaignsAssets/images/generic.jpg" width="50" height="50" />
                <input type="text" id="addCom" placeholder="Scrivi un commento..." />
            </div>
        </div>        
        
        </div>
    </div>

        </div>
    </div>

    </div>

    <script>
    window.hiddenNum = <?php echo $nascosti; ?>;
</script>

</div> 
<?php
}
?>