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

if ($user_status != 'admin') {
    exit();
}
//сортировка выручки
if (isset($_POST['zapros'])) {
    $zapros = "month = '" . $_POST['month'] . "' and year = '" . $_POST['year'] . "'";
} else {
    $zapros = "month = '" . date('m', time()) . "' and year = '" . date('Y', time()) . "'";
}
//снять деньги с проета
if (isset($_POST['vzyt'])) {
    $sumget = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka")) or die(mysql_error());
    mysql_query("INSERT INTO tb_getmoney (money, date) VALUES ('$sumget[sum]', '" . time() . "')") or die(mysql_error());
    mysql_query("DELETE FROM tb_viruchka");
}
//заметки
if (isset($_POST['addnotepad'])) {
	$sql = mysql_query("SELECT id FROM tb_notepad");
	if (mysql_num_rows($sql) == 0) {
	    mysql_query("INSERT INTO tb_notepad (text) VALUES ('$_POST[notepad]')");
	} else {
	    mysql_query("UPDATE tb_notepad SET text = '$_POST[notepad]' WHERE id = 1");
	}
}
//сброс снятых денег
if (isset($_POST['reset'])) {
    mysql_query("DELETE FROM tb_getmoney");
}

$getnotepad = mysql_fetch_array(mysql_query("SELECT text FROM tb_notepad WHERE id = 1"));

$vivel = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_getmoney"));
if ($vivel['sum'] == ''){$vivel = 0.00;}

$summ1 = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros"));
if ($summ1['sum'] == ''){$summ1 = 0.00;}

$summ2 = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka"));

$sumdyn = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 1"));
if ($sumdyn['sum'] == ''){$sumdyn['sum'] = 0.00;}

$sumpm = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 2"));
if ($sumpm['sum'] == ''){$sumpm['sum'] = 0.00;}

$sumtask = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 3"));
if ($sumtask['sum'] == ''){$sumtask['sum'] = 0.00;}

$sumstatlink = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 4"));
if ($sumstatlink['sum'] == ''){$sumstatlink['sum'] = 0.00;}

$sumban1 = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 5"));
if ($sumban1['sum'] == ''){$sumban1['sum'] = 0.00;}

$sumgolos = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 6"));
if ($sumgolos['sum'] == ''){$sumgolos['sum'] = 0.00;}

$sumbirj = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 7"));
if ($sumbirj['sum'] == ''){$sumbirj['sum'] = 0.00;}

$summasref = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 8"));
if ($summasref['sum'] == ''){$summasref['sum'] = 0.00;}

$sumwakeref = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 9"));
if ($sumwakeref['sum'] == ''){$sumwakeref['sum'] = 0.00;}

$sumfine = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 10"));
if ($sumfine['sum'] == ''){$sumfine['sum'] = 0.00;}

$sumcep = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 11"));
if ($sumcep['sum'] == ''){$sumcep['sum'] = 0.00;}

