Beispiel #1
0
 function CopyCommentRights($ID, $arFields)
 {
     if (empty($arFields['LOG_ID'])) {
         return false;
     }
     if (empty(self::$storedFileIdsByComment[$arFields['SOURCE_ID']])) {
         return false;
     }
     $arRights0 = array();
     $rConst = 0;
     $rs = CTask::GetList(array("LETTER" => "asc"), array("MODULE_ID" => "iblock", "LETTER" => "R"));
     if ($ar = $rs->Fetch()) {
         $rConst = $ar["ID"];
     } else {
         return false;
     }
     $dbRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arFields["LOG_ID"]));
     $i = 1;
     while ($arRight = $dbRight->Fetch()) {
         /*$arRights0["n" .$i] = Array(
         			"GROUP_CODE" => $arRight["GROUP_CODE"],
         			"TASK_ID" => $rConst,
         		);*/
         $gc = $arRight["GROUP_CODE"];
         if (array_key_exists($gc, $arRights0) && $arRights0[$gc]["TASK_ID"] >= $rConst) {
             continue;
         }
         $arRights0[$gc] = array("KEY" => "n" . $i, "GROUP_CODE" => $gc, "TASK_ID" => $rConst);
         $i++;
     }
     $arFilesID = self::$storedFileIdsByComment[$arFields['SOURCE_ID']];
     $arFiles = array();
     foreach ($arFilesID as $id) {
         $id = intval($id);
         if (intval($id) > 0) {
             $arFiles[] = $id;
         }
     }
     if (!$arFiles) {
         return;
     }
     $ibe = new CIBlockElement();
     $dbWDFile = $ibe->GetList(array(), array('ID' => $arFiles, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'NAME', 'SECTION_ID', 'IBLOCK_ID', 'WF_NEW'));
     while ($dbWDFile && ($arWDFile = $dbWDFile->Fetch())) {
         $arRights1 = $arRights0;
         $ob = new CIBlockElementRights($arWDFile['IBLOCK_ID'], $arWDFile['ID']);
         $ar = $ob->GetRights();
         foreach ($ar as $k => $v) {
             $gc = $v["GROUP_CODE"];
             if (array_key_exists($gc, $arRights1) && $arRights1[$gc]["TASK_ID"] >= $v["TASK_ID"]) {
                 continue;
             }
             $arRights1[$gc] = array("KEY" => $k, "GROUP_CODE" => $gc, "TASK_ID" => $v["TASK_ID"]);
         }
         $arRights2 = array();
         foreach ($arRights1 as $v) {
             $arRights2[$v["KEY"]] = array("GROUP_CODE" => $v["GROUP_CODE"], "TASK_ID" => $v["TASK_ID"]);
         }
         $ob->SetRights($arRights2);
     }
 }
Beispiel #2
0
 public function SetPermissions($documentId, $workflowId, $arPermissions, $bRewrite = true)
 {
     $documentId = intval($documentId);
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     $documentType = self::GetDocumentType($documentId);
     $iblockId = intval(substr($documentType, strlen("iblock_")));
     if ($iblockId <= 0) {
         throw new CBPArgumentOutOfRangeException("documentType", $documentType);
     }
     if (CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") !== "E") {
         return;
     }
     $ob = new CIBlockElementRights($iblockId, $documentId);
     $ar = $ob->GetRights();
     if ($bRewrite) {
         foreach ($ar as $i => $arRight) {
             if ($arRight["XML_ID"] == $workflowId) {
                 unset($ar[$i]);
             }
         }
     }
     $i = 0;
     $l = strlen("user_");
     foreach ($arPermissions as $taskId => $arUsers) {
         foreach ($arUsers as $user) {
             $gc = null;
             if ($user == 'author') {
                 $u = self::GetUsersFromUserGroup('author', $documentId);
                 foreach ($u as $u1) {
                     $gc = "U" . $u1;
                 }
             } else {
                 $gc = substr($user, 0, $l) == "user_" ? "U" . substr($user, $l) : "G" . $user;
             }
             if ($gc != null) {
                 $ar["n" . $i] = array("GROUP_CODE" => $gc, "TASK_ID" => $taskId, "XML_ID" => $workflowId);
                 $i++;
             }
         }
     }
     $ob->SetRights($ar);
 }
				</td>
			</tr>
			<?
		endif;
	endif;

	$tabControl->EndCustomField("BIZPROC", "");
