Вход Регистрация
Файл: modules/diary/inc/edit.php
Строк: 301
<?php

/* Мод "Блоги"
 * Версия v0.0.3
 * Дата последнего редактирования 22.04.2015
 * Двиг DCMS Special
 * Модифицировал densnet
 * Автор неизвестно
 * Файл edit.php
 * Описание: редактирование блога
 */

$ank = user::get_user($diary['id_user']);
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_files` WHERE `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'"), 0);

if (isset(
$_GET['poll'])) {
    include_once 
'inc/edit.poll' . $diary['poll'] . '.php';
}
if (!isset(
$_SESSION["diary_edit_$diary[id]"])) {
    
$_SESSION["diary_edit_$diary[id]"] = array();
    
$_SESSION["diary_edit_$diary[id]"]['id'] = $diary['id'];
    
$_SESSION["diary_edit_$diary[id]"]['text'] = $diary['text'];
    
$_SESSION["diary_edit_$diary[id]"]['name'] = $diary['name'];
    
$_SESSION["diary_edit_$diary[id]"]['tags'] = $diary['tags'];
    
$_SESSION["diary_edit_$diary[id]"]['adult'] = $diary['adult'];
    
$_SESSION["diary_edit_$diary[id]"]['access'] = $diary['access'];
    
$_SESSION["diary_edit_$diary[id]"]['komm'] = $diary['komm'];
    
$_SESSION["diary_edit_$diary[id]"]['password'] = $diary['password'];
}
$diary_edit = $_SESSION["diary_edit_$diary[id]"];

