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

if (!(isset($_SESSION["username"]) && isset($_SESSION["password"]))) {
    header("Location: /");
	exit();
}
?>
<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 />
<h4 style="border-bottom: 1px dotted #999999; 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">

<?
$idrefa_u = mysql_result(mysql_query("SELECT referer FROM tb_users WHERE id = '" . $_SESSION['iduser'] . "'"), 0);
$prov_kon_ref_u = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '1' AND referername = '".$idrefa_u."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref_u) > 0) {
    $prov_row_ref_u = mysql_fetch_array($prov_kon_ref_u);
    if (time() < $prov_row_ref_u['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_u['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref_u['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref_u['min_type'];?> кликов</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y (H - часов)', $prov_row_ref_u['start_date'])?> по <?=date('d.m.Y (H - часов)', $prov_row_ref_u['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref_u['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref_u['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref_u['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_u = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref_u[min_type]' and type = 1 and idkonkurs = ".$prov_row_ref_u['id']." AND summ >= '".$prov_row_ref_u['min_type']."' ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1_u) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1_u); $i++) {
                $lider_row_u = mysql_fetch_array($lider_kon1_u);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#F0F8FF; color:#4682B4"';
                } 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_u[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                    <td class="rt" align="left" <?=$tabclasx1?>>
						<?=$lider_username['username']; if($lider_username['username'] == $_SESSION['username']) { echo '<div style="color: #990033; text-align: right; margin-top: -15px;">Это вы!</div>'; }?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row_u['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 #999999; 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">

<?
$idrefa_u = mysql_result(mysql_query("SELECT referer FROM tb_users WHERE id = '" . $_SESSION['iduser'] . "'"), 0);
$prov_kon_ref_u = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '2' AND referername = '".$idrefa_u."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref_u) > 0) {
    $prov_row_ref_u = mysql_fetch_array($prov_kon_ref_u);
    if (time() < $prov_row_ref_u['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_u['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref_u['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref_u['min_type'];?> писем</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y (H - часов)', $prov_row_ref_u['start_date'])?> по <?=date('d.m.Y (H - часов)', $prov_row_ref_u['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref_u['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref_u['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref_u['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_u = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref_u[min_type]' and type = 2 and idkonkurs = ".$prov_row_ref_u['id']." AND summ >= '".$prov_row_ref_u['min_type']."' ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1_u) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1_u); $i++) {
                $lider_row_u = mysql_fetch_array($lider_kon1_u);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#F0F8FF; color:#4682B4"';
                } 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_u[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                    <td class="rt" align="left" <?=$tabclasx1?>>
						<?=$lider_username['username']; if($lider_username['username'] == $_SESSION['username']) { echo '<div style="color: #990033; text-align: right; margin-top: -15px;">Это вы!</div>'; }?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row_u['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 #999999; 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">

<?
$idrefa_u = mysql_result(mysql_query("SELECT referer FROM tb_users WHERE id = '" . $_SESSION['iduser'] . "'"), 0);
$prov_kon_ref_u = mysql_query("SELECT * FROM konkurs_ref WHERE status = '1' AND type = '3' AND referername = '".$idrefa_u."' ORDER by id DESC");
if (mysql_num_rows($prov_kon_ref_u) > 0) {
    $prov_row_ref_u = mysql_fetch_array($prov_kon_ref_u);
    if (time() < $prov_row_ref_u['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_u['name']?></span>
				</th>
			</tr>
		</thead>
		<tr>
			<td colspan="3" style="background: #ebebeb; padding: 5px;" align="left"><?=$prov_row_ref_u['description']?></td>
		</tr>
		<tr>
			<td class="lt">Минимум</td>
			<td colspan="2" class="rt"><?=$prov_row_ref_u['min_type'];?> заданий</td>
		</tr>		
		<tr>
			<td class="lt">Дата</td>
			<td colspan="3" class="rt">с <?=date('d.m.Y (H - часов)', $prov_row_ref_u['start_date'])?> по <?=date('d.m.Y (H - часов)', $prov_row_ref_u['end_date'])?></td>
		</tr>		
		<tr>
			<td class="lt">Призы</td>
			<td colspan="3" class="rt">
				I-e место <?=$prov_row_ref_u['comrefprice1'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				II-e место <?=$prov_row_ref_u['comrefprice2'] . ' ' . $sitevalname?>&nbsp;&nbsp;&nbsp;
				III-e место <?=$prov_row_ref_u['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_u = mysql_query("SELECT * FROM konkurs_ref_temp WHERE summ >= '$prov_row_ref_u[min_type]' and type = 3 and idkonkurs = ".$prov_row_ref_u['id']." AND summ >= '".$prov_row_ref_u['min_type']."' ORDER BY summ DESC");
        if (mysql_num_rows($lider_kon1_u) > 0) {
            for ($i = 1; $i <= mysql_num_rows($lider_kon1_u); $i++) {
                $lider_row_u = mysql_fetch_array($lider_kon1_u);
                if ($i <= 3) {
                    $tabclasx1 = 'style="background:#F0F8FF; color:#4682B4"';
                } 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_u[iduser]'"));
                ?>
                <tr>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$i?></td>
                    <td class="rt" align="left" <?=$tabclasx1?>>
						<?=$lider_username['username']; if($lider_username['username'] == $_SESSION['username']) { echo '<div style="color: #990033; text-align: right; margin-top: -15px;">Это вы!</div>'; }?>
					</td>
                    <td class="rt" align="center" <?=$tabclasx1?>><?=$lider_row_u['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>