endif;

if($arShowTabs['edit_rights']):
	$tabControl->BeginNextFormTab();
	if($ID > 0)
	{
		$obRights = new CIBlockElementRights($IBLOCK_ID, $ID);
		$htmlHidden = '';
		foreach($obRights->GetRights() as $RIGHT_ID => $arRight)
			$htmlHidden .= '
				<input type="hidden" name="RIGHTS[][RIGHT_ID]" value="'.htmlspecialcharsbx($RIGHT_ID).'">
				<input type="hidden" name="RIGHTS[][GROUP_CODE]" value="'.htmlspecialcharsbx($arRight["GROUP_CODE"]).'">
				<input type="hidden" name="RIGHTS[][TASK_ID]" value="'.htmlspecialcharsbx($arRight["TASK_ID"]).'">
			';
	}
	else
	{
		$obRights = new CIBlockSectionRights($IBLOCK_ID, $MENU_SECTION_ID);
		$htmlHidden = '';
	}

	$tabControl->BeginCustomField("RIGHTS", GetMessage("IBEL_E_RIGHTS_FIELD"));
		IBlockShowRights(
			'element',
 /**
  * @param array $arParams
  * @return array|false
  */
 public static function GetProductData($arParams)
 {
     $adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true;
     if (!isset($arParams['QUANTITY']) || (double) $arParams['QUANTITY'] <= 0) {
         $arParams['QUANTITY'] = 0;
     }
     $arParams['RENEWAL'] = isset($arParams['RENEWAL']) && $arParams['RENEWAL'] == 'Y' ? 'Y' : 'N';
     $arParams['CHECK_QUANTITY'] = isset($arParams['CHECK_QUANTITY']) && $arParams["CHECK_QUANTITY"] == 'N' ? 'N' : 'Y';
     $arParams['CHECK_PRICE'] = isset($arParams['CHECK_PRICE']) && $arParams['CHECK_PRICE'] == 'N' ? 'N' : 'Y';
     $arParams['CHECK_COUPONS'] = isset($arParams['CHECK_COUPONS']) && $arParams['CHECK_COUPONS'] == 'N' ? 'N' : 'Y';
     $arParams['CHECK_DISCOUNT'] = isset($arParams['CHECK_DISCOUNT']) && $arParams['CHECK_DISCOUNT'] == 'N' ? 'N' : 'Y';
     $arParams['SELECT_QUANTITY_TRACE'] = isset($arParams['SELECT_QUANTITY_TRACE']) && $arParams['SELECT_QUANTITY_TRACE'] == 'Y' ? 'Y' : 'N';
     $arParams['BASKET_ID'] = (string) (isset($arParams['BASKET_ID']) ? $arParams['BASKET_ID'] : '0');
     $arParams['USER_ID'] = isset($arParams['USER_ID']) ? (int) $arParams['USER_ID'] : 0;
     if ($arParams['USER_ID'] < 0) {
         $arParams['USER_ID'] = 0;
     }
     $arParams['SITE_ID'] = isset($arParams['SITE_ID']) ? $arParams['SITE_ID'] : false;
     $strSiteID = $arParams['SITE_ID'];
     $arParams['CURRENCY'] = isset($arParams['CURRENCY']) ? Currency\CurrencyManager::checkCurrencyID($arParams['CURRENCY']) : false;
     if ($arParams['CURRENCY'] === false) {
         $arParams['CURRENCY'] = CSaleLang::GetLangCurrency($strSiteID ? $strSiteID : SITE_ID);
     }
     $productID = (int) $arParams['PRODUCT_ID'];
     $quantity = (double) $arParams['QUANTITY'];
     $intUserID = (int) $arParams['USER_ID'];
     global $USER, $APPLICATION;
     $arResult = array();
     if ($adminSection) {
         if (!($userGroups = static::getHitCache('USER_GROUPS', $intUserID))) {
             $userGroups = self::getUserGroups($intUserID);
             static::setHitCache('USER_GROUPS', $intUserID, $userGroups);
         }
         if (empty($userGroups)) {
             return $arResult;
         }
         if (!($arProduct = static::getHitCache('IBLOCK_ELEMENT_PERM_N', $productID))) {
             $dbIBlockElement = CIBlockElement::GetList(array(), array('ID' => $productID, 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
             if ($arProduct = $dbIBlockElement->GetNext()) {
                 static::setHitCache('IBLOCK_ELEMENT_PERM_N', $productID, $arProduct);
             }
             unset($dbIBlockElement);
         }
         if (empty($arProduct) || !is_array($arProduct)) {
             return $arResult;
         }
         if (!($iblockRights = static::getHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID']))) {
             if ($iblockRights = CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'RIGHTS_MODE')) {
                 static::setHitCache('IBLOCK_RIGHT', $arProduct['IBLOCK_ID'], $iblockRights);
             }
         }
         $extRights = $iblockRights == 'E';
         if ($intUserID == 0) {
             if ($extRights) {
                 $elementRights = new CIBlockElementRights($arProduct['IBLOCK_ID'], $arProduct['ID']);
                 $readList = $elementRights->GetRights(array('operations' => array('element_read')));
                 $disable = true;
                 if (!empty($readList) && is_array($readList)) {
                     foreach ($readList as &$row) {
                         if ($row['GROUP_CODE'] == 'G2') {
                             $disable = false;
                             break;
                         }
                     }
                     unset($row);
                 }
                 unset($readList, $elementRights);
                 if ($disable) {
                     return $arResult;
                 }
                 unset($disable);
             } else {
                 $groupRights = CIBlock::GetGroupPermissions($arProduct['IBLOCK_ID']);
                 if (empty($groupRights) || !isset($groupRights[2]) || $groupRights[2] < 'R') {
                     return $arResult;
                 }
                 unset($groupRights);
             }
         } else {
             if ($extRights) {
                 $proxyUserPermissionKey = $productID . "|" . $intUserID;
                 if (!($arUserRights = static::getHitCache('USER_RIGHT', $proxyUserPermissionKey))) {
                     if ($arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID)) {
                         static::setHitCache('USER_RIGHT', $proxyUserPermissionKey, $arUserRights);
                     }
                 }
                 if (empty($arUserRights) || !isset($arUserRights['element_read'])) {
                     return $arResult;
                 }
                 unset($arUserRights);
             } else {
                 static $permissions = array();
                 if (empty($permissions[$arProduct['IBLOCK_ID'] . "_" . $intUserID])) {
                     $permissions[$arProduct['IBLOCK_ID'] . "_" . $intUserID] = CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID);
                 }
                 if ($permissions < 'R') {
                     return $arResult;
                 }
             }
         }
         unset($extRights);
     } else {
         $userGroups = $USER->GetUserGroupArray();
         if (!($arProduct = static::getHitCache('IBLOCK_ELEMENT_PERM_Y', $productID))) {
             $dbIBlockElement = CIBlockElement::GetList(array(), array('ID' => $productID, 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'R'), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
             if ($arProduct = $dbIBlockElement->GetNext()) {
                 static::setHitCache('IBLOCK_ELEMENT_PERM_Y', $productID, $arProduct);
             }
             unset($dbIBlockElement);
         }
         if (empty($arProduct) || !is_array($arProduct)) {
             return $arResult;
         }
     }
     if (!isset(self::$catalogList[$arProduct['IBLOCK_ID']])) {
         self::$catalogList[$arProduct['IBLOCK_ID']] = Catalog\CatalogIblockTable::getList(array('select' => array('IBLOCK_ID', 'SUBSCRIPTION'), 'filter' => array('=IBLOCK_ID' => $arProduct['IBLOCK_ID'])))->fetch();
     }
     if (empty(self::$catalogList[$arProduct['IBLOCK_ID']]) || !is_array(self::$catalogList[$arProduct['IBLOCK_ID']])) {
         return $arResult;
     }
     if (self::$catalogList[$arProduct['IBLOCK_ID']]['SUBSCRIPTION'] == 'Y') {
         $quantity = 1;
     }
     if (!($arCatalogProduct = static::getHitCache('CATALOG_PRODUCT', $productID))) {
         $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $productID), false, false, array('ID', 'CAN_BUY_ZERO', 'QUANTITY_TRACE', 'QUANTITY', 'WEIGHT', 'WIDTH', 'HEIGHT', 'LENGTH', 'BARCODE_MULTI', 'TYPE'));
         if ($arCatalogProduct = $rsProducts->Fetch()) {
             static::setHitCache('CATALOG_PRODUCT', $productID, $arCatalogProduct);
         }
         unset($rsProducts);
     }
     if (!empty($arCatalogProduct) && is_array($arCatalogProduct)) {
         $dblQuantity = doubleval($arCatalogProduct["QUANTITY"]);
         $boolQuantity = 'Y' != $arCatalogProduct["CAN_BUY_ZERO"] && 'Y' == $arCatalogProduct["QUANTITY_TRACE"];
         if ($arParams["CHECK_QUANTITY"] == "Y" && $boolQuantity && 0 >= $dblQuantity) {
             $APPLICATION->ThrowException(Loc::getMessage("CATALOG_NO_QUANTITY_PRODUCT", array("#NAME#" => htmlspecialcharsbx($arProduct["~NAME"]))), "CATALOG_NO_QUANTITY_PRODUCT");
             return $arResult;
         }
     } else {
         $APPLICATION->ThrowException(Loc::getMessage("CATALOG_ERR_NO_PRODUCT"), "CATALOG_NO_QUANTITY_PRODUCT");
         return $arResult;
     }
     if ($arParams["CHECK_PRICE"] == "Y") {
         $productHash = array('MODULE' => 'catalog', 'PRODUCT_ID' => $productID, 'BASKET_ID' => $arParams['BASKET_ID']);
         $arCoupons = array();
         if ($arParams['CHECK_COUPONS'] == 'Y') {
             $arCoupons = DiscountCouponsManager::getForApply(array(), $productHash, true);
             if (!empty($arCoupons)) {
                 $arCoupons = array_keys($arCoupons);
             }
         }
         if ($adminSection) {
             if ($intUserID > 0) {
                 CCatalogDiscountSave::SetDiscountUserID($intUserID);
             } else {
                 CCatalogDiscountSave::Disable();
             }
         }
         $currentVatMode = CCatalogProduct::getPriceVatIncludeMode();
         $currentUseDiscount = CCatalogProduct::getUseDiscount();
         CCatalogProduct::setUseDiscount($arParams['CHECK_DISCOUNT'] == 'Y');
         CCatalogProduct::setPriceVatIncludeMode(true);
         CCatalogProduct::setUsedCurrency($arParams['CURRENCY']);
         $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $arParams['RENEWAL'], array(), $adminSection ? $strSiteID : false, $arCoupons);
         if (empty($arPrice)) {
             if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $userGroups)) {
                 $quantity = $nearestQuantity;
                 $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $arParams['RENEWAL'], array(), $adminSection ? $strSiteID : false, $arCoupons);
             }
         }
         CCatalogProduct::clearUsedCurrency();
         CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
         CCatalogProduct::setUseDiscount($currentUseDiscount);
         unset($userGroups, $currentUseDiscount, $currentVatMode);
         if ($adminSection) {
             if ($intUserID > 0) {
                 CCatalogDiscountSave::ClearDiscountUserID();
             } else {
                 CCatalogDiscountSave::Enable();
             }
         }
         if (empty($arPrice)) {
             return $arResult;
         }
         $arDiscountList = array();
         if (empty($arPrice['DISCOUNT_LIST']) && !empty($arPrice['DISCOUNT']) && is_array($arPrice['DISCOUNT'])) {
             $arPrice['DISCOUNT_LIST'] = array($arPrice['DISCOUNT']);
         }
         if (!empty($arPrice['DISCOUNT_LIST'])) {
             $appliedCoupons = array();
             foreach ($arPrice['DISCOUNT_LIST'] as &$arOneDiscount) {
                 $arOneList = array('ID' => $arOneDiscount['ID'], 'NAME' => $arOneDiscount['NAME'], 'COUPON' => '', 'COUPON_TYPE' => '', 'USE_COUPONS' => isset($arOneDiscount['USE_COUPONS']) ? $arOneDiscount['USE_COUPONS'] : 'N', 'MODULE_ID' => isset($oneDiscount['MODULE_ID']) ? $oneDiscount['MODULE_ID'] : 'catalog', 'TYPE' => $arOneDiscount['TYPE'], 'VALUE' => $arOneDiscount['VALUE'], 'VALUE_TYPE' => $arOneDiscount['VALUE_TYPE'], 'MAX_VALUE' => $arOneDiscount['VALUE_TYPE'] == Catalog\DiscountTable::VALUE_TYPE_PERCENT ? $arOneDiscount['MAX_DISCOUNT'] : 0, 'CURRENCY' => $arOneDiscount['CURRENCY'], 'HANDLERS' => isset($arOneDiscount['HANDLERS']) ? $arOneDiscount['HANDLERS'] : array());
                 if (!empty($arOneDiscount['COUPON'])) {
                     $arOneList['USE_COUPONS'] = 'Y';
                     $arOneList['COUPON'] = $arOneDiscount['COUPON'];
                     $arOneList['COUPON_TYPE'] = $arOneDiscount['COUPON_ONE_TIME'];
                     $appliedCoupons[] = $arOneDiscount['COUPON'];
                 }
                 $arDiscountList[] = $arOneList;
             }
             unset($arOneList, $arOneDiscount);
             if (!empty($appliedCoupons)) {
                 $resultApply = DiscountCouponsManager::setApplyByProduct($productHash, $appliedCoupons);
             }
             unset($resultApply, $appliedCoupons);
         }
         if (empty($arPrice['PRICE']['CATALOG_GROUP_NAME'])) {
             if (!empty($arPrice['PRICE']['CATALOG_GROUP_ID'])) {
                 $priceName = self::getPriceTitle($arPrice['PRICE']['CATALOG_GROUP_ID']);
                 if ($priceName != '') {
                     $arPrice['PRICE']['CATALOG_GROUP_NAME'] = $priceName;
                 }
                 unset($priceName);
             }
         }
     } else {
         $vatRate = 0.0;
         if (!($arVAT = static::getHitCache('VAT_INFO', $productID))) {
             $rsVAT = CCatalogProduct::GetVATInfo($productID);
             if ($arVAT = $rsVAT->Fetch()) {
                 static::setHitCache('VAT_INFO', $productID, $arVAT);
             }
             unset($rsVAT);
         }
         if (!empty($arVAT) && is_array($arVAT)) {
             $vatRate = (double) $arVAT['RATE'] * 0.01;
         }
     }
     $arResult = array("NAME" => $arProduct["~NAME"], "CAN_BUY" => "Y", "DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'], "BARCODE_MULTI" => $arCatalogProduct["BARCODE_MULTI"], "WEIGHT" => (double) $arCatalogProduct['WEIGHT'], "DIMENSIONS" => serialize(array("WIDTH" => $arCatalogProduct["WIDTH"], "HEIGHT" => $arCatalogProduct["HEIGHT"], "LENGTH" => $arCatalogProduct["LENGTH"])), "TYPE" => $arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET ? CCatalogProductSet::TYPE_SET : null);
     if ($arParams['SELECT_QUANTITY_TRACE'] == "Y") {
         $arResult["QUANTITY_TRACE"] = $arCatalogProduct["QUANTITY_TRACE"];
     }
     if ($arParams["CHECK_QUANTITY"] == "Y") {
         $arResult["QUANTITY"] = $boolQuantity && $dblQuantity < $quantity ? $dblQuantity : $quantity;
     } else {
         $arResult["QUANTITY"] = $arParams["QUANTITY"];
     }
     if ($arParams["CHECK_QUANTITY"] == "Y" && $boolQuantity && $dblQuantity < $quantity) {
         $APPLICATION->ThrowException(Loc::getMessage("CATALOG_QUANTITY_NOT_ENOGH", array("#NAME#" => htmlspecialcharsbx($arProduct["~NAME"]), "#CATALOG_QUANTITY#" => $arCatalogProduct["QUANTITY"], "#QUANTITY#" => $quantity)), "CATALOG_QUANTITY_NOT_ENOGH");
     }
     if ($arParams['CHECK_PRICE'] == 'Y') {
         $arResult['PRODUCT_PRICE_ID'] = $arPrice['PRICE']['ID'];
         $arResult['NOTES'] = $arPrice['PRICE']['CATALOG_GROUP_NAME'];
         $arResult['VAT_RATE'] = $arPrice['PRICE']['VAT_RATE'];
         $arResult['DISCOUNT_NAME'] = '';
         $arResult['DISCOUNT_COUPON'] = '';
         $arResult['DISCOUNT_LIST'] = array();
         if (empty($arPrice['RESULT_PRICE']) || !is_array($arPrice['RESULT_PRICE'])) {
             $arPrice['RESULT_PRICE'] = CCatalogDiscount::calculateDiscountList($arPrice['PRICE'], $arParams['CURRENCY'], $arDiscountList, true);
         }
         $arResult['BASE_PRICE'] = $arPrice['RESULT_PRICE']['BASE_PRICE'];
         $arResult['PRICE'] = $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'];
         $arResult['CURRENCY'] = $arPrice['RESULT_PRICE']['CURRENCY'];
         $arResult['DISCOUNT_PRICE'] = $arPrice['RESULT_PRICE']['DISCOUNT'];
         if (isset($arPrice['RESULT_PRICE']['PERCENT'])) {
             $arResult['DISCOUNT_VALUE'] = $arPrice['RESULT_PRICE']['PERCENT'] > 0 ? $arPrice['RESULT_PRICE']['PERCENT'] . '%' : 0;
         } else {
             $arResult['DISCOUNT_VALUE'] = $arPrice['RESULT_PRICE']['DISCOUNT_VALUE'];
         }
         if (!empty($arDiscountList)) {
             $arResult['DISCOUNT_LIST'] = $arDiscountList;
         }
         if (!empty($arPrice['DISCOUNT'])) {
             $arResult['DISCOUNT_NAME'] = '[' . $arPrice['DISCOUNT']['ID'] . '] ' . $arPrice['DISCOUNT']['NAME'];
             if (!empty($arPrice['DISCOUNT']['COUPON'])) {
                 $arResult['DISCOUNT_COUPON'] = $arPrice['DISCOUNT']['COUPON'];
             }
             if (empty($arResult['DISCOUNT_LIST'])) {
                 $arResult['DISCOUNT_LIST'] = array($arPrice['DISCOUNT']);
             }
         }
     } else {
         $arResult['VAT_RATE'] = $vatRate;
     }
     $arResult["VAT_INCLUDED"] = "Y";
     return $arResult;
 }
