<?
require_once '../core/system.php';
echo admin();
$header = 'Админ Панель!';
require_once H.'core/head.php';
if($user[prava] >= 5 ){
echo "<div class='player menuList'>";

 echo' <div class="lst"><form action="smiles.php?add" method="post" enctype="multipart/form-data">
Название смайла:<br/>
<input type="text" name="name" value=""/><br/>';
echo'<input type="file" name="uploadfile"><br/>
      <input type="submit" value="Добавить">
      </form></div>';


if(isset($_GET['add'])){
$file = $_FILES['uploadfile']['name'];
function retrans($t){
$a = array('_','YA','Ya','ya','yee','YO','yo','Yo','ZH','zh','Zh','Z','z','CH','ch','Ch','SH','sh','Sh','YE','ye','Ye','YU','yu','Yu','JA','ja','Ja','A','a','B','b','V','v','G','g','D','d','E','e','I','i','J','j','K','k','L','l','M','m','N','n','O','o','P','p','R','r','S','s','T','t','U','u','F','f','H','h','W','w','x','q','Y','y','C','c','!');
$b = array(' ','Я','Я','я','ые','Ё','ё','Ё','Ж','ж','Ж','З','з','Ч','ч','Ch','Ш','ш','Ш','Э','э','Э','Ю','ю','Ю','Я','я','Я','А','а','Б','б','В','в','Г','г','Д','д','Е','е','И','и','Й','й','К','к','Л','л','М','м','Н','н','О','о','П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Щ','щ','ъ','ь','Ы','ы','Ц','ц','');
return str_replace($b,$a,$t);
}
function del($text)
{
$text=str_replace('&','', $text);
$text=str_replace('$','', $text);
$text=str_replace('>','', $text);
$text=str_replace('<','', $text);
$text=str_replace('~','', $text);
$text=str_replace('`','', $text);
$text=str_replace('#','', $text);
$text=str_replace('*','', $text);
return $text;
}

$file = retrans(del($file));
if (preg_match("/\php|htaccess|ini|htm|js\b/i", $file)) {
echo 'Запрещённый формат файла!'; exit;}
$name = check($_POST['name']);
if(mysql_result(mysql_query("SELECT count(id) FROM `smiles` where `name` = '".$name."'"),0)>=1){
echo 'Такой смайлик уже существует!'; exit;
}
$uploadfile = check($_SERVER['DOCUMENT_ROOT']).'/images/smiles/'.basename($file);
if (copy($_FILES['uploadfile']['tmp_name'], $uploadfile))
{
 $dir = '/images/smiles/'.$file;
  mysql_query("INSERT INTO `smiles` set `name` = '".$name."', `adres` = '".$dir."'");
echo'<br/>Смайлик добавлен!<br/>'; header('location:smiles.php'); exit;
}else{ echo 'Ошибка! Не удалось загрузить смайлик на сервер!';}
}


echo'<a href="$admin_tools_link">$admin_tools_title_name</a>';
echo "</div>";
}
require_once H.'core/foot.php';
?>