<?php
if (!defined('webid')) {
    exit();
}

if (!(isset($_SESSION["username"]) && isset($_SESSION["password"]))) {
    header("Location: /");
	exit();
}

$idreferer_con = $_SESSION['iduser'];
$panel_referer_konkurs = mysql_fetch_array(mysql_query("SELECT id FROM konkurs_ref WHERE referername = '".$idreferer_con."' AND status = '1'"));
$panel_moneu = mysql_fetch_array( mysql_query( "SELECT(SELECT sum(balance) FROM konkurs_ref WHERE referername = '" . $_SESSION['iduser'] . "' AND status = '1')balanseref, (SELECT count(*) FROM konkurs_ref WHERE referername = '" . $_SESSION['iduser'] . "' AND status = '1')activerefkon"));

$panel_uhasniki = mysql_query("SELECT `id` FROM `konkurs_ref` WHERE `referername` = '" . $_SESSION['iduser'] . "' AND `status` = '1'" );
while ($panel_uhasniki_row = mysql_fetch_assoc($panel_uhasniki)) 
{
    $panel_uhasniki_temp = mysql_query("SELECT * FROM `konkurs_ref_temp` WHERE `idkonkurs` = '" . $panel_uhasniki_row['id'] . "'" );
	$isx;
	while ($panel_uhasniki_temp_row = mysql_fetch_assoc($panel_uhasniki_temp)) 
	{$isx++;}
}
?>
<script>
	$('.titleref').tipTip({defaultPosition:'left'});
	$('.big_btn_doskas').tipTip({defaultPosition:'left'});
</script>
<h3 style="border-bottom: 1px dotted #cccccc; color: #1c62b9; text-shadow: 0 1px 0 #fafafa;">Управление конкурсами для рефералов</h3>
Здесь представлена для вас некая мини панель управления, вы можете как создавать новые конкурсы, так и отслеживать существующие, смотреть лидеров и всех участников каждого конкурса по отдельности .писать им сообщения, смотреть их стенку, отслеживать любые изменения в реальном времени. Внимание если во время конкурса ваш реферал будет заблокирован, за нарушение правил системы, он не получит приза! Деньги будут переданы либо предыдущему участнику если позволяет набранный им минимум либо вернутся вам на рекламный счет!<br />
<table class='doska_style_stat' style="background: #ebebeb; padding: 1px; padding-top: 5px; padding-bottom: 5px; align: center; margin-top: 8px;" align="center" width='100%' border='0'><br>
    <td >
		<a style="margin-left: 5px;" align="right" width='100%'  class="big_btn_doskas" href="/addconref" title="Создать новый конкурс вашим рефералам">Создать конкурс</a>
	</td>
	<? if($panel_referer_konkurs['id'] > 0) { ?>
    <td><div style="margin-left: 14px; color: #1c62b9;">Активных конкурсов: <? if($panel_moneu['activerefkon'] > 0 ) { echo $panel_moneu['activerefkon']; } else { echo 'нет'; }?></div></td>
	<td><div style="margin-left: 14px; color: #1c62b9;">Бюджет: <?=moneyraund($panel_moneu['balanseref'], 2)?> р.</div></td>
	<td><div style="margin-left: 14px; color: #1c62b9;">Учасники: (<?=$isx?>)</div></td>
	<? } else { ?>
	<td><div style="color: #999999; margin-left: 30px;">На данный момент нет активных конкурсов вашим рефералам!</div></td>
	<? } ?>