Beispiel #5
0
 static function GetReaders($ID, $iblockID = null)
 {
     static $arValidTasks = null;
     static $readersCache = array();
     $arReaders = array();
     $ID = (int) $ID;
     if ($ID <= 0) {
         return $arReaders;
     }
     if (isset($readersCache[$ID])) {
         return $readersCache[$ID];
     }
     if ($arValidTasks == null) {
         $arTasks = CWebDavIblock::GetTasks();
         $arValidTasks = array();
         foreach ($arTasks as $taskLetter => $taskID) {
             $arOperations = CTask::GetOperations($taskID, true);
             if (array_search('element_read', $arOperations) !== false) {
                 $arValidTasks[$taskID] = true;
             }
         }
     }
     if ($iblockID === null) {
         $rElement = CIBlockElement::GetList(array(), array('ID' => $ID, 'SHOW_NEW' => 'Y'), false, false, array('ID', 'IBLOCK_ID'));
         if ($rElement && ($arElement = $rElement->Fetch())) {
             $iblockID = $arElement['IBLOCK_ID'];
         }
     }
     $iblockID = (int) $iblockID;
     if ($iblockID <= 0) {
         return $arReaders;
     }
     $bSocNet = CModule::IncludeModule('socialnetwork');
     if (CIBlock::GetArrayByID($iblockID, "RIGHTS_MODE") === "E") {
         $ibRights = new CIBlockElementRights($iblockID, $ID);
         $arRights = $ibRights->GetRights();
         foreach ($arRights as $rightID => $arRight) {
             if (isset($arValidTasks[$arRight['TASK_ID']])) {
                 $arReaders[] = $arRight['GROUP_CODE'];
                 if ($bSocNet && preg_match('/^SG(\\d+)_[' . SONET_ROLES_OWNER . SONET_ROLES_MODERATOR . SONET_ROLES_USER . ']$/', $arRight['GROUP_CODE'], $matches)) {
                     $arReaders[] = "SG" . $matches[1];
                 }
             }
         }
     } else {
         $gr_res = CIBlock::GetGroupPermissions($iblockID);
         foreach ($gr_res as $group_id => $perm) {
             if ($perm >= 'R') {
                 $arReaders[] = 'G' . $group_id;
             }
         }
     }
     $readersCache[$ID] = array_unique($arReaders);
     return $readersCache[$ID];
 }
