<? include('checkcookie.php');
echo "<h3>Настройка рейтинга</h3>";

if(isset($_POST["rt"])){
$activ = floatval($_POST["activ"]);
$click = floatval($_POST["click"]);
$mails = floatval($_POST["mails"]);
$task = floatval($_POST["task"]);
$referal = floatval($_POST["referal"]);
$payout = floatval($_POST["payout"]);
$payout_ref = floatval($_POST["payout_ref"]);

$noactiv = floatval($_POST["noactiv"]);
$bad_task = floatval($_POST["bad_task"]);

mysql_query("UPDATE `b_config` SET `price`='$activ' WHERE `name`='activ'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$click' WHERE `name`='click'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$mails' WHERE `name`='mails'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$task' WHERE `name`='task'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$referal' WHERE `name`='referal'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$payout' WHERE `name`='payout'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$payout_ref' WHERE `name`='payout_ref'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$noactiv' WHERE `name`='noactiv'") or die(mysql_error());
mysql_query("UPDATE `b_config` SET `price`='$bad_task' WHERE `name`='bad_task'") or die(mysql_error());
$result_upd1 = "<b style='color:#6EAD2B;'>Сохранено </b>";
}

if(isset($_POST["st"])){
$sql = mysql_query("SELECT * FROM `b_status` ORDER BY `id` ASC") or die(mysql_error());
if(mysql_num_rows($sql) > 0){
while($row = mysql_fetch_assoc($sql)){
$i++;
$status = $_POST["status".$i];
$min_reyt = $_POST["min_reyt".$i];
$max_reyt = $_POST["max_reyt".$i];
$max_out = $_POST["max_out".$i];
$serf_mail = $_POST["serf_mail".$i];
$task = $_POST["task".$i];
mysql_query("UPDATE `b_status` SET `status`='$status', `min_reyt`='$min_reyt', `max_reyt`='$max_reyt', `max_out`='$max_out', `serf_mail`='$serf_mail', `task`='$task' WHERE `id`='".$row["id"]."'") or die(mysql_error());
$result_upd2 = "<b style='color:#6EAD2B;'>Сохранено </b>";
}
}
}

$b_activ = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='activ'"),0,0);
$b_click = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='click'"),0,0);
$b_mails = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='mails'"),0,0);
$b_task = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='task'"),0,0);
$b_referal = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='referal'"),0,0);
$b_payout = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='payout'"),0,0);
$b_payout_ref = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='payout_ref'"),0,0);
$b_noactiv = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='noactiv'"),0,0);
$b_bad_task = mysql_result(mysql_query("SELECT `price` FROM `b_config` WHERE `name`='bad_task'"),0,0);
?>

<form method="post" action="" id="MainForm1">
<input type="hidden" name="rt" value="1">
<table class="adn">
<tr class="lineb">
<td align="left">Значение</td>
<td align="left"><table class="adn"><tr><td align="left" style="border: none; padding: 0">Описание</td><td align="right" style="border: none; padding: 0"><? if(isset($result_upd1)) echo $result_upd1;?><a href="#" onclick="document.getElementById('MainForm1').submit(); return false" class="liv">Сохранить</a></td></tr></table></td>
</tr>
<tr class="liney ell"><td class="listsl" colspan="2"><b>Начисление рейтинга</b></td></tr>
<tr class="liney">
 <td class="listsl" width="120px"><input type=text value='<? echo $b_activ;?>' name='activ' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>Посещение в сутки</b></td>
</tr>
<tr class="liney ell">
 <td class="listsl"><input type=text value='<? echo $b_click;?>' name='click' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>За один клик</b></td>
</tr>
<tr class="liney">
 <td class="listsl"><input type=text value='<? echo $b_mails;?>' name='mails' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>За один просмотр письма</b></td>
</tr>
<tr class="liney ell">
 <td class="listsl"><input type=text value='<? echo $b_task;?>' name='task' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>За одно оплаченное задание</b></td>
</tr>
<tr class="liney">
 <td class="listsl"><input type=text value='<? echo $b_referal;?>' name='referal' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>Новый реферал</b></td>
</tr>
<tr class="liney ell">
 <td class="listsl"><input type=text value='<? echo $b_payout;?>' name='payout' maxlength="6" size="7"> %</td>
 <td class="listsl"><b>Процент от выплаты</b></td>
</tr>
<tr class="liney">
 <td class="listsl"><input type=text value='<? echo $b_payout_ref;?>' name='payout_ref' maxlength="6" size="7"> %</td>
 <td class="listsl"><b>Процент выплаты вашего реферала</b></td>
</tr>
<tr class="liney ell"><td class="listsl" colspan="2"><b>Снятие рейтинга</b></td></tr>
<tr class="liney">
 <td class="listsl"><input type=text value='<? echo $b_noactiv;?>' name='noactiv' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>Отсутствие активности</b><br>Отсутствие активности пользователя в проекте более недели</td>
</tr>
<tr class="liney ell">
 <td class="listsl"><input type=text value='<? echo $b_bad_task;?>' name='bad_task' maxlength="6" size="7"> балов</td>
 <td class="listsl"><b>Отказ выполненного задания</b></td>
</tr>
</table>
</form>
<br><br>

<form method="post" action="" id="MainForm2">
<input type="hidden" name="st" value="1">
<table class="adn">
<tr class="lineb">
<td align="left">№</td>
<td align="left">Статус</td>
<td align="left">Минимум рейтинга</td>
<td align="left">Максимум рейтинга</td>
<td align="left">Максимум на вывод</td>
<td align="left">Доход от рефералов <small>(серфинг, письма)</small></td>
<td align="left">Доход от рефералов <small>(задания)</small></td>
<td align="left">
<? if(isset($result_upd2)) echo $result_upd2;?><a href="#" onclick="document.getElementById('MainForm2').submit(); return false" class="liv">Сохранить</a>
</td>
</tr>
<?PHP
$sql = mysql_query("SELECT * FROM `b_status` ORDER BY `id` ASC") or die(mysql_error());
if(mysql_num_rows($sql) > 0) {
while($row = mysql_fetch_assoc($sql)){
$i++;
if($i%2) {$class = "liney";}else{$class = "liney ell";}
echo '<tr class="'.$class.'">';
echo '<td class="listsl">'.$row["id"].'</td>';
echo '<td class="listsl"><input type="text" name="status'.$row["id"].'" value="'.$row["status"].'" size="12" maxlength="15"></td>';
echo '<td class="listsl"><input type="text" name="min_reyt'.$row["id"].'" value="'.$row["min_reyt"].'" size="12" maxlength="6"></td>';
echo '<td class="listsl"><input type="text" name="max_reyt'.$row["id"].'" value="'.$row["max_reyt"].'" size="12" maxlength="6"></td>';
echo '<td class="listsl"><input type="text" name="max_out'.$row["id"].'" value="'.$row["max_out"].'" size="12" maxlength="6"></td>';
echo '<td class="listsl"><input type="text" name="serf_mail'.$row["id"].'" value="'.$row["serf_mail"].'" size="12" maxlength="3">%</td>';
echo '<td class="listsl" colspan="2"><input type="text" name="task'.$row["id"].'" value="'.$row["task"].'" size="12" maxlength="3">%</td>';
echo '</tr>';
}
}else{
echo "<tr class='liney'><td class='listsl' colspan='7'>Нет статусов</td></tr>";
}
?>
</table>
</form>