if (isset(
$_GET['access'])) {
    if (isset(
$_POST['cfms'])) {
        if (
$_POST['access'] == 'pass') {
            if (
text::utf8_strlen($_POST['password']) < $min_size_pass) {
                
$err[] = 'Введите пароль!';
            }
            if (
text::utf8_strlen($_POST['password']) > $max_size_pass) {
                
$err[] = 'Пароль слишком длинный!';
            }
            
$pass = $_POST['password'];
        } else {
            
$pass = NULL;
        }
        if (!isset(
$err)) {
            if (
in_array($_POST['access'], array('all', 'only_me', 'friends', 'pass', 'auth'))) {
                
$_SESSION["diary_edit_$diary[id]"]['password'] = $pass;
                
$_SESSION["diary_edit_$diary[id]"]['access'] = $_POST['access'];
            }
            
header("Location: /modules/diary/$diary[id]/edit");
            exit;
        }
    }
    
err();


    echo 
"<form action = '' method = 'post' class = 'comm'>";
    echo 
"<b>Запись доступна:</b><br />";
    echo 
"<label><input type = 'radio' name = 'access' value = 'all'" . ($diary_edit['access'] == 'all' ? " checked='checked'" : null) . "/>" . img('globe-small.png', '') . " Всем</label><br />";
    echo 
"<label><input type = 'radio' name = 'access' value = 'only_me'" . ($diary_edit['access'] == 'only_me' ? " checked='checked'" : null) . "/>" . img('lock-small.png', '') . " Только мне</label> <br />";
    echo 
"<label><input type = 'radio' name = 'access' value = 'friends'" . ($diary_edit['access'] == 'friends' ? " checked='checked'" : null) . "/>" . img('user-small.png', '') . " Только друзьям</label><br />";
    echo 
"<label><input type = 'radio' name = 'access' value = 'auth'" . ($diary_edit['access'] == 'auth' ? " checked='checked'" : null) . "/>" . img('user.png', '') . " Только авторизованным</label> <br />";
    echo 
"<label><input type = 'radio' name = 'access' value = 'pass'" . ($diary_edit['access'] == 'pass' ? " checked='checked'" : null) . "/>" . img('bullet_key.png', '') . " Только по паролю <br />";
    echo 
"<input name = 'password' size = '16' maxlength = '16' type = 'text' value = '" . output_title($diary_edit['password']) . "'/></label><br />";
    echo 
"<button class = 'flat blue md' name = 'cfms'>Сохранить</button>";
    echo 
"</form>";

    echo 
"<div class = 'comm'><a href = '/modules/diary/$diary[id]/edit'>" . img('left.png', '16') . " Назад</div>";

    require_once 
H . 'sys/inc/tfoot.php';
    exit;
} elseif (isset(
$_GET['komm'])) {
    if (isset(
$_POST['cfms'])) {
        if (
in_array($_POST['komm'], array('all', 'only_me', 'friends'))) {
            
$_SESSION["diary_edit_$diary[id]"]['komm'] = $_POST['komm'];
        }
        
header("Location:/modules/diary/$diary[id]/edit");
        exit;
    }

    echo 
"<form action = '' method = 'post' class = 'comm'>";
    echo 
"<b>Комментирование разрешено:</b><br />";
    echo 
"<label><input type = 'radio' name = 'komm' value = 'all'" . ($diary_edit['komm'] == 'all' ? " checked='checked'" : null) . "/>" . img('globe-small.png', '') . " Всем</label><br />";
    echo 
"<label><input type = 'radio' name = 'komm' value = 'only_me'" . ($diary_edit['komm'] == 'only_me' ? " checked='checked'" : null) . "/>" . img('lock-small.png', '') . " Только мне</label><br />";
    echo 
"<label><input type = 'radio' name = 'komm' value = 'friends'" . ($diary_edit['komm'] == 'friends' ? " checked='checked'" : null) . "/>" . img('user-small.png', '') . " Только друзьям</label><br />";
    echo 
"<button class = 'flat blue md' name = 'cfms'>Сохранить</button>";
    echo 
"</form>";

    echo 
"<div class = 'comm'><a href = '/modules/diary/$diary[id]/edit'>" . img('left.png', '16') . " Назад</div>";
    require_once 
H . 'sys/inc/tfoot.php';
    exit;
} elseif (isset(
$_GET['files']) && isset($_SESSION["diary_edit_$diary[id]"])) {
    if (isset(
$_POST['upload']) && $count_files < $max_files) {
        if (isset(
$_FILES['file'])) {
            
$name = text::esc(stripcslashes(htmlspecialchars($_FILES['file']['name'])));
            
$name = preg_replace('(#|?)', NULL, $name);
            
$ras = strtolower(preg_replace('#^.*.#', NULL, $name));
            
$name = preg_replace('#.[^.]*$#', NULL, $name);

            if (
$ras == $name || $ras == NULL || $name == NULL) {
                
$err[] = 'Неверное название файла';
            }
            if (!isset(
$_FILES['file']['tmp_name']) || filesize($_FILES['file']['tmp_name']) > $max_size_file * 1048576) {
                
$err[] = 'Размер файла превышает установленные ограничения';
            }
            if (
mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_files` WHERE `id_diary` = '$diary[id]' AND `name` = '$name', `ras` = '$ras'"), 0) != 0) {
                
$err[] = 'Вы уже прикрепляли такой файл к этой записи';
            }
            if (!isset(
$err)) {
                
mysql_query("INSERT INTO `diary_files` SET `id_diary` = '$diary[id]', `id_user` = '$ank[id]', `name` = '" . my_esc($name) . "', `ras` = '" . my_esc($ras) . "'");
                
$id = mysql_insert_id();
                
move_uploaded_file($_FILES['file']['tmp_name'], H . "modules/diary/files/$id.dat");
                
chmod(H . "modules/diary/files/$id.dat", 0777);
                
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_files` WHERE `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'"), 0);
            }
        } else {
            
$err[] = 'Выберите файл';
        }
    }
    
err();

    if (isset(
$_GET['dfid']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_files` WHERE `id` = '" . intval($_GET['dfid']) . "' AND `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'"), 0) != 0 && $_GET['mdp'] == md5($user['pass'])) {
        
mysql_query("DELETE FROM `diary_files` WHERE `id` = '" . intval($_GET['dfid']) . "' AND `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'");
        
unlink(H . "modules/diary/files/" . intval($_GET['dfid']) . ".dat");
        
$count_files = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_files` WHERE `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'"), 0);
    }
    
$q = mysql_query("SELECT * FROM `diary_files` WHERE `id_user` = '$ank[id]' AND `id_diary` = '$diary[id]'");
    if (
mysql_num_rows($q) == 0) {
        echo 
"<div class='errs'>Нет прикреплённых файловn";
    } else {
        echo 
"<div class='comm'>n";
    }
    while (
$post = mysql_fetch_array($q)) {
        echo 
"" . (is_file(H . "style/icons/files/$post[ras].png") ? "<img src='/style/icons/files/$post[ras].png'/>" : "<img src='/style/icons/file.png'/>") . " " . output_title($post['name'] . '.' . $post['ras']) . " <span style='color:grey'>(" . size_file(filesize(H . "modules/diary/files/$post[id].dat")) . ")</span> <a href='?files&amp;dfid=$post[id]&amp;mdp=" . md5($user['pass']) . "'><span style='float:right' id = 'hides'>" . img('del.png', '') . "</span></a><br/>n";
    }
    echo 
"</div>n";
    echo 
"<form enctype='multipart/form-data' action='' method='post'>n";
    echo 
"<div class='comm'>";
    echo 
"Файл (<" . size_file($max_size_file * 1048576) . "):<br />n";
    echo 
"<input name='file' type='file'" . ($count_files >= $max_files ? " disabled='disabled'" : null) . "/><br />n";
    echo 
"<input type='submit' class = 'flat blue md' name='upload' value='Загрузить!'" . ($count_files >= $max_files ? " disabled='disabled'" : null) . "/>" . ($count_files >= $max_files ? "<br/></div><div class='errs'>Вы уже прикрепили максимальное кол-во файлов к записи!" : null) . "n";
    echo 
"</div>";
    echo 
"<div class = 'comm'><a href = '/modules/diary/$diary[id]/edit'>" . img('left.png', '16') . " Назад</div>";

    require_once 
H . 'sys/inc/tfoot.php';
    exit;
}

if (isset(
$_POST['cfms']) && isset($_POST['text']) && isset($_POST['name']) && isset($_POST['tags'])) {
    
$name = $_POST['name'];
    
$text = $_POST['text'];
    
$tags = $_POST['tags'];
    if (
text::utf8_strlen($name) > $max_size_name) {
        
$err_name_long = 1;
        
$err_diary = 1;
    }
    if (
text::utf8_strlen($text) < $min_size_text) {
        
$err_text_short = 1;
        
$err_diary = 1;
    }
    if (
text::utf8_strlen($text) > $max_size_text) {
        
$err_text_long = 1;
        
$err_diary = 1;
    }
    
$count_tags = 0;
    
$array_tags = explode(",", $tags);
    foreach (
$array_tags as $key => $tag) {
        if (
$tag != NULL) {
            
$count_tags++;
        }
    }
    if (
$count_tags > $max_size_tags) {
        
$err_tags_long = 1;
        
$err_diary = 1;
    }
    
$count_t = 0;
    
$array_tags = explode(",", $tags);
    
$tags = NULL;
    foreach (
$array_tags as $key => $tag) {
        if (
$tag != NULL) {
            
$count_t++;
            if (
$tags == NULL) {
                
$tags = $tag;
            } else {
                
$tags = "$tags,$tag";
            }
        }
    }
    if (isset(
$_POST['adult']) && $_POST['adult'] == 1) {
        
$adult = 1;
    } else {
        
$adult = 0;
    }
    if (!isset(
$err_diary)) {
        
mysql_query("UPDATE `diary` SET `name` = '" . mysql_real_escape_string($name) . "', `text` = '" . mysql_real_escape_string($text) . "', `tags` = '" . mysql_real_escape_string($tags) . "', `adult` = '$adult' WHERE `id` = '$diary[id]'");
        
mysql_query("UPDATE `diary` SET `access` = '$diary_edit[access]', `password` = '$diary_edit[password]' WHERE `id` = '$diary[id]'");
        
mysql_query("UPDATE `diary` SET `komm` = '$diary_edit[komm]' WHERE `id` = '$diary[id]'");
        unset(
$_SESSION["diary_edit_$diary[id]"]);
        
header("Location:/modules/diary/$diary[id]/read");
        exit;
    }
}

if (isset(
$_POST['files'])) {
    if (isset(
$_POST['adult']) && $_POST['adult'] == 1) {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 1;
    } else {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 0;
    }
    
$_SESSION["diary_edit_$diary[id]"]['name'] = $_POST['name'];
    
$_SESSION["diary_edit_$diary[id]"]['text'] = $_POST['text'];
    
$_SESSION["diary_edit_$diary[id]"]['tags'] = $_POST['tags'];
    
header("Location:?files");
    exit;
}

if (isset(
$_POST['access'])) {
    if (isset(
$_POST['adult']) && $_POST['adult'] == 1) {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 1;
    } else {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 0;
    }
    
$_SESSION["diary_edit_$diary[id]"]['name'] = $_POST['name'];
    
$_SESSION["diary_edit_$diary[id]"]['text'] = $_POST['text'];
    
$_SESSION["diary_edit_$diary[id]"]['tags'] = $_POST['tags'];
    
header("Location:?access");
    exit;
}

if (isset(
$_POST['komm'])) {
    if (isset(
$_POST['adult']) && $_POST['adult'] == 1) {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 1;
    } else {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 0;
    }
    
$_SESSION["diary_edit_$diary[id]"]['name'] = $_POST['name'];
    
$_SESSION["diary_edit_$diary[id]"]['text'] = $_POST['text'];
    
$_SESSION["diary_edit_$diary[id]"]['tags'] = $_POST['tags'];
    
header("Location:?komm");
    exit;
}

if (isset(
$_POST['name'])) {
    
$dn = $_POST['name'];
} else {
    
$dn = $diary_edit['name'];
}
echo 
"<form action='' method='post' class='comm'>n";
if (isset(
$err_name_long)) {
    echo 
"<div class='errs'>n";
}
echo 
"<b>Тема</b> (" . sklon_text($max_size_name, array('знак', 'знака', 'знаков')) . ")<br />
<input type='text' name='name' value='" 
. output_title($dn) . "' /><br />";
if (isset(
$err_name_long)) {
    echo 
"Тема записи слишком длинная</div>n";
}
if (isset(
$err_text_long) || isset($err_text_short)) {
    echo 
"<div class='errs'>n";
}
echo 
"<b>Запись</b> (" . sklon_text($max_size_text, array('знак', 'знака', 'знаков')) . ")<br/>n";

if (isset(
$_POST['text'])) {
    
$dt = $_POST['text'];
} else {
    
$dt = $diary_edit['text'];
}
echo 
"<textarea id='textarea' name='text'>" . output_title($dt) . "</textarea><br/>" . (isset($err_text_long) ? "Текст записи слишком длинный" : null) . "" . (isset($err_text_short) ? "Введите текст записи" : null) . "n";
if (isset(
$err_text_long) || isset($err_text_short)) {
    echo 
"</div>n";
}

echo 
"<b>Прикрепить к записи:</b>n
<input style='cursor:pointer;text-decoration:underline;color:#069;background-color:transparent;border:0;' type='submit' name='files' value='Файлы" 
. ($count_files > 0 ? " ($count_files/$max_files)" : null) . "'/>n</div>n";
if (isset(
$_POST['adult']) && $_POST['adult'] == 1 || $diary_edit['adult'] == 1) {
    
$adult = 1;
}

echo 
"<br /><input type='checkbox' name='adult' value='1'" . (isset($adult) ? " checked='checked'" : null) . "/> Только для взрослых<br />n";

if (
$diary_edit['access'] == 'all') {
    
$access = 'всем';
} elseif (
$diary_edit['access'] == 'only_me') {
    
$access = 'только мне';
} elseif (
$diary_edit['access'] == 'friends') {
    
$access = 'только друзьям';
} elseif (
$diary_edit['access'] == 'pass') {
    
$access = "только по паролю ($diary_edit[password])";
} elseif (
$diary_edit['access'] == 'auth') {
    
$access = 'только авторизованным';
}

echo 
"<b>Запись доступна:</b>n
<input type='submit' name='access' value='
$access' style='cursor:pointer;text-decoration:underline;color:#069;background-color:transparent;border:0;color:green;font-weight:bold;'/><br/>n";
if (
$diary_edit['komm'] == 'all') {
    
$komm = 'всем';
} elseif (
$diary_edit['komm'] == 'only_me') {
    
$komm = 'только мне';
} elseif (
$diary_edit['komm'] == 'friends') {
    
$komm = 'только друзьям';
}
echo 
"<b>Комментирование разрешено:</b>n
<input type='submit' name='komm' value='
$komm' style='cursor:pointer;text-decoration:underline;color:#069;background-color:transparent;border:0;color:green;font-weight:bold;'/><br/>n";


if (isset(
$_POST['tags'])) {
    
$dt = $_POST['tags'];
} else {
    
$dt = $diary_edit['tags'];
}
if (isset(
$err_tags_long)) {
    echo 
"<div class='err'>n";
}
echo 
"<span style='font-size:small:color:grey'><b>Добавить метки</b> (через запятую):</span><br/><input name='tags' value='" . output_title($dt) . "' style='width:80%'/><br/>n";
echo 
"<span style='font-size:small" . (isset($err_tags_long) ? ";color:red" : null) . "'>Всего можно добавить не более " . sklon_text($max_size_tags, array('метки', 'метки', 'меток')) . "</span><br/>n";
if (isset(
$err_tags_long)) {
    echo 
"</div>n";
}
echo 
"<input type='submit' class = 'flat blue md' name='cfms' value='Сохранить'/>n
<input type='submit' class = 'flat blue md' name='previewbtn' value='Предпросмотр'/>n"
;

if (isset(
$_POST['previewbtn']) && isset($_POST['text']) && $_POST['text'] != NULL) {
    if (isset(
$_POST['adult']) && $_POST['adult'] == 1) {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 1;
    } else {
        
$_SESSION["diary_edit_$diary[id]"]['adult'] = 0;
    }
    
$_SESSION["diary_edit_$diary[id]"]['name'] = $_POST['name'];
    
$_SESSION["diary_edit_$diary[id]"]['text'] = $_POST['text'];
    
$_SESSION["diary_edit_$diary[id]"]['tags'] = $_POST['tags'];
    echo 
"<div class='msg'>n
<i><b>Предпросмотр:</b></i><br/>n
<div style='border-left: 2px solid grey; padding-left: 3px'>n
" 
. text::toOutput($_POST['text']) . "n
</div>n
</div>n"
;
}
echo 
"<input type='hidden' name='mdp' value='" . md5($user['pass']) . "'/>n
</form>n"
;

echo 
"<div class = 'comm'><a href = '/modules/diary/$diary[id]/read'>" . img('left.png', '16') . " Назад</div>";

require_once 
H . 'sys/inc/tfoot.php';
exit;
Онлайн: 3
Реклама