Beispiel #6
0
	public function SetPermissions($documentId, $workflowId, $arPermissions, $bRewrite = true)
	{
		$documentId = intval($documentId);
		if ($documentId <= 0)
			throw new CBPArgumentNullException("documentId");

		$documentType = self::GetDocumentType($documentId);
		$iblockId = intval(substr($documentType, strlen("iblock_")));
		if ($iblockId <= 0)
			throw new CBPArgumentOutOfRangeException("documentType", $documentType);

		if (CIBlock::GetArrayByID($iblockId, "RIGHTS_MODE") !== "E")
			return;

		$ob = new CIBlockElementRights($iblockId, $documentId);
		$documentRights = $ob->GetRights();

		$mode = 'Hold';
		$scope = 'ScopeWorkflow';

		if (is_array($bRewrite) && class_exists('CBPSetPermissionsMode'))
		{
			if (isset($bRewrite['setMode']))
				$mode = CBPSetPermissionsMode::outMode($bRewrite['setMode']);
			if (isset($bRewrite['setScope']))
				$scope = CBPSetPermissionsMode::outScope($bRewrite['setScope']);
		}
		elseif ($bRewrite == true)
		{
			$mode = 'Clear';
		}

		$overrideCodes = array();
		if ($mode == 'Clear' || $mode == 'Rewrite')
		{
			foreach ($documentRights as $i => $arRight)
			{
				if ($scope == 'ScopeDocument' || $scope == 'ScopeWorkflow' && $arRight["XML_ID"] == $workflowId)
				{
					if ($mode == 'Clear')
						unset($documentRights[$i]);

					if ($mode == 'Rewrite')
						$overrideCodes[$arRight["GROUP_CODE"]] = $i;
				}

			}
		}

		$i = 0;
		$l = strlen("user_");
		foreach ($arPermissions as $taskId => $arUsers)
		{
			foreach ($arUsers as $user)
			{
				if (!$user)
					continue;
				$gc = null;
				if ($user == 'author')
				{
					$u = self::GetUsersFromUserGroup('author', $documentId);
					foreach ($u as $u1)
						$gc = "U".$u1;
				}
				elseif (strpos($user, 'group_') === 0)
				{
					$gc = strtoupper(substr($user, strlen('group_')));
				}
				else
				{
					$gc = ((substr($user, 0, $l) == "user_") ? "U".substr($user, $l) : "G".$user);
				}
				if ($gc != null)
				{
					$documentRights["n".$i] = array("GROUP_CODE" => $gc, "TASK_ID" => $taskId, "XML_ID" => $workflowId);
					$i++;

					if (isset($overrideCodes[$gc]))
						unset($documentRights[$overrideCodes[$gc]]);
				}
			}
		}

		$ob->SetRights($documentRights);
	}
