<?php
define('NTLCMS', 1);
$module = 'avatar';
include ('../system/start.php');
include ('../system/function.php');
include ('../system/antidos.php');
$page_title = 'Страница загрузки вашего аватара - клик клуба ' . strtoupper($_SERVER['HTTP_HOST']);
include ('../system/head.php');
include ('../system/upload.class.php');
if (!$active){
header('Location: '.URL);
$_SESSION['fail'] = 'Вы не авторизированы!';
exit;
}
$us = DB :: run() -> query("select (`avatar`) from `users` where `login` = ? limit 1", array($ulogin)) -> fetch(PDO::FETCH_OBJ);
if (isset($_POST['submit'])){
$handle = new upload($_FILES['imagefile']);
if ($handle -> uploaded){
$handle -> file_new_name_body = $ilogin;
$handle -> allowed = array('image/jpeg', 'image/gif', 'image/png');
$handle -> file_max_size = 1024 * 1000 * 1;
$handle -> file_overwrite = true;
$handle -> image_resize = true;
$handle -> image_x = 160;
$handle -> image_ratio_y = true;
$handle -> image_convert = 'jpg';
$handle -> process(FOLDER.'/avatars/');
if ($handle -> processed){
$handle -> file_new_name_body = $ilogin;
$handle -> file_overwrite = true;
$handle -> image_resize = true;
$handle -> image_x = 40;
$handle -> image_ratio_y = true;
$handle -> image_convert = 'png';
$handle -> process(FOLDER.'/avatars/small');
DB :: run() -> query("update `users` set `avatar` = ? where `login` = ? limit 1", array(1, $ilogin));
} else {
header('Location: '.URL.'/cabinet');
$_SESSION['fail'] = $handle -> error;
}
$handle -> clean();
header('Location: '.URL.'/cabinet');
$_SESSION['success'] = 'Аватар успешно загружен!';
exit;
}
} else {
echo '<div class="title"><b>'.razd.' Загрузка аватара</b></div>';
if (isset($_GET['delete'])){
DB :: run() -> query("update `users` set `avatar` = ? where `login` = ? limit 1", array(0, $ilogin));
if (is_file(FOLDER.'/avatars/'.$ulogin.'.jpg')) unlink(FOLDER.'/avatars/'.$ulogin.'.jpg');
if (is_file(FOLDER.'/avatars/small/'.$ulogin.'.png')) unlink(FOLDER.'/avatars/small/'.$ulogin.'.png');
header('Location: '.URL.'/cabinet');
$_SESSION['success'] = 'Аватар успешно удален!';
}
echo '<div class="menu">';
if ($us -> avatar == '0'){
echo '<center><figure class="imgteaser"><img src="'.URL.'/style/icons/noavatar.gif" alt="*" style=" width: 110px; height: 110px; border-radius: 3%;"></figure></center>';
} else {
echo '<center><figure class="imgteaser"><img src="'.URL.'/avatars/'.$ulogin.'.jpg" alt="*" style=" width: 110px; height: 110px; border-radius: 3%;"></figure></center>';
}
if (is_file(FOLDER.'/avatars/'.$ulogin.'.jpg') || $us -> avatar != '0'){
echo '<center><a href="'.URL.'/ava_delete">Удалить аватар</a></center>';
}
echo '</div>';
echo '<div class="menu"><form enctype="multipart/form-data" method="post" action="'.URL.'/avatar">
Выберите изображение:<br/><input type="file" name="imagefile" value=""/>
<input type="hidden" name="MAX_FILE_SIZE" value="'.(1024 * 1000 * 1).'"/><br/>
<input type="submit" name="submit" value="Выгрузить файл"/></form>
<small>* Для выгрузки разрешены файлы JPG, JPEG, PNG, GIF<br/>* Размер файла не должен превышать 1 мб.</small></div>';
}
echo '<div class="block"><i class="fa fa-home fa-fw"></i> <a href="'.URL.'/cabinet">В кабинет</a></div>';
include ('../system/foot.php');
?>