function AdminArticlesEditor()
{
    global $editarticles;
    if (!$editarticles) {
        System::admin()->AccessDenied();
    }
    $cat_id = isset($_GET['to']) ? SafeDB($_GET['to'], 11, int) : 0;
    $author = '';
    $email = '';
    $www = '';
    $title = '';
    $description = '';
    $article = '';
    $image = '';
    $auto_br_desc = false;
    $auto_br_article = false;
    $allow_comments = true;
    $allow_votes = true;
    $view = 4;
    $active = true;
    //Модуль SEO
    $seo_title = '';
    $seo_keywords = '';
    $seo_description = '';
    //
    $form = 0;
    $product_id = '';
    if (!isset($_GET['id'])) {
        $action = 'add';
        $top = 'Добавить статью';
        $cap = 'Добавить';
    } else {
        $id = SafeEnv($_GET['id'], 11, str);
        System::database()->Select('articles', "`id`='{$id}'");
        $art = System::database()->FetchRow();
        $cat_id = SafeDB($art['cat_id'], 11, int);
        $author = SafeDB($art['author'], 200, str);
        $email = SafeDB($art['email'], 50, str);
        $www = SafeDB($art['www'], 250, str);
        $title = SafeDB($art['title'], 255, str);
        $description = SafeDB($art['description'], 0, str, false);
        $article = SafeDB($art['article'], 0, str, false);
        $image = SafeDB($art['image'], 250, str);
        $auto_br_article = SafeDB($art['auto_br_article'], 1, bool);
        $auto_br_desc = SafeDB($art['auto_br_desc'], 1, bool);
        $active = SafeDB($art['active'], 1, bool);
        $allow_comments = SafeDB($art['allow_comments'], 1, int);
        $allow_votes = SafeDB($art['allow_votes'], 1, int);
        $view = SafeDB($art['view'], 1, int);
        //Модуль SEO
        $seo_title = SafeDB($art['seo_title'], 255, str);
        $seo_keywords = SafeDB($art['seo_keywords'], 255, str);
        $seo_description = SafeDB($art['seo_description'], 255, str);
        //
        $form = SafeDB($art['form'], 11, int);
        $product_id = SafeDB($art['product_id'], 255, str);
        $action = 'save&id=' . $id;
        $top = 'Редактирование статьи';
        $cap = 'Сохранить изменения';
    }
    System::admin()->AddJS(Indent('
		ArticlesPreviewOpen = function(){
			if(tinyMCE){
				tinyMCE.triggerSave();
			}
			var form_data = Admin.SerializeFormData(document.forms.edit_form);
			var left = parseInt(screen.width / 2) - 400;
			var top = parseInt(screen.height / 10);
			var wp = window.open("", "Preview", "resizable=yes,scrollbars=yes,menubar=no,status=no,location=no,width=800,height=600,left="+left+",top="+top+"");
			wp.document.open();
			$.ajax({
				type: "POST",
				url: "' . ADMIN_FILE . '?exe=articles&a=preview",
				data: form_data,
				dataType: "html",
				success: function(data){
					wp.document.write(data);
					wp.document.close();
				}
			});
		}
	'));
    $cats_data = AdminArticlesGetTree()->GetCatsData($cat_id);
    if (count($cats_data) == 0) {
        $back_to_form = SaveRefererUrl();
        AddTextBox($top, 'Нет категорий для добавления! ' . System::admin()->SpeedButton('Добавить категорию', ADMIN_FILE . '?exe=articles&a=cateditor&back=' . $back_to_form, '', true, true));
        return;
    }
    FormRow('В категорию', System::site()->Select('category', $cats_data, false, $cat_id == 0 ? 'class="autofocus"' : ''));
    FormRow('Заголовок', System::site()->Edit('title', $title, false, 'maxlength="250" style="width:400px;"' . ($cat_id != 0 ? 'class="autofocus"' : '')));
    //Модуль SEO
    FormRow('[seo] Заголовок страницы', System::site()->Edit('seo_title', $seo_title, false, 'style="width:400px;"'));
    FormRow('[seo] Ключевые слова', System::site()->Edit('seo_keywords', $seo_keywords, false, 'style="width:400px;"'));
    FormRow('[seo] Описание', System::site()->Edit('seo_description', $seo_description, false, 'style="width:400px;"'));
    //
    // Веб форма
    $forms = System::database()->Select('forms', "`active`='1'");
    $forms_data = array();
    System::site()->DataAdd($forms_data, '0', 'Нет', $form == 0);
    foreach ($forms as $f) {
        System::site()->DataAdd($forms_data, SafeDB($f['id'], 11, int), SafeDB($f['hname'], 255, str), $f['id'] == $form);
    }
    FormRow('Форма', System::site()->Select('form', $forms_data));
    FormRow('Код товара', System::site()->Edit('product_id', $product_id, false, 'maxlength="250" style="width:400px;"'));
    AdminImageControl('Изображение', 'Загрузить изображение', $image, System::config('articles/images_dir'));
    FormTextRow('Короткая статья (HTML)', System::site()->HtmlEditor('description', $description, 600, 200));
    FormRow('', 'Преобразовать текст в HTML: ' . System::site()->Select('auto_br_desc', GetEnData($auto_br_desc, 'Да', 'Нет')));
    FormTextRow('Полная статья (HTML)', System::site()->HtmlEditor('article', $article, 600, 400));
    FormRow('', 'Преобразовать текст в HTML: ' . System::site()->Select('auto_br_article', GetEnData($auto_br_article, 'Да', 'Нет')));
    FormRow('Автор', System::site()->Edit('author', $author, false, 'style="width:400px;" maxlength="50"'));
    FormRow('E-mail автора', System::site()->Edit('email', $email, false, 'style="width:400px;" maxlength="50"'));
    FormRow('Сайт автора', System::site()->Edit('www', $www, false, 'style="width:400px;" maxlength="250"'));
    FormRow('Комментарии', System::site()->Select('allow_comments', GetEnData($allow_comments, 'Разрешить', 'Запретить')));
    FormRow('Оценки', System::site()->Select('allow_votes', GetEnData($allow_votes, 'Разрешить', 'Запретить')));
    FormRow('Кто видит', System::site()->Select('view', GetUserTypesFormData($view)));
    FormRow('Активна', System::site()->Select('active', GetEnData($active, 'Да', 'Нет')));
    AddCenterBox($top);
    if (!isset($_REQUEST['back'])) {
        $_REQUEST['back'] = SaveRefererUrl(ADMIN_FILE . '?exe=articles');
    }
    AddForm('<form name="edit_form" action="' . ADMIN_FILE . '?exe=articles&a=' . $action . '&back=' . SafeDB($_REQUEST['back'], 255, str) . '" method="post" enctype="multipart/form-data">', System::site()->Button('Отмена', 'onclick="history.go(-1)"') . System::site()->Button('Предпросмотр', 'onclick="ArticlesPreviewOpen();"') . System::site()->Submit($cap));
}
function AdminDownloadsFileEditor($action)
{
    if (!System::user()->CheckAccess2('downloads', 'edit_files')) {
        System::admin()->AccessDenied();
    }
    $category = isset($_GET['to']) ? SafeDB($_GET['to'], 11, int) : 0;
    $title = '';
    $url = '';
    $file_size = '0';
    $size_type = 'b';
    $shortdesc = '';
    $description = '';
    $image = '';
    $author = '';
    $author_site = '';
    $author_email = '';
    $file_ver = '';
    $allow_comments = true;
    $allow_votes = true;
    $view = 4;
    $active = true;
    if (!isset($_GET['id'])) {
        $action = 'addfilesave';
        $top = 'Добавить файл';
        $cap = 'Добавить';
    } else {
        $id = SafeEnv($_GET['id'], 11, int);
        System::database()->Select('downloads', "`id`='{$id}'");
        $file = System::database()->FetchRow();
        $category = SafeDB($file['category'], 11, int);
        $title = SafeDB($file['title'], 250, str);
        $url = SafeDB($file['url'], 250, str);
        $file_size = SafeDB($file['size'], 11, real);
        $size_type = SafeDB($file['size_type'], 1, str);
        $shortdesc = SafeDB($file['shortdesc'], 0, str, false);
        $description = SafeDB($file['description'], 0, str, false);
        $image = SafeDB($file['image'], 250, str);
        $author = SafeDB($file['author'], 200, str);
        $author_site = SafeDB($file['author_site'], 250, str);
        $author_email = SafeDB($file['author_email'], 50, str);
        $file_ver = SafeDB($file['file_version'], 250, str);
        $allow_comments = SafeDB($file['allow_comments'], 1, int);
        $allow_votes = SafeDB($file['allow_votes'], 1, int);
        $view = SafeDB($file['view'], 1, int);
        $active = SafeDB($file['active'], 1, int);
        $action = 'editfilesave&id=' . $id;
        $top = 'Редактирование файла';
        $cap = 'Сохранить изменения';
    }
    $cats_data = AdminDownloadsGetTree()->GetCatsData($category);
    if (count($cats_data) == 0) {
        $back_to_form = SaveRefererUrl();
        AddTextBox($top, 'Нет категорий для добавления! ' . System::admin()->SpeedButton('Добавить категорию', ADMIN_FILE . '?exe=downloads&a=cateditor&back=' . $back_to_form, '', true, true));
        return;
    }
    $filesize_data = array();
    System::site()->DataAdd($filesize_data, 'b', 'Байт', $size_type == 'b');
    System::site()->DataAdd($filesize_data, 'k', 'Килобайт', $size_type == 'k');
    System::site()->DataAdd($filesize_data, 'm', 'Мегабайт', $size_type == 'm');
    System::site()->DataAdd($filesize_data, 'g', 'Гигабайт', $size_type == 'g');
    $max_file_size = ini_get('upload_max_filesize');
    AddCenterBox($top);
    FormRow('В категорию', System::site()->Select('category', $cats_data, false, $category == 0 ? 'class="autofocus"' : ''));
    FormRow('Название', System::site()->Edit('title', $title, false, 'style="width:400px;"' . ($category != 0 ? ' class="autofocus"' : '')));
    FormRow('Путь к файлу', System::site()->Edit('url', $url, false, 'style="width:400px;"'));
    //FormRow('Путь к файлу', System::site()->FileManager( 'url', $url, 400));
    FormRow('Загрузить файл<br />(<small>Максимальный размер файла: ' . $max_file_size . '</small>)', System::site()->FFile('upload_file') . '<br /><div style="width: 400px; word-wrap:break-word;">Разрешенные форматы:<br />' . System::config('downloads/file_exts') . '</div>');
    FormRow('Размер файла', System::site()->Edit('size', $file_size, false, 'style="width:200px;"') . ' ' . System::site()->Select('filesize_type', $filesize_data));
    AdminImageControl('Изображение', 'Загрузить изображение', $image, System::config('downloads/images_dir'));
    FormTextRow('Краткое описание', System::site()->HtmlEditor('shortdesc', $shortdesc, 600, 200));
    FormTextRow('Полное описание', System::site()->HtmlEditor('description', $description, 600, 400));
    FormRow('Версия файла', System::site()->Edit('version', $file_ver, false, 'style="width:400px;"'));
    FormRow('Автор', System::site()->Edit('author', $author, false, 'style="width:400px;"'));
    FormRow('E-mail автора', System::site()->Edit('author_email', $author_email, false, 'style="width:400px;"'));
    FormRow('Сайт автора', System::site()->Edit('author_site', $author_site, false, 'style="width:400px;"'));
    FormRow('Комментарии', System::site()->Select('allow_comments', GetEnData($allow_comments, 'Разрешить', 'Запретить')));
    FormRow('Оценки', System::site()->Select('allow_votes', GetEnData($allow_votes, 'Разрешить', 'Запретить')));
    FormRow('Кто видит', System::site()->Select('view', GetUserTypesFormData($view)));
    FormRow('Активен', System::site()->Select('active', GetEnData($active, 'Да', 'Нет')));
    if (!isset($_REQUEST['back'])) {
        $_REQUEST['back'] = SaveRefererUrl(ADMIN_FILE . '?exe=downloads');
    }
    AddForm('<form action="' . ADMIN_FILE . '?exe=downloads&a=' . $action . '&back=' . SafeDB($_REQUEST['back'], 255, str) . '" method="post" enctype="multipart/form-data" name="edit_form">', System::site()->Button('Отмена', 'onclick="history.go(-1)"') . System::site()->Submit($cap));
}