<?php
session_start();
include ($_SERVER['DOCUMET_ROOT'].'/private/mysql.php');
include ($_SERVER['DOCUMET_ROOT'].'/tmp/head.php');

if($user['level']<'3' or $user['profa']!=='hunter'){
    header('Location: /main');
    exit;
}

switch($sd){
default:

echo "Мастерство охотника: ".number_format($user['p_hunter'])."<br><br>
<a href='/profession/knife'>Купить нож</a><br>
<a href='/profession/part'>Добыча</a>";
/*
if(empty($_POST['submit'])){
    
    echo "<form action='/profession' method='post'>
    название:<br>
    <input type='text' name='name'><br>
    тип:<br>
    <select name='tip'>
    <option value='all'>Все</option>
    <option value='bird'>птица</option>
    <option value='insect'>насекомое</option>
    </select><br>
    нужно мастерства:<br>
    <select name='need'>
    <option value='0'>0</option>
    <option value='1000'>1000</option>
    <option value='3000'>3000</option>
    <option value='7000'>7000</option>
    <option value='16000'>16000</option>
    <option value='37000'>37000</option>
    <option value='81000'>81000</option>
    </select><br>
    цена продажи:<br>
    <input type='text' name='cena'><br>
    картинка:<br>
    <input type='text' name='img'><br>
    <input type='submit' name='submit' value='создать'></form>";
    
}else{
    
    mysql_query("INSERT INTO `hunter_res` SET 
    `name`='$_POST[name]',
    `tip`='$_POST[tip]',
    `need`='$_POST[need]',
    `cena`='$_POST[cena]'");
    
    $next_id = mysql_insert_id();
    
    mysql_query("UPDATE `hunter_res` SET `img`='hunter_res_$next_id.png' WHERE `id`='$next_id'");
    
    $file = file_get_contents($_POST['img']);
    file_put_contents("./img/profa/hunter_res_$next_id.png", $file);
    
    header('Location: /profession');
    exit;
    
}
*/

break;


case 'part':
$q = mysql_query("SELECT * FROM `a_hunter` WHERE `user`='$uid'");

While($w = mysql_fetch_assoc($q)){
    
    $p = mysql_fetch_assoc(mysql_query("SELECT * FROM `hunter_res` WHERE `id`='$w[tip]'"));
    
    echo "<span style='float:left'><img src='/img/profa/$w[img]' width='25'></span>&nbsp;$w[name] <small>($w[kol])</small><br><br>";
    
}



echo "<hr>← <a href='/profession'>назад</a>";


break;


case 'buyknife':
$q = mysql_query("SELECT * FROM `hunter_knife` WHERE `id`='$id'");
if(mysql_num_rows($q)=='0'){
    header('Location: /profession/knife');
    exit;
}
$w = mysql_fetch_assoc($q);

if($user['silver']<$w['cena'] or $user['p_hunter']<$w['need']){
    header('Location: /profession/knife');
    exit;
}

mysql_query("UPDATE `users` SET `silver`=`silver`-'$w[silver]',`hunter_knife`='$w[id]' WHERE `id`='$uid'");

set('profknife', "Вы купили $w[name] за ".number_format($w['cena'])." <img src='/img/silver.png'><hr>");

header('Location: /profession/knife');
exit;

break;


case 'knife':


view('profknife');
clear('profknife');

echo "У вас: ";
if($user['hunter_knife']=='0'){
    echo "Нет ножа<br>";
}else{
    echo "<img src='/img/profa/knife$user[hunter_knife].png' width='24'>";
}

$q = mysql_query("SELECT * FROM `hunter_knife`");

While($w=mysql_fetch_assoc($q)){
    
    echo "<hr><small><img src='/img/profa/$w[img]' width='30'> $w[name] || ".number_format($w['cena'])." <img src='/img/silver.png'><br>Необходимо репутации охотника: ".number_format($w['need'])."<br>";
    if($user['p_hunter']>=$w['need']){echo "<a href='/profession/buyknife/$w[id]'>Купить</a>";}else{echo "Требования не выполнены";}
    echo "</small>";
}


echo "<hr>← <a href='/profession'>назад</a>";

break;


}
include ($_SERVER['DOCUMET_ROOT'].'/tmp/foot.php');
?>