public static function CheckFields($ACTION, &$arFields, $statusId = '') { if ((is_set($arFields, "SORT") || $ACTION == "ADD") && IntVal($arFields["SORT"]) <= 0) { $arFields["SORT"] = 100; } if ((is_set($arFields, "ID") || $ACTION == "ADD") && strlen($arFields["ID"]) <= 0) { return false; } if (is_set($arFields, "ID") && strlen($statusId) > 0 && $statusId != $arFields["ID"]) { return false; } if (is_set($arFields, "ID") && !preg_match("#[A-Za-z]#i", $arFields["ID"]) || strlen($statusId) > 0 && !preg_match("#[A-Za-z]#i", $statusId)) { $GLOBALS["APPLICATION"]->ThrowException(Loc::getMessage("SKGS_ID_NOT_SYMBOL"), "ERROR_ID_NOT_SYMBOL"); return false; } $result = new Result(); if (!self::$statusFields) { self::$statusFields = StatusTable::getEntity()->getScalarFields(); self::$langFields = StatusLangTable::getEntity()->getScalarFields(); self::$taskFields = StatusGroupTaskTable::getEntity()->getScalarFields(); } switch ($ACTION) { case 'ADD': $statusId = $arFields['ID']; StatusTable::checkFields($result, null, array_intersect_key($arFields, self::$statusFields)); break; case 'UPDATE': StatusTable::checkFields($result, $statusId, array_intersect_key(array_diff_key($arFields, array('ID' => 1)), self::$statusFields)); break; default: throw new SystemException('Invalid action: ' . $ACTION, 0, __FILE__, __LINE__); } if (isset($arFields['LANG']) && is_array($arFields['LANG']) && !empty($arFields['LANG'])) { $availableLanguages = array_map('current', LanguageTable::getList(array('select' => array('LID'), 'filter' => array('=ACTIVE' => 'Y')))->fetchAll()); foreach ($arFields['LANG'] as $data) { if ($data['NAME'] && in_array($data['LID'], $availableLanguages)) { StatusLangTable::checkFields($result, null, array('STATUS_ID' => $statusId) + array_intersect_key($data, self::$langFields)); } else { return false; } } } return $result->isSuccess(); }
break; } } } } // prepare & check status $status = array('TYPE' => $statusType, 'SORT' => ($statusSort = intval($_POST['SORT'])) ? $statusSort : 100, 'NOTIFY' => $_POST['NOTIFY'] ? 'Y' : 'N'); $isNew = true; $result = new \Bitrix\Main\Entity\Result(); if ($statusId) { $isNew = false; $sid = $statusId; StatusTable::checkFields($result, $statusId, $status); } else { $sid = $status['ID'] = trim($_POST['NEW_ID']); StatusTable::checkFields($result, null, $status); } $errors = array_merge($errors, $result->getErrorMessages()); // prepare & check translations foreach ($languages as $languageId => $languageName) { $translationName = trim($_REQUEST['NAME_' . $languageId]); $translations[$languageId] = array('STATUS_ID' => $sid, 'LID' => $languageId, 'NAME' => $translationName, 'DESCRIPTION' => trim($_REQUEST['DESCRIPTION_' . $languageId])); if (!$translationName) { $errors[] = Loc::getMessage('ERROR_NO_NAME') . " [{$languageId}] " . htmlspecialcharsbx($languageName); } } // prepare & check group tasks foreach ($groups as $groupId => $groupName) { $taskId = $_REQUEST['TASK' . $groupId]; $groupTasks[$groupId] = array('STATUS_ID' => $sid, 'GROUP_ID' => $groupId, 'TASK_ID' => $taskId); if (!$tasks[$taskId]) {