<?
define('_IN_JOHNCMS', 1);
require_once ('../incfiles/core.php');
require_once ('../incfiles/head.php');
require('../incfiles/lib/class.upload.php');
if (!$user_id) {
    echo functions::display_error('Faqat sayt a\'zolari uchun!');
    require_once ('../incfiles/end.php');
    exit;
}

$req = mysql_query("SELECT * FROM `fanclub` WHERE `id`='$id'");
$res = mysql_fetch_assoc($req);
if ($rights < 9) {
    echo functions::display_error('Dostup yo\'q!');
    echo '<div class="phdr"><a href="index.php">Orqaga</a></div>';
    require_once ("../incfiles/end.php");
    exit;
}
if (!$res) {
    echo functions::display_error('Klublar mavjud emas!');
    echo '<div class="phdr"><a href="index.php">Orqaga</a></div>';
    require_once ("../incfiles/end.php");
    exit;
}

echo '<div class="phdr"><b>Emblema yuklash</b></div>';
if (isset($_POST['submit'])) {

    $handle = new upload($_FILES['imagefile']);
    if ($handle->uploaded) {
        // Обрабатываем фото
        $handle->file_new_name_body = $res['id'];
        //$handle->mime_check = false;
        $handle->allowed = array('image/jpeg', 'image/gif', 'image/png');
        $handle->file_max_size = 1024 *  $set['flsz'];
        $handle->file_overwrite = true;
        $handle->image_resize = true;
        $handle->image_x = 320;
        $handle->image_ratio_y = true;
        $handle->image_convert = 'png';
        $handle->process('img/');
        if ($handle->processed) {
            // Обрабатываем превьюшку
            $handle->file_new_name_body = $res['id'] . '_small';
            $handle->file_overwrite = true;
            $handle->image_resize = true;
            $handle->image_x = 100;
            $handle->image_ratio_y = true;
            $handle->image_convert = 'png';
            $handle->process('img/');
            if ($handle->processed) {
                echo '<div class="gmenu"><p>Logotip yuklandi<br /><a href="titul_club.php?id=' .
                    $res['id'] . '">Davom etish</a></p></div>';
            } else {
                echo functions::display_error($handle->error);
            }
        } else {
            echo functions::display_error($handle->error);
        }
        $handle->clean();
    }
} else {
    echo '<form enctype="multipart/form-data" method="post" action="img.php?id=' . $id .
        '"><div class="menu"><p>';
    echo 'Klub emblemasini tanlang:<br /><input type="file" name="imagefile" value="" />';
    echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . (1024 * $flsz) .
        '" />';
    echo '</p><p><input type="submit" name="submit" value="Yuklash" />';
    echo '</p></div></form>';
    echo '<div class="phdr"><a href="titul_club.php?id=' . $res['id'] .
        '">В клуб</a><br/><small>Yuklash mumkin bo\'lgan fayllar JPG, JPEG, PNG, GIF<br />Faylning maks. hajmi  ' .
        $flsz . 'кб.<br />';
    echo 'Eski rasmni yangisiga almashtirish (agar u bo\'lsa)</small></div>';
}
require_once ('../incfiles/end.php');
?>