<?
include '../config.php';
include '../func.php';
head();
ban();

/////////////////////////////
if (! $id_session ) {
    echo head . "<b>Пишем пост...</b>" . div;  
    echo link2 . 'Вы не авторизованы' . div;
    
pod_navig();
foot();
exit();
}
if ( $id_session )
mysql_query("UPDATE `profile` SET `online` = 'forum' WHERE `id` = '".$id_session."'");

echo head . "<b>Редактирование</b>" . div;  

if ($_GET['mod'] == 'theme') {
    

    
    $theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_themes` WHERE `id` = '".num($_GET['theme'])."'"));
    
    if ( empty($theme['id']) ) {
        
        echo link2 . 'Данной тему не существует' . div;
        
        pod_navig();
        foot();
        exit();
    }
    $t_name = $theme['name'];
    $t_msg = $theme['msg'];
    
    if ($theme['user_id'] == $id_session OR $level_forum_session >= 1 OR $level_session >= 2){
    if ( empty ($_POST['submit']) ) {
    echo '<form action="edit.php?mod=theme&theme='.$theme['id'].'" method="post" name="form">';
    
    echo au . 'Тема:<br/> <textarea id="tarea" name="name" cols="30" rows="5">'.$t_name.'</textarea>';
    
    echo link2 . 'Сообщение:<br/ ><textarea id="tarea" name="msg" cols="30" rows="5">'.$t_msg.'</textarea><br/ >';
    echo "<a href=\"../smiles.php?\">Смайлы</a>" . div;
    echo link1 . '<input name="submit" type="submit" class="button" value="Изменить" /></form>' . div;
    } else {
        
        $msg = html($_POST['msg']);
        $name = html($_POST['name']);
        $th = num($_GET['theme']);
        

        $a = mysql_query("UPDATE `forum_themes` SET `msg` = '".$msg."', `name` = '".$name."' WHERE `id` = '".$th."'");
        if ($a == 1) {
            header('Location: theme.php?razdel='.$theme[razdel_id].'&pod_forum='.$theme['pod_forum'].'&theme='.$th.'&mod=edit_good');
        } else {
            header('Location: theme.php?razdel='.$theme[razdel_id].'&pod_forum='.$theme['pod_forum'].'&theme='.$th.'&mod=edit_error');
        }
    }
} else {
    
    echo link2 . 'Ошибка доступа' . div;
}

}

if ($_GET['mod'] == 'post') {
    
    
    $msg1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".num($_GET['post'])."'"));
    $theme = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_themes` WHERE `id` = '".$msg1['theme']."'"));
    
    if ( empty($msg1['id']) ) {
        
        echo link2 . 'Данного поста не существует' . div;
        
        pod_navig();
        foot();
        exit();
    }
    
    $m = $msg1['msg'];
    
    if ($msg1['user_id'] == $id_session OR $level_forum_session >= 1 OR $level_session >= 2){
    if ( empty ($_POST['submit']) ) {
    echo au . '<form action="edit.php?mod=post&post='.$msg1['id'].'" method="post" name="form">';
    echo '<textarea id="tarea" name="msg" cols="30" rows="5">'.$m.'</textarea><br/ >';
    echo '<input name="submit" type="submit" class="button" value="OK" /></form><br/ >';
    echo "<a href=\"../smiles.php?\">Смайлы</a>" . div;
    } else {
        
        $msg = html($_POST['msg']);
        $post = num($_GET['post']);
        
        $f = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_msg` WHERE `id` = '".num($post)."'"));
        $edit = $f['edit']+1;
        $a = mysql_query("UPDATE `forum_msg` SET `msg` = '".$msg."', `edit` = '".$edit."', `edit_user` = '".$id_session."' WHERE `id` = '".$post."'");
        if ($a == 1) {
            header('Location: theme.php?razdel='.$theme['razdel_id'].'&pod_forum='.$theme['pod_forum'].'&theme='.$theme['id'].'&mod=editp_good');
        } else {
            header('Location: theme.php?razdel='.$theme['razdel_id'].'&pod_forum='.$theme['pod_forum'].'&theme='.$theme['id'].'&mod=editp_error');
        }
    }
} else {
    
    echo link2 . 'Ошибка доступа' . div;
}

}




echo '</div>';
pod_navig();
foot();
?>