} } else { $arResult["ERRORS"][] = "Не могу обновить секцию"; } } else { if (CatalogSection::Add($arFields)) { AddMsg("Секция успешно добавлена!"); $this->redirectTo('/admin/catalog/catalog.php?TYPE=' . $arParams["TYPE"]); } else { $arResult["ERRORS"][] = "Такая секция уже есть"; } } } } if ($arParams["ID"] != '') { $rs = CatalogElement::GetByID($arParams["ID"]); if ($ob = $rs->GetNextElement()) { $arCatalogFields = $ob->GetFields(); $arResult["FIELDS"] = getCatalogFields($arCatalogFields); $arResult["PROPERTIES"] = $ob->GetProperties(); $arResult["MODE"] = "EDIT"; } else { AddMsg("Ошибка: Элемент с данным ID не найден!"); $this->redirectTo('/admin/catalog/catalog.php'); } } else { $arResult["FIELDS"] = getCatalogFields($arParams["FIELDS"], true); $arProps = Catalog::GetCatalogProperties($arParams["CATALOG_ID"]); $arResult["PROPERTIES"] = array(); foreach ($arProps as $k => $arProp) { $arProperties[] = array("ID" => $arProp["ID"], "NAME" => $arProp["NAME"], "VALUE" => $arProp["DEFAULT_VALUE"]);
<?php namespace ScriptAcid; if (!defined("KERNEL_INCLUDED") || KERNEL_INCLUDED !== true) { die; } if (!Modules::includeModule('catalog')) { ShowError("Модуль каталогов не установлен."); return; } $arParams["CATALOG_ID"] = intVal($arParams["CATALOG_ID"]); $arFilter = array(); if (array_key_exists("=SECTION_ID", $arParams)) { $arFilter['=CATALOG_SECTION_ID'] = empty($arParams["=SECTION_ID"]) ? 'NULL' : $arParams["=SECTION_ID"]; } else { $arFilter['CATALOG_SECTION_ID'] = !empty($arParams["SECTION_ID"]) ? intVal($arParams["SECTION_ID"]) : ''; } $arFilter["ID"] = intVal($arParams["ELEMENT_ID"]); $arFilter["CATALOG_ID"] = $arParams["CATALOG_ID"]; $rs = CatalogElement::GetList(array(), $arFilter); if ($ob = $rs->GetNextElement()) { $arElement = $ob->GetFields(); $arElement['PROPERTIES'] = $ob->GetProperties(); $arElement["DETAIL_PAGE_URL"] = str_replace(array("#SECTION_ID#", "#ID#"), array($arElement['CATALOG_SECTION_ID'], $arElement['ID']), $arElement["DETAIL_PAGE_URL"]); $arElement["SECTION_PAGE_URL"] = str_replace("#SECTION_ID#", $arElement['CATALOG_SECTION_ID'], $arElement["SECTION_PAGE_URL"]); $arResult = $arElement; SetTitle($arElement["NAME"]); } $this->connectComponentTemplate();
ShowMsg(); ?> <?php App::callComponent(":catalog.element.add", "_admin", array("FIELDS" => array("ID", "ACTIVE", "NAME", "CATALOG_SECTION_ID", "CATALOG_ID", "SORT", "CODE", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE", "DETAIL_PICTURE", "DETAIL_TEXT", "DETAIL_TEXT_TYPE", "TAGS"), "ID" => $_GET['ID'], "CATALOG_ID" => $_GET['CATALOG_ID'], "TYPE" => $_GET["TYPE"])); ?> <?php break; ?> <?php case 'DELETE': ?> <?php ShowMsg(); ?> <?php if (CatalogElement::Delete($_GET["ID"])) { AddMsg("Элемент успешно удалён"); RedirectTo('/scriptacid/admin/catalog/element.php' . '?CATALOG_ID=' . $_GET["CATALOG_ID"] . '&TYPE=' . $_GET["TYPE"] . '&ID=' . $_GET["ID"]); } else { echo ShowError("Ошибка при удалении элемента каталога"); } ?> <p><a href="/scriptacid/admin/catalog/">Список типов</a></p> <?php break; ?> <?php default: ?>
} } else { $arProperties[$propID] = $_POST["PROPERTY"][$propID]; } } } } $arElementFields = array("CATALOG_SECTION_ID" => intVal($_POST["CATALOG_SECTION_ID"]), "SORT" => intVal($_POST["SORT"]), "CODE" => sXss($_POST["CODE"]), "NAME" => sXss($_POST["NAME"]), "ACTIVE" => $_POST["ACTIVE"] == "Y" ? "Y" : '', "CATALOG_ID" => intVal($arParams["CATALOG_ID"]), "PREVIEW_TEXT" => sXss($_POST["PREVIEW_TEXT"]), "PREVIEW_PICTURE" => $_FILES["PREVIEW_PICTURE"], "PREVIEW_TEXT_TYPE" => sXss($_POST["PREVIEW_TEXT_TYPE"]), "DETAIL_TEXT" => sXss($_POST["DETAIL_TEXT"]), "DETAIL_TEXT_TYPE" => sXss($_POST["DETAIL_TEXT_TYPE"]), "DETAIL_PICTURE" => $_FILES["DETAIL_PICTURE"], "PROPERTIES" => $arProperties); if ($arParams['PREVIEW_FROM_DETAIL'] == "Y") { $arElementFields['PREVIEW_TEXT'] = TruncateText(sXss($_POST["DETAIL_TEXT"]), $arParams['PREVIEW_TEXT_LENGTH']); } if ($arParams["ID"] > 0) { if (CatalogElement::Update($arParams["ID"], $arElementFields)) { AddMsg($arParams['MSG_EDIT']); if (!isset($_POST["apply_btn"])) { $this->redirectTo($arParams['LIST_URL']); } } else { $arResult["ERRORS"][] = "Не могу найти элемент каталога"; } } else { if (CatalogElement::Add($arElementFields)) { AddMsg($arParams['MSG_ADD']); $this->redirectTo($arParams['LIST_URL']); } else { $arResult["ERRORS"][] = "Такой элемент каталога уже есть"; } } } } $this->connectComponentTemplate();
$arLimit = array('PAGE' => $arParams['CURRENT_PAGE'], 'COUNT' => $arParams['PAGE_COUNT']); } if (!empty($arParams['SORT_FIELD']) and !empty($arParams['SORT_ORDER'])) { $arOrder[$arParams['SORT_FIELD']] = $arParams['SORT_ORDER']; } else { $arOrder = array("ID" => "DESC"); } $arParams["CACHE_OFF"] = $arParams["CACHE_OFF"] == "Y" ? true : false; $cache = new Cache(array($arParams), 3600, !$arParams["CACHE_OFF"]); if ($cache->StartCache()) { $rs = CatalogElement::GetList($arOrder, $arFilter, array(), $arLimit); $arResult['PAGINATION'] = $rs->GetPagination(); while ($ob = $rs->GetNextElement()) { $arElement = $ob->GetFields(); $arElement['PROPERTIES'] = $ob->GetProperties(); if (intVal($arElement['CATALOG_SECTION_ID']) > 0) { $rsec = CatalogSection::GetByID($arElement['CATALOG_SECTION_ID']); $arSection = $rsec->GetNext(); } else { $arSection['CODE'] = ''; } $arPrepare = array('ID' => $arElement['ID'], 'SECTION_ID' => $arElement['CATALOG_SECTION_ID'], 'SECTION_CODE' => $arSection['CODE']); $arElement["DETAIL_PAGE_URL"] = CatalogElement::PrepareURL($arPrepare, $arElement["DETAIL_PAGE_URL"]); $arElement["SECTION_PAGE_URL"] = CatalogElement::PrepareURL($arPrepare, $arElement["SECTION_PAGE_URL"]); $arResult["ITEMS"][] = $arElement; } $cache->SaveCache($arResult); } else { $arResult = $cache->GetCache(); } $this->connectComponentTemplate();