Esempio n. 1
0
*/
$arrWhere = false;
// создаем массив секций, с которым мы будем работать
$sections = !($sections['full'] = $artsections->getSections($arrWhere)) ? false : $sections + $artsections->splitSections($sections['full']);
/**
 * просмотр полной статьи или статей по разделу
 */
if (isset($_GET['action']) && 'offset' !== $_GET['action']) {
    /**
     * Просмотр статей по разделу
     */
    if ('section' === $_GET['action'] && !empty($_GET['id']) && validate::checkNaturalNumber($_GET['id']) && !empty($sections['full'][$_GET['id']]) && is_array($sections['full'][$_GET['id']])) {
        if (!empty($_GET['tId']) && !in_array($_GET['tId'], $sections['full'][$_GET['id']])) {
            messages::error404();
        }
        if ($section = $artsections->getSectionById($_GET['id'])) {
            $arrNamePage = array(array('name' => MENU_ARTICLES, 'link' => chpu::createChpuUrl(CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=articles')), array('name' => $section['name'], 'link' => false));
            // Формируем TITLE страницы
            $arrTitle = array();
            CONF_ARTICLES_TITLE_SECTION_SITE ? $arrTitle[] = array('name' => MENU_ARTICLES) : null;
            $arrTitle[] = array('name' => $section['name']);
            //смещение, всегда 0 (затем берется из $_GET)
            $offset = !empty($_GET['offset']) && validate::checkNaturalNumber($_GET['offset']) ? validate::checkNaturalNumber($_GET['offset']) : 0;
            //получаем массив, содержащий текущий обработанный URL
            $path = CONF_SCRIPT_URL . 'index.php?ut=' . $_SESSION['sd_user'][DB_PREFIX . 'conf']['user_type'] . '&do=articles&action=section&id=' . $_GET['id'] . '&page=offset&';
            $strWhere = "id_section=" . secure::escQuoteData($section['id']);
            $arrLimit = array('strLimit' => $offset . ',' . CONF_ARTICLES_PERPAGE, 'calcRows' => true);
            $arrFields = array('id', 'title', 'small_text', 'datetime', 'id_section', 'author', 'rating', 'votes');
            // массив всех статей
            $arrArticles = $articles->getPuplishedArticles($strWhere, false, $arrLimit, $arrFields);
            $smarty->assign('articles', $arrArticles);
    /**
     * добавление раздела
     */
    if ('add' === $_GET['action']) {
        // инициируем "Наименование страницы" отображаемое в форме
        $arrNamePage[] = array('name' => MENU_DICTIONARY_ARTICLES_SECTIONS_ADD, 'link' => false);
        if (isset($_POST['save']) && isset($_POST['arrBindFields']['name']) && $_POST['arrBindFields']['name']) {
            // получаем из формы поля обязательные для заполнения
            $artsections->arrBindFields = $_POST['arrBindFields'];
            // производим запись в таблицу БД
            !$artsections->recSection() ? $arrErrors[] = db::$message_error ? db::$message_error : ERROR_MISMATCH_FIELDS : messages::messageChangeSaved(MESSAGE_SECTION_ADDED, false, CONF_ADMIN_FILE . '?m=dictionary&s=articles.sections&action=add');
        }
        $arrAction['add'] = true;
    } elseif ('edit' === $_GET['action'] && isset($_GET['id'])) {
        // проверяем существование раздела
        if ($arrData = $artsections->getSectionById($_GET['id'])) {
            $arrNamePage[] = array('name' => MENU_DICTIONARY_ARTICLES_SECTIONS_EDIT, 'link' => false);
            $smarty->assignByRef('return_data', $arrData);
            if (isset($_POST['save']) && isset($_POST['arrBindFields']['name']) && $_POST['arrBindFields']['name']) {
                // получаем из формы поля обязательные для заполнения
                $artsections->arrBindFields = $_POST['arrBindFields'];
                // производим запись в таблицу БД
                !$artsections->updateSections($_POST['arrBindFields'], array($_GET['id'])) ? $arrErrors[] = db::$message_error ? db::$message_error : ERROR_MISMATCH_FIELDS : messages::messageChangeSaved(MESSAGE_CHANGE_SAVED, false, CONF_ADMIN_FILE . '?m=dictionary&s=articles.sections');
            }
            $arrAction['edit'] = true;
        } else {
            $arrErrors[] = ERROR_SECTION_NOT_EXISTS;
        }
    }
} else {
    // инициируем "Наименование страницы" отображаемое в форме