Example #1
0
 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();
 }
Example #2
0
$groupTasks = array();
// GROUP_ID => GROUP_ID, TASK_ID
$languages = array();
// LID => NAME
$groups = array();
// ID => NAME
$errors = array();
$tasks = array();
// ID => TASK
$result = TaskTable::getList(array('select' => array('*'), 'filter' => array('=MODULE_ID' => 'sale', '=BINDING' => 'status')));
while ($row = $result->fetch()) {
    $tasks[$row['ID']] = $row;
}
asort($tasks);
$statusFields = StatusTable::getEntity()->getFields();
$statusLangFields = StatusLangTable::getEntity()->getFields();
// get languages
$result = LanguageTable::getList(array('select' => array('LID', 'NAME'), 'filter' => array('=ACTIVE' => 'Y')));
while ($row = $result->fetch()) {
    $languages[$row['LID']] = $row['NAME'];
}
// get groups
$saleGroupIds = array();
$result = $APPLICATION->GetGroupRightList(array('MODULE_ID' => 'sale', 'G_ACCESS' => 'U'));
while ($row = $result->Fetch()) {
    if ($row['GROUP_ID'] > 2) {
        $saleGroupIds[] = $row['GROUP_ID'];
    }
}
if ($saleGroupIds) {
    $result = GroupTable::getList(array('select' => array('ID', 'NAME'), 'filter' => array('=ID' => $saleGroupIds), 'order' => array('C_SORT' => 'ASC', 'ID' => 'ASC')));