Файл: Arhmobi_esdcms/theme/theme.edit.php
Строк: 27
<?php
include_once '../sys/inc/start.php';
$doc = new document(4);
$doc->title = __('Редактирование темы дня');
$doc->ret(__('К темам'), './');
$id = (int) @$_GET['id'];
$q = $db->prepare("SELECT * FROM `theme` WHERE `id` = ? LIMIT 1");
$q->execute(Array($id));
if (!$theme = $q->fetch())
    $doc->access_denied(__('Тема не найдена или удалена'));
$ank = new user($theme['id_user']);
if ($ank->group > $user->group)
    $doc->access_denied(__('У Вас нет прав для редактирования данной теме'));
$theme_e = &$_SESSION['theme_edit'][$id];
if (isset($_POST['clear']))
    $theme_e = array();
if (empty($theme_e)) {
    $theme_e = array();
    $theme_e['title'] = $theme['title'];
    $theme_e['text'] = $theme['text'];
    $theme_e['checked'] = false;
}
if ($theme_e['checked'] && isset($_POST['send'])) {
    if (empty($_POST['captcha']) || empty($_POST['captcha_session']) || !captcha::check($_POST['captcha'], $_POST['captcha_session']))
        $doc->err(__('Ошибка при вводе чисел с картинки'));
    else {
        $res = $db->prepare("UPDATE `theme` SET `title` = ?, `id_user` = ?, `text` = ?, `sended` = '0' WHERE `id` = ? LIMIT 1");
        $res->execute(Array($theme_e['title'], $user->id, $theme_e['text'], $id));
        $doc->msg(__('Тема дня успешно отредактирована'));
        $theme_e = array();
        header('Refresh: 1; ./');
        exit;
    }
}
if (isset($_POST['edit']))
    $theme['checked'] = 0;
if (isset($_POST['next'])) {
    $title = text::for_name($_POST['title']);
    $text = text::input_text($_POST['text']);
    if (!$title)
        $doc->err(__('Заполните "Заголовок темы дня"'));
    else
        $theme_e['title'] = $title;
    if (!$text)
        $doc->err(__('Заполните "Текст темы"'));
    else
        $theme_e['text'] = $text;
    if ($title && $text)
        $theme_e['checked'] = 1;
}
$form = new form(new url());
$form->text('title', __('Заголовок темы дня'), $theme_e['title'], true, false, $theme_e['checked']);
$form->textarea('text', __('Текст темы'), $theme_e['text'], true, $theme_e['checked']);
if ($theme_e['checked']) {
    $form->captcha();
    $form->button(__('Редактировать'), 'edit', false);
    $form->button(__('Применить'), 'send', false);
} else {
    $form->button(__('Очистить'), 'clear', false);
    $form->button(__('Далее'), 'next', false);
}
$form->display();