<?php userstatus();

$ebene_1 = false;
$ebene_2 = false;
$ebene_3 = false;

$ebene1 = db_query("SELECT werber.*, u.nickname, k.last_active FROM
                         ".$db_prefix."_werberdaten AS werber
                         LEFT JOIN ".$db_prefix."_userdaten AS u ON u.uid = werber.uid
                         LEFT JOIN ".$db_prefix."_kontodaten AS k ON k.uid = werber.uid
                   WHERE werber.werber=".$_SESSION['uid']." ORDER BY u.nickname ASC");

if (mysqli_num_rows($ebene1)){
   while ($user1 = mysqli_fetch_assoc($ebene1)){
   $ebene_1 = true;
   $count++;
   if ($count % 2 == 0){$row = 0;}else{$row = 1;}

    if ($user1['last_active'] >= (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:green;" alt="'.date("d.m.y - H:i",$user1['last_active']).'"></span>';
    if ($user1['last_active'] < (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:yellow;" alt="'.date("d.m.y - H:i",$user1['last_active']).'"></span>';
    if ($user1['last_active'] <= (time()-(86400*30))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:red;" alt="'.date("d.m.y - H:i",$user1['last_active']).'"></span>';

    $anz .= '
    <tr class="tr_row'.$row.'">
        <td align="center"><a href="?content=/nickpage&amp;nick='.$user1['nickname'].'">'.$user1['nickname'].'</a></td>
        <td align="center">'.number_format($user1['umsatz']/100*$pageconfig['re1'],2,",",".").'</td>
        <td align="center">'.number_format($user1['gesamt'],2,",",".").'</td>
        <td align="center">'.$user1['refback'].'%</td>
        <td align="center"><a href="?content=/konto/refdetails&amp;ruid='.$user1['uid'].'" target="_self">Details</a></td>
        <td align="center">'.$refstatus.'</td>
    </tr>
    ';
$ebene2 = db_query("SELECT werber.*, u.nickname, k.last_active FROM
                         ".$db_prefix."_werberdaten AS werber
                         LEFT JOIN ".$db_prefix."_userdaten AS u ON u.uid = werber.uid
                         LEFT JOIN ".$db_prefix."_kontodaten AS k ON k.uid = werber.uid
                   WHERE werber.werber=".$user1['uid']." ORDER BY u.nickname ASC");

      while ($user2 = mysqli_fetch_assoc($ebene2)){
      $ebene_2 = true;
      $count++;
      if ($count % 2 == 0){$row = 0;}else{$row = 1;}

      if ($user2['last_active'] >= (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:green;" alt="'.date("d.m.y - H:i",$user2['last_active']).'"></span>';
      if ($user2['last_active'] < (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:yellow;" alt="'.date("d.m.y - H:i",$user2['last_active']).'"></span>';
      if ($user2['last_active'] <= (time()-(86400*30))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:red;" alt="'.date("d.m.y - H:i",$user2['last_active']).'"></span>';

      $anz2 .= '
      <tr class="tr_row'.$row.'">
        <td align="center"><a href="?content=/nickpage&amp;nick='.$user2['nickname'].'">'.$user2['nickname'].'</a></td>
        <td align="center">'.$user1['nickname'].'</td>
        <td align="center">'.number_format($user2['umsatz']/100*$pageconfig['re2'],2,",",".").'</td>
        <td align="center">'.number_format($user2['gesamt'],2,",",".").'</td>
        <td align="center">'.$refstatus.'</td>
      </tr>
      ';

$ebene3 = db_query("SELECT werber.*, u.nickname, k.last_active FROM
                         ".$db_prefix."_werberdaten AS werber
                         LEFT JOIN ".$db_prefix."_userdaten AS u ON u.uid = werber.uid
                         LEFT JOIN ".$db_prefix."_kontodaten AS k ON k.uid = werber.uid
                   WHERE werber.werber=".$user2['uid']." ORDER BY u.nickname ASC");

        while ($user3 = mysqli_fetch_assoc($ebene3)){
        $ebene_3 = true;
        $count++;
        if ($count % 2 == 0){$row = 0;}else{$row = 1;}

         if ($user3['last_active'] >= (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:green;" alt="'.date("d.m.y - H:i",$user3['last_active']).'"></span>';
         if ($user3['last_active'] < (time()-(86400*7))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:yellow;" alt="'.date("d.m.y - H:i",$user3['last_active']).'"></span>';
         if ($user3['last_active'] <= (time()-(86400*30))) $refstatus = '<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:red;" alt="'.date("d.m.y - H:i",$user3['last_active']).'"></span>';

         $anz3 .= '
         <tr class="tr_row'.$row.'">
            <td align="center"><a href="?content=/nickpage&amp;nick='.$user3['nickname'].'">'.$user3['nickname'].'</a></td>
            <td align="center">'.$user2['nickname'].'</td>
            <td align="center">'.number_format($user3['umsatz']/100*$pageconfig['re3'],2,",",".").'</td>
            <td align="center">'.number_format($user3['gesamt'],2,",",".").'</td>
            <td align="center">'.$refstatus.'</td>
         </tr>
               ';

        }
      }

   }

}

head("Refübersicht");?>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<b><big>EBENE 1 </big><font color="green">&nbsp;&nbsp;( <?php echo number_format($pageconfig['re1']);?>% )</font></b>
<br><br>
<?php if($ebene_1 == true){?>
<table width="100%" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr class="tr_head">
<td align="center" width="20%"><b>User</b></td>
<td align="center" width="20%"><b>Heute</b></td>
<td align="center" width="20%"><b>Gesamt</b></td>
<td align="center" width="20%"><b>Refback</b></td>
<td align="center" width="10%"><b>Details</b></td>
<td align="center" width="10%"><b>Status</b></td>
</tr>
<?php echo $anz;?>
</table>
<?php }else{
echo "<center>Noch keine Refs in Ebene 1</center>";
}

if ($pageconfig['re2'] > 0){?>
<br><hr width="90%"><br>
&nbsp;&nbsp;&nbsp;&nbsp;<b><big>EBENE 2 </big><font color="green">&nbsp;&nbsp;( <?php echo number_format($pageconfig['re2']);?>% )</font></b>
<br><br>
<?php
if ($ebene_2 == true){ ?>
<table width="100%" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr class="tr_head">
<td align="center" width="20%"><b>User</b></td>
<td align="center" width="20%"><b>Werber</b></td>
<td align="center" width="25%"><b>Heute</b></td>
<td align="center" width="25%"><b>Gesamt</b></td>
<td align="center" width="10%"><b>Status</b></td>
</tr>
<?php echo $anz2;?>
</table>
<?php }else{
echo "<center>Noch keine Refs in Ebene 2</center>";
} } 

if ($pageconfig['re3'] > 0){?>
<br><hr width="90%"><br>
&nbsp;&nbsp;&nbsp;&nbsp;<b><big>EBENE 3 </big><font color="green">&nbsp;&nbsp;( <?php echo number_format($pageconfig['re3']);?>% )</font></b>
<br><br>
<?php
if ($ebene_3 == true){?>
<table width="100%" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr class="tr_head">
<td align="center" width="20%"><b>User</b></td>
<td align="center" width="20%"><b>Werber</b></td>
<td align="center" width="25%"><b>Heute</b></td>
<td align="center" width="25%"><b>Gesamt</b></td>
<td align="center" width="10%"><b>Status</b></td>
</tr>
<?php echo $anz3;?>
</table>
<?php }else{
echo "<center>Noch keine Refs in Ebene 3</center>";

} }?>

<br><hr width="90%"><br><center>
<table width="60%" cellpadding="3" cellspacing="1" border="0"><tr><td><center>
<b>Infos zur Refübersicht:</b><br><br>
<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:red;"></span> User war mind. 30 Tage nicht mehr aktiv.<br>
<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:yellow;"></span> User war mind. 7 Tage nicht mehr aktiv.<br>
<span class="glyphicon glyphicon-certificate" aria-hidden="true" style="color:green;"></span> User war in den letzen 7 Tagen aktiv.<br></center>
</td></tr></table></center>
<?php foot();?>