<?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'>Мои рефералы</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>
";
?>
<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 -->

<?
echo "<div class='filterlines' style='margin-top: 12px;'>";
echo "<a class='filterline$active1' href='/referals.php?sorting=1'>Все рефераллы</a>";
echo "<a class='filterline$active2' href='/referals.php?sorting=2'>Рабочие</a>";
echo "<a class='filterline$active3' href='/referals.php?sorting=3'>На ярмарке</a>";
echo "<a class='filterline$active4' href='/referals.php?sorting=4'>С бонусами</a>";
echo "</div>";
?>
<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='118px'><b>Логин</b></th>
<th align='center' nowrap='nowrap' width='8px'></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='55px'><img src='/images/narod.png' border='0' width='16' height='16' alt='Рефераллы'></th>
<th align='center' nowrap='nowrap' width='40px'>Доход</th>
<th align='center' nowrap='nowrap' width='110px' style='padding: 4px 12px;' data-sorter="false">Управление</th>

</tr>
</thead><tbody id="ref_show">
<?PHP
$sql = mysql_query("SELECT * FROM `b_users` WHERE `referer`='$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>";
$osql = mysql_query("SELECT `idus` FROM `b_online` WHERE `idus`='".$row["id"]."'") or die(mysql_error());
if(mysql_num_rows($osql) > 0){$online_img = "<img src='/css/images/online.png' align='absmiddle' title='Online'>";}else{$online_img = "<img src='/css/images/offline.png' align='absmiddle' title='Offline'>";}
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><br /><font color='red'>
";
$ref_site = $row["ref_site"];
if($ref_site != ''){echo $ref_site;}else{echo "не определено";}
echo "</font></td>";		
echo "<td class='visit1' nowrap='nowrap'>";
if($row["autoproc"] > 0) {$visible = "";}else{$visible = "style='display:none;'";}
echo "<a id='sref-bonus_".$row["id"]."' class='sref-bonus' title='Установлен бонус: ".$row["autoproc"]."%' $visible></a>";
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='55px' class='visit1' nowrap='nowrap'><span style='color: #b8452a'>".count_referals($row["id"])." шт.</span></td>";
echo "<td class='visit' width='45px' nowrap='nowrap'><span style='color: #009126'>".round($row["toref"],2)."</span></td>";
echo "<td width='112px' nowrap='nowrap'>";
echo "<span class='refdel' title='Исключить рефералла' onclick='dell_ref(".$row["id"].");'></span>";
echo "<span id='success_s_j_".$row["id"]."'>";
if($col_jar > 0){
echo "<a class='refex-back' href='javascript:void(0);' onclick='back_ref(".$row["id"].");' title='Вернуть рефералла с ярмарки'></a>";
}elseif($row["visits"] >= 50){
echo "<a class='refexchange' href='javascript:void(0);' onclick='add_jar(".$row["id"].");' title='Продать на ярмарке'></a>";
}else{
echo "<a class='refex-dis' title='Реферал не готов к продаже'></a>";
}
echo "</span>";
echo "<span class='refbonus' title='Установить/снять бонус' onclick='refback_show(".$row["id"].");'></span>";
echo "<a class='refstat' title='Расширенная статистика' href='javascript:void(0);' onclick='inf_user(".$row["id"].");'></a>";
$cod = mysql_result(mysql_query("SELECT `cod` FROM `b_users` WHERE `id`='".$row["id"]."'"),0);
$tel = mysql_result(mysql_query("SELECT `number` FROM `b_users` WHERE `id`='".$row["id"]."'"),0);
if($cod !=0 AND $tel !=0) {
echo "<a class='refstat1' title='Номер подтверждён'></a>";
}
if($cod ==0 AND $tel ==0) {
echo "<a class='refstat2' title='Номер не подтверждён'></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);}

$(document).ready(function(){
$( ".slider" ).slider({
animate: true,
range: "min",
value: <?=$new_rb?>,
min: 0,
max: 90,
step: 10,
slide: function( event, ui ) {
$( "#slider-result" ).html(ui.value);
},
change: function(event, ui) {
$('#new_rb_num').attr('value', ui.value);
}
});
});
$('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='8'>"+
"<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 new_rb(){
if(!progress){
var num = $.trim($("#new_rb_num").val());
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'new_rb', 'num' : num},
beforeSend: function() {progress = true; $('#info_ref').html('').attr("style", "");},
success: function(data) {
if(data == 1){
$("#info_ref").html("<?=$infstart?> Рефбек успешно выставлен!<?=$infend?>"); tm = setTimeout(function() { hidemsg() }, 3000);
}else if(data == 2){
$("#info_ref").html("<?=$infsterr?> Неверное значение рефбека!<?=$infederr?>"); tm = setTimeout(function() { hidemsg() }, 3000);
}else{$("#info_ref").html("<?=$infsterr?> ERROR!<?=$infederr?>"); tm = setTimeout(function() { hidemsg() }, 3000);}
progress = false;
}
});
}
}

function add_jar(id){
var text = $.trim($("#exblock_"+id).text());
if(text != '') {
$("#exblock_"+id).html("");return false;
}
var jar_form = 
"<tr id='exblock_" + id + "'>"+
"<td class='ext' colspan='8' align='right'>"+
"<input type='text' id='price_ref' size='5' value=''>"+
" <a class='button-flat-green1' href='javascript:void(0);' onclick='send_jar(" + id + ");'>Выставить на продажу</a>"+
"</td></tr>"
$(jar_form).insertAfter("#users_"+id);
}

function send_jar(id){
if(!progress){
var price = $.trim($("#price_ref").val());
var valute = "<?=$sitevalname?>";
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'send_jar', "id_us" : id, "price" : price},
beforeSend: function() {progress = true; $('#info_ref').html('').attr("style", "");},
success: function(data) {
if(data != ''){
$("#info_ref").html("<?=$infstart?>"+data+"<?=$infend?>");tm = setTimeout(function() { hidemsg() }, 3000);
}else{
$("#sale_jar_"+id).attr('title','Продаётся за '+price+''+valute).show('slow');
$("#success_s_j_"+id).html("<a class='refex-back' href='javascript:void(0);' onclick='back_ref("+id+");' title='Вернуть рефералла с ярмарки'></a>");
}
$("#exblock_"+id).remove();
progress = false;
}
});
}
}

function back_ref(id) {
if(!progress){
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'back_ref', "id_us" : id},
beforeSend: function() {progress = true;},
success: function(data) {
$("#sale_jar_"+id).removeAttr('title');
$("#sale_jar_"+id).hide('slow');
$("#success_s_j_"+id).html("<a class='refexchange' onclick='add_jar("+id+");' title='Продать на ярмарке'></a>");
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;
}
});
}
}

function dell_ref(id){
if(!progress){
if(confirm("Вы что хотите исключить реферала?")) {
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'dell_ref', "id" : id},
beforeSend: function() {progress = true;},
success: function(data) {
$("#users_"+id).remove();
progress = false;
}
});
}
}
}
      
function ref_show(num){
if(!progress){
if(num == '') { num = '0'; }
$.ajax({
type: "POST",url: "ajax/referals.php",
data: { 'func' : 'ref_show', "num" : num},
beforeSend: function() {progress = true;},
success: function(data) {
$("#ref_show").html(data);
$('span.filterlineactive').removeClass().addClass( "filterline");
$("#limk_"+num).addClass( "filterlineactive");
progress = false;
}
});
}
}
</script></div>
<?PHP include('footer.php');?>