Esempio n. 1
0
         echo CUtil::PhpToJSObject(array('ERROR' => 'COULD NOT FIND ACTIVITY'));
         die;
     }
     $primaryOwnerTypeID = intval($arRes['OWNER_TYPE_ID']);
     $primaryOwnerID = intval($arRes['OWNER_ID']);
     if ($primaryOwnerTypeID !== $ownerTypeID || $primaryOwnerID !== $ownerID) {
         $primaryOwnerTypeName = CCrmOwnerType::ResolveName($primaryOwnerTypeID);
         $arBindings["{$primaryOwnerTypeName}_{$primaryOwnerID}"] = array('OWNER_TYPE_ID' => $primaryOwnerTypeID, 'OWNER_ID' => $primaryOwnerID);
     }
     $arFields['OWNER_ID'] = $primaryOwnerID;
     $arFields['OWNER_TYPE_ID'] = $primaryOwnerTypeID;
     if ($responsibleID > 0) {
         $arFields['RESPONSIBLE_ID'] = $responsibleID;
     }
     //Merge new bindings with old bindings
     $presentBindings = CCrmActivity::GetBindings($ID);
     foreach ($presentBindings as &$binding) {
         $bindingOwnerID = $binding['OWNER_ID'];
         $bindingOwnerTypeID = $binding['OWNER_TYPE_ID'];
         $bindingOwnerTypeName = CCrmOwnerType::ResolveName($bindingOwnerTypeID);
         $arBindings["{$bindingOwnerTypeName}_{$bindingOwnerID}"] = array('OWNER_TYPE_ID' => $bindingOwnerTypeID, 'OWNER_ID' => $bindingOwnerID);
     }
     unset($binding);
     $arFields['BINDINGS'] = array_values($arBindings);
     if (!CCrmActivity::Update($ID, $arFields, false, true, array('REGISTER_SONET_EVENT' => true))) {
         echo CUtil::PhpToJSObject(array('ERROR' => CCrmActivity::GetLastErrorMessage()));
         die;
     }
 }
 CCrmActivity::SaveCommunications($ID, $arComms, $arFields, !$isNew, false);
 $commData = array();
Esempio n. 2
0
 public static function WriteDiskFileToResponse($ownerTypeID, $ownerID, $fileID, &$errors, $options = array())
 {
     $ownerTypeID = (int) $ownerTypeID;
     $ownerTypeName = CCrmOwnerType::ResolveName($ownerTypeID);
     $ownerID = (int) $ownerID;
     $fileID = (int) $fileID;
     $options = is_array($options) ? $options : array();
     if (!CCrmOwnerType::IsDefined($ownerTypeID) || $ownerID <= 0 || $fileID <= 0) {
         $errors[] = 'Invalid data ownerTypeID = ' . $ownerTypeID . ', ownerID = ' . $ownerID . ', fileID = ' . $fileID;
         return false;
     }
     if ($ownerTypeID !== CCrmOwnerType::Activity) {
         $errors[] = "The owner type '{$ownerTypeName}' is not supported in current context";
         return false;
     }
     $authToken = isset($options['oauth_token']) ? $options['oauth_token'] : '';
     if ($authToken !== '') {
         $authData = array();
         if (!(CModule::IncludeModule('rest') && CRestUtil::checkAuth($authToken, CCrmRestService::SCOPE_NAME, $authData) && CRestUtil::makeAuth($authData))) {
             $errors[] = 'Access denied.';
             return false;
         }
     }
     if (!CCrmActivity::CheckStorageElementExists($ownerID, CCrmActivityStorageType::Disk, $fileID)) {
         $errors[] = 'File not found';
         return false;
     }
     $isPermitted = false;
     if (CCrmPerms::IsAdmin()) {
         $isPermitted = true;
     } else {
         $userPermissions = CCrmPerms::GetCurrentUserPermissions();
         $bindings = CCrmActivity::GetBindings($ownerID);
         foreach ($bindings as $binding) {
             if (CCrmAuthorizationHelper::CheckReadPermission($binding['OWNER_TYPE_ID'], $binding['OWNER_ID'], $userPermissions)) {
                 $isPermitted = true;
                 break;
             }
         }
     }
     if (!$isPermitted) {
         $errors[] = 'Access denied.';
         return false;
     }
     Bitrix\Crm\Integration\DiskManager::writeFileToResponse($fileID);
     return true;
 }