View file panel/forum.php

File size: 5.96Kb
<?php
// by Mike O. (mides), coolcms.org
require_once '../includes/sys.php';
require_once '../includes/auth_a.php';
require_once '../includes/header.php';

if (!access(3)) {
    redirect(HTTPHOME);
}

switch ($act) {
    default:
        tp('<a href="./">АДМ</a>&raquo; '.$lang['forum']);
		echo '<div class="body">';
        $cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`, `name`");
        while ($cat = mysql_fetch_assoc($cats_r)) {
            echo '<a href="../forum/index.php?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&amp;id='.$cat['id'].'">ред</a>)<br />';
            $subcats_r = mysql_query("SELECT * FROM `forum_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `order`, `name`");
            while ($subcat = mysql_fetch_assoc($subcats_r)) {
                echo '- <a href="../forum/index.php?act=subcat&amp;id='.$subcat['id'].'">'.$subcat['name'].'</a> (<a href="?act=subcat_edit&amp;id='.$subcat['id'].'">ред</a>)<br />';
            }
        }
        echo '<br/>
        <form name="form" action="?act=cat_add" method="post" name="form">
        <select name="cat">
        <option value="0">'.$lang['Main'].'</option>';
        $cats_r = mysql_query("SELECT * FROM `forum_cats` ORDER BY `order`");
        while ($cat = mysql_fetch_assoc($cats_r)) {
                echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';	
        }
        echo '</select><br />
        '.$lang['sub_category_name'].':<br/><input name="name" type="text" maxlength="100" /><br />
        <input name="submit" type="submit" value="OK"></form><br />
		<a href="./">В админку</a>
		</div>';
    break;

    case 'cat_add':
        if ($_POST['name']) {
            $cat = intval($_POST['cat']);
            $name = check($_POST['name']);
            if ($cat > 0) {
                mysql_query("INSERT INTO `forum_subcats` SET `id_cat` = '$cat', `name` = '$name'");
            } else {
                mysql_query("INSERT INTO `forum_cats` SET `name` = '$name'");
            }
        }
        redirect('?');
    break;

    case 'cat_edit':
        $id = abs(intval($_GET['id']));
        $cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '$id'"));
        if ($cat['id']) {
            if ($ok) {
                if ($_POST['del']) {
                    // we need to make sure we don't have any subcats belonging to our cat
                    $forum_subcat_r = mysql_query("SELECT `id` FROM `forum_subcats` WHERE `id_cat` = '$id'");
                    if (!mysql_num_rows($forum_subcat_r)) {
                        mysql_query("DELETE FROM `forum_cats` WHERE `id` = '$id'");
                        redirect('?');
                    } else {
                        error($lang['Delete_all_subcats_first']);
                    }
                } else {
                    if ($_POST['name']) {
                        $name = check($_POST['name']);
                        mysql_query("UPDATE `forum_cats` SET `name` = '$name' WHERE `id` = '$id'");
                        redirect('?');
                    } else {
                        redirect('?act=cat_edit&id='.$id);
                    }
                }
            } else {
                tp('<a href="?">Форум</a>&raquo; Ред-е названия');
                echo '<div class="body"><form name="form" action="?act=cat_edit&amp;id='.$id.'&amp;ok=1" method="post">
                Имя:<br /><input name="name" type="text" value="'.$cat['name'].'" /><br />
                <input name="del" type="checkbox" value="1" /> '.$lang['delete'].' ('.$lang['if_there_are_subcategories_you_might_want_to_delete_them_first'].')<br />
                <input name="submit" type="submit" value="Ok" />
                </form>';
            }
        } else {
            redirect('?');
        }
        nav('?');
    break;

    case 'subcat_edit':
        $id = abs(intval($_GET['id']));
        $subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$id'"));
        if ($subcat['id']) {
            if ($ok) {
                if ($_POST['del']) {
                    // we need to delete everything that belongs to our subcat

                    $forum_msg_r = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_subcat` = '$id'");
                    while ($forum_msg = mysql_fetch_assoc($forum_msg_r) ) {
                            mysql_query("DELETE FROM `voting` WHERE `type` = 'forum' and `id_for` = '$forum_msg[id]'");
                    }

                    mysql_query("DELETE FROM `forum_topics` WHERE `id_subcat` = '$id'");
                    mysql_query("DELETE FROM `forum_msg` WHERE `id_subcat` = '$id'");
                    mysql_query("DELETE FROM `forum_subcats` WHERE `id` = '$id'");
                    
                    redirect('?');
                } else {
                    if ($_POST['name']) {
                        $name = check($_POST['name']);
                        mysql_query("UPDATE `forum_subcats` SET `name` = '$name' WHERE `id` = '$id'");
                        redirect('?');
                    } else {
                        redirect('?act=subcat_edit&id='.$id);
                    }
                }
            } else {
                tp($lang['Edit_subcategory']);
                echo '<div class="body"><form name="form" action="?act=subcat_edit&amp;id='.$id.'&amp;ok=1" method="post">
                '.$lang['name'].':<br /><input name="name" type="text" maxlength="50" value="'.$subcat['name'].'" /><br />
                <input name="del" type="checkbox" value="1" /> '.$lang['delete'].' ('.$lang['posts_topics_related_will_be_deleted'].')<br />
                <input name="submit" type="submit" value="Ok" />
                </form>';
                nav('?');
            }
        } else {
            redirect('?');
        }  
    break;
	
}

require_once '../includes/tail.php';
?>