function AddProduct($NAME)
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $code = self::translit($NAME);
     $i = 1;
     while (true) {
         $res = CIBlockElement::Getlist(array(), array("CODE" => $code), false, array("CODE"));
         if ($res->Fetch()) {
             $code = self::translit($NAME) . $i;
         } else {
             break;
         }
         $i++;
     }
     $arFields = array("IBLOCK_ID" => IBLOCK_ID, "NAME" => $NAME);
     $ib_element = new CIBlockElement();
     $result = $ib_element->Add($arFields);
     if ($result > 0) {
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: ' . $ib_element->LAST_ERROR);
 }
 function GetIBlockCatalog()
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $result = IBLOCK_ID;
     return $result;
     return new CSOAPFault('Server Error', 'Error');
 }
 function GetProperties()
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     if ($result > 0) {
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: Свойства не получены');
 }
 function GetCategory()
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $res = CIBlockSection::GetList(array('LEFT_MARGIN' => 'ASC'), array("IBLOCK_ID" => IBLOCK_ID), false, array("ID", "NAME", "DEPTH_LEVEL"));
     $result = array();
     while ($arres = $res->GetNext()) {
         $result[] = array("ID" => $arres['ID'], "NAME" => $arres['NAME'], "DEPTH_LEVEL" => $arres['DEPTH_LEVEL']);
     }
     if (count($result) > 0) {
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: Нет ни одной категории');
 }
Exemple #5
0
 public static function CheckElementOperation($intIBlockID, $intElementID, $strOperation, $strAccess)
 {
     $intIBlockID = intval($intIBlockID);
     if ($intIBlockID <= 0) {
         return false;
     }
     $intElementID = intval($intElementID);
     if ($intElementID <= 0) {
         return false;
     }
     if (!self::$boolCheck) {
         self::CheckExtRights();
     }
     if (self::$boolExtRights) {
         return CIBlockElementRights::UserHasRightTo($intIBlockID, $intElementID, $strOperation);
     } else {
         return CIBlock::GetPermission($intIBlockID) >= $strAccess;
     }
 }
 public static function ValidateProperties($arTestProperties = array(), CBPWorkflowTemplateUser $user = null)
 {
     $arErrors = array();
     if (!array_key_exists("AbsenceUser", $arTestProperties) || count($arTestProperties["AbsenceUser"]) <= 0) {
         $arErrors[] = array("code" => "NotExist", "parameter" => "AbsenceUser", "message" => GetMessage("BPSNMA_EMPTY_ABSENCEUSER"));
     }
     if (!array_key_exists("AbsenceName", $arTestProperties) || count($arTestProperties["AbsenceName"]) <= 0) {
         $arErrors[] = array("code" => "NotExist", "parameter" => "AbsenceName", "message" => GetMessage("BPSNMA_EMPTY_ABSENCENAME"));
     }
     if (!array_key_exists("AbsenceFrom", $arTestProperties) || strlen($arTestProperties["AbsenceFrom"]) <= 0) {
         $arErrors[] = array("code" => "NotExist", "parameter" => "AbsenceFrom", "message" => GetMessage("BPSNMA_EMPTY_ABSENCEFROM"));
     }
     if (!array_key_exists("AbsenceTo", $arTestProperties) || strlen($arTestProperties["AbsenceTo"]) <= 0) {
         $arErrors[] = array("code" => "NotExist", "parameter" => "AbsenceTo", "message" => GetMessage("BPSNMA_EMPTY_ABSENCETO"));
     }
     $absenceIblockId = COption::GetOptionInt("intranet", 'iblock_absence', 0);
     $iblockPerm = CIBlock::GetPermission($absenceIblockId);
     if ($iblockPerm < "W") {
         $arErrors[] = array("code" => "perm", "message" => GetMessage("BPAA2_NO_PERMS"));
     }
     return array_merge($arErrors, parent::ValidateProperties($arTestProperties, $user));
 }
 /**
  * @param $productId
  * @param null $userId
  * @return bool
  * @throws Main\ArgumentException
  */
 public static function getProductAvailableQuantity($productId, $userId = null)
 {
     $adminSection = defined('ADMIN_SECTION') && ADMIN_SECTION === true;
     $userId = isset($userId) ? (int) $userId : 0;
     if ($userId < 0) {
         $userId = 0;
     }
     static $arUserCache = array();
     if ($adminSection) {
         if ($userId == 0) {
             return false;
         }
         if (!isset($arUserCache[$userId])) {
             $userIterator = Main\UserTable::getList(array('select' => array('ID'), 'filter' => array('=ID' => $userId)));
             if ($userDat = $userIterator->fetch()) {
                 $userDat['ID'] = (int) $userDat['ID'];
                 $arUserCache[$userDat['ID']] = CUser::GetUserGroup($userDat['ID']);
             } else {
                 return false;
             }
         }
         $dbIBlockElement = CIBlockElement::GetList(array(), array('ID' => $productId, 'ACTIVE' => 'Y', 'ACTIVE_DATE' => 'Y', 'CHECK_PERMISSION' => 'N'), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
         if (!($arProduct = $dbIBlockElement->GetNext())) {
             return false;
         }
         $iblockRights = null;
         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);
             }
         }
         if ($iblockRights == 'E') {
             $proxyUserPermissionKey = $productId . "|" . $userId;
             if (!($arUserRights = static::getHitCache('USER_RIGHT', $proxyUserPermissionKey))) {
                 if ($arUserRights = CIBlockElementRights::GetUserOperations($productId, $userId)) {
                     static::setHitCache('USER_RIGHT', $proxyUserPermissionKey, $arUserRights);
                 }
             }
             if (empty($arUserRights) || !isset($arUserRights['element_read'])) {
                 return false;
             }
             unset($arUserRights);
         } else {
             if (CIBlock::GetPermission($arProduct['IBLOCK_ID'], $userId) < 'R') {
                 return false;
             }
         }
     } else {
         $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())) {
             return false;
         }
     }
     $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY'));
     if ($arCatalogProduct = $rsProducts->Fetch()) {
         return $arCatalogProduct['QUANTITY'];
     }
     return false;
 }
Exemple #8
0
 public static function GetMeetingRoomById($Params)
 {
     if (IntVal($Params['RMiblockId']) > 0 && CIBlock::GetPermission($Params['RMiblockId']) >= "R") {
         $arFilter = array("IBLOCK_ID" => $Params['RMiblockId'], "ACTIVE" => "Y", "ID" => $Params['id']);
         $arSelectFields = array("NAME");
         $res = CIBlockSection::GetList(array(), $arFilter, false, array("NAME"));
         if ($arMeeting = $res->GetNext()) {
             return $arMeeting;
         }
     }
     if (IntVal($Params['VMiblockId']) > 0 && CIBlock::GetPermission($Params['VMiblockId']) >= "R") {
         $arFilter = array("IBLOCK_ID" => $Params['VMiblockId'], "ACTIVE" => "Y");
         $arSelectFields = array("ID", "NAME", "DESCRIPTION", "IBLOCK_ID");
         $res = CIBlockSection::GetList(array(), $arFilter, false, $arSelectFields);
         if ($arMeeting = $res->GetNext()) {
             return array('ID' => $Params['VMiblockId'], 'NAME' => $arMeeting["NAME"], 'DESCRIPTION' => $arMeeting['DESCRIPTION']);
         }
     }
     return false;
 }
Exemple #9
0
 /**
  * <p>Метод проверяет доступ пользователя.</p>
  *
  *
  *
  *
  * @param string $access  Тип проверяемого доступа (view, write, delete)
  *
  *
  *
  * @return bool 
  *
  *
  * <h4>See Also</h4> 
  * <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikiutils/IsReadable.php">CWikiUtils::isReadable</a>
  * </li> <li> <a
  * href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikiutils/IsWriteable.php">CWikiUtils::isWriteable</a> </li> <li>
  * <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikiutils/IsDeleteable.php">CWikiUtils::IsDeleteable</a> </li>
  * <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikiutils/IsAllowHTML.php">CWikiUtils::isAllowHTML</a>
  * </li> </ul><br><br>
  *
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwikiutils/CheckAccess.php
  * @author Bitrix
  */
 static function CheckAccess($access = 'view')
 {
     global $APPLICATION, $USER, $arParams;
     if ($USER->IsAdmin()) {
         return true;
     }
     if (CWikiSocnet::IsSocNet()) {
         $arSonetGroup = CSocNetGroup::GetByID($iSocNetId);
         if ($arSonetGroup && CSocNetUser::IsCurrentUserModuleAdmin($arSonetGroup['SITE_ID'])) {
             return true;
         }
         if (!CSocNetFeaturesPerms::CanPerformOperation($USER->GetID(), SONET_ENTITY_GROUP, CWikiSocnet::$iSocNetId, 'wiki', $access)) {
             return false;
         }
         return true;
     } else {
         $letter = 'R';
         $letterI = 'R';
         switch ($access) {
             case 'write':
                 $letter = 'W';
                 $letterI = 'W';
                 break;
             case 'delete':
                 $letter = 'Y';
                 $letterI = 'W';
                 break;
             case 'perm':
                 $letter = 'Z';
                 $letterI = 'X';
                 break;
         }
         $wikiModulePermission = $APPLICATION->GetGroupRight('wiki');
         $iblockPermission = CIBlock::GetPermission($arParams['IBLOCK_ID']);
         return $wikiModulePermission >= $letter && $iblockPermission >= $letterI;
     }
 }
