// Комментарии
    case 'addpost':
        $id = intval(SafeEnv($_GET['poll_id'], 11, int));
        CommentsAddPost($id, 'polls_comments', 'polls', 'com_counter', 'allow_comments', "index.php?name=polls&op=viewpoll&poll_id={$id}", 'polls/{poll_id}/');
        break;
    case 'savepost':
        if (CommentsEditPostSave(SafeEnv($_GET['poll_id'], 11, int), 'polls_comments')) {
            break;
        }
    case 'editpost':
        CommentsEditPost('polls_comments', "index.php?name=polls&op=savepost&poll_id=" . SafeDB($_GET['poll_id'], 11, int) . '&back=' . SafeDB($_GET['back'], 255, str));
        break;
    case 'deletepost':
        $id = intval(SafeEnv($_GET['poll_id'], 11, int));
        $delete_url = 'index.php?name=polls&op=deletepost&poll_id=' . $id . '&back=' . SafeDB($_GET['back'], 255, str);
        CommentsDeletePost($id, 'polls_comments', 'polls', 'com_counter', $delete_url);
        break;
        // //
    // //
    default:
        HackOff();
}
function IndexPollsViewPolls()
{
    $polls = System::database()->Select('polls', GetWhereByAccess('view', "`active`='1'"));
    if (count($polls) > 0) {
        System::site()->AddTemplatedBox('Опросы', 'module/polls_main.html');
        System::site()->AddBlock('polls_title', true, false, 'ptitle');
        System::site()->Blocks['polls_title']['vars'] = array('public' => 'Добавлен', 'title' => 'Опрос', 'comments' => 'Комментарий', 'voices' => 'Всего ответов');
        System::site()->AddBlock('polls', true, true, 'poll');
        SortArray($polls, 'date', true);
    // Комментарии
    case 'addpost':
        $id = intval(SafeEnv($_GET['img'], 11, int));
        $cat = SafeDB($_GET['cat'], 11, int);
        CommentsAddPost($id, 'gallery_comments', 'gallery', 'com_counter', 'allow_comments', "index.php?name=gallery&op=view&img={$id}&cat={$cat}", 'gallery/{cat}/{img}/');
        break;
    case 'savepost':
        if (CommentsEditPostSave(SafeEnv($_GET['img'], 11, int), 'gallery_comments')) {
            break;
        }
    case 'editpost':
        CommentsEditPost('gallery_comments', "index.php?name=gallery&op=savepost&img=" . SafeDB($_GET['img'], 11, int) . '&back=' . SafeDB($_GET['back'], 255, str));
        break;
    case 'deletepost':
        $id = SafeEnv($_GET['img'], 11, int);
        CommentsDeletePost($id, 'gallery_comments', 'gallery', 'com_counter', "index.php?name=gallery&op=deletepost&img={$id}&back=" . SafeDB($_GET['back'], 255, str));
        break;
        // //
    // //
    default:
        HackOff();
}
function IndexGalleryGetTree()
{
    static $tree = null;
    if (is_null($tree)) {
        $tree = new IndexTree('gallery_cats');
        $tree->moduleName = 'gallery';
        $tree->id_par_name = 'cat';
        $tree->NumItems = 'IndexGalleryGetNumItems';
    }
    case 'addpost':
        $id = intval(SafeEnv($_GET['art'], 11, int));
        $cat = SafeDB($_GET['cat'], 11, int);
        CommentsAddPost($id, 'articles_comments', 'articles', 'comments_counter', 'allow_comments', "index.php?name=articles&op=read&art={$id}&cat={$cat}", 'articles/{cat}/{art}/');
        break;
    case 'savepost':
        if (CommentsEditPostSave(SafeEnv($_GET['art'], 11, int), 'articles_comments')) {
            break;
        }
    case 'editpost':
        CommentsEditPost('articles_comments', "index.php?name=articles&op=savepost&art=" . SafeDB($_GET['art'], 11, int) . '&back=' . SafeDB($_GET['back'], 255, str));
        break;
    case 'deletepost':
        $id = SafeEnv($_GET['art'], 11, int);
        $delete_url = "index.php?name=articles&op=deletepost&art={$id}&back=" . SafeDB($_GET['back'], 255, str);
        CommentsDeletePost($id, 'articles_comments', 'articles', 'comments_counter', $delete_url);
        break;
        // //
    // //
    default:
        HackOff();
}
function IndexArticlesGetTree()
{
    static $tree = null;
    if (is_null($tree)) {
        $tree = new IndexTree('articles_cats');
        $tree->moduleName = 'articles';
        $tree->id_par_name = 'cat';
        $tree->NumItems = 'IndexArticlesGetNumItems';
    }
    case 'addpost':
        $id = intval(SafeEnv($_GET['news'], 11, int));
        $topic = SafeDB($_GET['topic'], 11, int);
        CommentsAddPost($id, 'news_comments', 'news', 'comments_counter', 'allow_comments', "index.php?name=news&op=readfull&news={$id}&topic={$topic}", 'news/{topic}/{news}/');
        break;
    case 'savepost':
        if (CommentsEditPostSave(SafeEnv($_GET['news'], 11, int), 'news_comments')) {
            break;
        }
    case 'editpost':
        CommentsEditPost('news_comments', "index.php?name=news&op=savepost&news=" . SafeDB($_GET['news'], 11, int) . '&back=' . SafeDB($_GET['back'], 255, str));
        break;
    case 'deletepost':
        $id = intval(SafeEnv($_GET['news'], 11, int));
        $delete_url = 'index.php?name=news&op=deletepost&news=' . $id . '&back=' . SafeDB($_GET['back'], 255, str);
        CommentsDeletePost($id, 'news_comments', 'news', 'comments_counter', $delete_url);
        break;
        // //
    // //
    default:
        IndexNewsMain();
}
function IndexNewsFunc($id)
{
    return '&nbsp' . '<a href="' . ADMIN_FILE . '?exe=news&a=edit&id=' . $id . '&back=' . SaveRefererUrl() . '" class="admin_edit_link"><img src="images/admin/edit.png" title="Редактировать"></a>' . '<a href="' . ADMIN_FILE . '?exe=news&a=delete&id=' . $id . '&back=' . SaveRefererUrl() . '&ok=0" class="admin_edit_link"><img src="images/admin/delete.png" title="Удалить"></a>';
}
function IndexNewsGetTopics()
{
    System::database()->Select('news_topics', '');
    $rs = array();
    while ($topic = System::database()->FetchRow()) {
    case 'addpost':
        $id = intval(SafeEnv($_GET['file'], 11, int));
        $cat = SafeDB($_GET['cat'], 11, int);
        CommentsAddPost($id, 'downloads_comments', 'downloads', 'comments_counter', 'allow_comments', "index.php?name=downloads&op=full&file={$id}&cat={$cat}", 'downloads/{cat}/{file}/');
        break;
    case 'savepost':
        if (CommentsEditPostSave(SafeEnv($_GET['file'], 11, int), 'downloads_comments')) {
            break;
        }
    case 'editpost':
        CommentsEditPost('downloads_comments', "index.php?name=downloads&op=savepost&file=" . SafeDB($_GET['file'], 11, int) . '&back=' . SafeDB($_GET['back'], 255, str));
        break;
    case 'deletepost':
        $id = SafeEnv($_GET['file'], 11, int);
        $delete_url = "index.php?name=downloads&op=deletepost&file={$id}&back=" . SafeDB($_GET['back'], 255, str);
        CommentsDeletePost($id, 'downloads_comments', 'downloads', 'comments_counter', $delete_url);
        break;
        // //
    // //
    default:
        HackOff();
}
function IndexDownloadsGetFileType($filename)
{
    $ext = strtolower(GetFileExt($filename, true));
    $types = array('rar' => 'Архив RAR', 'zip' => 'Архив ZIP', '7z' => 'Архив 7zip', 'ace' => 'WinACE', 'odt' => 'Текстовый документ OpenDocument', 'odg' => 'Графический документ OpenDocument', 'odp' => 'Документ презентации OpenDocument', 'ods' => 'Электронная таблица OpenDocument', 'odc' => 'Документ диаграммы OpenDocument', 'odi' => 'Документ изображения OpenDocument', 'odf' => 'Документ формулы OpenDocument', 'odm' => 'Составной текстовый документ OpenDocument');
    if (isset($types[$ext])) {
        return $types[$ext];
    } else {
        if (preg_match('/pdf|pds/i', $ext)) {
            return 'Документ Adobe PDF';