$sumkonref = mysql_fetch_array(mysql_query("SELECT SUM(money) as sum FROM tb_viruchka WHERE $zapros and ident = 12"));
if ($sumkonref['sum'] == ''){$sumkonref['sum'] = 0.00;}
?>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="50%" align="center" valign="top">
<table width="450" border="0" cellpadding="0" cellspacing="1" class="tab">
    <thead>
        <th colspan="3" align="center" style="background: #ebebeb; padding: 3px; color: #800000;">ПРИБЫЛЬ</th>
    </thead>
    <tr>
        <td align="center" class="lt" colspan="3"><form action="" method="post">
        <select name="month" style="width: 180px;"><option value="01" <?if(date('m',time())=='01') echo'selected';?>>Январь</option><option value="02" <?if(date('m',time())=='02') echo'selected';?>>Февраль</option><option value="03" <?if(date('m',time())=='03') echo'selected';?>>Март</option><option value="04" <?if(date('m',time())=='04') echo'selected';?>>Апрель</option><option value="05" <?if(date('m',time())=='05') echo'selected';?>>Май</option><option value="06" <?if(date('m',time())=='06') echo'selected';?>>Июнь</option><option value="07" <?if(date('m',time())=='07') echo'selected';?>>Июль</option><option value="08" <?if(date('m',time())=='08') echo'selected';?>>Август</option><option value="09" <?if(date('m',time())=='09') echo'selected';?>>Сентябрь</option><option value="10" <?if(date('m',time())=='10') echo'selected';?>>Октябрь</option><option value="11" <?if(date('m',time())=='11')echo'selected';?>>Ноябрь</option><option value="12" <?if(date('m',time())=='12')echo'selected';?>>Декабрь</option></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<select name="year" style="width: 80px;"><option value="2016" <?if(date('Y',time())=='2016') echo'selected';?>>2016</option><option value="2017" <?if(date('Y',time())=='2017') echo'selected';?>>2017</option><option value="2018" <?if(date('Y',time())=='2018') echo'selected';?>>2018</option><option value="2019" <?if(date('Y',time())=='2019') echo'selected';?>>2019</option><option value="2020" <?if(date('Y',time())=='2020') echo'selected';?>>2020</option></select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="zapros" value="Показать" id="save" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="vzyt" value="Снять" id="save" />
        </form></td>
    </tr>
    <tr>
        <td width="20" align="center" class="lt">1</td>
        <td align="left" class="lt">Динамические ссылки</td>
        <td align="center" class="rt" width="80"><?=moneyraund($sumdyn['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">2</td>
        <td align="left" class="lt">Платные письма</td>
        <td align="center" class="rt"><?=moneyraund($sumpm['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">3</td>
        <td align="left" class="lt">Задания</td>
        <td align="center" class="rt"><?=moneyraund($sumtask['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">4</td>
        <td align="left" class="lt">Статические ссылки</td>
        <td align="center" class="rt"><?=moneyraund($sumstatlink['sum'], 3).' '.$sitevalname?></td>
    </tr>
	<tr>
        <td align="center" class="lt">5</td>
       <td align="left" class="lt">Рекламная цепочка</td>
        <td align="center" class="rt"><?=moneyraund($sumcep['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">6</td>
        <td align="left" class="lt">Баннеры</td>
        <td align="center" class="rt"><?=moneyraund($sumban1['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">7</td>
        <td align="left" class="lt">Голоса</td>
        <td align="center" class="rt"><?=moneyraund($sumgolos['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">8</td>
        <td align="left" class="lt">Ярмарка</td>
        <td align="center" class="rt"><?=moneyraund($sumbirj['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">9</td>
        <td align="left" class="lt">Рассылка рефералам</td>
        <td align="center" class="rt"><?=moneyraund($summasref['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">10</td>
        <td align="left" class="lt">Спящие рефералы</td>
        <td align="center" class="rt"><?=moneyraund($sumwakeref['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td align="center" class="lt">11</td>
        <td align="left" class="lt">Штраф за нарушение правил</td>
        <td align="center" class="rt"><?=moneyraund($sumfine['sum'], 3).' '.$sitevalname?></td>
    </tr>
	<tr>
        <td align="center" class="lt">12</td>
		<td align="left" class="lt">Конкурсы рефералов</td>
        <td align="center" class="rt"><?=moneyraund($sumkonref['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td colspan="2" class="lt" align="right">За месяц</td>
        <td align="center" class="rt"><?=moneyraund($summ1['sum'], 3).' '.$sitevalname?></td>
    </tr>
    <tr>
        <td colspan="3" class="lt" align="center">
        <?
        $sum = substr($summ2['sum'], 0, 5);
        $sum = explode('.', $sum);
        for ($i = 0; $i < strlen($sum[0]); $i++) {
            echo '<img src="img/numeric/'.$sum[0]{$i}.'.png" width="28" height="33" />';
        }
        echo '<span>&nbsp;&nbsp;&nbsp;</span>';
        for ($j = 0; $j < strlen($sum[1]); $j++) {
            echo '<img src="img/numeric/'.$sum[1]{$j}.'.png" width="28" height="33" />';
        }
        ?>
        </td>
    </tr>
</table>
</td>
<td width="50%" valign="top">
<table width="450" border="0" cellpadding="0" cellspacing="1" class="tab">
    <thead>
        <th style="padding: 3px; background: #ebebeb; color: #800000;">СНЯТО</th>
    </thead>
    <tr>
        <td class="lt" align="left"><div style="position: relative; padding: 5px;">Выведено из системы: <b><?=moneyraund($vivel['sum'], 3) .' ' . $sitevalname?><div style="position: absolute; right: 5px; top: 0;"><form action="" method="post"><input type="submit" name="reset" value="Очистить" id="save" title="Использовать только один раз" /></form></div></div></b></td>
    </tr>
</table><br />
<form action="" method="post">
<table width="450" border="0" cellpadding="0" cellspacing="1" class="tab">
    <thead>
        <th style="padding: 3px; padding-left: 5px; background: #ebebeb; color: #1c62b9;" align="left">ЗАМЕТКИ</th>
    </thead>
    <tr>
        <td align="center"><textarea name="notepad" style="width: 95%; margin: 5px; height: 161px; border: 1px solid #dddddd; padding: 3px;"><?=$getnotepad['text']?></textarea></td>
    </tr>
    <tr>
        <td style="background: #ebebeb; padding: 5px;" align="right"><input type="submit" name="addnotepad" value="Сохранить" id="save" /></td>
    </tr>
</table>
</form>
</td>
</tr>
</table>
<div style="margin-top: 15px;"><a href="http://www.rostixsoft.com" target="_blank" class="link">&copy;2012/2015. Права принадлежат rostixsoft.com</a></div>