Exemple #10
0
 function GetPermission($type, $id, $op = '', $runSymlinkProxy = true)
 {
     if ($this->e_rights) {
         if ($op === '') {
             return $this->GetPermissions($type, $id, $this->IBLOCK_ID);
         } else {
             if ($type == 'SECTION') {
                 if ($runSymlinkProxy) {
                     list($contextType, $contextEntityId) = $this->getContextData();
                     $sectionData = $this->getSectionDataForLinkAnalyze($id);
                     //if this element is link.
                     if ($sectionData && $sectionData['ID'] != $id) {
                         return self::GetPermission($type, $sectionData['ID'], $op);
                     }
                 }
             }
             $ibRights = $this->_get_ib_rights_object($type, $id);
             $result = $ibRights->UserHasRightTo($this->IBLOCK_ID, $id, trim($op));
             return $result;
         }
     } else {
         return CIBlock::GetPermission($this->IBLOCK_ID);
     }
 }
 function GetPermission()
 {
     static $arResult = array();
     $user_id = intVal($GLOBALS["USER"]->GetID());
     $user_groups = $GLOBALS["USER"]->GetGroups();
     if (!$this->IBlockID) {
         return false;
     }
     $arCache = array("id" => serialize(array("iblock_id" => $this->IBlockID, "permission" => $user_groups, "site" => SITE_ID)), "path" => $this->arCache["path"], "time" => $this->arCache["time"]);
     if (empty($arResult[$arCache["id"]])) {
         $cache = new CPHPCache();
         if ($arCache["time"] > 0 && $cache->InitCache($arCache["time"], $arCache["id"], $arCache["path"])) {
             $arResult[$arCache["id"]] = $cache->GetVars();
         } else {
             CModule::IncludeModule("iblock");
             $arResult[$arCache["id"]] = CIBlock::GetPermission($this->IBlockID);
             if ($arCache["time"] > 0) {
                 $cache->StartDataCache($arCache["time"], $arCache["id"], $arCache["path"]);
                 $cache->EndDataCache($arResult[$arCache["id"]]);
             }
         }
     }
     if (!empty($arResult[$arCache["id"]])) {
         if (!empty($this->Gallery) && "R" <= $arResult[$arCache["id"]] && $arResult[$arCache["id"]] < "W" && $this->Gallery["CREATED_BY"] == $user_id) {
             return "W";
         }
         return $arResult[$arCache["id"]];
     }
     return "D";
 }