</table>
<br>
<h4 style="border-bottom: 1px dotted #1c62b9; color: #1c62b9; text-shadow: 0 1px 0 #fafafa; text-align: right; font-size: 12px; margin-bottom: 3px;">Конкурс серфинга</h4>
<table class="crf" width="100%" border="0" cellpadding="0" cellspacing="1">
<?
$prov_kon_ref = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '1' AND referername = '".$_SESSION['iduser']."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref) > 0) {
    $prov_row_ref = mysql_fetch_array($prov_kon_ref);
    if (time() < $prov_row_ref['end_date']) {
        ?>
		<thead>
			<tr>
				<th colspan="3" style="padding: 5px; background: #ebebeb;">
					<span style="color: #212121; font-size: 12px; font-weight: bold; text-shadow: 0 1px 0 #f7f7f7; "><?=$prov_row_ref['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref['min_type'];?> кликов</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y H:**', $prov_row_ref['start_date'])?> по <?=date('d.m.Y H:**', $prov_row_ref['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref['comrefprice3'] . ' ' . $sitevalname?>
			</td>
		</tr>		
		<thead>
            <th style="background: #ebebeb; padding-top: 5px; padding-bottom: 5px;" width="60">Место</th>
            <th style="background: #ebebeb;">Логин</th>
            <th style="background: #ebebeb;" width="120">Очков</th>
        </thead>
        <?
        $lider_kon1 = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref[min_type]' and type = 1 and idkonkurs	= ".$prov_row_ref['id']."  ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1); $i++) {
                $lider_row = mysql_fetch_array($lider_kon1);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#E0F1AA; color:#616C21"';
                } else {
                    $tabclasx1 = 'style="background:#ffffff; color:#1c62b9"';
                }
                $lider_username = mysql_fetch_array(mysql_query("SELECT username, id, avatar FROM tb_users WHERE id = '$lider_row[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                    <td class="rt" align="left" <?=$tabclasx1?>>
						<a href="/id<?=$lider_username['id']?>"><img src="avp/<?=$lider_username['avatar']?>" width="15" height="15" style="margin-bottom: -3px;" title="Перейти на стенку" class="titleref" /></a>
						&nbsp;<a href="/mail/new<?=$lider_username['id']?>"><img src="theme/img/mail/mail.png" width="16" height="12" border="0" style="position: relative; top: 1px;" title="Написать сообщение" class="titleref"/></a>
						&nbsp;<?=$lider_username['username']?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row['summ']?></td>
                </tr>
                <?
            }
        } else {
			?><tr><td colspan="3" class="rt" align="center" style="background:#ffffff; color:#1c62b9">В этом конкурсе пока еще нет участников!</td></tr><?
		}
    } else {
        echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
    }
} else {
    echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
}
?>
</table>
<h4 style="border-bottom: 1px dotted #1c62b9; color: #1c62b9; text-shadow: 0 1px 0 #fafafa; text-align: right; font-size: 12px; margin-bottom: 3px;">Конкурс оплачиваемых писем</h4>
<table class="crf" width="100%" border="0" cellpadding="0" cellspacing="1">

