/** * Delete * @param $CODE * @return array * @throws \Exception */ public static function Delete($CODE) { $group = new \CGroup(); $user = new \CUser(); if (!empty($CODE)) { $by = "ID"; $order = "asc"; $dbGroup = $group->GetList($by, $order, array('STRING_ID' => $CODE)); if ($arGroup = $dbGroup->Fetch()) { $arReturn = $arGroup; } } else { throw new BimException('Empty group code'); } if (intval($arReturn['ID']) > 0) { $arUsers = $group->GetGroupUser($arReturn['ID']); foreach ($arUsers as $UserID) { $arGroup = $user->GetUserGroup($UserID); $arGroup[] = "3"; $user->SetUserGroup($UserID, $arGroup); } $res = $group->Delete($arReturn['ID']); if (is_object($res)) { return $arReturn['ID']; } else { throw new BimException($group->LAST_ERROR); } } else { throw new BimException('Group not found'); } }
function HaveRole($role, $userID = false) { global $DB, $USER, $APPLICATION, $SUPPORT_CACHE_USER_ROLES; if (!is_object($USER)) { $USER = new CUser(); } if ($userID === false && is_object($USER)) { $uid = $USER->GetID(); } else { $uid = $userID; } $arRoles = array(); if (array_key_exists($uid, $SUPPORT_CACHE_USER_ROLES) && is_array($SUPPORT_CACHE_USER_ROLES[$uid])) { $arRoles = $SUPPORT_CACHE_USER_ROLES[$uid]; } else { $arrGroups = array(); if ($userID === false && is_object($USER)) { $arrGroups = $USER->GetUserGroupArray(); } else { $arrGroups = CUser::GetUserGroup($userID); } sort($arrGroups); $arRoles = $APPLICATION->GetUserRoles("support", $arrGroups); $SUPPORT_CACHE_USER_ROLES[$uid] = $arRoles; } if (in_array($role, $arRoles)) { return true; } return false; }
private static function SetDiscount($USER_ID, $iSumm, $arDiscount) { $GROUP_ID = 0; $arGroups = array(); foreach($arDiscount as $ar) { if($iSumm >= $ar["PROPERTY_" . self::$PROPERTY_SUMM . "_VALUE"]) $GROUP_ID = $ar["PROPERTY_" . self::$PROPERTY_GROUP . "_VALUE"]; $arGroups[$ar["PROPERTY_" . self::$PROPERTY_GROUP . "_VALUE"]] = $ar["PROPERTY_" . self::$PROPERTY_GROUP . "_VALUE"]; } $arUserGroups = CUser::GetUserGroup($USER_ID); foreach($arUserGroups as $k => $ID) { if($GROUP_ID !== $ID && isset($arGroups[$ID])) unset($arUserGroups[$k]); } if($GROUP_ID) { $arUserGroups[] = $GROUP_ID; } CUser::SetUserGroup($USER_ID, $arUserGroups); }
public function onUserLoginExternal(&$arParams) { if (!$this->useOfficeAuth()) { return null; } $login = new UserLogin($arParams['LOGIN']); $password = $arParams['PASSWORD']; if ($this->isAuthorized($login->getOfficeLogin(), $password, $this->officeAuthUrl())) { $fields = array("LOGIN" => $login->getBitrixLogin(), "NAME" => $login->getOfficeLogin(), "PASSWORD" => $password, "EMAIL" => $login->getEmail(), "ACTIVE" => "Y", "EXTERNAL_AUTH_ID" => "Office", "LID" => SITE_ID); $user = new \CUser(); $existedUser = \CUser::GetList($by = "timestamp_x", $order = "desc", array("LOGIN_EQUAL_EXACT" => $login->getBitrixLogin(), "EXTERNAL_AUTH_ID" => "Office"))->Fetch(); if (!$existedUser) { $id = $user->Add($fields); } else { $id = $existedUser["ID"]; $user->Update($id, $fields); } if ($id > 0) { $groups = \CUser::GetUserGroup($id); if (!in_array(1, $groups)) { $groups[] = 1; \CUser::SetUserGroup($id, $groups); } $arParams["store_password"] = "******"; return $id; } } return null; }
public static function IsAdmin($userId = null) { $result = false; if ($userId === null) { $user = self::GetCurrentUser(); if ($user->IsAdmin()) { return true; } $userId = $user->getId(); } $userId = (int) $userId; if ($userId <= 0) { return false; } try { if (IsModuleInstalled('bitrix24') && CModule::IncludeModule('bitrix24')) { if (class_exists('CBitrix24') && method_exists('CBitrix24', 'IsPortalAdmin')) { // New style check $result = CBitrix24::IsPortalAdmin($userId); } else { // HACK: Check user group 1 ('Portal admins') $arGroups = CUser::GetUserGroup($userId); $result = in_array(1, $arGroups); } } } catch (Exception $e) { } return $result; }
/** * Возвращает список групп пользователя по отношению к городам * @return array */ public function getCityGroups() { if ($this->_cityGroups === null && !$this->isNew()) { $ids = \CUser::GetUserGroup($this->getAttribute('id')->getValue()); $this->_cityGroups = \bxpimple\Locator::$item->get('groupFinder')->mergeFilterWith(['ID' => implode(' | ', $ids), 'STRING_ID' => 'totaldict_city_%'])->all(); } return $this->_cityGroups; }
static function DoProcessOrderDelivery(&$arOrder, $arOptions, &$arErrors) { if ((!array_key_exists("TAX_LOCATION", $arOrder) || intval($arOrder["TAX_LOCATION"]) <= 0) && !$arOrder["USE_VAT"]) { return; } if (!array_key_exists("COUNT_DELIVERY_TAX", $arOptions)) { $arOptions["COUNT_DELIVERY_TAX"] = COption::GetOptionString("sale", "COUNT_DELIVERY_TAX", "N"); } if (doubleval($arOrder["DELIVERY_PRICE"]) <= 0 || $arOptions["COUNT_DELIVERY_TAX"] != "Y") { return; } if (!$arOrder["USE_VAT"]) { if (!array_key_exists("TAX_EXEMPT", $arOrder)) { $arUserGroups = CUser::GetUserGroup($arOrder["USER_ID"]); $dbTaxExemptList = CSaleTax::GetExemptList(array("GROUP_ID" => $arUserGroups)); while ($TaxExemptList = $dbTaxExemptList->Fetch()) { if (!in_array(intval($TaxExemptList["TAX_ID"]), $arOrder["TAX_EXEMPT"])) { $arOrder["TAX_EXEMPT"][] = intval($TaxExemptList["TAX_ID"]); } } } if (!array_key_exists("TAX_LIST", $arOrder)) { $arOrder["TAX_LIST"] = array(); $dbTaxRate = CSaleTaxRate::GetList(array("APPLY_ORDER" => "ASC"), array("LID" => $arOrder["SITE_ID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "ACTIVE" => "Y", "LOCATION" => $arOrder["TAX_LOCATION"])); while ($arTaxRate = $dbTaxRate->GetNext()) { if (!in_array(intval($arTaxRate["TAX_ID"]), $arOrder["TAX_EXEMPT"])) { if ($arTaxRate["IS_PERCENT"] != "Y") { $arTaxRate["VALUE"] = RoundEx(CCurrencyRates::ConvertCurrency($arTaxRate["VALUE"], $arTaxRate["CURRENCY"], $arOrder["CURRENCY"]), SALE_VALUE_PRECISION); $arTaxRate["CURRENCY"] = $arOrder["CURRENCY"]; } $arOrder["TAX_LIST"][] = $arTaxRate; } } } if (count($arOrder["TAX_LIST"]) > 0) { CSaleOrderTax::CountTaxes($arOrder["DELIVERY_PRICE"], $arOrder["TAX_LIST"], $arOrder["CURRENCY"]); foreach ($arOrder["TAX_LIST"] as &$arTax) { $arTax["VALUE_MONEY"] += roundEx($arTax["TAX_VAL"], SALE_VALUE_PRECISION); } unset($arTax); $arOrder["TAX_PRICE"] = 0; foreach ($arOrder["TAX_LIST"] as $arTax) { if ($arTax["IS_IN_PRICE"] != "Y") { $arOrder["TAX_PRICE"] += roundEx($arTax["VALUE_MONEY"], SALE_VALUE_PRECISION); } } } } else { $deliveryVat = roundEx($arOrder["DELIVERY_PRICE"] * $arOrder["VAT_RATE"] / (1 + $arOrder["VAT_RATE"]), 2); $arOrder["VAT_SUM"] += $deliveryVat; $arOrder["VAT_DELIVERY"] += $deliveryVat; //if (!array_key_exists("TAX_LIST", $arOrder)) //{ $arOrder["TAX_LIST"][0] = array("NAME" => GetMessage("SOA_VAT"), "IS_PERCENT" => "Y", "VALUE" => $arOrder["VAT_RATE"] * 100, "VALUE_FORMATED" => "(" . $arOrder["VAT_RATE"] * 100 . "%, " . GetMessage("SOA_VAT_INCLUDED") . ")", "VALUE_MONEY" => $arOrder["VAT_SUM"], "VALUE_MONEY_FORMATED" => SaleFormatCurrency($arOrder["VAT_SUM"], $arOrder["CURRENCY"]), "APPLY_ORDER" => 100, "IS_IN_PRICE" => "Y", "CODE" => "VAT"); //} } }
/** * Обработчик события подтверждения оплаты товара */ function OnSalePayOrderHandler($id, $val) { $currentUserId = $GLOBALS['USER']->GetID(); //Идентификатор текущего пользователя, по идее администратор $idRatingGroup = 5; //группа акции $curTo = "UAH"; //тип гривневой цены $arOrder = CSaleOrder::GetByID($id); //информация о заказе $price = CCurrencyRates::ConvertCurrency(floatval($arOrder["SUM_PAID"]), $arOrder["CURRENCY"], $curTo); $price = intval(ceil($price)); //стоимость заказа $userId = intval($arOrder["USER_ID"]); //пользователь, который оплатил заказ $arUserData = CUser::GetByID($userId)->Fetch(); //Информация о пользователе $userGroups = CUser::GetUserGroup($userId); //ИД групп, к которым принадлежит пользователь //Если пользователя нет в акционной группе, и он совершил заказ более чем на 900 грн, то добавить его в группу if (!in_array($idRatingGroup, $userGroups)) { if ($price >= 900 && $price <= 4000 && $val === 'Y') { $userGroups[] = $idRatingGroup; CUser::SetUserGroup($userId, $userGroups); } } $points = $price * 5; $payedUser = new CUser(); //Если оплата подтверждается, то добавить баллы if ($val === 'Y' && in_array($idRatingGroup, $userGroups)) { $points = intval($arUserData['UF_ACTION_POINTS']) + $points; $payedUser->Update($userId, array("UF_ACTION_POINTS" => $points, "UF_DATE_LAST_BUY" => $arOrder["DATE_UPDATE_FORMAT"])); } else { if ($val === 'N') { $price = CCurrencyRates::ConvertCurrency(floatval($arOrder["PRICE"]), $arOrder["CURRENCY"], $curTo); $price = intval(ceil($price)); //вычитаем полную стоимость $points = $price * 5; if ($arUserData['UF_ACTION_POINTS'] >= $points) { $points = intval($arUserData['UF_ACTION_POINTS']) - $points; $payedUser->Update($userId, array("UF_ACTION_POINTS" => $points)); //Если очков стало меньше 4500, то исключаем пользователя из группы участников if (in_array($idRatingGroup, $userGroups) && $points < 4500) { $indexGroup = array_search($idRatingGroup, $userGroups); if (isset($userGroups[$indexGroup])) { unset($userGroups[$indexGroup]); CUser::SetUserGroup($userId, $userGroups); } } } } } unset($payedUser); }
public function InitializeFromArray($arUser) { $this->userId = $arUser['ID']; $this->login = $arUser['LOGIN']; $this->name = $arUser["NAME"] . (strlen($arUser["NAME"]) <= 0 || strlen($arUser["LAST_NAME"]) <= 0 ? "" : " ") . $arUser["LAST_NAME"]; if (empty($this->name)) { $this->name = $this->login; } $this->email = $arUser['EMAIL']; $this->arUserGroups = CUser::GetUserGroup($this->userId); $this->isAdmin = in_array(1, $this->arUserGroups); }
static function DoProcessOrder(&$arOrder, $arOptions, &$arErrors) { global $DB; if (!array_key_exists("COUNT_DISCOUNT_4_ALL_QUANTITY", $arOptions)) { $arOptions["COUNT_DISCOUNT_4_ALL_QUANTITY"] = COption::GetOptionString("sale", "COUNT_DISCOUNT_4_ALL_QUANTITY", "N"); } $arMinDiscount = null; $allSum = 0; foreach ($arOrder["BASKET_ITEMS"] as $arItem) { $allSum += $arItem["PRICE"] * $arItem["QUANTITY"]; } $dblMinPrice = $allSum; $dbDiscount = CSaleDiscount::GetList(array("SORT" => "ASC"), array("LID" => $arOrder["SITE_ID"], "ACTIVE" => "Y", "!>ACTIVE_FROM" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "!<ACTIVE_TO" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "<=PRICE_FROM" => $arOrder["ORDER_PRICE"], ">=PRICE_TO" => $arOrder["ORDER_PRICE"], "USER_GROUPS" => CUser::GetUserGroup($arOrder["USER_ID"])), false, false, array("*")); while ($arDiscount = $dbDiscount->Fetch()) { $dblDiscount = 0; if ($arDiscount["DISCOUNT_TYPE"] == "P") { if ($arOptions["COUNT_DISCOUNT_4_ALL_QUANTITY"] == "Y") { foreach ($arOrder["BASKET_ITEMS"] as $arItem) { $dblDiscount += roundEx($arItem["PRICE"] * $arItem["QUANTITY"] * $arDiscount["DISCOUNT_VALUE"] / 100, SALE_VALUE_PRECISION); } } else { foreach ($arOrder["BASKET_ITEMS"] as $arItem) { $dblDiscount += roundEx(roundEx($arItem["PRICE"] * $arDiscount["DISCOUNT_VALUE"] / 100, SALE_VALUE_PRECISION) * $arItem["QUANTITY"], SALE_VALUE_PRECISION); } } } else { $dblDiscount = roundEx(CCurrencyRates::ConvertCurrency($arDiscount["DISCOUNT_VALUE"], $arDiscount["CURRENCY"], $arOrder["CURRENCY"]), SALE_VALUE_PRECISION); } if ($dblMinPrice > $allSum - $dblDiscount) { $dblMinPrice = $allSum - $dblDiscount; $arMinDiscount = $arDiscount; } } if ($arMinDiscount != null) { if ($arMinDiscount["DISCOUNT_TYPE"] == "P") { $arOrder["DISCOUNT_PERCENT"] = $arMinDiscount["DISCOUNT_VALUE"]; foreach ($arOrder["BASKET_ITEMS"] as &$arItem) { if ($arOptions["COUNT_DISCOUNT_4_ALL_QUANTITY"] == "Y") { $curDiscount = roundEx($arItem["PRICE"] * $arItem["QUANTITY"] * $arMinDiscount["DISCOUNT_VALUE"] / 100, SALE_VALUE_PRECISION); $arOrder["DISCOUNT_PRICE"] += $curDiscount; } else { $curDiscount = roundEx($arItem["PRICE"] * $arMinDiscount["DISCOUNT_VALUE"] / 100, SALE_VALUE_PRECISION); $arOrder["DISCOUNT_PRICE"] += roundEx($curDiscount * $arItem["QUANTITY"], SALE_VALUE_PRECISION); } //$arItem["DISCOUNT_PRICE"] = $arItem["PRICE"] - $curDiscount; } } else { $arOrder["DISCOUNT_PRICE"] = CCurrencyRates::ConvertCurrency($arMinDiscount["DISCOUNT_VALUE"], $arMinDiscount["CURRENCY"], $arOrder["CURRENCY"]); $arOrder["DISCOUNT_PRICE"] = roundEx($arOrder["DISCOUNT_PRICE"], SALE_VALUE_PRECISION); } } }
function makDelUserToGroup($uid, $gid) { if (intval($uid) > 0) { $makUserGroups = CUser::GetUserGroup($uid); $key = array_search($gid, $makUserGroups); if ($key !== false) { unset($makUserGroups[$key]); } CUser::SetUserGroup($uid, $makUserGroups); return true; } return false; }
public static function DoProcessOrder(&$arOrder, $arOptions, &$arErrors) { global $DB; if (!array_key_exists("COUNT_DISCOUNT_4_ALL_QUANTITY", $arOptions)) { $arOptions["COUNT_DISCOUNT_4_ALL_QUANTITY"] = COption::GetOptionString("sale", "COUNT_DISCOUNT_4_ALL_QUANTITY", "N"); } $arIDS = array(); $rsDiscountIDs = CSaleDiscount::GetDiscountGroupList(array(), array('GROUP_ID' => CUser::GetUserGroup($arOrder["USER_ID"])), false, false, array('DISCOUNT_ID')); while ($arDiscountID = $rsDiscountIDs->Fetch()) { $arDiscountID['DISCOUNT_ID'] = intval($arDiscountID['DISCOUNT_ID']); if (0 < $arDiscountID['DISCOUNT_ID']) { $arIDS[] = $arDiscountID['DISCOUNT_ID']; } } if (!empty($arIDS)) { $arIDS = array_values(array_unique($arIDS)); $rsDiscounts = CSaleDiscount::GetList(array("PRIORITY" => "DESC", "SORT" => "ASC"), array('ID' => $arIDS, "LID" => $arOrder["SITE_ID"], "ACTIVE" => "Y", "!>ACTIVE_FROM" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "!<ACTIVE_TO" => date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")))), false, false, array("ID", "PRIORITY", "LAST_DISCOUNT", "UNPACK", "APPLICATION")); while ($arDiscount = $rsDiscounts->Fetch()) { if (self::__Unpack($arOrder, $arDiscount['UNPACK'])) { self::__ApplyActions($arOrder, $arDiscount['APPLICATION']); } if ('Y' == $arDiscount['LAST_DISCOUNT']) { break; } } $arOrder["ORDER_PRICE"] = 0; $arOrder["ORDER_WEIGHT"] = 0; $arOrder["USE_VAT"] = false; $arOrder["VAT_RATE"] = 0; $arOrder["VAT_SUM"] = 0; $arOrder["DISCOUNT_PRICE"] = 0.0; $arOrder["DISCOUNT_VALUE"] = $arOrder["DISCOUNT_PRICE"]; $arOrder["DELIVERY_PRICE"] = $arOrder["PRICE_DELIVERY"]; foreach ($arOrder['BASKET_ITEMS'] as &$arShoppingCartItem) { $arOrder["ORDER_PRICE"] += $arShoppingCartItem["PRICE"] * $arShoppingCartItem["QUANTITY"]; $arOrder["ORDER_WEIGHT"] += $arShoppingCartItem["WEIGHT"] * $arShoppingCartItem["QUANTITY"]; if ($arShoppingCartItem["VAT_RATE"] > 0) { $arOrder["USE_VAT"] = true; if ($arShoppingCartItem["VAT_RATE"] > $arOrder["VAT_RATE"]) { $arOrder["VAT_RATE"] = $arShoppingCartItem["VAT_RATE"]; } $arOrder["VAT_SUM"] += $arShoppingCartItem["VAT_VALUE"] * $arShoppingCartItem["QUANTITY"]; } } if (isset($arShoppingCartItem)) { unset($arShoppingCartItem); } } }
function CanUserCreateBlog($userID = 0) { $userID = IntVal($userID); if ($userID > 0 && CBlogUser::IsLocked($userID)) { return False; } $arGroups = false; if ($userID > 0) { $arGroups = CUser::GetUserGroup($userID); } $blogModulePermissions = $GLOBALS["APPLICATION"]->GetGroupRight("blog", $arGroups); if ($blogModulePermissions >= "N") { return True; } return False; // return True; }
function OnBeforeUserUpdateHandler(&$arFields) { if (isset($arFields['UF_GROUPS']) && in_array(1, $arFields['UF_GROUPS'])) { $user = CUser::GetByID($arFields['ID'])->Fetch(); if (!in_array(1, $user['UF_GROUPS'])) { AddMessage2Log('update users'); CModule::IncludeModule("iblock"); CIBlockElement::SetPropertyValues(1, 4, getKentLabUsers(), "USERS"); $groups = CUser::GetUserGroup($user['UF_USER_PARENT']); $fields = array_flip(getValuesList('UF_STATUS', 'USER', 'ID')); if (intval($user['UF_USER_PARENT']) > 0 && $fields[$user['UF_STATUS']] == 4) { if (in_array(8, $groups)) { changeUserStatus($user['ID'], $user['UF_USER_PARENT'], $user['UF_STATUS'], 6, "Регистрация в KENT Lab"); } } } } }
function HaveRole($role, $USER_ID = false) { global $USER, $APPLICATION; if ($USER_ID === false && is_object($USER)) { $USER_ID = $USER->GetID(); } $USER_ID = intval($USER_ID); if ($USER_ID > 0) { if (is_object($USER) && $USER_ID == $USER->GetID()) { $arrGroups = $USER->GetUserGroupArray(); } else { $arrGroups = CUser::GetUserGroup($USER_ID); } $arRoles = $APPLICATION->GetUserRoles("advertising", $arrGroups); if (in_array($role, $arRoles)) { return true; } } return false; }
/** * Create new comment for task * * @param integer $taskId * @param integet $commentId * @param integer $commentEditorId - ID of user who is comment's editor * @param string[] $arFields - fields to be updated, including text in BB code * * @throws TasksException, CTaskAssertException * * @return boolean */ public static function update($taskId, $commentId, $commentEditorId, $arFields) { CTaskAssert::assertLaxIntegers($taskId, $commentId, $commentEditorId); CTaskAssert::assert(is_array($arFields) && !empty($arFields)); if (!CModule::includeModule('forum')) { throw new TasksException('forum module can not be loaded', TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED); } IncludeModuleLangFile(__FILE__); $forumId = CTasksTools::GetForumIdForIntranet(); $oTask = CTaskItem::getInstance($taskId, $commentEditorId); $arTask = $oTask->getData(); $outForumTopicId = $outStrUrl = null; $arErrorCodes = array(); $arFields = array_merge(array('EDITOR_ID' => $commentEditorId), $arFields); $messageId = self::__deprecated_Add($arFields['POST_MESSAGE'], $forumTopicId = $arTask['FORUM_TOPIC_ID'], $forumId, $nameTemplate = CSite::GetNameFormat(false), $arTask = $arTask, $permissions = 'Y', $commentId = $commentId, $givenUserId = $commentEditorId, $imageWidth = 300, $imageHeight = 300, $arSmiles = array(), $arForum = CForumNew::GetByID($forumId), $messagesPerPage = 10, $arUserGroupArray = CUser::GetUserGroup($commentEditorId), $backPage = null, $strMsgAddComment = GetMessage("TASKS_COMMENT_MESSAGE_ADD"), $strMsgEditComment = GetMessage("TASKS_COMMENT_MESSAGE_EDIT"), $strMsgNewTask = GetMessage("TASKS_COMMENT_SONET_NEW_TASK_MESSAGE"), $componentName = null, $outForumTopicId, $arErrorCodes, $outStrUrl, $arFields); if (!($messageId >= 1)) { throw new TasksException(serialize($arErrorCodes), TasksException::TE_ACTION_FAILED_TO_BE_PROCESSED | TasksException::TE_FLAG_SERIALIZED_ERRORS_IN_MESSAGE); } return true; }
$res["~POST_MESSAGE_TEXT"] = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $res["~POST_MESSAGE_FILTER"] : $res["~POST_MESSAGE"]; // attach $res["ATTACH_IMG"] = ""; $res["FILES"] = array(); $res["~ATTACH_FILE"] = array(); $res["ATTACH_FILE"] = array(); /************** Message info/***************************************/ /************** Author info ****************************************/ $res["AUTHOR_ID"] = intVal($res["AUTHOR_ID"]); $res["AUTHOR_NAME"] = $parser->wrap_long_words($res["AUTHOR_NAME"]); if ($res["AUTHOR_ID"] <= 0) { // Status list($res["AUTHOR_STATUS_CODE"], $res["AUTHOR_STATUS"]) = ForumGetUserForumStatus(0); } else { if (!array_key_exists($res["AUTHOR_ID"], $UserInfo)) { $perm = CForumNew::GetUserPermission($res["FORUM_ID"], CUser::GetUserGroup($res["AUTHOR_ID"])); $arUser = array("Perms" => $perm, "Rank" => $perm <= "Q" ? CForumUser::GetUserRank($res["AUTHOR_ID"], LANGUAGE_ID) : "", "Points" => !empty($res["POINTS"]) ? array("POINTS" => $res["POINTS"], "DATE_UPDATE" => $res["DATE_UPDATE"]) : false); $arUData = array(); // Status list($arUData["AUTHOR_STATUS_CODE"], $arUData["AUTHOR_STATUS"]) = ForumGetUserForumStatus($res["AUTHOR_ID"], $arUser["Perms"], $arUser); // Avatar if (!empty($res["AVATAR"])) { $arUData["AVATAR"] = array("ID" => $res["~AVATAR"], "FILE" => CFile::GetFileArray($res["~AVATAR"])); $arUData["AVATAR"]["HTML"] = CFile::ShowImage($arUData["AVATAR"]["FILE"], COption::GetOptionString("forum", "avatar_max_width", 90), COption::GetOptionString("forum", "avatar_max_height", 90), "border=\"0\"", "", true); } // Voting $arUData["VOTING"] = "N"; if (COption::GetOptionString("forum", "SHOW_VOTES", "Y") == "Y" && $USER->IsAuthorized() && ($GLOBALS["APPLICATION"]->GetGroupRight("forum") >= "W" || $USER->GetID() != $res["AUTHOR_ID"])) { $bUnVote = $arUser["Points"]; $bVote = !$arUser["Points"] ? $arResult["USER"]["RANK"]["VOTES"] : intval($arUser["Points"]["POINTS"]) < intval($arResult["USER"]["RANK"]["VOTES"]); $bVote = $bVote ? $bVote : $GLOBALS["APPLICATION"]->GetGroupRight("forum") >= "W";
public function __construct($userId = null) { $this->isAdmin = false; if (is_int($userId)) { $userGroups = CUser::GetUserGroup($userId); $this->isAdmin = in_array(1, $userGroups); } elseif ($userId == self::CurrentUser) { global $USER; if ($USER->IsAuthorized()) { $this->isAdmin = $USER->IsAdmin(); } } }
/** * @param $userId * @return array */ public static function loadExemptList($userId) { $exemptList = array(); static $proxyUserGroups = array(); static $proxyTaxExemptList = array(); if (!empty($proxyUserGroups[$userId])) { $userGroups = $proxyUserGroups[$userId]; } else { $userGroups = \CUser::GetUserGroup($userId); $proxyUserGroups[$userId] = $userGroups; } $proxyTaxExemptKey = md5(join('|', $userGroups)); if (!empty($proxyTaxExemptList[$proxyTaxExemptKey])) { $exemptList = $proxyTaxExemptList[$proxyTaxExemptKey]; } else { $dbTaxExemptList = \CSaleTax::GetExemptList(array("GROUP_ID" => $userGroups)); while ($taxExemptList = $dbTaxExemptList->Fetch()) { if (!in_array(intval($taxExemptList["TAX_ID"]), $exemptList)) { $exemptList[] = intval($taxExemptList["TAX_ID"]); } } $proxyTaxExemptList[$proxyTaxExemptKey] = $exemptList; } return $exemptList; }
protected function execute(InputInterface $input, OutputInterface $output) { $file = $input->getArgument('file'); if (!file_exists($file) || !($fh = fopen($file, 'r'))) { $output->writeln('<error>Can\'t read data from file</error>'); return null; } //выбираем группу $group = 0; $res = \CGroup::GetList($by = '', $order = '', ['STRING_ID' => 'totaldict_chairman_experts']); if ($ob = $res->Fetch()) { $group = $ob['ID']; } //выбираем список статусов $statusList = []; $rsData = \CUserTypeEntity::GetList([], ['ENTITY_ID' => 'USER', 'FIELD_NAME' => 'UF_TD_ORG_STATUS']); if ($fob = $rsData->GetNext()) { $ar = ['newby' => 'НОВИЧКИ', 'pretty_boy' => 'КРАСАВЧИКИ', 'catching' => 'ДОГОНЯЮЩИЕ', 'redneck' => 'ДЕРЕВНИ']; $res = \CUserFieldEnum::GetList([], ['USER_FIELD_ID' => $fob['ID']]); while ($ob = $res->Fetch()) { if (empty($ar[$ob['XML_ID']])) { continue; } $statusList[$ar[$ob['XML_ID']]] = $ob['ID']; } } //список стран для заполнения $countries = GetCountryArray(); $countries = array_combine($countries['reference'], $countries['reference_id']); $currentStatus = null; while (($data = fgetcsv($fh)) !== false) { //если заполнена только вторая колонка то это статус if (empty($data[1]) && !empty($data[0]) && isset($statusList[$data[0]])) { $currentStatus = $statusList[$data[1]]; continue; } //массив для загрузки данных пользователя $arLoad = ['ACTIVE' => 'Y', 'PERSONAL_COUNTRY' => isset($countries['Россия']) ? $countries['Россия'] : null, 'PERSONAL_CITY' => $data[0], 'LAST_NAME' => $data[1], 'WORK_POSITION' => $data[3], 'PERSONAL_MOBILE' => $data[4], 'PERSONAL_STREET' => $data[6], 'PERSONAL_WWW' => $data[8], 'PASSWORD' => 'Test,user,passwr0d', 'CONFIRM_PASSWORD' => 'Test,user,passwr0d', 'UF_TD_ORG_STATUS' => $currentStatus, 'GROUP_ID' => [2, $group]]; //пробуем разбить email if (strpos($data[5], ',')) { $explode = array_map('trim', explode(',', $data[5])); $arLoad['EMAIL'] = $explode[0]; unset($explode[0]); $arLoad['PERSONAL_NOTES'] = implode(', ', $explode); } elseif (strpos($data[5], 'и')) { $explode = array_map('trim', explode('и', $data[5])); $arLoad['EMAIL'] = $explode[0]; unset($explode[0]); $arLoad['PERSONAL_NOTES'] = implode(', ', $explode); } elseif (strpos($data[5], ';')) { $explode = array_map('trim', explode(';', $data[5])); $arLoad['EMAIL'] = $explode[0]; unset($explode[0]); $arLoad['PERSONAL_NOTES'] = implode(', ', $explode); } elseif (strpos($data[5], ' ')) { $explode = array_map('trim', explode(' ', $data[5])); $arLoad['EMAIL'] = $explode[0]; unset($explode[0]); $arLoad['PERSONAL_NOTES'] = implode(', ', $explode); } else { $arLoad['EMAIL'] = trim($data[5]); } //пробуем разбить фамилию и имя if (strpos($data[2], ' ')) { $explode = explode(' ', trim($data[2])); $arLoad['NAME'] = $explode[0]; $arLoad['SECOND_NAME'] = $explode[1]; } else { $arLoad['NAME'] = trim($data[2]); } //пробуем завести дату в базу if (($time = strtotime($data[7])) !== false) { $arLoad['PERSONAL_BIRTHDAY'] = ConvertTimeStamp($time, 'SHORT', 'ru'); } //пробуем найти страну, чтобы привязать пользователя к городу $country = \bxpimple\Locator::$item->get('countryFinder')->mergeFilterWith(['NAME' => 'Россия'])->one(); if ($country) { //если нашли страну, то пробуем найти и город $city = \bxpimple\Locator::$item->get('cityFinder')->mergeFilterWith(['NAME' => trim($data[0]), 'PROPERTY_TOTALDICT_GEO_CITIES_COUNTRY' => $country->getAttribute('ID')->getValue()])->one(); if ($city) { //если нашли город, то привязываем пользователя $arLoad['UF_TD_CITY_IB'] = $city->getAttribute('ID')->getValue(); } } //задаем логин, по умолчанию используем email $arLoad['LOGIN'] = $arLoad['EMAIL']; //пробуем найти пользователя по его логину $user = new \CUser(); $res = \CUser::GetList($by = '', $order = '', ['LOGIN_EQUAL' => $arLoad['LOGIN']]); if ($ob = $res->Fetch()) { $arGroups = \CUser::GetUserGroup($ob['ID']); if (is_array($arGroups)) { $arLoad['GROUP_ID'] = array_unique(array_merge($arLoad['GROUP_ID'], $arGroups)); } //обновляем if (!$user->Update($ob['ID'], $arLoad)) { $output->writeln('<error>User ' . $arLoad['LOGIN'] . ' error: ' . $user->LAST_ERROR . '</error>'); } else { $output->writeln('<info>User ' . $arLoad['LOGIN'] . ' updated</info>'); } } else { //создаем нового if (!$user->Add($arLoad)) { $output->writeln('<error>User ' . $arLoad['LOGIN'] . ' error: ' . $user->LAST_ERROR . '</error>'); } else { $output->writeln('<info>New user ' . $arLoad['LOGIN'] . ' added</info>'); } } } fclose($fh); }
function SendEvent($ID, $mailTemplate = "SONET_NEW_EVENT") { $ID = IntVal($ID); if ($ID <= 0) { return false; } $arFilter = array("ID" => $ID); $dbLogComments = CSocNetLogComments::GetList(array(), $arFilter, false, false, array("ID", "LOG_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "GROUP_NAME", "CREATED_BY_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_LOGIN", "LOG_SITE_ID", "SOURCE_ID", "LOG_SOURCE_ID")); $arLogComment = $dbLogComments->Fetch(); if (!$arLogComment) { return false; } $arLog = array(); if (intval($arLogComment["LOG_ID"]) > 0) { $dbLog = CSocNetLog::GetList(array(), array("ID" => $arLogComment["LOG_ID"])); $arLog = $dbLog->Fetch(); if (!$arLog) { $arLog = array(); } } $arEvent = CSocNetLogTools::FindLogCommentEventByID($arLogComment["EVENT_ID"]); if ($arEvent && array_key_exists("CLASS_FORMAT", $arEvent) && array_key_exists("METHOD_FORMAT", $arEvent) && strlen($arEvent["CLASS_FORMAT"]) > 0 && strlen($arEvent["METHOD_FORMAT"]) > 0) { $dbSiteCurrent = CSite::GetByID(SITE_ID); if ($arSiteCurrent = $dbSiteCurrent->Fetch()) { if ($arSiteCurrent["LANGUAGE_ID"] != LANGUAGE_ID) { $arLogComment["MAIL_LANGUAGE_ID"] = $arSiteCurrent["LANGUAGE_ID"]; } } $arLogComment["FIELDS_FORMATTED"] = call_user_func(array($arEvent["CLASS_FORMAT"], $arEvent["METHOD_FORMAT"]), $arLogComment, array(), true, $arLog); } if (array_key_exists($arLogComment["ENTITY_TYPE"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"]) && array_key_exists("HAS_MY", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && array_key_exists("METHOD_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]) && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"]) > 0 && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]) > 0 && method_exists($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"])) { $arOfEntities = call_user_func(array($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLogComment["ENTITY_TYPE"]]["METHOD_OF"]), $arLogComment["ENTITY_ID"]); } $arListParams = array("USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => $arLogComment["EVENT_ID"], "USER_ID" => $arLogComment["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => array("M", "X")); $arLogSites = array(); $rsLogSite = CSocNetLog::GetSite($arLog["ID"]); while ($arLogSite = $rsLogSite->Fetch()) { $arLogSites[] = $arLogSite["LID"]; } if (CModule::IncludeModule("extranet")) { if ($arLogComment["ENTITY_TYPE"] == SONET_ENTITY_GROUP) { $arSites = array(); $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y")); while ($arSite = $dbSite->Fetch()) { $arSites[$arSite["ID"]] = array("DIR" => strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/", "SERVER_NAME" => strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])); } $intranet_site_id = CSite::GetDefSite(); } $arIntranetUsers = CExtranet::GetIntranetUsers(); $extranet_site_id = CExtranet::GetExtranetSiteID(); } $dbSubscribers = CSocNetLogEvents::GetList(array("TRANSPORT" => "DESC"), array("USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false))), false, false, array("USER_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "USER_NAME", "USER_LAST_NAME", "USER_LOGIN", "USER_LID", "USER_EMAIL", "TRANSPORT"), $arListParams); $arListParams = array("USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => $arLogComment["EVENT_ID"], "USER_ID" => $arLogComment["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => "N"); $dbUnSubscribers = CSocNetLogEvents::GetList(array("TRANSPORT" => "DESC"), array("USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false))), false, false, array("USER_ID", "SITE_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "TRANSPORT", "EVENT_ID"), $arListParams); $arUnSubscribers = array(); while ($arUnSubscriber = $dbUnSubscribers->Fetch()) { $arUnSubscribers[] = $arUnSubscriber["USER_ID"] . "_" . $arUnSubscriber["ENTITY_TYPE"] . "_" . $arUnSubscriber["ENTITY_ID"] . "_" . $arUnSubscriber["ENTITY_MY"] . "_" . $arUnSubscriber["ENTITY_CB"] . "_" . $arUnSubscriber["EVENT_ID"]; } $bHasAccessAll = CSocNetLogRights::CheckForUserAll($arLog["ID"] ? $arLog["ID"] : $arLogComment["LOG_ID"]); $arSentUserID = array("M" => array(), "X" => array()); while ($arSubscriber = $dbSubscribers->Fetch()) { if (is_array($arIntranetUsers) && !in_array($arSubscriber["USER_ID"], $arIntranetUsers) && !in_array($extranet_site_id, $arLogSites)) { continue; } if (array_key_exists($arSubscriber["TRANSPORT"], $arSentUserID) && in_array($arSubscriber["USER_ID"], $arSentUserID[$arSubscriber["TRANSPORT"]])) { continue; } if (intval($arSubscriber["ENTITY_ID"]) != 0 && $arSubscriber["EVENT_ID"] == "all" && (in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arSubscriber["ENTITY_ID"] . "_N_" . $arSubscriber["ENTITY_CB"] . "_" . $arLogComment["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arSubscriber["ENTITY_ID"] . "_Y_" . $arSubscriber["ENTITY_CB"] . "_" . $arLogComment["EVENT_ID"], $arUnSubscribers))) { continue; } elseif (intval($arSubscriber["ENTITY_ID"]) == 0 && $arSubscriber["ENTITY_CB"] == "N" && $arSubscriber["EVENT_ID"] != "all" && (in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_Y_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_N_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_Y_N_" . $arLogComment["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"] . "_" . $arSubscriber["ENTITY_TYPE"] . "_" . $arLogComment["ENTITY_ID"] . "_N_N_" . $arLogComment["EVENT_ID"], $arUnSubscribers))) { continue; } $arSentUserID[$arSubscriber["TRANSPORT"]][] = $arSubscriber["USER_ID"]; if (!$bHasAccessAll) { $bHasAccess = CSocNetLogRights::CheckForUserOnly($arLog["ID"] ? $arLog["ID"] : $arLogComment["LOG_ID"], $arSubscriber["USER_ID"]); if (!$bHasAccess) { continue; } } if ($arLogComment["ENTITY_TYPE"] == SONET_ENTITY_GROUP && is_array($arIntranetUsers) && CModule::IncludeModule("extranet")) { $server_name = $arSites[!in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id ? $extranet_site_id : $intranet_site_id]["SERVER_NAME"]; $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] = str_replace(array("#SERVER_NAME#", "#GROUPS_PATH#"), array($server_name, COption::GetOptionString("socialnetwork", "workgroups_page", false, !in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id ? $extranet_site_id : $intranet_site_id)), $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]); } else { $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] = $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]; } switch ($arSubscriber["TRANSPORT"]) { case "X": if (array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0) { $link = GetMessage("SONET_GLC_SEND_EVENT_LINK") . $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]; } else { $link = ""; } $arMessageFields = array("FROM_USER_ID" => intval($arLogComment["USER_ID"]) > 0 ? $arLogComment["USER_ID"] : 1, "TO_USER_ID" => $arSubscriber["USER_ID"], "MESSAGE" => $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"] . " #BR# " . $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"] . (strlen($link) > 0 ? "#BR# " . $link : ""), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM, "IS_LOG" => "Y"); CSocNetMessages::Add($arMessageFields); break; case "M": $arFields["SUBSCRIBER_ID"] = $arSubscriber["USER_ID"]; $arFields["SUBSCRIBER_NAME"] = $arSubscriber["USER_NAME"]; $arFields["SUBSCRIBER_LAST_NAME"] = $arSubscriber["USER_LAST_NAME"]; $arFields["SUBSCRIBER_LOGIN"] = $arSubscriber["USER_LOGIN"]; $arFields["SUBSCRIBER_EMAIL"] = $arSubscriber["USER_EMAIL"]; $arFields["EMAIL_TO"] = $arSubscriber["USER_EMAIL"]; $arFields["TITLE"] = str_replace("#BR#", "\n", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"]); $arFields["MESSAGE"] = str_replace("#BR#", "\n", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"]); $arFields["ENTITY"] = $arLogComment["FIELDS_FORMATTED"]["ENTITY"]["FORMATTED"]; $arFields["ENTITY_TYPE"] = $arLogComment["FIELDS_FORMATTED"]["ENTITY"]["TYPE_MAIL"]; if (array_key_exists("URL_TO_SEND", $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0) { $arFields["URL"] = $arLogComment["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]; } else { $arFields["URL"] = $arLogComment["URL"]; } if (CModule::IncludeModule("extranet")) { $arUserGroup = CUser::GetUserGroup($arSubscriber["USER_ID"]); } foreach ($arLogSites as $site_id_tmp) { if (IsModuleInstalled("extranet")) { if (CExtranet::IsExtranetSite($site_id_tmp) && in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup) || !CExtranet::IsExtranetSite($site_id_tmp) && !in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup)) { $siteID = $site_id_tmp; break; } else { continue; } } else { $siteID = $site_id_tmp; break; } } if (!$siteID) { $siteID = defined("SITE_ID") ? SITE_ID : $arSubscriber["SITE_ID"]; } if (StrLen($siteID) <= 0) { $siteID = $arSubscriber["USER_LID"]; } if (StrLen($siteID) <= 0) { continue; } $event = new CEvent(); $event->Send($mailTemplate, $siteID, $arFields, "N"); break; default: } } CUserCounter::IncrementWithSelect(CSocNetLogCounter::GetSubSelect($arLog["ID"], $arLog["ENTITY_TYPE"], $arLog["ENTITY_ID"], $arLogComment["EVENT_ID"], $arLogComment["USER_ID"], $arOfEntities, false, false, "Y", "LC")); return true; }
function getProductDataToFillBasket($productId, $quantity, $userId, $LID, $userColumns, $tmpId = "") { if (!\Bitrix\Main\Loader::includeModule("catalog")) return array(); $arParams = array(); $productId = (int)$productId; if ($productId <= 0) { return $arParams; } $iblockId = (int)CIBlockElement::GetIBlockByID($productId); if ($iblockId <= 0) { return $arParams; } $arSku2Parent = array(); $arElementId = array(); $arElementId[] = $productId; $arParent = CCatalogSku::GetProductInfo($productId, $iblockId); if ($arParent) { $arElementId[] = $arParent["ID"]; $arSku2Parent[$productId] = $arParent["ID"]; } $arPropertyInfo = array(); $userColumns = (string)$userColumns; $arUserColumns = ($userColumns != '') ? explode(",", $userColumns) : array(); foreach ($arUserColumns as $key => $column) { if (strncmp($column, 'PROPERTY_', 9) != 0) { unset($arUserColumns[$key]); } else { $propertyCode = substr($column, 9); if ($propertyCode == '') { unset($arUserColumns[$key]); continue; } $dbres = CIBlockProperty::GetList(array(), array("CODE" => $propertyCode)); if ($arPropData = $dbres->GetNext()) $arPropertyInfo[$column] = $arPropData; } } $arSelect = array_merge( array("ID", "NAME", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "DETAIL_PAGE_URL", "XML_ID", "IBLOCK_XML_ID"), $arUserColumns ); $arProductData = getProductProps($arElementId, $arSelect); $defaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true); if (!empty($arProductData)) { $arElementInfo = array(); foreach ($arProductData as $elemId => &$arElement) { foreach ($arElement as $key => $value) { if (strncmp($key, 'PROPERTY_', 9) == 0 && substr($key, -6) == "_VALUE") { $columnCode = str_replace("_VALUE", "", $key); $arElement[$key] = getIblockPropInfo($value, $arPropertyInfo[$columnCode], array("WIDTH" => 90, "HEIGHT" => 90)); } } } unset($arElement); if (isset($arProductData[$productId])) $arElementInfo = $arProductData[$productId]; if (isset( $arSku2Parent[$productId])) $arParent = $arProductData[$arSku2Parent[$productId]]; if (!empty($arSku2Parent)) // if sku element doesn't have value of some property - we'll show parent element value instead { foreach ($arUserColumns as $field) { $fieldVal = $field."_VALUE"; $parentId = $arSku2Parent[$productId]; if ((!isset($arElementInfo[$fieldVal]) || (isset($arElementInfo[$fieldVal]) && strlen($arElementInfo[$fieldVal]) == 0)) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) // can be array or string { $arElementInfo[$fieldVal] = $arProductData[$parentId][$fieldVal]; } } if (strpos($arElementInfo["~XML_ID"], '#') === false) { $arElementInfo["~XML_ID"] = $arParent['~XML_ID'].'#'.$arElementInfo["~XML_ID"]; } } $arElementInfo["MODULE"] = "catalog"; $arElementInfo["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider"; $arElementInfo["PRODUCT_ID"] = $arElementInfo["ID"]; if ($arElementInfo["IBLOCK_ID"] > 0) { $arElementInfo["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arElementInfo["IBLOCK_ID"], $arElementInfo["PRODUCT_ID"], array( "find_section_section" => $arElementInfo["IBLOCK_SECTION_ID"], 'WF' => 'Y', )); } $arBuyerGroups = CUser::GetUserGroup($userId); // price $arPrice = CCatalogProduct::GetOptimalPrice($arElementInfo["ID"], 1, $arBuyerGroups, "N", array(), $LID); $currentPrice = $arPrice["DISCOUNT_PRICE"]; $arElementInfo["PRICE"] = $currentPrice; $arElementInfo["CURRENCY"] = $arPrice["PRICE"]["CURRENCY"]; $arElementInfo["DISCOUNT_PRICE"] = $arPrice["PRICE"]["PRICE"] - $arPrice["DISCOUNT_PRICE"]; $currentTotalPrice = ($arElementInfo["PRICE"] + $arElementInfo["DISCOUNT_PRICE"]); $discountPercent = 0; if ($arElementInfo["DISCOUNT_PRICE"] > 0) $discountPercent = intval(($arElementInfo["DISCOUNT_PRICE"] * 100) / $currentTotalPrice); $rsProducts = CCatalogProduct::GetList( array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY', 'WEIGHT', 'MEASURE', 'TYPE', 'BARCODE_MULTI') ); if (!($arProduct = $rsProducts->Fetch())) { return array(); } $balance = floatval($arProduct["QUANTITY"]); // sku props $arSkuData = array(); $arProps[] = array( "NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $arElementInfo['~IBLOCK_XML_ID'] ); $arSkuProperty = CSaleProduct::GetProductSkuProps($productId, '', true); if (!empty($arSkuProperty)) { foreach ($arSkuProperty as &$val) { $arSkuData[] = array( 'NAME' => $val['NAME'], 'VALUE' => $val['VALUE'], 'CODE' => $val['CODE'] ); } unset($val); } $arSkuData[] = array( "NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arElementInfo["~XML_ID"] ); // currency $arCurFormat = CCurrencyLang::GetCurrencyFormat($arElementInfo["CURRENCY"]); $priceValutaFormat = str_replace("#", "", $arCurFormat["FORMAT_STRING"]); $arElementInfo["WEIGHT"] = $arProduct["WEIGHT"]; // measure $arElementInfo["MEASURE_TEXT"] = ""; if ((int)$arProduct["MEASURE"] > 0) { $dbMeasure = CCatalogMeasure::GetList(array(), array("ID" => intval($arProduct["MEASURE"])), false, false, array("ID", "SYMBOL_RUS", "SYMBOL_INTL")); if ($arMeasure = $dbMeasure->Fetch()) $arElementInfo["MEASURE_TEXT"] = ($arMeasure["SYMBOL_RUS"] != '' ? $arMeasure["SYMBOL_RUS"] : $arMeasure["SYMBOL_INTL"]); } if ($arElementInfo["MEASURE_TEXT"] == '') { $arElementInfo["MEASURE_TEXT"] = ($defaultMeasure["SYMBOL_RUS"] != '' ? $defaultMeasure["SYMBOL_RUS"] : $defaultMeasure["SYMBOL_INTL"]); } // ratio $arElementInfo["RATIO"] = 1; $dbratio = CCatalogMeasureRatio::GetList(array(), array("PRODUCT_ID" => $productId)); if ($arRatio = $dbratio->Fetch()) $arElementInfo["RATIO"] = $arRatio["RATIO"]; // image if ($arElementInfo["PREVIEW_PICTURE"] > 0) $imgCode = $arElementInfo["PREVIEW_PICTURE"]; elseif ($arElementInfo["DETAIL_PICTURE"] > 0) $imgCode = $arElementInfo["DETAIL_PICTURE"]; if ($imgCode == "" && count($arParent) > 0) { if ($arParent["PREVIEW_PICTURE"] > 0) $imgCode = $arParent["PREVIEW_PICTURE"]; elseif ($arParent["DETAIL_PICTURE"] > 0) $imgCode = $arParent["DETAIL_PICTURE"]; } if ($imgCode > 0) { $arFile = CFile::GetFileArray($imgCode); $arImgProduct = CFile::ResizeImageGet($arFile, array('width'=>80, 'height'=>80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false); if (is_array($arImgProduct)) $imgUrl = $arImgProduct["src"]; } $arSetInfo = array(); $arStores = array(); /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider(array("MODULE" => $arElementInfo["MODULE"], "PRODUCT_PROVIDER_CLASS" => $arElementInfo["PRODUCT_PROVIDER_CLASS"]))) { // get set items if it is set if ($arProduct["TYPE"] == CCatalogProduct::TYPE_SET) { if (method_exists($productProvider, "GetSetItems")) { $arSets = $productProvider::GetSetItems($productId, CSaleBasket::TYPE_SET); if ($tmpId == "") $tmpId = randString(7); if (!empty($arSets)) { foreach ($arSets as $arSetData) { foreach ($arSetData["ITEMS"] as $setItem) { $arSetItemParams = getProductDataToFillBasket($setItem["PRODUCT_ID"], $setItem["QUANTITY"], $userId, $LID, $userColumns, $tmpId); // recursive call // re-define some fields with set data values $arSetItemParams["id"] = $setItem["PRODUCT_ID"]; $arSetItemParams["name"] = $setItem["NAME"]; $arSetItemParams["module"] = $setItem["MODULE"]; $arSetItemParams["productProviderClass"] = $setItem["PRODUCT_PROVIDER_CLASS"]; $arSetItemParams["url"] = $setItem["DETAIL_PAGE_URL"]; $arSetItemParams["quantity"] = $setItem["QUANTITY"] * $quantity; $arSetItemParams["barcodeMulti"] = $setItem["BARCODE_MULTI"]; $arSetItemParams["productType"] = $setItem["TYPE"]; $arSetItemParams["weight"] = $setItem["WEIGHT"]; $arSetItemParams["vatRate"] = $setItem["VAT_RATE"]; $arSetItemParams["setItems"] = ""; $arSetItemParams["setParentId"] = $productId."_tmp".$tmpId; $arSetItemParams["isSetItem"] = "Y"; $arSetItemParams["isSetParent"] = "N"; $arSetInfo[] = $arSetItemParams; } } } } } // get stores $storeCount = $productProvider::GetStoresCount(array("SITE_ID" => $LID)); // with exact SITE_ID or SITE_ID = NULL if ($storeCount > 0) { if ($arProductStore = $productProvider::GetProductStores(array("PRODUCT_ID" => $productId, "SITE_ID" => $LID))) $arStores = $arProductStore; } } $currentTotalPrice = (float)$currentTotalPrice; // params array $arParams["id"] = $productId; $arParams["name"] = $arElementInfo["~NAME"]; $arParams["url"] = htmlspecialcharsex($arElementInfo["~DETAIL_PAGE_URL"]); $arParams["urlEdit"] = $arElementInfo["EDIT_PAGE_URL"]; $arParams["urlImg"] = $imgUrl; $arParams["price"] = floatval($arElementInfo["PRICE"]); $arParams["priceBase"] = $currentTotalPrice; $arParams["priceBaseFormat"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], false); $arParams["priceFormated"] = CCurrencyLang::CurrencyFormat(floatval($arElementInfo["PRICE"]), $arElementInfo["CURRENCY"], false); $arParams["valutaFormat"] = $priceValutaFormat; $arParams["dimensions"] = serialize(array("WIDTH" => $arElementInfo["WIDTH"], "HEIGHT" => $arElementInfo["HEIGHT"], "LENGTH" => $arElementInfo["LENGTH"])); $arParams["priceDiscount"] = floatval($arElementInfo["DISCOUNT_PRICE"]); $arParams["priceTotalFormated"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], true); $arParams["discountPercent"] = $discountPercent; $arParams["summaFormated"] = CCurrencyLang::CurrencyFormat($arElementInfo["PRICE"], $arElementInfo["CURRENCY"], false); $arParams["quantity"] = $quantity; $arParams["module"] = $arElementInfo["MODULE"]; $arParams["currency"] = $arElementInfo["CURRENCY"]; $arParams["weight"] = $arElementInfo["WEIGHT"]; $arParams["vatRate"] = $arPrice["PRICE"]["VAT_RATE"]; $arParams["priceType"] = $arPrice["PRICE"]["CATALOG_GROUP_NAME"]; $arParams["balance"] = $balance; $arParams["notes"] = (is_array($arPrice["PRICE"]) && array_key_exists("CATALOG_GROUP_NAME", $arPrice["PRICE"])) ? $arPrice["PRICE"]["CATALOG_GROUP_NAME"] : ""; $arParams["catalogXmlID"] = $arElementInfo["~IBLOCK_XML_ID"]; $arParams["productXmlID"] = $arElementInfo["~XML_ID"]; $arParams["callback"] = ""; $arParams["orderCallback"] = ""; $arParams["cancelCallback"] = ""; $arParams["payCallback"] = ""; $arParams["productProviderClass"] = $arElementInfo["PRODUCT_PROVIDER_CLASS"]; $arParams["skuProps"] = $arSkuData; $arParams["measureText"] = $arElementInfo["MEASURE_TEXT"]; $arParams["ratio"] = $arElementInfo["RATIO"]; $arParams["barcodeMulti"] = $arProduct["BARCODE_MULTI"]; $arParams["productType"] = empty($arSetInfo) ? "" : CSaleBasket::TYPE_SET; $arParams["setParentId"] = empty($arSetInfo) ? "" : $productId."_tmp".$tmpId; $arParams["setItems"] = $arSetInfo; $arParams["isSetItem"] = "N"; $arParams["isSetParent"] = empty($arSetInfo) ? "N" : "Y"; $arParams["stores"] = empty($arSetInfo) ? $arStores : array(); $arParams["productPropsValues"] = $arElementInfo; // along with other information also contains values of properties with correct keys (after getProductProps) } return $arParams; }
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; }
function CanUserOperateDocumentType($operation, $userId, $documentType, $arParameters = array()) { $documentType = trim($documentType); if (strlen($documentType) <= 0) { return false; } $userId = intval($userId); if (array_key_exists("UserIsAdmin", $arParameters)) { if ($arParameters["UserIsAdmin"] === true) { return true; } } else { $arGroups = CUser::GetUserGroup($userId); if (in_array(1, $arGroups)) { return true; } } 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("bizproc", "CBPVirtualDocument", $documentType), 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"]); // $arAllowableOperations == null - workflow is not a statemachine // $arAllowableOperations == array() - no allowable operations // $arAllowableOperations == array("read", ...) - allowable operations list if (!is_array($arAllowableOperations) && $operation != 4) { return true; } if ($operation == 4) { return true; } $r = false; switch ($operation) { case 0: // DOCUMENT_OPERATION_VIEW_WORKFLOW $r = false; break; case 1: // DOCUMENT_OPERATION_START_WORKFLOW $r = in_array("create", $arAllowableOperations); break; case 4: // DOCUMENT_OPERATION_CREATE_WORKFLOW $r = false; break; case 2: // DOCUMENT_OPERATION_WRITE_DOCUMENT $r = in_array("create", $arAllowableOperations); break; case 3: // DOCUMENT_OPERATION_READ_DOCUMENT $r = false; break; default: $r = false; } return $r; }
function SendEvent($userGroupID, $mailTemplate = "SONET_INVITE_GROUP") { $userGroupID = IntVal($userGroupID); if ($userGroupID <= 0) { return false; } $dbRelation = CSocNetUserToGroup::GetList(array(), array("ID" => $userGroupID), false, false, array("ID", "USER_ID", "GROUP_ID", "ROLE", "DATE_CREATE", "MESSAGE", "INITIATED_BY_TYPE", "INITIATED_BY_USER_ID", "GROUP_NAME", "USER_NAME", "USER_LAST_NAME", "USER_EMAIL", "USER_LID")); $arRelation = $dbRelation->Fetch(); if (!$arRelation) { return false; } if (CModule::IncludeModule("extranet")) { $arUserGroup = CUser::GetUserGroup($arRelation["USER_ID"]); } $rsGroupSite = CSocNetGroup::GetSite($arRelation["GROUP_ID"]); while ($arGroupSite = $rsGroupSite->Fetch()) { if (IsModuleInstalled("extranet")) { if (CExtranet::IsExtranetSite($arGroupSite["LID"]) && in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup) || !CExtranet::IsExtranetSite($arGroupSite["LID"]) && !in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup)) { $siteID = $arGroupSite["LID"]; break; } else { continue; } } else { $siteID = $arGroupSite["LID"]; break; } } if ($siteID == false || StrLen($siteID) <= 0) { return false; } $requestsPagePath = str_replace("#USER_ID#", $arRelation["USER_ID"], COption::GetOptionString("socialnetwork", "user_request_page", IsModuleInstalled("intranet") ? "/company/personal/user/#USER_ID#/requests/" : "/club/user/#USER_ID#/requests/", $siteID)); $arUserInitiatedForEmail = array("NAME" => "", "LAST_NAME" => ""); if (intval($arRelation["INITIATED_BY_USER_ID"]) > 0) { $dbUserInitiated = CUser::GetList($by = "id", $order = "desc", array("ID" => $arRelation["INITIATED_BY_USER_ID"])); if ($arUserInitiated = $dbUserInitiated->Fetch()) { $arUserInitiatedForEmail = array("NAME" => $arUserInitiated["NAME"], "LAST_NAME" => $arUserInitiated["LAST_NAME"]); } } $arFields = array("RELATION_ID" => $userGroupID, "URL" => $requestsPagePath, "GROUP_ID" => $arRelation["GROUP_ID"], "USER_ID" => $arRelation["USER_ID"], "GROUP_NAME" => $arRelation["GROUP_NAME"], "USER_NAME" => $arRelation["USER_NAME"], "USER_LAST_NAME" => $arRelation["USER_LAST_NAME"], "USER_EMAIL" => $arRelation["USER_EMAIL"], "INITIATED_USER_NAME" => $arUserInitiatedForEmail["NAME"], "INITIATED_USER_LAST_NAME" => $arUserInitiatedForEmail["LAST_NAME"], "MESSAGE" => $arRelation["MESSAGE"]); $event = new CEvent(); $event->Send($mailTemplate, $siteID, $arFields, "N"); return true; }
public static function SendEvent($ID, $mailTemplate = "SONET_NEW_EVENT", $tmp_id = false, $bAgent = false, $bTransport = false) { $ID = IntVal($ID); if ($ID <= 0) return false; if (intval($tmp_id) > 0) $arFilter = array("ID" => $tmp_id); else $arFilter = array("ID" => $ID); $dbLog = CSocNetLog::GetList( array(), $arFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "EVENT_ID", "LOG_DATE", "TITLE_TEMPLATE", "TITLE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "CALLBACK_FUNC", "SITE_ID", "PARAMS", "SOURCE_ID", "GROUP_NAME", "CREATED_BY_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_LOGIN", "LOG_SOURCE_ID"), array("MIN_ID_JOIN" => true) ); $arLog = $dbLog->Fetch(); if (!$arLog) return $bAgent; if (MakeTimeStamp($arLog["LOG_DATE"]) > (time() + CTimeZone::GetOffset())) { $agent = "CSocNetLog::SendEventAgent(".$ID.", '".$mailTemplate."', ".($tmp_id ? $tmp_id : 'false').");"; $rsAgents = CAgent::GetList(array("ID"=>"DESC"), array("NAME" => $agent)); if(!$rsAgents->Fetch()) { $res = CAgent::AddAgent($agent, "socialnetwork", "N", 0, $arLog["LOG_DATE"], "Y", $arLog["LOG_DATE"]); if(!$res) $GLOBALS["APPLICATION"]->ResetException(); } elseif ($bAgent) { CAgent::RemoveAgent($agent, "socialnetwork"); CAgent::AddAgent($agent, "socialnetwork", "N", 0, $arLog["LOG_DATE"], "Y", $arLog["LOG_DATE"]); return true; } return false; } $arEvent = CSocNetLogTools::FindLogEventByID($arLog["EVENT_ID"], $arLog["ENTITY_TYPE"]); if ( $arEvent && array_key_exists("CLASS_FORMAT", $arEvent) && array_key_exists("METHOD_FORMAT", $arEvent) ) { $dbSiteCurrent = CSite::GetByID(SITE_ID); if ($arSiteCurrent = $dbSiteCurrent->Fetch()) if ($arSiteCurrent["LANGUAGE_ID"] != LANGUAGE_ID) $arLog["MAIL_LANGUAGE_ID"] = $arSiteCurrent["LANGUAGE_ID"]; $arLog["FIELDS_FORMATTED"] = call_user_func(array($arEvent["CLASS_FORMAT"], $arEvent["METHOD_FORMAT"]), $arLog, array(), true); } if ( array_key_exists($arLog["ENTITY_TYPE"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"]) && array_key_exists("HAS_MY", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]) && $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["HAS_MY"] == "Y" && array_key_exists("CLASS_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]) && array_key_exists("METHOD_OF", $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]) && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["CLASS_OF"]) > 0 && strlen($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["METHOD_OF"]) > 0 && method_exists($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["METHOD_OF"]) ) $arOfEntities = call_user_func(array($GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["CLASS_OF"], $GLOBALS["arSocNetAllowedSubscribeEntityTypesDesc"][$arLog["ENTITY_TYPE"]]["METHOD_OF"]), $arLog["ENTITY_ID"]); if ($bTransport) { $arListParams = array( "USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLog["ENTITY_TYPE"], "ENTITY_ID" => $arLog["ENTITY_ID"], "EVENT_ID" => $arLog["EVENT_ID"], "USER_ID" => $arLog["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => array("M", "X") ); $arLogSites = array(); $rsLogSite = CSocNetLog::GetSite($ID); while($arLogSite = $rsLogSite->Fetch()) $arLogSites[] = $arLogSite["LID"]; if (CModule::IncludeModule("extranet")) { $arSites = array(); $dbSite = CSite::GetList($by="sort", $order="desc", array("ACTIVE" => "Y")); while($arSite = $dbSite->Fetch()) $arSites[$arSite["ID"]] = array( "DIR" => (strlen(trim($arSite["DIR"])) > 0 ? $arSite["DIR"] : "/"), "SERVER_NAME" => (strlen(trim($arSite["SERVER_NAME"])) > 0 ? $arSite["SERVER_NAME"] : COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"])) ); $extranet_site_id = CExtranet::GetExtranetSiteID(); $intranet_site_id = CSite::GetDefSite(); $arIntranetUsers = CExtranet::GetIntranetUsers(); } $dbSubscribers = CSocNetLogEvents::GetList( array("TRANSPORT" => "DESC"), array( "USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false)) ), false, false, array("USER_ID", "SITE_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "USER_NAME", "USER_LAST_NAME", "USER_LOGIN", "USER_LID", "USER_EMAIL", "TRANSPORT"), $arListParams ); $arListParams = array( "USE_SUBSCRIBE" => "Y", "ENTITY_TYPE" => $arLog["ENTITY_TYPE"], "ENTITY_ID" => $arLog["ENTITY_ID"], "EVENT_ID" => $arLog["EVENT_ID"], "USER_ID" => $arLog["USER_ID"], "OF_ENTITIES" => $arOfEntities, "TRANSPORT" => "N" ); $dbUnSubscribers = CSocNetLogEvents::GetList( array("TRANSPORT" => "DESC"), array( "USER_ACTIVE" => "Y", "SITE_ID" => array_merge($arLogSites, array(false)) ), false, false, array("USER_ID", "SITE_ID", "ENTITY_TYPE", "ENTITY_ID", "ENTITY_CB", "ENTITY_MY", "TRANSPORT", "EVENT_ID"), $arListParams ); $arUnSubscribers = array(); while ($arUnSubscriber = $dbUnSubscribers->Fetch()) $arUnSubscribers[] = $arUnSubscriber["USER_ID"]."_".$arUnSubscriber["ENTITY_TYPE"]."_".$arUnSubscriber["ENTITY_ID"]."_".$arUnSubscriber["ENTITY_MY"]."_".$arUnSubscriber["ENTITY_CB"]."_".$arUnSubscriber["EVENT_ID"]; $bHasAccessAll = CSocNetLogRights::CheckForUserAll($arLog["ID"]); $arSentUserID = array("M" => array(), "X" => array()); while ($arSubscriber = $dbSubscribers->Fetch()) { if ( is_array($arIntranetUsers) && !in_array($arSubscriber["USER_ID"], $arIntranetUsers) && !in_array($extranet_site_id, $arLogSites) ) continue; if ( array_key_exists($arSubscriber["TRANSPORT"], $arSentUserID) && in_array($arSubscriber["USER_ID"], $arSentUserID[$arSubscriber["TRANSPORT"]]) ) continue; if ( intval($arSubscriber["ENTITY_ID"]) != 0 && $arSubscriber["EVENT_ID"] == "all" && ( in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arSubscriber["ENTITY_ID"]."_N_".$arSubscriber["ENTITY_CB"]."_".$arLog["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arSubscriber["ENTITY_ID"]."_Y_".$arSubscriber["ENTITY_CB"]."_".$arLog["EVENT_ID"], $arUnSubscribers) ) ) continue; elseif ( intval($arSubscriber["ENTITY_ID"]) == 0 && $arSubscriber["ENTITY_CB"] == "N" && $arSubscriber["EVENT_ID"] != "all" && ( in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arLog["ENTITY_ID"]."_Y_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arLog["ENTITY_ID"]."_N_N_all", $arUnSubscribers) || in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arLog["ENTITY_ID"]."_Y_N_".$arLog["EVENT_ID"], $arUnSubscribers) || in_array($arSubscriber["USER_ID"]."_".$arSubscriber["ENTITY_TYPE"]."_".$arLog["ENTITY_ID"]."_N_N_".$arLog["EVENT_ID"], $arUnSubscribers) ) ) continue; $arSentUserID[$arSubscriber["TRANSPORT"]][] = $arSubscriber["USER_ID"]; if (!$bHasAccessAll) { $bHasAccess = CSocNetLogRights::CheckForUserOnly($arLog["ID"], $arSubscriber["USER_ID"]); if (!$bHasAccess) continue; } if (CModule::IncludeModule("extranet")) { $server_name = $arSites[((!in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id) ? $extranet_site_id : $intranet_site_id)]["SERVER_NAME"]; $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"] = str_replace( array("#SERVER_NAME#", "#GROUPS_PATH#"), array( $server_name, COption::GetOptionString("socialnetwork", "workgroups_page", false, ((!in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id) ? $extranet_site_id : $intranet_site_id)) ), $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"] ); $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE_TO_SEND"] = str_replace( array("#SERVER_NAME#", "#GROUPS_PATH#"), array( $server_name, COption::GetOptionString("socialnetwork", "workgroups_page", false, ((!in_array($arSubscriber["USER_ID"], $arIntranetUsers) && $extranet_site_id) ? $extranet_site_id : $intranet_site_id)) ), $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"] ); } else $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE_TO_SEND"] = $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE"]; switch ($arSubscriber["TRANSPORT"]) { case "X": if ( array_key_exists("URL_TO_SEND", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0 ) $link = GetMessage("SONET_GL_SEND_EVENT_LINK").$arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]; elseif ( array_key_exists("URL", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]) > 0 ) $link = GetMessage("SONET_GL_SEND_EVENT_LINK").$arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]; else $link = ""; $arMessageFields = array( "FROM_USER_ID" => (intval($arLog["USER_ID"]) > 0 ? $arLog["USER_ID"] : 1), "TO_USER_ID" => $arSubscriber["USER_ID"], "MESSAGE" => $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"]." #BR#".$arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE_TO_SEND"].(strlen($link) > 0 ? "#BR# ".$link : ""), "=DATE_CREATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE_TYPE" => SONET_MESSAGE_SYSTEM, "IS_LOG" => "Y" ); CSocNetMessages::Add($arMessageFields); break; case "M": $arFields["SUBSCRIBER_ID"] = $arSubscriber["USER_ID"]; $arFields["SUBSCRIBER_NAME"] = $arSubscriber["USER_NAME"]; $arFields["SUBSCRIBER_LAST_NAME"] = $arSubscriber["USER_LAST_NAME"]; $arFields["SUBSCRIBER_LOGIN"] = $arSubscriber["USER_LOGIN"]; $arFields["SUBSCRIBER_EMAIL"] = $arSubscriber["USER_EMAIL"]; $arFields["EMAIL_TO"] = $arSubscriber["USER_EMAIL"]; $arFields["TITLE"] = str_replace("#BR#", "\n", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["TITLE"]); $arFields["MESSAGE"] = str_replace("#BR#", "\n", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["MESSAGE_TO_SEND"]); $arFields["ENTITY"] = $arLog["FIELDS_FORMATTED"]["ENTITY"]["FORMATTED"]; $arFields["ENTITY_TYPE"] = $arLog["FIELDS_FORMATTED"]["ENTITY"]["TYPE_MAIL"]; if ( array_key_exists("URL_TO_SEND", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]) > 0 ) $arFields["URL"] = $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL_TO_SEND"]; elseif ( array_key_exists("URL", $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]) && strlen($arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]) > 0 ) $arFields["URL"] = $arLog["FIELDS_FORMATTED"]["EVENT_FORMATTED"]["URL"]; else $arFields["URL"] = $arLog["URL"]; if (CModule::IncludeModule("extranet")) $arUserGroup = CUser::GetUserGroup($arSubscriber["USER_ID"]); foreach ($arLogSites as $site_id_tmp) { if (IsModuleInstalled("extranet")) { if ( ( CExtranet::IsExtranetSite($site_id_tmp) && in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup) ) || ( !CExtranet::IsExtranetSite($site_id_tmp) && !in_array(CExtranet::GetExtranetUserGroupID(), $arUserGroup) ) ) { $siteID = $site_id_tmp; break; } else continue; } else { $siteID = $site_id_tmp; break; } } if (!$siteID) $siteID = (defined("SITE_ID") ? SITE_ID : $arSubscriber["SITE_ID"]); if (StrLen($siteID) <= 0) $siteID = $arSubscriber["USER_LID"]; if (StrLen($siteID) <= 0) continue; $event = new CEvent; $event->Send($mailTemplate, $siteID, $arFields, "N"); break; default: } } } CSocNetLog::CounterIncrement($arLog["ID"], $arLog["EVENT_ID"], $arOfEntities); return true; }
"TIMESTAMP_2" => $find_timestamp_2, "LAST_LOGIN_1" => $find_last_login_1, "LAST_LOGIN_2" => $find_last_login_2, "ACTIVE" => $find_active, "LOGIN" => ($find!='' && $find_type == "login"? $find: $find_login), "NAME" => ($find!='' && $find_type == "name"? $find: $find_name), "EMAIL" => ($find!='' && $find_type == "email"? $find: $find_email), "KEYWORDS" => $find_keywords, "GROUPS_ID" => $find_group_id ); } if(!$USER->CanDoOperation('view_all_users')) { $arUserSubordinateGroups = array(); $arUserGroups = CUser::GetUserGroup($USER->GetID()); foreach($arUserGroups as $grp) $arUserSubordinateGroups = array_merge($arUserSubordinateGroups, CGroup::GetSubordinateGroups($grp)); $arFilter["CHECK_SUBORDINATE"] = array_unique($arUserSubordinateGroups); } $rsData = CUser::GetList($by, $order, $arFilter, array( "NAV_PARAMS"=> array("nPageSize"=>CAdminResult::GetNavSize($sTableID)), )); $rsData = new CAdminResult($rsData, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("PAGES")));
/** * @param $userId * @param $lid * @param $productId * @param string $productName * @param string $currency * @param array $arProduct * @return array|bool */ function GetProductSku($userId, $lid, $productId, $productName = '', $currency = '', $arProduct = array()) { $userId = intval($userId); $productId = intval($productId); if ($productId <= 0) { return false; } $lid = trim($lid); if (strlen($lid) <= 0) { return false; } $productName = trim($productName); $arResult = array(); static $arCacheGroups = array(); if (!isset($arCacheGroups[$userId])) { $arCacheGroups[$userId] = CUser::GetUserGroup($userId); } $arGroups = $arCacheGroups[$userId]; if (!isset($arProduct["IBLOCK_ID"]) || 0 >= intval($arProduct["IBLOCK_ID"])) { $arProduct["IBLOCK_ID"] = CIBlockElement::GetIBlockByID($arProduct["IBLOCK_ID"]); } static $arOffersIblock = array(); if (!isset($arOffersIblock[$arProduct["IBLOCK_ID"]])) { $mxResult = CCatalogSKU::GetInfoByProductIBlock($arProduct["IBLOCK_ID"]); if (is_array($mxResult)) { $arOffersIblock[$arProduct["IBLOCK_ID"]] = $mxResult["IBLOCK_ID"]; } } if ($arOffersIblock[$arProduct["IBLOCK_ID"]] > 0) { static $arCacheOfferProperties = array(); if (!is_set($arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]])) { $dbOfferProperties = CIBlockProperty::GetList(array('SORT' => 'ASC', 'ID' => 'ASC'), array('IBLOCK_ID' => $arOffersIblock[$arProduct["IBLOCK_ID"]], 'ACTIVE' => 'Y', "!XML_ID" => "CML2_LINK")); while ($arOfferProperties = $dbOfferProperties->Fetch()) { if ('F' == $arOfferProperties['PROPERTY_TYPE']) { continue; } $arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]][] = $arOfferProperties; } } $arOfferProperties = $arCacheOfferProperties[$arOffersIblock[$arProduct["IBLOCK_ID"]]]; $arIblockOfferProps = array(); $arIblockOfferPropsFilter = array(); if (is_array($arOfferProperties)) { foreach ($arOfferProperties as $val) { $arIblockOfferProps[] = array("CODE" => $val["CODE"], "NAME" => $val["NAME"]); $arIblockOfferPropsFilter[] = $val["CODE"]; } } $arOffers = CIBlockPriceTools::GetOffersArray($arProduct["IBLOCK_ID"], $productId, array("ID" => "DESC"), array("NAME", "EXTERNAL_ID"), $arIblockOfferPropsFilter, 0, array(), 1, array(), $userId, $lid); $arSku = array(); $arSkuId = array(); $arImgSku = array(); foreach ($arOffers as $arOffer) { $arSkuId[] = $arOffer['ID']; } if (!empty($arSkuId)) { $res = CIBlockElement::GetList(array(), array("ID" => $arSkuId), false, false, array("ID", "IBLOCK_ID", "NAME", "PREVIEW_PICTURE", "DETAIL_PICTURE", "DETAIL_PAGE_URL", "ACTIVE")); while ($arOfferImg = $res->GetNext()) { $arImgSku[$arOfferImg["ID"]] = $arOfferImg; } } $arOffersId = array(); foreach ($arOffers as $arOffer) { $arOffersId[] = $arOffer['ID']; } $dbCatalogProduct = CCatalogProduct::GetList(array(), array("ID" => $arOffersId)); while ($arCatalogProduct = $dbCatalogProduct->fetch()) { $arCatalogProductResult[$arCatalogProduct["ID"]] = $arCatalogProduct; } foreach ($arOffers as $arOffer) { $arSkuTmp = array(); $active = ''; $arOffer["CAN_BUY"] = "N"; $arCatalogProduct = $arCatalogProductResult[$arOffer["ID"]]; if (!empty($arCatalogProduct)) { if ($arCatalogProduct["CAN_BUY_ZERO"] != "Y" && ($arCatalogProduct["QUANTITY_TRACE"] == "Y" && doubleval($arCatalogProduct["QUANTITY"]) <= 0)) { $arOffer["CAN_BUY"] = "N"; } else { $arOffer["CAN_BUY"] = "Y"; } } $arSkuTmp["ImageUrl"] = ''; if ($arOffer["CAN_BUY"] == "Y") { if (isset($arImgSku[$arOffer['ID']]) && !empty($arImgSku[$arOffer['ID']])) { if ('' == $productName) { $productName = $arImgSku[$arOffer['ID']]["~NAME"]; } $active = $arImgSku[$arOffer['ID']]["ACTIVE"]; if ($arImgSku[$arOffer['ID']]["PREVIEW_PICTURE"] != "") { $arSkuTmp["PREVIEW_PICTURE"] = $arImgSku[$arOffer['ID']]["PREVIEW_PICTURE"]; } if ($arImgSku[$arOffer['ID']]["DETAIL_PICTURE"] != "") { $arSkuTmp["DETAIL_PICTURE"] = $arImgSku[$arOffer['ID']]["DETAIL_PICTURE"]; } } } foreach ($arIblockOfferProps as $arCode) { if (is_array($arCode) && isset($arOffer["PROPERTIES"][$arCode["CODE"]])) { if (isset($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]])) { $mxValues = ''; if ('E' == $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['PROPERTY_TYPE']) { if (!empty($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_ELEMENT_VALUE'])) { $mxValues = array(); foreach ($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_ELEMENT_VALUE'] as $arTempo) { $mxValues[] = $arTempo['NAME'] . ' [' . $arTempo['ID'] . ']'; } } } elseif ('G' == $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['PROPERTY_TYPE']) { if (!empty($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_SECTION_VALUE'])) { $mxValues = array(); foreach ($arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]['LINK_SECTION_VALUE'] as $arTempo) { $mxValues[] = $arTempo['NAME'] . ' [' . $arTempo['ID'] . ']'; } } } if (empty($mxValues)) { $mxValues = $arOffer["DISPLAY_PROPERTIES"][$arCode["CODE"]]["DISPLAY_VALUE"]; } $arSkuTmp[] = strip_tags(is_array($mxValues) ? implode("/ ", $mxValues) : $mxValues); } else { $arSkuTmp[] = ''; } } } if (!empty($arCatalogProduct)) { $arSkuTmp["BALANCE"] = $arCatalogProduct["QUANTITY"]; $arSkuTmp["WEIGHT"] = $arCatalogProduct["WEIGHT"]; $arSkuTmp["BARCODE_MULTI"] = $arCatalogProduct["BARCODE_MULTI"]; } else { $arSkuTmp["BALANCE"] = 0; $arSkuTmp["WEIGHT"] = 0; $arSkuTmp["BARCODE_MULTI"] = 'N'; } $arSkuTmp["USER_ID"] = $userId; $arSkuTmp["ID"] = $arOffer["ID"]; $arSkuTmp["TYPE"] = $arOffer["CATALOG_TYPE"]; $arSkuTmp["NAME"] = CUtil::JSEscape($arOffer["NAME"]); $arSkuTmp["PRODUCT_NAME"] = CUtil::JSEscape(htmlspecialcharsbx($productName)); $arSkuTmp["PRODUCT_ID"] = $productId; $arSkuTmp["LID"] = CUtil::JSEscape($lid); $arSkuTmp["CAN_BUY"] = $arOffer["CAN_BUY"]; $arSkuTmp["ACTIVE"] = $active; $arSkuTmp["EXTERNAL_ID"] = $arOffer['EXTERNAL_ID']; $arSku[] = $arSkuTmp; } if ((!is_array($arIblockOfferProps) || empty($arIblockOfferProps)) && is_array($arSku) && !empty($arSku)) { $arIblockOfferProps[0] = array("CODE" => "TITLE", "NAME" => GetMessage("SKU_TITLE")); foreach ($arSku as $key => $val) { $arSku[$key][0] = $val["NAME"]; } } $arResult["SKU_ELEMENTS"] = $arSku; $arResult["SKU_PROPERTIES"] = $arIblockOfferProps; $arResult["OFFERS_IBLOCK_ID"] = $arOffersIblock[$arProduct["IBLOCK_ID"]]; } return $arResult; }
public static function DoProcessOrder(&$arOrder, $arOptions, &$arErrors) { if (empty($arOrder['BASKET_ITEMS']) || !is_array($arOrder['BASKET_ITEMS'])) { return; } $arIDS = array(); $groupDiscountIterator = Internals\DiscountGroupTable::getList(array('select' => array('DISCOUNT_ID'), 'filter' => array('@GROUP_ID' => CUser::GetUserGroup($arOrder['USER_ID']), '=ACTIVE' => 'Y'))); while ($groupDiscount = $groupDiscountIterator->fetch()) { $groupDiscount['DISCOUNT_ID'] = (int) $groupDiscount['DISCOUNT_ID']; if ($groupDiscount['DISCOUNT_ID'] > 0) { $arIDS[$groupDiscount['DISCOUNT_ID']] = true; } } if (!empty($arIDS)) { $arIDS = array_keys($arIDS); $couponList = DiscountCouponsManager::getForApply(array('MODULE' => 'sale', 'DISCOUNT_ID' => $arIDS), array(), true); $arExtend = array('catalog' => array('fields' => true, 'props' => true)); foreach (GetModuleEvents('sale', 'OnExtendBasketItems', true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arOrder['BASKET_ITEMS'], $arExtend)); } foreach ($arOrder['BASKET_ITEMS'] as &$arOneItem) { if (array_key_exists('PRODUCT_PROVIDER_CLASS', $arOneItem) && empty($arOneItem['PRODUCT_PROVIDER_CLASS']) && array_key_exists('CALLBACK_FUNC', $arOneItem) && empty($arOneItem['CALLBACK_FUNC']) && (!isset($arOneItem['CUSTOM_PRICE']) || $arOneItem['CUSTOM_PRICE'] != 'Y')) { if (isset($arOneItem['DISCOUNT_PRICE'])) { $arOneItem['PRICE'] += $arOneItem['DISCOUNT_PRICE']; $arOneItem['DISCOUNT_PRICE'] = 0; } } } if (isset($arOneItem)) { unset($arOneItem); } if (empty(self::$cacheDiscountHandlers)) { self::$cacheDiscountHandlers = CSaleDiscount::getDiscountHandlers($arIDS); } else { $needDiscountHandlers = array(); foreach ($arIDS as &$discountID) { if (!isset(self::$cacheDiscountHandlers[$discountID])) { $needDiscountHandlers[] = $discountID; } } unset($discountID); if (!empty($needDiscountHandlers)) { $discountHandlersList = CSaleDiscount::getDiscountHandlers($needDiscountHandlers); if (!empty($discountHandlersList)) { foreach ($discountHandlersList as $discountID => $discountHandlers) { self::$cacheDiscountHandlers[$discountID] = $discountHandlers; } unset($discountHandlers, $discountID); } unset($discountHandlersList); } unset($needDiscountHandlers); } CTimeZone::Disable(); $currentDatetime = new Type\DateTime(); $discountSelect = array('ID', 'PRIORITY', 'SORT', 'LAST_DISCOUNT', 'UNPACK', 'APPLICATION', 'USE_COUPONS'); $discountOrder = array('PRIORITY' => 'DESC', 'SORT' => 'ASC', 'ID' => 'ASC'); $discountFilter = array('@ID' => $arIDS, '=LID' => $arOrder['SITE_ID'], array('LOGIC' => 'OR', 'ACTIVE_FROM' => '', '<=ACTIVE_FROM' => $currentDatetime), array('LOGIC' => 'OR', 'ACTIVE_TO' => '', '>=ACTIVE_TO' => $currentDatetime)); if (empty($couponList)) { $discountFilter['=USE_COUPONS'] = 'N'; } else { $discountFilter[] = array('LOGIC' => 'OR', '=USE_COUPONS' => 'N', array('=USE_COUPONS' => 'Y', '=COUPON.COUPON' => array_keys($couponList))); $discountSelect['DISCOUNT_COUPON'] = 'COUPON.COUPON'; } $discountIterator = Internals\DiscountTable::getList(array('select' => $discountSelect, 'filter' => $discountFilter, 'order' => $discountOrder)); $discountApply = array(); $resultDiscountList = array(); $resultDiscountKeys = array(); $resultDiscountIndex = 0; while ($discount = $discountIterator->fetch()) { $discount['ID'] = (int) $discount['ID']; if (isset($discountApply[$discount['ID']])) { continue; } $discount['MODULE'] = 'sale'; $discountApply[$discount['ID']] = true; $applyFlag = true; if (isset(self::$cacheDiscountHandlers[$discount['ID']])) { $moduleList = self::$cacheDiscountHandlers[$discount['ID']]['MODULES']; if (!empty($moduleList)) { foreach ($moduleList as &$moduleID) { if (!isset(self::$usedModules[$moduleID])) { self::$usedModules[$moduleID] = Loader::includeModule($moduleID); } if (!self::$usedModules[$moduleID]) { $applyFlag = false; break; } } unset($moduleID); } unset($moduleList); } if ($applyFlag && self::__Unpack($arOrder, $discount['UNPACK'])) { $oldOrder = $arOrder; self::__ApplyActions($arOrder, $discount['APPLICATION']); $discountResult = self::getDiscountResult($oldOrder, $arOrder, false); if (!empty($discountResult['DELIVERY']) || !empty($discountResult['BASKET'])) { if ($discount['USE_COUPONS'] == 'Y' && !empty($discount['DISCOUNT_COUPON'])) { if ($couponList[$discount['DISCOUNT_COUPON']]['TYPE'] == Internals\DiscountCouponTable::TYPE_BASKET_ROW) { self::changeDiscountResult($oldOrder, $arOrder, $discountResult); } $couponApply = DiscountCouponsManager::setApply($discount['DISCOUNT_COUPON'], $discountResult); } $resultDiscountList[$resultDiscountIndex] = array('MODULE_ID' => $discount['MODULE_ID'], 'ID' => $discount['ID'], 'PRIORITY' => $discount['PRIORITY'], 'SORT' => $discount['SORT'], 'LAST_DISCOUNT' => $discount['LAST_DISCOUNT'], 'UNPACK' => $discount['UNPACK'], 'APPLICATION' => $discount['APPLICATION'], 'RESULT' => $discountResult, 'HANDLERS' => self::$cacheDiscountHandlers[$discount['ID']], 'USE_COUPONS' => $discount['USE_COUPONS'], 'COUPON' => $discount['USE_COUPONS'] == 'Y' ? $couponList[$discount['DISCOUNT_COUPON']] : false); $resultDiscountKeys[$discount['ID']] = $resultDiscountIndex; $resultDiscountIndex++; if ($discount['LAST_DISCOUNT'] == 'Y') { break; } } unset($discountResult); } } unset($discount, $discountIterator); CTimeZone::Enable(); if ($resultDiscountIndex > 0) { $discountIterator = Internals\DiscountTable::getList(array('select' => array('ID', 'NAME', 'CONDITIONS', 'ACTIONS'), 'filter' => array('@ID' => array_keys($resultDiscountKeys)))); while ($discount = $discountIterator->fetch()) { $discount['ID'] = (int) $discount['ID']; if (isset($resultDiscountKeys[$discount['ID']])) { $key = $resultDiscountKeys[$discount['ID']]; $resultDiscountList[$key]['NAME'] = $discount['NAME']; $resultDiscountList[$key]['CONDITIONS'] = $discount['CONDITIONS']; $resultDiscountList[$key]['ACTIONS'] = $discount['ACTIONS']; } } unset($discount, $discountIterator); } $arOrder["ORDER_PRICE"] = 0; $arOrder["ORDER_WEIGHT"] = 0; $arOrder["USE_VAT"] = false; $arOrder["VAT_RATE"] = 0; $arOrder["VAT_SUM"] = 0; $arOrder["DISCOUNT_PRICE"] = 0.0; $arOrder["DISCOUNT_VALUE"] = $arOrder["DISCOUNT_PRICE"]; $arOrder["DELIVERY_PRICE"] = $arOrder["PRICE_DELIVERY"]; foreach ($arOrder['BASKET_ITEMS'] as &$arShoppingCartItem) { if (!CSaleBasketHelper::isSetItem($arShoppingCartItem)) { $arOrder["ORDER_PRICE"] += doubleval($arShoppingCartItem["PRICE"]) * doubleval($arShoppingCartItem["QUANTITY"]); $arOrder["ORDER_WEIGHT"] += $arShoppingCartItem["WEIGHT"] * $arShoppingCartItem["QUANTITY"]; $arShoppingCartItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arShoppingCartItem["PRICE"], $arShoppingCartItem["CURRENCY"], true); $arShoppingCartItem["DISCOUNT_PRICE_PERCENT"] = 0; if ($arShoppingCartItem["DISCOUNT_PRICE"] + $arShoppingCartItem["PRICE"] > 0) { $arShoppingCartItem["DISCOUNT_PRICE_PERCENT"] = $arShoppingCartItem["DISCOUNT_PRICE"] * 100 / ($arShoppingCartItem["DISCOUNT_PRICE"] + $arShoppingCartItem["PRICE"]); } $arShoppingCartItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arShoppingCartItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%"; if ($arShoppingCartItem["VAT_RATE"] > 0) { $arOrder["USE_VAT"] = true; if ($arShoppingCartItem["VAT_RATE"] > $arOrder["VAT_RATE"]) { $arOrder["VAT_RATE"] = $arShoppingCartItem["VAT_RATE"]; } $arOrder["VAT_SUM"] += $arShoppingCartItem["VAT_VALUE"] * $arShoppingCartItem["QUANTITY"]; } } } if (isset($arShoppingCartItem)) { unset($arShoppingCartItem); } $arOrder['DISCOUNT_LIST'] = $resultDiscountList; } }
function UpdateUser($arFields = array(), $FORMAT_DATE = false, $FORMAT_DATETIME = false) { global $DB; $arFields["ACTIVE"] = "Y"; $arFields["PASSWORD"] = md5(uniqid(rand(), true)); $oUser = new CUser(); unset($arFields["ID"]); unset($arFields["TIMESTAMP_X"]); unset($arFields["DATE_REGISTER"]); if (isset($arFields["PERSONAL_BIRTHDAY"]) && $arFields["PERSONAL_BIRTHDAY"] != '' && $FORMAT_DATE !== false) { $arFields["PERSONAL_BIRTHDAY"] = $DB->FormatDate($arFields["PERSONAL_BIRTHDAY"], $FORMAT_DATE, FORMAT_DATE); } $dbr_user = CUser::GetList($O, $B, array("LOGIN_EQUAL_EXACT" => $arFields["LOGIN"], "EXTERNAL_AUTH_ID" => "__controller")); if ($ar_user = $dbr_user->Fetch()) { $arFields['EXTERNAL_AUTH_ID'] = "__controller"; $USER_ID = $ar_user["ID"]; if (is_array($arFields["GROUPS_TO_ADD"]) && is_array($arFields["GROUPS_TO_DELETE"])) { $arFields["GROUP_ID"] = CUser::GetUserGroup($USER_ID); foreach ($arFields["GROUPS_TO_DELETE"] as $group_id) { $group_id = CGroup::GetIDByCode($group_id); if ($group_id > 0) { $p = array_search($group_id, $arFields["GROUP_ID"]); if ($p !== false) { unset($arFields["GROUP_ID"][$p]); } } } foreach ($arFields["GROUPS_TO_ADD"] as $group_id) { $group_id = CGroup::GetIDByCode($group_id); if ($group_id > 0) { $arFields["GROUP_ID"][] = $group_id; } } } elseif (is_array($arFields["GROUP_ID"])) { $groups = $arFields["GROUP_ID"]; $arFields["GROUP_ID"] = array(); foreach ($groups as $group_id) { $group_id = CGroup::GetIDByCode($group_id); if ($group_id > 0) { $arFields["GROUP_ID"][] = $group_id; } } } if (!$oUser->Update($USER_ID, $arFields)) { return false; } } else { $arFields['EXTERNAL_AUTH_ID'] = "__controller"; $arFields["LID"] = SITE_ID; if (is_array($arFields["GROUP_ID"])) { $groups = $arFields["GROUP_ID"]; $arFields["GROUP_ID"] = array(); foreach ($groups as $group_id) { $group_id = CGroup::GetIDByCode($group_id); if ($group_id > 0) { $arFields["GROUP_ID"][] = $group_id; } } } $USER_ID = $oUser->Add($arFields); } return $USER_ID; }