<?PHP
include('header.php'); 
$sorting = (isset($_GET["sorting"])) ? valideint($_GET["sorting"]) : '1';
$active1 = $active2 = $active3 = $active4 = NULL;
switch($sorting){
case 1:$active1 = "active"; $sql_req = "ORDER BY `id` DESC";break;
case 2:$active2 = "active"; $sql_req = "AND `toref`>'0'";break;
case 3:$active3 = "active"; $sql_req = "AND `id` IN (SELECT `rid` FROM `b_jarmarka`)";break;
case 4:$active4 = "active"; $sql_req = "AND `autoproc`>'0'";break;
default:$active1 = "active"; $sql_req = "ORDER BY `joindate` DESC";
}
echo "<span class='top-bl-s-verh'>Мои рефералы 2-го уровня</span>
<div class='menucenter-top1'>
<table class='profile' width='100%' border='0' cellpadding='0' cellspacing='0' style='margin-bottom: 0;'>
<tr><td class='value1'>
Это страница управления вашей коммандой. Можно узнать какие рефералы самые активные и посмотреть их статистику!
</td></tr>
</table><br />";
?>
<script type="text/javascript" src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="/js/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/js/jquery.tablesorter.widgets.js"></script>
<script type="text/javascript" src="/js/jquery.tablesorter.pager.js"></script> 
<!-- pager --> 
<div class="pager" style='text-align:center;'> 
<img src="/css/images/prev.png" align="left" style="margin-left:30px; padding-bottom:10px;" class="prev"/> 
<span class="desctext">Страницы</span>
<img src="/css/images/next.png" align="right" style="margin-right:30px; padding-bottom:10px;" class="next"/>
</div><br />

<table class="referals" id="tablesorter" width='100%' border='0' cellpadding='0' cellspacing='0'>
<thead>
<tr>
<th align='center' nowrap='nowrap' width='60px'></th>
<th align='left' nowrap='nowrap' width='128px'><b>Логин</b></th>
<th align='center' nowrap='nowrap' width='10px'></th>
<th align='center' nowrap='nowrap' width='10px'></th>
<th align='center' nowrap='nowrap' width='45px' data-sorter="false">Заходил</th>
<th align='center' nowrap='nowrap' width='45px'><img src='/images/narod.png' border='0' width='16' height='16' alt='Рефераллы'></th>
<th align='center' nowrap='nowrap' width='45px'>Доход</th>
<th align='center' nowrap='nowrap' width='105px' style='padding: 4px 12px;' data-sorter="false">Управление</th>