<?
$prov_kon_ref = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '2' AND referername = '".$_SESSION['iduser']."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref) > 0) {
    $prov_row_ref = mysql_fetch_array($prov_kon_ref);
    if (time() < $prov_row_ref['end_date']) {
        ?>
		<thead>
			<tr>
				<th colspan="3" style="padding: 5px; background: #ebebeb;">
					<span style="color: #212121; font-size: 12px; font-weight: bold; text-shadow: 0 1px 0 #f7f7f7; "><?=$prov_row_ref['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref['min_type'];?> писем</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y H:**', $prov_row_ref['start_date'])?> по <?=date('d.m.Y H:**', $prov_row_ref['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref['comrefprice3'] . ' ' . $sitevalname?>
			</td>
		</tr>		
		<thead>
            <th style="background: #ebebeb; padding-top: 5px; padding-bottom: 5px;" width="60">Место</th>
            <th style="background: #ebebeb;">Логин</th>
            <th style="background: #ebebeb;" width="120">Очков</th>
        </thead>
        <?
        $lider_kon1 = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref[min_type]' and type = 2 and idkonkurs	= ".$prov_row_ref['id']."  ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1); $i++) {
                $lider_row = mysql_fetch_array($lider_kon1);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#E0F1AA; color:#616C21"';
                } else {
                    $tabclasx1 = 'style="background:#ffffff; color:#1c62b9"';
                }
                $lider_username = mysql_fetch_array(mysql_query("SELECT username, id, avatar FROM tb_users WHERE id = '$lider_row[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                        <td class="rt" align="left" <?=$tabclasx1?>>
						<a href="/id<?=$lider_username['id']?>"><img src="avp/<?=$lider_username['avatar']?>" width="15" height="15" style="margin-bottom: -3px;" class="titleref" /></a>
						&nbsp;<a href="/mail/new<?=$lider_username['id']?>"><img src="theme/img/mail/mail.png" width="16" height="12" border="0" style="position: relative; top: 1px;" class="titleref" /></a>
						&nbsp;<?=$lider_username['username']?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row['summ']?></td>
                </tr>
                <?
            }
        } else {
			?><tr><td colspan="3" class="rt" align="center" style="background:#ffffff; color:#1c62b9">В этом конкурсе пока еще нет участников!</td></tr><?
		}
    } else {
        echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
    }
} else {
    echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
}
?>
</table>
<h4 style="border-bottom: 1px dotted #1c62b9; color: #1c62b9; text-shadow: 0 1px 0 #fafafa; text-align: right; font-size: 12px; margin-bottom: 3px;">Конкурс оплачиваемых заданий</h4>
<table class="crf" width="100%" border="0" cellpadding="0" cellspacing="1">

<?
$prov_kon_ref = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '3' AND referername = '".$_SESSION['iduser']."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref) > 0) {
    $prov_row_ref = mysql_fetch_array($prov_kon_ref);
    if (time() < $prov_row_ref['end_date']) {
        ?>
		<thead>
			<tr>
				<th colspan="3" style="padding: 5px; background: #ebebeb;">
					<span style="color: #212121; font-size: 12px; font-weight: bold; text-shadow: 0 1px 0 #f7f7f7; "><?=$prov_row_ref['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref['min_type'];?> заданий</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y H:**', $prov_row_ref['start_date'])?> по <?=date('d.m.Y H:**', $prov_row_ref['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref['comrefprice3'] . ' ' . $sitevalname?>
			</td>
		</tr>		
		<thead>
            <th style="background: #ebebeb; padding-top: 5px; padding-bottom: 5px;" width="60">Место</th>
            <th style="background: #ebebeb;">Логин</th>
            <th style="background: #ebebeb;" width="120">Очков</th>
        </thead>
        <?
        $lider_kon1 = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref[min_type]' and type = 3 and idkonkurs	= ".$prov_row_ref['id']."  ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1); $i++) {
                $lider_row = mysql_fetch_array($lider_kon1);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#E0F1AA; color:#616C21"';
                } else {
                    $tabclasx1 = 'style="background:#ffffff; color:#1c62b9"';
                }
                $lider_username = mysql_fetch_array(mysql_query("SELECT username, id, avatar FROM tb_users WHERE id = '$lider_row[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                        <td class="rt" align="left" <?=$tabclasx1?>>
						<a href="/id<?=$lider_username['id']?>"><img src="avp/<?=$lider_username['avatar']?>" width="15" height="15" style="margin-bottom: -3px;" class="titleref" /></a>
						&nbsp;<a href="/mail/new<?=$lider_username['id']?>"><img src="theme/img/mail/mail.png" width="16" height="12" border="0" style="position: relative; top: 1px;" class="titleref" /></a>
						&nbsp;<?=$lider_username['username']?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row['summ']?></td>
                </tr>
                <?
			}
        } else {
			?><tr><td colspan="3" class="rt" align="center" style="background:#ffffff; color:#1c62b9">В этом конкурсе пока еще нет участников!</td></tr><?
		}
    } else {
        echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
    }
} else {
    echo '<center><h4 style="color:#800000; font-weight:bold">Активных конкурсов нет</h4></center>';
}
?></table><br>