Exemple #12
0
}
if ($taskType == "user") {
    $arParams["PATH_TO_TASKS"] = Str_Replace("#user_id#", "#owner_id#", $arParams["PATH_TO_USER_TASKS"]);
    $arParams["PATH_TO_TASKS_VIEW"] = Str_Replace("#user_id#", "#owner_id#", $arParams["PATH_TO_USER_TASKS_VIEW"]);
} else {
    $arParams["PATH_TO_TASKS"] = Str_Replace("#group_id#", "#owner_id#", $arParams["PATH_TO_GROUP_TASKS"]);
    $arParams["PATH_TO_TASKS_VIEW"] = Str_Replace("#group_id#", "#owner_id#", $arParams["PATH_TO_GROUP_TASKS_VIEW"]);
}
if (!$GLOBALS["USER"]->IsAuthorized()) {
    $arResult["NEED_AUTH"] = "Y";
} else {
    $arResult["FatalError"] = "";
    $arParams["TASK_TYPE"] = $taskType;
    $arParams["OWNER_ID"] = $ownerId;
    include $_SERVER['DOCUMENT_ROOT'] . "/bitrix/components/bitrix/intranet.tasks/init.php";
    $iblockPerm = CIBlock::GetPermission($iblockId);
    if ($iblockPerm < "R") {
        $arResult["FatalError"] .= GetMessage("INTV_NO_IBLOCK_PERMS") . ".";
    }
    if (StrLen($arResult["FatalError"]) <= 0) {
        if (!__InTaskCheckActiveFeature($taskType, $ownerId)) {
            $arResult["FatalError"] .= GetMessage("INTV_TASKS_OFF") . ".";
        }
    }
    if (StrLen($arResult["FatalError"]) <= 0) {
        $arResult["Perms"] = __InTaskInitPerms($taskType, $ownerId);
        if (!$arResult["Perms"]["view"]) {
            $arResult["FatalError"] .= GetMessage("INTV_NO_SONET_PERMS") . ".";
        }
    }
    if (StrLen($arResult["FatalError"]) <= 0) {
Exemple #13
0
 public static function CheckAccess($IBLOCK_ID)
 {
     $result = null;
     $events = GetModuleEvents("intranet", "OnSharepointCheckAccess");
     while ($arEvent = $events->Fetch()) {
         $res = ExecuteModuleEventEx($arEvent, array($IBLOCK_ID));
         if ($res === false) {
             return false;
         } elseif ($res === true) {
             $result = true;
         }
     }
     if (null === $result) {
         $result = CIBlock::GetPermission($IBLOCK_ID) >= 'W';
     }
     return $result;
 }
Exemple #14
0
	static function _check_if_user_has_right($obRights, $ID, $permission, $flags = 0)
	{
		global $DB, $USER;
		$USER_ID = 0;

		if($USER_ID > 0 && (!is_object($USER) || $USER_ID != $USER->GetID()))
		{
			$user_id = intval($USER_ID);
			$arGroups = CUser::GetUserGroup($USER_ID);

			if(
				in_array(1, $arGroups)
				&& COption::GetOptionString("main", "controller_member", "N") != "Y"
				&& COption::GetOptionString("main", "~controller_limited_admin", "N") != "Y"
			)
			{
				return CIBlockRights::_mk_result($ID, CIBlockRights::LetterToOperations("X"), true, $flags);
			}
		}
		elseif(!is_object($USER))
		{
			return CIBlockRights::_mk_result($ID, array(), false, $flags);
		}
		elseif($USER->IsAdmin())
		{
			return CIBlockRights::_mk_result($ID, CIBlockRights::LetterToOperations("X"), true, $flags);
		}

		$user_id = intval($USER->GetID());
		$arGroups = $USER->GetUserGroupArray();

		$RIGHTS_MODE = CIBlock::GetArrayByID($obRights->GetIBlockID(), "RIGHTS_MODE");
		if($RIGHTS_MODE === "E")
		{
			static $Ecache;
			if(is_array($ID))
				$arOperations = $obRights->GetUserOperations($ID, $user_id);
			else
			{
				$cache_id = $user_id."|".$ID;
				if(!isset($Ecache[$cache_id]))
					$Ecache[$cache_id] = $obRights->GetUserOperations($ID, $user_id);
				$arOperations = $Ecache[$cache_id];
			}

			if($flags & CIBlockRights::RETURN_OPERATIONS)
				return $arOperations;
			else
				return isset($arOperations[$permission]);
		}
		else//if($RIGHTS_MODE === "S")
		{
			$letter = CIBlock::GetPermission($obRights->GetIBlockID());
			$arOperations = CIBlockRights::_mk_result($ID, CIBlockRights::LetterToOperations($letter), CIBlockRights::LetterToOperations($letter), $flags);

			if($flags & CIBlockRights::RETURN_OPERATIONS)
				return $arOperations;
			else
				return isset($arOperations[$permission]);
		}
	}
Exemple #15
0
 public static function GetIBlockPermission($iblock_id, $user_id)
 {
     global $USER;
     //IBlock permissions by default
     $Permission = CIBlock::GetPermission($iblock_id, $user_id);
     if ($Permission < "W") {
         $arIBlock = CIBlock::GetArrayByID($iblock_id);
         if ($arIBlock) {
             //Check if iblock is list
             $arListsPerm = CLists::GetPermission($arIBlock["IBLOCK_TYPE_ID"]);
             if (count($arListsPerm)) {
                 //User groups
                 if ($user_id == $USER->GetID()) {
                     $arUserGroups = $USER->GetUserGroupArray();
                 } else {
                     $arUserGroups = $USER->GetUserGroup($user_id);
                 }
                 //One of lists admins
                 if (count(array_intersect($arListsPerm, $arUserGroups))) {
                     $Permission = "X";
                 }
             }
         }
     }
     if ($Permission < "W" && $arIBlock["SOCNET_GROUP_ID"] && CModule::IncludeModule('socialnetwork')) {
         $arSocnetPerm = CLists::GetSocnetPermission($iblock_id);
         $socnet_role = CSocNetUserToGroup::GetUserRole($USER->GetID(), $arIBlock["SOCNET_GROUP_ID"]);
         $Permission = $arSocnetPerm[$socnet_role];
     }
     return $Permission;
 }
Exemple #16
0
 function __checkIBlockRights()
 {
     $iblockPerm = CIBlock::GetPermission($this->IBLOCK_ID);
     return $iblockPerm >= 'R';
 }
//Search
if ($this->__page == 'index') {
    ob_start();
    $APPLICATION->IncludeComponent("bitrix:idea.search", "", array(), $component);
    $arResult["ACTIONS"]["SEARCH"] = array("HTML" => ob_get_contents());
    ob_end_clean();
}
//Can Add Idea
if ($USER->IsAuthorized()) {
    $arBlog = CBlog::GetByUrl($arParams["BLOG_URL"]);
    if (CBlog::GetBlogUserPostPerms($arBlog["ID"], $USER->GetID()) >= BLOG_PERMS_PREMODERATE) {
        $arResult["ACTIONS"]["ADD_IDEA"] = array("ICON" => "btn-new section-add", "TEXT" => GetMessage("IDEA_ADD_IDEA_TITLE"), "LINK" => $arResult["~PATH_TO_POST_ADD"]);
    }
}
//Can Add category
if ($USER->IsAuthorized() && $arParams["IBLOCK_CATEGORIES"] > 0 && CIBlock::GetPermission($arParams["IBLOCK_CATEGORIES"], $USER->GetID()) >= "W") {
    $arButtons = CIBlock::GetPanelButtons($arParams["IBLOCK_CATEGORIES"], 0, 0, array("SESSID" => false));
    $arResult["ACTIONS"]["ADD_IDEA_CATEGORY"] = array("ICON" => "btn-new section-add", "TEXT" => GetMessage("IDEA_ADD_IDEA_CATEGORY_TITLE"), "LINK" => $arButtons["edit"]["add_section"]["ACTION"]);
}
//Menu
if ($USER->IsAuthorized()) {
    $arResult["ACTIONS"]["MENU"] = array("TEXT" => GetMessage("IDEA_MENU_TITLE"), "MENU" => array());
    //Own ideas
    $arResult["ACTIONS"]["MENU"]["MENU"][] = array("TEXT" => GetMessage("IDEA_MY_IDEA_TITLE"), "ONCLICK" => "top.window.location.href='" . $arResult["~PATH_TO_USER_IDEAS"] . "';");
    $arResult["ACTIONS"]["MENU"]["MENU"][] = array("SEPARATOR" => true);
    //Own subscribes
    $arResult["ACTIONS"]["MENU"]["MENU"][] = array("TEXT" => GetMessage("IDEA_MY_SUBSCRIBE_TITLE"), "ONCLICK" => "top.window.location.href='" . $arResult["~PATH_TO_USER_SUBSCRIBE"] . "';");
}
//Top part of sidebar Wrapper
$this->SetViewTarget("sidebar", 1);
echo '<div class="sidebar-block idea-detail-info">
	/**
	 * @param array $arParams
	 * @return array|false
	 */
	public static function OrderProduct($arParams)
	{
		$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_DISCOUNT'] = (isset($arParams['CHECK_DISCOUNT']) && $arParams['CHECK_DISCOUNT'] == 'N' ? 'N' : 'Y');
		$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['BASKET_ID'] = (string)(isset($arParams['BASKET_ID']) ? $arParams['BASKET_ID'] : '0');

		if (isset($arParams['CURRENCY']))
			$arParams['CURRENCY'] = CCurrency::checkCurrencyID($arParams['CURRENCY']);
		if ($arParams['CURRENCY'] === false)
			$arParams['CURRENCY'] = CSaleLang::GetLangCurrency($strSiteID ? $strSiteID : SITE_ID);

		global $USER;

		$productID = (int)$arParams['PRODUCT_ID'];
		$quantity = (float)$arParams['QUANTITY'];
		$renewal = $arParams['RENEWAL'];

		$intUserID = (int)$arParams['USER_ID'];

		$arResult = array();

		static $arUserCache = array();
		if (0 < $intUserID)
		{
			if (!isset($arUserCache[$intUserID]))
			{
				$by = 'ID';
				$order = 'DESC';
				$rsUsers = CUser::GetList($by, $order, array("ID_EQUAL_EXACT"=>$intUserID),array('FIELDS' => array('ID')));
				if ($arUser = $rsUsers->Fetch())
				{
					$arUser['ID'] = intval($arUser['ID']);
					$arUserCache[$arUser['ID']] = CUser::GetUserGroup($arUser['ID']);
				}
				else
				{
					$intUserID = 0;
					return $arResult;
				}
			}

			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
						"ID" => $productID,
						"ACTIVE" => "Y",
						"ACTIVE_DATE" => "Y",
						"CHECK_PERMISSION" => "N",
					),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
				);
			if(!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;

			if ('E' == CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], "RIGHTS_MODE"))
			{
				$arUserRights = CIBlockElementRights::GetUserOperations($productID,$intUserID);
				if (empty($arUserRights))
				{
					return $arResult;
				}
				elseif (!is_array($arUserRights) || !array_key_exists('element_read',$arUserRights))
				{
					return $arResult;
				}
			}
			else
			{
				if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID))
				{
					return $arResult;
				}
			}
		}
		else
		{
			$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()))
				return $arResult;
		}

		$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())
		{
			$arCatalogProduct["QUANTITY"] = (double)$arCatalogProduct["QUANTITY"];
			if ($arParams["CHECK_QUANTITY"] == "Y")
			{
				if (
					'Y' != $arCatalogProduct["CAN_BUY_ZERO"]
					&& 'Y' == $arCatalogProduct["QUANTITY_TRACE"]
					&& ($arCatalogProduct["QUANTITY"] <= 0 || $quantity > $arCatalogProduct["QUANTITY"])
				)
				{
					return $arResult;
				}
			}
		}
		else
		{
			return $arResult;
		}

		if (0 < $intUserID)
		{
			$arCoupons = CCatalogDiscountCoupon::GetCouponsByManage($intUserID);
			CCatalogDiscountSave::SetDiscountUserID($intUserID);
		}
		else
		{
			$arCoupons = CCatalogDiscountCoupon::GetCoupons();
		}

		$userGroups = ($intUserID > 0 ? $arUserCache[$intUserID] : $USER->GetUserGroupArray());
		$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, $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);

		if (empty($arPrice))
		{
			if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, $userGroups))
			{
				$quantity = $nearestQuantity;
				$arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $userGroups, $renewal, array(), (0 < $intUserID ? $strSiteID : false), $arCoupons);
			}
		}
		CCatalogProduct::clearUsedCurrency();
		CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
		CCatalogProduct::setUseDiscount($currentUseDiscount);
		unset($userGroups, $currentUseDiscount, $currentVatMode);
		if (0 < $intUserID)
		{
			CCatalogDiscountSave::ClearDiscountUserID();
		}

		if (empty($arPrice))
		{
			return $arResult;
		}

		$arDiscountList = array();
		$arCouponList = array();

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount)
			{
				$arOneList = array(
					'ID' => $arOneDiscount['ID'],
					'NAME' => $arOneDiscount['NAME'],
					'COUPON' => '',
					'COUPON_TYPE' => '',
					'MODULE_ID' => (isset($oneDiscount['MODULE_ID']) ? $oneDiscount['MODULE_ID'] : 'catalog'),
					'TYPE' => $arOneDiscount['TYPE'],
					'VALUE' => $arOneDiscount['VALUE'],
					'VALUE_TYPE' => $arOneDiscount['VALUE_TYPE'],
					'CURRENCY' => $arOneDiscount['CURRENCY'],
					'HANDLERS' => (isset($arOneDiscount['HANDLERS']) ? $arOneDiscount['HANDLERS'] : array())
				);

				if ($arOneDiscount['COUPON'])
				{
					$arOneList['COUPON'] = $arOneDiscount['COUPON'];
					$arOneList['COUPON_TYPE'] = $arOneDiscount['COUPON_ONE_TIME'];
					$arCouponList[] = $arOneDiscount['COUPON'];
				}

				$arDiscountList[] = $arOneList;
			}
			unset($arOneList, $arOneDiscount);
		}

		if (empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"]))
		{
			if (!empty($arPrice["PRICE"]["CATALOG_GROUP_ID"]))
			{
				$rsCatGroups = CCatalogGroup::GetListEx(array(),array('ID' => $arPrice["PRICE"]["CATALOG_GROUP_ID"]),false,false,array('ID','NAME','NAME_LANG'));
				if ($arCatGroup = $rsCatGroups->Fetch())
				{
					$arPrice["PRICE"]["CATALOG_GROUP_NAME"] = (!empty($arCatGroup['NAME_LANG']) ? $arCatGroup['NAME_LANG'] : $arCatGroup['NAME']);
				}
			}
		}

		$arResult = array(
			"PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"],
			'BASE_PRICE' => $arPrice['RESULT_PRICE']['BASE_PRICE'],
			"PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'],
			"VAT_RATE" => $arPrice['PRICE']['VAT_RATE'],
			"CURRENCY" => $arPrice['RESULT_PRICE']['CURRENCY'],
			"WEIGHT" => (float)$arCatalogProduct["WEIGHT"],
			"DIMENSIONS" => serialize(array(
				"WIDTH" => $arCatalogProduct["WIDTH"],
				"HEIGHT" => $arCatalogProduct["HEIGHT"],
				"LENGTH" => $arCatalogProduct["LENGTH"]
			)),
			"NAME" => $arProduct["~NAME"],
			"CAN_BUY" => "Y",
			"DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'],
			"NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"],
			"DISCOUNT_PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT'],
			"TYPE" => ($arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET) ? CCatalogProductSet::TYPE_SET : NULL,
			"DISCOUNT_VALUE" => ($arPrice['RESULT_PRICE']['PERCENT'] > 0 ? $arPrice['RESULT_PRICE']['PERCENT'].'%' : 0),
			"DISCOUNT_NAME" => "",
			"DISCOUNT_COUPON" => "",
			"DISCOUNT_LIST" => array()
		);

		if ($arParams["CHECK_QUANTITY"] == "Y")
			$arResult["QUANTITY"] = $quantity;
		else
			$arResult["QUANTITY"] = $arParams["QUANTITY"];

		if (!empty($arPrice["DISCOUNT_LIST"]))
		{
			$arResult['DISCOUNT_LIST'] = $arDiscountList;
			$arResult["DISCOUNT_NAME"] = "[".$arPrice["DISCOUNT"]["ID"]."] ".$arPrice["DISCOUNT"]["NAME"];

			if (!empty($arPrice["DISCOUNT"]["COUPON"]))
			{
				$arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"];
			}

			if (!empty($arCouponList))
			{
				$mxApply = CCatalogDiscountCoupon::CouponApply($intUserID, $arCouponList);
			}
		}

		return $arResult;
	}
