<?php

/**
 * @author Diamorph
 * @copyright 2013
 */
////////////////////////////
// ДОБАВИТЬ В bitva.php вместо старого кода
///////////////////////////
            $query = "SELECT * FROM `lvl_table` WHERE `lvl` = '" . $udata['lvl'] . "' + 1";
            $result = mysql_query($query) or die(mysql_error());
            $row = mysql_fetch_assoc($result);
            
            $query = "SELECT * FROM `lvl_table` WHERE `lvl` = '" . $udata['lvl'] . "'";
            $res = mysql_query($query) or die(mysql_error());
            $row1 = mysql_fetch_assoc($res);                                    
                                    
            $exp = floor((($udata['exp'] - $row1['need_exp']) / ($row['need_exp'] - $row1['need_exp'])) * 100);
////////////////////////////

////////////////////////////
// ДОБАВИТЬ В admin_panel.php + ссылку вида <a href="admin_panel.php?mod=edit_lvl">Управление уровнями</a>';
///////////////////////////

    case 'edit_lvl':
        
        echo '<a href="admin_panel.php?mod=lvl_add">Добавить уровни</a><br/>';
        echo '<a href="admin_panel.php?mod=lvl_edit">Редактировать уровни</a><br/>';
        echo '<a href="admin_panel.php?mod=lvl_delete">Удалить уровни</a><br/>';
        echo '<a href="admin_panel.php">Назад</a>';
        
        break;
        
    case 'lvl_add':
        if (empty($_POST['lvl']))
        {
            echo '<form action="admin_panel.php?mod=lvl_add" method="post">';
            echo 'Уровень:<br/><input class="input" type="text" name="lvl"/><br/>';
            echo 'Нужно опыта:<br/><input class="input" type="text" name="exp"/><br/>';
            echo '<input class="button" type="submit" value="Добавить" /></form>';
        }
        else
        {
            $query = "INSERT INTO `lvl_table`
                      SET `lvl` = '" . $_POST['lvl'] . "',
                          `need_exp` = '" . $_POST['exp']. "'";
            mysqli_query($db, $query) or die(mysqli_error($db));
            echo 'Уровень ' . $_POST['lvl'] . ' успешно добавлен<br/>';
            echo '<a href="admin_panel.php?mod=lvl_add">Назад</a>';
        }
        
        break;
////////////////////////////

////////////////////////////
// ДОБАВИТЬ В lvl.php и старое заменить (только до питов)
///////////////////////////


$query = "SELECT * FROM `lvl_table` WHERE `lvl` = '" . $udata['lvl'] . "' + 1";
$result = mysql_query($query) or die (mysql_error());
$row = mysql_fetch_assoc($result);

if($udata['exp'] >= $row['need_exp'] AND $row['need_exp'] != '')
{
    $updata['lvl'] = $udata['lvl'] + 1;
    $udata['skill'] = $udata['skill'] + 3;
    if($udata['lvl'] <= 4 and $udata['lvl'] >= 0){$updata['money'] = $udata['money'] + rand(150,300);}
    if($udata['lvl'] <= 8 and $udata['lvl'] > 4){$updata['money'] = $udata['money'] + rand(200,450);}
    if($udata['lvl'] <= 12 and $udata['lvl'] > 8){$updata['money'] = $udata['money'] + rand(350,650);}
    if($udata['lvl'] <= 16 and $udata['lvl'] > 12){$updata['money'] = $udata['money'] + rand(550,1000);}
    if($udata['lvl'] <= 20 and $udata['lvl'] > 16){$updata['money'] = $udata['money'] + rand(900,1500);}
    if($udata['lvl'] <= 25 and $udata['lvl'] > 20){$updata['money'] = $udata['money'] + rand(1500,3000);}
    if($udata['lvl'] > 25){$updata['money'] = $udata['money'] + rand(2500,5000);}
    if($udata['klas'] = 'fighert')
    {
        $avtor = 'Академия воинов';
    }
    else
    {
        $avtor = 'Академия магов';
    }
    $bon = $updata['money'] - $udata['money'];
    $time = date("H:i d.m.y");
    $text = 'Вы достигли' . $updata['lvl'] . 'уровня, сумма' . $bon . 'монет была успешно перечислена!';
    
    $query = "INSERT INTO `msg_r`
              SET `user_from` = '" . $avtor . "',
                  `user_to` = '" . $udata['usr'] . "',
                  `time` = '" . $time . "',
                  `read` = '1',
                  `mail_msg` = '" . $text . "'";
    mysql_query($query) or die(mysql_error());
    
    $query = "UPDATE `users`
              SET `lvl` = '" . $updata['lvl'] . "',
                  `money` = '" . $updata['money'] . "',
                  `skill` = '" . $udata['skill'] . "',
                  `hp` = '" . $udata['hpall'] . "'
              WHERE `usr` = '" . $log . "' LIMIT 1";
    mysql_query($query) or die(mysql_error());
}
////////////////////////////

?>