Beispiel #7
0
 $arTasks = CIBlockRights::GetRightsList();
 $arTaskLetters = CWebDavIblock::GetTasks();
 //bad hack. It's not public rights.
 if (isset($arTaskLetters['S'])) {
     unset($arTasks[$arTaskLetters['S']]);
 }
 if (isset($arTaskLetters['T'])) {
     unset($arTasks[$arTaskLetters['T']]);
 }
 $arResult['PERMISSIONS'] = $arTasks;
 if (!$bCreate) {
     $arRightParams = array("count_overwrited" => true);
     if (!empty($arResult['ENTITY_PARENTS'])) {
         $arRightParams['parents'] = $arResult['ENTITY_PARENTS'];
     }
     $arCurrent = $obIBlockRights->GetRights($arRightParams);
     foreach ($arCurrent as $arRightSet) {
         $arNames[] = $arRightSet["GROUP_CODE"];
     }
     $access = new CAccess();
     $arSubjs = $access->GetNames($arNames);
     if (!empty($arParams['SOCNET_TYPE']) && !$USER->CanDoOperation('webdav_change_settings') && intval($arParams['SOCNET_ID']) > 0) {
         foreach ($arCurrent as $rightID => &$arRight) {
             if ($arRight['GROUP_CODE'] === 'G1' && $arRight['IS_INHERITED'] === 'Y' && $arRight['TASK_ID'] === $arTaskLetters['X'] || $arRight['GROUP_CODE'] === 'G2' && $arRight['IS_INHERITED'] === 'Y' && $arRight['TASK_ID'] === $arTaskLetters['D']) {
                 unset($arCurrent[$rightID]);
                 // commont rights
                 continue;
             }
             if ($arParams['SOCNET_TYPE'] == 'group') {
                 if ($arRight['GROUP_CODE'] === 'SG' . $arParams['SOCNET_ID'] . '_A' && $arRight['TASK_ID'] === $arTaskLetters['X']) {
                     $arRight['IS_INHERITED'] = 'Y';