Exemple #19
0
 function UserTypeRightsCheck($entity_id)
 {
     if (preg_match("/^IBLOCK_(\\d+)_SECTION\$/", $entity_id, $match)) {
         return CIBlock::GetPermission($match[1]);
     } else {
         return "D";
     }
 }
 protected static function _lists_check($USER, $iblock_type_id, $iblock_id)
 {
     $iblock_check = CListPermissions::_iblock_check($iblock_type_id, $iblock_id);
     if ($iblock_check < 0) {
         return $iblock_check;
     }
     $arListsPerm = CLists::GetPermission($iblock_type_id);
     if (!count($arListsPerm)) {
         return CListPermissions::ACCESS_DENIED;
     }
     $arUSER_GROUPS = $USER->GetUserGroupArray();
     if (count(array_intersect($arListsPerm, $arUSER_GROUPS)) > 0) {
         return CListPermissions::IS_ADMIN;
     }
     return CIBlock::GetPermission($iblock_id);
 }
Exemple #21
0
 static function CanAccessFiles($iblock_id, $entity_type, $entity_id)
 {
     $result = false;
     $iblock_id = intval($iblock_id);
     $entity_id = intval($entity_id);
     if ($iblock_id > 0 && $entity_id > 0 && ($entity_type == 'group' || $entity_type == 'user')) {
         //cache
         $value = false;
         static $data = array();
         $CACHE_PATH = "/" . SITE_ID . "/webdav/can_access_files";
         $CACHE_ID = $iblock_id;
         $CACHE_TIME = 3600 * 24 * 30;
         $docCache = new CPHPCache();
         if (!isset($data[$iblock_id])) {
             if ($docCache->InitCache($CACHE_TIME, $CACHE_ID, $CACHE_PATH)) {
                 $value = $docCache->GetVars();
             }
             $data[$iblock_id] = $value;
         }
         if (isset($data[$iblock_id][$entity_type][$entity_id])) {
             return $data[$iblock_id][$entity_type][$entity_id];
         }
         //end cache
         CModule::IncludeModule('iblock');
         $rIB = CIBlock::GetList(array(), array('ID' => $iblock_id, "CHECK_PERMISSIONS" => "N"));
         if ($rIB && ($arIB = $rIB->Fetch()) && $arIB["RIGHTS_MODE"] === "E") {
             $rootSectionID = self::GetSectionID($iblock_id, $entity_type, $entity_id);
             if ($rootSectionID !== false) {
                 $ibRights = new CIBlockSectionRights($iblock_id, $rootSectionID);
                 $result = $ibRights->UserHasRightTo($iblock_id, $rootSectionID, 'section_read');
                 if (!$result) {
                     $arParams = array("DOCUMENT_TYPE" => array("webdav", "CIBlockDocumentWebdavSocnet", implode("_", array("iblock", $iblock_id, $entity_type, $entity_id))), "ROOT_SECTION_ID" => $rootSectionID, "ATTRIBUTES" => $entity_type == "user" ? array('user_id' => $entity_id) : array('group_id' => $entity_id));
                     $ob = new CWebDavIblock($iblock_id, '', $arParams);
                     if ($ob && empty($ob->arError) && $ob->permission > 'D') {
                         $files = array();
                         $options = array("path" => '/', "depth" => 1);
                         $res = $ob->PROPFIND($options, $files, array("return" => "array"));
                         $result = is_array($res) && sizeof($res['RESULT']) > 0;
                         // at least 1 item can be read
                     }
                 }
             } else {
                 return true;
             }
         } else {
             $result = CIBlock::GetPermission($iblock_id) > "D";
         }
         // cache
         if ($data[$iblock_id] === false) {
             $data[$iblock_id] = array();
         }
         $data[$iblock_id][$entity_type][$entity_id] = $result;
         $docCache->Clean($CACHE_ID, $CACHE_PATH);
         $docCache->InitCache($CACHE_TIME, $CACHE_ID, $CACHE_PATH);
         if ($docCache->StartDataCache()) {
             global $CACHE_MANAGER;
             $CACHE_MANAGER->StartTagCache($CACHE_PATH);
             $CACHE_MANAGER->RegisterTag("iblock_id_" . $iblock_id);
             $CACHE_MANAGER->RegisterTag('wd_socnet');
             $CACHE_MANAGER->EndTagCache();
             $docCache->EndDataCache($data[$iblock_id]);
         }
         // end cache
     }
     return $result;
 }