</tr>
</thead><tbody>
<?PHP
$sql = mysql_query("SELECT * FROM `b_users` WHERE `referer2`='$id_user' $sql_req") or die(mysql_error());
if(mysql_num_rows($sql) > 0){
while($row=mysql_fetch_assoc($sql)){
$iid=$row["id"];

echo "<tr id='users_".$row["id"]."'>";
echo "<td valign='top' align='center'><img style='border: solid 1px #ddd;padding:1px;' src='/avp/".$row["avatar"]."' border='0' width='50' height='50' alt='avatar' /></td>";

echo "<td>
<a class='usrname' style='border-bottom: none' href='/users-".$row["id"]."-wall.html' target='_blank' title='Перейти на стену реферала'><b>".$row["username"]."</b></a>
<br>
<span class='desctext'>Рейтинг: <span style='color: #34A305'>
".$row["reyting"]."
<br><span class='desctext'>ID: ".$row["id"]."</span>
";
echo "</td>";		
echo "<td class='visit1' nowrap='nowrap'>";
if($row["autoproc"] > 0) {$visible = "";}else{$visible = "style='display:none;'";}
echo "<span id='sref-bonus_".$row["id"]."' class='sref-bonus' title='Установлен бонус: ".$row["autoproc"]."%' $visible></span>";
echo "</td>";
echo "<td>";
$zz = mysql_query("SELECT `price` FROM `b_jarmarka` WHERE `rid`='".$row["id"]."'") or die(mysql_error());
$col_jar = mysql_num_rows($zz);
if($col_jar > 0) {	
$zzz=mysql_fetch_assoc($zz);
$price_jar = $zzz["price"];
$vis_j = "";
}else{$price_jar = NULL;$vis_j = "style='display:none;'";}
echo "<span id='sale_jar_".$row["id"]."' class='sref-jarmarka' title='Продаётся за $price_jar $sitevalname' $vis_j></span>";
$nowdate = '';
$nowdate1 = date("d.m.Y");
$gg = $row["lastlogdate"];
if($nowdate1==$gg) { $nowdate="<span style='color: #009126'>Сегодня</span><br />";
}elseif($gg == ''){
$nowdate = "<span style='color: #F78383'>Еще не заходил</span><br />";
}else{ $nowdate = "$gg<br />";
}
$ggj = $row["joindate"];
$nowdate .= "<span class='desctext'>$ggj</span>";
echo "</td>";		
echo "<td class='visit' width='60px' nowrap='nowrap'>".$nowdate."</td>";
echo "<td align='center' width='30px' class='visit1' nowrap='nowrap'><span style='color: #b8452a'>".count_referals($row["id"])." шт.</span></td>";
echo "<td class='visit' width='50px' nowrap='nowrap'><span style='color: #009126'>".round($row["toref"],2)."</span></td>";
echo "<td width='84px' nowrap='nowrap'>";
echo "<a class='refstat' title='Расширенная статистика' href='javascript:void(0);' onclick='inf_user(".$row["id"].");'></a>";
echo "</td></tr>";

if(isset($_GET["stat"]) && $_GET["stat"]==$row["id"]){
 require('statistika/stat_diogram.php');
 initstat($row["username"],1); 
 } ?>
<?
}
}else{
echo "<br /><center>У Вас нет рефералов</center>";
}
?>
</tbody></table>
 
<script>
function hidemsg(){ $('#info_ref').fadeOut('slow'); $("#iinfo_ref").attr("style", ""); if(tm)clearTimeout(tm);}

$('table').tablesorter({
    theme: 'green',
    sortInitialOrder: "desc"
}).tablesorterPager({
    container: $(".pager"),
    page: 0,
    size: 10,
    cssNext: '.next',
    cssPrev: '.prev',
    cssFirst: '.first',
    cssLast: '.last',
    cssGoto: '.gotoPage',
    cssPageDisplay: '.pagedisplay',
    cssPageSize: '.pagesize',
    cssDisabled: 'disabled'
});

var progress = false;

function refback_show(id){
var text = $.trim($("#bonusadd_"+id).text());
if(text != '') {
$("#bonusadd_"+id).html("");return false;
}
var proc_form = 
"<tr id='bonusadd_" + id + "'>"+
"<td class='ext' colspan='6'>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",0);'>нет</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",10);'>10%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",20);'>20%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",30);'>30%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",40);'>40%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",50);'>50%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",60);'>60%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",70);'>70%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",80);'>80%</a>"+
"<a class='addbudget' href='javascript:void(0);' onclick='refback_add(" + id + ",90);'>90%</a>"+
"</td></tr>";
$(proc_form).insertAfter("#users_"+id);
}

function refback_add(id, num){
if(!progress){
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'refback_add', "id_us" : id, "num" : num},
beforeSend: function() {progress = true;},
success: function(data) {
$("#sref-bonus_"+id).removeAttr('title');
if(num == 0){
$("#sref-bonus_"+id).hide('slow');
}else{
$("#sref-bonus_"+id).attr('title','Установлен бонус: '+num+'%').show('slow');
}
$("#bonusadd_"+id).remove();
progress = false;
}
});
}
}

function inf_user(id){
if(!progress){
var text = $.trim($("#infous_"+id).text());
if(text != '') {
$("#infous_"+id).remove(); return false;
}
$.ajax({
type: "POST",url: "ajax/inf_user.php",
data: { 'func' : 'inf_user', 'id' : id },
beforeSend: function() {progress = true;},
success: function(data) {
$(data).insertAfter("#users_"+id);
progress = false;
}
});
}
}
</script></div>
<?PHP include('footer.php');?>