<?PHP
include('header.php'); 
$num_page = (isset($_GET["pg"])) ? intval($_GET["pg"]) : '0';

function tabl_us($row,$sitevalname){
$about = mysql_fetch_assoc(mysql_query("SELECT `lastlogdate`, `joindate`, `referer`, `avatar`, `reyting` FROM `b_users` WHERE `id`='".$row["rid"]."'"));
$date = date("d.m",$row["timestart"]);
$nowdate = NULL;
$nowdate1 = date("d.m.Y");
$gg = $about["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 = $about["joindate"];
$nowdate .= "<span class='desctext'>$ggj</span>";
if($row["bron"] == 1) {
$stat = "<span class='refbron' title='Реферал забронирован'></span>";
}else{
if($about["referer"] == $_SESSION["iduser"]){
$stat = "<a class='refbay-not' href='javascript:void(0);' title='Снять реферала с продажи' onclick='dell_ref(\"".$row["rid"]."\",\"".$row["rname"]."\");'></a>";
}else{
$stat = "<a class='refbay' onclick='buy_ref(\"".$row["rid"]."\");' href='javascript:void(0);' title='Купить рефералла'></a>";
}
}
$prod = mysql_result(mysql_query("SELECT `username` FROM `b_users` WHERE `id`='".$row["trid"]."'"),0);
echo "<tr id='users_".$row["rid"]."'>";
echo "<td valign='top' align='center'  width='50px'><img style='border: solid 1px #ddd;padding:1px;' src='/avp/".$about["avatar"]."' border='0' width='50' height='50' alt='avatar' /></td>";
echo "<td width='118px'>
<a class='usrname' style='border-bottom: none' href='/users-".$row["rid"]."-wall.html' target='_blank' title='Перейти на стену реферала'><b>".$row["rname"]."</b></a>
<br><span class='desctext'>Рейтинг: ".$about["reyting"]."</span>
<br><span class='desctext'>ID: ".$row["rid"]."</span>
";
echo "</td>";		
echo "<td>";
echo "<span class='desctext'><center>$prod</center></span>";
echo "</td>";		
echo "<td class='visit' width='60px' nowrap='nowrap'>".$nowdate."</td>";
echo "<td align='center' width='50px' class='visit1' nowrap='nowrap'><span style='color: #b8452a'>".count_referals($row["rid"])." шт.</span></td>";
echo "<td class='visit' width='60px' nowrap='nowrap'><span style='color: #009126'>".$row["price"]." Руб.</span></td>";
echo "<td width='15px' onclick=\"inf_user('".$row["rid"]."');\">";
echo "<a class='fair-man' title='Расширенная статистика' href=\"javascript:void(0);\"></a>";
echo "</td>";
echo "<td width='15px' class='buy'>".$stat."</td>";
echo "</tr>";


}


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'>
Основа хорошего заработка на WM Rush — рефералы. 
Это страница на которой можно с лёгкостью преобрести любого реферала к себе в команду.
</td></tr>
</table>";

echo "<div id='info_ref'></div>";
?>
<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 --><br /><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='40px'></th>
<th align='center' nowrap='nowrap' width='100px'><b>Логни</b></th>
<th align='center' nowrap='nowrap' width='100px'><b>Продавец</b></th>
<th align='center' nowrap='nowrap' width='80px' data-sorter="false">Заходил</th>
 <th align='center' nowrap='nowrap' width='10px'><img src='/images/narod.png' border='0' width='16' height='16' alt='Рефераллы'></th>
 <th align='center' nowrap='nowrap'>Цена</th>
 <th align='center' nowrap='nowrap'></th>
 <th align='center' nowrap='nowrap'></th>
 </tr>
 </thead><tbody>
<?PHP
$sql = mysql_query("SELECT * FROM `b_jarmarka` ORDER BY `timestart` DESC");
if(mysql_num_rows($sql) > 0) {
// Формируем массив из 10 статей
while($row = mysql_fetch_assoc($sql)){
echo tabl_us($row,$sitevalname);
}
}
echo "</tbody></table>";
?>
<script> 
$('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 buy_ref(id){
if(!progress){
$.ajax({
type: "POST",url: "ajax/jarmarka.php",
data: { 'func' : 'buy_ref', 'id' : id },
beforeSend: function() {progress = true;},
success: function(data) {
if(data == 1) {
document.location.href = "/cart.html";
}else{
$("#info_ref").html(data);
}
progress = false;
}
});
}
}

function dell_ref(id,usname){
if(!progress){
$.ajax({
type: "POST",url: "ajax/jarmarka.php",
data: { 'func' : 'dell_ref', 'id' : id },
beforeSend: function() {progress = true;},
success: function(data) {
if(data == 1) {
$("#info_ref").html("<?=$infstart?>Реферал снят с продажи<?=$infend?>").fadeOut(2500);
$("#users_"+usname).hide('fast');
}
progress = false;
}
});
}
}

function inf_user(id){
if(!progress){
var text = $.trim($("#infous_"+id).text());
if(text != '') {
$("#infous_"+id).html("");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');?>