Exemple #22
0
function CatalogRecurringCallback($productID, $userID)
{
    global $APPLICATION;
    global $DB;
    $productID = intval($productID);
    if ($productID <= 0) {
        return false;
    }
    $userID = intval($userID);
    if ($userID <= 0) {
        return false;
    }
    $arProduct = CCatalogProduct::GetByID($productID);
    if (!$arProduct) {
        $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_NO_PRODUCT")), "NO_PRODUCT");
        return false;
    }
    if ($arProduct["PRICE_TYPE"] == "T") {
        $arProduct = CCatalogProduct::GetByID($arProduct["TRIAL_PRICE_ID"]);
        if (!$arProduct) {
            $APPLICATION->ThrowException(str_replace("#TRIAL_ID#", $productID, str_replace("#ID#", $arProduct["TRIAL_PRICE_ID"], Loc::getMessage("I_NO_TRIAL_PRODUCT"))), "NO_PRODUCT_TRIAL");
            return false;
        }
    }
    $productID = intval($arProduct["ID"]);
    if ($arProduct["PRICE_TYPE"] != "R") {
        $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_PRODUCT_NOT_SUBSCR")), "NO_IBLOCK_SUBSCR");
        return false;
    }
    $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 (!($arIBlockElement = $dbIBlockElement->GetNext())) {
        $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT");
        return false;
    }
    if ('E' == CIBlock::GetArrayByID($arIBlockElement['IBLOCK_ID'], "RIGHTS_MODE")) {
        $arUserRights = CIBlockElementRights::GetUserOperations($productID, $userID);
        if (empty($arUserRights)) {
            $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT");
            return false;
        } elseif (!is_array($arUserRights) || !array_key_exists('element_read', $arUserRights)) {
            $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT");
            return false;
        }
    } else {
        if ('R' > CIBlock::GetPermission($arIBlockElement['IBLOCK_ID'], $userID)) {
            $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_NO_IBLOCK_ELEM")), "NO_IBLOCK_ELEMENT");
            return false;
        }
    }
    $arCatalog = CCatalog::GetByID($arIBlockElement["IBLOCK_ID"]);
    if ($arCatalog["SUBSCRIPTION"] != "Y") {
        $APPLICATION->ThrowException(str_replace("#ID#", $arIBlockElement["IBLOCK_ID"], Loc::getMessage("I_CATALOG_NOT_SUBSCR")), "NOT_SUBSCRIPTION");
        return false;
    }
    if ($arProduct["CAN_BUY_ZERO"] != "Y" && ($arProduct["QUANTITY_TRACE"] == "Y" && doubleval($arProduct["QUANTITY"]) <= 0)) {
        $APPLICATION->ThrowException(str_replace("#ID#", $productID, Loc::getMessage("I_PRODUCT_SOLD")), "PRODUCT_END");
        return false;
    }
    $arUserGroups = CUser::GetUserGroup($userID);
    $arUserGroups = array_values(array_unique($arUserGroups));
    CCatalogDiscountSave::Disable();
    $arPrice = CCatalogProduct::GetOptimalPrice($productID, 1, $arUserGroups, "Y");
    if (empty($arPrice)) {
        if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, 1, $arUserGroups)) {
            $quantity = $nearestQuantity;
            $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, $arUserGroups, "Y");
        }
    }
    CCatalogDiscountSave::Enable();
    if (empty($arPrice)) {
        return false;
    }
    $currentPrice = $arPrice["PRICE"]["PRICE"];
    $currentDiscount = 0.0;
    //SIGURD: logic change. see mantiss 5036.
    // discount applied to a final price with VAT already included.
    if (doubleval($arPrice['PRICE']['VAT_RATE']) > 0) {
        $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE'];
    }
    $arDiscountList = array();
    if (!empty($arPrice["DISCOUNT_LIST"])) {
        $dblStartPrice = $currentPrice;
        foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount) {
            switch ($arOneDiscount['VALUE_TYPE']) {
                case CCatalogDiscount::TYPE_FIX:
                    if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                        $currentDiscount = $arOneDiscount['VALUE'];
                    } else {
                        $currentDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount["VALUE"], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                    }
                    $currentPrice = $currentPrice - $currentDiscount;
                    break;
                case CCatalogDiscount::TYPE_PERCENT:
                    $currentDiscount = $currentPrice * $arOneDiscount["VALUE"] / 100.0;
                    if (0 < $arOneDiscount['MAX_DISCOUNT']) {
                        if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                            $dblMaxDiscount = $arOneDiscount['MAX_DISCOUNT'];
                        } else {
                            $dblMaxDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount['MAX_DISCOUNT'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                        }
                        if ($currentDiscount > $dblMaxDiscount) {
                            $currentDiscount = $dblMaxDiscount;
                        }
                    }
                    $currentPrice = $currentPrice - $currentDiscount;
                    break;
                case CCatalogDiscount::TYPE_SALE:
                    if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                        $currentPrice = $arOneDiscount['VALUE'];
                    } else {
                        $currentPrice = CCurrencyRates::ConvertCurrency($arOneDiscount['VALUE'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                    }
                    break;
            }
            $arOneList = array('ID' => $arOneDiscount['ID'], 'NAME' => $arOneDiscount['NAME'], 'COUPON' => '', 'MODULE_ID' => 'catalog');
            if ($arOneDiscount['COUPON']) {
                $arOneList['COUPON'] = $arOneDiscount['COUPON'];
            }
            $arDiscountList[] = $arOneList;
        }
        if (isset($arOneDiscount)) {
            unset($arOneDiscount);
        }
        $currentDiscount = $dblStartPrice - $currentPrice;
    }
    $recurType = $arProduct["RECUR_SCHEME_TYPE"];
    $recurLength = intval($arProduct["RECUR_SCHEME_LENGTH"]);
    $recurSchemeVal = 0;
    if ($recurType == CCatalogProduct::TIME_PERIOD_HOUR) {
        $recurSchemeVal = mktime(date("H") + $recurLength, date("i"), date("s"), date("m"), date("d"), date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_DAY) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + $recurLength, date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_WEEK) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d") + 7 * $recurLength, date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_MONTH) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + $recurLength, date("d"), date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_QUART) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 3 * $recurLength, date("d"), date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_SEMIYEAR) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m") + 6 * $recurLength, date("d"), date("Y"));
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_YEAR) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + $recurLength);
    } elseif ($recurType == CCatalogProduct::TIME_PERIOD_DOUBLE_YEAR) {
        $recurSchemeVal = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y") + 2 * $recurLength);
    }
    $arResult = array("WEIGHT" => floatval($arProduct["WEIGHT"]), "DIMENSIONS" => serialize(array("WIDTH" => $arProduct["WIDTH"], "HEIGHT" => $arProduct["HEIGHT"], "LENGTH" => $arProduct["LENGTH"])), "VAT_RATE" => $arPrice["PRICE"]["VAT_RATE"], "QUANTITY" => 1, "PRICE" => $currentPrice, "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "PRODUCT_ID" => $productID, "PRODUCT_NAME" => $arIBlockElement["~NAME"], "PRODUCT_URL" => $arIBlockElement["~DETAIL_PAGE_URL"], "PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"], "CURRENCY" => $arPrice["PRICE"]["CURRENCY"], "NAME" => $arIBlockElement["NAME"], "MODULE" => "catalog", "PRODUCT_PROVIDER_CLASS" => "CCatalogProductProvider", "CATALOG_GROUP_NAME" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arIBlockElement["~DETAIL_PAGE_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "PRODUCT_XML_ID" => $arIBlockElement["~XML_ID"], "TYPE" => $arProduct["TYPE"] == CCatalogProduct::TYPE_SET ? CCatalogProductSet::TYPE_SET : NULL, "NEXT_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), $recurSchemeVal));
    if (!empty($arPrice["DISCOUNT_LIST"])) {
        $arResult['DISCOUNT_LIST'] = $arDiscountList;
    }
    return $arResult;
}
Exemple #23
0
 function CanUserOperateDocumentType($operation, $userId, $documentType, $arParameters = array())
 {
     $documentType = trim($documentType);
     if (strlen($documentType) <= 0) {
         return false;
     }
     $arParameters["IBlockId"] = intval(substr($documentType, strlen("iblock_")));
     if (!array_key_exists("IBlockRightsMode", $arParameters)) {
         $arParameters["IBlockRightsMode"] = CIBlock::GetArrayByID($arParameters["IBlockId"], "RIGHTS_MODE");
     }
     if ($arParameters["IBlockRightsMode"] === "E") {
         if ($operation === CBPCanUserOperateOperation::CreateWorkflow) {
             return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "iblock_rights_edit");
         } elseif ($operation === CBPCanUserOperateOperation::WriteDocument) {
             return CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "section_element_bind");
         } elseif ($operation === CBPCanUserOperateOperation::ViewWorkflow || $operation === CBPCanUserOperateOperation::StartWorkflow) {
             if (!array_key_exists("WorkflowId", $arParameters)) {
                 return false;
             }
             if ($operation === CBPCanUserOperateOperation::ViewWorkflow && !CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "element_read")) {
                 return false;
             }
             if ($operation === CBPCanUserOperateOperation::StartWorkflow && !CIBlockRights::UserHasRightTo($arParameters["IBlockId"], $arParameters["IBlockId"], "section_element_bind")) {
                 return false;
             }
             $userId = intval($userId);
             if (!array_key_exists("AllUserGroups", $arParameters)) {
                 if (!array_key_exists("UserGroups", $arParameters)) {
                     $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
                 }
                 $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
                 $arParameters["AllUserGroups"][] = "Author";
             }
             if (!array_key_exists("DocumentStates", $arParameters)) {
                 if ($operation === CBPCanUserOperateOperation::StartWorkflow) {
                     $arParameters["DocumentStates"] = CBPWorkflowTemplateLoader::GetDocumentTypeStates(array("iblock", "CIBlockDocument", "iblock_" . $arParameters["IBlockId"]));
                 } else {
                     $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(array("iblock", "CIBlockDocument", "iblock_" . $arParameters["IBlockId"]), null);
                 }
             }
             if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"])) {
                 $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
             } else {
                 return false;
             }
             $arAllowableOperations = CBPDocument::GetAllowableOperations($userId, $arParameters["AllUserGroups"], $arParameters["DocumentStates"]);
             if (!is_array($arAllowableOperations)) {
                 return false;
             }
             if ($operation === CBPCanUserOperateOperation::ViewWorkflow && in_array("read", $arAllowableOperations) || $operation === CBPCanUserOperateOperation::StartWorkflow && in_array("write", $arAllowableOperations)) {
                 return true;
             }
             $chop = $operation === CBPCanUserOperateOperation::ViewWorkflow ? "element_read" : "section_element_bind";
             foreach ($arAllowableOperations as $op) {
                 $ar = CTask::GetOperations($op, true);
                 if (in_array($chop, $ar)) {
                     return true;
                 }
             }
         }
         return false;
     }
     if (!array_key_exists("IBlockPermission", $arParameters)) {
         if (CModule::IncludeModule('lists')) {
             $arParameters["IBlockPermission"] = CLists::GetIBlockPermission($arParameters["IBlockId"], $userId);
         } else {
             $arParameters["IBlockPermission"] = CIBlock::GetPermission($arParameters["IBlockId"], $userId);
         }
     }
     if ($arParameters["IBlockPermission"] <= "R") {
         return false;
     } elseif ($arParameters["IBlockPermission"] >= "W") {
         return true;
     }
     $userId = intval($userId);
     if (!array_key_exists("AllUserGroups", $arParameters)) {
         if (!array_key_exists("UserGroups", $arParameters)) {
             $arParameters["UserGroups"] = CUser::GetUserGroup($userId);
         }
         $arParameters["AllUserGroups"] = $arParameters["UserGroups"];
         $arParameters["AllUserGroups"][] = "Author";
     }
     if (!array_key_exists("DocumentStates", $arParameters)) {
         $arParameters["DocumentStates"] = CBPDocument::GetDocumentStates(array("iblock", "CIBlockDocument", "iblock_" . $arParameters["IBlockId"]), null);
     }
     if (array_key_exists("WorkflowId", $arParameters)) {
         if (array_key_exists($arParameters["WorkflowId"], $arParameters["DocumentStates"])) {
             $arParameters["DocumentStates"] = array($arParameters["WorkflowId"] => $arParameters["DocumentStates"][$arParameters["WorkflowId"]]);
         } else {
             return false;
         }
     }
     $arAllowableOperations = CBPDocument::GetAllowableOperations($userId, $arParameters["AllUserGroups"], $arParameters["DocumentStates"]);
     if (!is_array($arAllowableOperations)) {
         return false;
     }
     $r = false;
     switch ($operation) {
         case CBPCanUserOperateOperation::ViewWorkflow:
             $r = in_array("read", $arAllowableOperations);
             break;
         case CBPCanUserOperateOperation::StartWorkflow:
             $r = in_array("write", $arAllowableOperations);
             break;
         case CBPCanUserOperateOperation::CreateWorkflow:
             $r = in_array("write", $arAllowableOperations);
             break;
         case CBPCanUserOperateOperation::WriteDocument:
             $r = in_array("write", $arAllowableOperations);
             break;
         case CBPCanUserOperateOperation::ReadDocument:
             $r = false;
             break;
         default:
             $r = false;
     }
     return $r;
 }
