<?php

require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/stdf.php';
require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/seo.php';
/*
 * Исправление сбитых позиций в SEO-каталоге /catalog/ 
 */
$sql = 'SELECT parent FROM seo_sections 
        WHERE parent <> 0 
        GROUP BY parent 
        HAVING COUNT(parent) <> MAX(pos_num) OR MIN(pos_num) <> 1';
$parents = $DB->rows($sql);
$seo = new seo();
if ($parents) {
    foreach ($parents as $k => $v) {
        $sql = "SELECT id FROM seo_sections WHERE parent = {$v['parent']} ORDER BY id ASC";
        $rows = $DB->rows($sql);
        if ($rows) {
            foreach ($rows as $i => $row) {
                $info['pos_num'] = $i + 1;
                $seo->updateSection($row['id'], $info);
            }
            echo "Update parent - {$v['parent']}<br/>";
        }
    }
}
Esempio n. 2
0
/**
 * Создание раздела/подраздела
 *
 * @param array $info Данные создания
 * @return object xajaxResponse
 */
function createSection($info, $action = 'create')
{
    global $GLOBALS;
    session_start();
    if (!hasPermissions('seo')) {
        return false;
    }
    $objResponse = new xajaxResponse();
    $info['id'] = intval($info['id']);
    $info['bind'] = intval($info['bind']);
    $info['subdomain'] = intval($info['subdomain']);
    $info['parent'] = intval($info['parent']);
    $info['old_position'] = intval($info['old_position']);
    $info['new_position'] = intval($info['new_position']);
    $info['direct_id'] = $direct_id = intval($info['direction']);
    $info['old_direction'] = intval($info['old_direction']);
    $saved_disable_link_processing = $GLOBALS['disable_link_processing'];
    $GLOBALS['disable_link_processing'] = TRUE;
    $section = array("bind" => 0, "parent" => (int) $info['parent'], "name_section" => (string) change_q_x($info['name_section'], true), "name_section_link" => (string) change_q_x($info['name_section_link'], true), "meta_description" => (string) change_q_x($info['meta_description'], true), "meta_keywords" => (string) change_q_x($info['meta_keywords'], true), "content_before" => (string) __paramValue('ckeditor', $info['content_before']), "content_after" => (string) __paramValue('ckeditor', $info['content_after']), "date_create" => "NOW();");
    $GLOBALS['disable_link_processing'] = $saved_disable_link_processing;
    $seo = new seo($_SESSION['subdomain']);
    if ($info['direct_id']) {
        $section['direct_id'] = $info['direct_id'];
    } else {
        $objResponse->script("alert('Не указано направление');");
        $objResponse->script("\$('s_direction').focus();");
        return $objResponse;
    }
    if ($info['is_subcategory'] && $info['subdomain'] == 0) {
        $objResponse->script("alert('Не указан регион');");
        return $objResponse;
    }
    if (trim($info['name_section']) == "") {
        $objResponse->script("alert('Введите название раздела');");
        $objResponse->script("\$('name_section').focus();");
        return $objResponse;
    }
    if (preg_match('/[^A-Za-z0-9_\\-]/', $info['name_section_link'])) {
        $objResponse->script("alert('Название ссылки раздела должно содержать только латинские буквы, цифры, нижнее подчеркивание или тире');");
        $objResponse->script("\$('name_section_link').focus();");
        return $objResponse;
    }
    if ($seo->checkLink('section', $section['name_section_link'], $info['direct_id'], $info['parent'], $info['id'], $info['subdomain'])) {
        $objResponse->script("alert('В выбранном разделе уже есть элемент с такой ссылкой');");
        $objResponse->script("\$('name_section_link').focus();");
        return $objResponse;
    }
    switch ($action) {
        default:
        case 'create':
            $section['name_section'] = stripslashes($section['name_section']);
            $section['meta_description'] = stripslashes($section['meta_description']);
            $section['meta_keywords'] = stripslashes($section['meta_keywords']);
            $section['content_before'] = stripslashes($section['content_before']);
            $section['content_after'] = stripslashes($section['content_after']);
            $new_section = $seo->createSection($section, $info['subdomain'], (int) $info['is_draft']);
            $section['id'] = $new_section['id'];
            $pos_old = $new_section['pos'];
            $section['pos_num'] = (int) $info['new_position'];
            if ($section['pos_num'] != -1) {
                $seo->updatePosition($pos_old, $info['new_position'], $info['parent'], $direct_id);
                $seo->updateSection($section['id'], $section, $info['bind'], $info['subdomain'], (int) $info['is_draft']);
            }
            if ($info['is_subcategory']) {
                $success_text = "Подраздел успешно добавлен";
                $url['msgok'] = 5;
            } else {
                $success_text = "Раздел успешно добавлен";
                $url['msgok'] = 1;
            }
            break;
        case 'update':
            if ($info['old_parent'] == $info['parent']) {
                $section['pos_num'] = (int) $info['new_position'];
                if ($info['old_direction'] != $direct_id) {
                    $seo->updatePosition($info['old_position'], null, $info['parent'], $info['old_direction']);
                    $section['pos_num'] = intval($seo->getPositions($section['parent'], $direct_id)) + 1;
                } else {
                    if ($info['new_position'] == -1) {
                        $section['pos_num'] = intval($seo->getPositions($section['parent'], $direct_id));
                        $info['new_position'] = $section['pos_num'];
                    }
                    $seo->updatePosition($info['old_position'], $info['new_position'], $info['parent'], $direct_id);
                }
                $seo->updateSection($info['id'], $section, $info['bind'], $info['subdomain'], (int) $info['is_draft']);
            } else {
                $new_position = $seo->getPositions($info['parent'], $direct_id) + 1;
                $section['pos_num'] = (int) $new_position;
                $seo->updatePositionsByParent($info['old_parent'], $info['old_position'], $direct_id);
                $seo->updateSection($info['id'], $section, $info['bind'], $info['subdomain'], (int) $info['is_draft']);
                if ($info['new_position'] != -1) {
                    $pos_old = $section['pos_num'];
                    $pos_new = $info['new_position'];
                    $seo->updatePosition($pos_old, $pos_new, $info['parent'], $direct_id);
                    $section['pos_num'] = $pos_new;
                    $seo->updateSection($info['id'], $section, $info['bind'], $info['subdomain'], (int) $info['is_draft']);
                }
            }
            $section['id'] = $info['id'];
            if ($info['is_subcategory']) {
                $success_text = "Подраздел успешно изменен";
                $url['msgok'] = 6;
            } else {
                $success_text = "Раздел успешно изменен";
                $url['msgok'] = 2;
            }
            break;
    }
    if ($info['old_position'] != $info['new_position'] && $info['parent'] == 0) {
        //       $objResponse->script("location.href = '/catalog/admin/'");
        $dir = $seo->getDirectionById($info['direct_id']);
        $url['direction'] = $dir['name_section_link'];
        if ($_SESSION['subdomain']) {
            $url['subdomain'] = $_SESSION['subdomain'];
        }
        $url = "/catalog/admin/?" . http_build_query($url);
        $objResponse->redirect($url);
        return $objResponse;
    }
    if ($info['old_direction'] != $info['direct_id']) {
        $dir = $seo->getDirectionById($info['direct_id']);
        $url['direction'] = $dir['name_section_link'];
        if ($_SESSION['subdomain']) {
            $url['subdomain'] = $_SESSION['subdomain'];
        }
        $url = "/catalog/admin/?" . http_build_query($url);
        $objResponse->redirect($url);
        return $objResponse;
    }
    $section = $seo->getFullSectionById($info['parent'] != 0 ? $info['parent'] : $section['id']);
    ob_start();
    include $_SERVER['DOCUMENT_ROOT'] . '/catalog/admin/tpl.section.php';
    $html = ob_get_clean();
    if ($info['parent'] != 0) {
        $objResponse->assign("section_{$info['parent']}", "innerHTML", $html);
        $objResponse->script("init_collapse_button('section_{$section['id']}');");
        // активируем кнопку разворачивания подменю
        $objResponse->script("\$('section_{$info['parent']}').addClass('active');");
    } else {
        if ($action == 'update') {
            $objResponse->assign("section_{$section['id']}", "innerHTML", $html);
            $objResponse->script("init_collapse_button('section_{$section['id']}');");
            // активируем кнопку разворачивания подменю
            $objResponse->script("\$('section_{$section['id']}').addClass('active');");
        } else {
            $objResponse->script("var section = new Element('li#section_{$section['id']}');\n                            \$('section_content').adopt(section);");
            $objResponse->assign("section_{$section['id']}", "innerHTML", $html);
        }
    }
    if ($info['parent'] != $info['old_parent'] && $action == 'update') {
        $section = $seo->getFullSectionById($info['old_parent']);
        ob_start();
        include $_SERVER['DOCUMENT_ROOT'] . '/catalog/admin/tpl.section.php';
        $html = ob_get_clean();
        $objResponse->assign("section_{$info['old_parent']}", "innerHTML", $html);
        $objResponse->script("init_collapse_button('section_{$info['old_parent']}');");
        // активируем кнопку разворачивания подменю
        $objResponse->script("\$('section_{$info['old_parent']}').removeClass('active');");
    }
    $objResponse->assign("form_content", "innerHTML", "<div class=\"b-fon b-fon_width_full b-fon_padbot_17\"><div class=\"b-fon__body b-fon__body_pad_10 b-fon__body_padleft_35 b-fon__body_fontsize_13 b-fon__body_bg_f0ffdf b-fon__body_bordbot_dfedcf\"><span class=\"b-icon b-icon_sbr_gok b-icon_margleft_-25\"></span><span>{$success_text}</span></div></div>");
    return $objResponse;
}