private function importSection($arItems, $IBLOCK_ID = 0, $event = 'section') { if (!$IBLOCK_ID) { $IBLOCK_ID = $this->CATALOG_ID; } static $arResult = array(); $arChild = array(); foreach ($arItems as $arItem) { if (!strlen($arItem['XML_ID'])) { throw new \Exception('Empty section XML ID '.$arItem['name']); } if (!strlen($arItem['CODE'])) { $arItem['CODE'] = \CUtil::translit($arItem['NAME'], 'ru', array( "replace_space" => '-', "replace_other" => '-' )); } $arFields = array( 'ACTIVE' => $arItem['ACTIVE'], 'CODE' => $arItem['CODE'], 'NAME' => $arItem['NAME'], 'XML_ID' => $arItem['XML_ID'], 'TIMESTAMP_X' => new DateTime ); $arSection = $this->getSectionByXML($arItem['XML_ID'], $IBLOCK_ID); if ($arSection['ID'] > 0) { // если раздел существует, сравним хэши if (!App::compareHash($arItem) || $arItem['ACTIVE'] !== $arSection['ACTIVE']) { // если хэши не совпали, то проапдейтим найденый раздел SectionTable::update($arSection['ID'], $arFields); Report::update($event); } } else { if (strlen($arItem['SECTION_XML_ID']) > 0) { $arParent = $this->getSectionByXML($arItem['SECTION_XML_ID'], $IBLOCK_ID); if (!$arParent['ID']) { // тут хитрая штука, если дочерний раздел идет раньше родителя, // то и создать его нужно позже, чуть ниже вызывается рекурсия $arChild[] = $arItem; continue; } // если он есть, то текущий раздел сделаем потомком $arFields['IBLOCK_SECTION_ID'] = $arParent['ID']; } $arFields = array_merge($arFields, array( 'IBLOCK_ID' => $IBLOCK_ID, 'DESCRIPTION_TYPE' => 'text' )); $arSection['ID'] = SectionTable::add($arFields)->getId(); App::compareHash($arItem); Report::create($event); } // если раздел не нашли и не создали, выплюнем эксепшен if (!$arSection['ID']) { throw new \Exception('Cant create sections'); } $arResult[$arItem['XML_ID']] = $arSection['ID']; } if (!empty($arChild)) { $this->importSection($arChild, $IBLOCK_ID, $event); } \CIBlockSection::ReSort($IBLOCK_ID); return $arResult; }
function DeleteCategory($ID) { $iblock_permission = CIBlock::GetPermission(IBLOCK_ID); if ($iblock_permission < "W") { $GLOBALS["USER"]->RequiredHTTPAuthBasic(); return new CSOAPFault('Server Error', 'Unable to authorize user.'); } $ib_section = new CIBlockSection(); if ($ib_section->Delete($ID)) { CIBlockSection::ReSort(); return 1; } return new CSOAPFault('Server Error', 'Error: ' . $ib_section->LAST_ERROR); }
/** * Creates new section in iblock * @param $arParams * @param $arResult * @param $name * @return bool|int */ public static function createAlbum($arParams, $arResult, &$name) { if (!CModule::IncludeModule("iblock")) { return false; } $name = trim($name); $name = strlen($name) > 0 ? $name : GetMessage("P_NEW_ALBUM"); $name = strlen($name) > 0 ? $name : "New album"; $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $arParams["BEHAVIOUR"] == "USER" ? $arResult["GALLERY"]["ID"] : 0, "DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "UF_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "NAME" => $name); $GLOBALS["UF_DATE"] = $arFields["UF_DATE"]; $bs = new CIBlockSection(); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields); $ID = $bs->Add($arFields); if ($ID > 0) { CIBlockSection::ReSort($arParams["IBLOCK_ID"]); $arPropertiesNeed = array(); // Array of properties to create foreach ($arParams['converters'] as $val) { if ($val['code'] == "real_picture" || $val['code'] == "thumbnail") { continue; } $db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $val['code'])); if (!($db_res && ($res = $db_res->Fetch()))) { $arPropertiesNeed[] = $val['code']; } } if (count($arPropertiesNeed) > 0) { $obProperty = new CIBlockProperty(); foreach ($arPropertiesNeed as $key) { $res = $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "F", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . strToUpper($key))) > 0 ? GetMessage("P_" . strToUpper($key)) : strToUpper($key), "CODE" => strToUpper($key), "FILE_TYPE" => "jpg, gif, bmp, png, jpeg")); } } // Check Public property $arPropertiesNeed = array(); foreach (array("PUBLIC_ELEMENT", "APPROVE_ELEMENT") as $key) { $db_res = CIBlock::GetProperties($arParams["IBLOCK_ID"], array(), array("CODE" => $key)); if (!$db_res || !($res = $db_res->Fetch())) { $arPropertiesNeed[] = $key; } } if (count($arPropertiesNeed) > 0) { $obProperty = new CIBlockProperty(); foreach ($arPropertiesNeed as $key) { $obProperty->Add(array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "ACTIVE" => "Y", "PROPERTY_TYPE" => "S", "MULTIPLE" => "N", "NAME" => strLen(GetMessage("P_" . $key)) > 0 ? GetMessage("P_" . $key) : $key, "DEFAULT_VALUE" => "N", "CODE" => $key)); } } } return $ID > 0 ? $ID : false; }
function SectionsResort() { CIBlockSection::ReSort($this->next_step["IBLOCK_ID"]); }
if ($arParams["BEHAVIOUR"] == "USER" && intVal($arResult["SECTION"]["IBLOCK_SECTION_ID"]) == intVal($arResult["GALLERY"]["ID"])) { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~GALLERY_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"])); } elseif (intVal($arResult["SECTION"]["IBLOCK_SECTION_ID"]) > 0) { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $arResult["SECTION"]["IBLOCK_SECTION_ID"])); } else { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~INDEX_URL"], array()); } $arResultFields = array("ID" => $arResult["SECTION"]["ID"], "error" => "", "url" => $arResult["URL"]); } elseif ($e = $APPLICATION->GetException()) { $strWarning .= $e->GetString(); } else { $strWarning .= GetMessage("IBSEC_A_DELERR_REFERERS"); } } if (!$bVarsFromForm) { CIBlockSection::ReSort($arParams["IBLOCK_ID"]); PClearComponentCache(array("search.page", "search.tags.cloud", "photogallery.detail", "photogallery.detail.comment", "photogallery.detail.edit", "photogallery.detail.list", "photogallery.gallery.edit", "photogallery.gallery.list", "photogallery.section", "photogallery.section.edit", "photogallery.section.edit.icon", "photogallery.section.list", "photogallery.upload", "photogallery.user")); if ($arParams["AJAX_CALL"] == "Y") { $APPLICATION->RestartBuffer(); echo CUtil::PhpToJSObject($arResultFields); die; } else { LocalRedirect($arResult["URL"]); } } $arResult["ERROR_MESSAGE"] = $strWarning; } /******************************************************************** /Actions ********************************************************************/ /********************************************************************
function ReSort($IBLOCK_ID, $ID = 0, $cnt = 0, $depth = 0, $ACTIVE = "Y") { global $DB; $IBLOCK_ID = IntVal($IBLOCK_ID); if ($ID > 0) { $DB->Query("\n\t\t\t\tUPDATE\n\t\t\t\t\tb_iblock_section\n\t\t\t\tSET\n\t\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t\t,RIGHT_MARGIN=" . IntVal($cnt) . "\n\t\t\t\t\t,LEFT_MARGIN=" . IntVal($cnt) . "\n\t\t\t\tWHERE\n\t\t\t\t\tID=" . IntVal($ID)); } $strSql = "\n\t\t\tSELECT BS.ID, BS.ACTIVE\n\t\t\tFROM b_iblock_section BS\n\t\t\tWHERE BS.IBLOCK_ID = " . $IBLOCK_ID . "\n\t\t\tAND " . ($ID > 0 ? "BS.IBLOCK_SECTION_ID=" . IntVal($ID) : "BS.IBLOCK_SECTION_ID IS NULL") . "\n\t\t\tORDER BY BS.SORT, BS.NAME\n\t\t"; $cnt++; $res = $DB->Query($strSql); while ($arr = $res->Fetch()) { $cnt = CIBlockSection::ReSort($IBLOCK_ID, $arr["ID"], $cnt, $depth + 1, $ACTIVE == "Y" && $arr["ACTIVE"] == "Y" ? "Y" : "N"); } if ($ID == 0) { $obIBlockRights = new CIBlockRights($IBLOCK_ID); $obIBlockRights->Recalculate(); return true; } $DB->Query("\n\t\t\tUPDATE\n\t\t\t\tb_iblock_section\n\t\t\tSET\n\t\t\t\tTIMESTAMP_X=" . ($DB->type == "ORACLE" ? "NULL" : "TIMESTAMP_X") . "\n\t\t\t\t,RIGHT_MARGIN=" . IntVal($cnt) . "\n\t\t\t\t,DEPTH_LEVEL=" . IntVal($depth) . "\n\t\t\t\t,GLOBAL_ACTIVE='" . $ACTIVE . "'\n\t\t\tWHERE\n\t\t\t\tID=" . IntVal($ID)); return $cnt + 1; }
function GetAlbumId($Params) { $arParams = $Params['arParams']; $sectionId = false; $savedData = CImageUploader::GetSavedData(); $arResult = $Params['~arResult']; if ($savedData['SECTION_ID'] <= 0) { // Upload photos to existing album if ($Params['id'] !== 'new' && intVal($Params['id']) > 0) { $sectionId = intVal($Params['id']); } else { if ($Params['id'] == 'new') { $Params['name'] = trim($Params['name']); if (empty($Params['name'])) { $Params['name'] = strLen(GetMessage("P_NEW_ALBUM")) > 0 ? GetMessage("P_NEW_ALBUM") : "New album"; } $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $arParams["IBLOCK_ID"], "IBLOCK_SECTION_ID" => $arParams["BEHAVIOUR"] == "USER" ? $arResult["GALLERY"]["ID"] : 0, "DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "UF_DATE" => ConvertTimeStamp(time() + CTimeZone::GetOffset()), "NAME" => $Params['name']); $GLOBALS["UF_DATE"] = $arFields["UF_DATE"]; $bs = new CIBlockSection(); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", $arFields); $ID = $bs->Add($arFields); if ($ID > 0) { CIBlockSection::ReSort($arParams["IBLOCK_ID"]); $sectionId = intVal($ID); $arFilter = array("IBLOCK_ID" => $arParams["IBLOCK_ID"], "CODE" => $arParams["USER_ALIAS"], "SECTION_ID" => 0); //$db_res = CIBlockSection::GetList(array(), $arFilter, false, array("ID", "NAME", "CREATED_BY", "RIGHT_MARGIN", "LEFT_MARGIN", "CODE", "UF_GALLERY_SIZE")); //$arResult["GALLERY"] = $db_res->Fetch(); $savedData['NEW_SECTION_NAME'] = $Params['name']; $savedData['NEW_SECTION_PICTURE'] = ""; } else { CImageUploader::SaveError(array(array("id" => "BXPH_FUNC_001", "text" => $bs->LAST_ERROR))); } } } } $savedData["SECTION_ID"] = $sectionId; CImageUploader::SetSavedData($savedData); return $sectionId; }
$xGroupNode = $groups[$j]; $GROUP_XML_ID = $xGroupNode->GetAttribute($nameUTF['ID']); $GROUP_PARENT_XML_ID = $xGroupNode->GetAttribute($nameUTF['ParentCategory']); $GROUP_NAME = $xGroupNode->GetAttribute($nameUTF['Name']); $arGrTmp[$tmpid.$GROUP_PARENT_XML_ID][] = Array( "GROUP_XML_ID"=>$GROUP_XML_ID, "GROUP_PARENT_XML_ID"=>$GROUP_PARENT_XML_ID, "GROUP_NAME"=>$GROUP_NAME ); } $arGroups = array(); AddSectionsRecursive(); CIBlockSection::ReSort($IBLOCK_ID); $el = new CIBlockElement(); $arProducts = array(); $products = $xCatNode->select_nodes("/".$nameUTF['Product']); for ($j = 0, $intProdCount = count($products); $j < $intProdCount; $j++) { $xProductNode = $products[$j]; $PRODUCT_XML_ID = $xProductNode->GetAttribute($nameUTF['ID']); $PRODUCT_PARENT_XML_ID = $xProductNode->GetAttribute($nameUTF['ParentCategory']); $PRODUCT_NAME = $xProductNode->GetAttribute($nameUTF['Name']); $PROP = array(); $GROUPS_ID = array(); if(strlen($PRODUCT_PARENT_XML_ID)>0 && strlen($arGroups[$PRODUCT_PARENT_XML_ID])>0)
} elseif (intVal($arResult["SECTION"]["IBLOCK_SECTION_ID"]) > 0) { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $arResult["SECTION"]["IBLOCK_SECTION_ID"])); } else { $arResult["URL"] = CComponentEngine::MakePathFromTemplate($arParams["~INDEX_URL"], array()); } $arResultFields = array("ID" => $arResult["SECTION"]["ID"], "error" => "", "url" => $arResult["URL"]); } elseif ($e = $APPLICATION->GetException()) { $strWarning .= $e->GetString(); $bVarsFromForm = true; } else { $strWarning .= GetMessage("IBSEC_A_DELERR_REFERERS"); $bVarsFromForm = true; } } if (!$bVarsFromForm) { CIBlockSection::ReSort($iblockId); $sectionsIds = array(0); $arGalleriesIds = array(0); $arUsers = array(); if ($ID > 0) { // Add $sectionsIds[] = $ID; } if ($arParams['SECTION_ID']) { // Del, edit $sectionsIds[] = $arParams['SECTION_ID']; } if ($arFields && $arFields['IBLOCK_SECTION_ID']) { $sectionsIds[] = $arFields['IBLOCK_SECTION_ID']; } if (isset($arResult) && isset($arResult['SECTION']['IBLOCK_SECTION_ID'])) {
function __intr_process_action($action, $arParams, &$res, &$mode, &$arUndo, &$undo_text) { $IBLOCK_ID = $arParams['IBLOCK_ID']; switch ($action) { case 'set_department_head': $dpt = intval($_REQUEST['dpt_id']); $user_id = intval($_REQUEST['user_id']); $ok = false; if ($dpt > 0 && $user_id > 0) { $dbUser = CUser::GetByID($user_id); if ($arUser = $dbUser->Fetch()) { $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt, "IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y"), false, array('NAME', 'UF_HEAD')); if ($arSection = $dbRes->GetNext()) { $ok = true; $ob = new CIBlockSection(); if ($ob->Update($dpt, array('UF_HEAD' => $user_id))) { $arUndo[] = array('action' => 'set_department_head', 'dpt_id' => $dpt, 'user_id' => $arSection['UF_HEAD']); $undo_text = GetMessage('ISV_set_department_head', array("#NAME#" => CUser::FormatName($arParams['NAME_TEMPLATE'], $arUser), "#DEPARTMENT#" => $arSection['NAME'])); $mode = 'reload'; } else { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } } } if (!$ok) { $res = array('error' => 'Wrong data'); } // we should change user department too, but have to return error if one exists if (is_array($res)) { break; } case 'change_department': $user_id = intval($_REQUEST['user_id']); $dpt_id = intval($_REQUEST['dpt_id']); $dpt_from = intval($_REQUEST['dpt_from']); $type = intval($_REQUEST['type']); $ok = false; if ($user_id > 0 && $dpt_id > 0) { if (isset($arUser)) { $arRes = $arUser; } else { $dbRes = CUser::GetByID($user_id); $arRes = $dbRes->Fetch(); } if (!isset($arSection)) { $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt_id, 'IBLOCK_ID' => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); $arSection = $dbRes->GetNext(); } if ($arRes && $arSection) { $ok = true; $arOldDpt = $arDpt = $arRes['UF_DEPARTMENT']; if ($type != 1) { foreach ($arDpt as $key => $dpt) { if ($dpt == $dpt_from) { unset($arDpt[$key]); break; } } } $arDpt[] = $dpt_id; } $obUser = new CUser(); if ($obUser->Update($user_id, array('UF_DEPARTMENT' => array_unique($arDpt)))) { if ($type != 1) { $arUndo[] = array('action' => 'change_department', 'user_id' => $user_id, 'dpt_id' => $dpt_from, 'dpt_from' => $dpt_id); if (!$undo_text) { $undo_text = GetMessage("ISV_change_department", array("#NAME#" => CUser::FormatName($arParams['NAME_TEMPLATE'], $arRes), "#DEPARTMENT#" => $arSection['NAME'])); } } if ($action != 'set_department_head' || $dpt_id != $dpt_from) { $dbRes = CIBlockSection::GetList(array(), array('ID' => $dpt_from, 'IBLOCK_ID' => $IBLOCK_ID, 'UF_HEAD' => $user_id)); if ($arSection = $dbRes->GetNext()) { if ($type != 1) { $arUndo[] = array('action' => 'set_department_head', 'dpt_id' => $dpt_from, 'user_id' => $user_id); } $obIBlockSection = new CIBlockSection(); $obIBlockSection->Update($dpt_from, array('UF_HEAD' => 0)); } } } } if (!$ok) { $res = array('error' => 'Wrong data'); } else { $mode = 'reload'; } break; case 'delete_department': $dpt = intval($_REQUEST['dpt_id']); $dbRes = CIBlockSection::GetList(array(), array("ID" => $dpt, "IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); if ($arSection = $dbRes->Fetch()) { if ($arSection['IBLOCK_SECTION_ID'] > 0) { $dbRes = CUser::GetList($by, $order, array('UF_DEPARTMENT' => $dpt), array('SELECT' => array('ID'))); if (!$dbRes->Fetch()) { $dbRes = CIBlockSection::GetList(array(), array('IBLOCK_ID' => $IBLOCK_ID, 'SECTION_ID' => $arSection['ID'])); $obIBlockSection = new CIBlockSection(); $GLOBALS['DB']->StartTransaction(); while ($arRes = $dbRes->Fetch()) { $obIBlockSection->Update($arRes['ID'], array('IBLOCK_SECTION_ID' => $arSection['IBLOCK_SECTION_ID'])); } if ($obIBlockSection->Delete($arSection['ID'])) { $GLOBALS['DB']->Commit(); $mode = 'reload'; } else { $GLOBALS['DB']->Rollback(); $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } else { $res = array('error' => GetMessage('ISV_ERROR_dpt_not_empty')); } } } break; case 'move_department': $dpt = intval($_REQUEST['dpt_id']); $dpt_to = intval($_REQUEST['dpt_to']); $ok = false; if ($dpt > 0 && $dpt_to > 0) { $dbRes = CIBlockSection::GetList(array(), array("ID" => array($dpt, $dpt_to), 'IBLOCK_ID' => $IBLOCK_ID, "CHECK_PERMISSIONS" => "Y")); while ($arRes = $dbRes->GetNext()) { if ($arRes['ID'] == $dpt) { $arSection = $arRes; } else { $arSectionTo = $arRes; } } if ($arSection && $arSectionTo) { $ok = true; $ob = new CIBlockSection(); if ($ob->Update($dpt, array('IBLOCK_SECTION_ID' => $dpt_to))) { $mode = 'reload'; $arUndo[] = array('action' => 'move_department', 'dpt_id' => $dpt, 'dpt_to' => $arSection['IBLOCK_SECTION_ID']); $undo_text = GetMessage('ISV_move_department', array("#DEPARTMENT#" => $arSection["NAME"], "#DEPARTMENT_TO#" => $arSectionTo["NAME"])); } else { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } } // we should resort departments in this case if (is_array($res) || !$_REQUEST['dpt_parent']) { break; } case 'sort_department': $dpt_id = intval($_REQUEST['dpt_id']); $dpt_before = intval($_REQUEST['dpt_before']); $dpt_after = intval($_REQUEST['dpt_after']); $dpt_parent = intval($_REQUEST['dpt_parent']); $ok = false; if ($dpt_id > 0 && $dpt_parent > 0 && ($dpt_before > 0 || $dpt_after > 0)) { $arSections = array(); $dbRes = CIBlockSection::GetList(array('left_margin' => asc), array('IBLOCK_ID' => $IBLOCK_ID, 'SECTION_ID' => $dpt_parent)); $arCurrentSection = array(); $arSections = array(); $sortAfter = 0; $sortBefore = 0; while ($arSection = $dbRes->GetNext()) { if ($arSection['ID'] != $dpt_id) { $arSections[] = $arSection; } else { $arCurrentSection = $arSection; } if ($arSection['ID'] == $dpt_after) { $sortAfter = $arSection['SORT']; } elseif ($arSection['ID'] == $dpt_before) { $sortBefore = $arSection['SORT']; } } $GLOBALS['APPLICATION']->RestartBuffer(); $new_sort = -1; if (!$dpt_before && $sortAfter > 0) { $new_sort = $sortAfter + 100; } elseif (!$dpt_after && $sortBefore > 1) { $new_sort = round($sortBefore / 2); } elseif ($dpt_before && $dpt_after && abs($sortBefore - $sortAfter) > 2) { $new_sort = round(abs($sortBefore + $sortAfter) / 2); } $obSection = new CIBlockSection(); if ($new_sort > 0) { // simple variant: update just one section $ok = true; if (!$obSection->Update($dpt_id, array('SORT' => $new_sort))) { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); } } else { if ($dpt_before && $dpt_after) { foreach ($arSections as $key => $arSection) { if ($arSection['ID'] == $dpt_before || $arSection['ID'] == $dpt_after) { $arSections = array_merge(array_slice($arSections, 0, $key + 1), array($arCurrentSection), array_slice($arSections, $key + 1)); break; } } } else { if (!$dpt_after) { array_unshift($arSections, $arCurrentSection); } else { $arSections[] = $arCurrentSection; } } $GLOBALS['DB']->StartTransaction(); $sort = 0; foreach ($arSections as $arSection) { $sort += 100; if (!$obSection->Update($arSection['ID'], array('SORT' => $sort), false)) { $res = array('error' => trim(str_replace('<br>', "\n", $ob->LAST_ERROR))); $GLOBALS['DB']->Rollback(); break; } } if (!is_array($res)) { CIBlockSection::ReSort($IBLOCK_ID); $GLOBALS['DB']->Commit(); $ok = true; } } } if (!is_array($res)) { if (!$ok) { $res = array('error' => 'Wrong data'); } else { $mode = 'reload'; } } break; } }