Exemple #24
0
			{
				$arResult["SELECTED_ELEMENT"] = array(
					"VALUES" => $arResult["SECTIONS"][$SectionId]["ELEMENTS"][$arItem["ID"]],
					"FILE" => $arResult["SECTIONS"][$SectionId]["ELEMENTS"][$arItem["ID"]]["FILE"],
				);
			}
		}
	}

	if(!isset($arResult["SELECTED_ELEMENT"]))
	{
		$this->AbortResultCache();
		return false;
	}

	if(CIBlock::GetPermission($arParams["IBLOCK_ID"])>='U')
		$arResult["CAN_EDIT"] = "Y";
	else
		$arResult["CAN_EDIT"] = "N";

	$this->SetResultCacheKeys(array(
		"CAN_EDIT", "IBLOCK_TYPE_ID", "RAW_FILES", "IBLOCK_ID"
	));

	$this->IncludeComponentTemplate();
}

//include js
$APPLICATION->AddHeadString('<script type="text/javascript" src="/bitrix/components/bitrix/player/wmvplayer/silverlight.js?v='.filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/components/bitrix/player/wmvplayer/silverlight.js').'"></script>', true);
$APPLICATION->AddHeadString('<script type="text/javascript" src="/bitrix/components/bitrix/player/wmvplayer/wmvplayer.js?v='.filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/components/bitrix/player/wmvplayer/wmvplayer.js').'"></script>', true);
$APPLICATION->AddHeadString('<script type="text/javascript" src="/bitrix/components/bitrix/player/mediaplayer/flvscript.js?v='.filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/components/bitrix/player/mediaplayer/flvscript.js').'"></script>', true);
Exemple #25
0
	"DATE_ACTIVE_TO_2"	=>$find_date_active_to_to,
	"ACTIVE"		=>$find_active,
	"DESCRIPTION"		=>$find_intext,
	"WF_STATUS"		=>$find_status==""?$find_status_id:$find_status,
	"?TAGS"			=>$find_tags,
	"CHECK_PERMISSIONS" => "Y",
	"MIN_PERMISSION" => "R",
);
if(!empty($find_timestamp_2))
	$arFilter["TIMESTAMP_X_2"] = CIBlock::isShortDate($find_timestamp_2)? ConvertTimeStamp(AddTime(MakeTimeStamp($find_timestamp_2), 1, "D"), "FULL"): $find_timestamp_2;
if(!empty($find_created_to))
	$arFilter["DATE_CREATE_2"] = CIBlock::isShortDate($find_created_to)? ConvertTimeStamp(AddTime(MakeTimeStamp($find_created_to), 1, "D"), "FULL"): $find_created_to;

if ($bBizproc && 'E' != $arIBlock['RIGHTS_MODE'])
{
	$strPerm = CIBlock::GetPermission($IBLOCK_ID);
	if ('W' > $strPerm)
	{
		unset($arFilter['CHECK_PERMISSIONS']);
		unset($arFilter['MIN_PERMISSION']);
		$arFilter['CHECK_BP_PERMISSIONS'] = 'read';
	}
}

foreach($arProps as $arProp)
{
	if($arProp["FILTRABLE"]=="Y" && $arProp["PROPERTY_TYPE"]!="F")
	{
		$value = ${"find_el_property_".$arProp["ID"]};

		if(array_key_exists("AddFilterFields", $arProp["PROPERTY_USER_TYPE"]))
 public static function OrderProduct($arParams)
 {
     if (!is_set($arParams, "RENEWAL") || $arParams["RENEWAL"] != "Y") {
         $arParams["RENEWAL"] = "N";
     }
     if (!is_set($arParams, "USER_ID") || IntVal($arParams["USER_ID"]) <= 0) {
         $arParams["USER_ID"] = 0;
     }
     if (!is_set($arParams["SITE_ID"])) {
         $arParams["SITE_ID"] = false;
     }
     global $USER;
     global $DB;
     $productID = intval($arParams["PRODUCT_ID"]);
     $quantity = doubleval($arParams["QUANTITY"]);
     $renewal = $arParams["RENEWAL"] == "Y" ? "Y" : "N";
     $strSiteID = $arParams["SITE_ID"];
     $intUserID = intval($arParams["USER_ID"]);
     if (0 > $intUserID) {
         $intUserID = 0;
     }
     $arResult = array();
     static $arUserCache = array();
     if (0 < $intUserID) {
         if (!array_key_exists($intUserID, $arUserCache)) {
             $rsUsers = CUser::GetList($by = 'ID', $order = 'DESC', array("ID_EQUAL_EXACT" => $intUserID), array('FIELDS' => array('ID')));
             if ($arUser = $rsUsers->Fetch()) {
                 $arUserCache[$arUser['ID']] = CUser::GetUserGroup($arUser['ID']);
             } else {
                 $intUserID = 0;
                 return $arResult;
             }
         }
         $dbIBlockElement = CIBlockElement::GetList(array(), array("ID" => $productID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", "CHECK_PERMISSION" => "N"), false, false, array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL'));
         if (!($arProduct = $dbIBlockElement->GetNext())) {
             return $arResult;
         }
         if ('E' == CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], "RIGHTS_MODE")) {
             $arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID);
             if (empty($arUserRights)) {
                 return $arResult;
             } elseif (!is_array($arUserRights) || !array_key_exists('element_read', $arUserRights)) {
                 return $arResult;
             }
         } else {
             if ('R' > CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID)) {
                 return $arResult;
             }
         }
     } else {
         $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())) {
             return $arResult;
         }
     }
     if ($arCatalogProduct = CCatalogProduct::GetByID($productID)) {
         if ($arCatalogProduct["CAN_BUY_ZERO"] != "Y" && ($arCatalogProduct["QUANTITY_TRACE"] == "Y" && doubleval($arCatalogProduct["QUANTITY"]) < doubleVal($quantity))) {
             return $arResult;
         }
     } else {
         return $arResult;
     }
     if (0 < $intUserID) {
         $arCoupons = CCatalogDiscountCoupon::GetCouponsByManage($intUserID);
         CCatalogDiscountSave::SetDiscountUserID($intUserID);
     } else {
         $arCoupons = CCatalogDiscountCoupon::GetCoupons();
     }
     $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray(), $renewal, array(), 0 < $intUserID ? $strSiteID : false, $arCoupons);
     if (empty($arPrice)) {
         if ($nearestQuantity = CCatalogProduct::GetNearestQuantityPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray())) {
             $quantity = $nearestQuantity;
             $arPrice = CCatalogProduct::GetOptimalPrice($productID, $quantity, 0 < $intUserID ? $arUserCache[$intUserID] : $USER->GetUserGroupArray(), $renewal, array(), 0 < $intUserID ? $strSiteID : false, $arCoupons);
         }
     }
     if (empty($arPrice)) {
         if (0 < $intUserID) {
             CCatalogDiscountSave::ClearDiscountUserID();
         }
         return $arResult;
     }
     $boolDiscountVat = 'N' != COption::GetOptionString('catalog', 'discount_vat', 'Y');
     $currentPrice = $arPrice["PRICE"]["PRICE"];
     $currentDiscount = 0.0;
     if ($boolDiscountVat) {
         if ('N' == $arPrice['PRICE']['VAT_INCLUDED']) {
             $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE'];
             $arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
         }
     } else {
         if ('Y' == $arPrice['PRICE']['VAT_INCLUDED']) {
             $currentPrice /= 1 + $arPrice['PRICE']['VAT_RATE'];
             $arPrice['PRICE']['VAT_INCLUDED'] = 'N';
         }
     }
     $arDiscountList = array();
     $arCouponList = array();
     if (!empty($arPrice["DISCOUNT_LIST"])) {
         $dblStartPrice = $currentPrice;
         foreach ($arPrice["DISCOUNT_LIST"] as &$arOneDiscount) {
             switch ($arOneDiscount['VALUE_TYPE']) {
                 case 'F':
                     if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                         $currentDiscount = $arOneDiscount['VALUE'];
                     } else {
                         $currentDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount["VALUE"], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                     }
                     $currentPrice = $currentPrice - $currentDiscount;
                     break;
                 case 'P':
                     $currentDiscount = $currentPrice * $arOneDiscount["VALUE"] / 100.0;
                     if (0 < $arOneDiscount['MAX_DISCOUNT']) {
                         if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                             $dblMaxDiscount = $arOneDiscount['MAX_DISCOUNT'];
                         } else {
                             $dblMaxDiscount = CCurrencyRates::ConvertCurrency($arOneDiscount['MAX_DISCOUNT'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                         }
                         if ($currentDiscount > $dblMaxDiscount) {
                             $currentDiscount = $dblMaxDiscount;
                         }
                     }
                     $currentPrice = $currentPrice - $currentDiscount;
                     break;
                 case 'S':
                     if ($arOneDiscount['CURRENCY'] == $arPrice["PRICE"]["CURRENCY"]) {
                         $currentPrice = $arOneDiscount['VALUE'];
                     } else {
                         $currentPrice = CCurrencyRates::ConvertCurrency($arOneDiscount['VALUE'], $arOneDiscount["CURRENCY"], $arPrice["PRICE"]["CURRENCY"]);
                     }
                     break;
             }
             $arOneList = array('ID' => $arOneDiscount['ID'], 'NAME' => $arOneDiscount['NAME'], 'COUPON' => '');
             if ($arOneDiscount['COUPON']) {
                 $arOneList['COUPON'] = $arOneDiscount['COUPON'];
                 $arCouponList[] = $arOneDiscount['COUPON'];
             }
             $arDiscountList[] = $arOneList;
         }
         if (isset($arOneDiscount)) {
             unset($arOneDiscount);
         }
         $currentDiscount = $dblStartPrice - $currentPrice;
     }
     if (empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"])) {
         if (!empty($arPrice["PRICE"]["CATALOG_GROUP_ID"])) {
             $rsCatGroups = CCatalogGroup::GetList(array(), array('ID' => $arPrice["PRICE"]["CATALOG_GROUP_ID"]), false, array('nTopCount' => 1), array('ID', 'NAME', 'NAME_LANG'));
             if ($arCatGroup = $rsCatGroups->Fetch()) {
                 $arPrice["PRICE"]["CATALOG_GROUP_NAME"] = !empty($arCatGroup['NAME_LANG']) ? $arCatGroup['NAME_LANG'] : $arCatGroup['NAME'];
             }
         }
     }
     if (!$boolDiscountVat) {
         $currentPrice *= 1 + $arPrice['PRICE']['VAT_RATE'];
         $currentDiscount *= 1 + $arPrice['PRICE']['VAT_RATE'];
         $arPrice['PRICE']['VAT_INCLUDED'] = 'Y';
     }
     $arResult = array("PRODUCT_PRICE_ID" => $arPrice["PRICE"]["ID"], "PRICE" => $currentPrice, "VAT_RATE" => $arPrice['PRICE']['VAT_RATE'], "CURRENCY" => $arPrice["PRICE"]["CURRENCY"], "QUANTITY" => $quantity, "WEIGHT" => 0, "NAME" => $arProduct["~NAME"], "CAN_BUY" => "Y", "DETAIL_PAGE_URL" => $arProduct['DETAIL_PAGE_URL'], "NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"], "DISCOUNT_PRICE" => $currentDiscount);
     if (!empty($arPrice["DISCOUNT_LIST"])) {
         $arResult["DISCOUNT_VALUE"] = 100 * $currentDiscount / ($currentDiscount + $currentPrice) . "%";
         $arResult["DISCOUNT_NAME"] = "[" . $arPrice["DISCOUNT"]["ID"] . "] " . $arPrice["DISCOUNT"]["NAME"];
         $arResult['DISCOUNT_LIST'] = $arDiscountList;
         if (strlen($arPrice["DISCOUNT"]["COUPON"]) > 0) {
             $arResult["DISCOUNT_COUPON"] = $arPrice["DISCOUNT"]["COUPON"];
         }
         if (!empty($arCouponList)) {
             foreach ($arCouponList as &$strOneCoupon) {
                 $mxApply = CCatalogDiscountCoupon::CouponApply($intUserID, $strOneCoupon);
             }
             if (isset($strOneCoupon)) {
                 unset($strOneCoupon);
             }
         }
     }
     if ($arCatalogProduct) {
         $arResult["WEIGHT"] = intval($arCatalogProduct["WEIGHT"]);
     }
     if (0 < $intUserID) {
         CCatalogDiscountSave::ClearDiscountUserID();
     }
     return $arResult;
 }
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
$arParams["PATH_TO_USER"] = isset($arParams["PATH_TO_USER"]) ? $arParams["PATH_TO_USER"] : SITE_DIR . "company/personal/user/#user_id#/";
$arParams["PATH_TO_USER_EDIT"] = isset($arParams["PATH_TO_USER_EDIT"]) ? $arParams["PATH_TO_USER_EDIT"] : SITE_DIR . "company/personal/user/#user_id#/edit/";
$arParams["VIS_STRUCTURE_URL"] = isset($arParams["VIS_STRUCTURE_URL"]) ? $arParams["VIS_STRUCTURE_URL"] : SITE_DIR . "company/vis_structure.php";
$IBLOCK_PERMISSION = CIBlock::GetPermission(COption::GetOptionInt('intranet', 'iblock_structure'));
$arParams['bAdmin'] = $IBLOCK_PERMISSION >= 'U';
$iblockID = COption::GetOptionInt("intranet", "iblock_structure");
$db_up_department = CIBlockSection::GetList(array(), array("SECTION_ID" => 0, "IBLOCK_ID" => $iblockID));
if ($ar_up_department = $db_up_department->Fetch()) {
    $arParams["TOP_DEPARTMENT"] = $ar_up_department['ID'];
}
<?php

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if ($arParams['bCache']) {
    $cache_dir = '/' . SITE_ID . $this->__component->GetRelativePath() . '/' . $this->GetName();
    $cache_id = $this->GetFile() . '|' . $arParams['NUM_USERS'] . '|' . $arParams['IBLOCK_ID'];
    //.'|'.$USER->GetGroups();
    $obCache = new CPHPCache();
}
$IBLOCK_PERMISSION = CIBlock::GetPermission($arParams['IBLOCK_ID']);
$arParams['bAdmin'] = $IBLOCK_PERMISSION >= 'U';
/*
$arParams['SHOW_FILTER'] = $arParams['SHOW_FILTER'] == 'N' ? 'N' : 'Y';

if ($arParams['SHOW_FILTER'] == 'Y')
{
	$arUserFields = $GLOBALS['USER_FIELD_MANAGER']->GetUserFields('USER', 0, LANGUAGE_ID);
	$arResult['UF_DEPARTMENT_field'] = $arUserFields['UF_DEPARTMENT'];
	$arResult['UF_DEPARTMENT_field']['FIELD_NAME'] = 'department';
	$arResult['UF_DEPARTMENT_field']['MULTIPLE'] = 'N';
	$arResult['UF_DEPARTMENT_field']['SETTINGS']['LIST_HEIGHT'] = 1;
}
*/
$bLoadDepartments = is_array($arParams['USER_PROPERTY']) && in_array('UF_DEPARTMENT', $arParams['USER_PROPERTY']);
if ($arParams['bCache'] && $obCache->InitCache($arParams['CACHE_TIME'], $cache_id, $cache_dir)) {
    $vars = $obCache->GetVars();
    $arCacheData = $vars['TEMPLATE_DATA'];
    $arResult['USER_PROP'] = $vars['USER_PROP'];
} else {
}
/********************************************************************
				Main Data
********************************************************************/
$cache = new CPHPCache();
$cache_path = str_replace(array(":", "//"), "/", "/" . SITE_ID . "/" . $componentName . "/" . $arParams["IBLOCK_ID"]);
/************** PERMISSION *****************************************/
$cache_id = "permission" . serialize(array("USER_GROUP" => $GLOBALS["USER"]->GetGroups(), "IBLOCK_ID" => $arParams["IBLOCK_ID"]));
if (($tzOffset = CTimeZone::GetOffset()) != 0) {
    $cache_id .= "_" . $tzOffset;
}
if ($arParams["CACHE_TIME"] > 0 && $cache->InitCache($arParams["CACHE_TIME"], $cache_id, $cache_path)) {
    $arParams["PERMISSION"] = $cache->GetVars();
} else {
    CModule::IncludeModule("iblock");
    $arParams["PERMISSION"] = CIBlock::GetPermission($arParams["IBLOCK_ID"]);
    if ($arParams["CACHE_TIME"] > 0) {
        $cache->StartDataCache($arParams["CACHE_TIME"], $cache_id, $cache_path);
        $cache->EndDataCache($arParams["PERMISSION"]);
    }
}
$arParams["ABS_PERMISSION"] = $arParams["PERMISSION"];
$arParams["PERMISSION"] = !empty($arParams["PERMISSION_EXTERNAL"]) ? $arParams["PERMISSION_EXTERNAL"] : $arParams["PERMISSION"];
if ("R" <= $arParams["PERMISSION"] && $arParams["PERMISSION"] < "W" && $arParams["BEHAVIOUR"] == "USER" && $arParams["USER_ID"] == $GLOBALS["USER"]->GetId()) {
    $arParams["PERMISSION"] = "W";
} elseif ($arParams["PERMISSION"] < "R") {
    return ShowError(GetMessage("P_DENIED_ACCESS"));
}
/************** GALLERIES ******************************************/
//PAGENAVIGATION
$arNavParams = false;
	/**
	 * @param array $arParams
	 * @return array|false
	 */
	public static function OrderProduct($arParams)
	{
		$adminSection = (defined('ADMIN_SECTION') && ADMIN_SECTION === true);

		$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_DISCOUNT'] = (isset($arParams['CHECK_DISCOUNT']) && $arParams['CHECK_DISCOUNT'] == 'N' ? 'N' : 'Y');
		$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['BASKET_ID'] = (string)(isset($arParams['BASKET_ID']) ? $arParams['BASKET_ID'] : '0');

		$arParams['CURRENCY'] = (isset($arParams['CURRENCY']) ? Currency\CurrencyManager::checkCurrencyID($arParams['CURRENCY']) : false);
		if ($arParams['CURRENCY'] === false)
			$arParams['CURRENCY'] = CSaleLang::GetLangCurrency($strSiteID ? $strSiteID : SITE_ID);

		global $USER;

		$productID = (int)$arParams['PRODUCT_ID'];
		$quantity = (float)$arParams['QUANTITY'];
		$intUserID = (int)$arParams['USER_ID'];

		$arResult = array();

		if ($adminSection)
		{
			if ($intUserID == 0)
				return $arResult;
			$userGroups = self::getUserGroups($intUserID);
			if (empty($userGroups))
				return $arResult;

			$dbIBlockElement = CIBlockElement::GetList(
				array(),
				array(
					'ID' => $productID,
					'ACTIVE' => 'Y',
					'ACTIVE_DATE' => 'Y',
					'CHECK_PERMISSION' => 'N'
				),
				false,
				false,
				array('ID', 'IBLOCK_ID', 'NAME', 'DETAIL_PAGE_URL')
			);
			if (!($arProduct = $dbIBlockElement->GetNext()))
				return $arResult;

			if (CIBlock::GetArrayByID($arProduct['IBLOCK_ID'], 'RIGHTS_MODE') == 'E')
			{
				$arUserRights = CIBlockElementRights::GetUserOperations($productID, $intUserID);
				if (empty($arUserRights) || !isset($arUserRights['element_read']))
					return $arResult;
				unset($arUserRights);
			}
			else
			{
				if (CIBlock::GetPermission($arProduct['IBLOCK_ID'], $intUserID) < 'R')
					return $arResult;
			}
		}
		else
		{
			$userGroups = $USER->GetUserGroupArray();
			$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()))
				return $arResult;
		}

		$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())
		{
			$arCatalogProduct["QUANTITY"] = (double)$arCatalogProduct["QUANTITY"];
			if ($arParams["CHECK_QUANTITY"] == "Y")
			{
				if (
					'Y' != $arCatalogProduct["CAN_BUY_ZERO"]
					&& 'Y' == $arCatalogProduct["QUANTITY_TRACE"]
					&& ($arCatalogProduct["QUANTITY"] <= 0 || $quantity > $arCatalogProduct["QUANTITY"])
				)
				{
					return $arResult;
				}
			}
		}
		else
		{
			return $arResult;
		}

		if ($adminSection)
			CCatalogDiscountSave::SetDiscountUserID($intUserID);

		$productHash = array(
			'MODULE' => 'catalog',
			'PRODUCT_ID' => $productID,
			'BASKET_ID' => $arParams['BASKET_ID']
		);
		$arCoupons = DiscountCouponsManager::getForApply(array(), $productHash, true);

		if (!empty($arCoupons))
			$arCoupons = array_keys($arCoupons);

		$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)
			CCatalogDiscountSave::ClearDiscountUserID();

		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'],
					'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($appliedCoupons);
		}

		if (empty($arPrice['PRICE']['CATALOG_GROUP_NAME']))
		{
			if (!empty($arPrice['PRICE']['CATALOG_GROUP_ID']))
			{
				$groupIterator = Catalog\GroupTable::getList(array(
					'select' => array('ID', 'NAME', 'NAME_LANG' => 'CURRENT_LANG.NAME'),
					'filter' => array('ID' => $arPrice['PRICE']['CATALOG_GROUP_ID'])
				));
				if ($group = $groupIterator->fetch())
					$arPrice["PRICE"]["CATALOG_GROUP_NAME"] = (!empty($group['NAME_LANG']) ? $group['NAME_LANG'] : $group['NAME']);
				unset($group, $groupIterator);
			}
		}

		if (empty($arPrice['RESULT_PRICE']) || !is_array($arPrice['RESULT_PRICE']))
			$arPrice['RESULT_PRICE'] = CCatalogDiscount::calculateDiscountList($arPrice['PRICE'], $arParams['CURRENCY'], $arDiscountList, true);

		$arResult = array(
			'PRODUCT_PRICE_ID' => $arPrice['PRICE']['ID'],
			'BASE_PRICE' => $arPrice['RESULT_PRICE']['BASE_PRICE'],
			'PRICE' => $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'],
			'VAT_RATE' => $arPrice['PRICE']['VAT_RATE'],
			"CURRENCY" => $arPrice['RESULT_PRICE']['CURRENCY'],
			"WEIGHT" => (float)$arCatalogProduct["WEIGHT"],
			"DIMENSIONS" => serialize(array(
				"WIDTH" => $arCatalogProduct["WIDTH"],
				"HEIGHT" => $arCatalogProduct["HEIGHT"],
				"LENGTH" => $arCatalogProduct["LENGTH"]
			)),
			"NAME" => $arProduct["~NAME"],
			"CAN_BUY" => "Y",
			"DETAIL_PAGE_URL" => $arProduct['~DETAIL_PAGE_URL'],
			"NOTES" => $arPrice["PRICE"]["CATALOG_GROUP_NAME"],
			"DISCOUNT_PRICE" => $arPrice['RESULT_PRICE']['DISCOUNT'],
			"TYPE" => ($arCatalogProduct["TYPE"] == CCatalogProduct::TYPE_SET) ? CCatalogProductSet::TYPE_SET : NULL,
			"DISCOUNT_VALUE" => ($arPrice['RESULT_PRICE']['PERCENT'] > 0 ? $arPrice['RESULT_PRICE']['PERCENT'].'%' : 0),
			"DISCOUNT_NAME" => '',
			"DISCOUNT_COUPON" => '',
			"DISCOUNT_LIST" => array()
		);

		if ($arParams["CHECK_QUANTITY"] == "Y")
			$arResult["QUANTITY"] = $quantity;
		else
			$arResult["QUANTITY"] = $arParams["QUANTITY"];

		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']);
		}

		return $arResult;
	}